Giter Site home page Giter Site logo

badger-finance / badger-api Goto Github PK

View Code? Open in Web Editor NEW
5.0 6.0 5.0 50.77 MB

Serverless API for Badger DAO protocol.

Home Page: https://api.badger.com/docs

License: MIT License

TypeScript 99.98% Shell 0.02%
decentralized-finance api badger serverless-framework typescript web3

badger-api's Introduction

Ts.ED logo

Badger API

Application   •   Swagger   •   Discord   •   Twitter


Service Tests Deploy Test Coverage


Collection of serverless API to enable public access to data surrounding the Badger protocol.

Development

To get started, install the following dependencies:

  • Node
  • Java

Note: If you are running on an M1 Mac you will have to install the x86 version of Java and run the following commands in Rosetta

Setup project dependencies:

yarn install --frozen-lockfile
npm install -g serverless
sls dynamodb install

In case if u don't have .aws credentials yet

sls config credentials --provider aws \
 --key <aws_access_key_id>
 --secret <aws_secret_access_key>

Contact Tritium | BadgerDAO#4816 for AWS access if required. After getting keys, complite the MFA section.

Git

Badger accepts only verified commits, this can be done by signing them with gpg keys. For more info, proceed to github gpg doc.

Environment Variables

Variables are handled by a combination of dot env files, and the serverless manifest. An example file is available at .env.example.

Before running the API, make sure to create a local .env file:

cp .env.example .env

Update the RPC values and Graph API key with data from the DevOps team or your own endpoints.

Contact jintao#0713 for RPC or TheGraph access if required.

AWS Lambda Environment

yarn dev

Note: You cannot view Swagger documentation via Serverless

Express Environment

npx ts-node src/index.ts

Express is not the recommended development environment as implmentations will execute in lambda. Serverless offline framework is the closest to production execution environment.

Local Testing

The API supports local (offline) testing of nearly all endpoints. Certain endpoints which require access to AWS resources may not work appropriately without AWS credentials. The databased used for local testing DynamoDB - a local version with exact table copies of production. These tables are seeded with data located in the seed folder.

Note: Running only sls offline will not start or seed dynamo. Run sls offline start, or yarn dev instead.

badger-api's People

Contributors

0xikalgo avatar benefacto avatar btcookies avatar darruma avatar dependabot[bot] avatar eliobricenov avatar ethkaneki avatar lookfirst avatar mitche50 avatar mranilrai avatar mrbasado avatar namelsking avatar notbdu avatar okjintao avatar sajanrajdev avatar shakotn avatar shuklaayush avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

badger-api's Issues

[feat. request]: Wire up renBTC vault in experimental zone

Description

A new renBTC vault for wiring: 0x58cac1409f1ffbdcba6a58d54c94cac3fb4c6f8b
It is not connected to controller yet

Provide a short description of the feature - provide business context if required.

Request Metrics

Metric Rating
Priority Medium
Effort Low
Risk Low

Options: low, medium, high

Documentation (optional)

Add any supporting documentation, proposed API responses, interaction diagrams etc.

Resources (optional)

Add any new or updated resource requirements for the system

Discord Bug Report: hyment

Reported on: 2021-09-12T04:05:51.094000+00:00
Bug Description:
Multiplier boost displayed in the app doesn't update after multiple cycles and modifying the native/non-native balance.

Attachments:
content_type: image/png
ephemeral: False
filename: unknown.png
height: 1024
id: 886462587229847602
proxy_url: https://media.discordapp.net/attachments/863051342436499498/886462587229847602/unknown.png
size: 389353
url: https://cdn.discordapp.com/attachments/863051342436499498/886462587229847602/unknown.png
width: 1894

API-2: [feat. request]: Add health check endpoint(s) to support a public status page

Description

We need a public status page to communicate downtime and issues to our users, similar to what TheGraph has. In order to create this status page, (a) certain endpoint(s) will need to be added to the API (something like a /health route) to provide health checks for APIs, TheGraph, and ideally smart contracts (i.e. badger API endpoints returning 200s, subgraph endpoints returning 200s, smart contract reads returning normal responses, etc.). The ultimate monitoring of these are likely to come from the Badger Prometheus instance (still in development) and not available to consume yet. In the meantime, Prometheus could be run locally in a Docker container and configured to monitor the required sources that way.

Request Metrics

