Branch data Line data Source code
1 : : ;; Title: BME04 Core Execute
2 : : ;; Synopsis:
3 : : ;; This extension allows a small number of very trusted principals to immediately
4 : : ;; execute a proposal once a super majority is reached.
5 : : ;; Description:
6 : : ;; An extension meant for the bootstrapping period of a DAO. It temporarily gives
7 : : ;; some very trusted principals the ability to perform an "executive action";
8 : : ;; meaning, they can skip the voting process to immediately executive a proposal.
9 : : ;; The Core execute extension has an optional sunset period of ~1 month from deploy
10 : : ;; time, set it to 0 to disable. The core executive team, parameters, and sunset period may be changed
11 : : ;; by means of a future proposal.
12 : :
13 : : (impl-trait 'SP3JP0N1ZXGASRJ0F7QAHWFPGTVK9T2XNXDB908Z.extension-trait.extension-trait)
14 : : (use-trait proposal-trait 'SP3JP0N1ZXGASRJ0F7QAHWFPGTVK9T2XNXDB908Z.proposal-trait.proposal-trait)
15 : :
16 : : (define-data-var executive-team-sunset-height uint u0) ;; does not expire by default - can be changed by proposal
17 : :
18 : : (define-constant err-unauthorised (err u3400))
19 : : (define-constant err-not-executive-team-member (err u3401))
20 : : (define-constant err-already-executed (err u3402))
21 : : (define-constant err-sunset-height-reached (err u3403))
22 : : (define-constant err-sunset-height-in-past (err u3404))
23 : :
24 : : (define-map executive-team principal bool)
25 : : (define-map executive-action-signals {proposal: principal, team-member: principal} bool)
26 : : (define-map executive-action-signal-count principal uint)
27 : :
28 : : (define-data-var executive-signals-required uint u1) ;; signals required for an executive action.
29 : :
30 : : ;; --- Authorisation check
31 : :
32 : 300 : (define-public (is-dao-or-extension)
33 [ - ][ + - ]: 1500 : (ok (asserts! (or (is-eq tx-sender .bigmarket-dao) (contract-call? .bigmarket-dao is-extension contract-caller)) err-unauthorised))
34 : : )
35 : :
36 : : ;; --- Internal DAO functions
37 : :
38 : 0 : (define-public (set-executive-team-sunset-height (height uint))
39 : 0 : (begin
40 : 0 : (try! (is-dao-or-extension))
41 [ - ]: 0 : (asserts! (> height burn-block-height) err-sunset-height-in-past)
42 : 0 : (ok (var-set executive-team-sunset-height height))
43 : : )
44 : : )
45 : :
46 : 300 : (define-public (set-executive-team-member (who principal) (member bool))
47 : 1200 : (begin
48 : 1200 : (try! (is-dao-or-extension))
49 : 1200 : (ok (map-set executive-team who member))
50 : : )
51 : : )
52 : :
53 : 300 : (define-public (set-signals-required (new-requirement uint))
54 : 300 : (begin
55 : 300 : (try! (is-dao-or-extension))
56 : 300 : (ok (var-set executive-signals-required new-requirement))
57 : : )
58 : : )
59 : :
60 : : ;; --- Public functions
61 : :
62 : 18 : (define-read-only (is-executive-team-member (who principal))
63 : 48 : (default-to false (map-get? executive-team who))
64 : : )
65 : :
66 : 18 : (define-read-only (has-signalled (proposal principal) (who principal))
67 : 48 : (default-to false (map-get? executive-action-signals {proposal: proposal, team-member: who}))
68 : : )
69 : :
70 : 0 : (define-read-only (get-signals-required)
71 : 0 : (var-get executive-signals-required)
72 : : )
73 : :
74 : 18 : (define-read-only (get-signals (proposal principal))
75 : 48 : (default-to u0 (map-get? executive-action-signal-count proposal))
76 : : )
77 : :
78 : 18 : (define-public (executive-action (proposal <proposal-trait>))
79 : 48 : (let
80 : : (
81 : 48 : (proposal-principal (contract-of proposal))
82 [ - + ]: 48 : (signals (+ (get-signals proposal-principal) (if (has-signalled proposal-principal tx-sender) u0 u1)))
83 : : )
84 [ - ]: 48 : (asserts! (is-executive-team-member tx-sender) err-not-executive-team-member)
85 [ - ][ + - ]: 48 : (asserts! (or (is-eq (var-get executive-team-sunset-height) u0) (< burn-block-height (var-get executive-team-sunset-height))) err-sunset-height-reached)
86 [ + ]: 48 : (and (>= signals (var-get executive-signals-required))
87 [ + ]: 48 : (try! (contract-call? .bigmarket-dao execute proposal tx-sender))
88 : : )
89 : 24 : (map-set executive-action-signals {proposal: proposal-principal, team-member: tx-sender} true)
90 : 24 : (map-set executive-action-signal-count proposal-principal signals)
91 : 24 : (ok signals)
92 : : )
93 : : )
94 : :
95 : : ;; --- Extension callback
96 : :
97 : 0 : (define-public (callback (sender principal) (memo (buff 34)))
98 : 0 : (ok true)
99 : : )
|