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

@metamask-institutional/defi-adapters

v0.14.0

Published

Defi adapters for MMI Dashboard

Downloads

275

Readme

Welcome to our DeFi Adapter Library! 🚀

This library is designed to simplify and standardise the process of fetching data and interacting with various DeFi protocols, which often have unique interfaces and data structures. Our adapters 1) fetch and transform underlying protocol data into a standardised format that can be easily used by portfolio dashboards and 2) generate transaction params to create and update protocol positions.

Note: Please note that in this library, adapters must query on-chain data to ensure accuracy and reliability, we do not accept centralised APIs to get positions, withdrawals, deposits, profits or rewards.

How to create a Read Adapter

Setup steps

Watch the setup video for a detailed guide.

  1. Install:
    • nvm use to select the environment
    • npm i to install dependencies
    • npm run build to build the CLI
  2. Run project:
    • npm run dev to run the project

Continue watching videos for the following steps or, alternatively, find a written version in Steps to create a read adapter

Build adapter steps

Watch the build adapter video for a detailed guide.

  1. Use CLI:
    • npm run new-adapter this launches our interactive CLI that will prompt you with a series of questions

Inspect your automatically created adapter file and implement unfinished methods

Watch the inspect your adapter video for a detailed guide.

Build Smart Contract Classes from ABIs

Watch the build contract classes from ABIs video for a detailed guide.

  1. Save a json file with your abi and add it to your ${protocolName}/contracts/abis/ folder
  2. Run:
    • npm run build-types to generate your smart contract classes

Build your DeFi asset metadata files

Watch the build your DeFi asset metadata files video for a detailed guide.

  1. Implement the getProtocolToken function in your adapter.
  2. Run:
    • npm run build-metadata -- -p <protocol-id> to create your metadata files

Build your Snapshot tests

Watch the build your snapshot tests video for a detailed guide.

  1. Populate your test cases file.
  2. Run:
    • npm run build-snapshots -- -p <protocol-id> to build your snapshot tests

How to create a Write Adapter

The tutorial video below shows an intro to on how to add write adapter actions to an existing read adapter:

Don't have a read adapter? And don't intend to create a read adapter? Then:

  1. Select "WriteOnlyAdapterTemplate" on our new-adapter CLI. See section "Build adapter steps" above for more information.
  2. Implement the buildMetadata() method see section "Build your DeFi asset metadata files" above for more information.
  3. Then follow the video tutorial below:

Watch the build write adapter video for a detailed guide.

Example code for write-adapters, as described in the above video:

export const WriteActionInputs = {
  [WriteActions.Deposit]: z.object({
    asset: z.string(),
    amount: z.string(),
    onBehalfOf: z.string(),
    referralCode: z.number(),
  }),
  [WriteActions.Withdraw]: z.object({
    asset: z.string(),
    amount: z.string(),
    to: z.string(),
  }),
} satisfies WriteActionInputSchemas
async getTransactionParams({
  action,
  inputs,
}: Extract<
  GetTransactionParams,
  { protocolId: typeof Protocol.YourProtocolKey; productId: 'YourProductId' }
>): Promise<{ to: string; data: string }> {
  switch (action) {
    case WriteActions.Deposit: {
      const { asset, amount, onBehalfOf, referralCode } = inputs
      return poolContract.supply.populateTransaction(
        asset,
        amount,
        onBehalfOf,
        referralCode,
      )
    }
    case WriteActions.Withdraw: {
      const { asset, amount, to } = inputs
      return poolContract.withdraw.populateTransaction(asset, amount, to)
    }
  }
}