Branch data Line data Source code
1 : : ;; BigMarket DAO
2 : : ;; Synopsis:
3 : : ;; bigmarket-dao is the core of the dao framework.
4 : : ;; Description:
5 : : ;; Valid extensions must be registered here. The DAO is bootstrapped
6 : : ;; by calling construct with a bootstrap proposal.
7 : :
8 : : (use-trait extension-trait 'SP3JP0N1ZXGASRJ0F7QAHWFPGTVK9T2XNXDB908Z.extension-trait.extension-trait)
9 : : (use-trait proposal-trait 'SP3JP0N1ZXGASRJ0F7QAHWFPGTVK9T2XNXDB908Z.proposal-trait.proposal-trait)
10 : :
11 : : (define-constant err-unauthorised (err u1000))
12 : : (define-constant err-already-executed (err u1001))
13 : : (define-constant err-invalid-extension (err u1002))
14 : : (define-constant err-invalid-caller (err u1003))
15 : :
16 : : (define-data-var executive principal tx-sender)
17 : : (define-map executed-proposals principal uint)
18 : : (define-map extensions principal bool)
19 : :
20 : : ;; --- Authorisation check
21 : :
22 : 421 : (define-private (is-self-or-extension)
23 [ + ][ + + ]: 1040 : (ok (asserts! (or (is-eq tx-sender (as-contract tx-sender)) (is-extension contract-caller)) err-unauthorised))
24 : : )
25 : :
26 : : ;; --- Extensions
27 : :
28 : 386 : (define-read-only (is-extension (extension principal))
29 : 1365 : (default-to false (map-get? extensions extension))
30 : : )
31 : :
32 : 1 : (define-public (set-extension (extension principal) (enabled bool))
33 : 2 : (begin
34 : 2 : (try! (is-self-or-extension))
35 : 1 : (print {event: "extension", extension: extension, enabled: enabled})
36 : 1 : (ok (map-set extensions extension enabled))
37 : : )
38 : : )
39 : :
40 : 421 : (define-private (set-extensions-iter (item {extension: principal, enabled: bool}))
41 : 6330 : (begin
42 : 6330 : (print {event: "extension", extension: (get extension item), enabled: (get enabled item)})
43 : 6330 : (map-set extensions (get extension item) (get enabled item))
44 : : )
45 : : )
46 : :
47 : 421 : (define-public (set-extensions (extension-list (list 200 {extension: principal, enabled: bool})))
48 : 435 : (begin
49 : 435 : (try! (is-self-or-extension))
50 : 435 : (ok (map set-extensions-iter extension-list))
51 : : )
52 : : )
53 : :
54 : : ;; --- Proposals
55 : :
56 : 126 : (define-read-only (executed-at (proposal <proposal-trait>))
57 : 167 : (map-get? executed-proposals (contract-of proposal))
58 : : )
59 : :
60 : 421 : (define-public (execute (proposal <proposal-trait>) (sender principal))
61 : 603 : (begin
62 : 603 : (try! (is-self-or-extension))
63 [ + ]: 603 : (asserts! (map-insert executed-proposals (contract-of proposal) stacks-block-height) err-already-executed)
64 : 579 : (print {event: "execute", proposal: proposal})
65 : 579 : (as-contract (contract-call? proposal execute sender))
66 : : )
67 : : )
68 : :
69 : : ;; --- Bootstrap
70 : :
71 : 421 : (define-public (construct (proposal <proposal-trait>))
72 : 543 : (let ((sender tx-sender))
73 [ + ]: 543 : (asserts! (is-eq sender (var-get executive)) err-unauthorised)
74 : 421 : (var-set executive (as-contract tx-sender))
75 : 421 : (as-contract (execute proposal sender))
76 : : )
77 : : )
78 : :
79 : : ;; --- Extension requests
80 : :
81 : 1 : (define-public (request-extension-callback (extension <extension-trait>) (memo (buff 34)))
82 : 1 : (let ((sender tx-sender))
83 [ + ]: 1 : (asserts! (is-extension contract-caller) err-invalid-extension)
84 [ - ]: 0 : (asserts! (is-eq contract-caller (contract-of extension)) err-invalid-caller)
85 : 0 : (as-contract (contract-call? extension callback sender memo))
86 : : )
87 : : )
|