Overview
This document explains the complete user flow for integrating with Lighter DEX through HyperDEX. The process involves creating a server wallet, registering with exchanges, depositing funds, and executing trades.Complete User Flow Diagrams
Aster DEX Flow
Hyperliquid DEX Flow
Lighter DEX Flow
Avantis DEX Flow
Avantis Architecture: Unlike other exchanges, Avantis uses a split architecture. The Tide backend provides data only (positions, orders, history, balances). All trade execution happens client-side via wallet signing on the Base network through the
useAvantisTrade React hook.Step-by-Step Flow
Step 1: Create Server Wallet
Create a server-side wallet secured with MPC (Multi-Party Computation) key management through Dynamic Labs. Endpoint:POST /api/wallets
Request:
- Dynamic Labs creates a wallet with 2-of-2 MPC threshold scheme
- Wallet includes: private key shares, public key, and address
- Wallet is stored securely in the database
userId- User identifier for wallet lookupaddress- Wallet address (0x…) needed for deposits & transactionswalletId- Wallet UUID needed for API registration & signingpublicKey- Public key for verification
Step 2: Register API Keys with Exchanges
After wallet creation, register the wallet with exchanges to get API credentials for trading.Aster Exchange
Endpoint:POST /api/trading/aster/apikey
Request:
userId: “user_123”walletId: “29dd4dc0-1ff9-4df6-a19f-936f997cbc5a”address: “0x173404aAAa4d6539e2C7dbcC1931Cf41b3A3D5c7”
Hyperliquid Exchange
Endpoint:POST /api/trading/hyperliquid/apikey
Request:
Lighter Exchange
Step 3: Fund the Server Wallet
Before depositing to exchanges, your server wallet must have:- USDT - Trading token on BSC
- BNB - Native currency for gas fees
Step 4: Deposit to Exchange
Endpoint:POST /api/trading/:exchange/deposit
Aster Deposit Example
Request:| Field | Type | Required | Description |
|---|---|---|---|
walletIdOrAddress | string | Yes | Can be userId, walletId, or address |
tokenSymbol | string | Yes | Token to deposit (e.g., “USDT”) |
amount | string | Yes | Amount in token units (e.g., “100” = 100 USDT) |
broker | number | Yes | Broker ID (default: 1000) |
network | string | Yes | Network (“ethereum”, “arbitrum”, “bnb”) |
- Check Balance - Verify server wallet has sufficient USDT and BNB for gas
- Approve Token (if needed) - Sign approval transaction and broadcast
- Deposit Transaction - Sign deposit transaction to exchange contract
- Internal Transfer (optional) - Transfer from Spot to Futures/Perp account
Transfer Between Spot and Perp Accounts
Endpoint:POST /api/aster/wallet/transfer
Request:
SPOT_FUTURE- Transfer from Spot → FuturesFUTURE_SPOT- Transfer from Futures → Spot
Step 5: Trading Operations
Aster Trading
Endpoint:POST /api/trading/aster/orders
Headers:
Hyperliquid Trading
Endpoint:POST /api/trading/hyperliquid/orders
Request:
Lighter Trading
Lighter DEX Trading: Lighter requires API credentials as query parameters in the order request.
POST /api/trading/lighter/orders?apiKeyPrivateKey=<key>&apiKeyIndex=<index>&accountIndex=<account>
Query Parameters:
apiKeyPrivateKey- Your Lighter API key private key (hex format)apiKeyIndex- API key index from LighteraccountIndex- Your Lighter account index
Step 6: Withdraw from Exchange
Endpoint:POST /api/trading/:exchange/withdraw
Aster Withdrawal
Request:Hyperliquid Withdrawal
Request:Summary
The complete flow for using HyperDEX with exchange integrations:- Create Wallet - Generate MPC-secured server wallet via Dynamic Labs
- Register API Keys - Link wallet to exchanges (Aster, Hyperliquid)
- Fund Wallet - Transfer USDT and gas tokens to server wallet
- Deposit - Move funds from wallet to exchange accounts
- Trade - Execute orders across multiple exchanges
- Withdraw - Move funds back to server wallet or personal wallet
useAvantisTrade hook for on-chain trade execution. No server wallet or API key registration is required.