Skip to main content
Three commands cover treasury movement beyond simple transfers. swap routes through the Trails DEX API, including cross-chain swaps via --to-chain. deposit parks idle balances in Trails earn pools (Aave v3, Morpho, ERC-4626 vaults). withdraw exits those positions, with auto-discovery if you know only the asset and protocol. The CLI picks the highest-TVL pool by default; pass --protocol to constrain. All three are dry-run by default. Pass --broadcast to execute.

How it works

Treasury sweep flow
1OperatorCLIpolygon-agent swap —from USDT —to USDC …
2CLITrailsRoutes swap quote and gas across DEX aggregators
3Smart walletPolygonSwap executes; output token received
4OperatorCLIpolygon-agent deposit —asset USDC —amount 1000
5TrailsAave / MorphoDeposits into highest-TVL pool by default
--defi at wallet create time gives the smart wallet permission to interact with Aave v3, Morpho, and ERC-4626 vaults. Without --defi, deposit and withdraw fail with a session-rejection error before any funds move.

Commands

swap

polygon-agent swap --from USDC --to WETH --amount 100
polygon-agent swap --from USDC --to USDC --amount 100 --to-chain base --broadcast
DEX swap routed through Trails. Pass --to-chain to bridge during the swap.
FlagDefaultPurpose
--walletmainWallet name
--chainnoneSource chain
--fromrequiredSource token symbol
--torequiredDestination token symbol
--amountrequiredAmount to swap
--slippagenoneTolerance 0–0.5 (e.g. 0.005 for 0.5%)
--to-chainnoneDestination chain for cross-chain swap
--broadcastfalseExecute the transaction

deposit

polygon-agent deposit --asset USDC --amount 1000
polygon-agent deposit --asset USDC --amount 1000 --protocol aave --broadcast
Deposit into a Trails earn pool. With no --protocol, the CLI auto-selects the highest-TVL pool for the asset. --protocol aave or --protocol morpho constrains the choice.
FlagDefaultPurpose
--walletmainWallet name
--chainnoneChain
--assetUSDCAsset symbol
--amountrequiredAmount to deposit
--protocolnoneFilter: aave or morpho
--broadcastfalseExecute the transaction

withdraw

# By auto-discovery
polygon-agent withdraw --asset USDC --protocol aave --amount max
# By explicit position address
polygon-agent withdraw --position 0xPool... --amount 500
Withdraw from an Aave v3 aToken position or an ERC-4626 vault. Use --amount max for a full exit.
FlagDefaultPurpose
--walletmainWallet name
--chainnoneChain
--positionnoneaToken or vault share address
--assetnoneAsset symbol (use with --protocol to auto-discover)
--protocolnoneaave or morpho
--amountrequiredUnderlying amount (Aave) or max / partial (ERC-4626)
--broadcastfalseExecute the transaction

Worked example

# Sweep idle USDC into Aave v3
polygon-agent deposit --asset USDC --amount 5000 --protocol aave
# ⚡ Dry run, pool: 0x794a..., projected APY 4.8%

polygon-agent deposit --asset USDC --amount 5000 --protocol aave --broadcast
# Deposited 5000.00 USDC to Aave v3
# Tx: 0xabc... → https://polygonscan.com/tx/0xabc...

# Pull funds back when an initiative kicks off
polygon-agent withdraw --asset USDC --protocol aave --amount max --broadcast
# Withdrew 5,012.34 USDC from Aave v3 (principal + yield)
# Tx: 0xdef...

Implementation

Setup and wallets

Pass --defi at wallet creation to enable swaps and yield.

Transfers

Plain token transfers; no DEX routing.

Trails

The underlying DEX and earn-pool router.