Skip to content

Conversation

@NeOMakinG
Copy link
Collaborator

@NeOMakinG NeOMakinG commented Jan 7, 2026

Description

Adds perpetuals trading functionality to ShapeShift using Orderly Network's SDK.

Key Implementation Details

Broker-Specific Accounts

Orderly Network uses broker-specific accounts. Each (wallet_address + broker_id) pair creates a unique, isolated account:

  • Account ID = keccak256(wallet_address + keccak256(broker_id))
  • Balances deposited under one broker ID are NOT accessible under a different broker ID
  • Users must deposit USDC under the correct broker ID to see their balance
    The broker ID is configured via VITE_ORDERLY_BROKER_ID (default: "shapeshift").

Wallet Adapter Architecture

The OrderlyWalletAdapter bridges ShapeShift's wallet system to Orderly's SDK:

  1. Native Wallets (Native, Mobile): Uses custom NativeWalletProvider EIP-1193 adapter
  2. WalletConnect V2: Directly passes the wcV2Provider
  3. MIPD Wallets (MetaMask, Rabby, etc.): Uses the rdns identifier to find the correct provider

Bug Fix: MIPD Provider Selection

Fixed an issue where MetaMask (and other MIPD wallets) would fail with "error getting address from wallet" errors.
Root Cause: The original code grabbed the first available MIPD provider instead of the specific wallet the user connected with.
Fix: Now uses the rdns (Reverse Domain Name System identifier like io.metamask) stored during wallet connection to find the exact provider.

Files Changed

  • src/pages/Perpetuals/PerpetualsPage.tsx - Main perpetuals trading page using Orderly SDK
  • src/pages/Perpetuals/OrderlyWalletAdapter.tsx - Bridges ShapeShift wallet to Orderly SDK
  • src/pages/Perpetuals/NativeWalletProvider.ts - EIP-1193 provider adapter for native/mobile wallets

Issue (if applicable)

closes #

Risk

Medium Risk - New feature behind VITE_FEATURE_ORDERLY_PERPETUALS feature flag.

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

  • Orderly Network perpetuals trading (deposits, withdrawals, trading)
  • Wallet signing for Orderly account registration and trading keys
  • EVM chain interactions on Arbitrum, Optimism, Polygon, Base, Avalanche, BNB

Testing

Engineering

  1. Enable feature flag: VITE_FEATURE_ORDERLY_PERPETUALS=true
  2. Set broker ID: VITE_ORDERLY_BROKER_ID=shapeshift (or your test broker)
  3. Connect with different wallet types:
    • MetaMask: Should correctly identify provider via rdns
    • Rabby/Other MIPD: Should work if multiple wallets installed
    • WalletConnect: Should use wcV2Provider
    • Native wallet: Should use custom EIP-1193 adapter
  4. Navigate to /perpetuals
  5. Verify:
    • Account connects to Orderly
    • Balance shows correctly (if deposited under same broker ID)
    • Can place test orders
    • Console shows [Orderly] Wallet state updated with correct accounts

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

Screenshots (if applicable)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch perps

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants