Skip to main content

Getting Started

This guide helps you integrate Morpho into your project.

The onchain scripts are written in Solidity, and based on the Foundry toolkit. The offchain version is written in Typescript and based on ethers-v6 library.

Installation

forge install morpho-org/morpho-blue

Import

We are going to use the MorphoBalancesLib library to ease the reading of Morpho balances. You should also add it on top of your contract:

import {IMorpho} from "@morpho-blue/interfaces/IMorpho.sol";
import {MorphoBalancesLib} from "@morpho-blue/libraries/periphery/MorphoBalancesLib.sol";

contract MyContract {
using MorphoBalancesLib for IMorpho;

// Your code here...
}

Examples

An educational repository has been released for integrators and users:

Morpho Snippets Repository

It shows how to properly call the different Morpho functions from your own smart contract according to the operations you want to perform.

/* SETUP */
...
/* VIEW FUNCTIONS */


/// @notice Calculates the total supply balance of a given user in a specific market.
/// @param marketParams The parameters of the market.
/// @param user The address of the user whose supply balance is being calculated.
/// @return totalSupplyAssets The calculated total supply balance.
function supplyAssetsUser(MarketParams memory marketParams, address user)
public
view
returns (uint256 totalSupplyAssets)
{
totalSupplyAssets = morpho.expectedSupplyAssets(marketParams, user);
}
...