Skip to content

Scraper of onchain events for Li.Fi FeeCollector contracts. Serverless ethers-based scanning of EVM chains, MongoDB storage and support for REST API queries

License

Notifications You must be signed in to change notification settings

ja88a/feecollector-report

Repository files navigation

LiFi FeeCollector Events Reporter

Overview

Purpose

This is a mono-repository for developing and running 2 main backend services, on top of the LiFi protocol:

  1. A serverless scraper of on-chain events: FeeCollected events emitted by the LiFi FeeCollector contracts deployed on several blockchains. A scraping session can be triggered manually or scheduled to run periodically on a given blockchain.

  2. A backend REST/json API to report the fees collected by the integrators of the LiFi protocol

A database stores and indexes the collected onchain events, as well as the supported chains' configuration. The scraper feeds the DB while the reporter consumes its data, towards clients.

Technical Stack

Deployment architecture overview

The FeeCollected events are stored in a MongoDB database/cluster. Typegoose is used, on top of the Mongoose ODM, as well as the GrapeoffJS/kindagoose for the NestJS integration.

The NestJS development framework is used as one of the main foundation for developing the backend modules.

The Serverless framework/tooling is used for developing locally the events scraper and deploying the functions on AWS Lambda for instance.

Docker containers are used for packaging and for easily managing the composition of servers to run locally.

Installation

Node.js must be installed on your OS. Lower versions than 18.x have not been tested. The usage of NVM is recommended to install and manage your Node.js environments.

pnpm is used as the package manager for this project, as well as for managing this mono-repository workspaces. Please refer to its installation instructions.

To install all the necessary packages and tooling dependencies, run:

pnpm project:init

Which is equivalent to the following individual commands:

# Init the Git submodule(s), e.g. LiFi contract types
$ git submodule init

# Download/install all package dependencies
$ pnpm install

# Build / tsc compilation to sub dirs `dist`
$ pnpm -r build

Running the Apps Locally

Start MongoDB via Docker Compose

Run locally only the Mongo Database:

docker compose up fcrs-db

Run locally the CollectedFees Reporter API, a Mongo DB and a Redis cache server:

docker compose up

Note that the events scraper remains to be manually started.

Start an Events Scraping session

As a Nodejs-based CLI command

The blocks of the specified target blockchain are scanned and the found FeeCollector.FeeCollected events are imported into MongoDB.

cd ./events-scraper && pnpm start

The default target blockchain is then 'Polygon mainnet' (key: pol), and the target LiFi FeeCollector contract is 0xbD6C7B0d2f68c2b7805d88388319cfB6EcB50eA9.

Refer to events-scraper main and the chains' configuration in fee-collector.config to change the default config.

Using the Serverless Offline Framework

You can use the local Serverless offline runtime framework, run:

# Start all available serverless functions
$ pnpm serverless:offline

# From the sub-project
$ cd ./events-scraper && pnpm serverless offline

Then you trigger the scraping function using a GET request http://localhost:3003/dev/collectedfees/scrap/{chainKey}

Start the Collected Fees Reporter API

For locally running the service, run:

cd ./fees-reporter && pnpm start

You can then request for a report on fees collected by a given integrator, e.g. http://localhost:3000/api/v1/collectedfees/integrators/0xD5e230cEa6dA2F0C62bdeED2Cf85326F1063e27D

A sample response (JSON) to a request for the collected fees by an integrator is available here.

An optional Swagger/OpenAPIv3 documentation of the REST API is published when having the env variable OPENAPI_PUBLISH set to true:

A screenshot of the Web view is available here.

Test

Actual testing framework is not much developped yet.

# unit tests
$ pnpm run test

# e2e tests
$ pnpm run test:e2e

# test coverage
$ pnpm run test:cov

License

This project is licensed under the GNU AGPL-v3.

About

Scraper of onchain events for Li.Fi FeeCollector contracts. Serverless ethers-based scanning of EVM chains, MongoDB storage and support for REST API queries

Topics

Resources

License

Stars

Watchers

Forks