Metric Rating
Priority medium
Effort high
Risk medium

Options: low, medium, high

Documentation (optional)

Resources (optional)

  • Badger Prometheus instance

Scope

APIs

Contracts

Ethereum Mainnet

Note: these contracts were obtained from the latest v2-ui configuration on master; some contracts were excluded due to a lack of read methods, unverified code on Etherscan, or duplicate names

DIGG system
Logic
Tokens

Subgraphs

Binance Smart Chain

Tokens
Logic
Sett System
Controllers

Development

  • Create a controller: HealthController that includes a /health endpoint for a full health check with also paths for smaller health checks like /health/contracts, /health/subgraphs, and /health/apis
  • Create the following services: HealthService abstract class with extended classes -- ContractsHealthService, SubgraphsHealthService, ApisHealthService
  • Import all necessary contract ABIs to new folders: src/health/config/abi/digg, src/health/config/abi/logic, src/health/config/abi/tokens
  • Add a health.yml health.ts configuration to the base directory that specifies which contracts, subgraphs, and APIs should be checked
  • Remove TypeChain and rework ABIs added to match those present in the abi folder with a flat structure, an abi file name postfix, and the abis manually declared as TypeScript variables rather than using generated code like TypeChain does
  • Add health logic to ContractsHealthService to test every parameter-less view method of the configured contracts
  • Figure out efficient way of making view method calls (e.g. JsonRpcBatchProvider)
  • Report results (success/failure) of contract methods
  • Add contracts health logic to HealthController at /health/contracts to return JSON data
  • Add contract names to abis: maybe can get this from the import key
  • Rework config to draw API/subgraphs from other configs
  • Add health logic to SubgraphsHealthService to run example queries on each configured subgraph and report results (success/failure)
  • Add subgraph health logic to HealthController at /health/subgraphs to return JSON data
  • Add health logic to ProviderHealthService to run test RPC calls (like get block number or something) on each configured provider and report results (success/failure)
  • Add provider logic to HealthController at /health/providers to return JSON data
  • Add health logic to ApisHealthService to perform parameter-less API GET calls and report results (success/failure)
  • Add API health logic to HealthController at /health/apis to return JSON data
  • Add all health check logic to HealthController at /health to return JSON data
    Rework services & API to only retrieve cached data
    Add scheduled task to push cache data (example of caching, example of scheduled task)
    Delete any cached data that is older than 90 days via a scheduled task (not doing a react app
  • Remove storage/caching logic
  • Refactor and clean up code
  • Add name of subgraph, and isError property
  • Fix linting error
    Add storage and caching This will be handled by the status page
  • Add tests: TBD
  • Add docs to describe how to maintain & add/remove new contracts/apis/subgraphs
  • Comment pull request so it can be effectively reviewed: see message here
  • Undo serverless.yml comments before merging
    Integrate into selected status page: depends on this issue; implementation still TBD, this may be broken out into a separate issue
  • Integrate health logic into scout: implementation still TBD, this may be broken out into a separate issue on the scout side

[feat. request]: add uniswap untracked volume tracking for lp fees

Description

Uniswap does not track wbtc pair data on the pair day datas as several other pairs. Add untracked volume counting for fairs to asses LP fee

Request Metrics

Metric Rating
Priority Low
Effort Medium
Risk Low

Options: low, medium, high

Documentation (optional)

Add any supporting documentation, proposed API responses, interaction diagrams etc.

Resources (optional)

Add any new or updated resource requirements for the system

API-1: [feat. request]: Add OpenAPI documentation

Description

It would be great if we could add some OpenAPI documentation (like Swagger or an equivalent) to the default route of the API. That way, it would make it much easier for developers to explore, built on, and extend the API without having to go through its code base in depth. The delivery of this may be related to planned implementation of Ts.ED (issue TBD).

Request Metrics

Metric Rating
Priority Medium
Effort Medium
Risk Low

Options: low, medium, high

Documentation (optional)

N/A

Resources (optional)

N/A

feat: add leaderboard summary endpoint

Description

The idea is to have an endpoint that has all the information needed by the UI to construct the leaderboard. This information requires some calculations work beforehand, we can have a job that performs them and stores it in a table, then have the endpoint serve it directly.

Request Metrics

Metric Rating
Priority medium
Effort medium
Risk low

ERROR: Local environment failing without Java

If a local development environment does not have java installed, the yarn dev command will fail with an ambiguous error.

In order to properly install on ubuntu, a user should run

sudo apt-get update && sudo apt install default-jre -y

Discord Bug Report: blackbear | BadgerDAO

Reported on: 2021-08-13T22:41:26.745000+00:00
Bug Description:
Multiple reports from users and myself not being able to see the boost on the dashboard + boost optmizer isn't loading.

Attachments:
content_type: image/png
filename: 1.png
height: 969
id: 875871699940306994
proxy_url: https://media.discordapp.net/attachments/863051342436499498/875871699940306994/1.png
size: 154424
url: https://cdn.discordapp.com/attachments/863051342436499498/875871699940306994/1.png
width: 1682

Discord Bug Report: Kryptobi

Reported on: 2021-10-14T12:31:48.769000+00:00
Bug Description:
Bridge not working on coinbase wallet on chrome.

Attachments:

[feat. request]: Revert back to quicknode

Description

Tritium has access to quicknode slack to discuss issues that were raised with their RPC. Discuss and see viability of switching back to quicknode for data.

Request Metrics

Metric Rating
Priority low
Effort low
Risk low

Options: low, medium, high

Documentation (optional)

Resources (optional)

Discord Bug Report: hyment

Reported on: 2021-08-27T00:21:15.222000+00:00
Bug Description:
Multiple users reported that the multiplier boost displayed in the app doesn't update, even after various cycles.

Attachments:
content_type: image/png
ephemeral: False
filename: Screen_Shot_2021-08-26_at_6.31.35_PM.png
height: 472
id: 880607859883249674
proxy_url: https://media.discordapp.net/attachments/863051342436499498/880607859883249674/Screen_Shot_2021-08-26_at_6.31.35_PM.png
size: 226559
url: https://cdn.discordapp.com/attachments/863051342436499498/880607859883249674/Screen_Shot_2021-08-26_at_6.31.35_PM.png
width: 2814

API-6: [feat]: Charts Service

Description

Historic charts for sett balances, and $ values can be exposed using the sett snapshot data.
Introduce a chart request endpoint that allows for the following queries:

- Sett Contract Address (required)
- Range for data display
- Granularity of intervals
- Padding for any missing data for new setts

Notes
- All data is stored at 30 minutes intervals, this would be the maximum (and default) granularity
- By default we can show the last 2 weeks of data

Example Scenarios

Request w/ no granularity or range
/v2/charts?sett=0x9eb0aAd5Bb943D3b2F7603Deb772faa35f60aDF9
return: last 2 weeks of data at 30 min intervals

Request w/ no granularity
/v2/charts?sett=0x9eb0aAd5Bb943D3b2F7603Deb772faa35f60aDF9&start=1616771830
return: 4 weeks of data (then to now) at 30 min intervals

/v2/charts?sett=0x9eb0aAd5Bb943D3b2F7603Deb772faa35f60aDF9&start=1616771830&end=1620227830
return: 1 week of data from 4 weeks ago at 30 min intervals

Request w/ no interval
/v2/charts?sett=0x9eb0aAd5Bb943D3b2F7603Deb772faa35f60aDF9?freq=2
return: 2 weeks of data at 2 hour intervals

Full requests
/v2/charts?sett=0x9eb0aAd5Bb943D3b2F7603Deb772faa35f60aDF9&start=1616771830&freq=2
return: 4 weeks of data (then to now) at 2 hour intervals

/v2/charts?sett=0x9eb0aAd5Bb943D3b2F7603Deb772faa35f60aDF9&start=1616771830&end=1620227830&freq=2
return: 1 week of data from 4 weeks ago at 2 hour intervals

[feat. request]: Update readme to document first time Serverless setup

Description

When a developer is running this API locally for the first time, there are certain potentially necessary setup steps not yet documented in the README. In particular, the developer has to configure an AWS access and secret key after installing Severless via NPM; example: serverless config credentials --provider aws --key something --secret somethingElse. The readme should be updated to reflect this additional potentially necessary setup step.

Request Metrics

Metric Rating
Priority medium
Effort low
Risk low

Options: low, medium, high

Documentation (optional)

Resources (optional)

N/A

Discord Bug Report: hyment

Reported on: 2021-08-11T22:56:54.465000+00:00
Bug Description:
DIGG's ROI breakdown shows that around ~6.00% is paid in DIGG, even though 100% of the rewards are automatically compounded.

Attachments:
content_type: image/png
filename: Screenshot_1.png
height: 74
id: 875150813620756510
proxy_url: https://media.discordapp.net/attachments/863051342436499498/875150813620756510/Screenshot_1.png
size: 3263
url: https://cdn.discordapp.com/attachments/863051342436499498/875150813620756510/Screenshot_1.png
width: 372

Discord Bug Report: hyment

Reported on: 2021-10-20T17:35:53.039000+00:00
Bug Description:
User deposited in the Arbitrum Curve renBTC/wBTC sett vault and holding Badger tokens doesn't get any boost displayed on the app: 0xED9376094Ce37635827E0Cfddc23bFbb6D788469.

Attachments:
content_type: image/png
filename: Screen_Shot_2021-10-20_at_10.31.34_AM_1.png
height: 1148
id: 900437177605959811
proxy_url: https://media.discordapp.net/attachments/863051342436499498/900437177605959811/Screen_Shot_2021-10-20_at_10.31.34_AM_1.png
size: 213643
url: https://cdn.discordapp.com/attachments/863051342436499498/900437177605959811/Screen_Shot_2021-10-20_at_10.31.34_AM_1.png
width: 1084

API-5: [epic]: Badger Portfolio

Description

The Badger Portfolio is a way for any badger to view their current and historic portfolio with badger.

The following functionality would be available to the user:

  • Historic portfolio value and balances ($ + coin)
  • Earned value with badger from sett compounding ($ + coin)
  • Earned value with badger from badger tree ($ + coin)
  • Evaluated KPI for user investment portfolio
  • Badger boost, reward multiplier data
  • User balances and portfolio allocations
  • Badger boost / stake ratio information

Development Areas

  • UX
    • Mock Ups
    • Community Feedback
  • Front End
    • API Integration
    • Visualization
  • Back End
    • Expose user specific data + charts (all above points)
    • Unit tests for all new added functionality
    • Open API Documentation

Request Metrics

Metric Rating
Priority medium
Effort high
Risk low

Options: low, medium, high

Documentation (optional)

The badger portfolio would be a page separate of the existing sett interface - no longer a replicated sett page toggled.
This page can then replace the user specific toggled view offering a more personalized experience with some potential for customization.

Resources (optional)

  • Dynamo DB

[feat. request]: Add DROPT-2 Token Support

Description

The DROPT-2 Token needs to be referenced on the UI for DIGG options claiming. Adding in configuration to the API to handle this token.

Request Metrics

Metric Rating
Priority medium
Effort low
Risk low

Options: low, medium, high

Documentation (optional)

Add any supporting documentation, proposed API responses, interaction diagrams etc.

Resources (optional)

Add any new or updated resource requirements for the system

add block times per chain

block time is a constant currently defined as the ETH block time, we need to define per chain block times (block per year) to allow for proper indexing and apy estimation per chain

API-7: [feat. request]: Add endpoint for getClaimableFor method on Badger Tree

Description

Add an endpoint for the getClaimableFor method on the Badger Tree.
This is needed for the rewards architecture - we want these calls to be cached so that the rewards system isn't slowed down by all the web3 calls.

Request Metrics

Metric Rating
Priority high
Effort medium
Risk low

Options: low, medium, high

Documentation (optional)

Badger Tree Contract

Resources (optional)

Add any new or updated resource requirements for the system

API-3: [feat. request]: Operational Data -- Rewards Cycle Time & Harvest Time on Setts

Description

Request from @BenLeibig
"It would also be nice if you could include information around:

Rewards Cycle Time
Harvest Time on setts (harvest is for all setts per chain I think)

These are other operational data our community cares about. Maybe this doesn't fit well into changes in the API, but if you can easily build in metrics points/health checks that would be nice.

Cycles should occur every 2 hours but is sometimes late, more than 4-6 hours is bad/go red.
BSC harvests should occur ever 2 hours
ETH harvests should occur every 24 hours
These numbers should be dynamic.

This is a suggestion not a requirement."

UI implementation still TBD -- @benefacto

Request Metrics

Metric Rating
Priority TBD
Effort TBD
Risk TBD

Options: low, medium, high

Documentation (optional)

Add any supporting documentation, proposed API responses, interaction diagrams etc.

Resources (optional)

Add any new or updated resource requirements for the system

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.