Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Prod - 31.10.24 #242

Merged
merged 7 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/components/votes-list/votes-list.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const getParticipantPercentage = (
if (totalVotes > 0n) {
const decimals = 8;
const accuracy = 10n ** BigInt(decimals);

const weightScaled = participant.weight * 100n;

const valueInRawBN = (weightScaled * accuracy) / totalVotes;
Expand All @@ -70,7 +69,7 @@ const getParticipantPercentage = (

if (formatted.includes(".")) {
const [integers, remainingDecimals] = formatted.split(".");
return `${integers}.${remainingDecimals.substring(0, 2)}%`;
return `${integers}.${remainingDecimals.substring(0, 5)}%`;
} else {
return `${formatted}%`;
}
Expand Down
18 changes: 12 additions & 6 deletions src/lib/graphql/subgraph/fragments/proposalFields.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ fragment ProposalFields on Proposal {

# Votes
votecast {
timestamp
voter {
id
id
support{
weight
}
support {
support
receipt {
id
voter {
id
}
weight
support {
id
support
}
}
}

# Start & End Time
startBlock
endBlock
Expand Down
23 changes: 15 additions & 8 deletions src/lib/graphql/subgraph/generated/subgraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7286,7 +7286,7 @@ export enum _SubgraphErrorPolicy_ {
Deny = 'deny'
}

export type ProposalFieldsFragment = { __typename?: 'Proposal', proposalId: any, description: string, startBlock: any, endBlock: any, queued: boolean, canceled: boolean, executed: boolean, state: ProposalState, proposer: { __typename?: 'Account', id: any }, proposalCreated: Array<{ __typename?: 'ProposalCreated', timestamp: any }>, proposalQueued: Array<{ __typename?: 'ProposalQueued', eta: any }>, proposalExecuted: Array<{ __typename?: 'ProposalExecuted', transaction: { __typename?: 'Transaction', id: string, timestamp: any } }>, votecast: Array<{ __typename?: 'VoteCast', timestamp: any, voter: { __typename?: 'Account', id: any }, support: { __typename?: 'ProposalSupport', support: number, weight: any } }>, metadata: { __typename?: 'ProposalMetadata', title: string, description: string }, votes: { __typename?: 'ProposalVotes', total: any, for: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, against: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, abstain: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> } } };
export type ProposalFieldsFragment = { __typename?: 'Proposal', proposalId: any, description: string, startBlock: any, endBlock: any, queued: boolean, canceled: boolean, executed: boolean, state: ProposalState, proposer: { __typename?: 'Account', id: any }, proposalCreated: Array<{ __typename?: 'ProposalCreated', timestamp: any }>, proposalQueued: Array<{ __typename?: 'ProposalQueued', eta: any }>, proposalExecuted: Array<{ __typename?: 'ProposalExecuted', transaction: { __typename?: 'Transaction', id: string, timestamp: any } }>, votecast: Array<{ __typename?: 'VoteCast', id: string, support: { __typename?: 'ProposalSupport', weight: any }, receipt: { __typename?: 'VoteReceipt', id: string, weight: any, voter: { __typename?: 'Account', id: any }, support: { __typename?: 'ProposalSupport', id: string, support: number } } }>, metadata: { __typename?: 'ProposalMetadata', title: string, description: string }, votes: { __typename?: 'ProposalVotes', total: any, for: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, against: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, abstain: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> } } };

export type GetAllLocksQueryVariables = Exact<{ [key: string]: never; }>;

Expand All @@ -7313,12 +7313,12 @@ export type GetProposalQueryVariables = Exact<{
}>;


export type GetProposalQuery = { __typename?: 'Query', proposals: Array<{ __typename?: 'Proposal', proposalId: any, description: string, startBlock: any, endBlock: any, queued: boolean, canceled: boolean, executed: boolean, state: ProposalState, calls: Array<{ __typename?: 'ProposalCall', index: number, value: any, signature: string, calldata: any, target: { __typename?: 'Account', id: any } }>, proposer: { __typename?: 'Account', id: any }, proposalCreated: Array<{ __typename?: 'ProposalCreated', timestamp: any }>, proposalQueued: Array<{ __typename?: 'ProposalQueued', eta: any }>, proposalExecuted: Array<{ __typename?: 'ProposalExecuted', transaction: { __typename?: 'Transaction', id: string, timestamp: any } }>, votecast: Array<{ __typename?: 'VoteCast', timestamp: any, voter: { __typename?: 'Account', id: any }, support: { __typename?: 'ProposalSupport', support: number, weight: any } }>, metadata: { __typename?: 'ProposalMetadata', title: string, description: string }, votes: { __typename?: 'ProposalVotes', total: any, for: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, against: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, abstain: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> } } }> };
export type GetProposalQuery = { __typename?: 'Query', proposals: Array<{ __typename?: 'Proposal', proposalId: any, description: string, startBlock: any, endBlock: any, queued: boolean, canceled: boolean, executed: boolean, state: ProposalState, calls: Array<{ __typename?: 'ProposalCall', index: number, value: any, signature: string, calldata: any, target: { __typename?: 'Account', id: any } }>, proposer: { __typename?: 'Account', id: any }, proposalCreated: Array<{ __typename?: 'ProposalCreated', timestamp: any }>, proposalQueued: Array<{ __typename?: 'ProposalQueued', eta: any }>, proposalExecuted: Array<{ __typename?: 'ProposalExecuted', transaction: { __typename?: 'Transaction', id: string, timestamp: any } }>, votecast: Array<{ __typename?: 'VoteCast', id: string, support: { __typename?: 'ProposalSupport', weight: any }, receipt: { __typename?: 'VoteReceipt', id: string, weight: any, voter: { __typename?: 'Account', id: any }, support: { __typename?: 'ProposalSupport', id: string, support: number } } }>, metadata: { __typename?: 'ProposalMetadata', title: string, description: string }, votes: { __typename?: 'ProposalVotes', total: any, for: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, against: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, abstain: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> } } }> };

export type GetProposalsQueryVariables = Exact<{ [key: string]: never; }>;


export type GetProposalsQuery = { __typename?: 'Query', proposals: Array<{ __typename?: 'Proposal', proposalId: any, description: string, startBlock: any, endBlock: any, queued: boolean, canceled: boolean, executed: boolean, state: ProposalState, proposer: { __typename?: 'Account', id: any }, proposalCreated: Array<{ __typename?: 'ProposalCreated', timestamp: any }>, proposalQueued: Array<{ __typename?: 'ProposalQueued', eta: any }>, proposalExecuted: Array<{ __typename?: 'ProposalExecuted', transaction: { __typename?: 'Transaction', id: string, timestamp: any } }>, votecast: Array<{ __typename?: 'VoteCast', timestamp: any, voter: { __typename?: 'Account', id: any }, support: { __typename?: 'ProposalSupport', support: number, weight: any } }>, metadata: { __typename?: 'ProposalMetadata', title: string, description: string }, votes: { __typename?: 'ProposalVotes', total: any, for: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, against: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, abstain: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> } } }> };
export type GetProposalsQuery = { __typename?: 'Query', proposals: Array<{ __typename?: 'Proposal', proposalId: any, description: string, startBlock: any, endBlock: any, queued: boolean, canceled: boolean, executed: boolean, state: ProposalState, proposer: { __typename?: 'Account', id: any }, proposalCreated: Array<{ __typename?: 'ProposalCreated', timestamp: any }>, proposalQueued: Array<{ __typename?: 'ProposalQueued', eta: any }>, proposalExecuted: Array<{ __typename?: 'ProposalExecuted', transaction: { __typename?: 'Transaction', id: string, timestamp: any } }>, votecast: Array<{ __typename?: 'VoteCast', id: string, support: { __typename?: 'ProposalSupport', weight: any }, receipt: { __typename?: 'VoteReceipt', id: string, weight: any, voter: { __typename?: 'Account', id: any }, support: { __typename?: 'ProposalSupport', id: string, support: number } } }>, metadata: { __typename?: 'ProposalMetadata', title: string, description: string }, votes: { __typename?: 'ProposalVotes', total: any, for: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, against: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> }, abstain: { __typename?: 'VoteType', total: any, participants: Array<{ __typename?: 'Participant', address: string, weight: any }> } } }> };

