Skip to content

Commit 41c8616

Browse files
committed
fix: fill in base dao implementation
1 parent 0107a3b commit 41c8616

File tree

1 file changed

+84
-7
lines changed

1 file changed

+84
-7
lines changed

contracts/dao/aibtcdev-dao.clar

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,107 @@
1-
2-
;; title: aibtcdev-basedao
3-
;; version:
4-
;; summary:
5-
;; description:
1+
;; title: aibtcdev-dao
2+
;; version: 1.0.0
3+
;; summary: An ExecutorDAO implementation for aibtcdev
64

75
;; traits
86
;;
97

10-
;; token definitions
11-
;;
8+
(use-trait proposal-trait .aibtcdev-proposal-trait.proposal-trait)
9+
(use-trait extension-trait .aibtcdev-extension-trait.extension-trait)
1210

1311
;; constants
1412
;;
1513

14+
(define-constant ERR_UNAUTHORIZED (err u900))
15+
(define-constant ERR_ALREADY_EXECUTED (err u901))
16+
(define-constant ERR_INVALID_EXTENSION (err u902))
17+
1618
;; data vars
1719
;;
1820

21+
;; used for initial construction, set to contract itself after
22+
(define-data-var executive principal tx-sender)
23+
1924
;; data maps
2025
;;
2126

27+
;; tracks block height of executed proposals
28+
(define-map ExecutedProposals principal uint)
29+
;; tracks enabled status of extensions
30+
(define-map Extensions principal bool)
31+
2232
;; public functions
2333
;;
2434

35+
;; initial construction of the DAO
36+
(define-public (construct (proposal <proposal-trait>))
37+
(let
38+
((sender tx-sender))
39+
(asserts! (is-eq sender (var-get executive)) ERR_UNAUTHORIZED)
40+
(var-set executive (as-contract tx-sender))
41+
(as-contract (execute proposal sender))
42+
)
43+
)
44+
45+
;; execute Clarity code in a proposal
46+
(define-public (execute (proposal <proposal-trait>) (sender principal))
47+
(begin
48+
(try! (is-self-or-extension))
49+
(asserts! (map-insert ExecutedProposals (contract-of proposal) block-height) ERR_ALREADY_EXECUTED)
50+
(print {event: "execute", proposal: proposal})
51+
(as-contract (contract-call? proposal execute sender))
52+
)
53+
)
54+
55+
;; add an extension or update the status of an existing one
56+
(define-public (set-extension (extension principal) (enabled bool))
57+
(begin
58+
(try! (is-self-or-extension))
59+
(print {event: "extension", enabled: enabled, extension: extension,})
60+
(ok (map-set Extensions extension enabled))
61+
)
62+
)
63+
64+
;; add multiple extensions or update the status of existing ones
65+
(define-public (set-extensions (extensionList (list 200 {extension: principal, enabled: bool})))
66+
(begin
67+
(try! (is-self-or-extension))
68+
(ok (map set-extensions-iter extensionList))
69+
)
70+
)
71+
72+
;; request a callback from an extension
73+
(define-public (request-extension-callback (extension <extension-trait>) (memo (buff 34)))
74+
(let
75+
((sender tx-sender))
76+
(asserts! (is-extension contract-caller) ERR_INVALID_EXTENSION)
77+
(asserts! (is-eq contract-caller (contract-of extension)) ERR_INVALID_EXTENSION)
78+
(as-contract (contract-call? extension callback sender memo))
79+
)
80+
)
81+
2582
;; read only functions
2683
;;
2784

85+
(define-read-only (is-extension (extension principal))
86+
(default-to false (map-get? Extensions extension))
87+
)
88+
89+
(define-read-only (executed-at (proposal <proposal-trait>))
90+
(map-get? ExecutedProposals (contract-of proposal))
91+
)
92+
2893
;; private functions
2994
;;
3095

96+
;; authorization check
97+
(define-private (is-self-or-extension)
98+
(ok (asserts! (or (is-eq tx-sender (as-contract tx-sender)) (is-extension contract-caller)) ERR_UNAUTHORIZED))
99+
)
100+
101+
;; set extensions helper function
102+
(define-private (set-extensions-iter (item {extension: principal, enabled: bool}))
103+
(begin
104+
(print {event: "extension", enabled: (get enabled item), extension: (get extension item)})
105+
(map-set Extensions (get extension item) (get enabled item))
106+
)
107+
)

0 commit comments

Comments
 (0)