From c8e01fd5a3dbf7b29c9c4e27732ecc449ce58c51 Mon Sep 17 00:00:00 2001 From: Ciabas Date: Tue, 8 Jul 2025 13:08:19 +0200 Subject: [PATCH] (fix) Hotfix for calculations on SPOs on gov actions --- govtool/backend/sql/get-network-total-stake.sql | 10 +++++++++- .../src/components/molecules/VotesSubmitted.tsx | 17 ++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/govtool/backend/sql/get-network-total-stake.sql b/govtool/backend/sql/get-network-total-stake.sql index 9399df5c3..80e29d06c 100644 --- a/govtool/backend/sql/get-network-total-stake.sql +++ b/govtool/backend/sql/get-network-total-stake.sql @@ -67,8 +67,16 @@ TotalStakeControlledByActiveDReps AS ( AND COALESCE(rd.deposit, 0) >= 0 AND ((DRepActivity.epoch_no - GREATEST(COALESCE(lve.epoch_no, 0), COALESCE(rd.epoch_no, 0))) <= DRepActivity.drep_activity) ), +-- it's a hotfix for duplication issue https://github.com/IntersectMBO/cardano-db-sync/issues/1986 +LatestPoolStat AS ( + SELECT DISTINCT ON (pool_hash_id) * + FROM + pool_stat + WHERE + epoch_no = (SELECT MAX(no) FROM epoch) +), TotalStakeControlledBySPOs AS ( - SELECT SUM(ps.stake)::bigint AS total FROM pool_stat ps WHERE ps.epoch_no = (SELECT no FROM CurrentEpoch) + SELECT SUM(ps.stake)::bigint AS total FROM LatestPoolStat ps WHERE ps.epoch_no = (SELECT no FROM CurrentEpoch) ), AlwaysAbstainVotingPower AS ( SELECT COALESCE((SELECT amount FROM drep_hash diff --git a/govtool/frontend/src/components/molecules/VotesSubmitted.tsx b/govtool/frontend/src/components/molecules/VotesSubmitted.tsx index 87f3ab8a0..7b81cd370 100644 --- a/govtool/frontend/src/components/molecules/VotesSubmitted.tsx +++ b/govtool/frontend/src/components/molecules/VotesSubmitted.tsx @@ -109,14 +109,17 @@ export const VotesSubmitted = ({ 100 - (dRepYesVotesPercentage ?? 0) - (dRepNoVotesPercentage ?? 0); const poolYesVotesPercentage = - poolYesVotes + poolNoVotes - ? (poolYesVotes / (poolYesVotes + poolNoVotes)) * 100 + typeof poolYesVotes === "number" && + typeof networkTotalStake?.totalStakeControlledBySPOs === "number" && + networkTotalStake.totalStakeControlledBySPOs > 0 + ? (poolYesVotes / networkTotalStake.totalStakeControlledBySPOs) * 100 + : undefined; + const poolNoVotesPercentage = + typeof poolNoVotes === "number" && + typeof networkTotalStake?.totalStakeControlledBySPOs === "number" && + networkTotalStake.totalStakeControlledBySPOs > 0 + ? (poolNoVotes / networkTotalStake.totalStakeControlledBySPOs) * 100 : undefined; - const poolNoVotesPercentage = poolYesVotesPercentage - ? 100 - poolYesVotesPercentage - : poolNoVotes - ? 100 - : undefined; const ccYesVotesPercentage = noOfCommitteeMembers ? (ccYesVotes / noOfCommitteeMembers) * 100