Skip to content

mento-protocol/mento-analytics-api

Repository files navigation

Mento Analytics API

The Mento Analytics API is a service designed to provide real-time analytics for the Mento Protocol's stablecoins and reserve assets across multiple blockchains (Celo, Ethereum, and Bitcoin). It serves as the data backbone for the Mento Reserve dashboard, offering insights into reserve holdings and stablecoin metrics.

The API can be used by consumers to fetch information about the Mento Stables, the Reserve and it's composition.

Getting Started

Prerequisites

  • Node.js (v21+)
  • pnpm

Installation

# Install dependencies
pnpm install

# Start development server
pnpm run start:dev

# Build for production
pnpm run build

# Start production server
pnpm run start:prod

Environment Variables

Create a .env file in the root directory:

cp .env.example .env

You'll need to obtain API keys for the Coinmarket cap & exchange rates API then add them to your env file

Key Features

  • Stablecoin Analytics: Tracks the total supply of all Mento stables
  • Multi-Chain Reserve Tracking: Monitors reserve assets across Celo, Ethereum and Bitcoin networks
  • Reserve Composition Analysis: Detailed breakdown of reserve holdings and their USD values
  • Collateralization Metrics: Real-time tracking of reserve-to-stablecoin ratios
  • Automated Cache Management: Optimized data delivery with cache warming
  • Health Monitoring: System health checks across all integrated services

Project Structure

Below is the project structure:

src/
├── app.module.ts            # Root module
├── main.ts                  # Entry point
├── api/                     # API features
│   ├── stablecoins/         # Stablecoin-related endpoints
│   ├── reserve/             # Reserve-related endpoints
│   └── health/              # Health check endpoints
├── common/                      
│   └── services/            # Shared services   
├── types/                   # Shared types/interfaces
└── utils/                   # Utility functions

System Architecture

The Mento Analytics API is hosted on Google Cloud Platform (GCP) using Cloud Run with logging handled by Cloud Logging. The diagram below illustrates the high-level architecture and data flow:

Mento Analytics API Overview

API Documentation

Detailed documentaion for the API endpoints is available at /docs when running the application.

Data Sources & Updates

Data Sources

  • On-chain data from multiple networks:
    • Celo: Mento SDK beta + Infura
    • Ethereum: Mento SDK beta + Infura
    • Bitcoin: Blockchain.info & Blockstream
  • Price feeds: CoinmarketCap API for real-time asset pricing
  • Exchange rate data: API Layer exchange rates API

Data Update Frequency

Data provided by the API will be < 1 hour old. Data is only updated on an hourly schedule.

Cache Management

The API implements a cache warming strategy to ensure data availability:

  1. Initial warmup on service start
  2. Scheduled refreshes every hour
  3. Manual invalidation via admin endpoints - To Be Added

Configuration Guide

Adding New Stablecoins

Stablecoins are fetched directly from the blockchain using the Mento SDK. Additional information is requred for the price and image.

  1. Add a fiat ticker for the stablecoin in the SDK repo
  2. Publish the new sdk package version and update the verion in the API repo
  3. Add an svg image for the stablecoin to the tokens directory, ensuring the filename matches the symbol.
  4. Deploy changes and verify in /stablecoins endpoint

Managing Reserve Addresses

  1. Update addresses in api/reserve/config/addresses.config.ts
  2. Deploy changes and verify in /reserve endpoints

Adding Reserve Assets

Reserve assets are fetched directly from the blockchain using the Mento SDK. However the metadata is needed to enrich the data. This is hardcoded to reduce the number of external calls.

  1. Add asset configuration to api/reserve/config/assets.config.ts
  2. Deploy changes and verify in /reserve endpoints

Monitoring & Logs

Application Logs

  • GCP Cloud Logging: View Logs
  • Log levels:
    • INFO: Regular operation events
    • WARN: Potential issues requiring attention
    • ERROR: Critical issues affecting operation
    • DEBUG: Detailed information for development

Monitoring Dashboard

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published