diff --git a/src/EVENT_PROCESSORS.ts b/src/EVENT_PROCESSORS.ts index 0d41dab..a7678b5 100644 --- a/src/EVENT_PROCESSORS.ts +++ b/src/EVENT_PROCESSORS.ts @@ -40,6 +40,7 @@ import { } from "./events/staker"; import { DescribedEvent, + GovernorReconfiguredEvent, GovernorCanceledEvent, GovernorCreationThresholdBreached, GovernorExecutedEvent, @@ -51,6 +52,7 @@ import { parseGovernorExecutedEvent, parseGovernorProposedEvent, parseGovernorVotedEvent, + parseGovernorReconfigured, } from "./events/governor"; import { parseRegistrationEvent, @@ -430,4 +432,20 @@ export const EVENT_PROCESSORS = [ await dao.insertGovernorProposalDescribedEvent(parsed, key); }, }, + >{ + filter: { + fromAddress: FieldElement.fromBigInt(process.env.GOVERNOR_ADDRESS), + keys: [ + // Reconfigured + FieldElement.fromBigInt( + 0x02b9973fd701ab68169e139e241db74576eca4e885bad73d016982a59f1ac9fbn + ), + ], + }, + parser: parseGovernorReconfigured, + async handle(dao, { parsed, key }): Promise { + logger.debug("GovernorReconfigured", { parsed, key }); + await dao.insertGovernorReconfiguredEvent(parsed, key); + }, + }, ] as const; diff --git a/src/dao.ts b/src/dao.ts index 24e24a5..a29abf2 100644 --- a/src/dao.ts +++ b/src/dao.ts @@ -26,6 +26,7 @@ import { GovernorCreationThresholdBreached, GovernorExecutedEvent, GovernorProposedEvent, + GovernorReconfiguredEvent, GovernorVotedEvent, } from "./events/governor"; import { TokenRegistrationEvent } from "./events/tokenRegistry"; @@ -322,12 +323,29 @@ export class DAO { CREATE INDEX IF NOT EXISTS idx_staker_withdrawn_delegate_from_address ON staker_staked USING btree (delegate, from_address); CREATE INDEX IF NOT EXISTS idx_staker_withdrawn_from_address_delegate ON staker_staked USING btree (from_address, delegate); + CREATE TABLE IF NOT EXISTS governor_reconfigured + ( + event_id int8 REFERENCES event_keys (id) ON DELETE CASCADE PRIMARY KEY, + + version BIGINT NOT NULL, + + voting_start_delay BIGINT NOT NULL, + voting_period BIGINT NOT NULL, + voting_weight_smoothing_duration BIGINT NOT NULL, + quorum NUMERIC NOT NULL, + proposal_creation_threshold NUMERIC NOT NULL, + execution_delay BIGINT NOT NULL, + execution_window BIGINT NOT NULL + ); + CREATE UNIQUE INDEX IF NOT EXISTS idx_governor_reconfigured_version ON governor_reconfigured USING btree (version); + CREATE TABLE IF NOT EXISTS governor_proposed ( - event_id int8 REFERENCES event_keys (id) ON DELETE CASCADE PRIMARY KEY, + event_id int8 REFERENCES event_keys (id) ON DELETE CASCADE PRIMARY KEY, - id NUMERIC NOT NULL, - proposer NUMERIC NOT NULL + id NUMERIC NOT NULL, + proposer NUMERIC NOT NULL, + config_version BIGINT REFERENCES governor_reconfigured (version) ON DELETE CASCADE ); CREATE UNIQUE INDEX IF NOT EXISTS idx_governor_proposed_id ON governor_proposed USING btree (id); @@ -343,9 +361,9 @@ export class DAO { CREATE TABLE IF NOT EXISTS governor_canceled ( - event_id int8 REFERENCES event_keys (id) ON DELETE CASCADE PRIMARY KEY, + event_id int8 REFERENCES event_keys (id) ON DELETE CASCADE PRIMARY KEY, - id NUMERIC NOT NULL + id NUMERIC NOT NULL ); CREATE UNIQUE INDEX IF NOT EXISTS idx_governor_canceled_id ON governor_canceled USING btree (id); @@ -1516,8 +1534,8 @@ export class DAO { inserted_governor_proposed AS ( INSERT INTO governor_proposed - (event_id, id, proposer) - VALUES ((SELECT id FROM inserted_event), $5, $6)) + (event_id, id, proposer, config_version) + VALUES ((SELECT id FROM inserted_event), $5, $6, $7)) INSERT INTO governor_proposed_calls (proposal_id, index, to_address, selector, calldata) VALUES @@ -1539,8 +1557,8 @@ export class DAO { RETURNING id) INSERT INTO governor_proposed - (event_id, id, proposer) - VALUES ((SELECT id FROM inserted_event), $5, $6); + (event_id, id, proposer, config_version) + VALUES ((SELECT id FROM inserted_event), $5, $6, $7); `; await this.pg.query({ text: query, @@ -1551,6 +1569,7 @@ export class DAO { key.transactionHash, parsed.id, parsed.proposer, + parsed.config_version, ], }); } @@ -1714,4 +1733,37 @@ export class DAO { ], }); } + + async insertGovernorReconfiguredEvent( + parsed: GovernorReconfiguredEvent, + key: EventKey + ) { + await this.pg.query({ + text: ` + WITH inserted_event AS ( + INSERT INTO event_keys (block_number, transaction_index, event_index, transaction_hash) + VALUES ($1, $2, $3, $4) + RETURNING id) + INSERT + INTO governor_reconfigured + (event_id, version, voting_start_delay, voting_period, voting_weight_smoothing_duration, quorum, + proposal_creation_threshold, execution_delay, execution_window) + VALUES ((SELECT id FROM inserted_event), $5, $6, $7, $8, $9, $10, $11, $12) + `, + values: [ + key.blockNumber, + key.transactionIndex, + key.eventIndex, + key.transactionHash, + parsed.version, + parsed.new_config.voting_start_delay, + parsed.new_config.voting_period, + parsed.new_config.voting_weight_smoothing_duration, + parsed.new_config.quorum, + parsed.new_config.proposal_creation_threshold, + parsed.new_config.execution_delay, + parsed.new_config.execution_window, + ], + }); + } } diff --git a/src/events/governor.ts b/src/events/governor.ts index d2504f1..cd02d62 100644 --- a/src/events/governor.ts +++ b/src/events/governor.ts @@ -1,4 +1,5 @@ import { + backwardsCompatibleParserAdditionalArgument, combineParsers, GetParserType, parseAddress, @@ -21,6 +22,10 @@ export const parseGovernorProposedEvent = combineParsers({ id: { index: 0, parser: parseFelt252 }, proposer: { index: 1, parser: parseAddress }, calls: { index: 2, parser: parseSpanOf(parseCall) }, + config_version: { + index: 3, + parser: backwardsCompatibleParserAdditionalArgument(parseU64), + }, }); export type GovernorProposedEvent = GetParserType< typeof parseGovernorProposedEvent @@ -62,3 +67,22 @@ export const parseDescribedEvent = combineParsers({ description: { index: 1, parser: parseByteArray }, }); export type DescribedEvent = GetParserType; + +export const parseGovernorConfig = combineParsers({ + voting_start_delay: { index: 0, parser: parseU64 }, + voting_period: { index: 1, parser: parseU64 }, + voting_weight_smoothing_duration: { index: 2, parser: parseU64 }, + quorum: { index: 3, parser: parseU128 }, + proposal_creation_threshold: { index: 4, parser: parseU128 }, + execution_delay: { index: 5, parser: parseU64 }, + execution_window: { index: 6, parser: parseU64 }, +}); +export type GovernorConfig = GetParserType; + +export const parseGovernorReconfigured = combineParsers({ + new_config: { index: 0, parser: parseGovernorConfig }, + version: { index: 1, parser: parseU64 }, +}); +export type GovernorReconfiguredEvent = GetParserType< + typeof parseGovernorReconfigured +>;