|
5 | 5 | ;; traits
|
6 | 6 | ;;
|
7 | 7 | (impl-trait .aibtcdev-dao-traits-v1.extension)
|
8 |
| -(impl-trait .aibtcdev-dao-traits-v1.bank-acccount) |
| 8 | +(impl-trait .aibtcdev-dao-traits-v1.bank-account) |
9 | 9 |
|
10 | 10 | ;; constants
|
11 | 11 | ;;
|
12 | 12 | (define-constant SELF (as-contract tx-sender))
|
| 13 | +(define-constant DEPLOYED_AT burn-block-height) |
13 | 14 | (define-constant ERR_INVALID (err u1000))
|
14 | 15 | (define-constant ERR_UNAUTHORIZED (err u1001))
|
15 | 16 | (define-constant ERR_TOO_SOON (err u1002))
|
|
58 | 59 | (define-public (override-last-withdrawal-block (block uint))
|
59 | 60 | (begin
|
60 | 61 | (try! (is-dao-or-extension))
|
61 |
| - (asserts! (> block u0) ERR_INVALID) |
| 62 | + (asserts! (> block DEPLOYED_AT) ERR_INVALID) |
62 | 63 | (ok (var-set lastWithdrawalBlock block))
|
63 | 64 | )
|
64 | 65 | )
|
65 | 66 |
|
66 |
| -(define-public (update-terms |
67 |
| - (accountHolder (optional principal)) |
68 |
| - (withdrawalPeriod (optional uint)) |
69 |
| - (withdrawalAmount (optional uint)) |
70 |
| - (lastWithdrawalBlock (optional uint)) |
71 |
| - (opcode (optional (buff 16)))) |
72 |
| - |
73 |
| - (begin |
74 |
| - ;; Check authorization |
75 |
| - (try! (is-dao-or-extension)) |
76 |
| - |
77 |
| - ;; Update account holder if provided |
78 |
| - (match accountHolder holder |
79 |
| - (begin |
80 |
| - (asserts! (not (is-eq (var-get accountHolder) holder)) ERR_INVALID) |
81 |
| - (var-set accountHolder holder) |
82 |
| - ) |
83 |
| - true |
84 |
| - ) |
85 |
| - |
86 |
| - ;; Update withdrawal period if provided |
87 |
| - (match withdrawalPeriod period |
88 |
| - (begin |
89 |
| - (asserts! (> period u0) ERR_INVALID) |
90 |
| - (var-set withdrawalPeriod period) |
91 |
| - ) |
92 |
| - true |
93 |
| - ) |
94 |
| - |
95 |
| - ;; Update withdrawal amount if provided |
96 |
| - (match withdrawalAmount amount |
97 |
| - (begin |
98 |
| - (asserts! (> amount u0) ERR_INVALID) |
99 |
| - (var-set withdrawalAmount amount) |
100 |
| - ) |
101 |
| - true |
102 |
| - ) |
103 |
| - |
104 |
| - ;; Update last withdrawal block if provided |
105 |
| - (match lastWithdrawalBlock block |
106 |
| - (begin |
107 |
| - (asserts! (> block u0) ERR_INVALID) |
108 |
| - (var-set lastWithdrawalBlock block) |
109 |
| - ) |
110 |
| - true |
111 |
| - ) |
112 |
| - |
113 |
| - ;; Print settings update event |
114 |
| - (print { |
115 |
| - notification: "terms-updated", |
116 |
| - payload: { |
117 |
| - accountHolder: (var-get accountHolder), |
118 |
| - withdrawalPeriod: (var-get withdrawalPeriod), |
119 |
| - withdrawalAmount: (var-get withdrawalAmount), |
120 |
| - lastWithdrawalBlock: (var-get lastWithdrawalBlock), |
121 |
| - opcode: opcode, |
122 |
| - caller: contract-caller, |
123 |
| - sender: tx-sender |
124 |
| - } |
125 |
| - }) |
126 |
| - |
127 |
| - (ok true) |
128 |
| - ) |
129 |
| -) |
130 |
| - |
131 | 67 | (define-public (deposit-stx (amount uint))
|
132 | 68 | (begin
|
133 | 69 | (asserts! (> amount u0) ERR_INVALID_AMOUNT)
|
|
148 | 84 | ;; verify user is enabled in the map
|
149 | 85 | (try! (is-account-holder))
|
150 | 86 | ;; verify user is not withdrawing too soon
|
151 |
| - (asserts! (>= block-height (+ (var-get lastWithdrawalBlock) (var-get withdrawalPeriod))) ERR_TOO_SOON) |
| 87 | + (asserts! (>= burn-block-height (+ (var-get lastWithdrawalBlock) (var-get withdrawalPeriod))) ERR_TOO_SOON) |
152 | 88 | ;; update last withdrawal block
|
153 |
| - (var-set lastWithdrawalBlock block-height) |
| 89 | + (var-set lastWithdrawalBlock burn-block-height) |
154 | 90 | ;; print notification and transfer STX
|
155 | 91 | (print {
|
156 | 92 | notification: "withdraw-stx",
|
|
166 | 102 |
|
167 | 103 | ;; read only functions
|
168 | 104 | ;;
|
| 105 | +(define-read-only (get-deployed-block) |
| 106 | + DEPLOYED_AT |
| 107 | +) |
| 108 | + |
169 | 109 | (define-read-only (get-account-balance)
|
170 | 110 | (stx-get-balance SELF)
|
171 | 111 | )
|
|
174 | 114 | (var-get accountHolder)
|
175 | 115 | )
|
176 | 116 |
|
| 117 | +(define-read-only (get-last-withdrawal-block) |
| 118 | + (var-get lastWithdrawalBlock) |
| 119 | +) |
| 120 | + |
177 | 121 | (define-read-only (get-withdrawal-period)
|
178 | 122 | (var-get withdrawalPeriod)
|
179 | 123 | )
|
|
182 | 126 | (var-get withdrawalAmount)
|
183 | 127 | )
|
184 | 128 |
|
185 |
| -(define-read-only (get-last-withdrawal-block) |
186 |
| - (var-get lastWithdrawalBlock) |
187 |
| -) |
188 |
| - |
189 |
| -(define-read-only (get-terms) |
| 129 | +(define-read-only (get-account-terms) |
190 | 130 | {
|
191 |
| - accountHolder: (var-get accountHolder), |
192 |
| - lastWithdrawalBlock: (var-get lastWithdrawalBlock), |
193 |
| - withdrawalAmount: (var-get withdrawalAmount), |
194 |
| - withdrawalPeriod: (var-get withdrawalPeriod), |
| 131 | + accountBalance: (get-account-balance), |
| 132 | + accountHolder: (get-account-holder), |
| 133 | + contractName: SELF, |
| 134 | + deployedAt: (get-deployed-block), |
| 135 | + lastWithdrawalBlock: (get-last-withdrawal-block), |
| 136 | + withdrawalAmount: (get-withdrawal-amount), |
| 137 | + withdrawalPeriod: (get-withdrawal-period), |
195 | 138 | }
|
196 | 139 | )
|
197 | 140 |
|
|
0 commit comments