Skip to content

Commit

Permalink
fix: set from field when estimating gas (#37)
Browse files Browse the repository at this point in the history
In some cases `tx.origin` might be checked, so we should set `from` in
the request, otherwise these calls revert
  • Loading branch information
onbjerg authored Oct 15, 2024
1 parent aff5101 commit 811f874
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Ethereum>::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::<u128>() + max_priority_fee_per_gas);
Expand Down

0 comments on commit 811f874

Please sign in to comment.