Skip to content

fix(transaction-pay-controller, transaction-controller): support Predict same-chain withdraw on swap-only Relay routes#8735

Open
dan437 wants to merge 5 commits intomainfrom
predict-withdraw-from-override-swap-route
Open

fix(transaction-pay-controller, transaction-controller): support Predict same-chain withdraw on swap-only Relay routes#8735
dan437 wants to merge 5 commits intomainfrom
predict-withdraw-from-override-swap-route

Conversation

@dan437
Copy link
Copy Markdown
Contributor

@dan437 dan437 commented May 7, 2026

Explanation

Since the Polymarket pUSD migration on April 28 2026, Predict same-chain withdraws on Polygon (e.g. pUSD → USDC) sometimes fail with transaction gas limit too high (cap: 33554432, tx: 42121000).

Two interacting bugs:

  1. transaction-pay-controllercalculateSourceNetworkCost always uses fromOverride = Safe proxy for Predict withdraws. That works for deposit-style Relay routes but breaks for the swap-aggregator routes that same-chain destinations now use post-migration: DEX aggregators reject contract callers (anti-MEV msg.sender == tx.origin checks etc.), so the swap step reverts in simulation.
  2. transaction-controllerestimateGasBatch's 7702 path always calls estimateGas, even when every batch entry already has a gas value. The non-7702 path has had an allTransactionsHaveGas short-circuit since #7405; the 7702 path was missed. When TPC tries the EOA from, the swap sub-call reverts (EOA has no source token until the prepended Safe.execTransaction sub-call runs mid-batch), the whole 7702 batch falls back to ~block-gas-limit × buffer ≈ 42M, and Polygon's per-tx gascap rejects it.

Fix

  • TPC relay-quotes.ts: gate fromOverride = Safe proxy on the route having a deposit step. Same-chain swap routes use the relay params' EOA from instead. Gas-fee-token lookup keeps using the Safe proxy (gated on isPredictWithdraw && refundTo) so the gasless flow still works for users with 0 POL.
  • TPC constants.ts: add POLYGON_PUSD_ADDRESS and include it in STABLECOINS[Polygon] for correct stablecoin display.
  • TC gas.ts: mirror the existing non-7702 short-circuit in the 7702 branch — when every transaction has a provided gas, sum them and skip simulation.

Verified end-to-end on mobile (yalc-linked): Polygon pUSD → USDC withdraw produces a sane fee both with POL and gasless (paid in pUSD). BNB cross-chain unchanged.

References

N/A

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
Modifies gas estimation and Relay quote logic used during transaction preparation; incorrect from selection or fallback behavior could impact fee estimates or cause failed submissions for batched transactions.

Overview
Fixes Predict same-chain withdraws on swap-only Relay routes by gating the Safe-proxy fromOverride to routes that include a deposit step, while still using the Safe proxy for Predict gas-fee-token eligibility checks.

Updates TransactionController batch gas estimation by extracting getProvidedBatchGasLimits and using it both to short-circuit simulation in the non-7702 path and to fall back to summed per-tx gas when EIP-7702 node simulation fails (preserving requiresAuthorizationList when applicable).

Adds Polygon Polymarket pUSD support via POLYGON_PUSD_ADDRESS, includes it in STABLECOINS[Polygon], and adds targeted unit tests plus changelog entries for both packages.

Reviewed by Cursor Bugbot for commit c500b35. Bugbot is set up for automated code reviews on this repo. Configure here.

@dan437 dan437 requested review from a team as code owners May 7, 2026 13:22
@dan437 dan437 temporarily deployed to default-branch May 7, 2026 13:22 — with GitHub Actions Inactive
Comment thread packages/transaction-controller/src/utils/gas.ts
@dan437 dan437 force-pushed the predict-withdraw-from-override-swap-route branch from c6678db to 511a49e Compare May 8, 2026 08:49
dan437 added 4 commits May 8, 2026 13:30
…ess Predict same-chain withdraw on swap-only Relay routes

Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
…elper

Both branches of `estimateGasBatch` (EIP-7702 and non-7702) now share a
single helper that returns parsed limits + sum when every transaction
has a provided `gas`, or `undefined` otherwise.

Adds a focused `describe('getProvidedBatchGasLimits')` block covering:
- all transactions have gas
- none have gas
- mixed (some have gas)
- hex gas values
- empty batch (documents current behaviour)

No behavioural change.
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
@dan437 dan437 force-pushed the predict-withdraw-from-override-swap-route branch from 7ee6223 to 30749d8 Compare May 8, 2026 11:31
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
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.

2 participants