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

fix: set from field when estimating gas #37

Merged
merged 1 commit into from
Oct 15, 2024
Merged
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
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