diff --git a/CHANGELOG.md b/CHANGELOG.md index d2bae14cc..4cd31f5f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ changes. ### Fixed -- +- Fix counting submitted votes [Issue 2609](https://github.com/IntersectMBO/govtool/issues/2609) ### Changed diff --git a/govtool/backend/sql/get-network-metrics.sql b/govtool/backend/sql/get-network-metrics.sql index fd4d4d043..17404faa7 100644 --- a/govtool/backend/sql/get-network-metrics.sql +++ b/govtool/backend/sql/get-network-metrics.sql @@ -83,6 +83,16 @@ total_stake_controlled_by_dreps AS ( SUM(dd.amount)::bigint AS total FROM drep_distr dd + WHERE + dd.epoch_no = (SELECT no FROM current_epoch) +), +total_stake_controlled_by_spos AS ( + SELECT + SUM(ps.stake)::bigint AS total + FROM + pool_stat ps + WHERE + ps.epoch_no = (SELECT no FROM current_epoch) ), total_registered_direct_voters AS ( SELECT @@ -176,6 +186,7 @@ SELECT total_drep_votes.count as total_drep_votes, total_registered_dreps.unique_registrations as total_registered_dreps, COALESCE(total_stake_controlled_by_dreps.total, 0) as total_stake_controlled_by_dreps, + COALESCE(total_stake_controlled_by_spos.total, 0) as total_stake_controlled_by_spos, total_active_dreps.unique_active_drep_registrations as total_active_dreps, total_inactive_dreps.total_inactive_dreps as total_inactive_dreps, total_active_cip119_compliant_dreps.unique_active_cip119_compliant_drep_registrations as total_active_cip119_compliant_dreps, @@ -192,6 +203,7 @@ FROM CROSS JOIN total_drep_votes CROSS JOIN total_registered_dreps CROSS JOIN total_stake_controlled_by_dreps + CROSS JOIN total_stake_controlled_by_spos CROSS JOIN total_active_dreps CROSS JOIN total_inactive_dreps CROSS JOIN total_active_cip119_compliant_dreps @@ -208,6 +220,7 @@ GROUP BY total_drep_votes.count, total_registered_dreps.unique_registrations, total_stake_controlled_by_dreps.total, + total_stake_controlled_by_spos.total, total_active_dreps.unique_active_drep_registrations, total_inactive_dreps.total_inactive_dreps, total_active_cip119_compliant_dreps.unique_active_cip119_compliant_drep_registrations, diff --git a/govtool/backend/sql/list-proposals.sql b/govtool/backend/sql/list-proposals.sql index d3bd992c9..a0d61254a 100644 --- a/govtool/backend/sql/list-proposals.sql +++ b/govtool/backend/sql/list-proposals.sql @@ -10,40 +10,32 @@ LatestEpoch AS ( start_time, no FROM - epoch ORDER BY no DESC LIMIT 1 + epoch + ORDER BY + no DESC + LIMIT 1 ), -always_no_confidence_voting_power AS ( +DRepVotingPower AS ( SELECT - coalesce(( - SELECT - amount - FROM drep_hash - LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id - WHERE - drep_hash.view = 'drep_always_no_confidence' ORDER BY epoch_no DESC LIMIT 1), 0) AS amount -), -always_abstain_voting_power AS ( - SELECT - coalesce(( - SELECT - amount - FROM drep_hash - LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id - WHERE - drep_hash.view = 'drep_always_abstain' ORDER BY epoch_no DESC LIMIT 1), 0) AS amount + SUM(CASE WHEN drep_hash.view = 'drep_always_no_confidence' THEN amount ELSE 0 END) AS no_confidence, + SUM(CASE WHEN drep_hash.view = 'drep_always_abstain' THEN amount ELSE 0 END) AS abstain + FROM + drep_hash + LEFT JOIN drep_distr ON drep_hash.id = drep_distr.hash_id + WHERE drep_hash.view IN ('drep_always_no_confidence', 'drep_always_abstain') ), -committee_data AS ( +CommitteeData AS ( SELECT DISTINCT ON (ch.raw) encode(ch.raw, 'hex') AS hash, cm.expiration_epoch, ch.has_script FROM committee_member cm - JOIN - committee_hash ch ON cm.committee_hash_id = ch.id - ORDER BY ch.raw, cm.expiration_epoch DESC + JOIN committee_hash ch ON cm.committee_hash_id = ch.id + ORDER BY + ch.raw, cm.expiration_epoch DESC ), -parsed_description AS ( +ParsedDescription AS ( SELECT gov_action_proposal.id, description->'tag' AS tag, @@ -55,17 +47,17 @@ parsed_description AS ( WHERE gov_action_proposal.type = 'NewCommittee' ), -members_to_be_removed AS ( +MembersToBeRemoved AS ( SELECT id, - json_agg(value->>'keyHash') AS members_to_be_removed + json_agg(VALUE->>'keyHash') AS members_to_be_removed FROM - parsed_description, + ParsedDescription pd, json_array_elements(members_to_be_removed::json) AS value GROUP BY id ), -processed_current_members AS ( +ProcessedCurrentMembers AS ( SELECT pd.id, json_agg( @@ -75,12 +67,12 @@ processed_current_members AS ( ) ) AS current_members FROM - parsed_description pd, + ParsedDescription pd, jsonb_each_text(pd.members) AS kv(key, value) GROUP BY pd.id ), -enriched_current_members AS ( +EnrichedCurrentMembers AS ( SELECT pcm.id, json_agg( @@ -92,53 +84,100 @@ enriched_current_members AS ( ) ) AS enriched_members FROM - processed_current_members pcm + ProcessedCurrentMembers pcm LEFT JOIN json_array_elements(pcm.current_members) AS member ON true LEFT JOIN - committee_data cm ON cm.hash = encode(decode(member->>'hash', 'hex'), 'hex') + CommitteeData cm ON cm.hash = encode(decode(member->>'hash', 'hex'), 'hex') GROUP BY pcm.id +), +RankedPoolVotes AS ( + SELECT + *, + ROW_NUMBER() OVER (PARTITION BY vp.pool_voter ORDER BY vp.tx_id DESC) AS rn + FROM + voting_procedure vp +), +PoolVotes AS ( + SELECT + rpv.gov_action_proposal_id, + ps.epoch_no, + COUNT(DISTINCT CASE WHEN vote = 'Yes' THEN rpv.pool_voter ELSE 0 END) AS total_unique_votes, + COUNT(DISTINCT CASE WHEN vote = 'No' THEN rpv.pool_voter ELSE 0 END) AS total_unique_votes, + COUNT(DISTINCT CASE WHEN vote = 'Abstain' THEN rpv.pool_voter ELSE 0 END) AS total_unique_votes, + SUM(CASE WHEN rpv.vote = 'Yes' THEN ps.voting_power ELSE 0 END) AS poolYesVotes, + SUM(CASE WHEN rpv.vote = 'No' THEN ps.voting_power ELSE 0 END) AS poolNoVotes, + SUM(CASE WHEN rpv.vote = 'Abstain' THEN ps.voting_power ELSE 0 END) AS poolAbstainVotes + FROM + RankedPoolVotes rpv + JOIN + pool_stat ps + ON rpv.pool_voter = ps.pool_hash_id + WHERE + rpv.rn = 1 AND ps.epoch_no = (SELECT MAX(no) FROM epoch) + GROUP BY + rpv.gov_action_proposal_id, ps.epoch_no +), +CommitteeVotes AS ( + SELECT + gov_action_proposal_id, + + SUM(CASE WHEN vote = 'Yes' THEN 1 ELSE 0 END) AS ccYesVotes, + SUM(CASE WHEN vote = 'No' THEN 1 ELSE 0 END) AS ccNoVotes, + SUM(CASE WHEN vote = 'Abstain' THEN 1 ELSE 0 END) AS ccAbstainVotes + FROM + voting_procedure AS vp + WHERE + vp.committee_voter IS NOT NULL + AND (vp.tx_id, vp.committee_voter, vp.gov_action_proposal_id) IN ( + SELECT MAX(tx_id), committee_voter, gov_action_proposal_id + FROM voting_procedure + WHERE committee_voter IS NOT NULL + GROUP BY committee_voter, gov_action_proposal_id + ) + GROUP BY + gov_action_proposal_id ) SELECT gov_action_proposal.id, - encode(creator_tx.hash, 'hex'), + encode(creator_tx.hash, 'hex') tx_hash, gov_action_proposal.index, gov_action_proposal.type::text, COALESCE( - case when gov_action_proposal.type = 'TreasuryWithdrawals' then + CASE WHEN gov_action_proposal.type = 'TreasuryWithdrawals' THEN ( - select json_agg( + SELECT json_agg( jsonb_build_object( 'receivingAddress', stake_address.view, 'amount', treasury_withdrawal.amount ) ) - from treasury_withdrawal - left join stake_address - on stake_address.id = treasury_withdrawal.stake_address_id - where treasury_withdrawal.gov_action_proposal_id = gov_action_proposal.id + FROM treasury_withdrawal + LEFT JOIN stake_address + ON stake_address.id = treasury_withdrawal.stake_address_id + WHERE treasury_withdrawal.gov_action_proposal_id = gov_action_proposal.id ) - when gov_action_proposal.type::text = 'InfoAction' then + WHEN gov_action_proposal.type::text = 'InfoAction' THEN json_build_object('data', gov_action_proposal.description) - when gov_action_proposal.type::text = 'HardForkInitiation' then + WHEN gov_action_proposal.type::text = 'HardForkInitiation' THEN json_build_object( 'major', (gov_action_proposal.description->'contents'->1->>'major')::int, 'minor', (gov_action_proposal.description->'contents'->1->>'minor')::int ) - when gov_action_proposal.type::text = 'NoConfidence' then + WHEN gov_action_proposal.type::text = 'NoConfidence' THEN json_build_object('data', gov_action_proposal.description->'contents') - when gov_action_proposal.type::text = 'ParameterChange' then + WHEN gov_action_proposal.type::text = 'ParameterChange' THEN json_build_object('data', gov_action_proposal.description->'contents') - when gov_action_proposal.type::text = 'NewConstitution' then + WHEN gov_action_proposal.type::text = 'NewConstitution' THEN json_build_object( 'anchor', gov_action_proposal.description->'contents'->1->'anchor' ) - when gov_action_proposal.type::text = 'NewCommittee' then + WHEN gov_action_proposal.type::text = 'NewCommittee' THEN ( SELECT json_build_object( @@ -148,18 +187,18 @@ SELECT 'threshold', pd.threshold::float ) FROM - parsed_description pd + ParsedDescription pd JOIN - members_to_be_removed mtr ON pd.id = mtr.id + MembersToBeRemoved mtr ON pd.id = mtr.id JOIN - enriched_current_members em ON pd.id = em.id + EnrichedCurrentMembers em ON pd.id = em.id WHERE pd.id = gov_action_proposal.id ) - else - null - end - , '{}'::json) as description, + ELSE + NULL + END + , '{}'::JSON) AS description, CASE WHEN meta.network_name::text = 'mainnet' OR meta.network_name::text = 'preprod' THEN latest_epoch.start_time + (gov_action_proposal.expiration - latest_epoch.no)::bigint * INTERVAL '5 days' @@ -170,7 +209,7 @@ SELECT creator_block.time, creator_block.epoch_no, voting_anchor.url, - encode(voting_anchor.data_hash, 'hex'), + encode(voting_anchor.data_hash, 'hex') data_hash, jsonb_set( ROW_TO_JSON(proposal_params)::jsonb, '{cost_model}', @@ -185,81 +224,53 @@ SELECT off_chain_vote_gov_action_data.abstract, off_chain_vote_gov_action_data.motivation, off_chain_vote_gov_action_data.rationale, - coalesce(Sum(ldd_drep.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0) +( - CASE WHEN gov_action_proposal.type = 'NoConfidence' THEN - always_no_confidence_voting_power.amount - ELSE + COALESCE(SUM(ldd_drep.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0) yes_votes, + COALESCE(SUM(ldd_drep.amount) FILTER (WHERE voting_procedure.vote::text = 'No'), 0) + ( + CASE WHEN gov_action_proposal.type = 'NoConfidence' OR gov_action_proposal.type = 'HardForkInitiation' THEN 0 - END) "yes_votes", - coalesce(Sum(ldd_drep.amount) FILTER (WHERE voting_procedure.vote::text = 'No'), 0) +( - CASE WHEN gov_action_proposal.type = 'NoConfidence' THEN + ELSE + drep_voting_power.no_confidence + END) no_votes, + COALESCE(SUM(ldd_drep.amount) FILTER (WHERE voting_procedure.vote::text = 'Abstain'), 0) + ( + CASE WHEN gov_action_proposal.type = 'NoConfidence' OR gov_action_proposal.type = 'HardForkInitiation' THEN 0 ELSE - always_no_confidence_voting_power.amount - END) "no_votes", - coalesce(Sum(ldd_drep.amount) FILTER (WHERE voting_procedure.vote::text = 'Abstain'), 0) + always_abstain_voting_power.amount "abstain_votes", - coalesce(Sum(ldd_pool.amount) FILTER (WHERE voting_procedure.vote::text = 'Yes'), 0), - coalesce(Sum(ldd_pool.amount) FILTER (WHERE voting_procedure.vote::text = 'No'), 0), - coalesce(Sum(ldd_pool.amount) FILTER (WHERE voting_procedure.vote::text = 'Abstain'), 0), - coalesce(vp_by_cc.ccYesVotes, 0), - coalesce(vp_by_cc.ccNoVotes, 0), - coalesce(vp_by_cc.ccAbstainVotes, 0), + drep_voting_power.abstain + END) abstain_votes, + COALESCE(ps.poolYesVotes, 0) pool_yes_votes, + COALESCE(ps.poolNoVotes, 0) pool_no_votes, + COALESCE(ps.poolAbstainVotes, 0) pool_abstain_votes, + COALESCE(cv.ccYesVotes, 0) cc_yes_votes, + COALESCE(cv.ccNoVotes, 0) cc_no_votes, + COALESCE(cv.ccAbstainVotes, 0) cc_abstain_votes, prev_gov_action.index as prev_gov_action_index, encode(prev_gov_action_tx.hash, 'hex') as prev_gov_action_tx_hash FROM gov_action_proposal - LEFT JOIN treasury_withdrawal - on gov_action_proposal.id = treasury_withdrawal.gov_action_proposal_id - LEFT JOIN stake_address - on stake_address.id = treasury_withdrawal.stake_address_id CROSS JOIN LatestEpoch AS latest_epoch - CROSS JOIN always_no_confidence_voting_power - CROSS JOIN always_abstain_voting_power + CROSS JOIN DRepVotingPower AS drep_voting_power CROSS JOIN meta - JOIN tx AS creator_tx ON creator_tx.id = gov_action_proposal.tx_id - JOIN block AS creator_block ON creator_block.id = creator_tx.block_id + LEFT JOIN tx AS creator_tx ON creator_tx.id = gov_action_proposal.tx_id + LEFT JOIN block AS creator_block ON creator_block.id = creator_tx.block_id LEFT JOIN voting_anchor ON voting_anchor.id = gov_action_proposal.voting_anchor_id - LEFT JOIN param_proposal as proposal_params ON gov_action_proposal.param_proposal = proposal_params.id - LEFT JOIN cost_model AS cost_model ON proposal_params.cost_model_id = cost_model.id LEFT JOIN off_chain_vote_data ON off_chain_vote_data.voting_anchor_id = voting_anchor.id LEFT JOIN off_chain_vote_gov_action_data ON off_chain_vote_gov_action_data.off_chain_vote_data_id = off_chain_vote_data.id - LEFT JOIN voting_procedure ON voting_procedure.gov_action_proposal_id = gov_action_proposal.id - LEFT JOIN LatestDrepDistr ldd_drep ON ldd_drep.hash_id = voting_procedure.drep_voter - AND ldd_drep.rn = 1 - LEFT JOIN LatestDrepDistr ldd_pool ON ldd_pool.hash_id = voting_procedure.pool_voter - AND ldd_pool.rn = 1 - LEFT JOIN - ( - SELECT - gov_action_proposal_id, - SUM(CASE WHEN vote = 'Yes' THEN 1 ELSE 0 END) AS ccYesVotes, - SUM(CASE WHEN vote = 'No' THEN 1 ELSE 0 END) AS ccNoVotes, - SUM(CASE WHEN vote = 'Abstain' THEN 1 ELSE 0 END) AS ccAbstainVotes - FROM - voting_procedure AS vp - WHERE - vp.committee_voter IS NOT NULL - AND (vp.tx_id, vp.committee_voter, vp.gov_action_proposal_id) IN ( - SELECT MAX(tx_id), committee_voter, gov_action_proposal_id - FROM voting_procedure - WHERE committee_voter IS NOT NULL - GROUP BY committee_voter, gov_action_proposal_id - ) - GROUP BY - gov_action_proposal_id - ) vp_by_cc - ON gov_action_proposal.id = vp_by_cc.gov_action_proposal_id - LEFT JOIN LatestDrepDistr ldd_cc ON ldd_cc.hash_id = voting_procedure.committee_voter - AND ldd_cc.rn = 1 + LEFT JOIN param_proposal AS proposal_params ON gov_action_proposal.param_proposal = proposal_params.id + LEFT JOIN cost_model AS cost_model ON proposal_params.cost_model_id = cost_model.id + LEFT JOIN PoolVotes ps ON gov_action_proposal.id = ps.gov_action_proposal_id + LEFT JOIN CommitteeVotes cv ON gov_action_proposal.id = cv.gov_action_proposal_id + LEFT JOIN voting_procedure ON voting_procedure.gov_action_proposal_id = gov_action_proposal.id + LEFT JOIN LatestDrepDistr ldd_drep ON ldd_drep.hash_id = voting_procedure.drep_voter + AND ldd_drep.epoch_no = latest_epoch.no LEFT JOIN gov_action_proposal AS prev_gov_action ON gov_action_proposal.prev_gov_action_proposal = prev_gov_action.id LEFT JOIN tx AS prev_gov_action_tx ON prev_gov_action.tx_id = prev_gov_action_tx.id WHERE - (COALESCE(?, '') = '' OR - off_chain_vote_gov_action_data.title ILIKE ? OR - off_chain_vote_gov_action_data.abstract ILIKE ? OR - off_chain_vote_gov_action_data.motivation ILIKE ? OR - off_chain_vote_gov_action_data.rationale ILIKE ? OR - concat(encode(creator_tx.hash, 'hex'), '#', gov_action_proposal.index) ILIKE ?) + (COALESCE(?, '') = '' OR + off_chain_vote_gov_action_data.title ILIKE ? OR + off_chain_vote_gov_action_data.abstract ILIKE ? OR + off_chain_vote_gov_action_data.motivation ILIKE ? OR + off_chain_vote_gov_action_data.rationale ILIKE ? OR + concat(encode(creator_tx.hash, 'hex'), '#', gov_action_proposal.index) ILIKE ?) AND gov_action_proposal.expiration >( SELECT Max(NO) @@ -270,25 +281,26 @@ AND gov_action_proposal.enacted_epoch IS NULL AND gov_action_proposal.expired_epoch IS NULL AND gov_action_proposal.dropped_epoch IS NULL GROUP BY - (gov_action_proposal.id, - creator_block.epoch_no, - off_chain_vote_gov_action_data.title, - off_chain_vote_gov_action_data.abstract, - off_chain_vote_gov_action_data.motivation, - off_chain_vote_gov_action_data.rationale, - vp_by_cc.ccYesVotes, - vp_by_cc.ccNoVotes, - vp_by_cc.ccAbstainVotes, - gov_action_proposal.index, - creator_tx.hash, - creator_block.time, - latest_epoch.start_time, - latest_epoch.no, - proposal_params, - voting_anchor.url, - voting_anchor.data_hash, - always_no_confidence_voting_power.amount, - always_abstain_voting_power.amount, - prev_gov_action.index, - prev_gov_action_tx.hash, - meta.network_name) \ No newline at end of file + gov_action_proposal.id, + creator_tx.hash, + creator_block.id, + latest_epoch.start_time, + latest_epoch.no, + drep_voting_power.no_confidence, + drep_voting_power.abstain, + cv.ccYesVotes, + cv.ccNoVotes, + cv.ccAbstainVotes, + proposal_params, + ps.poolYesVotes, + ps.poolNoVotes, + ps.poolAbstainVotes, + meta.network_name, + voting_anchor.url, + voting_anchor.data_hash, + prev_gov_action.index, + prev_gov_action_tx.hash, + off_chain_vote_gov_action_data.title, + off_chain_vote_gov_action_data.abstract, + off_chain_vote_gov_action_data.motivation, + off_chain_vote_gov_action_data.rationale \ No newline at end of file diff --git a/govtool/backend/src/VVA/API.hs b/govtool/backend/src/VVA/API.hs index 4d7b6d727..180fb55a7 100644 --- a/govtool/backend/src/VVA/API.hs +++ b/govtool/backend/src/VVA/API.hs @@ -438,6 +438,7 @@ getNetworkMetrics = do , getNetworkMetricsResponseTotalDRepVotes = networkMetricsTotalDRepVotes , getNetworkMetricsResponseTotalRegisteredDReps = networkMetricsTotalRegisteredDReps , getNetworkMetricsResponseTotalStakeControlledByDReps = networkMetricsTotalStakeControlledByDReps + , getNetworkMetricsResponseTotalStakeControlledBySPOs = networkMetricsTotalStakeControlledBySPOs , getNetworkMetricsResponseTotalActiveDReps = networkMetricsTotalActiveDReps , getNetworkMetricsResponseTotalInactiveDReps = networkMetricsTotalInactiveDReps , getNetworkMetricsResponseTotalActiveCIP119CompliantDReps = networkMetricsTotalActiveCIP119CompliantDReps diff --git a/govtool/backend/src/VVA/API/Types.hs b/govtool/backend/src/VVA/API/Types.hs index 3360b3daf..9cbf41690 100644 --- a/govtool/backend/src/VVA/API/Types.hs +++ b/govtool/backend/src/VVA/API/Types.hs @@ -881,6 +881,7 @@ data GetNetworkMetricsResponse , getNetworkMetricsResponseTotalDRepVotes :: Integer , getNetworkMetricsResponseTotalRegisteredDReps :: Integer , getNetworkMetricsResponseTotalStakeControlledByDReps :: Integer + , getNetworkMetricsResponseTotalStakeControlledBySPOs :: Integer , getNetworkMetricsResponseTotalActiveDReps :: Integer , getNetworkMetricsResponseTotalInactiveDReps :: Integer , getNetworkMetricsResponseTotalActiveCIP119CompliantDReps :: Integer @@ -894,22 +895,23 @@ deriveJSON (jsonOptions "getNetworkMetricsResponse") ''GetNetworkMetricsResponse exampleGetNetworkMetricsResponse :: Text exampleGetNetworkMetricsResponse = - "{\"currentTime\": \"1970-01-01T00:00:00Z\"," - <> "\"currentEpoch\": 0," - <> "\"currentBlock\": 0," - <> "\"uniqueDelegators\": 0," - <> "\"totalDelegations\": 0," - <> "\"totalGovernanceActions\": 0," - <> "\"totalDRepVotes\": 0," - <> "\"totalRegisteredDReps\": 0," - <> "\"totalStakeControlledByDReps\": 0," - <> "\"totalActiveDReps\": 0," - <> "\"totalInactiveDReps\": 0," - <> "\"totalActiveCIP119CompliantDReps\": 0," - <> "\"totalRegisteredDirectVoters\": 0," - <> "\"alwaysAbstainVotingPower\": 0," - <> "\"alwaysNoConfidenceVotingPower\": 0," - <> "\"networkName\": \"Mainnet\"}" + "{\"currentTime\": \"1970-01-01T00:00:00Z\"," + <> "\"currentEpoch\": 0," + <> "\"currentBlock\": 0," + <> "\"uniqueDelegators\": 0," + <> "\"totalDelegations\": 0," + <> "\"totalGovernanceActions\": 0," + <> "\"totalDRepVotes\": 0," + <> "\"totalRegisteredDReps\": 0," + <> "\"totalStakeControlledByDReps\": 0," + <> "\"totalStakeControlledBySPOs\": 0," + <> "\"totalActiveDReps\": 0," + <> "\"totalInactiveDReps\": 0," + <> "\"totalActiveCIP119CompliantDReps\": 0," + <> "\"totalRegisteredDirectVoters\": 0," + <> "\"alwaysAbstainVotingPower\": 0," + <> "\"alwaysNoConfidenceVotingPower\": 0," + <> "\"networkName\": \"Mainnet\"}" instance ToSchema GetNetworkMetricsResponse where declareNamedSchema _ = pure $ NamedSchema (Just "GetNetworkMetricsResponse") $ mempty diff --git a/govtool/backend/src/VVA/Network.hs b/govtool/backend/src/VVA/Network.hs index 7d86f6c0c..8b844d5d2 100644 --- a/govtool/backend/src/VVA/Network.hs +++ b/govtool/backend/src/VVA/Network.hs @@ -43,6 +43,7 @@ networkMetrics = withPool $ \conn -> do , total_drep_votes , total_registered_dreps , total_stake_controlled_by_dreps + , total_stake_controlled_by_spos , total_active_dreps , total_inactive_dreps , total_active_cip119_compliant_dreps @@ -60,6 +61,7 @@ networkMetrics = withPool $ \conn -> do total_drep_votes total_registered_dreps total_stake_controlled_by_dreps + total_stake_controlled_by_spos total_active_dreps total_inactive_dreps total_active_cip119_compliant_dreps diff --git a/govtool/backend/src/VVA/Types.hs b/govtool/backend/src/VVA/Types.hs index 1fcecdd4f..95d0e622e 100644 --- a/govtool/backend/src/VVA/Types.hs +++ b/govtool/backend/src/VVA/Types.hs @@ -225,6 +225,7 @@ data NetworkMetrics , networkMetricsTotalDRepVotes :: Integer , networkMetricsTotalRegisteredDReps :: Integer , networkMetricsTotalStakeControlledByDReps :: Integer + , networkMetricsTotalStakeControlledBySPOs :: Integer , networkMetricsTotalActiveDReps :: Integer , networkMetricsTotalInactiveDReps :: Integer , networkMetricsTotalActiveCIP119CompliantDReps :: Integer diff --git a/govtool/frontend/src/components/molecules/VotesSubmitted.tsx b/govtool/frontend/src/components/molecules/VotesSubmitted.tsx index 921aec6f4..b743de7b3 100644 --- a/govtool/frontend/src/components/molecules/VotesSubmitted.tsx +++ b/govtool/frontend/src/components/molecules/VotesSubmitted.tsx @@ -42,51 +42,36 @@ export const VotesSubmitted = ({ areCCVoteTotalsDisplayed, } = useFeatureFlag(); const { t } = useTranslation(); - const { networkMetrics, epochParams } = useAppContext(); - const totalDRepStake = - dRepYesVotes + - dRepAbstainVotes + - dRepNoVotes + - (networkMetrics?.alwaysAbstainVotingPower || 0) + - (networkMetrics?.alwaysNoConfidenceVotingPower || 0); - const totalPoolStake = poolYesVotes + poolAbstainVotes + poolNoVotes; - const totalCCStake = ccYesVotes + ccAbstainVotes + ccNoVotes; + const { epochParams } = useAppContext(); - const dRepNegativeVotesPercentage = totalDRepStake - ? ((dRepAbstainVotes + - dRepNoVotes + - (networkMetrics?.alwaysAbstainVotingPower || 0) + - (networkMetrics?.alwaysNoConfidenceVotingPower || 0)) / - totalDRepStake) * - 100 - : undefined; - const dRepNoVotesPercentage = totalDRepStake - ? (dRepNoVotes / totalDRepStake) * 100 - : undefined; - const dRepYesVotesPercentage = dRepNegativeVotesPercentage - ? 100 - dRepNegativeVotesPercentage + const dRepYesVotesPercentage = + dRepYesVotes + dRepNoVotes + ? (dRepYesVotes / (dRepYesVotes + dRepNoVotes)) * 100 + : undefined; + const dRepNoVotesPercentage = dRepYesVotesPercentage + ? 100 - dRepYesVotesPercentage + : dRepNoVotes + ? 100 : undefined; - // TODO: add abstain votes to the calculation - const poolNegativeVotesPercentage = totalPoolStake - ? ((poolAbstainVotes + poolNoVotes) / totalPoolStake) * 100 - : undefined; - const poolNoVotesPercentage = totalPoolStake - ? (poolNoVotes / totalPoolStake) * 100 - : undefined; - const poolYesVotesPercentage = poolNegativeVotesPercentage - ? 100 - poolNegativeVotesPercentage + const poolYesVotesPercentage = + poolYesVotes + poolNoVotes + ? (poolYesVotes / (poolYesVotes + poolNoVotes)) * 100 + : undefined; + const poolNoVotesPercentage = poolYesVotesPercentage + ? 100 - poolYesVotesPercentage + : poolNoVotes + ? 100 : undefined; - // TODO: add abstain votes to the calculation - const ccNegativeVotesPercentage = totalCCStake - ? (ccAbstainVotes + ccNoVotes) / totalCCStake - : undefined; - const ccNoVotesPercentage = totalCCStake - ? ccNoVotes / totalCCStake - : undefined; - const ccYesVotesPercentage = ccNegativeVotesPercentage - ? 100 - ccNegativeVotesPercentage + const ccYesVotesPercentage = + ccYesVotes + ccNoVotes + ? (ccYesVotes / (ccYesVotes + ccNoVotes)) * 100 + : undefined; + const ccNoVotesPercentage = ccYesVotesPercentage + ? 100 - ccYesVotesPercentage + : ccNoVotes + ? 100 : undefined; return ( diff --git a/govtool/frontend/src/models/api.ts b/govtool/frontend/src/models/api.ts index cbd271368..5deceeba3 100644 --- a/govtool/frontend/src/models/api.ts +++ b/govtool/frontend/src/models/api.ts @@ -88,6 +88,7 @@ export type NetworkMetrics = { totalDRepVotes: number; totalRegisteredDReps: number; totalStakeControlledByDReps: number; + totalStakeControlledBySPOs: number; totalActiveDReps: number; totalInactiveDReps: number; totalActiveCIP119CompliantDReps: number;