Git Product home page Git Product logo

beefy-api's Introduction

Beefy API

API that powers Beefy Finance. You can find the repo for the frontend here.


To Run.

yarn install-all 
yarn start

Note: After you start the API it can take a minute or two before you can fetch the APYs. We currently log getApys() to the console when all the data is available.

Optional environment vars:

BSC_RPC - A custom RPC endpoint that you want to use. HECO_RPC - A custom RPC endpoint for HECO. You can just leave the default one otherwise. FORTUBE_API_TOKEN - A token from Fortube to use their API. If you don't have a token you will get a console warning and the Fortube APYs will be slightly smaller than in production. Everything works fine otherwise.



Endpoints

http://localhost:3000/


Consumed by the app

/apy

The main endpoint used by the frontend. It returns the APY of all the vaults in the following format.

{
	"bifi-maxi": 0.22448469479728606, // 22%
	"cake-cake": 2.8002377054263174, // 280%
	"cake-smart": 2.8002377054263174, // 280%
	"cake-swingby-bnb": 21.85102752680053 // 2185%
}

NB This is the legacy format. A new endpoint is being created at /apy/breakdown with a staggered migration.

/apy/breakdown

The new version of the APY endpoint, broken down into component parts when they are available. The endpoint moves to a new format, which is consistent whether or not the breakdown stats are possible to display. It has the following structure:

{
  "bifi-maxi": {
    "totalApy": 0.07598675804818633
  },
  "cometh-must-eth": {
    "vaultApr": 1.186973388240745,
    "compoundingsPerYear": 2190,
    "beefyPerformanceFee": 0.045,
    "vaultApy": 2.1057844292858614,
    "lpFee": 0.005,
    "tradingApr": 0.22324214039526927,
    "totalApy": 2.8825691266420788
  }
}

Note the endpoint exposes elements needed for the Total APY calculation. Where this is not possible, we just show the legacy Total APY. Note that the legacy Total APY -> totalApy does not include the trading fees.

Each of these fields within the structure are:

  • vaultApr - Yearly rewards in USD divided by total staked in USD.
  • compoundingsPerYear - The estimated compounding events. This is an internal field and references the value used within the calculation for this project.
  • beefyPerformanceFee - The flat Beefy performance fee included in the calculation. This is an internal field for reference.
  • vaultApy - The vaultApr compounded, using compoundingsPerYear and beefyPerformanceFee in the calculation.
  • lpFee - The Liquidity Provider (LP) fee per trade. This is an internal field for reference.
  • tradingApr - Annual interest from trading fees, not compounded.
  • totalApy - The known Total APY. Where fields are available to calculate the Total APY including trading fees, this is calculated. The final calculation is totalApy = (1 + vaultApy) * (1 + tradingApr) - 1.

/prices All token prices under the same endpoint (crosschain).

/lps: All liquidity pair prices under a single endpoint (crosschain).

/vaults: TBD


Consumed by the dashboard

/earnings: Used to display the total and daily earnings of the platform

/holders: Used to display the total number of holders. This calc takes into account users with 0 BIFI in their wallet, but BIFI staked in the reward pool


Consumed by third party platforms

/cmc: Custom endpoint required by CoinMarketCap to display our vaults in their yield farming section

/supply: Used by Coingecko to display BIFI's total supply and circulating supply



Further Information

For further information on the range of endpoints currently supported by the Beefy API, check out the latest version of our API documentation.



Contribute

Beefy.Finance exists thanks to its contributors. There are many ways you can participate and help build high quality software. Check out the contribution guide!



License

MIT.

beefy-api's People

Contributors

0xcmdrkeen avatar 1932293 avatar andreb0x avatar brknrobot avatar bustinjieber420 avatar cartman-dev avatar defidebauchery avatar derlomo avatar epete-epete avatar erenjaegar77 avatar galmoli avatar gh-action-bump-version avatar jordanraphael avatar jpopxfile avatar kexleybeefy avatar lodelux avatar mirthfutures avatar moonster-bsc avatar prevostc avatar pumpingghost avatar qkyrie avatar reflectivechimp avatar roman-monk avatar schnarkus avatar seguido avatar shadoweddev avatar shatterproof avatar sirbeefalot avatar tilty-mctiltface avatar wivern-co-uk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beefy-api's Issues

Improve the README.md of the repo

Right now the docs for the API are almost non-existent. If we improve our README.md at least with some clear instructions on the API structure, how to run it, how to contribute, etc, it will make it much easier for new contributors to help out.

Smart Web3 client

Context

At our current rate, we are adding a dozen of strats per week to the system. This is making us hit the ratelimit on initialization.

A naive solution could be to group the requests, by splitting the pools in batches and waiting between them.
This approach has the problem that it relies on initialization order, or "knowing" the network rules from the application layer.

Proposed solution

