Commit 36fb960
authored
feat(predict): add Deposit Wallet order flow (MetaMask#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 -->1 parent e124dd0 commit 36fb960
5 files changed
Lines changed: 773 additions & 155 deletions
File tree
- app/components/UI/Predict/providers/polymarket
- protocol
Lines changed: 182 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
471 | 472 | | |
472 | 473 | | |
473 | 474 | | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
474 | 478 | | |
475 | 479 | | |
476 | 480 | | |
| |||
480 | 484 | | |
481 | 485 | | |
482 | 486 | | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
483 | 494 | | |
484 | 495 | | |
485 | 496 | | |
| |||
488 | 499 | | |
489 | 500 | | |
490 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
491 | 673 | | |
492 | 674 | | |
493 | 675 | | |
| |||
0 commit comments