Skip to content

Commit

Permalink
Merge pull request #2936 from IntersectMBO/staging
Browse files Browse the repository at this point in the history
GovTool - v2.0.11-patch2
  • Loading branch information
MSzalowski authored Feb 10, 2025
2 parents 197b0eb + fae9ff1 commit d176709
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ changes.
### Added

- Add metadata url and hash to drep details [Issue 2911](https://github.com/IntersectMBO/govtool/issues/2911)
- Add CC votes percentages, not voted and Ratification threshold

### Fixed

Expand Down
25 changes: 24 additions & 1 deletion govtool/backend/sql/get-network-metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,24 @@ AlwaysNoConfidenceVotingPower AS (
),
TotalDRepDistr AS (
SELECT SUM(COALESCE(amount, 0))::bigint total_drep_distr FROM drep_distr where epoch_no = (SELECT no from CurrentEpoch)
),
CommitteeMembersCount AS (
SELECT COUNT(*) AS no_of_committee_members FROM committee_member
),
LatestGovAction AS (
SELECT gap.id, gap.enacted_epoch
FROM gov_action_proposal gap
JOIN CurrentEpoch ce ON gap.enacted_epoch < ce.no
ORDER BY gap.id DESC
LIMIT 1
),
CommitteeThreshold AS (
SELECT
c.*
FROM committee c
LEFT JOIN LatestGovAction lga ON c.gov_action_proposal_id = lga.id
WHERE (c.gov_action_proposal_id IS NOT NULL AND lga.id IS NOT NULL)
OR (c.gov_action_proposal_id IS NULL)
)
SELECT
CurrentEpoch.no AS epoch_no,
Expand All @@ -204,7 +222,10 @@ SELECT
TotalRegisteredDirectVoters.unique_direct_voters AS total_registered_direct_voters,
AlwaysAbstainVotingPower.amount AS always_abstain_voting_power,
AlwaysNoConfidenceVotingPower.amount AS always_no_confidence_voting_power,
meta.network_name
meta.network_name,
CommitteeMembersCount.no_of_committee_members,
CommitteeThreshold.quorum_numerator,
CommitteeThreshold.quorum_denominator
FROM CurrentEpoch
CROSS JOIN CurrentBlock
CROSS JOIN UniqueDelegators
Expand All @@ -221,4 +242,6 @@ CROSS JOIN TotalActiveCIP119CompliantDReps
CROSS JOIN TotalRegisteredDirectVoters
CROSS JOIN AlwaysAbstainVotingPower
CROSS JOIN AlwaysNoConfidenceVotingPower
CROSS JOIN CommitteeMembersCount
CROSS JOIN CommitteeThreshold
CROSS JOIN meta;
3 changes: 3 additions & 0 deletions govtool/backend/src/VVA/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,7 @@ getNetworkMetrics = do
, getNetworkMetricsResponseAlwaysAbstainVotingPower = networkMetricsAlwaysAbstainVotingPower
, getNetworkMetricsResponseAlwaysNoConfidenceVotingPower = networkMetricsAlwaysNoConfidenceVotingPower
, getNetworkMetricsResponseNetworkName = networkMetricsNetworkName
, getNetworkMetricsResponseNoOfCommitteeMembers = networkMetricsNoOfCommitteeMembers
, getNetworkMetricsResponseQuorumNumerator = networkMetricsQuorumNumerator
, getNetworkMetricsResponseQuorumDenominator = networkMetricsQuorumDenominator
}
8 changes: 7 additions & 1 deletion govtool/backend/src/VVA/API/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,9 @@ data GetNetworkMetricsResponse
, getNetworkMetricsResponseAlwaysAbstainVotingPower :: Integer
, getNetworkMetricsResponseAlwaysNoConfidenceVotingPower :: Integer
, getNetworkMetricsResponseNetworkName :: Text
, getNetworkMetricsResponseNoOfCommitteeMembers :: Integer
, getNetworkMetricsResponseQuorumNumerator :: Integer
, getNetworkMetricsResponseQuorumDenominator :: Integer
}

deriveJSON (jsonOptions "getNetworkMetricsResponse") ''GetNetworkMetricsResponse
Expand All @@ -917,7 +920,10 @@ exampleGetNetworkMetricsResponse =
<> "\"totalRegisteredDirectVoters\": 0,"
<> "\"alwaysAbstainVotingPower\": 0,"
<> "\"alwaysNoConfidenceVotingPower\": 0,"
<> "\"networkName\": \"Mainnet\"}"
<> "\"networkName\": \"Mainnet\","
<> "\"noOfCommitteeMembers\": 7,"
<> "\"quorumNumerator\": 2,"
<> "\"quorumDenominator\": 3}"

