Code Monkey home page Code Monkey logo

aaveinterest's Introduction

aaveinterest

A simple http api to get Aave interest rates from the blockchain.

Dependencies

  • Node >= v12

  • Mongodb >= 4.2

Run Application

There are two services:

  • API

  • Worker (listens to the ethereum network for events)

The worker uses an in memory queue and a configurable number of workers (default is 10 for testnet and 3 for mainnet) to process the events in the queue. The configuration of the number of workers should be based on number of requests your Ethereum node is able to process (Infura was ~1-2 while testing) else you would have request timeouts

Manual

Start Http Server

It can connect to either the mainnet or ropsten ethereum network

$ npm run build
$ npm start -- --network=mainnet

Start Worker Service

It listens to the ethereum network for ReserveUpdated Aave events and stores in the database

It can listen to either the mainnet or ropsten ethereum network

$ npm run build
$ npm run start-worker -- --network=mainnet

Docker

This automatically startups both the Http and Worker service

$ docker-compose up

Run Tests

For the tests to pass you MUST seed the database

$ npm run seed-database

Run tests

$ npm test

Routes

Get Reserves List

The reserves list is updated every hour from the blockchain, this is to prevent having to make a expensive blockchain network call on every request.

URL

/

Response

{
    data: ["0x6B175474E89094C44Da98b954EedeAC495271d0F"],
    updatedAt: "2020-02-06T06:48:53.037Z"
}

Get Deposit Rates

Returns the rates for the last 24 hours by default

URL

/deposit/:reserve/:mode?

Route Params

reserve: Reserve address (e.g. 0x6B175474E89094C44Da98b954EedeAC495271d0F)

mode (optional): Get weighted average rate for the options ['week', 'month', 'all-time']

Response

{
    data: [
        {
            liquidityRate: 0.0000005,
            time: "2020-02-06T06:48:53.037Z"
        }
    ]
}

Get Borrow Rates

Returns the rates for the last 24 hours by default

URL

/borrow/:reserve/:mode?

Route Params

reserve: Reserve address (e.g. 0x6B175474E89094C44Da98b954EedeAC495271d0F)

mode (optional): Get weighted average rate for the options ['week', 'month', 'all-time']

Query Params

borrowRate: ['stable', 'variable']

Response

{
    data: [
        {
            stableBorrowRate: 0.0000005,
            time: "2020-02-06T06:48:53.037Z"
        }
    ]
}

Running locally

Sample data

There is a sample Mongodb dump data in the ./data directory. It can be imported to the local mongodb server

$ cd ./data
$ mongorestore

There is should now be a collection of sample 208 documents in your local database that you can test against

LICENSE

MIT

aaveinterest's People

Contributors

samparsky avatar

Watchers

 avatar  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.