From 811f87443605fc181ed00fb2099ef361d4444447 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 15 Oct 2024 06:24:32 +0200 Subject: [PATCH] fix: set from field when estimating gas (#37) In some cases `tx.origin` might be checked, so we should set `from` in the request, otherwise these calls revert --- crates/wallet/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/wallet/src/lib.rs b/crates/wallet/src/lib.rs index 32a82a2..47d431f 100644 --- a/crates/wallet/src/lib.rs +++ b/crates/wallet/src/lib.rs @@ -272,17 +272,20 @@ where request.chain_id = Some(self.chain_id()); // set gas limit + // note: we also set the `from` field here to correctly estimate for contracts that use e.g. + // `tx.origin` + request.from = Some(NetworkWallet::::default_signer_address(&self.inner.wallet)); let (estimate, base_fee) = tokio::join!( EthCall::estimate_gas_at(&self.inner.eth_api, request.clone(), BlockId::latest(), None), LoadFee::eip1559_fees(&self.inner.eth_api, None, None) ); - let estimate = estimate.map_err(Into::into)?; if estimate >= U256::from(350_000) { return Err(OdysseyWalletError::GasEstimateTooHigh { estimate: estimate.to() }.into()); } request.gas = Some(estimate.to()); + // set gas price let (base_fee, _) = base_fee.map_err(|_| OdysseyWalletError::InvalidTransactionRequest)?; let max_priority_fee_per_gas = 1_000_000_000; // 1 gwei request.max_fee_per_gas = Some(base_fee.to::() + max_priority_fee_per_gas);