Wallet Integration

Complete guide to wallet integration for LX - Web3, MPC, hardware, custodial, and smart contract wallets

Wallet Integration

Specification: LP-9002 DEX API & RPC | LP-333 MPC Signers

Overview

LX supports comprehensive wallet integration for all user types:

Wallet TypeUse CaseSecurity ModelLatency
Web3Retail usersUser-controlled keys~2-5s
MPCInstitutionalThreshold signatures~100ms
HardwareHigh securityAir-gapped signing~5-10s
CustodialEnterpriseCustodian-managed~50ms
MultisigTreasuryM-of-N approval~30s
Smart WalletsAdvanced usersContract-based~2-5s
MobileOn-the-goNative SDK~1-3s

Architecture

                    LX Wallet Architecture

+------------------+     +------------------+     +------------------+
|   User Device    |     |   LX API     |     |   Settlement     |
|                  |     |                  |     |                  |
|  +------------+  |     |  +------------+  |     |  +------------+  |
|  | Wallet SDK |  |---->|  | Auth Layer |  |---->|  | C-Chain    |  |
|  +------------+  |     |  +------------+  |     |  +------------+  |
|        |         |     |        |         |     |        |         |
|  +------------+  |     |  +------------+  |     |  +------------+  |
|  | Signer     |  |     |  | Order      |  |     |  | Warp Msg   |  |
|  +------------+  |     |  | Engine     |  |     |  +------------+  |
+------------------+     +------------------+     +------------------+

Supported Wallets

Browser Wallets

  • MetaMask (EIP-1193, EIP-6963)
  • Coinbase Wallet
  • Rainbow
  • Trust Wallet
  • Rabby

WalletConnect

  • WalletConnect v2 (all compatible wallets)
  • Mobile deep linking
  • QR code pairing

Hardware Wallets

  • Ledger (Nano S/X/S Plus)
  • Trezor (Model T, Safe 3)
  • GridPlus Lattice1

MPC Providers

  • Fireblocks
  • BitGo
  • Copper
  • Anchorage

Smart Contract Wallets

  • Safe (formerly Gnosis Safe)
  • Argent
  • Sequence
  • ZeroDev

Quick Start

TypeScript SDK

import { Client, WalletAdapter } from '@luxfi/trading';
import { MetaMaskAdapter } from '@luxfi/trading/wallets';

// Create client with wallet adapter
const wallet = new MetaMaskAdapter();
const client = new Client({
  endpoint: 'https://dex.lux.network',
  wallet: wallet
});

// Connect wallet
await client.connect();

// Sign and place order
const order = await client.placeOrder({
  symbol: 'BTC-USD',
  side: 'buy',
  type: 'limit',
  price: '50000',
  quantity: '1.0'
});

Python SDK

from lx_dex import Client
from lx_dex.wallets import Web3Wallet

# Create client with wallet
wallet = Web3Wallet(private_key=os.environ['PRIVATE_KEY'])
client = Client(
    endpoint='https://dex.lux.network',
    wallet=wallet
)

# Place signed order
order = client.place_order(
    symbol='BTC-USD',
    side='buy',
    type='limit',
    price='50000',
    quantity='1.0'
)

Go SDK

import (
    "github.com/luxfi/dex/sdk"
    "github.com/luxfi/dex/sdk/wallets"
)

// Create client with wallet
wallet, _ := wallets.NewPrivateKeyWallet(privateKey)
client := sdk.NewClient(&sdk.Config{
    Endpoint: "https://dex.lux.network",
    Wallet:   wallet,
})

// Place signed order
order, err := client.PlaceOrder(&sdk.Order{
    Symbol:   "BTC-USD",
    Side:     sdk.Buy,
    Type:     sdk.Limit,
    Price:    "50000",
    Quantity: "1.0",
})

Authentication Flow

1. Connection

// Request wallet connection
const accounts = await wallet.connect();
const address = accounts[0];

