Dual-Chain Perp Trading: Drift on Solana + Hyperliquid in One Bot

Building a perp trading bot that operates across both Solana and EVM chains means juggling multiple wallets, protocols, and execution environments. When your bot spots an arbitrage opportunity between Drift on Solana and Hyperliquid on Arbitrum, you need infrastructure that can execute trades instantly without manual wallet switching or complex key management.

Traditional multi-chain trading setups force you to maintain separate wallet implementations, manage private keys across environments, and handle protocol integrations individually. This creates latency, security risks, and missed opportunities when market conditions change faster than your infrastructure can adapt.

Why Cross-Chain Perp Trading Matters

Perpetual futures markets fragment liquidity across chains and protocols. Drift offers leveraged trading on Solana with competitive funding rates, while Hyperliquid provides deep liquidity pools on Arbitrum. Arbitrageurs and market makers need to operate on both simultaneously to capture cross-protocol inefficiencies.

The challenge isn't just technical complexity—it's execution speed. When funding rates diverge or basis trades appear, your bot has minutes or seconds to establish positions before the opportunity disappears. Every API call, wallet interaction, and protocol integration adds latency that directly impacts profitability.

The WAIaaS Approach: Unified Cross-Chain Execution

WAIaaS provides a single REST API that abstracts wallet management and protocol integrations across both Solana and EVM chains. Your trading bot makes HTTP calls instead of managing blockchain connections directly.

The system includes 15 DeFi protocol providers, including both Drift and Hyperliquid integrations. Your bot authenticates once with a session token, then executes trades across any supported protocol without managing separate wallets or private keys.

Setting Up Multi-Chain Wallets

# Create Solana wallet for Drift
curl -X POST http://127.0.0.1:3100/v1/wallets \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{"name": "solana-perps", "chain": "solana", "environment": "mainnet"}'

# Create Arbitrum wallet for Hyperliquid
curl -X POST http://127.0.0.1:3100/v1/wallets \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{"name": "arbitrum-perps", "chain": "evm", "environment": "arbitrum-mainnet"}'

Executing Drift Trades

# Open long position on SOL-PERP via Drift
curl -X POST http://127.0.0.1:3100/v1/actions/drift/place-order \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "market": "SOL-PERP",
    "side": "long",
    "orderType": "market",
    "baseAssetAmount": "10000000000",
    "reduceOnly": false
  }'

Executing Hyperliquid Trades

# Hedge with short position on Hyperliquid
curl -X POST http://127.0.0.1:3100/v1/actions/hyperliquid/place-order \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer wai_sess_<token>" \
  -d '{
    "coin": "SOL",
    "is_buy": false,
    "sz": "10",
    "limit_px": "185.5",
    "order_type": "Limit",
    "reduce_only": false
  }'

Real-World Trading Bot Implementation

Here's how a funding rate arbitrage bot would operate using the unified API:

import { WAIaaSClient } from '@waiaas/sdk';

class FundingArbitrageBot {
  private solanaClient: WAIaaSClient;
  private arbitrumClient: WAIaaSClient;
  
  constructor() {
    this.solanaClient = new WAIaaSClient({
      baseUrl: 'http://127.0.0.1:3100',
      sessionToken: process.env.SOLANA_SESSION_TOKEN,
    });
    
    this.arbitrumClient = new WAIaaSClient({
      baseUrl: 'http://127.0.0.1:3100', 
      sessionToken: process.env.ARBITRUM_SESSION_TOKEN,
    });
  }
  
  async checkFundingRates() {
    // Get current positions across both protocols
    const driftPositions = await this.solanaClient.executeAction({
      provider: 'drift',
      action: 'get-positions'
    });
    
    const hyperliquidPositions = await this.arbitrumClient.executeAction({
      provider: 'hyperliquid',
      action: 'get-positions'
    });
    
    // Calculate funding rate differential
    const driftFunding = driftPositions.positions.find(p => p.market === 'SOL-PERP')?.fundingRate || 0;
    const hyperFunding = hyperliquidPositions.positions.find(p => p.coin === 'SOL')?.fundingRate || 0;
    
    const fundingDiff = Math.abs(driftFunding - hyperFunding);
    
    if (fundingDiff > 0.02) { // 2% threshold
      await this.executeFundingArbitrage(driftFunding, hyperFunding);
    }
  }
  
