Docs

Exit an illiquid vault in kind

Build in-kind exits for Morpho Vault V1 and V2 when borrowed assets limit normal withdrawals, with API and SDK options for Vault V2.

In-kind redemption is the fallback exit for the part of a vault position that cannot be returned through a normal withdrawal because the underlying liquidity is borrowed. It transfers the vault's exposure instead of manufacturing liquidity.

For the Python examples, install Requests with pip install requests.

Prefer a normal withdraw or redeem while the vault can return the underlying asset. Use this flow only for an illiquid remainder, and show the user the assets and market positions they will receive before requesting a signature.

Before you begin

VaultUser receivesAmountRequired shape
Vault V1Ordered Morpho Blue supply positions.Asset-denominated exit amount.A caller-ordered list of enabled vault markets consumed greedily.
Vault V2Available idle assets first, then ordered Morpho Blue supply positions net of the force-deallocation penalty.Penalty-inclusive, asset-denominated exit amount.Exactly one MorphoMarketV1AdapterV2; ordered markets are consumed after idle assets.

The SDK does not validate the user's share balance. For Vault V1, size amount against the vault contract's previewRedeem(sharesHeld); for Vault V2, keep amount + BigInt(marketParamsList.length) <= previewRedeem(sharesHeld) because each market needs a one-asset withdrawal-rounding buffer. getRequirements() reuses sufficient share allowances or requests an unlimited approval or ERC-2612 vault-share permit. Its minimum covers V1 fee accrual and version-specific loss handling, or V2 rounding and deadline-accrual buffers. Neither exit has an on-chain share-burn bound; a share-price drop before inclusion can burn more shares than quoted. Simulate the final transaction after authorization because Vault V2 gates and snapshot drift are not fully preflighted.

Vault V2 Redeem In-Kind prepares and simulates the exit in one POST. There is no separate Actions preview route. Set VAULT_SELECTOR and MARKET_SELECTOR to chain-qualified selectors for the vault and a Morpho Blue market it allocates, on the same chain. Set ACCOUNT to the user's wallet and keep MORPHO_API_KEY in your backend environment. This example assumes a six-decimal asset: 1000000 is a penalty-inclusive exit of one token.

curl --silent --show-error --include \
  --request POST \
  "https://private.api.morpho.org/v0/actions/vaults-v2/${VAULT_SELECTOR:?Set VAULT_SELECTOR}/redeem-in-kind" \
  --header "x-api-key: ${MORPHO_API_KEY:?Set MORPHO_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data "{
    \"account\": \"${ACCOUNT:?Set ACCOUNT}\",
    \"amount\": { \"unit\": \"assets\", \"value\": \"1000000\" },
    \"market\": \"${MARKET_SELECTOR:?Set MARKET_SELECTOR}\",
    \"max_penalty_bps\": 200,
    \"signature_mode\": \"none\"
  }"
Response fieldPreview check
data.status, data.actionRequire prepared and vault_v2.redeem_in_kind.
data.simulation.statusRequire success; a failed simulation has no executable calls.
data.simulation.effectsShow wallet_assets, supplied_assets, and penalty_assets. These are simulated, not guaranteed execution amounts.
data.simulation.position_changesInspect vault_shares and market_supply_shares.
data.callsThe preparation already contains ordered approval and redemption calls, not just a quote.

The amount must be exact; the API does not silently shrink an unsupported exit. The selected market must have enough capacity. Vaults containing a Midnight adapter are unsupported. Handle 422 ACTION_UNSUPPORTED by selecting a supported amount or market, not by submitting a failed preparation.

max_penalty_bps: 200 allows a 2% preparation-time penalty. If the current penalty is below 2% and its setter is not abdicated, this field must cover the whole-exit worst case even with a setter timelock: a queued change may become executable before expiry. The cap is checked during preparation and continuation, never enforced onchain. Execution recomputes the penalty and idle/in-kind split.

The user's wallet sends the returned calls, in order, only after checking the simulation and verifying the signed proof, with user approval. Morpho does not submit transactions.

Complete the Morpho SDK setup before using this SDK example.

The examples assume a private-key signer for a backend integration. In a frontend, construct the wallet client from the connected provider but keep the same invariant: the account that builds the action signs its requirements and submits the final transaction.

import { parseAbi, publicActions, type Address } from "viem";

const publicClient = client.extend(publicActions);
const userAddress = account.address;
const vaultV1Address = process.env.VAULT_V1_ADDRESS as Address;
const vaultV2Address = process.env.VAULT_V2_ADDRESS as Address;
const vaultReadAbi = parseAbi([
  "function balanceOf(address account) view returns (uint256)",
  "function previewRedeem(uint256 shares) view returns (uint256)",
]);
import { previewVaultV2InKindRedeem } from "@morpho-org/morpho-sdk";

