Skip to content

Commit

Permalink
index governor reconfigured events
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Jun 2, 2024
1 parent 4d120fa commit 1be47da
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
18 changes: 18 additions & 0 deletions src/EVENT_PROCESSORS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
} from "./events/staker";
import {
DescribedEvent,
GovernorReconfiguredEvent,
GovernorCanceledEvent,
GovernorCreationThresholdBreached,
GovernorExecutedEvent,
Expand All @@ -51,6 +52,7 @@ import {
parseGovernorExecutedEvent,
parseGovernorProposedEvent,
parseGovernorVotedEvent,
parseGovernorReconfigured,
} from "./events/governor";
import {
parseRegistrationEvent,
Expand Down Expand Up @@ -430,4 +432,20 @@ export const EVENT_PROCESSORS = [
await dao.insertGovernorProposalDescribedEvent(parsed, key);
},
},
<EventProcessor<GovernorReconfiguredEvent>>{
filter: {
fromAddress: FieldElement.fromBigInt(process.env.GOVERNOR_ADDRESS),
keys: [
// Reconfigured
FieldElement.fromBigInt(
0x02b9973fd701ab68169e139e241db74576eca4e885bad73d016982a59f1ac9fbn
),
],
},
parser: parseGovernorReconfigured,
async handle(dao, { parsed, key }): Promise<void> {
logger.debug("GovernorReconfigured", { parsed, key });
await dao.insertGovernorReconfiguredEvent(parsed, key);
},
},
] as const;
70 changes: 61 additions & 9 deletions src/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
GovernorCreationThresholdBreached,
GovernorExecutedEvent,
GovernorProposedEvent,
GovernorReconfiguredEvent,
GovernorVotedEvent,
} from "./events/governor";
import { TokenRegistrationEvent } from "./events/tokenRegistry";
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -1551,6 +1569,7 @@ export class DAO {
key.transactionHash,
parsed.id,
parsed.proposer,
parsed.config_version,
],
});
}
Expand Down Expand Up @@ -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,
],
});
}
}
24 changes: 24 additions & 0 deletions src/events/governor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
backwardsCompatibleParserAdditionalArgument,
combineParsers,
GetParserType,
parseAddress,
Expand All @@ -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
Expand Down Expand Up @@ -62,3 +67,22 @@ export const parseDescribedEvent = combineParsers({
description: { index: 1, parser: parseByteArray },
});
export type DescribedEvent = GetParserType<typeof parseDescribedEvent>;

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<typeof parseGovernorConfig>;

export const parseGovernorReconfigured = combineParsers({
new_config: { index: 0, parser: parseGovernorConfig },
version: { index: 1, parser: parseU64 },
});
export type GovernorReconfiguredEvent = GetParserType<
typeof parseGovernorReconfigured
>;

0 comments on commit 1be47da

Please sign in to comment.