Skip to main content
Morpho is a decentralized lending protocol deployed on Tempo that enables capital-efficient borrowing. Using the cbBTC/pathUSD market, your app can let users supply cbBTC as collateral and borrow pathUSD against it. This recipe demonstrates how to integrate Morpho lending into your app using Privy embedded wallets and the Morpho SDK.

Install dependencies

1. Configure the Morpho market

Define the market parameters for the cbBTC/pathUSD market on Tempo. These parameters uniquely identify the Morpho Blue market your app will interact with.
These parameters are fixed for each Morpho Blue market — they are set by the market creator at deployment and cannot be changed. The lltv (liquidation loan-to-value) determines the maximum ratio of debt to collateral before a position becomes liquidatable. To find these values for any market, query the Morpho Blue contract or look them up on the Morpho app.
Both cbBTC and pathUSD use 6 decimals on Tempo. When specifying amounts, 1_000_000n equals 1 cbBTC or 1 pathUSD. Note that cbBTC uses 8 decimals on other chains but 6 on Tempo.

2. Set up the Privy wallet and viem client

Create a viem wallet client from the Privy embedded wallet and extend it with the Morpho SDK. The morphoViemExtension adds Morpho market methods directly to the client.

3. Supply collateral and borrow

Use the Morpho SDK to construct and send transactions atomically via Bundler3. The SDK handles ERC-20 approvals, Morpho setAuthorization for the GeneralAdapter1, and Permit/Permit2 signatures automatically through its requirements system.
The SDK bundles supplyCollateral and borrow into a single atomic transaction via Bundler3. It also includes an LLTV buffer check to prevent the new position from being instantly liquidatable.
Always verify that the borrow amount stays safely below the liquidation threshold. The market LLTV is 77%, meaning a position is liquidated when the debt value exceeds 77% of the collateral value. Use a safety buffer (e.g., borrow at most 70% of max) to avoid liquidation from price movements.

4. Repay and withdraw collateral

To close the position, repay the borrowed pathUSD and withdraw the cbBTC collateral. The SDK bundles repay and withdraw into a single atomic transaction (repay executes first, then withdraw).
Repaying by shares instead of a fixed asset amount ensures the full debt is repaid, including any interest that accrued since the borrow.

5. Check position health

Monitor a position’s health factor to alert users before liquidation risk becomes critical. The AccrualPosition returned by getPositionData includes a built-in healthFactor getter (WAD-scaled). These values may be undefined if the oracle is unavailable.

Market parameters

Morpho SDK

TypeScript SDK reference for Morpho protocol interactions

Sending transactions on Tempo

Create embedded wallets and send transactions on Tempo