Commit 11349b0
- feat(predict): add deposit wallet deposit 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 -->
[36204c5](36204c5)
[PRED-858]:
https://consensyssoftware.atlassian.net/browse/PRED-858?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Co-authored-by: Luis Taniça <matallui@gmail.com>
1 parent 0207b3c commit 11349b0
15 files changed
Lines changed: 2557 additions & 128 deletions
File tree
- app/components/UI/Predict
- controllers
- hooks
- providers
- polymarket
- preflight
- types
Lines changed: 148 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
281 | 284 | | |
282 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
283 | 293 | | |
284 | 294 | | |
285 | 295 | | |
| |||
4885 | 4895 | | |
4886 | 4896 | | |
4887 | 4897 | | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
| 4909 | + | |
| 4910 | + | |
| 4911 | + | |
| 4912 | + | |
| 4913 | + | |
| 4914 | + | |
| 4915 | + | |
| 4916 | + | |
| 4917 | + | |
| 4918 | + | |
| 4919 | + | |
| 4920 | + | |
| 4921 | + | |
| 4922 | + | |
| 4923 | + | |
| 4924 | + | |
| 4925 | + | |
| 4926 | + | |
| 4927 | + | |
| 4928 | + | |
| 4929 | + | |
4888 | 4930 | | |
4889 | 4931 | | |
4890 | 4932 | | |
| |||
5721 | 5763 | | |
5722 | 5764 | | |
5723 | 5765 | | |
| 5766 | + | |
5724 | 5767 | | |
5725 | 5768 | | |
5726 | 5769 | | |
| |||
6140 | 6183 | | |
6141 | 6184 | | |
6142 | 6185 | | |
6143 | | - | |
| 6186 | + | |
6144 | 6187 | | |
6145 | | - | |
6146 | | - | |
6147 | | - | |
6148 | | - | |
6149 | | - | |
6150 | | - | |
6151 | | - | |
6152 | | - | |
| 6188 | + | |
| 6189 | + | |
| 6190 | + | |
| 6191 | + | |
| 6192 | + | |
| 6193 | + | |
| 6194 | + | |
| 6195 | + | |
6153 | 6196 | | |
6154 | 6197 | | |
| 6198 | + | |
| 6199 | + | |
| 6200 | + | |
| 6201 | + | |
| 6202 | + | |
| 6203 | + | |
6155 | 6204 | | |
6156 | 6205 | | |
6157 | 6206 | | |
| |||
9077 | 9126 | | |
9078 | 9127 | | |
9079 | 9128 | | |
9080 | | - | |
9081 | | - | |
| 9129 | + | |
| 9130 | + | |
9082 | 9131 | | |
9083 | 9132 | | |
9084 | 9133 | | |
| |||
9126 | 9175 | | |
9127 | 9176 | | |
9128 | 9177 | | |
| 9178 | + | |
| 9179 | + | |
| 9180 | + | |
9129 | 9181 | | |
9130 | 9182 | | |
9131 | 9183 | | |
| |||
9135 | 9187 | | |
9136 | 9188 | | |
9137 | 9189 | | |
9138 | | - | |
9139 | | - | |
| 9190 | + | |
| 9191 | + | |
| 9192 | + | |
| 9193 | + | |
| 9194 | + | |
| 9195 | + | |
| 9196 | + | |
| 9197 | + | |
| 9198 | + | |
| 9199 | + | |
| 9200 | + | |
| 9201 | + | |
| 9202 | + | |
| 9203 | + | |
| 9204 | + | |
| 9205 | + | |
| 9206 | + | |
| 9207 | + | |
| 9208 | + | |
| 9209 | + | |
| 9210 | + | |
| 9211 | + | |
| 9212 | + | |
| 9213 | + | |
| 9214 | + | |
| 9215 | + | |
| 9216 | + | |
| 9217 | + | |
| 9218 | + | |
| 9219 | + | |
| 9220 | + | |
| 9221 | + | |
| 9222 | + | |
| 9223 | + | |
| 9224 | + | |
| 9225 | + | |
| 9226 | + | |
| 9227 | + | |
| 9228 | + | |
| 9229 | + | |
| 9230 | + | |
| 9231 | + | |
| 9232 | + | |
| 9233 | + | |
| 9234 | + | |
| 9235 | + | |
| 9236 | + | |
| 9237 | + | |
| 9238 | + | |
| 9239 | + | |
| 9240 | + | |
| 9241 | + | |
| 9242 | + | |
| 9243 | + | |
| 9244 | + | |
| 9245 | + | |
| 9246 | + | |
| 9247 | + | |
| 9248 | + | |
| 9249 | + | |
| 9250 | + | |
| 9251 | + | |
| 9252 | + | |
| 9253 | + | |
| 9254 | + | |
| 9255 | + | |
| 9256 | + | |
| 9257 | + | |
| 9258 | + | |
| 9259 | + | |
| 9260 | + | |
| 9261 | + | |
9140 | 9262 | | |
9141 | 9263 | | |
9142 | 9264 | | |
| |||
9184 | 9306 | | |
9185 | 9307 | | |
9186 | 9308 | | |
| 9309 | + | |
| 9310 | + | |
| 9311 | + | |
9187 | 9312 | | |
9188 | 9313 | | |
9189 | 9314 | | |
| |||
9645 | 9770 | | |
9646 | 9771 | | |
9647 | 9772 | | |
9648 | | - | |
9649 | | - | |
| 9773 | + | |
| 9774 | + | |
9650 | 9775 | | |
9651 | 9776 | | |
9652 | 9777 | | |
| |||
9694 | 9819 | | |
9695 | 9820 | | |
9696 | 9821 | | |
| 9822 | + | |
| 9823 | + | |
| 9824 | + | |
9697 | 9825 | | |
9698 | 9826 | | |
9699 | 9827 | | |
| |||
9805 | 9933 | | |
9806 | 9934 | | |
9807 | 9935 | | |
9808 | | - | |
9809 | | - | |
| 9936 | + | |
| 9937 | + | |
9810 | 9938 | | |
9811 | 9939 | | |
9812 | 9940 | | |
| |||
9854 | 9982 | | |
9855 | 9983 | | |
9856 | 9984 | | |
| 9985 | + | |
| 9986 | + | |
| 9987 | + | |
9857 | 9988 | | |
9858 | 9989 | | |
9859 | 9990 | | |
| |||
Lines changed: 68 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2144 | 2144 | | |
2145 | 2145 | | |
2146 | 2146 | | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
| 2156 | + | |
| 2157 | + | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
| 2172 | + | |
| 2173 | + | |
| 2174 | + | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
2147 | 2179 | | |
2148 | 2180 | | |
2149 | 2181 | | |
| |||
2157 | 2189 | | |
2158 | 2190 | | |
2159 | 2191 | | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
2160 | 2206 | | |
2161 | 2207 | | |
2162 | 2208 | | |
| |||
2186 | 2232 | | |
2187 | 2233 | | |
2188 | 2234 | | |
2189 | | - | |
2190 | | - | |
2191 | | - | |
2192 | | - | |
2193 | | - | |
2194 | | - | |
2195 | | - | |
2196 | | - | |
2197 | | - | |
2198 | | - | |
2199 | | - | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
2200 | 2243 | | |
2201 | | - | |
2202 | | - | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
2203 | 2253 | | |
2204 | 2254 | | |
2205 | 2255 | | |
| |||
2621 | 2671 | | |
2622 | 2672 | | |
2623 | 2673 | | |
2624 | | - | |
| 2674 | + | |
2625 | 2675 | | |
2626 | 2676 | | |
2627 | | - | |
| 2677 | + | |
| 2678 | + | |
| 2679 | + | |
| 2680 | + | |
2628 | 2681 | | |
2629 | 2682 | | |
2630 | 2683 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
0 commit comments