> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# Treasury yield sweep

> Sweep idle USDC into Aave v3, Morpho, or ERC-4626 vaults from the CLI. Withdraw on a schedule before the next disbursement run.

A treasury wallet rarely uses all its balance at once. Between payouts, x402 spend, and operating reserve, a meaningful slice sits idle. Idle USDC earning zero is a cost. The Agent CLI sweeps that idle balance into Trails earn pools (Aave v3, Morpho, ERC-4626 vaults) in one command, and pulls it back the same way before the next disbursement cycle. Dry-run by default, broadcast when finance signs off.

The CLI handles pool discovery (highest TVL by default), session-scoped contract permissions (set once at wallet creation with `--defi`), and the underlying Trails routing. No multisig coordination, no DEX UI, no signature-collection step.

**Who this is for:**

* Treasurers at platforms running agent fleets with weekly or monthly disbursement cycles
* Crypto-native businesses holding USDC working capital
* Operations teams looking for predictable yield on operating reserves

***

## How it works

<div style={{border:"1px solid #C8CFE1",borderRadius:"12px",overflow:"hidden",marginBottom:"24px"}}>
  <div style={{background:"linear-gradient(180deg,#EAE4F5 0%,#F6F3FB 100%)",borderBottom:"1px solid #D5C4F2",padding:"10px 16px",fontSize:"11px",fontWeight:"700",color:"#670DE5",letterSpacing:"0.06em",textTransform:"uppercase"}}>Sweep and exit cycle</div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>1</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>Operator</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>CLI</span>
    <span style={{fontFamily:"'Geist Mono',ui-monospace,monospace",fontSize:"12px",color:"#141635"}}>polygon-agent deposit --asset USDC --amount 50000 (dry-run)</span>
  </div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>2</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>CLI</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>Trails</span>
    <span style={{fontSize:"13px",color:"#141635"}}>Selects highest-TVL pool, returns projected APY</span>
  </div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>3</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>Operator</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>CLI</span>
    <span style={{fontFamily:"'Geist Mono',ui-monospace,monospace",fontSize:"12px",color:"#141635"}}>Re-runs with --broadcast after finance review</span>
  </div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>4</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>Smart wallet</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>Aave / Morpho</span>
    <span style={{fontSize:"13px",color:"#141635"}}>Deposits, accrues yield, holds aToken or vault share</span>
  </div>

  <div style={{padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>5</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>Operator</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>CLI</span>
    <span style={{fontFamily:"'Geist Mono',ui-monospace,monospace",fontSize:"12px",color:"#141635"}}>polygon-agent withdraw --asset USDC --amount max --broadcast</span>
  </div>
</div>

The wallet must be created with `--defi` (or with explicit `--contract` flags listing the pool and the asset token) so the smart wallet can interact with Aave v3, Morpho, and ERC-4626 vaults without re-approval. Without that, deposit and withdraw fail at dry-run with a session-rejection error.

***

## Get started

Two CLI commands drive the cycle: `deposit` into the highest-TVL pool by default (override with `--protocol aave` or `--protocol morpho`), and `withdraw --amount max` for a clean exit before the next disbursement run. Both are dry-run by default.

### Install

```bash theme={null}
npm install -g @polygonlabs/agent-cli
polygon-agent setup --name "treasury"
polygon-agent wallet create --defi --usdc-limit 50000
```

The `--defi` flag is required at wallet creation so the smart wallet can interact with Aave v3, Morpho, and ERC-4626 vaults without re-approval. Without it, `deposit` and `withdraw` fail at dry-run.

### Drive it from an LLM

```text theme={null}
Read https://agentconnect.polygon.technology/SKILL.md and deposit my idle USDC into the highest-TVL lending vault on Polygon and report the APY and pool address. Then set up a daily cron job to automatically re-evaluate and deposit into the best vault each morning.
```

### Run the commands directly

```bash theme={null}
# Sweep idle USDC (dry-run first, review APY and pool, then broadcast)
polygon-agent deposit --asset USDC --amount 5000 --protocol aave
polygon-agent deposit --asset USDC --amount 5000 --protocol aave --broadcast

# Exit before the next disbursement run
polygon-agent withdraw --asset USDC --amount max --protocol aave --broadcast
```

Full reference: [Swaps and yield](/payment-services/agentic-payments/cli/swaps-and-yield).

***

## Implementation

<CardGroup cols={2}>
  <Card title="Swaps and yield" icon="arrow-right-arrow-left" href="/payment-services/agentic-payments/cli/swaps-and-yield">
    Full reference for `deposit`, `withdraw`, and `swap` against Trails earn pools.
  </Card>

  <Card title="Setup and wallets" icon="key" href="/payment-services/agentic-payments/cli/setup-and-wallets">
    Pass `--defi` at wallet creation to enable yield operations.
  </Card>

  <Card title="Trails" icon="route" href="/trails/index">
    The underlying earn-pool router.
  </Card>
</CardGroup>
