Skip to content

feat(predict): add deposit wallet deposit foundation#29917

Merged
matallui merged 3 commits into
mainfrom
predict/dw-deposit-foundation
May 8, 2026
Merged

feat(predict): add deposit wallet deposit foundation#29917
matallui merged 3 commits into
mainfrom
predict/dw-deposit-foundation

Conversation

@matallui

@matallui matallui commented May 8, 2026

Copy link
Copy Markdown
Contributor

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

Manual testing steps

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
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

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 to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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.

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.

Reviewed by Cursor Bugbot for commit c5f61e2. Bugbot is set up for automated code reviews on this repo. Configure here.

@metamaskbotv2 metamaskbotv2 Bot added the team-predict Predict team label May 8, 2026
@github-actions github-actions Bot added the pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. label May 8, 2026
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
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.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.21771% with 78 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (predict/dw-confirmation-hooks@1f2109f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...Predict/providers/polymarket/PolymarketProvider.ts 63.30% 32 Missing and 19 partials ⚠️
...s/UI/Predict/providers/polymarket/depositWallet.ts 80.00% 10 Missing and 9 partials ⚠️
...onents/UI/Predict/controllers/PredictController.ts 57.14% 5 Missing and 1 partial ⚠️
...viders/polymarket/preflight/legacySafeMigration.ts 85.71% 2 Missing ⚠️
Additional details and impacted files
@@                       Coverage Diff                        @@
##             predict/dw-confirmation-hooks   #29917   +/-   ##
================================================================
  Coverage                                 ?   81.41%           
================================================================
  Files                                    ?     5309           
  Lines                                    ?   141008           
  Branches                                 ?    32096           
================================================================
  Hits                                     ?   114800           
  Misses                                   ?    18344           
  Partials                                 ?     7864           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@matallui matallui force-pushed the predict/dw-deposit-foundation branch from 7c87db3 to 61b290a Compare May 8, 2026 15:45
@matallui matallui added skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. and removed pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. labels May 8, 2026
ghgoodreau
ghgoodreau previously approved these changes May 8, 2026
caieu
caieu previously approved these changes May 8, 2026
Base automatically changed from predict/dw-confirmation-hooks to main May 8, 2026 18:35
@matallui matallui dismissed stale reviews from caieu and ghgoodreau May 8, 2026 18:35

The base branch was changed.

@matallui matallui force-pushed the predict/dw-deposit-foundation branch from 61b290a to 4a42a4a Compare May 8, 2026 18:39
@matallui matallui marked this pull request as ready for review May 8, 2026 18:39
@matallui matallui requested a review from a team as a code owner May 8, 2026 18:39
ghgoodreau
ghgoodreau previously approved these changes May 8, 2026
Comment thread app/components/UI/Predict/providers/polymarket/PolymarketProvider.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3da3ea8. Configure here.

Comment thread app/components/UI/Predict/controllers/PredictController.ts
@matallui matallui enabled auto-merge May 8, 2026 19:42
@matallui matallui added the force-builds Forces e2e native builds to trigger label May 8, 2026
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePredict
  • Risk Level: high
  • AI Confidence: 92%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are entirely within the Predictions/Polymarket feature area, introducing a significant architectural change: a new "deposit-wallet" wallet type alongside the existing "safe" wallet type.

Key changes:

  1. PredictController.ts (CRITICAL): New syncDepositWalletBalanceAllowanceIfNeeded method; beforePublish now calls beforePublishDepositWalletDeposit which performs pre-transaction checks (wallet deployment, allowance setup) before publishing deposit transactions. This is a significant behavioral change in the transaction lifecycle.
  2. PolymarketProvider.ts: Major refactor of getAccountState to support both 'safe' and 'deposit-wallet' wallet types, with new caching helpers and invalidateAccountState. The deposit flow now branches based on wallet type.
  3. depositWallet.ts (NEW): Complete deposit wallet implementation including address derivation, relayer communication, batch execution, and polling.
  4. preflight/depositWallet.ts (NEW): Preflight planning for deposit wallet allowance requirements.
  5. preflight/legacySafeMigration.ts (NEW): Migration sweep from legacy Safe to deposit wallet.
  6. preflight/v2AllowanceRequirements.ts: Filters out Permit2 approvals for deposit wallets.

SmokePredictions is the primary tag - these changes directly affect the Polymarket deposit flow, account state detection, and position lifecycle (opening positions requires deposits).

Per SmokePredictions tag description: "When selecting SmokePredictions, also select SmokeWalletPlatform (Trending section) and SmokeConfirmations (opening/closing positions are on-chain transactions)."

No changes to shared infrastructure (navigation, Engine, controllers outside Predict, etc.) so other tags are not warranted.

Performance Test Selection:
The new deposit wallet flow introduces network polling (waiting for wallet deployment and relayer transaction completion with up to 20 polls at 1s intervals each), pre-transaction preflight checks, and balance/allowance sync after deposit confirmation. These additions could meaningfully impact the timing of the Predict deposit flow. @PerformancePredict covers prediction market deposit flows and balance display, making it directly relevant to these changes.

View GitHub Actions results

@sonarqubecloud

sonarqubecloud Bot commented May 8, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
76.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@matallui matallui removed the force-builds Forces e2e native builds to trigger label May 8, 2026
@matallui matallui added this pull request to the merge queue May 8, 2026
Merged via the queue into main with commit 36204c5 May 8, 2026
169 of 195 checks passed
@matallui matallui deleted the predict/dw-deposit-foundation branch May 8, 2026 21:43
@github-actions github-actions Bot locked and limited conversation to collaborators May 8, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.78.0 Issue or pull request that will be included in release 7.78.0 label May 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.78.0 Issue or pull request that will be included in release 7.78.0 size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants