-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fill in base dao implementation
- Loading branch information
Showing
1 changed file
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,107 @@ | ||
|
||
;; title: aibtcdev-basedao | ||
;; version: | ||
;; summary: | ||
;; description: | ||
;; title: aibtcdev-dao | ||
;; version: 1.0.0 | ||
;; summary: An ExecutorDAO implementation for aibtcdev | ||
|
||
;; traits | ||
;; | ||
|
||
;; token definitions | ||
;; | ||
(use-trait proposal-trait .aibtcdev-proposal-trait.proposal-trait) | ||
(use-trait extension-trait .aibtcdev-extension-trait.extension-trait) | ||
|
||
;; constants | ||
;; | ||
|
||
(define-constant ERR_UNAUTHORIZED (err u900)) | ||
(define-constant ERR_ALREADY_EXECUTED (err u901)) | ||
(define-constant ERR_INVALID_EXTENSION (err u902)) | ||
|
||
;; data vars | ||
;; | ||
|
||
;; used for initial construction, set to contract itself after | ||
(define-data-var executive principal tx-sender) | ||
|
||
;; data maps | ||
;; | ||
|
||
;; tracks block height of executed proposals | ||
(define-map ExecutedProposals principal uint) | ||
;; tracks enabled status of extensions | ||
(define-map Extensions principal bool) | ||
|
||
;; public functions | ||
;; | ||
|
||
;; initial construction of the DAO | ||
(define-public (construct (proposal <proposal-trait>)) | ||
(let | ||
((sender tx-sender)) | ||
(asserts! (is-eq sender (var-get executive)) ERR_UNAUTHORIZED) | ||
(var-set executive (as-contract tx-sender)) | ||
(as-contract (execute proposal sender)) | ||
) | ||
) | ||
|
||
;; execute Clarity code in a proposal | ||
(define-public (execute (proposal <proposal-trait>) (sender principal)) | ||
(begin | ||
(try! (is-self-or-extension)) | ||
(asserts! (map-insert ExecutedProposals (contract-of proposal) block-height) ERR_ALREADY_EXECUTED) | ||
(print {event: "execute", proposal: proposal}) | ||
(as-contract (contract-call? proposal execute sender)) | ||
) | ||
) | ||
|
||
;; add an extension or update the status of an existing one | ||
(define-public (set-extension (extension principal) (enabled bool)) | ||
(begin | ||
(try! (is-self-or-extension)) | ||
(print {event: "extension", enabled: enabled, extension: extension,}) | ||
(ok (map-set Extensions extension enabled)) | ||
) | ||
) | ||
|
||
;; add multiple extensions or update the status of existing ones | ||
(define-public (set-extensions (extensionList (list 200 {extension: principal, enabled: bool}))) | ||
(begin | ||
(try! (is-self-or-extension)) | ||
(ok (map set-extensions-iter extensionList)) | ||
) | ||
) | ||
|
||
;; request a callback from an extension | ||
(define-public (request-extension-callback (extension <extension-trait>) (memo (buff 34))) | ||
(let | ||
((sender tx-sender)) | ||
(asserts! (is-extension contract-caller) ERR_INVALID_EXTENSION) | ||
(asserts! (is-eq contract-caller (contract-of extension)) ERR_INVALID_EXTENSION) | ||
(as-contract (contract-call? extension callback sender memo)) | ||
) | ||
) | ||
|
||
;; read only functions | ||
;; | ||
|
||
(define-read-only (is-extension (extension principal)) | ||
(default-to false (map-get? Extensions extension)) | ||
) | ||
|
||
(define-read-only (executed-at (proposal <proposal-trait>)) | ||
(map-get? ExecutedProposals (contract-of proposal)) | ||
) | ||
|
||
;; private functions | ||
;; | ||
|
||
;; authorization check | ||
(define-private (is-self-or-extension) | ||
(ok (asserts! (or (is-eq tx-sender (as-contract tx-sender)) (is-extension contract-caller)) ERR_UNAUTHORIZED)) | ||
) | ||
|
||
;; set extensions helper function | ||
(define-private (set-extensions-iter (item {extension: principal, enabled: bool})) | ||
(begin | ||
(print {event: "extension", enabled: (get enabled item), extension: (get extension item)}) | ||
(map-set Extensions (get extension item) (get enabled item)) | ||
) | ||
) |