Skip to content

Commit

Permalink
fix: accesslist request not insufficient funds
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Feb 1, 2024
1 parent 456e5b3 commit 146e432
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
2 changes: 2 additions & 0 deletions bin/silius/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ where
client,
uopool_grpc_client,
metrics_args.enable_metrics,
args.enable_access_list,
);
}
SendStrategy::Flashbots => {
Expand Down Expand Up @@ -180,6 +181,7 @@ where
client,
uopool_grpc_client,
metrics_args.enable_metrics,
args.enable_access_list,
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions bin/silius/src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ pub struct BundlerArgs {
/// By default, this option is set to `ethereum-client`.
#[clap(long, default_value = "ethereum-client", value_parser=parse_send_bundle_mode)]
pub send_bundle_mode: SendStrategy,

/// Indicates whether the access list is enabled.
#[clap(long)]
pub enable_access_list: bool,
}

/// UoPool CLI args
Expand Down Expand Up @@ -352,6 +356,7 @@ mod tests {
send_bundle_mode: SendStrategy::EthereumClient,
bundler_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
bundler_port: 3002,
enable_access_list: false,
},
BundlerArgs::try_parse_from(args).unwrap()
);
Expand Down
65 changes: 37 additions & 28 deletions crates/bundler/src/bundler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_chains::{Chain, NamedChain};
use alloy_chains::Chain;
use ethers::{
providers::Middleware,
signers::Signer,
Expand Down Expand Up @@ -45,6 +45,8 @@ where
pub eth_client: Arc<M>,
/// Client that sends the bundle to some network
pub client: Arc<S>,
/// Whether add access list into tx
pub enable_access_list: bool,
}

impl<M, S> Bundler<M, S>
Expand All @@ -56,6 +58,7 @@ where
///
/// # Returns
/// * `Self` - A new `Bundler` instance
#[allow(clippy::too_many_arguments)]
pub fn new(
wallet: Wallet,
beneficiary: Address,
Expand All @@ -64,8 +67,18 @@ where
min_balance: U256,
eth_client: Arc<M>,
client: Arc<S>,
enable_access_list: bool,
) -> Self {
Self { wallet, beneficiary, entry_point, chain, min_balance, eth_client, client }
Self {
wallet,
beneficiary,
entry_point,
chain,
min_balance,
eth_client,
client,
enable_access_list,
}
}

/// Functions that generates a bundle of user operations (i.e.,
Expand Down Expand Up @@ -95,34 +108,30 @@ where
)
.tx;

match Chain::from_id(self.chain.id()).named() {
// Mumbai
Some(NamedChain::PolygonMumbai) => {
tx.set_nonce(nonce).set_chain_id(self.chain.id());
}
// All other surpported networks, including Mainnet, Goerli
_ => {
let accesslist = self.eth_client.create_access_list(&tx, None).await?.access_list;
tx.set_access_list(accesslist.clone());
let estimated_gas = self.eth_client.estimate_gas(&tx, None).await?;
let accesslist = if self.enable_access_list {
let accesslist = self.eth_client.create_access_list(&tx, None).await?.access_list;
tx.set_access_list(accesslist.clone());
accesslist
} else {
Default::default()
};
let estimated_gas = self.eth_client.estimate_gas(&tx, None).await?;

let (max_fee_per_gas, max_priority_fee) =
self.eth_client.estimate_eip1559_fees(None).await?;
let (max_fee_per_gas, max_priority_fee) =
self.eth_client.estimate_eip1559_fees(None).await?;

tx = TypedTransaction::Eip1559(Eip1559TransactionRequest {
to: tx.to().cloned(),
from: Some(self.wallet.signer.address()),
data: tx.data().cloned(),
chain_id: Some(U64::from(self.chain.id())),
max_priority_fee_per_gas: Some(max_priority_fee),
max_fee_per_gas: Some(max_fee_per_gas),
gas: Some(estimated_gas),
nonce: Some(nonce),
value: None,
access_list: accesslist,
});
}
};
tx = TypedTransaction::Eip1559(Eip1559TransactionRequest {
to: tx.to().cloned(),
from: Some(self.wallet.signer.address()),
data: tx.data().cloned(),
chain_id: Some(U64::from(self.chain.id())),
max_priority_fee_per_gas: Some(max_priority_fee),
max_fee_per_gas: Some(max_fee_per_gas),
gas: Some(estimated_gas),
nonce: Some(nonce),
value: None,
access_list: accesslist,
});

Ok(tx)
}
Expand Down
1 change: 1 addition & 0 deletions crates/bundler/tests/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ async fn setup() -> eyre::Result<TestContext<Provider<Ws>, FlashbotsClient<Provi
U256::from(100000000000000000u64),
eth_client,
client,
true,
);

Ok(TestContext { bundler, _entry_point: ep_address, _anvil: anvil })
Expand Down
2 changes: 2 additions & 0 deletions crates/grpc/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub fn bundler_service_run<M, S>(
client: Arc<S>,
uopool_grpc_client: UoPoolClient<tonic::transport::Channel>,
enable_metrics: bool,
enable_access_list: bool,
) where
M: Middleware + Clone + 'static,
S: SendBundleOp + Clone + 'static,
Expand All @@ -190,6 +191,7 @@ pub fn bundler_service_run<M, S>(
min_balance,
eth_client.clone(),
client.clone(),
enable_access_list,
)
})
.collect();
Expand Down

0 comments on commit 146e432

Please sign in to comment.