From 99666f8ccaa22113824c12069cf04814c9af7835 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 7 Sep 2023 12:29:15 +0200 Subject: [PATCH] feat: add initial vote impelmentation --- src/commands/governance-v3.ts | 28 +++++++++++++++++++++++++--- src/simulate/govv3/governance.ts | 2 +- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/commands/governance-v3.ts b/src/commands/governance-v3.ts index d728326..4847cba 100644 --- a/src/commands/governance-v3.ts +++ b/src/commands/governance-v3.ts @@ -1,7 +1,7 @@ -import { Command } from '@commander-js/extra-typings'; +import { Command, Option } from '@commander-js/extra-typings'; import { simulateProposal } from '../simulate/govv3/simulate'; import { GovernanceV3Sepolia } from '@bgd-labs/aave-address-book'; -import { getGovernance } from '../simulate/govv3/governance'; +import { State, getGovernance } from '../simulate/govv3/governance'; import { createPublicClient } from 'viem'; import { sepoliaClient } from '../utils/rpcClients'; import { logInfo } from '../utils/logger'; @@ -95,6 +95,28 @@ export function addCommand(program: Command) { .description('generates the proof etc') .requiredOption('--proposalId ', 'proposalId to generate the proof for') .action((name, options) => { - console.log('simulate', options); + console.log('proof', options); + }); + + govV3 + .command('vote') + .description('vote for or against any given proposal') + .requiredOption('--proposalId ', 'proposalId to vote for') + .option('--for', 'Vote in favour of the proposal') + .option('--against', 'vote against the proposal') + .action(async (name, options) => { + const governance = getGovernance(GovernanceV3Sepolia.GOVERNANCE, sepoliaClient); + const proposalId = BigInt(options.getOptionValue('proposalId')); + const proposal = await governance.governanceContract.read.getProposal([proposalId]); + if (proposal.state !== State.Active) { + throw new Error('can only vote on active proposals'); + } + const voteFor = options.getOptionValue('for'); + const voteAgainst = options.getOptionValue('against'); + if (voteFor && voteAgainst) { + throw new Error('you must either vote --for, or --against'); + } + + logInfo('Vote', 'not yet implemented'); }); } diff --git a/src/simulate/govv3/governance.ts b/src/simulate/govv3/governance.ts index b64b8ca..5968b4e 100644 --- a/src/simulate/govv3/governance.ts +++ b/src/simulate/govv3/governance.ts @@ -62,7 +62,7 @@ const SLOTS = { PROPOSALS_MAPPING: 7n, }; -enum State { +export enum State { Null, // proposal does not exists Created, // created, waiting for a cooldown to initiate the balances snapshot Active, // balances snapshot set, voting in progress