DEV Community

Cover image for Tracking Your AI Agent's DeFi Positions Across Chains
Wallet Guy
Wallet Guy

Posted on

Tracking Your AI Agent's DeFi Positions Across Chains

Your trading bot is making moves across Jupiter, Aave, Lido, and Drift — but how do you track positions when they're scattered across 14 different protocols and 2 chains? Writing custom integrations for each protocol's unique API is a nightmare, and most wallets show balances but miss the nuanced details of lending rates, liquidation risks, and staking rewards.

Why DeFi Position Tracking is a Developer's Nightmare

Modern DeFi strategies span multiple protocols. Your SOL might be staked on Jito, your USDC lending on Aave, ETH bridged via LI.FI, and perpetual positions open on Hyperliquid. Each protocol has its own API format, authentication method, and data structure.

Traditional approaches force you to maintain separate integrations for Jupiter's swap data, Aave's lending positions, Lido's staking rewards, and Pendle's yield tokenization. That's 14+ different SDKs, API keys, and rate limits to manage. When your bot needs to rebalance or assess risk, it's querying a dozen endpoints and stitching together fragmented data.

The stakes are real: missing a liquidation threshold because your Aave integration broke, or failing to unstake before a network upgrade because your monitoring was incomplete.

One API for 14 DeFi Protocols

WAIaaS provides a unified DeFi positions API that aggregates data across 14 protocols on both EVM and Solana. Instead of juggling multiple integrations, your application gets normalized position data through a single endpoint.

Here's what comprehensive position tracking looks like:

curl http://127.0.0.1:3100/v1/defi/positions \
  -H "Authorization: Bearer wai_sess_<token>"
Enter fullscreen mode Exit fullscreen mode

The response aggregates positions across all integrated protocols:

{
  "positions": [
    {
      "protocol": "aave-v3",
      "chain": "ethereum",
      "type": "lending",
      "asset": "USDC",
      "supplied": "10000.50",
      "borrowed": "0",
      "apy": "4.2",
      "healthFactor": null,
      "liquidationThreshold": null
    },
    {
      "protocol": "lido-staking",
      "chain": "ethereum", 
      "type": "staking",
      "asset": "stETH",
      "staked": "5.0",
      "rewards": "0.12",
      "apy": "3.8"
    },
    {
      "protocol": "jito-staking",
      "chain": "solana",
      "type": "staking", 
      "asset": "jitoSOL",
      "staked": "100.0",
      "rewards": "4.2",
      "apy": "7.1"
    },
    {
      "protocol": "hyperliquid",
      "chain": "hyperliquid",
      "type": "perpetual",
      "market": "ETH-USD",
      "size": "2.5",
      "side": "long",
      "entryPrice": "2400.0",
      "unrealizedPnl": "+125.50",
      "leverage": "3.0x"
    }
  ],
  "summary": {
    "totalValueUsd": "45280.75",
    "protocolCount": 4,
    "riskLevel": "moderate"
  }
}
Enter fullscreen mode Exit fullscreen mode

Protocol Coverage That Actually Matters

WAIaaS integrates the protocols your strategies actually use:

Solana DeFi:

  • Jupiter — DEX aggregation and swapping
  • Drift — Perpetual futures and spot trading
  • Jito — Liquid staking with MEV rewards

EVM DeFi:

  • Aave V3 — Lending and borrowing with health factors
  • Lido — ETH liquid staking (stETH)
  • Pendle — Yield tokenization and trading

Cross-chain:

  • LI.FI — Bridge aggregation across 20+ chains
  • Across — Fast optimistic bridging

Trading:

  • Hyperliquid — On-chain perps with sub-accounts
  • Polymarket — Prediction market positions

Each protocol integration provides normalized data while preserving protocol-specific details like Aave's health factors, Hyperliquid's leverage ratios, and Pendle's yield components.

Executable Actions, Not Just Data

Beyond position tracking, WAIaaS lets you execute actions across all integrated protocols using the same session authentication:

# Swap on Jupiter
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Authorization: Bearer wai_sess_<token>" \
  -H "Content-Type: application/json" \
  -d '{
    "inputMint": "So11111111111111111111111111111111111111112",
    "outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", 
    "amount": "1000000000"
  }'
