Improve Governance Functions
This commit is contained in:
parent
6ab73c7d59
commit
75f57937e3
13
dist/events/base.d.ts
vendored
13
dist/events/base.d.ts
vendored
@ -143,6 +143,7 @@ export declare const proposalState: {
|
||||
};
|
||||
export interface GovernanceProposals extends GovernanceProposalCreatedEvents {
|
||||
title: string;
|
||||
proposerName?: string;
|
||||
forVotes: bigint;
|
||||
againstVotes: bigint;
|
||||
executed: boolean;
|
||||
@ -153,6 +154,8 @@ export interface GovernanceProposals extends GovernanceProposalCreatedEvents {
|
||||
export interface GovernanceVotes extends GovernanceVotedEvents {
|
||||
contact: string;
|
||||
message: string;
|
||||
fromName?: string;
|
||||
voterName?: string;
|
||||
}
|
||||
export interface BaseGovernanceServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract' | 'type'> {
|
||||
Governance: Governance;
|
||||
@ -173,16 +176,14 @@ export declare class BaseGovernanceService extends BaseEventsService<AllGovernan
|
||||
fromBlock: number;
|
||||
}): Promise<BaseEvents<AllGovernanceEvents>>;
|
||||
getAllProposals(): Promise<GovernanceProposals[]>;
|
||||
getVotes(proposalId: number): Promise<{
|
||||
votes: GovernanceVotes[];
|
||||
ensNames: {
|
||||
[key: string]: string;
|
||||
};
|
||||
}>;
|
||||
getVotes(proposalId: number): Promise<GovernanceVotes[]>;
|
||||
getDelegatedBalance(ethAccount: string): Promise<{
|
||||
delegatedAccs: string[];
|
||||
undelegatedAccs: string[];
|
||||
uniq: string[];
|
||||
uniqNames: {
|
||||
[key: string]: string;
|
||||
};
|
||||
balances: bigint[];
|
||||
balance: bigint;
|
||||
}>;
|
||||
|
60
dist/index.js
vendored
60
dist/index.js
vendored
@ -3351,13 +3351,24 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
}
|
||||
async getAllProposals() {
|
||||
const { events } = await this.updateEvents();
|
||||
const [QUORUM_VOTES, proposalStatus] = await Promise.all([
|
||||
const proposalEvents = events.filter((e) => e.event === "ProposalCreated");
|
||||
const allProposers = [...new Set(proposalEvents.map((e) => [e.proposer]).flat())];
|
||||
const [QUORUM_VOTES, proposalStatus, proposerNameRecords] = await Promise.all([
|
||||
this.Governance.QUORUM_VOTES(),
|
||||
this.Aggregator.getAllProposals(this.Governance.target)
|
||||
this.Aggregator.getAllProposals(this.Governance.target),
|
||||
this.ReverseRecords.getNames(allProposers)
|
||||
]);
|
||||
return events.filter((e) => e.event === "ProposalCreated").map(
|
||||
(event, index) => {
|
||||
const { id, description: text } = event;
|
||||
const proposerNames = allProposers.reduce(
|
||||
(acc, address, index) => {
|
||||
if (proposerNameRecords[index]) {
|
||||
acc[address] = proposerNameRecords[index];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
return proposalEvents.map((event, index) => {
|
||||
const { id, proposer, description: text } = event;
|
||||
const status = proposalStatus[index];
|
||||
const { forVotes, againstVotes, executed, extended, state } = status;
|
||||
const { title, description } = parseDescription(id, text);
|
||||
@ -3365,6 +3376,7 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
return {
|
||||
...event,
|
||||
title,
|
||||
proposerName: proposerNames[proposer] || void 0,
|
||||
description,
|
||||
forVotes,
|
||||
againstVotes,
|
||||
@ -3373,22 +3385,13 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
quorum,
|
||||
state: proposalState[String(state)]
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
async getVotes(proposalId) {
|
||||
const { events } = await this.getSavedEvents();
|
||||
const votedEvents = events.filter(
|
||||
(e) => e.event === "Voted" && e.proposalId === proposalId
|
||||
);
|
||||
const votes = votedEvents.map((event) => {
|
||||
const { contact, message } = parseComment(this.Governance, event.input);
|
||||
return {
|
||||
...event,
|
||||
contact,
|
||||
message
|
||||
};
|
||||
});
|
||||
const allVoters = [...new Set(votedEvents.map((e) => [e.from, e.voter]).flat())];
|
||||
const names = await this.ReverseRecords.getNames(allVoters);
|
||||
const ensNames = allVoters.reduce(
|
||||
@ -3400,10 +3403,18 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
},
|
||||
{}
|
||||
);
|
||||
const votes = votedEvents.map((event) => {
|
||||
const { from, voter } = event;
|
||||
const { contact, message } = parseComment(this.Governance, event.input);
|
||||
return {
|
||||
votes,
|
||||
ensNames
|
||||
...event,
|
||||
contact,
|
||||
message,
|
||||
fromName: ensNames[from] || void 0,
|
||||
voterName: ensNames[voter] || void 0
|
||||
};
|
||||
});
|
||||
return votes;
|
||||
}
|
||||
async getDelegatedBalance(ethAccount) {
|
||||
const { events } = await this.getSavedEvents();
|
||||
@ -3418,11 +3429,24 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const balances = await this.Aggregator.getGovernanceBalances(this.Governance.target, uniq);
|
||||
const [balances, uniqNameRecords] = await Promise.all([
|
||||
this.Aggregator.getGovernanceBalances(this.Governance.target, uniq),
|
||||
this.ReverseRecords.getNames(uniq)
|
||||
]);
|
||||
const uniqNames = uniq.reduce(
|
||||
(acc, address, index) => {
|
||||
if (uniqNameRecords[index]) {
|
||||
acc[address] = uniqNameRecords[index];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
return {
|
||||
delegatedAccs,
|
||||
undelegatedAccs,
|
||||
uniq,
|
||||
uniqNames,
|
||||
balances,
|
||||
balance: balances.reduce((acc, curr) => acc + curr, BigInt(0))
|
||||
};
|
||||
|
60
dist/index.mjs
vendored
60
dist/index.mjs
vendored
@ -3330,13 +3330,24 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
}
|
||||
async getAllProposals() {
|
||||
const { events } = await this.updateEvents();
|
||||
const [QUORUM_VOTES, proposalStatus] = await Promise.all([
|
||||
const proposalEvents = events.filter((e) => e.event === "ProposalCreated");
|
||||
const allProposers = [...new Set(proposalEvents.map((e) => [e.proposer]).flat())];
|
||||
const [QUORUM_VOTES, proposalStatus, proposerNameRecords] = await Promise.all([
|
||||
this.Governance.QUORUM_VOTES(),
|
||||
this.Aggregator.getAllProposals(this.Governance.target)
|
||||
this.Aggregator.getAllProposals(this.Governance.target),
|
||||
this.ReverseRecords.getNames(allProposers)
|
||||
]);
|
||||
return events.filter((e) => e.event === "ProposalCreated").map(
|
||||
(event, index) => {
|
||||
const { id, description: text } = event;
|
||||
const proposerNames = allProposers.reduce(
|
||||
(acc, address, index) => {
|
||||
if (proposerNameRecords[index]) {
|
||||
acc[address] = proposerNameRecords[index];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
return proposalEvents.map((event, index) => {
|
||||
const { id, proposer, description: text } = event;
|
||||
const status = proposalStatus[index];
|
||||
const { forVotes, againstVotes, executed, extended, state } = status;
|
||||
const { title, description } = parseDescription(id, text);
|
||||
@ -3344,6 +3355,7 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
return {
|
||||
...event,
|
||||
title,
|
||||
proposerName: proposerNames[proposer] || void 0,
|
||||
description,
|
||||
forVotes,
|
||||
againstVotes,
|
||||
@ -3352,22 +3364,13 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
quorum,
|
||||
state: proposalState[String(state)]
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
async getVotes(proposalId) {
|
||||
const { events } = await this.getSavedEvents();
|
||||
const votedEvents = events.filter(
|
||||
(e) => e.event === "Voted" && e.proposalId === proposalId
|
||||
);
|
||||
const votes = votedEvents.map((event) => {
|
||||
const { contact, message } = parseComment(this.Governance, event.input);
|
||||
return {
|
||||
...event,
|
||||
contact,
|
||||
message
|
||||
};
|
||||
});
|
||||
const allVoters = [...new Set(votedEvents.map((e) => [e.from, e.voter]).flat())];
|
||||
const names = await this.ReverseRecords.getNames(allVoters);
|
||||
const ensNames = allVoters.reduce(
|
||||
@ -3379,10 +3382,18 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
},
|
||||
{}
|
||||
);
|
||||
const votes = votedEvents.map((event) => {
|
||||
const { from, voter } = event;
|
||||
const { contact, message } = parseComment(this.Governance, event.input);
|
||||
return {
|
||||
votes,
|
||||
ensNames
|
||||
...event,
|
||||
contact,
|
||||
message,
|
||||
fromName: ensNames[from] || void 0,
|
||||
voterName: ensNames[voter] || void 0
|
||||
};
|
||||
});
|
||||
return votes;
|
||||
}
|
||||
async getDelegatedBalance(ethAccount) {
|
||||
const { events } = await this.getSavedEvents();
|
||||
@ -3397,11 +3408,24 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const balances = await this.Aggregator.getGovernanceBalances(this.Governance.target, uniq);
|
||||
const [balances, uniqNameRecords] = await Promise.all([
|
||||
this.Aggregator.getGovernanceBalances(this.Governance.target, uniq),
|
||||
this.ReverseRecords.getNames(uniq)
|
||||
]);
|
||||
const uniqNames = uniq.reduce(
|
||||
(acc, address, index) => {
|
||||
if (uniqNameRecords[index]) {
|
||||
acc[address] = uniqNameRecords[index];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
return {
|
||||
delegatedAccs,
|
||||
undelegatedAccs,
|
||||
uniq,
|
||||
uniqNames,
|
||||
balances,
|
||||
balance: balances.reduce((acc, curr) => acc + curr, BigInt(0))
|
||||
};
|
||||
|
60
dist/tornado.umd.js
vendored
60
dist/tornado.umd.js
vendored
@ -59653,13 +59653,24 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
}
|
||||
async getAllProposals() {
|
||||
const { events } = await this.updateEvents();
|
||||
const [QUORUM_VOTES, proposalStatus] = await Promise.all([
|
||||
const proposalEvents = events.filter((e) => e.event === "ProposalCreated");
|
||||
const allProposers = [...new Set(proposalEvents.map((e) => [e.proposer]).flat())];
|
||||
const [QUORUM_VOTES, proposalStatus, proposerNameRecords] = await Promise.all([
|
||||
this.Governance.QUORUM_VOTES(),
|
||||
this.Aggregator.getAllProposals(this.Governance.target)
|
||||
this.Aggregator.getAllProposals(this.Governance.target),
|
||||
this.ReverseRecords.getNames(allProposers)
|
||||
]);
|
||||
return events.filter((e) => e.event === "ProposalCreated").map(
|
||||
(event, index) => {
|
||||
const { id, description: text } = event;
|
||||
const proposerNames = allProposers.reduce(
|
||||
(acc, address, index) => {
|
||||
if (proposerNameRecords[index]) {
|
||||
acc[address] = proposerNameRecords[index];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
return proposalEvents.map((event, index) => {
|
||||
const { id, proposer, description: text } = event;
|
||||
const status = proposalStatus[index];
|
||||
const { forVotes, againstVotes, executed, extended, state } = status;
|
||||
const { title, description } = parseDescription(id, text);
|
||||
@ -59667,6 +59678,7 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
return {
|
||||
...event,
|
||||
title,
|
||||
proposerName: proposerNames[proposer] || void 0,
|
||||
description,
|
||||
forVotes,
|
||||
againstVotes,
|
||||
@ -59675,22 +59687,13 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
quorum,
|
||||
state: proposalState[String(state)]
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
async getVotes(proposalId) {
|
||||
const { events } = await this.getSavedEvents();
|
||||
const votedEvents = events.filter(
|
||||
(e) => e.event === "Voted" && e.proposalId === proposalId
|
||||
);
|
||||
const votes = votedEvents.map((event) => {
|
||||
const { contact, message } = parseComment(this.Governance, event.input);
|
||||
return {
|
||||
...event,
|
||||
contact,
|
||||
message
|
||||
};
|
||||
});
|
||||
const allVoters = [...new Set(votedEvents.map((e) => [e.from, e.voter]).flat())];
|
||||
const names = await this.ReverseRecords.getNames(allVoters);
|
||||
const ensNames = allVoters.reduce(
|
||||
@ -59702,10 +59705,18 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
},
|
||||
{}
|
||||
);
|
||||
const votes = votedEvents.map((event) => {
|
||||
const { from, voter } = event;
|
||||
const { contact, message } = parseComment(this.Governance, event.input);
|
||||
return {
|
||||
votes,
|
||||
ensNames
|
||||
...event,
|
||||
contact,
|
||||
message,
|
||||
fromName: ensNames[from] || void 0,
|
||||
voterName: ensNames[voter] || void 0
|
||||
};
|
||||
});
|
||||
return votes;
|
||||
}
|
||||
async getDelegatedBalance(ethAccount) {
|
||||
const { events } = await this.getSavedEvents();
|
||||
@ -59720,11 +59731,24 @@ class BaseGovernanceService extends BaseEventsService {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const balances = await this.Aggregator.getGovernanceBalances(this.Governance.target, uniq);
|
||||
const [balances, uniqNameRecords] = await Promise.all([
|
||||
this.Aggregator.getGovernanceBalances(this.Governance.target, uniq),
|
||||
this.ReverseRecords.getNames(uniq)
|
||||
]);
|
||||
const uniqNames = uniq.reduce(
|
||||
(acc, address, index) => {
|
||||
if (uniqNameRecords[index]) {
|
||||
acc[address] = uniqNameRecords[index];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
return {
|
||||
delegatedAccs,
|
||||
undelegatedAccs,
|
||||
uniq,
|
||||
uniqNames,
|
||||
balances,
|
||||
balance: balances.reduce((acc, curr) => acc + curr, BigInt(0))
|
||||
};
|
||||
|
2
dist/tornado.umd.min.js
vendored
2
dist/tornado.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -686,6 +686,7 @@ function parseComment(Governance: Governance, calldata: string): { contact: stri
|
||||
|
||||
export interface GovernanceProposals extends GovernanceProposalCreatedEvents {
|
||||
title: string;
|
||||
proposerName?: string;
|
||||
forVotes: bigint;
|
||||
againstVotes: bigint;
|
||||
executed: boolean;
|
||||
@ -697,6 +698,8 @@ export interface GovernanceProposals extends GovernanceProposalCreatedEvents {
|
||||
export interface GovernanceVotes extends GovernanceVotedEvents {
|
||||
contact: string;
|
||||
message: string;
|
||||
fromName?: string;
|
||||
voterName?: string;
|
||||
}
|
||||
|
||||
export interface BaseGovernanceServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract' | 'type'> {
|
||||
@ -845,14 +848,28 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
|
||||
async getAllProposals(): Promise<GovernanceProposals[]> {
|
||||
const { events } = await this.updateEvents();
|
||||
|
||||
const [QUORUM_VOTES, proposalStatus] = await Promise.all([
|
||||
const proposalEvents = events.filter((e) => e.event === 'ProposalCreated') as GovernanceProposalCreatedEvents[];
|
||||
|
||||
const allProposers = [...new Set(proposalEvents.map((e) => [e.proposer]).flat())];
|
||||
|
||||
const [QUORUM_VOTES, proposalStatus, proposerNameRecords] = await Promise.all([
|
||||
this.Governance.QUORUM_VOTES(),
|
||||
this.Aggregator.getAllProposals(this.Governance.target),
|
||||
this.ReverseRecords.getNames(allProposers),
|
||||
]);
|
||||
|
||||
return (events.filter((e) => e.event === 'ProposalCreated') as GovernanceProposalCreatedEvents[]).map(
|
||||
(event, index) => {
|
||||
const { id, description: text } = event;
|
||||
const proposerNames = allProposers.reduce(
|
||||
(acc, address, index) => {
|
||||
if (proposerNameRecords[index]) {
|
||||
acc[address] = proposerNameRecords[index];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{} as { [key: string]: string },
|
||||
);
|
||||
|
||||
return proposalEvents.map((event, index) => {
|
||||
const { id, proposer, description: text } = event;
|
||||
|
||||
const status = proposalStatus[index];
|
||||
|
||||
@ -865,6 +882,7 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
|
||||
return {
|
||||
...event,
|
||||
title,
|
||||
proposerName: proposerNames[proposer] || undefined,
|
||||
description,
|
||||
forVotes,
|
||||
againstVotes,
|
||||
@ -873,32 +891,16 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
|
||||
quorum,
|
||||
state: proposalState[String(state)],
|
||||
};
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async getVotes(proposalId: number): Promise<{
|
||||
votes: GovernanceVotes[];
|
||||
ensNames: {
|
||||
[key: string]: string;
|
||||
};
|
||||
}> {
|
||||
async getVotes(proposalId: number): Promise<GovernanceVotes[]> {
|
||||
const { events } = await this.getSavedEvents();
|
||||
|
||||
const votedEvents = events.filter(
|
||||
(e) => e.event === 'Voted' && (e as GovernanceVotedEvents).proposalId === proposalId,
|
||||
) as GovernanceVotedEvents[];
|
||||
|
||||
const votes = votedEvents.map((event) => {
|
||||
const { contact, message } = parseComment(this.Governance, event.input);
|
||||
|
||||
return {
|
||||
...event,
|
||||
contact,
|
||||
message,
|
||||
};
|
||||
});
|
||||
|
||||
const allVoters = [...new Set(votedEvents.map((e) => [e.from, e.voter]).flat())];
|
||||
|
||||
const names = await this.ReverseRecords.getNames(allVoters);
|
||||
@ -913,10 +915,21 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
|
||||
{} as { [key: string]: string },
|
||||
);
|
||||
|
||||
const votes = votedEvents.map((event) => {
|
||||
const { from, voter } = event;
|
||||
|
||||
const { contact, message } = parseComment(this.Governance, event.input);
|
||||
|
||||
return {
|
||||
votes,
|
||||
ensNames,
|
||||
...event,
|
||||
contact,
|
||||
message,
|
||||
fromName: ensNames[from] || undefined,
|
||||
voterName: ensNames[voter] || undefined,
|
||||
};
|
||||
});
|
||||
|
||||
return votes;
|
||||
}
|
||||
|
||||
async getDelegatedBalance(ethAccount: string) {
|
||||
@ -941,12 +954,26 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
|
||||
return true;
|
||||
});
|
||||
|
||||
const balances = await this.Aggregator.getGovernanceBalances(this.Governance.target, uniq);
|
||||
const [balances, uniqNameRecords] = await Promise.all([
|
||||
this.Aggregator.getGovernanceBalances(this.Governance.target, uniq),
|
||||
this.ReverseRecords.getNames(uniq),
|
||||
]);
|
||||
|
||||
const uniqNames = uniq.reduce(
|
||||
(acc, address, index) => {
|
||||
if (uniqNameRecords[index]) {
|
||||
acc[address] = uniqNameRecords[index];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{} as { [key: string]: string },
|
||||
);
|
||||
|
||||
return {
|
||||
delegatedAccs,
|
||||
undelegatedAccs,
|
||||
uniq,
|
||||
uniqNames,
|
||||
balances,
|
||||
balance: balances.reduce((acc, curr) => acc + curr, BigInt(0)),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user