Skip to content

fix(frontend): reload the native balance after every mined EVM transaction - #14001

Draft
AntonioVentilii wants to merge 2 commits into
mainfrom
av/eth-native-balance-after-mined-tx
Draft

fix(frontend): reload the native balance after every mined EVM transaction#14001
AntonioVentilii wants to merge 2 commits into
mainfrom
av/eth-native-balance-after-mined-tx

Conversation

@AntonioVentilii

Copy link
Copy Markdown
Collaborator

Motivation

A "send max" of ETH on Arbitrum was refused by the node with gas required exceeds allowance (17277), reported from staging. The signed transaction reserved 21507 * 0.2 gwei = 4,301,400,000,000 wei on top of the amount, while the account held 845,984,590,000 wei less than the wallet thought.

That figure is exactly the gas of the ARB transfer the same account had sent three minutes earlier. We reload the balance of the token a mined transaction moved, and only that one, so the ETH balance still carried gas that had already been spent. "Max" priced the send against it, and the amount plus the gas it reserves came out above the real balance. The chain refuses such a transaction outright rather than trimming it.

The retry a few minutes later, once the poll had caught up, spent the balance to the wei, which confirms the amount logic itself is right and the balance it was drawn from was not.

Every EVM operation pays its gas in the native coin, so the same window follows an ERC-20 transfer, an approval, a swap or an NFT send.

Changes

  • After a mined transaction, reload the balance of the network's native token alongside the balance of the token that moved.
  • Skip the second reload when the token that moved is the native one.

Tests

  • New eth-transaction.services.spec.ts: the native balance is reloaded after an ERC-20 transfer, it is not reloaded twice for a native send, and a native token of another network is left alone.
  • Each new test was checked against the unpatched code and fails there.
  • npm run format, npm run lint -- --max-warnings 0, npm run check, npm run check:tests and npm run test (1098 files, 18790 tests) all pass.

…ction

A mined transaction reloaded the balance of the token it moved, and only
that one. The gas, however, is paid in the network's native coin whatever
was sent, so an ERC-20 transfer leaves that balance overstated too, and
nothing corrected it until the next 30 second balance poll.

In that window "Max" prices a native send against a balance that still
holds gas the account has already spent. The amount plus the gas it
reserves then exceeds what the account has, and the node refuses the
transaction with "gas required exceeds allowance" instead of trimming it.
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.

1 participant