  async executeFundingArbitrage(driftRate: number, hyperRate: number) {
    const size = "5"; // 5 SOL position size
    
    if (driftRate > hyperRate) {
      // Long Hyperliquid (pay lower funding), Short Drift (receive higher funding)
      await Promise.all([
        this.arbitrumClient.executeAction({
          provider: 'hyperliquid',
          action: 'place-order',
          params: {
            coin: 'SOL',
            is_buy: true,
            sz: size,
            order_type: 'Market'
          }
        }),
        this.solanaClient.executeAction({
          provider: 'drift',
          action: 'place-order',
          params: {
            market: 'SOL-PERP',
            side: 'short',
            orderType: 'market',
            baseAssetAmount: (parseFloat(size) * 1e9).toString()
          }
        })
      ]);
    } else {
      // Reverse: Long Drift, Short Hyperliquid
      await Promise.all([
        this.solanaClient.executeAction({
          provider: 'drift',
          action: 'place-order',
          params: {
            market: 'SOL-PERP',
            side: 'long',
            orderType: 'market',
            baseAssetAmount: (parseFloat(size) * 1e9).toString()
          }
        }),
        this.arbitrumClient.executeAction({
          provider: 'hyperliquid',
          action: 'place-order',
          params: {
            coin: 'SOL',
            is_buy: false,
            sz: size,
            order_type: 'Market'
          }
        })
      ]);
    }
  }
}

Gas-Optimized Execution

Trading bots need to minimize transaction costs, especially on Ethereum mainnet. WAIaaS includes gas conditional execution—transactions only execute when gas prices meet your specified threshold.

# Set policy for gas-conditional execution
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "SPENDING_LIMIT", 
    "rules": {
      "gas_price_gwei_max": 25,
      "instant_max_usd": 1000
    }
  }'

Your bot can queue transactions that automatically execute when gas costs drop below the threshold, improving profit margins on high-frequency strategies.

Risk Management Through Policies

Automated trading requires robust risk controls. WAIaaS provides 21 policy types that enforce position limits, leverage constraints, and protocol restrictions at the infrastructure level.

# Set leverage limit for perpetual trading
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "Content-Type: application/json" \
  -H "X-Master-Password: my-secret-password" \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "PERP_MAX_LEVERAGE",
    "rules": {
      "max_leverage": 5.0,
      "allowed_markets": ["SOL-PERP", "ETH-PERP", "BTC-PERP"]
    }
  }'

These policies operate below your bot's logic, providing a safety net if your algorithm malfunctions or market conditions trigger unexpected behavior.

Quick Start: Deploy Your Cross-Chain Perp Bot

  1. Install and initialize WAIaaS

    npm install -g @waiaas/cli
    waiaas init && waiaas start
    
  2. Create wallets for both chains

    waiaas wallet create --name solana-trading --chain solana
    waiaas wallet create --name arbitrum-trading --chain evm --network arbitrum-mainnet
    
  3. Set up sessions for your bot

    waiaas session prompt --wallet solana-trading
    waiaas session prompt --wallet arbitrum-trading
    
  4. Configure risk policies

    # Add position size limits, leverage caps, and gas controls
    
  5. Deploy your trading algorithm

    # Your bot now makes HTTP calls instead of managing wallets directly
    

For rapid prototyping, the Docker deployment option gets you running in under 60 seconds:

git clone https://github.com/minhoyoo-iotrust/WAIaaS.git
cd WAIaaS
docker compose up -d

The system includes 39 REST API route modules covering wallet management, transaction execution, DeFi protocol access, and risk policy enforcement. Your bot integrates via standard HTTP calls rather than blockchain-specific libraries.

What's Next

Cross-chain perp trading is just one use case for unified wallet infrastructure. The same API supports MEV strategies, yield farming automation, and portfolio rebalancing across 15 DeFi protocols. Start with the GitHub repository at https://github.com/minhoyoo-iotrust/WAIaaS or explore the full documentation at https://waiaas.ai to see how unified blockchain access can streamline your trading operations.