Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(entrypoint): replace get_deposit calls with balance_of #383

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions crates/provider/src/ethers/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use ethers::{
contract::{ContractError, FunctionCall},
providers::{spoof, Middleware, RawCall},
types::{
transaction::eip2718::TypedTransaction, Address, Bytes, Eip1559TransactionRequest, H256,
U256,
transaction::eip2718::TypedTransaction, Address, BlockId, Bytes, Eip1559TransactionRequest,
H256, U256,
},
};
use rundler_types::{
Expand Down Expand Up @@ -72,23 +72,20 @@ where
Err(error)?
}

async fn balance_of(&self, address: Address) -> anyhow::Result<U256> {
self.balance_of(address)
async fn balance_of(
&self,
address: Address,
block_id: Option<BlockId>,
) -> anyhow::Result<U256> {
block_id
.map_or(self.balance_of(address), |bid| {
self.balance_of(address).block(bid)
})
.call()
.await
.context("entry point should return balance")
}

async fn get_deposit(&self, address: Address, block_hash: H256) -> anyhow::Result<U256> {
let deposit_info = self
.get_deposit_info(address)
.block(block_hash)
.call()
.await
.context("entry point should return deposit info")?;
Ok(deposit_info.deposit.into())
}

async fn call_spoofed_simulate_op(
&self,
op: UserOperation,
Expand Down
10 changes: 5 additions & 5 deletions crates/provider/src/traits/entry_point.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use ethers::types::{spoof, transaction::eip2718::TypedTransaction, Address, Bytes, H256, U256};
use ethers::types::{
spoof, transaction::eip2718::TypedTransaction, Address, BlockId, Bytes, H256, U256,
};
#[cfg(feature = "test-utils")]
use mockall::automock;
use rundler_types::{
Expand Down Expand Up @@ -35,10 +37,8 @@ pub trait EntryPoint: Send + Sync + 'static {
) -> anyhow::Result<HandleOpsOut>;

/// Get the balance of an address
async fn balance_of(&self, address: Address) -> anyhow::Result<U256>;

/// Get the deposit value of an address on the entry point contract
async fn get_deposit(&self, address: Address, block_hash: H256) -> anyhow::Result<U256>;
async fn balance_of(&self, address: Address, block_id: Option<BlockId>)
-> anyhow::Result<U256>;

/// Call the entry point contract's `simulateValidation` function
async fn simulate_validation(
Expand Down
9 changes: 6 additions & 3 deletions crates/rundler/src/builder/bundle_proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use anyhow::Context;
use ethers::types::{Address, Bytes, H256, U256};
use ethers::types::{Address, BlockId, Bytes, H256, U256};
use futures::future;
use linked_hash_map::LinkedHashMap;
#[cfg(test)]
Expand Down Expand Up @@ -421,7 +421,10 @@ where
block_hash: H256,
) -> anyhow::Result<HashMap<Address, U256>> {
let futures = addreses.map(|address| async move {
let deposit = self.entry_point.get_deposit(address, block_hash).await?;
let deposit = self
.entry_point
.balance_of(address, Some(BlockId::Hash(block_hash)))
.await?;
Ok::<_, anyhow::Error>((address, deposit))
});
let addresses_and_deposits = future::try_join_all(futures)
Expand Down Expand Up @@ -1222,7 +1225,7 @@ mod tests {
}
for deposit in mock_paymaster_deposits {
entry_point
.expect_get_deposit()
.expect_balance_of()
.times(..=1)
.return_once(move |_, _| Ok(deposit));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rundler/src/common/precheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<P: Provider, E: EntryPoint> PrecheckerImpl<P, E> {
None => op.sender,
};
self.entry_point
.balance_of(payer)
.balance_of(payer, None)
.await
.context("precheck should get payer balance")
}
Expand Down
Loading