weweswap / app-backend

Utils and APR backend
MIT License
0 stars 0 forks source link

Vault Aggregation and APR Calculation Service

Overview

This service is designed to handle two primary tasks:

  1. Vault Aggregation:

    • Listens to "LogCollectedFees" events and stores them in the database.
    • Aggregates vault data daily and stores historical vault information (TVL).
  2. APR Calculation:

    • Provides an API endpoint to calculate and serve the APR (Annual Percentage Rate) based on collected vault fees and liquidity provider (LP) data.

Features

1. Vault Fee Collection and Aggregation

2. APR Calculation API

Project Structure

src/
├── aggregators/
│   ├── vault-aggregator/         # Handles daily vault data aggregation
│   └── operations-aggregator/    # Handles listening to "LogCollectedFees" events
├── api/
│   └── lp/                       # API module for LP-related data, including APR calculations
├── blockchain-connectors/        # Manages blockchain connectivity and provides ERC20 service
├── contract-connectors/          # Services for interacting with contracts (eg. Arrakis)
├── database/                     # MongoDB schemas and database interaction services
├── price-oracles/                # Price-Oracle service (Coingecko API)
├── config/                       # Configuration settings for the service
├── shared/                       # Shared models, types, classes and enums and utility functions
└── utils/                        # Various utility functions

Key Files

Setup and Installation

  1. Clone the Repository:

    git clone <repository-url>
    cd <project-directory>
  2. Install Dependencies:

    npm install
  3. Environment Variables:

    • Configure the necessary environment variables in a .env file. You’ll need:
      • Database connection URI (MongoDB)
      • Blockchain provider URLs (for EVM connectors)
      • Any other relevant config variables such as vault addresses.
  4. Run the Application:

    npm run start
  5. Running Tests:

    • Tests are included in the project, and you can run them with:
      npm run test

Usage

Vault Aggregation

The vault aggregation logic starts automatically:

APR Calculation

The APR calculation is exposed via an API:

Further improvements