An autonomous DeFi agent that discovers and deposits into the highest-yielding pools on Polygon. Powered by Trails pool discovery — APY and vault addresses are resolved at runtime, never hardcoded. Supports Aave v3 and Morpho vaults on Polygon mainnet and Katana.
Deploy it on Pinata Agents and get a yield optimizer that monitors your positions every 6 hours and alerts you when a better opportunity appears.
- Discovers the best available APY across Aave v3 and Morpho for USDC, USDT, and WETH
- Executes deposits into the highest-TVL pool on your confirmation
- Monitors positions every 6 hours via scheduled tasks, alerting when a >1% APY improvement is available
- Reports a daily portfolio snapshot at 9am
All commands are dry-run by default — the agent shows you exactly what it will do (APY, TVL, contract address) before asking for confirmation.
- A funded Polygon mainnet wallet (USDC, USDT, or POL for gas)
- A Pinata Agents account
- A Trails API key — get one at https://dashboard.trails.build
- Import this repo into agents.pinata.cloud
- Deploy — the build script installs the
polygon-agentCLI automatically - Start a conversation with your agent and follow the first-run guide
| Secret | Required | Description |
|---|---|---|
TRAILS_API_KEY |
Optional | Your Trails API key from dashboard.trails.build. If set, takes precedence for all swap/deposit/bridge operations. If omitted, the CLI uses the key generated by polygon-agent setup. |
The agent walks you through four steps on first conversation:
1. Setup — creates an EOA and Sequence project, stores credentials encrypted on disk
polygon-agent setup --name "YieldOptimizer"2. Create Wallet — creates a smart contract wallet pre-authorized for yield vaults
polygon-agent wallet create \
--usdc-limit 100 \
--native-limit 5 \
--contract 0x794a61358d6845594f94dc1db02a252b5b4814ad \
--contract 0x781fb7f6d845e3be129289833b04d43aa8558c42 \
--contract 0xf5c81d25ee174d83f1fd202ca94ae6070d073ccfA browser window opens for approval. After approving, enter the 6-digit code shown in the browser.
3. Fund — run polygon-agent fund to get a Trails funding widget URL. Open it to deposit USDC or USDT.
4. Optimize — the agent dry-runs a deposit to show you the current best APY, then executes on your confirmation.
# Dry-run — shows protocol, APY, TVL, and contract before any commitment
polygon-agent deposit --asset USDC --amount <amount>
# Filter by protocol
polygon-agent deposit --asset USDC --amount <amount> --protocol aave
polygon-agent deposit --asset USDC --amount <amount> --protocol morphopolygon-agent deposit --asset USDC --amount <amount> --broadcast# POL → USDC before depositing
polygon-agent swap --from POL --to USDC --amount 1 --broadcastpolygon-agent balances| Protocol | Assets | Chain |
|---|---|---|
| Aave v3 | USDC, USDT, WETH, WMATIC | Polygon mainnet |
| Morpho Compound | USDC, WETH, POL | Polygon mainnet |
| Morpho (Gauntlet, Steakhouse, Yearn) | USDC, USDT, WETH | Katana |
These run automatically once your agent is deployed and set up.
| Task | Schedule | Description |
|---|---|---|
yield-monitor |
Every 6 hours | Checks current best APY vs open positions. Alerts if >1% better available. |
daily-report |
9am daily | Portfolio snapshot: balances, positions, estimated daily yield. |
The wallet session is scoped to the pre-whitelisted vault contracts. If you want to deposit into a vault not in the whitelist, dry-run first to get its address, then re-create the wallet with --contract <address> added.
manifest.json # Agent config and scheduled tasks
workspace/
SOUL.md # Agent principles and DeFi rules
TOOLS.md # Full CLI command reference and vault whitelist
AGENTS.md # Workspace conventions
IDENTITY.md # Agent name and vibe
HEARTBEAT.md # Periodic monitoring tasks
BOOTSTRAP.md # First-run setup guide (deleted after setup)
USER.md # Notes about the human (built over time)
memory/
yield-state.json # Open positions, recorded APY, deposit history
YYYY-MM-DD.md # Daily logs
| Error | Fix |
|---|---|
Deposit session rejected |
Pool contract not in whitelist — re-run wallet create with --contract <depositAddress> from dry-run |
Builder configured already |
Add --force to the setup command |
Missing SEQUENCE_PROJECT_ACCESS_KEY |
Run polygon-agent setup first |
Missing wallet |
Run wallet list, then wallet create |
Session expired |
Re-run wallet create (sessions last 6 months) |
swap: no route found |
Try a smaller amount or different pair |
- Polygon Agent CLI — on-chain operations, wallet management
- Trails — live pool discovery and DeFi routing
- Sequence — smart contract wallet infrastructure
- Pinata Agents — agent hosting and scheduling