From 7b64a78cf4b821867e1a0906e2f8f1eca244f705 Mon Sep 17 00:00:00 2001 From: Claudia Date: Thu, 11 Apr 2024 13:55:36 +0200 Subject: [PATCH] feat: create a constant for the default index of undefined voting mode --- packages/subgraph/src/plugin/plugin.ts | 11 ++++++++--- packages/subgraph/src/utils/constants.ts | 4 +++- packages/subgraph/tests/helpers/method-classes.ts | 7 ++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/subgraph/src/plugin/plugin.ts b/packages/subgraph/src/plugin/plugin.ts index 662851f2..984d9e35 100644 --- a/packages/subgraph/src/plugin/plugin.ts +++ b/packages/subgraph/src/plugin/plugin.ts @@ -14,7 +14,12 @@ import { MembershipContractAnnounced, TokenVoting, } from '../../generated/templates/TokenVoting/TokenVoting'; -import {RATIO_BASE, VOTER_OPTIONS, VOTING_MODES} from '../utils/constants'; +import { + RATIO_BASE, + VOTER_OPTIONS, + VOTING_MODES, + VOTING_MODE_UNDEFINED_INDEX, +} from '../utils/constants'; import {identifyAndFetchOrCreateERC20TokenEntity} from '../utils/erc20'; import {generateMemberEntityId, generateVoteEntityId} from '../utils/ids'; import { @@ -73,7 +78,7 @@ export function _handleProposalCreated( let votingModeIndex = parameters.votingMode; if (!VOTING_MODES.has(votingModeIndex)) { // if the voting mode is not defined, set it to 'Undefined' - votingModeIndex = 10; + votingModeIndex = VOTING_MODE_UNDEFINED_INDEX; } const votingMode = VOTING_MODES.get(votingModeIndex); @@ -273,7 +278,7 @@ export function handleVotingSettingsUpdated( let votingModeIndex = event.params.votingMode; if (!VOTING_MODES.has(votingModeIndex)) { // if the voting mode is not defined, set it to 'Undefined' - votingModeIndex = 10; + votingModeIndex = VOTING_MODE_UNDEFINED_INDEX; } const votingMode = VOTING_MODES.get(votingModeIndex); diff --git a/packages/subgraph/src/utils/constants.ts b/packages/subgraph/src/utils/constants.ts index e11b9cbd..611a6c30 100644 --- a/packages/subgraph/src/utils/constants.ts +++ b/packages/subgraph/src/utils/constants.ts @@ -17,6 +17,8 @@ export enum TransferType { Deposit, } +export const VOTING_MODE_UNDEFINED_INDEX = 10; + export const DECODE_OFFSET = '0x0000000000000000000000000000000000000000000000000000000000000020'; @@ -40,7 +42,7 @@ export const VOTING_MODES = new Map() .set(0, 'Standard') .set(1, 'EarlyExecution') .set(2, 'VoteReplacement') - .set(10, 'Undefined'); + .set(VOTING_MODE_UNDEFINED_INDEX, 'Undefined'); export const TOKEN_VOTING_INTERFACE_ID = '0x50eb001e'; export const ADDRESSLIST_VOTING_INTERFACE_ID = '0x5f21eb8b'; diff --git a/packages/subgraph/tests/helpers/method-classes.ts b/packages/subgraph/tests/helpers/method-classes.ts index 8c4c4cdb..ac1755f5 100644 --- a/packages/subgraph/tests/helpers/method-classes.ts +++ b/packages/subgraph/tests/helpers/method-classes.ts @@ -28,6 +28,7 @@ import { VOTER_OPTIONS, VOTE_OPTIONS, VOTING_MODES, + VOTING_MODE_UNDEFINED_INDEX, } from '../../src/utils/constants'; import {generateMemberEntityId} from '../../src/utils/ids'; import { @@ -205,7 +206,7 @@ class TokenVotingProposalMethods extends TokenVotingProposal { this.votingModeIndex = votingModeIndex; this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(10) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); this.minVotingPower = BigInt.fromString(MIN_VOTING_POWER); @@ -384,7 +385,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { this.votingModeIndex = votingModeIndex; // for event we need the index of the mapping to simulate the contract event this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(10) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); this.supportThreshold = BigInt.fromString(SUPPORT_THRESHOLD); this.minParticipation = BigInt.fromString(MIN_PARTICIPATION); @@ -440,7 +441,7 @@ class TokenVotingPluginMethods extends TokenVotingPlugin { this.votingModeIndex = votingModeIndex; this.votingMode = VOTING_MODES.has(parseInt(votingModeIndex)) ? (VOTING_MODES.get(parseInt(votingModeIndex)) as string) - : (VOTING_MODES.get(10) as string); + : (VOTING_MODES.get(VOTING_MODE_UNDEFINED_INDEX) as string); this.supportThreshold = newSupportThreshold; this.minParticipation = newMinParticipation; this.minDuration = newMinDuration;