Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tkporter committed Nov 23, 2023
1 parent 01b26ce commit fb3ddf9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 51 deletions.
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-ethereum/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ where
metadata.to_vec().into(),
RawHyperlaneMessage::from(message).to_vec().into(),
);
fill_tx_gas_params(tx, tx_gas_limit, self.provider.clone(), message.destination).await
fill_tx_gas_params(tx, tx_gas_limit, self.provider.clone()).await
}
}

Expand Down
51 changes: 2 additions & 49 deletions rust/chains/hyperlane-ethereum/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ use std::time::Duration;

use ethers::{
abi::Detokenize,
middleware::gas_oracle::{GasCategory, GasOracle, Polygon},
prelude::{NameOrAddress, TransactionReceipt},
types::Eip1559TransactionRequest,
};
use ethers_contract::builders::ContractCall;
use ethers_core::types::BlockNumber;
use hyperlane_core::{
utils::fmt_bytes, ChainCommunicationError, ChainResult, KnownHyperlaneDomain, H256, U256,
};
use hyperlane_core::{utils::fmt_bytes, ChainCommunicationError, ChainResult, H256, U256};
use tracing::{error, info};

use crate::Middleware;
Expand Down Expand Up @@ -74,7 +71,6 @@ pub(crate) async fn fill_tx_gas_params<M, D>(
tx: ContractCall<M, D>,
tx_gas_limit: Option<U256>,
provider: Arc<M>,
domain: u32,
) -> ChainResult<ContractCall<M, D>>
where
M: Middleware + 'static,
Expand All @@ -88,7 +84,7 @@ where
.saturating_add(U256::from(GAS_ESTIMATE_BUFFER).into())
.into()
};
let Ok((max_fee, max_priority_fee)) = estimate_eip1559_fees(&provider, domain).await else {
let Ok((max_fee, max_priority_fee)) = provider.estimate_eip1559_fees(None).await else {
// Is not EIP 1559 chain
return Ok(tx.gas(gas_limit));
};
Expand Down Expand Up @@ -134,46 +130,3 @@ where
Ok(call)
}
}

/// Heavily borrowed from:
/// https://github.com/foundry-rs/foundry/blob/fdaed8603fc330cbc94c936f15594bccdc381225/crates/common/src/provider.rs#L254-L290
///
/// Estimates EIP1559 fees depending on the chain
///
/// Uses custom gas oracles for
/// - polygon
/// - mumbai
///
/// Fallback is the default [`Provider::estimate_eip1559_fees`] implementation
pub async fn estimate_eip1559_fees<M: Middleware>(
provider: &M,
domain: u32,
) -> ChainResult<(ethers::types::U256, ethers::types::U256)>
where
M::Error: 'static,
{
if let Ok(domain) = KnownHyperlaneDomain::try_from(domain) {
// handle chains that deviate from `eth_feeHistory` and have their own oracle
match domain {
KnownHyperlaneDomain::Polygon | KnownHyperlaneDomain::Mumbai => {
let chain = match domain {
KnownHyperlaneDomain::Polygon => ethers_core::types::Chain::Polygon,
KnownHyperlaneDomain::Mumbai => ethers_core::types::Chain::PolygonMumbai,
_ => unreachable!(),
};
let estimator = Polygon::new(chain)
.map_err(ChainCommunicationError::from_other)?
.category(GasCategory::Standard);
return estimator
.estimate_eip1559_fees()
.await
.map_err(ChainCommunicationError::from_other);
}
_ => {}
}
}
provider
.estimate_eip1559_fees(None)
.await
.map_err(ChainCommunicationError::from_other)
}
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-ethereum/src/validator_announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ where
announcement.value.storage_location,
serialized_signature.into(),
);
fill_tx_gas_params(tx, tx_gas_limit, self.provider.clone(), self.domain.id()).await
fill_tx_gas_params(tx, tx_gas_limit, self.provider.clone()).await
}
}

Expand Down

0 comments on commit fb3ddf9

Please sign in to comment.