Skip to content

Subaccount Autonomous Trading ​

To let an AI Agent open/close positions, adjust margin, manage TP/SL, and cancel orders without per-transaction wallet popups, OursMeme provides the on-chain SubaccountRouter channel.


1. Contract-Enforced Security Boundaries ​

  • Zero Withdrawal Rights: Subaccounts can only submit Perp orders on behalf of the master wallet. The smart contract enforces receiver == masterWallet, so all collateral and profits can only return to your master wallet.
  • Capped Actions & Expiry: Configure maximum allowed actions (e.g., 100) and validity duration (default 3 days, max 30 days). Access automatically expires once either limit is reached.
  • Instant Revocation: Call build_agent_revoke from your master wallet to revoke permissions immediately (optionally resetting Perp Router USDC allowance to 0).

⚠️ Important Note on usdcBudget (Shared Router Allowance): Setting usdcBudget in build_agent_authorize configures an exact ERC-20 approve allowance on Perp Router, which is shared with manual orders placed from the web UI. If you trade manually on the same wallet frequently, your manual orders may consume or overwrite that allowance. Consider using a dedicated wallet for automated agent strategies.


  1. Generate a dedicated local subaccount key (chmod 0600, never printed to chat logs, never using your master key).
  2. One-time master wallet authorization:
    • Authorize visually on /agent, or build steps with POST /api/agent/tools/build_agent_authorize and sign once with your master wallet.
  3. Issue an API Key for the subaccount address:
    • Call GET /api/v1/agent/keys/challenge?wallet=<AGENT_ADDR> + POST /api/v1/agent/keys signed by the subaccount key.
  4. Autonomous monitoring and execution:
    • Call get_account({ account: MASTER_WALLET }) with the subaccount's X-API-Key: the backend verifies on-chain SubaccountRouter authorization and returns full positions and pending orders (accessRole: "subaccount").
    • Call build_open_position, build_close_position, build_set_tp_sl, or build_cancel_orders with account: MASTER_WALLET and agent: AGENT_ADDR, then sign and broadcast with the subaccount key.

3. Inspection & Revocation ​

  • Check remaining actions & expiry: POST /api/agent/tools/get_agent_access
  • Revoke immediately: POST /api/agent/tools/build_agent_revoke (pass clearUsdcAllowance: true to also reset Router USDC allowance to 0)

Non-custodial perpetuals & AI Agent infrastructure on BNB Chain.