Code Monkey home page Code Monkey logo

yield-server's Introduction

DefiLlama APY Server

How to list a new protocol

  1. Make sure you are listed on defillama's TVL page (see https://github.com/DefiLlama/DefiLlama-Adapters)
  2. Fork this repository
  3. Create a new folder within src/adaptors/ with your protocol name (use your project slug from https://api.llama.fi/protocols)
  4. Write an adaptor for your protocol (tutorial below)
  5. Test your adaptor by running npm run test --adapter=YOUR_ADAPTER (remember to install dependencies with npm i first!)
  6. Submit a PR

Adaptors

An adaptor is just a javascript (or typescript) file that exports an async function that returns an array of objects that represent pools of a protocol. The pools follow the following schema (all values are just examples):

interface Pool {
  pool: string;
  chain: string;
  project: string;
  symbol: string;
  tvlUsd: number;
  apyBase?: number;
  apyReward?: number;
  rewardTokens?: Array<string>;
  underlyingTokens?: Array<string>;
  poolMeta?: string;
}
{
    pool: "0x3ed3b47dd13ec9a98b44e6204a523e766b225811-ethereum", // unique identifier for the pool in the form of: `${ReceivedTokenAddress}-${chain}`.toLowerCase()
    chain: "Ethereum", // chain where the pool is (needs to match the `name` field in here https://api.llama.fi/chains)
    project: 'aave', // protocol (using the slug again)
    symbol: "USDT", // symbol of the tokens in pool, can be a single symbol if pool is single-sided or multiple symbols (eg: USDT-ETH) if it's an LP
    tvlUsd: 1000.1, // number representing current USD TVL in pool
    apyBase: 0.5, // APY from pool fees/supplying in %
    apyReward: 0.7, // APY from pool LM rewards in %
    rewardTokens: ['0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9'], // Array of reward token addresses (you can omit this field if a pool doesn't have rewards)
    underlyingTokens: ['0xdAC17F958D2ee523a2206206994597C13D831ec7'], // Array of underlying token addresses from a pool, eg here USDT address on ethereum
    poolMeta: "V3 market", // A string value which can stand for any specific details of a pool position, market, fee tier, lock duration, specific strategy etc
  };
A note on how to set apy related fields:

- if a pool's apy only consists of a base component, provide `apyBase` and omit `apyReward` (or set to null) [and vice versa]
- if a pool's apy consists of both, provide both fields
- if you are unsure/your data source doesn't contain a detailed breakdown, then provide an `apy` field indicating the total apy and omit the `apyBase` and `apyReward` fields (or set to null)

Adapter module structure

module.exports = {
  timetravel: false,
  apy: apy, // Main function, returns pools
  url: 'https://example.com/pools', // Link to page with pools
};

An example of the most basic adaptor is the following for Anchor on terra:

const utils = require('../utils');

const poolsFunction = async () => {
  const apyData = await utils.getData(
    'https://api.anchorprotocol.com/api/v1/market/ust'
  );
  const dataTvl = await utils.getData(
    'https://api.anchorprotocol.com/api/v1/deposit'
  );

  const ustPool = {
    pool: 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu',
    chain: utils.formatChain('terra'),
    project: 'anchor',
    symbol: utils.formatSymbol('UST'),
    tvlUsd: Number(dataTvl.total_ust_deposits) / 1e6,
    apy: apyData.deposit_apy * 100,
  };

  return [ustPool]; // Anchor only has a single pool with APY
};

module.exports = {
  timetravel: false,
  apy: poolsFunction,
};

You can find examples for a bunch of other protocols in the src/adaptors/ folder, and if you have any questions feel free to ask them on our discord.

Running the server

This is not needed if you just want to contribute an a new protocol through an adapter, only needed if you want to fork defillama.

set api keys in config.env

ETHERSCAN=
INFURA_CONNECTION=

yield-server's People

Contributors

0xaces avatar 0xandrewclark avatar 0xdapper avatar 0xngmi avatar abtheo avatar adamxyzxyz avatar adityapune avatar brettkolodny avatar chaoticgoodpanda avatar chunwang1998 avatar devn03 avatar dtmkeng avatar hirorylabo avatar hubertnastaly avatar joaoavf avatar julien-devatom avatar kalesberg avatar kfukue avatar mashup-purveyor avatar miogreen avatar opyet avatar paulvaden avatar pierremarsotlyon1 avatar quagliero avatar sbbutler avatar shengda avatar slasher125 avatar tech-dapper avatar vrtnd avatar waynebruce0x avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.