Skip to content

Commit b508485

Browse files
fix(fortuna): catch contract error in simulation (#2854)
1 parent 9805bbd commit b508485

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

apps/fortuna/src/eth_utils/utils.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use {
88
ethers::{
99
contract::{ContractCall, ContractError},
1010
middleware::Middleware,
11-
providers::ProviderError,
11+
providers::{MiddlewareError, ProviderError},
1212
signers::Signer,
1313
types::{
1414
transaction::eip2718::TypedTransaction, TransactionReceipt, TransactionRequest, U256,
@@ -253,7 +253,19 @@ pub async fn submit_tx<T: Middleware + NonceManaged + 'static>(
253253
client
254254
.fill_transaction(&mut transaction, None)
255255
.await
256-
.map_err(|e| backoff::Error::transient(SubmitTxError::GasPriceEstimateError(e)))?;
256+
.map_err(|e| {
257+
// If there is revert data, the contract reverted during gas usage estimation.
258+
if let Some(e) = e.as_error_response() {
259+
if let Some(e) = e.as_revert_data() {
260+
return backoff::Error::transient(SubmitTxError::GasUsageEstimateError(
261+
ContractError::Revert(e.clone()),
262+
));
263+
}
264+
}
265+
266+
// If there is no revert data, there was likely an error during gas price polling.
267+
backoff::Error::transient(SubmitTxError::GasPriceEstimateError(e))
268+
})?;
257269

258270
// Apply the fee escalation policy. Note: the unwrap_or_default should never default as we have a gas oracle
259271
// in the client that sets the gas price.

0 commit comments

Comments
 (0)