Skip to content

Commit 3b63c65

Browse files
committed
feat: format with clarinet format
1 parent 9cd3132 commit 3b63c65

File tree

1 file changed

+65
-60
lines changed

1 file changed

+65
-60
lines changed

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

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -35,97 +35,102 @@
3535

3636
;; The block height at which vesting starts. On Mainnet, this is
3737
;; burn height 907740, which is what is specified in SIP-031.
38-
(define-constant DEPLOY_BLOCK_HEIGHT (if is-in-mainnet u907740 burn-block-height))
38+
(define-constant DEPLOY_BLOCK_HEIGHT (if is-in-mainnet
39+
u907740
40+
burn-block-height
41+
))
3942

4043
;; The authorized recipient of the funds.
4144
;; Note than in production environments, `tx-sender` is
4245
;; replaced with a hard-coded address.
4346
(define-data-var recipient principal tx-sender)
4447

45-
(define-read-only (get-recipient) (var-get recipient))
48+
(define-read-only (get-recipient)
49+
(var-get recipient)
50+
)
4651

47-
(define-read-only (get-deploy-block-height) DEPLOY_BLOCK_HEIGHT)
52+
(define-read-only (get-deploy-block-height)
53+
DEPLOY_BLOCK_HEIGHT
54+
)
4855

4956
;; Update the recipient of the funds.
5057
;; May only be called by the current `recipient`.
5158
;; Returns `true` if the recipient was updated.
52-
(define-public (update-recipient (new-recipient principal)) (begin
59+
(define-public (update-recipient (new-recipient principal))
60+
(begin
5361
(begin
54-
(try! (validate-caller))
55-
(print {
56-
topic: "update-recipient",
57-
old-recipient: (var-get recipient),
58-
new-recipient: new-recipient,
59-
})
60-
(var-set recipient new-recipient)
61-
(ok true))
62-
))
62+
(try! (validate-caller))
63+
(print {
64+
topic: "update-recipient",
65+
old-recipient: (var-get recipient),
66+
new-recipient: new-recipient,
67+
})
68+
(var-set recipient new-recipient)
69+
(ok true)
70+
)
71+
)
72+
)
6373

6474
;; Transfer all currently withdrawable STX (vested + extra) to `recipient`.
6575
;; Errors with `ERR_NOTHING_TO_CLAIM` if there is nothing to withdraw.
6676
(define-public (claim)
67-
(let
68-
(
69-
(claimable (calc-claimable-amount burn-block-height))
70-
)
71-
(try! (validate-caller))
72-
(asserts! (> claimable u0) (err ERR_NOTHING_TO_CLAIM))
73-
74-
(try! (as-contract (stx-transfer? claimable tx-sender (var-get recipient))))
75-
(print {
76-
topic: "claim",
77-
claimable: claimable,
78-
recipient: (var-get recipient),
79-
})
80-
(ok claimable)
81-
)
77+
(let ((claimable (calc-claimable-amount burn-block-height)))
78+
(try! (validate-caller))
79+
(asserts! (> claimable u0) (err ERR_NOTHING_TO_CLAIM))
80+
(try! (as-contract (stx-transfer? claimable tx-sender (var-get recipient))))
81+
(print {
82+
topic: "claim",
83+
claimable: claimable,
84+
recipient: (var-get recipient),
85+
})
86+
(ok claimable)
87+
)
8288
)
8389

8490
;; Authorization check. Verify that the caller is the current `recipient`.
8591
;; This also prevents `recipient` calling into this contract
8692
;; via an indirect contract-call.
8793
(define-private (validate-caller)
88-
(if (is-eq (var-get recipient) contract-caller tx-sender)
89-
(ok true)
90-
(err ERR_NOT_ALLOWED))
94+
(if (is-eq (var-get recipient) contract-caller tx-sender)
95+
(ok true)
96+
(err ERR_NOT_ALLOWED)
97+
)
9198
)
9299

93100
;; Returns the *total* vested amount at `burn-height`, i.e.
94101
;; immediate bucket + linear vesting so far (DOES NOT subtract any claims).
95102
(define-private (calc-total-vested (burn-height uint))
96-
(let
97-
(
98-
(diff (- burn-height DEPLOY_BLOCK_HEIGHT))
99-
;; Note: this rounds down
100-
(iterations (/ diff INITIAL_MINT_VESTING_ITERATION_BLOCKS))
101-
(vested-multiple (/ (* STX_PER_ITERATION diff) INITIAL_MINT_VESTING_ITERATION_BLOCKS))
102-
103-
;; If we have completed (or exceeded) the scheduled number of iterations,
104-
;; consider the *entire* vesting bucket unlocked. This avoids leaving a
105-
;; tiny remainder caused by integer-division truncation.
106-
(vested-amount (if (>= iterations INITIAL_MINT_VESTING_ITERATIONS)
107-
INITIAL_MINT_VESTING_AMOUNT
108-
vested-multiple))
109-
(total-amount (+ INITIAL_MINT_IMMEDIATE_AMOUNT vested-amount))
110-
)
111-
total-amount
103+
(let (
104+
(diff (- burn-height DEPLOY_BLOCK_HEIGHT))
105+
;; Note: this rounds down
106+
(iterations (/ diff INITIAL_MINT_VESTING_ITERATION_BLOCKS))
107+
(vested-multiple (/ (* STX_PER_ITERATION diff) INITIAL_MINT_VESTING_ITERATION_BLOCKS))
108+
;; If we have completed (or exceeded) the scheduled number of iterations,
109+
;; consider the *entire* vesting bucket unlocked. This avoids leaving a
110+
;; tiny remainder caused by integer-division truncation.
111+
(vested-amount (if (>= iterations INITIAL_MINT_VESTING_ITERATIONS)
112+
INITIAL_MINT_VESTING_AMOUNT
113+
vested-multiple
114+
))
115+
(total-amount (+ INITIAL_MINT_IMMEDIATE_AMOUNT vested-amount))
112116
)
117+
total-amount
118+
)
113119
)
114120

115121
;; Returns the amount of STX that is claimable from the vested balance at `burn-height`
116122
(define-read-only (calc-claimable-amount (burn-height uint))
117-
(if (< burn-height DEPLOY_BLOCK_HEIGHT)
118-
u0
119-
(let
120-
(
121-
(reserved (- INITIAL_MINT_AMOUNT (calc-total-vested burn-height)))
122-
(balance (stx-get-balance (as-contract tx-sender)))
123-
(claimable
124-
(if (> balance reserved)
125-
(- balance reserved)
126-
u0))
127-
)
128-
claimable
129-
)
123+
(if (< burn-height DEPLOY_BLOCK_HEIGHT)
124+
u0
125+
(let (
126+
(reserved (- INITIAL_MINT_AMOUNT (calc-total-vested burn-height)))
127+
(balance (stx-get-balance (as-contract tx-sender)))
128+
(claimable (if (> balance reserved)
129+
(- balance reserved)
130+
u0
131+
))
132+
)
133+
claimable
130134
)
135+
)
131136
)

0 commit comments

Comments
 (0)