Skip to content

Commit 53268e9

Browse files
committed
fix(#3061): fix missing subtraction of withdrawals for ada holder balance
1 parent cc18127 commit 53268e9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ changes.
1616

1717
- Fix responsive error on menu [Issue 3055](https://github.com/IntersectMBO/govtool/issues/3055)
1818
- Fix wrong placement of nav items in disconnected menu [Issue 3057](https://github.com/IntersectMBO/govtool/issues/3057)
19+
- Fix missing subtraction withdrawals from ada holder balance [Issue 3061](https://github.com/IntersectMBO/govtool/issues/3061)
1920

2021
### Changed
2122

govtool/backend/sql/get-stake-key-voting-power.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,32 @@ Balance AS (
2727
GROUP BY
2828
addr_id,
2929
addr_raw
30+
),
31+
Withdrawal AS (
32+
SELECT
33+
COALESCE(SUM(w.amount), 0) AS withdrawal_amount,
34+
w.addr_id
35+
FROM
36+
withdrawal w
37+
GROUP BY
38+
w.addr_id
3039
)
3140
SELECT
32-
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0)) AS total_balance,
41+
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0) - COALESCE(w.withdrawal_amount, 0)) AS total_balance,
3342
b.addr_raw::text AS stake_address
3443
FROM
3544
Balance b
3645
LEFT JOIN
3746
RewardRest rr ON rr.addr_id = b.addr_id
3847
LEFT JOIN
3948
Reward r ON r.addr_id = rr.addr_id
49+
LEFT JOIN
50+
Withdrawal w ON w.addr_id = b.addr_id
4051
WHERE
4152
b.addr_id = (SELECT id FROM stake_address WHERE hash_raw = decode(?, 'hex'))
4253
GROUP BY
4354
b.addr_raw,
4455
rr.amount,
4556
r.amount,
46-
b.amount
57+
b.amount,
58+
w.withdrawal_amount

0 commit comments

Comments
 (0)