PBO Delegation Pool Activity Tracker
Overview
The PBO Delegation Pool Activity Tracker tool is designed to keep track on activities related to PBO delegation pool. It fetches data from an RPC endpoint, processes it and store it on database. The application also provides an REST API for querying data related to pool.
Building PBO-Delegation-Pool-Activity-Tracker binary from source
Once Rust and PostgresDB is installed and setup, you can use the following commands to build the binaries:
-
Clone the repository:
git clone https://github.com/Entropy-Foundation/supra-toolbox.git -
Go to project location:
cd trackers/pbo-delegation-pool-activity-tracker -
Migrate sql to database:
DATABASE_URL="postgres://<username>:<password>@localhost/<database_name>" cargo sqlx migrate run -
Build sql queries:
DATABASE_URL="postgres://<username>:<password>@localhost/<database_name>" cargo sqlx prepare -- --lib -
Build the binary:
DATABASE_URL="postgres://<username>:<password>@localhost/<database_name>" cargo build --release
Prerequisite
Prepare config.json file
The config.json file contains the information about pool details, delegator stake details, pool stake details and legacy commission percentage data.
Example Structure of the file:
{
"pool_details": {
"block_height": 0,
"data": {
"<pool_id>": {
"operator_address": "<operator_address>",
"commission_info": {
"current_commission_percentage": <current_commission_percentage>,
"next_commission_percentage": <next_commission_percentage>,
"next_commission_effective_time": <next_commission_effective_time>
}
},
}
},
"delegator_stake_details": {
"<pool_id>": {
"<delegator_1>": <stake_amount>,
"<delegator_2>": <stake_amount>,
},
},
"pool_stake_details": {
"<pool_id>": <stake_amount>,
},
"legacy_commission_percentage_data": {
"<pool_id>": {
"<epoch_id>": <percentage>,
},
"<pool_id>": {
"<epoch_id>": <percentage>,
},
}
}
Usage
Run the application with the following command options:
- To run application from Block with config file.
$ cargo run --release -- --rpc-url <RPC_URL> --config "config.json" --start-block 0
2. To run application with first syncing data from snapshot.
```sh
$ cargo run --release -- --rpc-url <RPC_URL> --config "config.json" --sync-db-path <PATH_TO_STORE>
- To run application from start block with default config and latest block.
$ cargo run --release -- --rpc-url <RPC_URL>
HTTP API Endpoints
The application starts an HTTP server to provide an interface for querying reward data. The default port is 3000.
| Endpoint | Method | Description |
|---|---|---|
/pbo-tracker/pools | GET | Retrieves list of pools. |
/pbo-tracker/pools/{pool_address}/delegators | GET | Retrieves list of delegators for given pool_address. |
/pbo-tracker/pools/{pool_address}/events | GET | Retrieves list of queried events in for given pool_adress. |
/pbo-tracker/delegators/{delegator_address}/events | GET | Retrieves list of queried events for given delegator_adress. |
/pbo-tracker/delegators/{delegator_address}/stakes | GET | Retrieves list of stakes of given delegator_adress. |
/pbo-tracker/pools/{pool_address}/operators/{operator_address}/commission | GET | Retrieves commission for given operator_address for pool_address. |
/pbo-tracker/pools/{pool_address}/delegators/{delegator_address}/commission | GET | Retrieves commission for given delegator_address for pool_address. |
Example API request:
$ curl http://machine_ip:3000/pools
Logging Mechanism
The application uses env_logger for logging various stages of execution, including data fetching, processing, and errors.
Log Levels
ERROR- Logs failures during execution.INFO- Logs key status updates.DEBUG- Logs detailed data processing information.
Enabling Logging
To enable info logs, set the RUST_LOG environment variable before running the application:
$ RUST_LOG=info cargo run --release -- --rpc-url <RPC_URL>
This helps in monitoring and debugging the service effectively.