Skip to content

feat: cp-7.78.0 support deposit-wallet polymarket withdraw#29953

Merged
matthewwalsh0 merged 20 commits into
mainfrom
feat/polymarket-bridge-withdraw-adopt
May 15, 2026
Merged

feat: cp-7.78.0 support deposit-wallet polymarket withdraw#29953
matthewwalsh0 merged 20 commits into
mainfrom
feat/polymarket-bridge-withdraw-adopt

Conversation

@matthewwalsh0
Copy link
Copy Markdown
Member

@matthewwalsh0 matthewwalsh0 commented May 11, 2026

Description

Adopts the new Polymarket deposit-wallet support landed in @metamask/transaction-pay-controller@22.5.0 so Polymarket users whose pUSD lives in a deposit wallet (a per-user batch contract on Polygon) can withdraw cross-chain through MetaMask Pay.

Highlights:

  • Lets Polymarket deposit-wallet users withdraw cross-chain through MetaMask Pay.
  • Gated behind a new remote feature flag, with the existing "withdraw unavailable" sheet preserved when off.
  • Polishes Predict withdraw activity rendering.

Changelog

CHANGELOG entry: null

Related issues

Manual testing steps

Feature: Polymarket deposit-wallet withdraw

  Scenario: deposit-wallet user with the flag on
    Given enableDepositWalletWithdraw is on
    And the user has a Polymarket deposit wallet with pUSD balance on Polygon
    When the user taps Withdraw on the Predict balance
    Then the standard Pay confirmation opens
    And confirming submits via the Polymarket strategy with no Polygon gas

  Scenario: deposit-wallet user with the flag off
    Given enableDepositWalletWithdraw is off
    When the user taps Withdraw on the Predict balance
    Then the existing "Withdraw unavailable" sheet is shown

Screenshots/Recordings

Before

After

Activity

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
  • I've tested with a power user scenario
  • I've instrumented key operations with Sentry traces for production performance metrics

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Changes withdrawal behavior and MetaMask Pay transaction configuration for Polymarket predictWithdraw, including new controller callbacks and retry logic; mistakes could impact withdraw routing/fees for affected users. Gated by a remote feature flag, limiting blast radius.

Overview
Enables Polymarket deposit-wallet users to run predictWithdraw through MetaMask Pay when the new confirmations_pay_extended.enableDepositWalletWithdraw flag is on; when off, the existing “withdraw unavailable” handling remains.

Updates Predict/Pay plumbing for deposit-wallet withdraws: PredictController.prepareWithdraw now omits gasFeeToken for deposit-wallet accounts, useTransactionPayPostQuote skips refundTo and marks isPolymarketDepositWallet, and Transaction Pay initialization wires new Polymarket callbacks that can derive deposit-wallet addresses and submit deposit-wallet batches (with “wallet busy” retries + keyring signing support).

Polishes confirmations activity rendering for predictWithdraw by adding a dedicated predict_withdraw title and treating it as a receive-summary type using the source token/network metadata. Tests are added/updated accordingly, and @metamask/transaction-pay-controller is bumped to 22.5.0.

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

@matthewwalsh0 matthewwalsh0 force-pushed the feat/polymarket-bridge-withdraw-adopt branch from 4a62ff7 to 7b3c92f Compare May 11, 2026 09:12
@matthewwalsh0 matthewwalsh0 changed the title feat(predict): adopt Polymarket deposit-wallet withdraw feat(predict): route deposit-wallet withdraws through PolymarketBridgeStrategy May 11, 2026
@matthewwalsh0 matthewwalsh0 force-pushed the feat/polymarket-bridge-withdraw-adopt branch from 0c8771c to ff34c51 Compare May 14, 2026 13:58
@github-actions github-actions Bot added size-L and removed size-M labels May 14, 2026
@matthewwalsh0 matthewwalsh0 added the team-predict Predict team label May 14, 2026
@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 14, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​metamask/​transaction-pay-controller@​22.4.0 ⏵ 22.5.09710081 +198 +1100

View full report

@matthewwalsh0 matthewwalsh0 added team-confirmations Push issues to confirmations team and removed team-predict Predict team labels May 14, 2026
@matthewwalsh0 matthewwalsh0 changed the title feat(predict): route deposit-wallet withdraws through PolymarketBridgeStrategy feat: support deposit-wallet polymarket withdraw May 14, 2026
…eStrategy

When a Predict withdraw originates from a Polymarket deposit wallet,
flag the post-quote transaction with isPolymarketDepositWallet so that
@metamask/transaction-pay-controller routes it to PolymarketBridgeStrategy.

The deposit-wallet check resolves async via PredictController:getAccountState
and runs as a follow-up update so the initial post-quote config setup
stays synchronous.
Deposit-wallet withdraws are gas-sponsored by the Polymarket bridge
relayer via TransactionPayPublishHook → PolymarketBridgeStrategy. The
TransactionController gas-fee-token validation should not gate publish
for these transactions, otherwise the 7702 batch path throws
'Gas fee token not found and insufficient native balance' because the
simulation does not list pUSD as a supported gas-paying token.

Branch on walletType === 'deposit-wallet' from PolymarketProvider's
account state and omit gasFeeToken from the addTransactionBatch request
for deposit-wallet users. Safe-wallet withdraws keep the existing
gasFeeToken: MATIC_CONTRACTS_V2.collateral path.
- Add predictWithdraw to SUMMARY_SECTION_TYPES so the activity row
  renders the bridge-style summary block.
