Update script to generate account allocations

This commit is contained in:
Prathamesh Musale 2024-08-19 12:47:01 +05:30
parent 5af0500d18
commit eb834a8579
2 changed files with 53 additions and 12 deletions

View File

@ -35,11 +35,11 @@
# yarn map-subscribers-to-participants --subscribers-csv subscribers.csv --output result-$(date +"%Y-%m-%dT%H%M%S").csv # yarn map-subscribers-to-participants --subscribers-csv subscribers.csv --output result-$(date +"%Y-%m-%dT%H%M%S").csv
``` ```
- Generate a list of onboarded participants with given list of validators: - Generate a list of onboarded participants and allocations with given list of validators:
```bash ```bash
yarn participants-with-filtered-validators --validators-csv <validators-csv-file> --output <output-csv-file> 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: # Example:
# yarn participants-with-filtered-validators --validators-csv ./validators.csv --output stage1-participants-$(date +"%Y-%m-%dT%H%M%S").csv # 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
``` ```

View File

@ -19,11 +19,14 @@ async function main(): Promise<void> {
console.time('time_taken_getParticipants'); console.time('time_taken_getParticipants');
const participants = await registry.getParticipants(); const participants = await registry.getParticipants();
console.log('Fetched participants, count:', participants.length);
console.timeEnd('time_taken_getParticipants'); console.timeEnd('time_taken_getParticipants');
const validators = await readValidators(argv.validatorsCsv); let validators: Array<string> = await readValidators(argv.validatorsCsv);
console.log('Read validators, count:', validators.length); console.log('Read validators, count:', validators.length);
let stage1Allocations: Array<{ 'cosmos_address': string, balance: string }> = [];
const stage1Participants = participants.map((participant: any) => { const stage1Participants = participants.map((participant: any) => {
const outputParticipant: any = { const outputParticipant: any = {
'cosmos_address': participant.cosmosAddress, 'cosmos_address': participant.cosmosAddress,
@ -31,18 +34,43 @@ async function main(): Promise<void> {
'kyc_id': participant.kycId 'kyc_id': participant.kycId
}; };
if ((validators as Array<string>).includes(participant.cosmosAddress)) { if (validators.includes(participant.cosmosAddress)) {
outputParticipant.role = 'validator'; 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 { } else {
outputParticipant.role = 'participant'; outputParticipant.role = 'participant';
stage1Allocations.push({
cosmos_address: participant.cosmosAddress,
balance: argv.participantAlloc
});
} }
return outputParticipant; return outputParticipant;
}); });
const outputFilePath = path.resolve(argv.output); // Provide allocs for remaining validators
fs.writeFileSync(outputFilePath, JSON.stringify(stage1Participants, null, 2)); validators.forEach(val => {
console.log(`Onboarded participants with filtered validators written to ${outputFilePath}`); 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> { async function readValidators(subscribersCsvPath: string): Promise<any> {
@ -53,16 +81,29 @@ async function readValidators(subscribersCsvPath: string): Promise<any> {
function _getArgv (): any { function _getArgv (): any {
return yargs(hideBin(process.argv)) return yargs(hideBin(process.argv))
.option('validatorsCsv', { .option('validatorsCsv', {
alias: 'v',
type: 'string', type: 'string',
demandOption: true, demandOption: true,
describe: 'Path to a CSV file with validators list', describe: 'Path to a CSV file with validators list',
}) })
.option('output', { .option('participantAlloc', {
alias: 'o',
type: 'string', type: 'string',
demandOption: true, demandOption: true,
describe: 'Path to the output CSV file', 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() .help()
.argv; .argv;