Skip to content

Conversation

@bakoushin
Copy link
Contributor

@bakoushin bakoushin commented May 6, 2025

Description

Currently, when we try to estimate gas as a part of fee currency selection, and run into an error we don’t recognize, we throw it to the user. We rely on a hand-picked list of “known” errors, and anything else gets thrown.

This approach is hurting users — they can’t complete swaps in certain edge cases we didn’t think of.
Context: https://valora-app.slack.com/archives/C04B61SJ6DS/p1746461883367569
In this case, an RpcRequestError with details ”execution reverted” was thrown, but the root cause was the insufficient amount of that particular fee currency on the user balance.

This PR proposes to silently handle any estimation error instead of cherry-picked ones. It seems that re-throwing during estimation does not bring any value to the user, just the contrary. Since we are calling the estimation while looping over all possible fee currencies, it seems fine to just skip a particular currency if we encounter any error, and move on, enabling users to complete their intended task.

Test plan

  • Tested manually
  • Updated unit test

Related issues

NA

Backwards compatibility

Y

Network scalability

Y

Comment on lines -181 to -187
e instanceof EstimateGasExecutionError &&
(e.cause instanceof InsufficientFundsError ||
(e.cause instanceof ExecutionRevertedError && // viem does not reliably label node errors as InsufficientFundsError when the user has enough to pay for the transfer, but not for the transfer + gas
(/transfer value exceeded balance of sender/.test(e.cause.details) ||
/transfer amount exceeds balance/.test(e.cause.details))) ||
(e.cause instanceof InvalidInputRpcError &&
/gas required exceeds allowance/.test(e.cause.details)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the change is to get rid of this guessing

Copy link
Contributor

@sviderock sviderock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Great proposal IMO!
Approved considering that you definitely know the flow better than me and acknowledging that removal of throw won't affect anything else. Feel free to ignore my approval otherwise 😄

Copy link
Member

@jeanregisser jeanregisser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have been thinking about this too lately, related to another bug:
https://github.com/jeanregisser/celo-fee-currency-estimate-gas-bug

Anyway, one downside is we won't be able to surface revert reason to the user while estimating:
valora-xyz/wallet#4864

But I guess we don't have much choice if the error is [EstimateGasExecutionError: Execution reverted for an unknown reason. 🤔

@bakoushin
Copy link
Contributor Author

ok, it seems the root cause is the celo error.
once it's fixed, we probably don't need this change.
so i hold off on merging it for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants