For the complete documentation index, see llms.txt. This page is also available as Markdown.

Morpho Blue

Supply, borrow, repay and withdraw on Morpho Blue markets.

Morpho Blue interactions follow a two-phase pattern. When you call any build method, the SDK returns an object containing requirements (prerequisite transactions like token approvals or authorizations) and a bundlerTx (the actual protocol call). Your app is responsible for sending these transactions in order.

Supply (lend)

Supplies underlying assets into a Morpho Blue market as a lender. The SDK figures out what approvals or setup transactions are needed and returns them as requirements.

const prepared = await lendingClient.buildSupply({
  marketId: "0xYourMorphoMarketId",
  assets: 1_000_000n, // Amount in underlying token decimals
});

To execute, loop through the prerequisites first, then send the bundler transaction:

// Step 1: Send any prerequisite transactions (approvals, authorizations, etc.)
for (const tx of prepared.requirements) {
  await walletClient.sendTransaction({
    account,
    to: tx.to,
    data: tx.data,
    value: tx.value,
  });
}

// Step 2: Send the main bundler transaction
await walletClient.sendTransaction({
  account,
  to: prepared.bundlerTx.to,
  data: prepared.bundlerTx.data,
  value: prepared.bundlerTx.value,
});

This two-step pattern is the same for all Morpho Blue write operations. The examples below omit the execution step for brevity, but the flow is always: build, send requirements, send bundler tx.

Borrow

Borrows assets from a Morpho Blue market against your posted collateral. The returned object follows the same { requirements, bundlerTx } shape as supply.

Note: You need sufficient collateral posted in the market before calling this. If the borrow would put your position above the market's maximum LTV, the transaction will revert onchain.

Repay

Repays borrowed assets on a Morpho Blue market. Repayment requires a token approval for the repayment amount.

Withdraw

Withdraws previously supplied assets from a Morpho Blue market.

Last updated