Skip to content

Commit 0a91904

Browse files
committed
(fix) Hotfix for calculations on SPOs on gov actions
1 parent ff3a7d1 commit 0a91904

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

govtool/backend/sql/get-network-total-stake.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,18 @@ TotalStakeControlledByActiveDReps AS (
6767
AND COALESCE(rd.deposit, 0) >= 0
6868
AND ((DRepActivity.epoch_no - GREATEST(COALESCE(lve.epoch_no, 0), COALESCE(rd.epoch_no, 0))) <= DRepActivity.drep_activity)
6969
),
70+
LatestPoolStat AS (
71+
SELECT DISTINCT ON (pool_hash_id, epoch_no, number_of_blocks, number_of_delegators, stake, voting_power)
72+
*
73+
FROM
74+
pool_stat
75+
WHERE
76+
epoch_no = (SELECT MAX(no) FROM epoch)
77+
ORDER BY
78+
pool_hash_id, epoch_no, number_of_blocks, number_of_delegators, stake, voting_power, id DESC
79+
),
7080
TotalStakeControlledBySPOs AS (
71-
SELECT SUM(ps.stake)::bigint AS total FROM pool_stat ps WHERE ps.epoch_no = (SELECT no FROM CurrentEpoch)
81+
SELECT SUM(ps.stake)::bigint AS total FROM LatestPoolStat ps WHERE ps.epoch_no = (SELECT no FROM CurrentEpoch)
7282
),
7383
AlwaysAbstainVotingPower AS (
7484
SELECT COALESCE((SELECT amount FROM drep_hash

govtool/frontend/src/components/molecules/VotesSubmitted.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,17 @@ export const VotesSubmitted = ({
109109
100 - (dRepYesVotesPercentage ?? 0) - (dRepNoVotesPercentage ?? 0);
110110

111111
const poolYesVotesPercentage =
112-
poolYesVotes + poolNoVotes
113-
? (poolYesVotes / (poolYesVotes + poolNoVotes)) * 100
112+
typeof poolYesVotes === "number" &&
113+
typeof networkTotalStake?.totalStakeControlledBySPOs === "number" &&
114+
networkTotalStake.totalStakeControlledBySPOs > 0
115+
? (poolYesVotes / networkTotalStake.totalStakeControlledBySPOs) * 100
116+
: undefined;
117+
const poolNoVotesPercentage =
118+
typeof poolNoVotes === "number" &&
119+
typeof networkTotalStake?.totalStakeControlledBySPOs === "number" &&
120+
networkTotalStake.totalStakeControlledBySPOs > 0
121+
? (poolNoVotes / networkTotalStake.totalStakeControlledBySPOs) * 100
114122
: undefined;
115-
const poolNoVotesPercentage = poolYesVotesPercentage
116-
? 100 - poolYesVotesPercentage
117-
: poolNoVotes
118-
? 100
119-
: undefined;
120123

121124
const ccYesVotesPercentage = noOfCommitteeMembers
122125
? (ccYesVotes / noOfCommitteeMembers) * 100

0 commit comments

Comments
 (0)