Wrap the web3 object into a new object that understands the rules of each network. This object should keep track of the amount of request per minute / second and insert delays between them as needed.

The entry point for this solution would be src/utils/web3.js where the multiple clients are initialized.
we could replace: new Web3(endpoint) with new Web3(endpoint, ratelimit).

Invalid assets via /apy

There seems to be assets that are not valid and not available in the Beefy app, e.g. FORTRESS-BNB

Can you double check to ensure these are correct?

Unable to run

I'm trying to run this, but getting one error.

image

I cloned the repo, then installed the dependancies. Am I missing something?

Keep consistent naming with the price oracle IDs

We used to use Pancakeswap's API at thttps://api.pancakeswap.finance/api/v1/price as a price oracle. Now we're using smart contract oracles directly. It seems like a good opportunity to stop using their inconsistent naming of mixing uppercase with capitalised or lowercase ids and move all our IDs to be uppercase.

The app/cowllector/dashboad repos might have to be updated as well.

Get more recent trading APR data from sushiswap (if subgraph is not lagging)

Currently, an average of a few days of the previous week's data is used for calculating the trading APR for sushi LPs. This was done towards the beginning of polygon adoption, when there were subgraph lag issues, and the trading APRs had stabilized, so it was decided showing the previous week's trading APR was fairly accurate.

Since then sushi has expanded to other chains, and we are blindly using last week's data for all chains sushi is on, regardless if there is a subgraph lag issue. The request is to investigate if there is a subgraph lag issue on each chain sushi is on, and adjust the trading APR calculation to:

  1. allow customizing the days to average in the trading APR calculation per chain.
  2. update to use the fresh data possible that's available on each chain.
    If there isn't a lag issue present anymore on any chains, we can globally update the days chosen for trading data to the average of the past 2 days (freshest data possible by the current query in place)

Bonus if the current query can be modified to use a trailing 48 hours of data

/apy api details

/apy api does not provide much information other than just the name of the asset and APY, but can you please add other tags like TVL, Display Name, Platform, Vault type, Asset 1 & 2 (if any) and whether deposit is paused

having these available in the endpoint will minimise traffic on your host and also simplify my analysis. Thanks

Unify all LP token prices under a single endpoint

Context

We're trying to increase performance and decrease load of the Beefy API. We currently have different endpoints to track the value of LP tokens from different platforms. For example BUSD-BNB from pancakeswap and BUSD-BNB from streetswap, or kebab.

Problem

This causes redundancy by having to fetch multiple prices for assets that will be valued at pretty much the same price. It also means there's more files and lines of code that devs have to edit when adding pools.
Devs have to add a bunch of handlers and this type of things will only get worse:

const oracleEndpoints = {
  'bakery-lp': () => fetchLP(endpoints.bakeryLp),
  bakery: () => fetchBakery(),
  'bdollar-lp': () => fetchLP(endpoints.bdollarLp),
  coingecko: ids => fetchCoingecko(ids),
  'jetfuel-lp': () => fetchLP(endpoints.jetfuelLp),
  'monster-lp': () => fetchLP(endpoints.monsterLp),
  'narwhal-lp': () => fetchLP(endpoints.narwhalLp),
  'nyanswop-lp': () => fetchLP(endpoints.nyanswopLp),
  pancake: () => fetchPancake(),
  'pancake-lp': () => fetchLP(endpoints.pancakeLp),
  'thugs-lp': () => fetchLP(endpoints.thugsLp),
  'kebab-lp': () => fetchLP(endpoints.kebabLp),
  'sponge-lp': () => fetchLP(endpoints.spongeLp),
};

Solution

Just keeping all LP prices under a single endpoint. If we already have a BUSD-BNB LP price, we shouldn't need to add it again just because Kebab is different. We don't use the LP prices for anything mission critical so slight variations don't affect us.
The goal would be to make it as simple as possible to add and maintain new LP prices.

Create endpoint for the '/stake' section to use

A Beefy dev has the staking section pretty much ready on the frontend side. This section will be useful for many things, one of them is to bring the BIFI rewards pool out of the https://gov.beefy.finance subdomain and into the main app. That way we can finally decommission that subdomain.

We need an endpoint that can return 5 data points for each staking pool:

  1. id: A unique ID for the pool. For example "bifi-wbnb"
  2. name: Custom name for the pool.
  3. tvl: Amount of the asset staked in the pool. For example in a pool with 4200 BIFI staked, this number would be 4200.
  4. apy: APY that the pool currently pays out. This takes into account both the value of the staked assets and of the reward token.
  5. staked: The amount of staked assets, but priced in USD. (Just need to multiply TVL * asset price)
{
  "data": [
    {
      "id": "yearn-eth",
      "name": "yearn.finance", 
      "tvl": 367025.4, 
      "apy": "20.82%", 
      "staked": 101453.46825158167
    },
    {
      "id": "bal-btcb",
      "name": "Balancer Pool",
      "tvl": 64245.17,
      "apy": "0.55%",
      "staked": 99.14566080152174
    }
  ]
}

