Skip to content

Commit d9e0d50

Browse files
committed
fix: underflow error in calc-claimable-amount
1 parent 2bd1801 commit d9e0d50

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

contrib/core-contract-tests/tests/sip-031/sip-031.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,10 @@ test('new recipient claims vested tranche plus extra deposit', () => {
281281
expect(evt.data.amount).toBe(expected.toString());
282282
expect(evt.data.recipient).toBe(accounts.wallet_1.address);
283283
expect(evt.data.sender).toBe(contract.identifier);
284+
});
285+
286+
test('calculating claimable amount at invalid block height returns 0', () => {
287+
mintInitial();
288+
const deployBlockHeight = rov(contract.getDeployBlockHeight());
289+
expect(rov(contract.calcClaimableAmount(deployBlockHeight - 1n))).toBe(0n);
284290
});

stackslib/src/chainstate/stacks/boot/sip-031.clar

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,18 @@
8383

8484
;; Returns the amount of STX that is claimable from the vested balance at `burn-height`
8585
(define-read-only (calc-claimable-amount (burn-height uint))
86-
(let
87-
(
88-
(total-vested (calc-total-vested burn-height))
89-
(reserved (- INITIAL_MINT_AMOUNT total-vested))
90-
(balance (stx-get-balance (as-contract tx-sender)))
91-
(claimable
92-
(if (> balance reserved)
93-
(- balance reserved)
94-
u0))
86+
(if (< burn-height deploy-block-height)
87+
u0
88+
(let
89+
(
90+
(reserved (- INITIAL_MINT_AMOUNT (calc-total-vested burn-height)))
91+
(balance (stx-get-balance (as-contract tx-sender)))
92+
(claimable
93+
(if (> balance reserved)
94+
(- balance reserved)
95+
u0))
96+
)
97+
claimable
9598
)
96-
claimable
9799
)
98100
)

0 commit comments

Comments
 (0)