chore(runway): cherry-pick feat(predict): add Deposit Wallet order flow#30100
Merged
Conversation
…ow (#29933) ## **Description** Adds Predict order placement support for Polymarket Deposit Wallet accounts on top of the Deposit Wallet deposit foundation. This PR: - Adds the `POLY_1271` Polymarket signature type. - Adds Deposit Wallet / ERC-1271 order signing via the `TypedDataSign` wrapper. - Routes order maker/signer fields from active Predict account state. - Uses Deposit Wallet maker/signer for Deposit Wallet users. - Preserves legacy Safe order signing for grandfathered Safe users. - Runs Deposit Wallet create/setup preflight before submitting Deposit Wallet orders. - Passes an optional signed legacy Safe migration sweep as `allowancesTx` for Deposit Wallet orders, so stranded pUSD/USDC.e can be swept before the backend relays the order. - Skips Safe trade allowance and Permit2 fee preflight for Deposit Wallet orders. - Continues signing CLOB L2 headers with the EOA owner address. This PR is temporarily stacked on `predict/dw-deposit-foundation` while PRs 1 and 2 are under review, and should be rebased/retargeted after those merge. Validation run locally: ```bash yarn jest app/components/UI/Predict/providers/polymarket/protocol/orderCodec.test.ts app/components/UI/Predict/providers/polymarket/PolymarketProvider.test.ts --runInBand yarn lint:tsc ``` ## **Changelog** CHANGELOG entry: Fixed Predict order placement for Polymarket Deposit Wallet accounts ## **Related issues** Fixes: [PRED-860](https://consensyssoftware.atlassian.net/browse/PRED-860) ## **Manual testing steps** ```gherkin Feature: Predict Deposit Wallet order flow Scenario: Deposit Wallet user places a Predict order Given a Predict user is routed to a Polymarket Deposit Wallet And the Deposit Wallet has enough pUSD balance and required setup from the deposit flow When the user places a Predict buy or sell order Then the order is signed with POLY_1271 semantics And the order is submitted successfully to the Polymarket CLOB Scenario: Deposit Wallet user places first order before wallet setup Given a Predict user is routed to a Polymarket Deposit Wallet And the Deposit Wallet still needs creation or allowance setup When the user places a Predict buy or sell order Then the app creates/sets up the Deposit Wallet before order submission And the order is submitted successfully to the Polymarket CLOB Scenario: Deposit Wallet user has funds stranded in legacy Safe Given a Predict user is routed to a Polymarket Deposit Wallet And the deterministic legacy Safe has sweepable pUSD or USDC.e When the user places a Predict buy or sell order Then the signed legacy Safe sweep is included as allowancesTx And the backend can submit the sweep before relaying the order Scenario: Legacy Safe user places a Predict order Given a Predict user is grandfathered to the legacy Safe wallet When the user places a Predict buy or sell order Then the order continues to use legacy Safe signing and preflight behavior ``` ## **Screenshots/Recordings** ### **Before** N/A - provider/order-signing change only. ### **After** N/A - provider/order-signing change only. ## **Pre-merge author checklist** - [ ] 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). - [ ] I've completed the PR template to the best of my ability - [ ] I've included tests if applicable - [ ] 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-860]: https://consensyssoftware.atlassian.net/browse/PRED-860?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes core Predict order submission/signing paths, adding a new ERC-1271 signing format and deposit-wallet preflight flows; mistakes could cause failed or incorrectly-signed orders. Legacy Safe behavior is preserved but now shares more conditional branching. > > **Overview** > Adds end-to-end order placement support for Polymarket **Deposit Wallet** accounts. > > Order submission now derives maker/signer from the resolved account state and, for deposit-wallet users, performs a create/allowance batch preflight before signing/submitting. Deposit-wallet orders use the new `SignatureType.POLY_1271` and are signed via `signProtocolOrder` using an ERC-7739 `TypedDataSign` wrapper, while Safe users keep legacy Safe signing. > > Fee collection and Safe trade preflight steps (Permit2 fee authorization + allowances tx) are skipped for deposit-wallet orders; instead an optional legacy Safe migration sweep can be attached as `allowancesTx`. L2 CLOB headers are consistently signed using the EOA owner address. Tests were expanded to cover both Safe and deposit-wallet order flows and the new signing payload. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b2bf1ee. 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
Adds Predict order placement support for Polymarket Deposit Wallet
accounts on top of the Deposit Wallet deposit foundation.
This PR:
POLY_1271Polymarket signature type.TypedDataSignwrapper.
Wallet orders.
allowancesTxfor Deposit Wallet orders, so stranded pUSD/USDC.e can beswept before the backend relays the order.
Wallet orders.
This PR is temporarily stacked on
predict/dw-deposit-foundationwhilePRs 1 and 2 are under review, and should be rebased/retargeted after
those merge.
Validation run locally:
Changelog
CHANGELOG entry: Fixed Predict order placement for Polymarket Deposit
Wallet accounts
Related issues
Fixes:
PRED-860
Manual testing steps
Screenshots/Recordings
Before
N/A - provider/order-signing change only.
After
N/A - provider/order-signing change only.
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
Medium Risk
Changes core Predict order submission/signing paths, adding a new
ERC-1271 signing format and deposit-wallet preflight flows; mistakes
could cause failed or incorrectly-signed orders. Legacy Safe behavior is
preserved but now shares more conditional branching.
Overview
Adds end-to-end order placement support for Polymarket Deposit
Wallet accounts.
Order submission now derives maker/signer from the resolved account
state and, for deposit-wallet users, performs a create/allowance batch
preflight before signing/submitting. Deposit-wallet orders use the new
SignatureType.POLY_1271and are signed viasignProtocolOrderusingan ERC-7739
TypedDataSignwrapper, while Safe users keep legacy Safesigning.
Fee collection and Safe trade preflight steps (Permit2 fee
authorization + allowances tx) are skipped for deposit-wallet orders;
instead an optional legacy Safe migration sweep can be attached as
allowancesTx. L2 CLOB headers are consistently signed using the EOAowner address. Tests were expanded to cover both Safe and deposit-wallet
order flows and the new signing payload.
Reviewed by Cursor Bugbot for commit
b2bf1ee. Bugbot is set up for automated
code reviews on this repo. Configure
here.