chore(runway): cherry-pick feat(predict): add deposit wallet deposit foundation#30085
Merged
Merged
Conversation
…foundation (#29917) ## **Description** This is PR 2 for the Predict Deposit Wallet migration and is temporarily opened against `predict/dw-confirmation-hooks` to accelerate review while PR 1 is reviewed. Once PR 1 merges, this PR should be rebased/retargeted to `main`. Polymarket migrated new API users from the legacy Safe/proxy wallet model to deterministic Deposit Wallets. This PR adds the shared Predict Deposit Wallet foundation and enables the deposit flow while preserving legacy Safe behavior for users with existing Polymarket activity. Included changes: - Adds `walletType` to Predict account state and routes users by legacy Safe activity: - legacy Safe with raw Polymarket activity stays on Safe - legacy Safe without activity routes to Deposit Wallet - deployed legacy Safe + Activity API failure fails closed - Adds Deposit Wallet helper utilities for deterministic address derivation, relayer proxy calls, polling, EIP-712 batch execution, and CLOB balance-allowance sync. - Adds Deposit Wallet deposit preflight to deploy/setup allowances in `beforePublish`. - Adds legacy Safe migration sweep planning for zero-activity users with stranded pUSD/USDC.e. - Updates deposit preparation so Deposit Wallet users receive pUSD transfers to their Deposit Wallet. - Updates balance/position lookup to use the active Predict wallet. - Adds post-confirm best-effort CLOB balance-allowance sync for Deposit Wallet deposits and deposit-and-order deposits. - Keeps order and claim execution support out of scope for this PR; those follow in separate PRs. Validation performed: - `yarn jest app/components/UI/Predict/providers/polymarket/depositWallet.test.ts app/components/UI/Predict/providers/polymarket/preflight/legacySafeMigration.test.ts app/components/UI/Predict/providers/polymarket/preflight/depositWallet.test.ts app/components/UI/Predict/providers/polymarket/preflight/v2AllowanceRequirements.test.ts app/components/UI/Predict/providers/polymarket/PolymarketProvider.test.ts app/components/UI/Predict/controllers/PredictController.test.ts app/components/UI/Predict/hooks/usePredictAccountState.test.ts --runInBand --forceExit` - `yarn lint:tsc` ## **Changelog** CHANGELOG entry: Added support for Polymarket Deposit Wallet deposits in Predict ## **Related issues** Fixes: [PRED-858](https://consensyssoftware.atlassian.net/browse/PRED-858) ## **Manual testing steps** ```gherkin Feature: Predict Deposit Wallet deposits Scenario: new Predict user deposits to a Polymarket Deposit Wallet Given the selected wallet has no legacy Safe Polymarket activity And the user opens Predict deposit When user confirms a Predict deposit Then the Deposit Wallet setup preflight runs through the relayer And the pUSD deposit transaction transfers funds to the derived Deposit Wallet And the deposit completes without changing legacy Safe users' behavior ``` ```gherkin Feature: Legacy Safe compatibility Scenario: existing Predict user with legacy Safe activity deposits Given the selected wallet has a deployed legacy Safe with Polymarket activity When user prepares a Predict deposit Then Predict keeps using the legacy Safe path And no Deposit Wallet relayer preflight is run ``` ## **Screenshots/Recordings** N/A — core/provider flow changes covered by tests and manual wallet-flow validation. ### **Before** N/A ### **After** N/A ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. #### Performance checks (if applicable) - [ ] I've tested on Android - Ideally on a mid-range device; emulator is acceptable - [ ] I've tested with a power user scenario - Use these [power-user SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93) to import wallets with many accounts and tokens - [ ] I've instrumented key operations with Sentry traces for production performance metrics - See [`trace()`](/app/util/trace.ts) for usage and [`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274) for an example For performance guidelines and tooling, see the [Performance Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers). ## **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. [PRED-858]: https://consensyssoftware.atlassian.net/browse/PRED-858?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **High Risk** > High risk because it changes how Predict chooses deposit addresses and adds new pre-publish relayer/batch execution plus post-confirm sync, which directly affects deposit and deposit+order transaction flows and fund routing. > > **Overview** > Adds first-class support for Polymarket **Deposit Wallet** accounts in Predict by extending `AccountState` with `walletType` and routing users to either legacy Safe or a deterministic deposit wallet based on legacy Safe deployment and Polymarket Activity API results (failing closed on API errors). > > Implements deposit-wallet infrastructure in the Polymarket provider: deterministic address derivation, relayer proxy calls/polling, EIP-712 batch execution, allowance-preflight planning (excluding Permit2), and a legacy Safe “sweep” preflight to migrate stranded USDC.e/pUSD to the deposit wallet. > > Updates the deposit pipeline to (1) build deposits targeting the deposit wallet (with optional sweep), (2) run a new `beforePublish` deposit-wallet preflight to ensure wallet deployment and required allowances, and (3) on confirmed deposits/deposit+order, invalidate cached account state and best-effort sync CLOB balance/allowance—waiting for that sync before placing the follow-on order. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c5f61e2. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Contributor
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - PR targets a release branch (release/*) All E2E tests pre-selected. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
This is PR 2 for the Predict Deposit Wallet migration and is temporarily
opened against
predict/dw-confirmation-hooksto accelerate reviewwhile PR 1 is reviewed. Once PR 1 merges, this PR should be
rebased/retargeted to
main.Polymarket migrated new API users from the legacy Safe/proxy wallet
model to deterministic Deposit Wallets. This PR adds the shared Predict
Deposit Wallet foundation and enables the deposit flow while preserving
legacy Safe behavior for users with existing Polymarket activity.
Included changes:
walletTypeto Predict account state and routes users by legacySafe activity:
derivation, relayer proxy calls, polling, EIP-712 batch execution, and
CLOB balance-allowance sync.
beforePublish.stranded pUSD/USDC.e.
transfers to their Deposit Wallet.
Wallet deposits and deposit-and-order deposits.
those follow in separate PRs.
Validation performed:
yarn jest app/components/UI/Predict/providers/polymarket/depositWallet.test.ts app/components/UI/Predict/providers/polymarket/preflight/legacySafeMigration.test.ts app/components/UI/Predict/providers/polymarket/preflight/depositWallet.test.ts app/components/UI/Predict/providers/polymarket/preflight/v2AllowanceRequirements.test.ts app/components/UI/Predict/providers/polymarket/PolymarketProvider.test.ts app/components/UI/Predict/controllers/PredictController.test.ts app/components/UI/Predict/hooks/usePredictAccountState.test.ts --runInBand --forceExityarn lint:tscChangelog
CHANGELOG entry: Added support for Polymarket Deposit Wallet deposits in
Predict
Related issues
Fixes:
PRED-858
Manual testing steps
Screenshots/Recordings
N/A — core/provider flow changes covered by tests and manual wallet-flow
validation.
Before
N/A
After
N/A
Pre-merge author checklist
Docs and MetaMask Mobile
Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Performance checks (if applicable)
SRPs
to import wallets with many accounts and tokens
performance metrics
trace()for usage andaddTokenfor an example
For performance guidelines and tooling, see the Performance
Guide.
Pre-merge reviewer checklist
app, test code being changed).
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Note
High Risk
High risk because it changes how Predict chooses deposit addresses and
adds new pre-publish relayer/batch execution plus post-confirm sync,
which directly affects deposit and deposit+order transaction flows and
fund routing.
Overview
Adds first-class support for Polymarket Deposit Wallet accounts in
Predict by extending
AccountStatewithwalletTypeand routing usersto either legacy Safe or a deterministic deposit wallet based on legacy
Safe deployment and Polymarket Activity API results (failing closed on
API errors).
Implements deposit-wallet infrastructure in the Polymarket provider:
deterministic address derivation, relayer proxy calls/polling, EIP-712
batch execution, allowance-preflight planning (excluding Permit2), and a
legacy Safe “sweep” preflight to migrate stranded USDC.e/pUSD to the
deposit wallet.
Updates the deposit pipeline to (1) build deposits targeting the
deposit wallet (with optional sweep), (2) run a new
beforePublishdeposit-wallet preflight to ensure wallet deployment and required
allowances, and (3) on confirmed deposits/deposit+order, invalidate
cached account state and best-effort sync CLOB balance/allowance—waiting
for that sync before placing the follow-on order.
Reviewed by Cursor Bugbot for commit
c5f61e2. Bugbot is set up for automated
code reviews on this repo. Configure
here.