Skip to content

feat(transaction-pay-controller): support Predict withdraw in the server strategy - #10702

Open
matthewwalsh0 wants to merge 9 commits into
mainfrom
feat/server-predict-withdraw
Open

matthewwalsh0 wants to merge 9 commits into
mainfrom
feat/server-predict-withdraw

Conversation

@matthewwalsh0

@matthewwalsh0 matthewwalsh0 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Explanation

The server strategy declined Predict withdraws, so they could only be quoted and submitted through the Relay strategy.

  • The server strategy now supports each Predict withdraw variant:
    • Safe: quotes honour refundTo, and gas estimation and gas fee token lookups use the Safe that holds the source token.
    • Polymarket deposit wallet: quotes are requested from the deposit wallet in USDC.e with useDepositAddress. On submit, the Polymarket relayer unwraps pUSD directly to the provider deposit address, then any leftover or refunded USDC.e is swept back to the deposit wallet. No source network fee is charged, as the relayer pays origin gas.
    • Payment overrides (e.g. withdrawing to a Money Account): non-atomic quotes settle on the override recipient, and the override calls run as a second leg.
  • Post-quote quotes include the original transaction in gas estimation and reserve the gas fee token cost from the source amount.
  • Server quote requests accept useDepositAddress. The deposit step is identified as a plain ERC-20 transfer with no extra calldata or native value, and deposit-address quotes without one are ignored.

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

High Risk
Changes core server quote/submit orchestration for withdraws, refunds, multi-leg settlement, and Polymarket relayer paths where incorrect gas, recipient, or sweep timing could mis-route funds or double-execute calls.

Overview
Server strategy now handles Predict withdraw instead of leaving those flows to Relay. Quoting and submission paths were extended for Safe, Polymarket deposit wallet, and non-atomic payment overrides.

Safe / legacy Predict withdraw: post-quote requests pass refundTo to the server; source gas uses estimateSourceGas (including the original tx), with deposit routes estimated from the Safe and fee-token lookups on the Safe account.

Polymarket deposit wallet: quotes use useDepositAddress, USDC.e from the deposit wallet as sender/refund, and no gasless flag; only quotes with a plain ERC-20 transfer deposit step are kept (deposit-step.ts). Submit replaces quote steps with submitPolymarketWithdraw to the deposit address, zeros user origin fees, sweeps leftover/refunded USDC.e after polling, and PolymarketDepositWallet is removed from server unsupported reasons.

Non-atomic overrides (e.g. Money Account): settlement recipient comes from the override; requiresSecondLeg is true; override calls are not embedded in the quote batch but built in the second leg via getCalls. Post-quote flows can re-quote the same provider to reserve gas paid in the source token.

Submit also assigns leading gas limits to prepended post-quote txs, skips prepending override calls when atomic === false, and returns terminal intent status from polling so deposit-wallet sweep can run before failures are surfaced.

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

