> For the complete documentation index, see [llms.txt](https://docs.kpk.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kpk.io/vaults/vault-integration/integration/morpho.md).

# Morpho

How to integrate KPK Morpho vaults, with Morpho SDK code for deposits and withdrawals, direct ERC-4626 calls, Merkl reward claims, and how to request a Morpho Fee Wrapper for distribution partners.

This page covers the Morpho-specific nuances of integrating KPK vaults: the Morpho SDK, direct contract calls, and the Morpho Fee Wrapper. For the general integrator overview and audience-routing, start at the [Integration page](/vaults/vault-integration/integration.md).

End-users who simply want to deposit should use the [Morpho UI](https://app.morpho.org/) directly. Vault addresses, supported assets, and current parameters are listed on each [vault page](/vaults/vaults/morpho.md).

{% hint style="info" %}
**Where deposits end up:** KPK Morpho v2 vaults route deposits through the [**Markets V1 Adapter**](https://docs.morpho.org/get-started/resources/contracts/morpho-market-v1-adapter-v2#morphomarketv1adapterv2) directly into individual Morpho v1 markets. Integrators tracing the flow of funds should follow the adapter address listed on each vault page (under **Key information**) to see the markets the v2 vault is currently allocated to.
{% endhint %}

### Integrating via the Morpho SDK

The Morpho SDK handles contract interactions, approvals, slippage protection, and transaction construction. It returns ready-to-send transaction objects so the integrator focuses on UX, not low-level encoding.

#### 1. Install and instantiate

```bash
npm install @morpho-org/morpho-sdk
```

```typescript
import { MorphoClient } from "@morpho-org/morpho-sdk";
import { mainnet } from "viem/chains";

const morpho = new MorphoClient(walletClient, {
  supportSignature: true,
  supportDeployless: false,
});

// KPK USDC Prime on Ethereum
const vault = morpho.vaultV2(
  "0x4Ef53d2cAa51C447fdFEEedee8F07FD1962C9ee6",
  mainnet.id,
);
```

All KPK vaults are ERC-4626 compliant and built on Morpho v2. Vault addresses live on each vault page; for example:

| Vault          | Chain    | Address                                      |
| -------------- | -------- | -------------------------------------------- |
| KPK USDC Prime | Ethereum | `0x4Ef53d2cAa51C447fdFEEedee8F07FD1962C9ee6` |
| KPK USDC Yield | Ethereum | `0xD5cCe260E7a755DDf0Fb9cdF06443d593AaeaA13` |
| KPK ETH Prime  | Ethereum | `0xBb50A5341368751024ddf33385BA8cf61fE65FF9` |

For the full list, see the [Morpho vault directory](/vaults/vaults/morpho.md).

#### 2. Read vault and position data

`vault.getData()` returns the onchain state needed to display APY, total assets, and convert between shares and assets.

```typescript
const accrualVault = await vault.getData();

// accrualVault.totalAssets        → total assets in the vault
// accrualVault.toAssets(shares)   → convert user shares to asset amount
// accrualVault.toShares(assets)   → convert asset amount to shares
```

For APY and reward-rate data, query Morpho's offchain API alongside the onchain state. See the [Morpho API reference](https://docs.morpho.org/api/vaults-v2/get-v2-vault-realized-average-apy/) for endpoints.

#### 3. Deposit flow

The SDK uses a two-step pattern: first resolve what's needed (approvals or permit signatures), then build the final transaction.

```typescript
import { parseUnits } from "viem";

const { buildTx, getRequirements } = vault.deposit({
  amount: parseUnits("1000", 6), // 1,000 USDC
  userAddress: USER_ADDRESS,
  accrualVault,
});

const requirements = await getRequirements();
// requirements: (ERC20Approval | Permit | Permit2)[]
// Surface each requirement to the user, collect signatures or send approval txs.

const tx = buildTx(/* signed requirement, if any */);
await walletClient.sendTransaction(tx);
```

Slippage protection is applied automatically: the SDK enforces a `maxSharePrice` ceiling to guard against ERC-4626 inflation attacks.

#### 4. Withdrawal flow

```typescript
// Withdraw a specific asset amount
const { buildTx: buildWithdrawTx } = vault.withdraw({
  amount: parseUnits("500", 6), // 500 USDC
  userAddress: USER_ADDRESS,
});
await walletClient.sendTransaction(buildWithdrawTx());

// Or redeem a specific share amount
const { buildTx: buildRedeemTx } = vault.redeem({
  shares: sharesToRedeem,
  userAddress: USER_ADDRESS,
});
await walletClient.sendTransaction(buildRedeemTx());
```

Withdrawals beyond the vault's idle buffer are routed through the configured liquidity adapter into the underlying Morpho v1 markets. If neither idle nor the liquidity adapter can cover the withdrawal, the SDK can construct a `forceDeallocate` call to pull liquidity from a specific market; see [Liquidity and `forceDeallocate`](/vaults/vaults/morpho.md#liquidity-and-forcedeallocate) for details.

#### 5. Rewards

Some vaults receive MORPHO incentives or other reward campaigns distributed via Merkl. Query the Merkl API by user address to fetch claimable amounts:

```typescript
const res = await fetch(
  `https://api.merkl.xyz/v3/userRewards?user=${userAddress}`,
);
const rewards = await res.json();
```

The claim is a separate transaction and does not modify the user's deposited position.

### Direct contract integration

For custodians, CEXs, and onchain protocols that prefer raw contract calls without a JavaScript SDK, KPK vaults expose the standard ERC-4626 interface. The flows below use **KPK USDC Prime on Ethereum** (`0x4Ef53d2cAa51C447fdFEEedee8F07FD1962C9ee6`) as the example; substitute the vault address for the asset and chain you need from the [vault directory](/vaults/vaults/morpho.md).

{% hint style="info" %}
For the canonical Morpho bundler and adapter contract addresses across chains, see the [Morpho contract addresses page](https://docs.morpho.org/get-started/resources/addresses/). Addresses change occasionally; always cross-reference before integrating.
{% endhint %}

#### Deposit

The simplest deposit path is a direct ERC-4626 call:

{% stepper %}
{% step %}
**Approve the vault to spend USDC.**

Call `approve(spender, amount)` on USDC (`0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48`):

* `spender` = the KPK vault address
* `amount` = the deposit amount, in token units
  {% endstep %}

{% step %}
**Deposit into the vault.**

Call `deposit(assets, receiver)` on the KPK vault:

* `assets` = the deposit amount
* `receiver` = the address that should receive the vault shares (typically the depositor)
  {% endstep %}
  {% endstepper %}

For multi-step flows that batch approval and deposit in a single transaction (e.g. via Permit2), use Morpho's Bundler3. The Bundler3 and General Adapter contract addresses are listed on the [Morpho addresses page](https://docs.morpho.org/get-started/resources/addresses/); the Morpho UI builds the calldata for you.

#### Withdraw

{% stepper %}
{% step %}
**Withdraw a specific asset amount.**

Call `withdraw(assets, receiver, owner)` on the KPK vault:

* `assets` = the asset amount to withdraw
* `receiver` = the address that should receive the underlying asset
* `owner` = the address whose shares should be burned (the depositor, or any address that has approved the caller)
  {% endstep %}
  {% endstepper %}

Or by share amount:

{% stepper %}
{% step %}
**Redeem a specific share amount.**

Call `redeem(shares, receiver, owner)` on the KPK vault:

* `shares` = the share amount to redeem
* `receiver`, `owner` = same as above
  {% endstep %}
  {% endstepper %}

#### Claim rewards

Merkl-distributed reward tokens are claimed via the Merkl distributor:

* Call `claim(users, tokens, amounts, proofs)` on the Merkl distributor, with the values returned by the [Merkl API](https://docs.merkl.xyz/) for the depositor's address.

### Fee wrapper for distribution partners

Distribution partners can request KPK to deploy a [Morpho Fee Wrapper](https://docs.morpho.org/build/earn/concepts/fee-wrapper) on top of a curated vault. This lets the partner charge their users a fee on the underlying KPK strategy without changing the vault itself. Wrapper deployment is a **free service** on KPK's side.

A fee wrapper is a fully ERC-4626 compliant vault that sits on top of the underlying KPK vault. Users deposit into the wrapper, which deposits 1:1 into the selected KPK vault. Yield accrues automatically through share appreciation. The partner's fee is deducted before user withdrawals.

<figure><picture><source srcset="/files/witN71Jgh4E0DKTqfWJ6" media="(prefers-color-scheme: dark)"><img src="https://2037261023-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fb7kueLGoREgSbtMhzWGT%2Fuploads%2F4A9lQnA3XnBPSRApSdLG%2FMORPHOV2_L.png?alt=media&amp;token=cac3615c-24b9-44d2-a702-08fdf1ba14dc" alt=""></picture><figcaption></figcaption></figure>

**What partners get:**

* A standalone ERC-4626 vault, configured with a chosen fee and a recipient address. Supports any standard integration (`deposit`, `withdraw`, `redeem`, `preview`).
* **Flexible fee configuration.** The fee can be a **performance fee** (charged on yield), a **management fee** (charged on AUM), or a combination. Rates and recipient address are set at deployment.
* **Optional permissioned setup.** Wrappers can be deployed with gates on deposit, transfer, and withdrawal to comply with jurisdictional requirements (e.g. KYC-gated access, allowlisted depositors). KPK and the partner agree the gating policy at deployment.
* **Non-custodial guarantees.** Once deployed, gates that could restrict user withdrawals are permanently abdicated, so neither KPK nor the partner can block exits beyond the agreed policy.
* **APY queryable via Morpho.** The wrapper's APY is exposed through the [Morpho GraphQL API](https://docs.morpho.org/tools/offchain/api/morpho-vaults/#feewrapper-yield), already net of the configured fee.

#### What to send when requesting a wrapper

To deploy, KPK needs three details from the partner:

1. **Fee recipient address.** The wallet that will receive performance and/or management fees, in `0x...` format. Any address the partner controls works; KPK can also spin up a fresh Gnosis Safe and transfer ownership. The address must be able to call `redeem()` on the wrapper to convert accrued fee shares to assets.
2. **Custody mode.** Either:
   * **Non-custodial mode** (recommended for DeFi-native deployments). The gate setters (`receiveShares`, `sendShares`, `receiveAssets`) are permanently locked at deployment, so no one can restrict deposits, withdrawals, or transfers afterwards.
   * **Configurable gates.** The owner/curator retains the ability to set gates later for compliance (e.g. KYC/AML allowlists). Configurable gates may introduce custodial characteristics depending on the policy.
3. **Vault naming.**
   * **Vault name** (max 60 characters), e.g. `Partner USDC Yield by KPK`.
   * **Vault symbol** (max 30 characters), the onchain ticker, e.g. `partnerUSDCy`.

Either way, the wrapper does not appear in the public Morpho UI; it is reachable only through the partner's integration or via direct contract calls.

#### Sensible defaults

Partners without a strong preference can ask KPK to proceed with:

* **Non-custodial mode** (standard for DeFi-native deployments).
* **A Fee Recipient Safe** that KPK spins up on the partner's behalf, with the partner's chosen signers; ownership transferable later.
* **Naming** in the form `<Partner> <Asset> <Strategy> by KPK` for the vault name, and `<partner><asset><Strategy>` for the symbol. All three can be changed at deployment time.

To request a wrapper, contact <sales@karpatkey.com> or use the [contact form](https://kpk.io/contact) with the underlying vault, fee structure, and any required gating.

### Support

For integration questions, technical reviews, or hands-on help, reach out to <sales@karpatkey.com> or use the [contact form](https://kpk.io/contact). For protocol-level Morpho documentation, see [docs.morpho.org](https://docs.morpho.org/).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.kpk.io/vaults/vault-integration/integration/morpho.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