// Verify chain ID
const chainId = await wallet.getChainId();
if (chainId !== LUX_CHAIN_ID) {
  await wallet.switchChain(LUX_CHAIN_ID);
}

2. Session Creation

// Create authenticated session
const session = await client.createSession({
  address: address,
  expiry: Date.now() + 24 * 60 * 60 * 1000, // 24 hours
});

// Sign session message
const signature = await wallet.signMessage(session.message);

// Verify and activate session
const token = await client.verifySession(signature);

3. Order Signing

// Orders require EIP-712 typed data signature
const orderData = {
  domain: {
    name: 'LX',
    version: '1',
    chainId: LUX_CHAIN_ID,
    verifyingContract: DEX_CONTRACT_ADDRESS
  },
  types: {
    Order: [
      { name: 'symbol', type: 'string' },
      { name: 'side', type: 'uint8' },
      { name: 'price', type: 'uint256' },
      { name: 'quantity', type: 'uint256' },
      { name: 'nonce', type: 'uint256' },
      { name: 'expiry', type: 'uint256' }
    ]
  },
  message: order
};

const signature = await wallet.signTypedData(orderData);

Wallet Interface

All wallet adapters implement the standard interface:

interface WalletAdapter {
  // Connection
  connect(): Promise<string[]>;
  disconnect(): Promise<void>;
  isConnected(): boolean;

  // Account info
  getAddress(): Promise<string>;
  getChainId(): Promise<number>;
  getBalance(): Promise<bigint>;

  // Signing
  signMessage(message: string): Promise<string>;
  signTypedData(data: TypedData): Promise<string>;
  signTransaction(tx: Transaction): Promise<string>;

  // Events
  on(event: WalletEvent, handler: EventHandler): void;
  off(event: WalletEvent, handler: EventHandler): void;
}

type WalletEvent =
  | 'connect'
  | 'disconnect'
  | 'accountsChanged'
  | 'chainChanged'
  | 'error';

Chain Configuration

Lux Mainnet

const LUX_MAINNET = {
  chainId: 96369,
  chainName: 'Lux Mainnet',
  nativeCurrency: {
    name: 'LUX',
    symbol: 'LUX',
    decimals: 18
  },
  rpcUrls: ['https://api.lux.network/ext/bc/C/rpc'],
  blockExplorerUrls: ['https://explorer.lux.network']
};

Lux Testnet

const LUX_TESTNET = {
  chainId: 96370,
  chainName: 'Lux Testnet',
  nativeCurrency: {
    name: 'LUX',
    symbol: 'LUX',
    decimals: 18
  },
  rpcUrls: ['https://api.testnet.lux.network/ext/bc/C/rpc'],
  blockExplorerUrls: ['https://testnet.explorer.lux.network']
};

Error Handling

import { WalletError, WalletErrorCode } from '@luxfi/trading/wallets';

try {
  await wallet.connect();
} catch (error) {
  if (error instanceof WalletError) {
    switch (error.code) {
      case WalletErrorCode.USER_REJECTED:
        console.log('User rejected connection');
        break;
      case WalletErrorCode.CHAIN_NOT_SUPPORTED:
        console.log('Please switch to Lux network');
        break;
      case WalletErrorCode.WALLET_NOT_FOUND:
        console.log('Please install a wallet');
        break;
      case WalletErrorCode.ALREADY_CONNECTED:
        console.log('Wallet already connected');
        break;
      default:
        console.error('Wallet error:', error.message);
    }
  }
}

Security Considerations

Key Management

  • Never expose private keys in client code
  • Use environment variables for server-side keys
  • Implement proper key rotation policies

Session Management

  • Set appropriate session expiry times
  • Implement session revocation
  • Monitor for suspicious activity

Transaction Verification

  • Always verify transaction details before signing
  • Implement spending limits
  • Use allowlists for contract interactions

See Security Best Practices for comprehensive guidelines.

Next Steps