Enter fullscreen mode Exit fullscreen mode
# Supply to Aave V3
curl -X POST http://127.0.0.1:3100/v1/actions/aave-v3/supply \
  -H "Authorization: Bearer wai_sess_<token>" \
  -H "Content-Type: application/json" \
  -d '{
    "asset": "0xA0b86a33E6464C9C68ce1b36B9F41bf691Ed7566",
    "amount": "1000000000",
    "onBehalfOf": "<wallet-address>"
  }'
Enter fullscreen mode Exit fullscreen mode
# Open Hyperliquid perp position  
curl -X POST http://127.0.0.1:3100/v1/actions/hyperliquid/place-order \
  -H "Authorization: Bearer wai_sess_<token>" \
  -H "Content-Type: application/json" \
  -d '{
    "coin": "ETH",
    "sz": "1.5",
    "px": "2500.0",
    "side": "B",
    "orderType": {"limit": {}}
  }'
Enter fullscreen mode Exit fullscreen mode

The same session token works across all protocols. No API key juggling, no protocol-specific authentication flows.

Risk Monitoring with Policy Engine

DeFi strategies need guardrails. WAIaaS includes a policy engine with 21 policy types specifically designed for DeFi risk management:

# Create lending LTV limit policy
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "X-Master-Password: <password>" \
  -H "Content-Type: application/json" \
  -d '{
    "walletId": "<uuid>",
    "type": "LENDING_LTV_LIMIT", 
    "rules": {
      "maxLtv": 0.75,
      "protocols": ["aave-v3"],
      "emergencyLtv": 0.85
    }
  }'
Enter fullscreen mode Exit fullscreen mode
# Restrict perpetual leverage
curl -X POST http://127.0.0.1:3100/v1/policies \
  -H "X-Master-Password: <password>" \
  -H "Content-Type: application/json" \
  -d '{
    "walletId": "<uuid>",
    "type": "PERP_MAX_LEVERAGE",
    "rules": {
      "maxLeverage": 5.0,
      "protocols": ["hyperliquid", "drift"]
    }
  }'
Enter fullscreen mode Exit fullscreen mode

When your bot tries to execute a trade that would exceed risk limits, the transaction gets automatically blocked or delayed for manual approval.

Quick Start: Deploy and Connect

Get a unified DeFi API running in under 5 minutes:

  1. Start WAIaaS with Docker:
git clone https://github.com/minhoyoo-iotrust/WAIaaS.git
cd WAIaaS  
docker compose up -d
Enter fullscreen mode Exit fullscreen mode
  1. Create wallets and sessions:
npm install -g @waiaas/cli
waiaas quickset --mode mainnet  # Creates EVM + Solana wallets
Enter fullscreen mode Exit fullscreen mode
  1. Query DeFi positions:
curl http://127.0.0.1:3100/v1/defi/positions \
  -H "Authorization: Bearer $(cat ~/.waiaas/sessions/mainnet-trading.token)"
Enter fullscreen mode Exit fullscreen mode
  1. Execute your first cross-protocol strategy:
# Bridge USDC from Ethereum to Solana
curl -X POST http://127.0.0.1:3100/v1/actions/lifi/bridge \
  -H "Authorization: Bearer <token>" \
  -d '{"fromChain": "ethereum", "toChain": "solana", "token": "USDC", "amount": "1000"}'

# Then swap for SOL on Jupiter  
curl -X POST http://127.0.0.1:3100/v1/actions/jupiter-swap/swap \
  -H "Authorization: Bearer <token>" \
  -d '{"inputMint": "USDC", "outputMint": "SOL", "amount": "1000"}'
Enter fullscreen mode Exit fullscreen mode
  1. Set up risk policies before you scale:
waiaas quickset --policies  # Creates sensible DeFi risk defaults
Enter fullscreen mode Exit fullscreen mode

What's Next

Your trading strategies no longer need separate integrations for each DeFi protocol. With 39 REST API endpoints, 14 DeFi protocol integrations, and a 7-stage transaction pipeline with policy enforcement, you can focus on alpha generation instead of API maintenance.

Check out the complete integration at GitHub or explore the interactive API documentation at waiaas.ai.

Top comments (0)