|
16 | 16 | ;; The amount of STX that is vested over the 24 months
|
17 | 17 | (define-constant INITIAL_MINT_VESTING_AMOUNT (- INITIAL_MINT_AMOUNT INITIAL_MINT_IMMEDIATE_AMOUNT))
|
18 | 18 |
|
| 19 | +;; The amount of STX that is vested per iteration |
| 20 | +(define-constant STX_PER_ITERATION (/ INITIAL_MINT_VESTING_AMOUNT INITIAL_MINT_VESTING_ITERATIONS)) |
| 21 | + |
19 | 22 | (define-data-var recipient principal tx-sender)
|
20 | 23 |
|
21 | 24 | (define-data-var deploy-block-height uint burn-block-height)
|
|
44 | 47 | (define-public (claim)
|
45 | 48 | (let
|
46 | 49 | (
|
47 |
| - (balance (stx-get-balance (as-contract tx-sender))) |
48 |
| - (burn-height burn-block-height) |
49 |
| - (total-vested (calc-total-vested burn-height)) |
| 50 | + (balance (stx-get-balance (as-contract tx-sender))) |
| 51 | + (total-vested (calc-total-vested burn-block-height)) |
50 | 52 | (vested-claimed (var-get vested-claimed-amount))
|
51 |
| - ;; Vested that has not yet been claimed |
52 |
| - (available-vested (- total-vested vested-claimed)) |
53 | 53 | ;; Portion of the initial mint that is *still* locked (not yet vested)
|
54 | 54 | (reserved (- INITIAL_MINT_AMOUNT total-vested))
|
55 | 55 | ;; Free balance = everything the caller may withdraw right now
|
56 | 56 | (claimable
|
57 | 57 | (if (> balance reserved)
|
58 | 58 | (- balance reserved)
|
59 | 59 | u0))
|
60 |
| - (vested-to-claim (if (> available-vested claimable) claimable available-vested)) |
61 |
| - (extra-to-claim (- claimable vested-to-claim)) |
62 | 60 | )
|
63 | 61 | (try! (validate-caller))
|
64 | 62 | (asserts! (> claimable u0) (err ERR_NOTHING_TO_CLAIM))
|
65 |
| - (var-set vested-claimed-amount (+ vested-claimed vested-to-claim)) |
| 63 | + (var-set vested-claimed-amount (+ vested-claimed total-vested)) |
66 | 64 |
|
67 | 65 | (try! (as-contract (stx-transfer? claimable tx-sender (var-get recipient))))
|
68 | 66 | (ok claimable)
|
69 |
| - ) |
| 67 | + ) |
70 | 68 | )
|
71 | 69 |
|
72 | 70 | (define-private (validate-caller)
|
|
79 | 77 | (let
|
80 | 78 | (
|
81 | 79 | (diff (- burn-height (var-get deploy-block-height)))
|
| 80 | + ;; Note: this rounds down |
82 | 81 | (iterations (/ diff INITIAL_MINT_VESTING_ITERATION_BLOCKS))
|
83 |
| - (stx-per-iteration (/ INITIAL_MINT_VESTING_AMOUNT INITIAL_MINT_VESTING_ITERATIONS)) |
84 |
| - (vesting-multiple (* stx-per-iteration iterations)) |
| 82 | + (vested-multiple (* STX_PER_ITERATION iterations)) |
85 | 83 |
|
86 | 84 | ;; If we have completed (or exceeded) the scheduled number of iterations,
|
87 | 85 | ;; consider the *entire* vesting bucket unlocked. This avoids leaving a
|
88 | 86 | ;; tiny remainder caused by integer-division truncation.
|
89 |
| - (vesting-amount (if (>= iterations INITIAL_MINT_VESTING_ITERATIONS) |
| 87 | + (vested-amount (if (>= iterations INITIAL_MINT_VESTING_ITERATIONS) |
90 | 88 | INITIAL_MINT_VESTING_AMOUNT
|
91 |
| - vesting-multiple)) |
92 |
| - (total-amount (+ INITIAL_MINT_IMMEDIATE_AMOUNT vesting-amount)) |
| 89 | + vested-multiple)) |
| 90 | + (total-amount (+ INITIAL_MINT_IMMEDIATE_AMOUNT vested-amount)) |
93 | 91 | )
|
94 | 92 | total-amount
|
95 | 93 | )
|
96 | 94 | )
|
97 | 95 |
|
98 |
| -;; Returns the amount of STX that is vested at `burn-height` |
99 |
| -(define-read-only (calc-vested-amount (burn-height uint)) |
| 96 | +;; Returns the amount of STX that is claimable from the vested balance at `burn-height` |
| 97 | +(define-read-only (calc-claimable-amount (burn-height uint)) |
100 | 98 | (let
|
101 |
| - ( |
102 |
| - (total-vested (calc-total-vested burn-height)) |
103 |
| - ) |
104 |
| - (ok (- total-vested (var-get vested-claimed-amount))) |
| 99 | + ( |
| 100 | + (total-vested (calc-total-vested burn-height)) |
| 101 | + ) |
| 102 | + (- total-vested (var-get vested-claimed-amount)) |
105 | 103 | )
|
106 | 104 | )
|
0 commit comments