fix: Support gasless withdraw even with no gas fee tokens in EOA#8146
fix: Support gasless withdraw even with no gas fee tokens in EOA#8146
Conversation
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
…balance-only Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
| fullRequest, | ||
| ); | ||
|
|
||
| if ( |
There was a problem hiding this comment.
To clarify, won't it always be the inverse in this scenario?
We don't have gas station to begin with, then we get it after we fix the quote?
Should we early return to skip all this if the user can already do gas station using token balance from their EOA?
There was a problem hiding this comment.
Currently both phase1Quote.fees.isSourceGasFeeToken and phase2Quote.fees.isSourceGasFeeToken are true. Maybe I should ensure the first one is false?
We can use an existing gas fee token in EOA instead of taking it from Predict balance, I will make that change.
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
packages/transaction-pay-controller/src/strategy/relay/relay-quotes.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Explanation
When a user has no native POL and no USDC.e in their EOA (tokens are in a Predict Safe), gasless withdrawals to non-USDC.e tokens fail with
FAILED_INSUFFICIENT_FUNDS. The gas station simulation returns no fee tokens because the EOA balance is zero at quote time.This PR skips the simulation for post-quote flows and builds a synthetic gas fee token by taking the estimated gas cost in USD (from
calculateGasCost), applying a 10% buffer, and converting to USDC.e via its USD exchange rate. It also implements two-phase quoting: the first quote determines the gas cost, then a second quote is fetched with the source amount reduced by that cost. Source balance validation is skipped for post-quote flows since tokens move from Safe to EOA during batch execution.References
Checklist
Note
Medium Risk
Changes Relay quote/submit behavior for post-quote withdrawals, including gas estimation and quote amount adjustments, which can affect final amounts and transaction batching. Risk is mitigated by extensive new tests and fallbacks, but it touches fee computation and submission logic.
Overview
Fixes gasless post-quote withdraw flows (e.g. Predict Withdraw) when the EOA has no balance by estimating and simulating gas using the
refundToproxy/Safe address forpredictWithdrawtransactions, including clearing Relay-providedgasfields when afromoverride is used.Adds two-phase Relay quoting for post-quote flows: fetch a phase-1 quote to compute gas fee token cost, then re-fetch a phase-2 quote with
sourceTokenAmountreduced by that cost, with fallbacks to phase 1 if the adjusted amount is non-positive, phase-2 fetch fails, or phase 2 loses gas-fee-token eligibility.Updates Relay submit to skip source balance validation for post-quote flows (since funds become available after the original tx in the batch) and adds extra submission logging; includes a new
isPredictWithdrawTransactionhelper with tests, plus expanded Relay quote/submit test coverage and a changelog entry.Written by Cursor Bugbot for commit a20982a. This will update automatically on new commits. Configure here.