export const ProposalFieldsFragmentDoc = gql`
fragment ProposalFields on Proposal {
Expand All @@ -7340,14 +7340,21 @@ export const ProposalFieldsFragmentDoc = gql`
}
}
votecast {
timestamp
voter {
id
}
id
support {
support
weight
}
receipt {
id
voter {
id
}
weight
support {
id
support
}
}
}
startBlock
endBlock
Expand Down
58 changes: 16 additions & 42 deletions src/lib/graphql/subgraph/policies/Proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ProposalVotes,
Scalars,
VoteCast,
VoteReceipt,
} from "@/lib/graphql/subgraph/generated/subgraph";

type ProposalID = Scalars["ID"]["output"];
Expand Down Expand Up @@ -46,46 +47,28 @@ export const ProposalPolicy: TypePolicy = {

return votecastRefs.reduce(
(acc: ProposalVotes, votecastRef) => {
const voterRef = readField<Account>("voter", votecastRef);
const supportRef = readField<ProposalSupport>(
"support",
votecastRef,
);
const rawWeight = readField<string>("weight", supportRef) || "";
const weight = BigInt(rawWeight);
const receipt = readField<VoteReceipt>("receipt", votecastRef);
if (!receipt) return acc;

const voterRef = readField<Account>("voter", receipt);
const supportRef = readField<ProposalSupport>("support", receipt);
const weight = BigInt(readField<string>("weight", receipt) || "0");
const address = readField<string>("id", voterRef) as Address;
const support = readField<ProposalSupport["support"]>(
"support",
supportRef,
);

const support = readField<number>("support", supportRef);
switch (support) {
// AGAINST
case 0:
case 0: // AGAINST
acc.against.total += weight;
acc.against.participants.push({
address,
weight,
});
acc.against.participants.push({ address, weight });
break;

// FOR
case 1:
case 1: // FOR
acc.for.total += weight;
acc.for.participants.push({
address,
weight,
});
acc.for.participants.push({ address, weight });
break;

// ABSTAIN
case 2:
case 2: // ABSTAIN
acc.abstain.total += weight;
acc.abstain.participants.push({
address,
weight,
});
acc.abstain.participants.push({ address, weight });
break;

default:
Expand All @@ -96,18 +79,9 @@ export const ProposalPolicy: TypePolicy = {
return acc;
},
{
for: {
participants: [],
total: 0n,
},
against: {
participants: [],
total: 0n,
},
abstain: {
participants: [],
total: 0n,
},
for: { participants: [], total: 0n },
against: { participants: [], total: 0n },
abstain: { participants: [], total: 0n },
total: 0n,
},
);
Expand Down
Loading