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

# Plan Reinvest Rewards

> Create a plan to claim rewards, swap them, and resupply

# Plan Reinvest Rewards

Creates a plan that atomically claims protocol rewards, swaps them into the supply asset, and resupplies into the protocol. This automates the "reinvest rewards" flow in a single transaction. Returns a plan ID and an EIP-712 digest that must be signed to authorize execution.

## Request

```
POST /accounts/:account_id/plan/reinvest_rewards
```

### Path parameters

| Parameter    | Type   | Description        |
| ------------ | ------ | ------------------ |
| `account_id` | string | The sub-account ID |

### Body parameters

| Parameter       | Type      | Required | Description                                                |
| --------------- | --------- | -------- | ---------------------------------------------------------- |
| `asset`         | string    | Yes      | The supply asset to compound into (e.g., `"USDC"`)         |
| `protocol`      | string    | Yes      | Protocol: `"compound"`, `"aave"`, or `"morpho_vault"`      |
| `network`       | string    | Yes      | Network name (e.g., `"base"`, `"mainnet"`)                 |
| `reward_assets` | string\[] | Yes      | List of reward assets to claim and swap (e.g., `["COMP"]`) |
| `market`        | string    | No       | Market reference (required for `morpho_vault`)             |

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/plan/reinvest_rewards \
    -H "Authorization: Bearer $LEGEND_QUERY_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "asset": "USDC",
      "protocol": "compound",
      "network": "base",
      "reward_assets": ["COMP"]
    }'
  ```

  ```typescript TypeScript theme={null}
  const plan = await client.plan.reinvestRewards("acc_2o0yiljtp378", {
    asset: "USDC",
    protocol: "compound",
    network: "base",
    rewardAssets: ["COMP"],
  });
  ```

  ```python Python theme={null}
  plan = await client.plan.reinvest_rewards(
      "acc_2o0yiljtp378",
      asset="USDC",
      protocol="compound",
      network="base",
      reward_assets=["COMP"],
  )
  ```

  ```rust Rust theme={null}
  use legend_client::ReinvestRewardsParams;

  let plan = client.plan.reinvest_rewards("acc_2o0yiljtp378", &ReinvestRewardsParams {
      asset: "USDC".into(),
      protocol: "compound".into(),
      network: "base".into(),
      reward_assets: vec!["COMP".into()],
      ..Default::default()
  }).await?;
  ```
</CodeGroup>

```json Response (201 Created) theme={null}
{
  "plan_id": "pln_71mcui082png",
  "details": {
    "quark_operation_actions": [...],
    "eip712_data": {
      "digest": "0x8a3f...b7c2",
      "domain_separator": "0x...",
      "hash_struct": "0x..."
    }
  },
  "expires_at": "2025-06-15T10:32:00Z"
}
```

### Response fields

| Field                        | Type   | Description                                                 |
| ---------------------------- | ------ | ----------------------------------------------------------- |
| `plan_id`                    | string | Unique identifier for this plan (`pln_` prefix)             |
| `details`                    | object | Transaction details including EIP-712 signing data          |
| `details.eip712_data.digest` | string | The hash to sign with the account's signer key              |
| `expires_at`                 | string | ISO 8601 timestamp — plan must be executed before this time |

## Errors

| Status | Code                | Description                                                                |
| ------ | ------------------- | -------------------------------------------------------------------------- |
| 400    | `invalid_params`    | Missing required parameters, unsupported protocol, or empty reward\_assets |
| 400    | `plan_failed`       | Could not generate a valid plan (e.g., no rewards to claim)                |
| 400    | `no_wallet`         | Account has no wallets                                                     |
| 408    | `timeout`           | Folio computation timed out                                                |
| 422    | `swap_quote_failed` | Could not fetch a swap quote for one of the reward assets                  |

## Notes

* Plans expire after 2 minutes. Sign and execute via [Execute Plan](/api-reference/plan-execute) before expiry.
* The claim, swap, and supply all happen atomically in a single transaction.
* Each reward asset in the list generates a separate claim and swap operation.
* A 0.15% Legend fee is applied to the buy side of each swap quote.
* When using `morpho_vault` as the protocol, you must provide the `market` parameter.
