From 41c8616189aa90bce512e3c6ebc6dd2892955401 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Mon, 25 Nov 2024 14:51:27 -0700 Subject: [PATCH] fix: fill in base dao implementation --- contracts/dao/aibtcdev-dao.clar | 91 ++++++++++++++++++++++++++++++--- 1 file changed, 84 insertions(+), 7 deletions(-) diff --git a/contracts/dao/aibtcdev-dao.clar b/contracts/dao/aibtcdev-dao.clar index ab452e8..ef1a885 100644 --- a/contracts/dao/aibtcdev-dao.clar +++ b/contracts/dao/aibtcdev-dao.clar @@ -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 )) + (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 ) (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 ) (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 )) + (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)) + ) +)