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

# Yield Lifecycle

> The end-to-end flow from preparing an intent to tracking yield.

# Yield Lifecycle

Every yield operation follows the same pattern: **prepare, sign, execute, track**.

```mermaid theme={null}
graph LR
    A[Prepare] --> B[Sign]
    B --> C[Execute]
    C --> D[Track]
    D -->|Redeem/Rebalance| A
```

## 1. Prepare

Call `POST /v1/yield/prepare` with an operation and your agent address. Rhaios returns strategy data plus setup/execution payloads.

```bash theme={null}
curl -X POST https://api.staging.rhaios.com/v1/yield/prepare \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "deposit",
    "asset": "USDC",
    "amount": "1000",
    "agentAddress": "0x...",
    "vaultId": "42"
  }'
```

The response includes `intentId`, `needsSetup`, and strategy metadata. If setup is needed, a setup block is returned (`intentEnvelope: null`); otherwise an execution block with `intentEnvelope` is returned.

## 2. Sign

If `intentEnvelope` is present, your agent signs `intentEnvelope.signing` with its own key (EIP-712).
If `needsSetup=true`, execute the returned setup transaction first, then call `POST /v1/yield/prepare` again to get an executable `intentEnvelope`. The setup transaction type depends on `setup.setupType`:

* `"full"`: Sign a Type-4 (EIP-7702) transaction with authorization\_list for first-time delegation + module initialization.
* `"modules"`: Sign a regular Type-2 (EIP-1559) self-call to re-initialize modules when delegation already exists.

## 3. Execute

Pass the signed envelope to `POST /v1/yield/execute`.

```bash theme={null}
curl -X POST https://api.staging.rhaios.com/v1/yield/execute \
  -H "Content-Type: application/json" \
  -d '{
    "intentEnvelope": {
      "version": "1",
      "chainId": 8453,
      "userOps": [{ "userOperation": { "sender": "0x...", "nonce": "0x1", "callData": "0x...", "signature": "0x..." } }],
      "destinationExecutions": [],
      "expiry": 1739932000,
      "validAfter": 1739931100,
      "merkleRoot": "0x...",
      "proofs": [[]]
    },
    "intentSignature": "0x...",
    "intentId": "0x<same-as-merkleRoot>"
  }'
```

Rhaios validates and submits through the bundler path. `intentId` is optional and must match `intentEnvelope.merkleRoot` when present. The intent signer must match `intentEnvelope.userOps[0].userOperation.sender`.

## 4. Track

Call `GET /v1/yield/status` to monitor your positions.

```bash theme={null}
curl "https://api.staging.rhaios.com/v1/yield/status?userAddress=0x..."
```

Returns all active positions with current value, unrealized yield, and APY.

Use `GET /v1/yield/history` to see historical APY data for any vault.

```bash theme={null}
curl "https://api.staging.rhaios.com/v1/yield/history?vaultId=42&period=30d"
```

## 5. Withdraw

When ready to exit, call `POST /v1/yield/prepare` with `operation: "redeem"` to prepare withdrawal calldata.

```bash theme={null}
curl -X POST https://api.staging.rhaios.com/v1/yield/prepare \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "redeem",
    "vaultId": "42",
    "percentage": 100,
    "agentAddress": "0x..."
  }'
```

Then sign and pass the result to `POST /v1/yield/execute` — same flow as depositing.

You can also rebalance between vaults using `operation: "rebalance"`, which atomically redeems from one vault and deposits into a better one.
