The Validator Selector tool is designed for obtaining comprehensive details about validators and eras from specified Substrate chains. This updated version introduces new enhancements in terms of efficient data fetching, data representation, and additional functionalities.
- Connect to any specified Substrate chain.
- Retrieve information about validators and eras.
- Enhanced data representation for validators.
- Insight into validators' commissions, era points, bonded tokens, and more.
- Exponential Moving Average (EMA) calculation for validator era points.
- Ensure you have Node.js and npm installed.
- Install the required dependencies
npm install
- Install the CLI tool globally
npm install -g .
- Build the script
tsc
To connect to a specified chain (e.g., Polkadot):
validator-selector --chain polkadot
The script will fetch and display information about validators and eras from the specified chain.
Inside the .vscode folder in your workspace, create a file named launch.json with the following content:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/lib/main.js",
"outFiles": ["${workspaceFolder}/lib/**/*.js"],
"args": ["--chain polkadot"],
"sourceMaps": true
}
]
}
Inside the .vscode folder, create a file named tasks.json with the following content:
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"option": "watch",
"problemMatcher": ["$tsc-watch"],
"group": {
"kind": "build",
"isDefault": true
},
"label": "tsc: watch - tsconfig.json"
}
]
}
If you need to debug the tool using Visual Studio Code, follow these steps:
- Make sure you've added the launch.json and tasks.json files to the .vscode folder in your workspace.
- Start the TypeScript file watcher task by pressing Ctrl + Shift + B or selecting Run Build Task... from the Command Palette. This task will continuously compile the TypeScript code into JavaScript upon changes.
- Make sure to uncomment the line // const chainInfo = config.chains['polkadot']; in the main.ts script to set the chain to Polkadot for the debugging session.
- Press F5 or click on the green play button in the Debugging panel to start the debugger. By default, the script will start with the --chain polkadot argument.
This script is the main entry point of the tool. Upon execution:
- The script uses the command-line argument to determine which chain to connect to.
- It fetches the validator data, enriching it with key details and representing large numerical values as strings for better readability.
This script is responsible for all the data-fetching functionalities:
- Connects to the specified chain.
- Fetches and filters validator and era data.
- Calculates the Exponential Moving Average (EMA) of era points for each validator.
- Retrieves bonded token information for each validator.
- Sorting functionalities based on criteria like commission and EMA.
The tool references a config file to determine its configurations. This includes details like maximum commission, maximum validators, maximum eras, and chain-specific details. Adjust this configuration as per your requirements.