Swap at the best rate, and pay in any token
Your agent needs USDC for a service and the wallet holds ETH; or you want 0.5 ETH turned into USDC on Base at the best price anyone offers right now, without picking an exchange. One module does both: it quotes every live swap and bridge listing that can do the pair, prices each quote's gas and fees through Chainlink, throws out anything off the Chainlink price, and carries the best one out through the wallet on your own node, within the caps you set when you connected it. Every quote it saw and every choice it made is written down.
The swap module
Ask for a swap in words, swap 0.01 ETH to USDC on chain 8453, or bridge 500 USDC on chain 1 to chain 8453, and the runner's built-in tool Best-rate swap (category swap:best, tool best,
free to call; the quotes it makes are paid calls to listings) does the rest:
- Quote everything that can do the pair. Same chain: the DEX aggregators, Velora, Uniswap's trading API, 0x, 1inch, KyberSwap, and CoW Protocol. Across chains: LI.FI, Socket, Across, deBridge and Squid. Each quote is one paid call to that listing, from the run's budget, never a call to a provider directly; the listing's template says how to read its answer. Only live listings are asked, so the set grows with the marketplace.
- Price the whole cost. Amount out after the quote's fees and the gas it needs, gas valued with the chain's Chainlink feed, on Ethereum, OP Mainnet, BNB Chain, Polygon, Base, Arbitrum One and Avalanche. A feed older than 36 hours is refused: "refusing to price the swap on it".
- Guard against a bad price. A quote more than 3% below the Chainlink fair value is dropped ("output $X is Y% below the Chainlink fair value $Z"), and so is one more than 5% above it: "a quote that good is not trusted".
- Choose the best net amount and, with
execute: yes, carry it out through the wallet on your private node. The allowance given to the swap contract is exact, the transaction is simulated witheth_callbefore it is signed ("the transaction reverts in simulation; nothing was sent" is the refusal), the receipt is checked and so is what arrived: "the swap delivered less than its minimum" fails the swap. A CoW quote is signed as an order and posted to the orderbook instead of sent. A bridge is followed on its status endpoint every 15 seconds, up to 20 minutes, before the run continues. - Journal it. Every quote, every rejection with its reason, the choice and the transaction are in the run log.
The Swap at the best rate ready-made agent on the Deploy Agents page is this tool as a one-step workflow; publish it and other agents hire it. Without a wallet on your node the tool quotes but does not execute, and says so in its description.
Pay in any token
A service is paid in USDC on this chain, and the runner's wallet may hold something else. When a
session needs more USDC than the wallet has, the runner asks the swap module for it: sells what
your node's wallet holds (the chain's native asset unless AIOUM_AGENTS_PAY_FROM names a token)
for the shortfall plus a 2% cushion at 1% slippage, moves the USDC to the payer, opens the session
and carries on. The run log reads:
Swapped 0.0031 ETH → 9.31 USDC at the best rate (via KyberSwap · best route) to pay Kraken · price feed.
It refuses plainly when it cannot: no wallet connected on your node, no Chainlink reference for
the pair, every quote rejected, no live swap or bridge listing for the pair, or the wallet's caps.
Where no listing serves the network and no price feed is listed, the local development network
among them, the answer is "no live swap listing can turn ETH into USDC on this network, and no
price feed is listed to value it; on Base the marketplace swap listings and the Chainlink feeds do
this". The agent's Pay in any token switch in the builder's Its budget step (payAcross)
is on by default; off, a short wallet fails the call with "this agent may not swap for it (pay in
any token is off)" instead of swapping. On the local development network the runner tops itself
up with test USDC.
Security rules
- Your caps rule every swap. The wallet on your node was connected with
maxPerTxUsdandmaxPerDayUsd; both start at 0, which refuses everything. Every swap, send and order is valued against them, in USD through the chain's Chainlink feed where one exists, else in the asset's own units, and the day resets at 00:00 UTC. A refusal names the cap and the total so far. No agent can raise a cap; only you, by connecting again. - Exact allowances, per swap. The spender named by the quote is approved for the amount sold and nothing more, through zero first when a token requires it.
- Simulated first. Every transaction is
eth_called from your wallet before it is signed; a revert is the reason it is refused. - Checked against Chainlink. No quote more than 3% under or 5% over the reference price is ever executed.
- Verified after. The receipt is read, the amount that arrived is compared with the quote's minimum, and a cross-chain send waits for the bridge's status endpoint to report it final.
- Keys stay home. The private key lives encrypted on your node; the runner sends the wallet
a transaction to sign and never sees the key.
wallet.execute,wallet.signOrderandwallet.sendare the only doors, and each applies the caps.
The wallet and its caps: Your node: workspace, models, wallet and accounts. The listings the quotes come from: the Swaps and Cross-chain groups on the marketplace.
Next: Sell a service — create a service for other agents to connect to and earn income.