-
-
Notifications
You must be signed in to change notification settings - Fork 275
Comments
Conversation
49395d8 to
45eabcb
Compare
d5ee7ec to
dc11cf7
Compare
packages/transaction-pay-controller/src/strategy/relay/relay-max-gas-station.ts
Show resolved
Hide resolved
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.
relay-max-gas-station? Maybe the file also?
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.
Done
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.
Minor, some duplication with the existing relay-quotes, so probably worth some gas-station utils not specific to any pay strategy in future.
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.
Good call, addressed it by extracting shared Relay gas-station logic into gas-station-utils.ts and reusing it from both quote paths.
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.
To clarify, this shouldn't be possible with max amount since there would always be no balance left?
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.
This is a big duplication with the existing logic in relay-quotes, could we make some gas-station utils that are Relay specific for now within strategy/relay?
Maybe a getGasStationCost(quote) for example?
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.
I extracted the duplicated Relay gas-station logic into gas-station.ts and now reuse it in both relay-quotes and relay-max-gas-station.
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.
For greater readability, should we avoid these tiny utils that are only used once?
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.
Done
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 don't care about the new amount do we, as we calculated the old one to be exactly what is remaining of the balance, so do we want to use that to avoid dust?
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.
I think we shouldn't blindly trust the new amount, but we also avoid forcing the original estimate when quote internals shift slightly. This keeps max safety and minimizes dust risk without introducing a new submit API in this PR.
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.
isMaxGasStation?
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.
Done
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.
Should we force isSourceGasFeeToken here and also set the fees and amount for sourceNetwork using our original value from the probe quote?
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.
Is this needed since currently the user just gets an error so there is no risk to functionality?
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.
Removed it, as it fallbacks and shows error. It rarely happens but still shows error on re-quoting so I assume we are safe
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.
Potentially a separate PR, but are the gas fee tokens consistent in your testing?
Or should we also update relay-submit to specify a new gasFeeTokenAmount property to the TransactionController to avoid any dust?
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Uh oh!
There was an error while loading. Please reload this page.
Explanation
This PR introduces a dedicated max-amount gas-station fallback flow for Relay, extracted into a focused helper and wired into quote orchestration. The goal was fixing max-amount mUSD conversion failures caused by gas-fee-token estimation dead-ends but in fact it fixes for any kind of intent.
The helper (
getMaxAmountQuoteWithGasStationFallback) now implements a clear two-phase flow with explicit fallback points:maxGaslessEnabledisfalse.PROBE_AMOUNT_PERCENTAGE = 0.25) to discover gas fee token + amount.TransactionController:getGasFeeTokensandcalculateGasFeeTokenCostto normalize source-token gas fee amount.twoPhaseQuoteForMaxAmount = trueand return phase-2.References
gasless.max.mov
Checklist
Note
Medium Risk
Introduces new control flow for Relay max-amount quoting and changes how gas-fee-token costs are estimated/normalized, which can affect quote correctness and max-amount execution paths across supported chains.
Overview
Implements a dedicated max-amount "gas station" fallback for Relay quotes: when
isMaxAmountis set, the strategy now may request an initial quote, estimate gas cost in the source token (via quote values, Gas Station estimation, or a probe quote), then re-request an adjusted quote and validate affordability before returning it.Extracts Gas Station logic into a new
gas-stationhelper (eligibility + source-token gas cost with multi-item normalization and support for decimal/hex simulation fields) and wires it into existing post-quote/source-network fee calculation to reuse the same normalization behavior.Adds
metamask.isMaxGasStationto Relay quote types and adjusts Relay submission behavior to keep max-gas-station executions on the existinggasFeeToken-only path (nogasFeeTokenAmount), with extensive new unit test coverage and changelog entry.Written by Cursor Bugbot for commit 11d1a85. This will update automatically on new commits. Configure here.