Skip to content

Commit

Permalink
fix(sends): Fix error checking when estimating gas (#4738)
Browse files Browse the repository at this point in the history
### Description

Currently, the error strings we check for when estimating gas are not
sufficient to catch all types of errors we care about. Basically, what
was happening was when a user tries to send MAX balance of some
gas-payable asset A, we try to prepare the transaction using asset A
(and other gas-payable assets) as gas, and estimation fails when using
asset A as gas since gas + transfer amount exceeds balance. This error
during estimation wasn't being caught by the `cause` strings we were
looking at. This caused gas estimation to hang forever, preventing the
user from continuing with the transfer. This PR adds in a new cause
string to fix that.

In general, it appears as if this cause string is determined _by the
blockchain_ itself, i.e., not by `viem`, and therefore may be liable to
change in the wild. This is a temporary fix, but it may be worth
revisiting this if it crops up again, and making the errors we check for
configurable remotely.

### Test plan

Manual tested.

### Related issues

- Fixes ACT-1045

### Backwards compatibility

<!-- Brief explanation of why these changes are/are not backwards
compatible. -->

Co-authored-by: Tom McGuire <Mcgtom10@gmail.com>
Co-authored-by: Jacob Waterman <jacobrwaterman@gmail.com>
  • Loading branch information
3 people authored Jan 11, 2024
1 parent f63d27b commit 72478b6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/viem/prepareTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export async function tryEstimateTransaction({
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 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)))
) {
Expand Down

0 comments on commit 72478b6

Please sign in to comment.