Commit cc932b3
chore(runway): cherry-pick feat(predict): remove CLOB v1 support and migrate to pUSD (#29819)
- feat(predict): remove CLOB v1 support and migrate to pUSD cp-7.76.0
(#29451)
## **Description**
This PR removes legacy Predict Polymarket CLOB v1 support and completes
the pUSD migration in Predict-owned code.
It includes:
- CLOB v2 as the unconditional Polymarket protocol path.
- Removal of CLOB v1 protocol selection, order codec branches, and v1
Safe helper wrappers.
- pUSD as the canonical Predict trading, fee, deposit, withdraw,
reward-fee, and claim gas top-up token.
- Legacy Safe USDC.e retained only as temporary hidden sweep state.
- Legacy USDC.e → pUSD sweep preflight for deposit, withdraw, trade, and
claim operations.
- Displayed Predict balance as total recoverable Predict funds (`pUSD +
legacy USDC.e`).
- In-memory cache to stop refetching legacy USDC.e balance for a Safe
after a zero balance is observed.
Stack note: this PR is stacked on the confirmations-only pUSD PR so the
diff stays limited to Predict-owned files.
## **Changelog**
CHANGELOG entry: Updated Predict to use pUSD and the Polymarket CLOB v2
protocol.
## **Related issues**
Fixes:
[PRED-851](https://consensyssoftware.atlassian.net/browse/PRED-851) ,
[PRED-852](https://consensyssoftware.atlassian.net/browse/PRED-852)
## **Manual testing steps**
```gherkin
Feature: Predict pUSD migration
Scenario: user with pUSD places a Predict trade
Given the user has a funded Predict Safe with pUSD
When the user places a Predict trade
Then the order is submitted through the CLOB v2 path
And pUSD is used for trading and fee authorization
Scenario: legacy user performs their first Predict operation
Given the user has legacy USDC.e in their Predict Safe
When the user deposits, withdraws, trades, or claims
Then the Safe preflight wraps legacy USDC.e into pUSD before the main operation
```
## **Screenshots/Recordings**
### **Before**
N/A — code-only protocol migration PR; no screenshots captured.
### **After**
N/A — code-only protocol migration PR; no screenshots captured.
## **Testing**
- `yarn lint:tsc`
- `yarn jest
app/components/UI/Predict/providers/polymarket/protocol/definitions.test.ts
app/components/UI/Predict/providers/polymarket/protocol/orderCodec.test.ts
app/components/UI/Predict/providers/polymarket/protocol/transport.test.ts
app/components/UI/Predict/providers/polymarket/preflight/v2AllowanceRequirements.test.ts
app/components/UI/Predict/providers/polymarket/preflight/withdraw.test.ts
app/components/UI/Predict/providers/polymarket/preflight/workflows.test.ts
app/components/UI/Predict/providers/polymarket/PolymarketProvider.test.ts
app/components/UI/Predict/controllers/PredictController.test.ts
app/components/UI/Predict/hooks/usePredictBalanceTokenFilter.test.ts
app/components/UI/Predict/hooks/usePredictRewards.test.ts
app/components/UI/Predict/views/PredictBuyWithAnyToken/components/PredictPayWithRow/PredictPayWithRow.test.tsx
--runInBand --forceExit`
## **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
- [x] 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.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Updates on-chain token identifiers/addresses used for Predict gas fee
and rewards calculations, which could impact transactions if
misconfigured. Changes are localized to Predict hooks/controller and
accompanying tests.
>
> **Overview**
> Predict now consistently references the **pUSD / CLOB v2 collateral**
across Predict-owned code: `PredictController` uses
`MATIC_CONTRACTS_V2.collateral` as the `gasFeeToken` for claim/withdraw
`addTransactionBatch`, `usePredictBalanceTokenFilter` displays the
Predict balance row using the `POLYGON_PUSD` token (icon + symbol), and
`usePredictRewards` estimates points using `POLYGON_PUSD_CAIP_ASSET_ID`.
>
> Cleans up account-state handling by removing `hasAllowances`
expectations/tests and updating `usePredictAccountState` docs to reflect
the slimmer `AccountState` shape.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
7dfda61. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
[PRED-851]:
https://consensyssoftware.atlassian.net/browse/PRED-851?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
---------
Co-authored-by: Caainã Jeronimo <caainaje@gmail.com>
[bf54b9b](bf54b9b)
[PRED-851]:
https://consensyssoftware.atlassian.net/browse/PRED-851?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Co-authored-by: Luis Taniça <matallui@gmail.com>
Co-authored-by: Caainã Jeronimo <caainaje@gmail.com>1 parent cc0b6b0 commit cc932b3
44 files changed
Lines changed: 1162 additions & 17993 deletions
File tree
- app/components/UI/Predict
- controllers
- hooks
- providers/polymarket
- preflight
- protocol
- safe
- selectors/featureFlags
- types
- utils
- views/PredictBuyWithAnyToken/components/PredictPayWithRow
- tests
- api-mocking/mock-responses/polymarket
- smoke/confirmations/transactions
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5721 | 5721 | | |
5722 | 5722 | | |
5723 | 5723 | | |
5724 | | - | |
5725 | 5724 | | |
5726 | 5725 | | |
5727 | 5726 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
1453 | 1453 | | |
1454 | 1454 | | |
1455 | 1455 | | |
1456 | | - | |
| 1456 | + | |
1457 | 1457 | | |
1458 | 1458 | | |
1459 | 1459 | | |
| |||
2564 | 2564 | | |
2565 | 2565 | | |
2566 | 2566 | | |
2567 | | - | |
| 2567 | + | |
2568 | 2568 | | |
2569 | 2569 | | |
2570 | 2570 | | |
| |||
Lines changed: 0 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
| |||
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
120 | | - | |
121 | 119 | | |
122 | 120 | | |
123 | 121 | | |
| |||
215 | 213 | | |
216 | 214 | | |
217 | 215 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | 216 | | |
237 | 217 | | |
238 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
Lines changed: 4 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | 55 | | |
60 | 56 | | |
61 | 57 | | |
| |||
85 | 81 | | |
86 | 82 | | |
87 | 83 | | |
88 | | - | |
| 84 | + | |
89 | 85 | | |
90 | 86 | | |
91 | 87 | | |
| |||
165 | 161 | | |
166 | 162 | | |
167 | 163 | | |
168 | | - | |
| 164 | + | |
169 | 165 | | |
170 | 166 | | |
171 | 167 | | |
172 | 168 | | |
173 | 169 | | |
174 | 170 | | |
175 | 171 | | |
176 | | - | |
| 172 | + | |
177 | 173 | | |
178 | 174 | | |
179 | 175 | | |
180 | | - | |
| 176 | + | |
181 | 177 | | |
182 | 178 | | |
183 | 179 | | |
| |||
Lines changed: 9 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
8 | | - | |
9 | | - | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | | - | |
21 | | - | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
| 50 | + | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| |||
0 commit comments