- ReceiveSummaryLine: for predictWithdraw, show the destination token
  (sourceTokenAddress on the source chain) instead of mUSD.
- SourceHashSummaryLine: for predictWithdraw, render the new
  predict_withdraw string ("Withdraw pUSD from Polygon") since the
  source leg always burns pUSD on Polygon.
- transactionController dedupe: drop the actionId-based dedupe key.
  predictWithdraw produces multiple local transactions per actionId
  (deposit-wallet batch + the original wrapper) and they were getting
  incorrectly collapsed.
- Locale: add transaction_details.summary_title.predict_withdraw.
- PredictController: comment update PolymarketBridgeStrategy ->
  PolymarketStrategy to reflect the core rename.
…ontroller

TransactionPayController now accepts a polymarket option holding two
callbacks (getDepositWalletAddress, submitDepositWalletBatch) that the
controller invokes for the predictWithdraw flow. The Polymarket relayer
protocol (signing, transport, polling, busy retry) stays mobile-side
and is supplied at controller construction.

- polymarket-callbacks.ts: builds the PolymarketCallbacks bag by
  wrapping the existing depositWallet.ts helpers (deriveDepositWalletAddress,
  executeDepositWalletBatch, waitForDepositWalletTransaction). Owns the
  wallet-busy retry loop so all controller-driven batches retry on the
  relayer's transient 'wallet action in progress' rejections.
- transaction-pay-controller-init.ts: passes the callbacks at
  TransactionPayController construction.
- transaction-pay-controller-messenger: delegates
  KeyringController:signTypedMessage and KeyringController:signPersonalMessage
  to the init messenger so the callback's inline Signer can call them.

The existing PolymarketProvider.ts uses of executeDepositWalletBatch
(deposit and claim flows) are unchanged.
…onController init messenger

The publish hook running inside TransactionController calls the
TransactionPayController:polymarketGetDepositWalletAddress and
TransactionPayController:polymarketSubmitDepositWalletBatch actions via
its messenger, so the TransactionController init messenger has to
delegate them through alongside the existing
getDelegationTransaction/getState/getStrategy actions.

Also refactor polymarket-callbacks.ts:
- Use executeDepositWalletBatchAndWaitForCompletion so the callback
  waits for the relayer's terminal STATE_MINED/STATE_CONFIRMED before
  returning the sourceHash. This means by the time Relay polling starts
  in core, the source tx is already on-chain, and any
  STATE_FAILED/STATE_INVALID is caught before Relay sees it.
- Split each callback into a named private function for readability.
- Extract createSigner as a private helper instead of inlining.
The relayer returns errors like:

  Polymarket relayer proxy request failed: 400 {"error":"wallet busy: active action exists"}

The previous marker `wallet action` does not appear in that string, so
`isWalletBusyError` returned false and the call rejected on the first
attempt instead of retrying. Match the actual `wallet busy` substring
the relayer emits so the existing 5-attempt / 3s retry loop kicks in.

Also collapse the duplicate `@metamask/keyring-controller` imports into
a single statement to satisfy `no-duplicate-imports` in pre-commit
lint-staged.
@matthewwalsh0 matthewwalsh0 force-pushed the feat/polymarket-bridge-withdraw-adopt branch from e60e82c to d9d0d29 Compare May 14, 2026 22:38
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeSwap, SmokeStake, SmokeWalletPlatform, SmokeMoney, SmokePerps, SmokeMultiChainAPI, SmokePredictions, SmokeSeedlessOnboarding, SmokeBrowser, SmokeSnaps
  • Selected Performance tags: @PerformanceAccountList, @PerformanceOnboarding, @PerformanceLogin, @PerformanceSwaps, @PerformanceLaunch, @PerformanceAssetLoading, @PerformancePredict, @PerformancePreps
  • Risk Level: high
  • AI Confidence: 100%
click to see 🤖 AI reasoning details

E2E Test Selection:
Hard rule (controller-version-update): @MetaMask controller package version updated in package.json: @metamask/transaction-pay-controller. Running all tests.

Performance Test Selection:
Hard rule (controller-version-update): @MetaMask controller package version updated in package.json: @metamask/transaction-pay-controller. Running all tests.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@matthewwalsh0 matthewwalsh0 marked this pull request as ready for review May 15, 2026 09:34
@matthewwalsh0 matthewwalsh0 requested review from a team as code owners May 15, 2026 09:34
@matthewwalsh0 matthewwalsh0 changed the title feat: support deposit-wallet polymarket withdraw feat: cp-7.78.0 support deposit-wallet polymarket withdraw May 15, 2026
Copy link
Copy Markdown
Contributor

@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.

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 054697c. Configure here.

@matthewwalsh0 matthewwalsh0 added this pull request to the merge queue May 15, 2026
Merged via the queue into main with commit 4997055 May 15, 2026
134 of 135 checks passed
@matthewwalsh0 matthewwalsh0 deleted the feat/polymarket-bridge-withdraw-adopt branch May 15, 2026 13:42
@github-actions github-actions Bot locked and limited conversation to collaborators May 15, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.79.0 Issue or pull request that will be included in release 7.79.0 label May 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.79.0 Issue or pull request that will be included in release 7.79.0 size-L team-confirmations Push issues to confirmations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants