From eb834a8579388ebbf2b21844b6ee7ad0ffb0dd79 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Mon, 19 Aug 2024 12:47:01 +0530 Subject: [PATCH] Update script to generate account allocations --- scripts/README.md | 6 +- .../participants-with-filtered-validators.ts | 59 ++++++++++++++++--- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/scripts/README.md b/scripts/README.md index 3f2e039..f1b6e91 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -35,11 +35,11 @@ # 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 - yarn participants-with-filtered-validators --validators-csv --output + yarn participants-with-filtered-validators --validators-csv --participant-alloc --validator-alloc --output --output-allocs # 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 ``` diff --git a/scripts/src/participants-with-filtered-validators.ts b/scripts/src/participants-with-filtered-validators.ts index 94ad544..bf036da 100644 --- a/scripts/src/participants-with-filtered-validators.ts +++ b/scripts/src/participants-with-filtered-validators.ts @@ -19,11 +19,14 @@ async function main(): Promise { console.time('time_taken_getParticipants'); const participants = await registry.getParticipants(); + console.log('Fetched participants, count:', participants.length); console.timeEnd('time_taken_getParticipants'); - const validators = await readValidators(argv.validatorsCsv); + let validators: Array = 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, @@ -31,18 +34,43 @@ async function main(): Promise { 'kyc_id': participant.kycId }; - if ((validators as Array).includes(participant.cosmosAddress)) { + 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; }); - const outputFilePath = path.resolve(argv.output); - fs.writeFileSync(outputFilePath, JSON.stringify(stage1Participants, null, 2)); - console.log(`Onboarded participants with filtered validators written to ${outputFilePath}`); + // 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 { @@ -53,16 +81,29 @@ async function readValidators(subscribersCsvPath: string): Promise { function _getArgv (): any { return yargs(hideBin(process.argv)) .option('validatorsCsv', { - alias: 'v', type: 'string', demandOption: true, describe: 'Path to a CSV file with validators list', }) - .option('output', { - alias: 'o', + .option('participantAlloc', { type: 'string', 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() .argv;