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

# Blend to DeFindex

Moves a user's Blend USDC lending position into a DeFindex vault. Mainnet only.

Two steps, and the first is optional:

1. **(Optional) Recover BLND rewards.** If your users have accrued BLND emissions on Blend and you want to sweep them into a wallet before migrating, call `POST /migration/claim-blnd` first. If you do not care about the BLND rewards, skip this step.
2. **Migrate the USDC position.** Call `POST /migration/blend-to-defindex` to atomically withdraw the user's full Blend USDC position and deposit it into a DeFindex vault.

Each call returns one XDR. Have the user sign it, submit it, wait for confirmation, then move on to the next step.

## `POST /migration/claim-blnd`

Claims the user's first available BLND claimable balance (the standard place Blend leaves emission rewards) and forwards the BLND to a destination wallet. The returned transaction wraps the claim and payment between an open-trustline and a close-trustline operation, so the user does not need to keep a permanent BLND trustline on their account.

```json theme={null}
{
  "from": "G...",
  "destination": "G..."
}
```

| Field         | Type   | Required | Notes                                                                                                                                                           |
| ------------- | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `from`        | string | yes      | User's Stellar public key. This account must sign the returned XDR.                                                                                             |
| `destination` | string | no       | Wallet that receives the claimed BLND. If omitted, the BLND is sent to a DeFindex-operated fallback address, so always pass the wallet you want the rewards in. |

Response:

```json theme={null}
{
  "xdr": "AAAAAg...",
  "balanceId": "0000000071f...",
  "amount": "1234.5678901",
  "destination": "G..."
}
```

`amount` is the BLND being forwarded, formatted with 7 decimal places. Surface it to the user before they sign.

One thing to watch: this XDR is a **classic Stellar transaction**, not a Soroban one. Submit it directly to Horizon; the `POST /send` endpoint will not accept it.

Errors: `400` when an address is invalid, `404` when the user has no BLND claimable balance or the account does not exist.

## `POST /migration/blend-to-defindex`

Atomically withdraws the user's **full** Blend USDC position and deposits the proceeds into a DeFindex vault, in a single signed transaction. The endpoint reads the user's Blend position on-chain and computes the exact withdrawal amount on the server side, handling the small interest accrual that happens between simulation and submission so the user always receives at least what was simulated. Your client only passes two addresses:

```json theme={null}
{
  "from": "G...",
  "vaultAddress": "C..."
}
```

| Field          | Type   | Required | Notes                                                               |
| -------------- | ------ | -------- | ------------------------------------------------------------------- |
| `from`         | string | yes      | User's Stellar public key. This account must sign the returned XDR. |
| `vaultAddress` | string | yes      | DeFindex vault contract address that receives the deposit.          |

Response:

```json theme={null}
{
  "xdr": "AAAAAg...",
  "simulationResponse": [ ],
  "functionName": "exec",
  "operationXDR": "AAAAEA...",
  "isSmartWallet": false
}
```

`simulationResponse` carries the decoded return values of the simulated transaction, useful for previewing the result to the user before they sign. `operationXDR` is the raw operation, in case you need to rebuild the transaction with a different fee or timeout. Sign `xdr` and submit it through your own RPC or `POST /send`.

Errors: `400` when an address is invalid or the user holds both a supply and a collateral position at once (contact us if you hit this for a real user), `404` when the user has no Blend USDC position to migrate.