@matthewwalsh0
matthewwalsh0 force-pushed the feat/transaction-pay-non-atomic-second-leg branch 2 times, most recently from 5429248 to fd5bbe3 Compare October 11, 2026 12:33
Base automatically changed from feat/transaction-pay-non-atomic-second-leg to main October 12, 2026 12:49
@matthewwalsh0
matthewwalsh0 force-pushed the feat/server-predict-withdraw branch from be6b5f1 to 328268a Compare October 12, 2026 14:05
@matthewwalsh0
matthewwalsh0 force-pushed the feat/server-predict-withdraw branch from 74d3df6 to f4c739d Compare October 13, 2026 08:54
@matthewwalsh0
matthewwalsh0 changed the base branch from main to refactor/transaction-pay-polymarket-utils October 13, 2026 08:54
@matthewwalsh0
matthewwalsh0 force-pushed the feat/server-predict-withdraw branch from f4c739d to 66d1986 Compare October 13, 2026 09:02
@matthewwalsh0
matthewwalsh0 force-pushed the feat/server-predict-withdraw branch from 66d1986 to 021f983 Compare October 13, 2026 11:47
@matthewwalsh0
matthewwalsh0 changed the base branch from refactor/transaction-pay-polymarket-utils to refactor/transaction-pay-post-quote October 13, 2026 11:47
@matthewwalsh0
matthewwalsh0 force-pushed the refactor/transaction-pay-post-quote branch from f35a6de to ea9634a Compare October 14, 2026 13:29
@matthewwalsh0
matthewwalsh0 force-pushed the feat/server-predict-withdraw branch 2 times, most recently from d5c0f89 to adcc810 Compare October 14, 2026 13:42
@matthewwalsh0
matthewwalsh0 force-pushed the refactor/transaction-pay-post-quote branch from 3ed4f55 to f5b1abf Compare October 14, 2026 13:49
@matthewwalsh0
matthewwalsh0 force-pushed the feat/server-predict-withdraw branch from adcc810 to 8e4b9bc Compare October 14, 2026 13:52
Naz-Ovh pushed a commit to 0x-fork/metamask-core that referenced this pull request Oct 15, 2026
…lpers from the Relay strategy (MetaMask#10799)

## Explanation

The Polymarket withdraw helpers live under the Relay strategy and take
Relay quotes and statuses, but the server strategy also needs them to
support Predict withdraws. This is a refactor with no change in
behaviour.

- Moves `strategy/relay/polymarket/` to `utils/polymarket/`.
- The helpers no longer depend on Relay types:
- Withdraw, simulation and sweep helpers take the deposit step calldata,
source amount and a refund flag instead of a Relay quote or status.
- `getPolymarketDepositWalletOverrides` returns the deposit wallet and
source token, and the Relay strategy applies them to its request body.
- The Safe address lookup takes a deposit-step flag, and the gas fee
token account lookup has its own helper.
- Relay deposit step lookups move to `strategy/relay/deposit-step.ts`.

## References

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] 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](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Refactor with updated tests and call-site wiring; no intentional
behavior change to payment or withdraw flows.
> 
> **Overview**
> **Decouples Polymarket Predict withdraw logic from Relay-specific
types** so the same helpers can be reused outside the Relay strategy
(e.g. server strategy work in MetaMask#10702). Behavior is intended to stay the
same.
> 
> Polymarket code moves from `strategy/relay/polymarket/` to
`utils/polymarket/`. Withdraw, simulation, and sweep APIs now take plain
inputs—deposit-step calldata, source amount, and an `isRefund`
flag—instead of `RelayQuote` or Relay status strings. Quote-time
deposit-wallet wiring is split: `getPolymarketDepositWalletOverrides`
returns the wallet and USDC.e source token while `relay-quotes` mutates
the Relay request body. Predict withdraw gas behavior is unchanged but
callers pass a **deposit-step flag** into
`getPredictWithdrawSafeAddress` and use new
`getPredictWithdrawFeeTokenAccount` for fee-token lookup.
> 
> Relay-only deposit-step detection is centralized in new
`deposit-step.ts` (`hasRelayDepositStep`, `getRelayDepositData`), with
unit tests; Relay submit/validation pull deposit calldata through those
helpers before calling Polymarket utils.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
a3a798b. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Base automatically changed from refactor/transaction-pay-post-quote to main October 16, 2026 05:27
@matthewwalsh0
matthewwalsh0 force-pushed the feat/server-predict-withdraw branch from 8e4b9bc to e27abb2 Compare October 16, 2026 05:40
@matthewwalsh0
matthewwalsh0 marked this pull request as ready for review October 17, 2026 00:20
@matthewwalsh0
matthewwalsh0 requested review from a team as code owners October 17, 2026 00:20
@matthewwalsh0
matthewwalsh0 deployed to default-branch October 17, 2026 00:20 — with GitHub Actions Active

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 using default effort and found 2 potential issues.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit e27abb2. Configure here.

This branch was successfully deployed

1 active deployment
default-branch — e27abb2c Deployed Oct 17, 2026 by matthewwalsh0 via Determine whether this PR is a release PR #5620
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant