-
-
Notifications
You must be signed in to change notification settings - Fork 267
Fix/balance change calculation gas sponsored #7608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| return getSimulationBalanceChange( | ||
| previousBalance, | ||
| newBalance, | ||
| transactionResponse.gasCost, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not want to keep the gas cost in for non-sponsored here?
| getSimulationConfig, | ||
| transactions, | ||
| withGas: true, | ||
| withGas: !request.isGasFeeSponsored, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We specify gas here to ensure a more accurate simulation that can't be as easily detected.
Why exactly would we not want that if sponsored if we mock the native balance below if insufficient?
| offset: BN = new BN(0), | ||
| ): SimulationBalanceChange | undefined { | ||
| const newBalanceBN = hexToBN(newBalance).add(new BN(offset)); | ||
| const newBalanceBN = hexToBN(newBalance).add(offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of this offset is to remove any gas costs from the native balance change.
Do we know why this calculation isn't working if sponsored?
Is that the root of the issue rather than the withGas option?
Is the gasCost property still correct?
Explanation
This PR fixes a UX issue where, in fully sponsored transactions involving the native token, the displayed balance change incorrectly included gas fees that were not actually paid by the user.
References
For testing and validation, please refer to this hotfix PR, which includes the same changes applied as a patch:
MetaMask/metamask-extension#39219
Checklist
Note
Ensures native balance changes are accurate for gas‑sponsored transactions by excluding gas costs during simulation.
gasFeeTokensbefore simulation and determineisGasFeeSponsoredinTransactionControllerisGasFeeSponsoredtogetBalanceChangesand setsimulateTransactionswithGastofalsewhen sponsoredgetSimulationBalanceChangeto use state diffs directly (remove gas offset) and switchoffsettoBNisGasFeeSponsoredplumbed through and correct balance diffs; add expectations forwithGasbehaviorCHANGELOG.mdentry under UnreleasedWritten by Cursor Bugbot for commit d5234ea. This will update automatically on new commits. Configure here.