|
30 | 30 | (define-constant ERR_TREASURY_CANNOT_BE_SAME (err u1202))
|
31 | 31 |
|
32 | 32 | ;; error messages - voting token
|
33 |
| -(define-constant ERR_TOKEN_ALREADY_INITIALIZED (err u1300)) |
34 |
| -(define-constant ERR_TOKEN_MISMATCH (err u1301)) |
35 |
| -(define-constant ERR_INSUFFICIENT_BALANCE (err u1302)) |
36 |
| -(define-constant ERR_TOKEN_CANNOT_BE_SELF (err u1303)) |
37 |
| -(define-constant ERR_TOKEN_CANNOT_BE_SAME (err u1304)) |
| 33 | +(define-constant ERR_INSUFFICIENT_BALANCE (err u1300)) |
| 34 | +(define-constant ERR_FETCHING_TOKEN_DATA (err u1301)) |
38 | 35 |
|
39 | 36 | ;; error messages - proposals
|
40 | 37 | (define-constant ERR_PROPOSAL_NOT_FOUND (err u1400))
|
|
56 | 53 | ;; data vars
|
57 | 54 | ;;
|
58 | 55 | (define-data-var protocolTreasury principal SELF) ;; the treasury contract for protocol funds
|
59 |
| -(define-data-var votingToken principal SELF) ;; the FT contract used for voting |
60 | 56 | (define-data-var proposalCount uint u0) ;; total number of proposals
|
61 | 57 |
|
62 | 58 | ;; data maps
|
|
113 | 109 | )
|
114 | 110 | )
|
115 | 111 |
|
116 |
| -(define-public (set-voting-token (token <ft-trait>)) |
| 112 | +(define-public (propose-action (action <action-trait>) (parameters (buff 2048))) |
117 | 113 | (let
|
118 | 114 | (
|
119 |
| - (tokenContract (contract-of token)) |
120 |
| - ) |
121 |
| - (try! (is-dao-or-extension)) |
122 |
| - ;; cannot set token to self |
123 |
| - (asserts! (not (is-eq tokenContract SELF)) ERR_TOKEN_CANNOT_BE_SELF) |
124 |
| - ;; cannot set token to same value |
125 |
| - (asserts! (not (is-eq tokenContract (var-get votingToken))) ERR_TOKEN_CANNOT_BE_SAME) |
126 |
| - ;; cannot set token if already set once |
127 |
| - (asserts! (is-eq (var-get votingToken) SELF) ERR_TOKEN_ALREADY_INITIALIZED) |
128 |
| - (print { |
129 |
| - notification: "set-voting-token", |
130 |
| - payload: { |
131 |
| - token: tokenContract |
132 |
| - } |
133 |
| - }) |
134 |
| - (ok (var-set votingToken tokenContract)) |
135 |
| - ) |
136 |
| -) |
137 |
| - |
138 |
| -(define-public (propose-action (action <action-trait>) (parameters (buff 2048)) (token <ft-trait>)) |
139 |
| - (let |
140 |
| - ( |
141 |
| - (tokenContract (contract-of token)) |
142 | 115 | (newId (+ (var-get proposalCount) u1))
|
| 116 | + (voterBalance (unwrap! (contract-call? .aibtc-token get-balance tx-sender) ERR_FETCHING_TOKEN_DATA)) |
143 | 117 | )
|
144 | 118 | ;; required variables must be set
|
145 | 119 | (asserts! (is-initialized) ERR_NOT_INITIALIZED)
|
146 |
| - ;; token matches set voting token |
147 |
| - (asserts! (is-eq tokenContract (var-get votingToken)) ERR_TOKEN_MISMATCH) |
148 | 120 | ;; caller has the required balance
|
149 |
| - (asserts! (> (try! (contract-call? token get-balance tx-sender)) u0) ERR_INSUFFICIENT_BALANCE) |
| 121 | + (asserts! (> voterBalance u0) ERR_INSUFFICIENT_BALANCE) |
150 | 122 | ;; print proposal creation event
|
151 | 123 | (print {
|
152 | 124 | notification: "propose-action",
|
|
178 | 150 | )
|
179 | 151 | )
|
180 | 152 |
|
181 |
| -(define-public (vote-on-proposal (proposalId uint) (token <ft-trait>) (vote bool)) |
| 153 | +(define-public (vote-on-proposal (proposalId uint) (vote bool)) |
182 | 154 | (let
|
183 | 155 | (
|
184 | 156 | (proposalRecord (unwrap! (map-get? Proposals proposalId) ERR_PROPOSAL_NOT_FOUND))
|
185 | 157 | (proposalBlock (get startBlock proposalRecord))
|
186 | 158 | (proposalBlockHash (unwrap! (get-block-hash proposalBlock) ERR_RETRIEVING_START_BLOCK_HASH))
|
187 |
| - (tokenContract (contract-of token)) |
188 |
| - (senderBalanceResponse (at-block proposalBlockHash (contract-call? .aibtc-token get-balance tx-sender))) |
189 |
| - (senderBalance (unwrap-panic senderBalanceResponse)) |
| 159 | + (senderBalance (unwrap! (at-block proposalBlockHash (contract-call? .aibtc-token get-balance tx-sender)) ERR_FETCHING_TOKEN_DATA)) |
190 | 160 | )
|
191 | 161 | ;; required variables must be set
|
192 | 162 | (asserts! (is-initialized) ERR_NOT_INITIALIZED)
|
193 |
| - ;; token matches set voting token |
194 |
| - (asserts! (is-eq tokenContract (var-get votingToken)) ERR_TOKEN_MISMATCH) |
195 | 163 | ;; caller has the required balance
|
196 | 164 | (asserts! (> senderBalance u0) ERR_INSUFFICIENT_BALANCE)
|
197 |
| - ;; proposal is still active |
| 165 | + ;; proposal not still active |
198 | 166 | (asserts! (>= burn-block-height (get startBlock proposalRecord)) ERR_VOTE_TOO_SOON)
|
199 | 167 | (asserts! (< burn-block-height (get endBlock proposalRecord)) ERR_VOTE_TOO_LATE)
|
200 | 168 | ;; proposal not already concluded
|
|
222 | 190 | )
|
223 | 191 | )
|
224 | 192 |
|
225 |
| -(define-public (conclude-proposal (proposalId uint) (action <action-trait>) (treasury <treasury-trait>) (token <ft-trait>)) |
| 193 | +(define-public (conclude-proposal (proposalId uint) (action <action-trait>) (treasury <treasury-trait>)) |
226 | 194 | (let
|
227 | 195 | (
|
228 | 196 | (proposalRecord (unwrap! (map-get? Proposals proposalId) ERR_PROPOSAL_NOT_FOUND))
|
229 |
| - (tokenContract (contract-of token)) |
230 |
| - (tokenTotalSupply (try! (contract-call? token get-total-supply))) |
| 197 | + (tokenTotalSupply (unwrap! (contract-call? .aibtc-token get-total-supply) ERR_FETCHING_TOKEN_DATA)) |
231 | 198 | (treasuryContract (contract-of treasury))
|
232 |
| - (treasuryBalance (try! (contract-call? token get-balance treasuryContract))) |
| 199 | + (treasuryBalance (unwrap! (contract-call? .aibtc-token get-balance treasuryContract) ERR_FETCHING_TOKEN_DATA)) |
233 | 200 | (votePassed (> (get votesFor proposalRecord) (* tokenTotalSupply (- u100 treasuryBalance) VOTING_QUORUM)))
|
234 | 201 | )
|
235 | 202 | ;; required variables must be set
|
|
277 | 244 | )
|
278 | 245 | )
|
279 | 246 |
|
280 |
| -(define-read-only (get-voting-token) |
281 |
| - (if (is-eq (var-get votingToken) SELF) |
282 |
| - none |
283 |
| - (some (var-get votingToken)) |
284 |
| - ) |
285 |
| -) |
286 |
| - |
287 | 247 | (define-read-only (get-proposal (proposalId uint))
|
288 | 248 | (map-get? Proposals proposalId)
|
289 | 249 | )
|
|
293 | 253 | )
|
294 | 254 |
|
295 | 255 | (define-read-only (is-initialized)
|
296 |
| - ;; check if the required variables are set |
297 |
| - (not (or |
298 |
| - (is-eq (var-get votingToken) SELF) |
299 |
| - (is-eq (var-get protocolTreasury) SELF) |
300 |
| - )) |
| 256 | + (not (is-eq (var-get protocolTreasury) SELF)) |
301 | 257 | )
|
302 | 258 |
|
303 | 259 | (define-read-only (get-voting-period)
|
|
0 commit comments