> ## 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 Loop Long

> Create a plan to open or increase a leveraged long position

# Plan Loop Long

Creates a plan to open or increase a leveraged long position on a Morpho market. Looping borrows the backing asset, swaps it for the exposure asset, and supplies it as collateral — repeatedly — to achieve leverage. Returns a plan ID and an EIP-712 digest that must be signed to authorize execution.

## Request

```
POST /accounts/:account_id/plan/loop-long
```

### Path parameters

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

### Body parameters

| Parameter                     | Type    | Required | Description                                                                                    |
| ----------------------------- | ------- | -------- | ---------------------------------------------------------------------------------------------- |
| `exposure_asset`              | string  | Yes      | Asset to go long on (e.g., `"WETH"`)                                                           |
| `backing_asset`               | string  | Yes      | Asset used as loan currency (e.g., `"USDC"`)                                                   |
| `market_id`                   | string  | Yes      | Morpho market ID (0x-prefixed 32-byte hex)                                                     |
| `is_increase`                 | boolean | Yes      | `true` to open/increase position, `false` to adjust existing                                   |
| `exposure_amount`             | string  | Yes      | Target exposure amount in the asset's smallest unit                                            |
| `max_swap_backing_amount`     | string  | Yes      | Maximum backing asset to use in swaps                                                          |
| `max_provided_backing_amount` | string  | Yes      | Maximum backing asset to supply as collateral                                                  |
| `pool_fee`                    | integer | Yes      | Uniswap pool fee tier (e.g., `500`, `3000`, `10000`)                                           |
| `network`                     | string  | Yes      | Target network (e.g., `"base"`, `"mainnet"`). Funds on other chains are bridged automatically. |

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://prime-api.legend.xyz/accounts/acc_2o0yiljtp378/plan/loop-long \
    -H "Authorization: Bearer $LEGEND_QUERY_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "exposure_asset": "WETH",
      "backing_asset": "USDC",
      "market_id": "0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc",
      "is_increase": true,
      "exposure_amount": "1000000000000000000",
      "max_swap_backing_amount": "5000000000",
      "max_provided_backing_amount": "1000000000",
      "pool_fee": 500,
      "network": "base"
    }'
  ```

  ```typescript TypeScript theme={null}
  const plan = await client.plan.loopLong("acc_2o0yiljtp378", {
    exposureAsset: "WETH",
    backingAsset: "USDC",
    marketId: "0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc",
    isIncrease: true,
    exposureAmount: "1000000000000000000",
    maxSwapBackingAmount: "5000000000",
    maxProvidedBackingAmount: "1000000000",
    poolFee: 500,
    network: "base",
  });
  ```

  ```python Python theme={null}
  plan = await client.plan.loop_long(
      "acc_2o0yiljtp378",
      exposure_asset="WETH",
      backing_asset="USDC",
      market_id="0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc",
      is_increase=True,
      exposure_amount="1000000000000000000",
      max_swap_backing_amount="5000000000",
      max_provided_backing_amount="1000000000",
      pool_fee=500,
      network="base",
  )
  ```

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

  let plan = client.plan.loop_long("acc_2o0yiljtp378", &LoopLongParams {
      exposure_asset: "WETH".into(),
      backing_asset: "USDC".into(),
      market_id: "0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc".into(),
      is_increase: true,
      exposure_amount: "1000000000000000000".into(),
      max_swap_backing_amount: "5000000000".into(),
      max_provided_backing_amount: "1000000000".into(),
      pool_fee: 500,
      network: "base".into(),
  }).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 or invalid market ID |
| 400    | `plan_failed`    | Could not generate a valid plan                  |
| 400    | `no_wallet`      | Account has no wallets                           |
| 408    | `timeout`        | Folio computation timed out                      |

## Notes

* Plans expire after 2 minutes. Sign and execute via [Execute Plan](/api-reference/plan-execute) before expiry.
* The `market_id` must be a valid Morpho market ID (0x-prefixed 32-byte hex).
* Common `pool_fee` values: `500` (0.05%), `3000` (0.3%), `10000` (1%). These correspond to Uniswap V3 fee tiers.
* Use [Plan Unloop Long](/api-reference/plan-unloop-long) to close or reduce the position.