instance ToSchema GetNetworkMetricsResponse where
declareNamedSchema _ = pure $ NamedSchema (Just "GetNetworkMetricsResponse") $ mempty
Expand Down
6 changes: 6 additions & 0 deletions govtool/backend/src/VVA/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ networkMetrics = withPool $ \conn -> do
, always_abstain_voting_power
, always_no_confidence_voting_power
, network_name
, no_of_committee_members
, quorum_numerator
, quorum_denominator
)] -> return $ NetworkMetrics
current_time
epoch_no
Expand All @@ -71,4 +74,7 @@ networkMetrics = withPool $ \conn -> do
always_abstain_voting_power
always_no_confidence_voting_power
network_name
no_of_committee_members
quorum_numerator
quorum_denominator
_ -> throwError $ CriticalError "Could not query the network metrics. This should never happen."
3 changes: 3 additions & 0 deletions govtool/backend/src/VVA/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ data NetworkMetrics
, networkMetricsAlwaysAbstainVotingPower :: Integer
, networkMetricsAlwaysNoConfidenceVotingPower :: Integer
, networkMetricsNetworkName :: Text
, networkMetricsNoOfCommitteeMembers :: Integer
, networkMetricsQuorumNumerator :: Integer
, networkMetricsQuorumDenominator :: Integer
}

data Delegation
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/components/atoms/VotePill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const ccVoteLabelKey: Record<string, string> = {
yes: "votes.constitutional",
no: "votes.unconstitutional",
abstain: "votes.abstain",
notvoted: "",
notvoted: "votes.notVoted",
};

type VoteExtended = Vote | "notVoted";
Expand Down
27 changes: 19 additions & 8 deletions govtool/frontend/src/components/molecules/VotesSubmitted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export const VotesSubmitted = ({
const { t } = useTranslation();
const { epochParams, networkMetrics } = useAppContext();

const noOfCommitteeMembers = networkMetrics?.noOfCommitteeMembers ?? 0;
const ccThreshold = (
networkMetrics?.quorumDenominator
? networkMetrics.quorumNumerator / networkMetrics.quorumDenominator
: 0
).toPrecision(2);

// Coming from be
// Equal to: total active drep stake + auto no-confidence stake
const totalStakeControlledByDReps =
Expand Down Expand Up @@ -96,15 +103,16 @@ export const VotesSubmitted = ({
? 100
: undefined;

const ccYesVotesPercentage =
ccYesVotes + ccNoVotes
? (ccYesVotes / (ccYesVotes + ccNoVotes)) * 100
: undefined;
const ccNoVotesPercentage = ccYesVotesPercentage
? 100 - ccYesVotesPercentage
: ccNoVotes
? 100
const ccYesVotesPercentage = noOfCommitteeMembers
? (ccYesVotes / noOfCommitteeMembers) * 100
: undefined;
const ccNoVotesPercentage = noOfCommitteeMembers
? (ccNoVotes / noOfCommitteeMembers) * 100
: undefined;
const ccNotVotedVotes =
noOfCommitteeMembers - ccYesVotes - ccNoVotes - ccAbstainVotes;
const ccNotVotedVotesPercentage =
100 - (ccYesVotesPercentage ?? 0) - (ccNoVotesPercentage ?? 0);

return (
<Box
Expand Down Expand Up @@ -193,6 +201,9 @@ export const VotesSubmitted = ({
abstainVotes={ccAbstainVotes}
yesVotesPercentage={ccYesVotesPercentage}
noVotesPercentage={ccNoVotesPercentage}
notVotedVotes={ccNotVotedVotes}
notVotedPercentage={ccNotVotedVotesPercentage}
threshold={Number(ccThreshold)}
/>
)}
</Box>
Expand Down
3 changes: 3 additions & 0 deletions govtool/frontend/src/models/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export type NetworkMetrics = {
alwaysAbstainVotingPower: number;
alwaysNoConfidenceVotingPower: number;
networkName: string;
noOfCommitteeMembers: number;
quorumNumerator: number;
quorumDenominator: number;
};

export type VoterInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ export const GovernanceActionDetailsCardComponent: Story = {

await expect(canvas.getAllByText(/yes/i)).toHaveLength(2);
await expect(canvas.getAllByText(/abstain/i)).toHaveLength(3);
await expect(canvas.getAllByText(/no/i)).toHaveLength(2);
await expect(canvas.getAllByText(/no/i)).toHaveLength(4);
await expect(canvas.getAllByText(/constitutional/i)).toHaveLength(3);
await expect(canvas.getAllByText(/not voted/i)).toHaveLength(2);
},
};

Expand Down

0 comments on commit d176709

Please sign in to comment.