const vaultV2 = client.morpho.vaultV2(vaultV2Address, mainnet.id);
const [vaultV2Data, latestBlock, sharesHeld] = await Promise.all([
  vaultV2.getData(),
  publicClient.getBlock(),
  publicClient.readContract({
    address: vaultV2Address,
    abi: vaultReadAbi,
    functionName: "balanceOf",
    args: [userAddress],
  }),
]);
const maximumRedeemAssets = await publicClient.readContract({
  address: vaultV2Address,
  abi: vaultReadAbi,
  functionName: "previewRedeem",
  args: [sharesHeld],
});
// This example passes one market, so reserve the one-asset V2 rounding buffer.
const marketRoundingBuffer = 1n;
if (maximumRedeemAssets <= marketRoundingBuffer) {
  throw new Error("Vault V2 position is too small for in-kind redemption");
}
const requestedExitAssets = maximumRedeemAssets - marketRoundingBuffer;
const [marketChoice] = previewVaultV2InKindRedeem(vaultV2Data, {
  requestedExitAssets,
  timestamp: latestBlock.timestamp,
});

if (marketChoice == null) {
  throw new Error("No supported Vault V2 in-kind redemption choice");
}

console.log({
  marketParams: marketChoice.marketParams,
  maxExitAssets: marketChoice.maxExitAssets,
  exitAssets: marketChoice.exitAssets,
  remainingExitAssets: marketChoice.remainingExitAssets,
  idleAssets: marketChoice.idleAssets,
  netAssets: marketChoice.netAssets,
  feeAssets: marketChoice.feeAssets,
});
// This example executes one market choice. Rebuild from fresh state for any
// remainingExitAssets after the transaction confirms.

Reuse the prepared response from the API preview above. If the user changes the amount or selected market, make a fresh Vault V2 Redeem In-Kind request instead. Using the same backend environment variables, the request is:

curl --silent --show-error --include \
  --request POST \
  "https://private.api.morpho.org/v0/actions/vaults-v2/${VAULT_SELECTOR:?Set VAULT_SELECTOR}/redeem-in-kind" \
  --header "x-api-key: ${MORPHO_API_KEY:?Set MORPHO_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data "{
    \"account\": \"${ACCOUNT:?Set ACCOUNT}\",
    \"amount\": { \"unit\": \"assets\", \"value\": \"1000000\" },
    \"market\": \"${MARKET_SELECTOR:?Set MARKET_SELECTOR}\",
    \"max_penalty_bps\": 200,
    \"signature_mode\": \"none\"
  }"
Response fieldAuthorization check
data.statusRequire prepared; handle signature_required through the continuation flow before expecting calls.
data.simulation.statusRequire success; do not send anything for simulation_failed.
data.callsWith signature_mode: "none", send any approval before the final redemption, in the returned order. Inspect persistent allowances as well as the action.
data.simulation.effectsRecheck the wallet assets, supplied market assets, and penalty against user approval.

The user's wallet sends the returned calls, in order, only after checking the simulation and verifying the signed proof, with user approval. Morpho does not submit transactions.

Do not send both the preview's calls and a newly prepared copy of the same exit. Respect the response expiry and reprepare when inputs change. The penalty cap is a preparation check, not an onchain bound; execution can change the penalty and the assets/position split.

Complete the Morpho SDK setup before using this SDK example.

import {
  isRequirementSignature,
  type RequirementSignature,
} from "@morpho-org/morpho-sdk";

// Reuse the selected market and fresh snapshot from the SDK preview above.
const vaultV2 = client.morpho.vaultV2(vaultV2Address, mainnet.id);
const vaultV2Exit = vaultV2.inKindRedeem({
  amount: marketChoice.exitAssets,
  marketParamsList: [marketChoice.marketParams],
  vaultData: vaultV2Data,
  userAddress,
});
const vaultV2Signatures: RequirementSignature[] = [];

// A sufficient share allowance is reused; otherwise approval or permit is unlimited.
// The minimum allowance is not an on-chain share-burn bound.
for (const requirement of await vaultV2Exit.getRequirements()) {
  if (isRequirementSignature(requirement)) {
    vaultV2Signatures.push(await requirement.sign(client, userAddress));
  } else {
    const hash = await client.sendTransaction(requirement);
    await publicClient.waitForTransactionReceipt({ hash });
  }
}

