Morpho Ethers Contract

This package aims to facilitate the integration around morpho with ethers-v5. Instead of importing ABIs,
finding implementations, and guessing which functions to call, this package gives you typed classes by using
typechain, and mainnet addresses of deployed contracts.
The package contains all contracts to interract with Morpho and withe the Compound and Aave pools.
NB: for security reasons, we invite you to always check the addresses of the contracts used, and check whether they are indeed those of Morpho.
You will find more information on the integration of Morpho in the developer documentation.
Install
npm install @morpho-labs/morpho-ethers-contract
yarn add @morpho-labs/morpho-ethers-contract
Usage
import { providers, Wallet } from "ethers";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import addresses from "@morpho-labs/morpho-ethers-contract/addresses"
import {
MorphoAaveV2Lens__factory,
MorphoAaveV2__factory,
ERC20__factory,
} from "@morpho-labs/morpho-ethers-contract";
(async () => {
const provider = new providers.StaticJsonRpcProvider(process.env.RPC, "mainnet");
const morphoAaveLens = MorphoAaveV2Lens__factory.connect(addresses.morphoAave.lens, provider);
const morphoAaveMarkets = await morphoAaveLens.getAllMarkets();
const signer = new Wallet(process.env.PRIVATE_KEY!, provider);
const morphoAaveV2 = MorphoAaveV2__factory.connect(addresses.morphoAave.morpho, provider);
const toSupply = parseUnits("10");
const daiAddress = "0x6b175474e89094c44da98b954eedeac495271d0f";
const aDaiAddress = "0x028171bCA77440897B824Ca71D1c56caC55b68A3";
const DAI = ERC20__factory.connect(daiAddress, signer);
const approvalTransaction = await DAI.approve(morphoAaveV2.address, toSupply);
console.log(`Approval transaction: https://etherscan.io/tx/${approvalTransaction.hash}`);
await approvalTransaction.wait();
console.log(`${formatUnits(toSupply)} DAI approved`);
const supplyTransaction = await morphoAaveV2["supply(address,address,uint256)"](
aDaiAddress,
signer.address,
toSupply
);
console.log(
`Supply on Morpho-AaveV2 transaction: https://etherscan.io/tx/${supplyTransaction.hash}`
);
const receipt = await supplyTransaction.wait();
console.log(
`You have successfully supplied ${formatUnits(
toSupply
)} DAI on Morpho Aave, with a gas consuption of ${formatUnits(receipt.gasUsed, "gwei")} gWei`
);
})();