Skip to content

Commit 68fa42b

Browse files
authored
Merge pull request #3136 from IntersectMBO/fix/3134-incorrect-delegation-amount
fix(#3134): calculating withdrawals when there are no rewards
2 parents 657af82 + 2cf020c commit 68fa42b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ changes.
1414

1515
### Fixed
1616

17+
- Fix calculating withdrawals when rewards records are empty for a given stake key [Issue 3134](https://github.com/IntersectMBO/govtool/issues/3134)
18+
1719
### Changed
1820

1921
### Removed
2022

2123
## [v2.0.13](https://github.com/IntersectMBO/govtool/releases/tag/v2.0.13) 2025-02-27
2224

23-
2425
### Added
2526

2627
### Fixed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ Withdrawal AS (
3838
w.addr_id
3939
)
4040
SELECT
41-
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0) - COALESCE(w.withdrawal_amount, 0)) AS total_balance,
41+
(COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) + COALESCE(b.amount, 0) -
42+
-- records in rewards tables might be missing for some epochs
43+
-- so we need to check if the sum of rewards is greater than the sum of withdrawals before subtracting
44+
CASE
45+
WHEN COALESCE(rr.amount, 0) + COALESCE(r.amount, 0) > COALESCE(w.withdrawal_amount, 0)
46+
THEN COALESCE(w.withdrawal_amount, 0)
47+
ELSE 0
48+
END
49+
) AS total_balance,
4250
b.addr_raw::text AS stake_address
4351
FROM
4452
Balance b

0 commit comments

Comments
 (0)