|
17 | 17 |
|
18 | 18 | (define-constant SELF (as-contract tx-sender))
|
19 | 19 | (define-constant VOTING_PERIOD u144) ;; 144 Bitcoin blocks, ~1 day
|
20 |
| -(define-constant VOTING_QUORUM u95) ;; 95% of liquid supply (total supply - treasury) |
| 20 | +(define-constant VOTING_QUORUM u95) ;; 95% of liquid supply |
21 | 21 |
|
22 | 22 | ;; error messages - authorization
|
23 | 23 | (define-constant ERR_NOT_DAO_OR_EXTENSION (err u3000))
|
24 |
| - |
25 |
| -;; error messages - initialization |
26 |
| -(define-constant ERR_NOT_INITIALIZED (err u3100)) |
| 24 | +(define-constant ERR_FETCHING_TOKEN_DATA (err u3001)) |
27 | 25 |
|
28 | 26 | ;; error messages - treasury
|
29 | 27 | (define-constant ERR_TREASURY_CANNOT_BE_SELF (err u3200))
|
|
49 | 47 | (define-constant ERR_VOTE_TOO_SOON (err u3500))
|
50 | 48 | (define-constant ERR_VOTE_TOO_LATE (err u3501))
|
51 | 49 | (define-constant ERR_ALREADY_VOTED (err u3502))
|
52 |
| -(define-constant ERR_QUORUM_NOT_REACHED (err u3504)) |
| 50 | +(define-constant ERR_QUORUM_NOT_REACHED (err u3503)) |
53 | 51 |
|
54 |
| -;; data vars |
55 |
| -;; |
56 |
| -(define-data-var protocolTreasury principal SELF) ;; the treasury contract for protocol funds |
57 |
| -(define-data-var votingToken principal SELF) ;; the FT contract used for voting |
| 52 | +;; contracts used for voting calculations |
| 53 | +(define-constant VOTING_TOKEN_DEX .aibtc-token-dex) |
| 54 | +(define-constant VOTING_TOKEN_POOL .aibtc-bitflow-pool) |
| 55 | +(define-constant VOTING_TREASURY .aibtc-treasury) |
58 | 56 |
|
59 | 57 | ;; data maps
|
60 | 58 | ;;
|
|
88 | 86 | (ok true)
|
89 | 87 | )
|
90 | 88 |
|
91 |
| -(define-public (set-protocol-treasury (treasury <treasury-trait>)) |
92 |
| - (let |
93 |
| - ( |
94 |
| - (treasuryContract (contract-of treasury)) |
95 |
| - ) |
96 |
| - (try! (is-dao-or-extension)) |
97 |
| - ;; cannot set treasury to self |
98 |
| - (asserts! (not (is-eq treasuryContract SELF)) ERR_TREASURY_CANNOT_BE_SELF) |
99 |
| - ;; cannot set treasury to same value |
100 |
| - (asserts! (not (is-eq treasuryContract (var-get protocolTreasury))) ERR_TREASURY_CANNOT_BE_SAME) |
101 |
| - (print { |
102 |
| - notification: "set-protocol-treasury", |
103 |
| - payload: { |
104 |
| - treasury: treasuryContract |
105 |
| - } |
106 |
| - }) |
107 |
| - (ok (var-set protocolTreasury treasuryContract)) |
108 |
| - ) |
109 |
| -) |
110 |
| - |
111 |
| -(define-public (set-voting-token (token <ft-trait>)) |
112 |
| - (let |
113 |
| - ( |
114 |
| - (tokenContract (contract-of token)) |
115 |
| - ) |
116 |
| - (try! (is-dao-or-extension)) |
117 |
| - ;; cannot set token to self |
118 |
| - (asserts! (not (is-eq tokenContract SELF)) ERR_TOKEN_CANNOT_BE_SELF) |
119 |
| - ;; cannot set token to same value |
120 |
| - (asserts! (not (is-eq tokenContract (var-get votingToken))) ERR_TOKEN_CANNOT_BE_SAME) |
121 |
| - ;; cannot set token if already set once |
122 |
| - (asserts! (is-eq (var-get votingToken) SELF) ERR_TOKEN_ALREADY_INITIALIZED) |
123 |
| - (print { |
124 |
| - notification: "set-voting-token", |
125 |
| - payload: { |
126 |
| - token: tokenContract |
127 |
| - } |
128 |
| - }) |
129 |
| - (ok (var-set votingToken tokenContract)) |
130 |
| - ) |
131 |
| -) |
132 |
| - |
133 |
| -(define-public (create-proposal (proposal <proposal-trait>) (token <ft-trait>)) |
| 89 | +(define-public (create-proposal (proposal <proposal-trait>)) |
134 | 90 | (let
|
135 | 91 | (
|
136 | 92 | (proposalContract (contract-of proposal))
|
137 |
| - (tokenContract (contract-of token)) |
138 | 93 | )
|
139 |
| - ;; required variables must be set |
140 |
| - (asserts! (is-initialized) ERR_NOT_INITIALIZED) |
141 |
| - ;; token matches set voting token |
142 |
| - (asserts! (is-eq tokenContract (var-get votingToken)) ERR_TOKEN_MISMATCH) |
143 | 94 | ;; caller has the required balance
|
144 |
| - (asserts! (> (try! (contract-call? token get-balance tx-sender)) u0) ERR_INSUFFICIENT_BALANCE) |
| 95 | + (asserts! (> (unwrap! (contract-call? .aibtc-token get-balance tx-sender) ERR_FETCHING_TOKEN_DATA) u0) ERR_INSUFFICIENT_BALANCE) |
145 | 96 | ;; proposal was not already executed
|
146 | 97 | (asserts! (is-none (contract-call? .aibtcdev-base-dao executed-at proposal)) ERR_PROPOSAL_ALREADY_EXECUTED)
|
147 | 98 | ;; print proposal creation event
|
|
168 | 119 | }) ERR_SAVING_PROPOSAL))
|
169 | 120 | ))
|
170 | 121 |
|
171 |
| -(define-public (vote-on-proposal (proposal <proposal-trait>) (token <ft-trait>) (vote bool)) |
| 122 | +(define-public (vote-on-proposal (proposal <proposal-trait>) (vote bool)) |
172 | 123 | (let
|
173 | 124 | (
|
174 | 125 | (proposalContract (contract-of proposal))
|
175 | 126 | (proposalRecord (unwrap! (map-get? Proposals proposalContract) ERR_PROPOSAL_NOT_FOUND))
|
176 | 127 | (proposalBlock (get startBlock proposalRecord))
|
177 | 128 | (proposalBlockHash (unwrap! (get-block-hash proposalBlock) ERR_RETRIEVING_START_BLOCK_HASH))
|
178 |
| - (tokenContract (contract-of token)) |
179 | 129 | (senderBalanceResponse (at-block proposalBlockHash (contract-call? .aibtc-token get-balance tx-sender)))
|
180 | 130 | (senderBalance (unwrap-panic senderBalanceResponse))
|
181 | 131 | )
|
182 |
| - ;; required variables must be set |
183 |
| - (asserts! (is-initialized) ERR_NOT_INITIALIZED) |
184 |
| - ;; token matches set voting token |
185 |
| - (asserts! (is-eq tokenContract (var-get votingToken)) ERR_TOKEN_MISMATCH) |
186 | 132 | ;; caller has the required balance
|
187 | 133 | (asserts! (> senderBalance u0) ERR_INSUFFICIENT_BALANCE)
|
188 | 134 | ;; proposal was not already executed
|
|
215 | 161 | )
|
216 | 162 | )
|
217 | 163 |
|
218 |
| -(define-public (conclude-proposal (proposal <proposal-trait>) (treasury <treasury-trait>) (token <ft-trait>)) |
| 164 | +(define-public (conclude-proposal (proposal <proposal-trait>)) |
219 | 165 | (let
|
220 | 166 | (
|
221 | 167 | (proposalContract (contract-of proposal))
|
222 | 168 | (proposalRecord (unwrap! (map-get? Proposals proposalContract) ERR_PROPOSAL_NOT_FOUND))
|
223 |
| - (tokenContract (contract-of token)) |
224 |
| - (tokenTotalSupply (try! (contract-call? token get-total-supply))) |
225 |
| - (treasuryContract (contract-of treasury)) |
226 |
| - (treasuryBalance (try! (contract-call? token get-balance treasuryContract))) |
| 169 | + (tokenTotalSupply (unwrap! (contract-call? .aibtc-token get-total-supply) ERR_FETCHING_TOKEN_DATA)) |
| 170 | + (treasuryBalance (unwrap! (contract-call? .aibtc-token get-balance .aibtc-treasury) ERR_FETCHING_TOKEN_DATA)) |
227 | 171 | (votePassed (> (get votesFor proposalRecord) (* tokenTotalSupply (- u100 treasuryBalance) VOTING_QUORUM)))
|
228 | 172 | )
|
229 |
| - ;; required variables must be set |
230 |
| - (asserts! (is-initialized) ERR_NOT_INITIALIZED) |
231 |
| - ;; verify treasury matches protocol treasury |
232 |
| - (asserts! (is-eq treasuryContract (var-get protocolTreasury)) ERR_TREASURY_MISMATCH) |
233 | 173 | ;; proposal was not already executed
|
234 | 174 | (asserts! (is-none (contract-call? .aibtcdev-base-dao executed-at proposal)) ERR_PROPOSAL_ALREADY_EXECUTED)
|
235 | 175 | ;; proposal past end block height
|
|
261 | 201 | ;; read only functions
|
262 | 202 | ;;
|
263 | 203 |
|
264 |
| -(define-read-only (get-protocol-treasury) |
265 |
| - (if (is-eq (var-get protocolTreasury) SELF) |
266 |
| - none |
267 |
| - (some (var-get protocolTreasury)) |
268 |
| - ) |
269 |
| -) |
270 |
| - |
271 |
| -(define-read-only (get-voting-token) |
272 |
| - (if (is-eq (var-get votingToken) SELF) |
273 |
| - none |
274 |
| - (some (var-get votingToken)) |
275 |
| - ) |
| 204 | +(define-read-only (get-linked-voting-contracts) |
| 205 | + { |
| 206 | + treasury: VOTING_TREASURY, |
| 207 | + token-dex: VOTING_TOKEN_DEX, |
| 208 | + token-pool: VOTING_TOKEN_POOL |
| 209 | + } |
276 | 210 | )
|
277 | 211 |
|
278 | 212 | (define-read-only (get-proposal (proposal principal))
|
|
283 | 217 | (default-to u0 (map-get? VotingRecords {proposal: proposal, voter: voter}))
|
284 | 218 | )
|
285 | 219 |
|
286 |
| -(define-read-only (is-initialized) |
287 |
| - ;; check if the required variables are set |
288 |
| - (not (or |
289 |
| - (is-eq (var-get votingToken) SELF) |
290 |
| - (is-eq (var-get protocolTreasury) SELF) |
291 |
| - )) |
292 |
| -) |
293 |
| - |
294 | 220 | (define-read-only (get-voting-period)
|
295 | 221 | VOTING_PERIOD
|
296 | 222 | )
|
|
0 commit comments