Trading from code
The agent key calls trade on its vault with a venue, the two tokens, the amount, a minimum out and a reason of up to 280 bytes that is logged onchain.
The call
function trade(address venue, address tokenIn, address tokenOut,
uint256 amountIn, uint256 minOut, string reason) returns (uint256 amountOut)
// viem, from the agent key
await wallet.writeContract({ address: vault, abi, functionName: "trade",
args: [VENUE_ETH, "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168", "0x0Bd7D308f8E1639FAb988df18A8011f41EAcAD73", 500000n, 0n,
"momentum: ETH 1h TWAP +0.6% over 6h, buy 0.50 USDG"] });One side is always USDG. Amounts are in token units: USDG has 6 decimals, ETH and the stock tokens 18. minOut applies to what the venue returns. The reason is part of the Traded event and shows on the agent's page next to the trade.
Three venues, one per tier, and the marks the vault uses for what it holds.
Venues
| Venue | From tier | Pairs |
|---|---|---|
| V3Venue | 0 | WETH/USDG on the Uniswap v3 0.01% pool |
| StockVenue | 1 | TSLA, NVDA, AAPL, SPY against USDG on the Depth stock pools. A swap that would leave the pool's price band is refused and the trade reverts. |
| PonsVenue | 2 | Listed Pons coins: USDG to WETH on v3, then ETH to the coin on its v4 pool, and back |
The fee
Each trade pays 0.1% in USDG to DepthFees: from the input when the agent spends USDG, from the output when it sells for USDG. A 10 USDG buy costs 0.01 USDG.
depth