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

# Auto-Deployment

> How idle capital is automatically deployed to yield protocols

## Overview

Auto-deployment is the process by which Idle Yield Router moves idle capital to yield-generating protocols. This happens automatically, requiring no user action.

## Deployment Flow

### Step 1: Idle Detection

Capital is considered idle when:

* Lend order placed but not matched
* Vault has excess cash buffer
* Position matured, awaiting re-deployment
* Order cancelled, funds pending return

### Step 2: Delay Period

Capital waits in holding before deployment:

| Scenario       | Delay     | Reason                        |
| -------------- | --------- | ----------------------------- |
| New lend order | 5 minutes | Allow time for quick matches  |
| Vault buffer   | 1 hour    | Absorb normal withdrawal flow |
| Post-maturity  | 5 minutes | Allow for auto-rollover       |

<Info>
  **Why the delay?** Deploying and recalling has overhead. Brief delays prevent unnecessary churn for capital that matches quickly.
</Info>

### Step 3: Protocol Selection

Idle Yield Router selects the optimal protocol:

```
Available Protocols:
├── Aave V3:     3.5% APY, $50M available
├── Compound V3: 3.2% APY, $30M available
├── DSR:         4.0% APY, $100M available
└── Spark:       3.8% APY, $25M available

Selection Logic:
1. Filter: All meet liquidity requirements ✓
2. Filter: All meet audit requirements ✓
3. Sort by yield: DSR (4.0%) > Spark (3.8%) > Aave (3.5%) > Compound (3.2%)
4. Select: DSR (highest yield)

Result: Deploy to DSR at 4.0% APY
```

### Step 4: Deployment Execution

Capital is deposited to the selected protocol:

```typescript theme={null}
// Simplified deployment flow
async function deployIdleCapital(amount: bigint, user: address) {
  // Select best protocol
  const protocol = await yieldRouter.selectProtocol(amount);

  // Deposit to protocol
  const receipt = await protocol.deposit(amount);

  // Track deployment
  await yieldRouter.recordDeployment({
    user,
    amount,
    protocol: protocol.address,
    receipt
  });
}
```

## Protocol Selection Algorithm

### Scoring Factors

| Factor              | Weight | Description                 |
| ------------------- | ------ | --------------------------- |
| Current APY         | 50%    | Higher yield preferred      |
| Available Liquidity | 25%    | Must support instant recall |
| Protocol Health     | 15%    | Utilization, reserves       |
| Diversification     | 10%    | Avoid over-concentration    |

### Example Scoring

```
Deploying: $100,000 USDC

Protocol Scores:
┌──────────┬───────┬───────────┬────────┬───────┬─────────┐
│ Protocol │ APY   │ Liquidity │ Health │ Divers│ TOTAL   │
├──────────┼───────┼───────────┼────────┼───────┼─────────┤
│ DSR      │ 50    │ 25        │ 15     │ 8     │ 98      │
│ Aave     │ 43    │ 25        │ 14     │ 10    │ 92      │
│ Spark    │ 47    │ 22        │ 13     │ 6     │ 88      │
│ Compound │ 40    │ 23        │ 12     │ 10    │ 85      │
└──────────┴───────┴───────────┴────────┴───────┴─────────┘

Winner: DSR (score 98)
```

### Diversification Rules

To avoid concentration risk:

| Rule                            | Limit                          |
| ------------------------------- | ------------------------------ |
| Max single protocol             | 60% of user's idle capital     |
| Max protocol utilization        | No deployment if >90% utilized |
| Min protocols for large amounts | >\$500k splits across 2+       |

## Deployment Monitoring

### Real-Time Tracking

Dashboard shows deployment status:

```
┌─────────────────────────────────────────────────────────┐
│                 Idle Yield Router Status                     │
├─────────────────────────────────────────────────────────┤
│ Idle Capital: $50,000                                   │
│                                                         │
│ Deployed:                                               │
│   DSR:        $30,000 (60%) @ 4.0% APY                 │
│   Aave:       $20,000 (40%) @ 3.5% APY                 │
│                                                         │
│ Blended Yield: 3.8% APY                                │
│ Daily Earnings: ~$5.21                                  │
│ Total Earned: $127.50                                   │
│                                                         │
│ Status: ● Active                                        │
└─────────────────────────────────────────────────────────┘
```

### Deployment Events

Track all deployment activity:

| Timestamp    | Action | Amount   | Protocol | APY  |
| ------------ | ------ | -------- | -------- | ---- |
| Mar 15 14:32 | Deploy | \$25,000 | DSR      | 4.0% |
| Mar 15 09:15 | Recall | \$10,000 | Aave     | 3.5% |
| Mar 14 16:45 | Deploy | \$10,000 | Aave     | 3.5% |
| Mar 14 11:20 | Deploy | \$15,000 | DSR      | 4.0% |

## Yield Accrual

### How Yield Accumulates

Yield accrues continuously:

```
Time: T+0 (deployment)
  Principal: $10,000
  Protocol: DSR @ 4.0% APY

Time: T+1 day
  Value: $10,001.10 (daily yield)

Time: T+7 days
  Value: $10,007.67 (week of yield)

Time: T+30 days
  Value: $10,032.88 (month of yield)
```

### Claiming Yield

Yield is automatically claimed when:

* Capital is recalled for order matching
* You manually withdraw from order book
* Position matures

No separate claim action needed.

## Gas Optimization

### Batch Deployments

Multiple users' capital batched together:

```
Individual Deployments:
  User A: $10,000 → Aave (1 tx)
  User B: $15,000 → Aave (1 tx)
  User C: $25,000 → Aave (1 tx)
  Total: 3 transactions

Batched Deployment:
  Users A+B+C: $50,000 → Aave (1 tx)
  Total: 1 transaction, 3x gas savings
```

### Timing Optimization

Deployments scheduled during low-gas periods when possible:

* Priority: Order matching always takes precedence
* Flexibility: Deployment timing flexible within delay window
* Monitoring: Gas price checked before deployment

## Edge Cases

### Protocol Rate Changes

If a protocol's rate drops significantly:

1. Monitor detects rate change
2. If better option available, rebalance triggered
3. Capital moved to higher-yield protocol
4. Rebalancing cost weighed against yield improvement

### Protocol Incidents

If a deployed protocol has an incident:

1. Immediate pause of new deployments
2. Recall of existing capital (if possible)
3. Fallback to remaining protocols
4. User notification

### Insufficient Liquidity

If deployment amount exceeds protocol capacity:

1. Deploy maximum available
2. Remainder stays in holding or splits to other protocol
3. Continue monitoring for capacity

## FAQs

<AccordionGroup>
  <Accordion title="Can I prevent my capital from being deployed?">
    Yes. Disable Idle Yield Router in your settings. Your capital will remain idle in the order book earning 0%.
  </Accordion>

  <Accordion title="What if I want to use a specific protocol?">
    The protocol manages all Idle Yield Router parameters, optimized for safety and yield. Individual users use protocol defaults.
  </Accordion>

  <Accordion title="Is deployed capital still available for matching?">
    Yes, absolutely. Deployed capital is recalled instantly when your order matches. The deployment is transparent to the matching process.
  </Accordion>

  <Accordion title="How often does rebalancing happen?">
    Only when yield differential justifies the cost (typically >50bps difference sustained for 24+ hours).
  </Accordion>
</AccordionGroup>

<Card title="Capital Recall" icon="rotate-left" href="./capital-recall">
  Learn how capital is instantly recalled for order matching
</Card>
