fix(frontend): reload the native balance after every mined EVM transaction - #14001
Draft
AntonioVentilii wants to merge 2 commits into
Draft
fix(frontend): reload the native balance after every mined EVM transaction#14001AntonioVentilii wants to merge 2 commits into
AntonioVentilii wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 reserved21507 * 0.2 gwei = 4,301,400,000,000wei on top of the amount, while the account held845,984,590,000wei 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
Tests
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.npm run format,npm run lint -- --max-warnings 0,npm run check,npm run check:testsandnpm run test(1098 files, 18790 tests) all pass.