> ## 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.

# POST /v1/yield/prepare

> Prepare yield intents with execution calldata.

# POST /v1/yield/prepare

<Note>**Pricing policy** — \$0.01 per call via x402 when payment enforcement is enabled. Current pre-prod deployment keeps x402 disabled. When enforced, attach the `X-PAYMENT` header.</Note>

Prepare yield intents with execution calldata. Handles deposits, redemptions, and rebalances. Operations:

* deposit (default): Discover best vault, score, and return deposit calldata. For unconfigured EOAs, includes EIP-7702 setup.
* redeem: Build calldata for withdrawing from a vault position.
* rebalance: Move funds from one vault to a better one. Always returns the recommended vault strategy with APY, risk, and TVL data.

## Parameters

<ParamField body="operation" type="enum" optional>
  Operation type: deposit into vault, redeem from vault, or rebalance between vaults

  Allowed values: `deposit`, `redeem`, `rebalance`

  Default: `"deposit"`
</ParamField>

<ParamField body="asset" type="string" optional>
  Asset to deposit (e.g., "USDC"). Required for deposit.
</ParamField>

<ParamField body="amount" type="string" optional>
  Amount to deposit in human-readable form (e.g., "10000"). Required for deposit.
</ParamField>

<ParamField body="chain" type="enum" optional>
  Target chain

  Allowed values: active chain keys from `rhaios-config.yaml` for the deployment. Current pre-prod profile supports `ethereum` and `base`.

  Default: `"base"`
</ParamField>

<ParamField body="agentAddress" type="string" required>
  Agent's EOA address
</ParamField>

<ParamField body="vaultId" type="string" required>
  Target vault ID from yield\_discover. Required for all operations.
</ParamField>

<ParamField body="shares" type="string" optional>
  Number of shares to redeem (as string for BigInt). Provide shares or percentage, not both.
</ParamField>

<ParamField body="percentage" type="number" optional>
  Percentage of position to redeem. Provide shares or percentage, not both.
</ParamField>

## Example

```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"
  }'
```

With x402 payment (when enforced):

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

## Response

The response varies based on whether your wallet needs first-time EIP-7702 setup.

### Deposit — wallet already configured (`needsSetup: false`)

```json theme={null}
{
  "operation": "deposit",
  "intentId": "f3ab8fb8-4adb-4f0f-bcff-f38165d55f58",
  "needsSetup": false,
  "strategy": {
    "vaultName": "Aave V3 USDC",
    "expectedAPY": 0.162,
    "riskScore": "low",
    "protocol": "Aave V3",
    "chain": "base",
    "tvl": 45000000
  },
  "execution": {
    "intentEnvelope": {
      "version": "1",
      "intentId": "f3ab8fb8-4adb-4f0f-bcff-f38165d55f58",
      "chainId": 8453,
      "entryPoint": "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
      "sender": "0x...",
      "userOps": [{ "userOperation": { "sender": "0x...", "nonce": "0x1", "callData": "0x...", "signature": "0x1234" } }],
      "destinationExecutions": [],
      "expiry": 1739932000,
      "validAfter": 1739931100,
      "merkleRoot": "0x...",
      "proofs": [[]],
      "signing": { "domain": {}, "types": {}, "primaryType": "IntentEnvelope", "message": {} }
    },
    "to": "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
    "calldata": "0x...",
    "estimatedGas": "300000"
  }
}
```

### Deposit — first-time wallet, full setup (`needsSetup: true`, `setupType: "full"`)

```json theme={null}
{
  "operation": "deposit",
  "intentId": "a1b2c3d4-...",
  "needsSetup": true,
  "strategy": {
    "vaultName": "Aave V3 USDC",
    "expectedAPY": 0.162,
    "riskScore": "low"
  },
  "setup": {
    "setupType": "full",
    "description": "First-time EIP-7702 delegation + module initialization",
    "authorization": {
      "contractAddress": "0x...",
      "chainId": 8453
    },
    "initCalldata": "0x...",
    "to": "0x..."
  },
  "setupTicket": {
    "version": 1,
    "walletAddress": "0x...",
    "chainId": 8453,
    "implementation": "0x...",
    "initCalldataHash": "0x...",
    "setupType": "full",
    "expiresAt": "2025-03-01T00:00:00.000Z"
  }
}
```

### Deposit — module re-initialization (`needsSetup: true`, `setupType: "modules"`)

When delegation already exists but modules failed to initialize (e.g., `initializeAccount()` reverted silently in a prior setup attempt):

```json theme={null}
{
  "operation": "deposit",
  "intentId": "e5f6g7h8-...",
  "needsSetup": true,
  "strategy": {
    "vaultName": "Aave V3 USDC",
    "expectedAPY": 0.162,
    "riskScore": "low"
  },
  "setup": {
    "setupType": "modules",
    "description": "Module initialization only. Delegation already active — send as regular transaction (type 2), not Type-4.",
    "authorization": null,
    "initCalldata": "0x...",
    "to": "0x..."
  },
  "setupTicket": {
    "version": 1,
    "walletAddress": "0x...",
    "chainId": 8453,
    "implementation": "0x...",
    "initCalldataHash": "0x...",
    "setupType": "modules",
    "expiresAt": "2025-03-01T00:00:00.000Z"
  }
}
```

When `needsSetup` is `true`, sign and submit the setup transaction first, then call `POST /v1/yield/prepare` again to get the execution payload. For `setupType: "full"`, sign a Type-4 (EIP-7702) transaction with authorization\_list. For `setupType: "modules"`, sign a regular Type-2 (EIP-1559) self-call transaction.

### Redeem

```json theme={null}
{
  "operation": "redeem",
  "intentId": "2db20fca-a844-442c-9267-624f47b2f1f7",
  "needsSetup": false,
  "execution": {
    "intentEnvelope": { "version": "1", "chainId": 8453, "userOps": [{ "userOperation": { "sender": "0x...", "callData": "0x..." } }], "merkleRoot": "0x...", "proofs": [[]] },
    "to": "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
    "calldata": "0x...",
    "estimatedGas": "250000"
  }
}
```