Pretty much as soon as we can have this endpoint ready, we could have the stake section of the app live.

Curve LP token price

Using the endpoint /lps, one can fetch all the LP prices crosschain. Below you can find a subset of the response:

"curve-poly-atricrypto3": 1938.4656787747067

Could you please explain where the value 1938.46 comes from? I cannot derive this calculation from any value displayed on the curve website pool (https://polygon.curve.fi/atricrypto3). Thank you!

/apy/breakdown vaultApr should include performance fee

To have consistency between the Apy and Apr, the vaultApr in the apy breakdown endpoint should be returned with the vault-specific performance fee deducted.

Optionally something like vaultSimpleApr could be added to keep the underlying farm Apr exposed, however this is not needed for the UI.

Create endpoint to calculate SmartCake poolId

The harvester currently doesn't take into account its own CAKE funds while deciding where to farm.
It's easier to calculate the optimal poolId from the API because we already have functions that do most of the work.

how to host the api on server

i was trying to host the api on my server after modification, confused on what to build for hosting, ii tried build folder in address book and i did see the OK response after host.

Custom Endpoint for CoinMarketCap

We need to create an endpoint that conforms to this format for the developers from CMC. It should include all the vaults that we want them to track and display:

{
    provider: 'SushiSwap',  // Project name - Sushi
    provider_logo: 'URL', // Project logo, square, less than 100*100 px
    links: [        // social media info
    {
      title: 'Twitter',
      link: 'https://twitter.com/sushiswap',
     }
  ], 
    pools: [
      {

          name: 'Pool Name 1', // Pool name if any, eg. Sushi Party, Uniswap Sushi-ETH LP
          pair: 'SUSHI-ETH'  // Pool pairs, e.g SUSHI-ETH
          pairLink: 'https://sushiswapclassic.org/farms/SUSHI-ETH%20SLP', // The URL to this pool
          logo: 'URL', //  Pool logo if any, otherwise just use Project logo
          poolRewards: ['SUSHI'], // The reward token ticker
          apr: 1.1,  // APY, 1.1 means 110%
          totalStaked: 13987213,  // Total valued lock in USD 

      },
      {
          name: 'Pool Name 2', 
          pair: 'LEND-ETH'
          pairLink: 'https://sushiswapclassic.org/farms/SUSHI-ETH%20SLP'
          logo: 'URL', 
          poolRewards: ['SUSHI'], 
          apr: 1.1,
          totalStaked: 13987213, 
      }
    ]
}

Wrong APY calculations due to skipped `compund` parameter

There are a few instances in the stats API that call the compound function with just three arguments when it was meant to be called with four, forgetting to pass the default value for the third argument. Resulting in incorrect APY calculations.

For example:

This cases are calling compound(apr, hpy, shareAfterPerformanceFee) instead of compound(apr, hpy, 1, shareAfterPerformanceFee), forgetting the 1 (one year for APY) as third parameter.

`GLP` flaky integration

for the GLP vaults, the underlying tokens should be transferred through the sGLP (staked). documentation here: https://gmxio.gitbook.io/gmx/contracts#transferring-staked-glp

the api is returning sGLP's address as the tokenAddress, so the front-end knows which token to transfer, but this has some side-effects. some integrations rely on tokenAddress to display underlying information about positions, and those integrations expect GLP as the underlying. this breaks GLP vaults on zapper, for example.

i think the api should return both addresses, and the front-end already calls this value locally as depositTokenAddress, so this could be a good field name here.

Trading Apr for pancake vaults are higher than expected

The trading APRs shown on beefy for pancake vaults tends to be much higher than what's shown shown on pancake.

Following the code it looks like the beefy backend calculates the trading Apr based on 0.25% trading fees to LP holders. but only 0.17% is actually rewarded to LP holders.

Split from Pancake docs

screenshot_2022-06-16_at_3.29.21_pm.png

Remove "SmartCake" endpoint and feature from the api

There's quite a bit of code in the api repo that we no longer use. We're trying to prune as much of it to improve the api.

We had an endpoint at '/smart' that managed the SmartCake vault here The new version of CakeSmart won't require this so we can remove it.

We should also be able to remove getCakeSmartApy.js as the current smart cake vault just tracks the apy of the CakeSimple farm.

tvl endpoint is missing in docs (README)

Hi,

Seems like the tvl endpoint is working, but there is no mention of it in the docs.

Furthermore, what is the output format ?

I see the following for example :

{
  "25": {
     ...
  },
  "56": {
     ...
   },
  "137": {
     ...
  }
}

What do these numbers mean ?

Thanks

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.