npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@morpho-labs/morpho-ethers-contract

v1.20.1

Published

Use Morpho contracts with ethers js

Downloads

1,082

Readme

Morpho Ethers Contract

npm package Build Status Downloads Issues Commitizen Friendly Semantic Release

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);

  // now you have autocompletion for morpho contract
  const morphoAaveMarkets = await morphoAaveLens.getAllMarkets();

  // For example, you can easily supply on Morpho

  const signer = new Wallet(process.env.PRIVATE_KEY!, provider);

  const morphoAaveV2 = MorphoAaveV2__factory.connect(addresses.morphoAave.morpho, provider);

  const toSupply = parseUnits("10"); // 10 DAI
  const daiAddress = "0x6b175474e89094c44da98b954eedeac495271d0f";
  const aDaiAddress = "0x028171bCA77440897B824Ca71D1c56caC55b68A3";
  // We first need to approve the amount to supply through the ERC20 token
  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(); // wait until transaction was mined

  console.log(`${formatUnits(toSupply)} DAI approved`);

  const supplyTransaction = await morphoAaveV2["supply(address,address,uint256)"](
    aDaiAddress, // poolToken aka aToken for aave
    signer.address, // onBehalf of the signer
    toSupply // amount to supply in WEI units
  );

  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`
  );
})();