Skip to content

Commit b194f44

Browse files
committed
fix: hardcode token contract instead of init
This simplifies the code we have to test per dao, and we can insert this contract reference using the templates when generating, so the init was an extra step that wasn't needed. Every dao is focused around one token, so we can directly reference it and let other values change, like which treasury is compared for voting.
1 parent 002f610 commit b194f44

File tree

5 files changed

+15
-86
lines changed

5 files changed

+15
-86
lines changed

Clarinet.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,11 @@ path = 'contracts/dao/proposals/aibtc-action-proposals-set-protocol-treasury.cla
282282
clarity_version = 2
283283
epoch = 3.0
284284

285-
[contracts.aibtc-action-proposals-set-voting-token]
286-
path = 'contracts/dao/proposals/aibtc-action-proposals-set-voting-token.clar'
287-
clarity_version = 2
288-
epoch = 3.0
289-
290285
[contracts.aibtc-core-proposals-set-protocol-treasury]
291286
path = 'contracts/dao/proposals/aibtc-core-proposals-set-protocol-treasury.clar'
292287
clarity_version = 2
293288
epoch = 3.0
294289

295-
[contracts.aibtc-core-proposals-set-voting-token]
296-
path = 'contracts/dao/proposals/aibtc-core-proposals-set-voting-token.clar'
297-
clarity_version = 2
298-
epoch = 3.0
299-
300290
# dao traits
301291

302292
[contracts.aibtcdev-dao-traits-v1]

contracts/dao/extensions/aibtc-action-proposals.clar

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030
(define-constant ERR_TREASURY_CANNOT_BE_SAME (err u1202))
3131

3232
;; 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))
3835

3936
;; error messages - proposals
4037
(define-constant ERR_PROPOSAL_NOT_FOUND (err u1400))
@@ -56,7 +53,6 @@
5653
;; data vars
5754
;;
5855
(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
6056
(define-data-var proposalCount uint u0) ;; total number of proposals
6157

6258
;; data maps
@@ -113,40 +109,16 @@
113109
)
114110
)
115111

116-
(define-public (set-voting-token (token <ft-trait>))
112+
(define-public (propose-action (action <action-trait>) (parameters (buff 2048)))
117113
(let
118114
(
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))
142115
(newId (+ (var-get proposalCount) u1))
116+
(voterBalance (unwrap! (contract-call? .aibtc-token get-balance tx-sender) ERR_FETCHING_TOKEN_DATA))
143117
)
144118
;; required variables must be set
145119
(asserts! (is-initialized) ERR_NOT_INITIALIZED)
146-
;; token matches set voting token
147-
(asserts! (is-eq tokenContract (var-get votingToken)) ERR_TOKEN_MISMATCH)
148120
;; 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)
150122
;; print proposal creation event
151123
(print {
152124
notification: "propose-action",
@@ -178,23 +150,19 @@
178150
)
179151
)
180152

181-
(define-public (vote-on-proposal (proposalId uint) (token <ft-trait>) (vote bool))
153+
(define-public (vote-on-proposal (proposalId uint) (vote bool))
182154
(let
183155
(
184156
(proposalRecord (unwrap! (map-get? Proposals proposalId) ERR_PROPOSAL_NOT_FOUND))
185157
(proposalBlock (get startBlock proposalRecord))
186158
(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))
190160
)
191161
;; required variables must be set
192162
(asserts! (is-initialized) ERR_NOT_INITIALIZED)
193-
;; token matches set voting token
194-
(asserts! (is-eq tokenContract (var-get votingToken)) ERR_TOKEN_MISMATCH)
195163
;; caller has the required balance
196164
(asserts! (> senderBalance u0) ERR_INSUFFICIENT_BALANCE)
197-
;; proposal is still active
165+
;; proposal not still active
198166
(asserts! (>= burn-block-height (get startBlock proposalRecord)) ERR_VOTE_TOO_SOON)
199167
(asserts! (< burn-block-height (get endBlock proposalRecord)) ERR_VOTE_TOO_LATE)
200168
;; proposal not already concluded
@@ -222,14 +190,13 @@
222190
)
223191
)
224192

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>))
226194
(let
227195
(
228196
(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))
231198
(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))
233200
(votePassed (> (get votesFor proposalRecord) (* tokenTotalSupply (- u100 treasuryBalance) VOTING_QUORUM)))
234201
)
235202
;; required variables must be set
@@ -277,13 +244,6 @@
277244
)
278245
)
279246

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-
287247
(define-read-only (get-proposal (proposalId uint))
288248
(map-get? Proposals proposalId)
289249
)
@@ -293,11 +253,7 @@
293253
)
294254

295255
(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))
301257
)
302258

303259
(define-read-only (get-voting-period)

contracts/dao/proposals/aibtc-action-proposals-set-voting-token.clar

Lines changed: 0 additions & 5 deletions
This file was deleted.

contracts/dao/proposals/aibtc-core-proposals-set-voting-token.clar

Lines changed: 0 additions & 5 deletions
This file was deleted.

contracts/dao/traits/aibtcdev-dao-traits-v1.clar

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,22 @@
3030
;; @param treasury the treasury contract principal
3131
;; @returns (response bool uint)
3232
(set-protocol-treasury (<treasury>) (response bool uint))
33-
;; set the voting token contract
34-
;; @param token the token contract principal
35-
;; @returns (response bool uint)
36-
(set-voting-token (<ft-trait>) (response bool uint))
3733
;; propose a new action
3834
;; @param action the action contract
3935
;; @param parameters encoded action parameters
40-
;; @param token the voting token contract
4136
;; @returns (response bool uint)
42-
(propose-action (<action> (buff 2048) <ft-trait>) (response bool uint))
37+
(propose-action (<action> (buff 2048)) (response bool uint))
4338
;; vote on an existing proposal
4439
;; @param proposal the proposal id
45-
;; @param token the voting token contract
4640
;; @param vote true for yes, false for no
4741
;; @returns (response bool uint)
48-
(vote-on-proposal (uint <ft-trait> bool) (response bool uint))
42+
(vote-on-proposal (uint bool) (response bool uint))
4943
;; conclude a proposal after voting period
5044
;; @param proposal the proposal id
5145
;; @param action the action contract
5246
;; @param treasury the treasury contract
53-
;; @param token the voting token contract
5447
;; @returns (response bool uint)
55-
(conclude-proposal (uint <action> <treasury> <ft-trait>) (response bool uint))
48+
(conclude-proposal (uint <action> <treasury>) (response bool uint))
5649
))
5750

5851
(define-trait bank-account (

0 commit comments

Comments
 (0)