Skip to content

fix: Support gasless withdraw even with no gas fee tokens in EOA#8146

Merged
dan437 merged 15 commits intomainfrom
predict-balance-only
Mar 12, 2026
Merged

fix: Support gasless withdraw even with no gas fee tokens in EOA#8146
dan437 merged 15 commits intomainfrom
predict-balance-only

Conversation

@dan437
Copy link
Contributor

@dan437 dan437 commented Mar 9, 2026

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

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

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 refundTo proxy/Safe address for predictWithdraw transactions, including clearing Relay-provided gas fields when a from override 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 sourceTokenAmount reduced 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 isPredictWithdrawTransaction helper 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.

@dan437 dan437 requested a review from a team as a code owner March 9, 2026 12:59
dan437 added 3 commits March 9, 2026 14:05
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>
@dan437 dan437 requested a review from a team as a code owner March 9, 2026 13:11
dan437 added 7 commits March 10, 2026 10:07
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>
Copy link

@cursor cursor bot left a 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.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

dan437 added 2 commits March 11, 2026 16:59
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
fullRequest,
);

if (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
@dan437 dan437 added this pull request to the merge queue Mar 12, 2026
Merged via the queue into main with commit edcce33 Mar 12, 2026
322 checks passed
@dan437 dan437 deleted the predict-balance-only branch March 12, 2026 11:02
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.

[Bug]: Gasless withdraw doesn't work if a user doesn't have any gas fee token in EOA, only their Predict balance

2 participants