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
- Solidity (Foundry)
- Typescript (Hardhat)
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:
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);
}
...
Morpho contracts are deployed on npm to ease the integration with Hardhat.
yarn add @morpho-org/morpho-blue
Now you can import the contracts in your project.
Import
For example here, we are going to use the MorphoBalancesLib library to ease the read of Morpho balances. You should also add it on top of your contract:
import {IMorpho} from "@morpho-org/morpho-blue/src/interfaces/IMorpho.sol";
import {MorphoBalancesLib} from "@morpho-org/morpho-blue/src/libraries/periphery/MorphoBalancesLib.sol";
contract MyContract {
using MorphoBalancesLib for IMorpho;
// Your code here...
}