Add a script to generate stage1 participants and allocations with given validators (#25)

Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675)
Requires cerc-io/fixturenet-laconicd-stack#14

Reviewed-on: #25
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit was merged in pull request #25.
This commit is contained in:
2024-08-19 10:12:29 +00:00
committed by nabarun
parent 98e882bf28
commit 8c672c0966
7 changed files with 118154 additions and 102 deletions
+10 -1
View File
@@ -26,11 +26,20 @@
cp .env.example .env
```
- Generate a list of onboarded participants and allocations with given list of validators:
```bash
yarn participants-with-filtered-validators --validators-csv <validators-csv-file> --participant-alloc <participant-alloc-amount> --validator-alloc <validator-alloc-amount> --output <output-json-file> --output-allocs <output-allocs-json-file>
# Example:
# yarn participants-with-filtered-validators --validators-csv ./validators.csv --participant-alloc 200000000000 --validator-alloc 1000200000000000 --output stage1-participants-$(date +"%Y-%m-%dT%H%M%S").json --output-allocs stage1-allocs-$(date +"%Y-%m-%dT%H%M%S").json
```
- Map subscribers to onboarded participants:
```bash
yarn map-subscribers-to-participants --subscribers-csv <subscribers-csv-file> --output <output-csv-file>
# Example:
# yarn map-subscribers-to-participants --subscribers-csv subscribers.csv --output result-$(date +"%Y-%m-%d%Y%m%d").csv
# yarn map-subscribers-to-participants --subscribers-csv subscribers.csv --output result-$(date +"%Y-%m-%dT%H%M%S").csv
```
@@ -0,0 +1,114 @@
import * as fs from 'fs';
import * as path from 'path';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import dotenv from 'dotenv';
import { Registry } from '@cerc-io/registry-sdk';
dotenv.config();
const LACONICD_GQL_ENDPOINT = process.env.LACONICD_GQL_ENDPOINT || 'https://laconicd.laconic.com/api';
const LACONICD_RPC_ENDPOINT = process.env.LACONICD_RPC_ENDPOINT || 'https://laconicd.laconic.com';
const LACONICD_CHAIN_ID = process.env.LACONICD_CHAIN_ID || 'laconic_9000-1';
async function main(): Promise<void> {
const argv = _getArgv();
const registry = new Registry(LACONICD_GQL_ENDPOINT, LACONICD_RPC_ENDPOINT, LACONICD_CHAIN_ID);
console.time('time_taken_getParticipants');
const participants = await registry.getParticipants();
console.log('Fetched participants, count:', participants.length);
console.timeEnd('time_taken_getParticipants');
let validators: Array<string> = await readValidators(argv.validatorsCsv);
console.log('Read validators, count:', validators.length);
let stage1Allocations: Array<{ 'cosmos_address': string, balance: string }> = [];
const stage1Participants = participants.map((participant: any) => {
const outputParticipant: any = {
'cosmos_address': participant.cosmosAddress,
'nitro_address': participant.nitroAddress,
'kyc_id': participant.kycId
};
if (validators.includes(participant.cosmosAddress)) {
outputParticipant.role = 'validator';
stage1Allocations.push({
cosmos_address: participant.cosmosAddress,
balance: argv.validatorAlloc
});
// Remove processed participant from validators list
validators = validators.filter(val => val !== participant.cosmosAddress);
} else {
outputParticipant.role = 'participant';
stage1Allocations.push({
cosmos_address: participant.cosmosAddress,
balance: argv.participantAlloc
});
}
return outputParticipant;
});
// Provide allocs for remaining validators
validators.forEach(val => {
stage1Allocations.push({
cosmos_address: val,
balance: argv.validatorAlloc
});
});
const participantsOutputFilePath = path.resolve(argv.output);
fs.writeFileSync(participantsOutputFilePath, JSON.stringify(stage1Participants, null, 2));
console.log(`Onboarded participants with filtered validators written to ${participantsOutputFilePath}`);
const allocsOutputFilePath = path.resolve(argv.outputAllocs);
fs.writeFileSync(allocsOutputFilePath, JSON.stringify(stage1Allocations, null, 2));
console.log(`Stage1 allocations written to ${allocsOutputFilePath}`);
}
async function readValidators(subscribersCsvPath: string): Promise<any> {
const fileContent = fs.readFileSync(path.resolve(subscribersCsvPath), { encoding: 'utf-8' });
return fileContent.split('\r\n').map(address => address.trim());
}
function _getArgv (): any {
return yargs(hideBin(process.argv))
.option('validatorsCsv', {
type: 'string',
demandOption: true,
describe: 'Path to a CSV file with validators list',
})
.option('participantAlloc', {
type: 'string',
demandOption: true,
describe: 'Participant stage1 balance allocation',
})
.option('validatorAlloc', {
type: 'string',
demandOption: true,
describe: 'Validator stage1 balance allocation',
})
.option('output', {
type: 'string',
demandOption: true,
describe: 'Path to the output JSON file',
})
.option('outputAllocs', {
type: 'string',
demandOption: true,
describe: 'Path to the output JSON file with allocs',
})
.help()
.argv;
}
main().catch(err => {
console.log(err);
});