Skip to content

Commit a2fa857

Browse files
authored
Merge pull request #2582 from IntersectMBO/fix/voting-power-with-rewards
fix: drep and ada holder voting power adjustments
2 parents 68b2d56 + 06b6780 commit a2fa857

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ changes.
1818

1919
- Fix calculating DRep live voting power [Issue 2460](https://github.com/IntersectMBO/govtool/issues/2460)
2020
- Fix link and description validation [Issue 2403](https://github.com/IntersectMBO/govtool/issues/2403)
21+
- Revert to drep_distr for providing active voting power
22+
- Add rewards amount in the ada holder voting power
2123

2224
### Changed
2325

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
1-
SELECT COALESCE(SUM(utxo_view.value::numeric), 0),
2-
encode(stake_address.hash_raw, 'hex')
3-
FROM stake_address
4-
JOIN utxo_view ON utxo_view.stake_address_id = stake_address.id
5-
WHERE stake_address.hash_raw = decode(?, 'hex')
6-
GROUP BY stake_address.hash_raw;
1+
WITH RewardRest AS (
2+
SELECT
3+
SUM(amount) AS amount,
4+
addr_id
5+
FROM
6+
reward_rest
7+
GROUP BY
8+
addr_id
9+
),
10+
Reward AS (
11+
SELECT
12+
SUM(amount) AS amount,
13+
addr_id
14+
FROM
15+
reward
16+
GROUP BY
17+
addr_id
18+
),
19+
Balance AS (
20+
SELECT
21+
COALESCE(SUM(uv.value), 0) AS amount,
22+
sa.id AS addr_id,
23+
encode(sa.hash_raw, 'hex') AS addr_raw
24+
FROM
25+
stake_address sa
26+
JOIN utxo_view uv ON uv.stake_address_id = sa.id
27+
GROUP BY
28+
addr_id,
29+
addr_raw
30+
)
31+
SELECT
32+
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
33+
b.addr_raw
34+
FROM
35+
Balance b
36+
LEFT JOIN
37+
RewardRest rr ON rr.addr_id = b.addr_id
38+
LEFT JOIN
39+
Reward r ON r.addr_id = rr.addr_id
40+
WHERE
41+
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
42+
GROUP BY
43+
b.addr_raw,
44+
rr.amount,
45+
r.amount,
46+
b.amount
Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
1-
WITH LatestDelegationVote AS (
2-
SELECT
3-
addr_id,
4-
MAX(id) AS latest_vote_id
5-
FROM
6-
delegation_vote
7-
GROUP BY
8-
addr_id
9-
)
10-
SELECT
11-
SUM(uv.value) AS total_value
12-
FROM
13-
utxo_view uv
14-
JOIN
15-
stake_address sa ON sa.id = uv.stake_address_id
16-
JOIN
17-
LatestDelegationVote ldv ON uv.stake_address_id = ldv.addr_id
18-
JOIN
19-
delegation_vote dv ON dv.id = ldv.latest_vote_id
20-
WHERE
21-
dv.drep_hash_id = (SELECT id FROM drep_hash WHERE raw = decode(?,'hex'))
1+
SELECT
2+
amount
3+
FROM
4+
drep_distr
5+
WHERE
6+
hash_id = (SELECT id FROM drep_hash WHERE raw = decode(?,'hex'))
7+
ORDER BY epoch_no DESC LIMIT 1

0 commit comments

Comments
 (0)