const vaultV2Tx = vaultV2Exit.buildTx(vaultV2Signatures);
// Simulate after authorization to check gates and post-snapshot state.
await publicClient.call({
  account: userAddress,
  to: vaultV2Tx.to,
  data: vaultV2Tx.data,
  value: vaultV2Tx.value,
});
const vaultV2Hash = await client.sendTransaction(vaultV2Tx);
await publicClient.waitForTransactionReceipt({ hash: vaultV2Hash });
console.log("Vault V2 in-kind redemption confirmed:", vaultV2Hash);

If the preview reports a non-zero remainder, do not append another preview row to the same call: each row is an alternative single-market choice. Complete the selected partial exit, fetch a new vault snapshot, and preview the remainder again, or build an ordered multi-market list only if your integration independently validates the combined coverage.

Prepare a Vault V1 exit

Vault V1 has no single-market preview helper. Build its ordered market list from the fresh vault snapshot, then let the entity validate coverage before resolving requirements.

const vaultV1 = client.morpho.vaultV1(vaultV1Address, mainnet.id);
const [vaultV1Data, vaultV1SharesHeld] = await Promise.all([
  vaultV1.getData(),
  publicClient.readContract({
    address: vaultV1Address,
    abi: vaultReadAbi,
    functionName: "balanceOf",
    args: [userAddress],
  }),
]);
const vaultV1ExitAssets = await publicClient.readContract({
  address: vaultV1Address,
  abi: vaultReadAbi,
  functionName: "previewRedeem",
  args: [vaultV1SharesHeld],
});
const marketParamsList = [...vaultV1Data.allocations.values()]
  .filter(
    ({ config, position }) =>
      config.enabled && position.supplyShares > 0n,
  )
  .map(({ position }) => position.market.params);

// The allocations Map is unique by market id. Repeated entries cannot spend
// the same vault position twice.
const vaultV1Exit = vaultV1.inKindRedeem({
  amount: vaultV1ExitAssets,
  marketParamsList,
  vaultData: vaultV1Data,
  userAddress,
});

Authorize, simulate, and submit a Vault V1 exit

import {
  isRequirementSignature,
  type RequirementSignature,
} from "@morpho-org/morpho-sdk";

const vaultV1Signatures: RequirementSignature[] = [];
for (const requirement of await vaultV1Exit.getRequirements()) {
  if (isRequirementSignature(requirement)) {
    vaultV1Signatures.push(await requirement.sign(client, userAddress));
  } else {
    const hash = await client.sendTransaction(requirement);
    await publicClient.waitForTransactionReceipt({ hash });
  }
}

const vaultV1Tx = vaultV1Exit.buildTx(vaultV1Signatures);
await publicClient.call({
  account: userAddress,
  to: vaultV1Tx.to,
  data: vaultV1Tx.data,
  value: vaultV1Tx.value,
});
const vaultV1Hash = await client.sendTransaction(vaultV1Tx);
await publicClient.waitForTransactionReceipt({ hash: vaultV1Hash });
console.log("Vault V1 in-kind redemption confirmed:", vaultV1Hash);

Recover from rejected previews or transactions

ErrorMeaningRecovery
VaultV2SingleAdapterRequiredErrorThe Vault V2 snapshot does not contain exactly one adapter.Use another exit path; in-kind redemption supports one MorphoMarketV1AdapterV2.
InKindRedeemZeroDeallocationErrorWith no idle assets, the penalty-adjusted exit rounds to zero deallocated assets.Increase the amount or use another exit path.
EmptyMarketParamsListErrorMarkets are required but the ordered list is empty.Supply enough current vault markets to cover the non-idle exit.
InKindRedeemCoverageErrorThe ordered markets cannot cover the requested exit without exceeding a vault position.Reduce the amount to the error's maxExitAssets or rebuild with sufficient current markets.
ExpiredDeadlineErrorThe deadline has passed at action creation or requirement resolution.Rebuild the action and resolve its requirements again.
InsufficientBlueBalanceForInKindRedeemErrorMorpho Blue cannot fund the required flash loan or largest callback.Reduce the amount or wait for Blue liquidity.
UnknownAddressErrorVaultExitBundlesV1 is not registered for the selected chain.Register a custom deployment or use a chain with a canonical deployment.
VaultIsBlueFeeRecipientErrorA Vault V1 is Morpho Blue's fee recipient, whose accrued fee shares cannot be safely accounted for.Use another exit path.
BundlesPermitMismatchErrorThe supplied permit has the wrong kind, asset, or signature encoding.Rebuild the action and sign its new vault-exit permit.

RPC or multicall failures surface as viem.BaseError; after any quote-time or submission failure, fetch a fresh snapshot and rebuild the action instead of reusing the old transaction.

For the complete mechanics, parameter table, and error surface, see the Morpho SDK vault reference.