Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion @aibtc/types/src/clarity-contract-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ export enum ErrCodeActionProposalVoting {

// aibtc-dao-charter.clar
export enum ErrCodeDaoCharter {
ERR_NOT_DAO_OR_EXTENSION = 1400,
ERR_NOT_AUTHORIZED = 1400,
ERR_SAVING_CHARTER,
ERR_CHARTER_TOO_SHORT,
ERR_CHARTER_TOO_LONG,
ERR_SAVING_MONARCH,
}

// aibtc-dao-epoch.clar
Expand Down
5 changes: 3 additions & 2 deletions @aibtc/types/src/contract-error-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ const errorDefinitions: {
DAO_CHARTER: {
enumObject: ClarityErrors.ErrCodeDaoCharter,
descriptions: {
ERR_NOT_DAO_OR_EXTENSION:
"Caller is not the DAO or an authorized extension.",
ERR_NOT_AUTHORIZED:
"Caller is not the DAO, an authorized extension, or the current monarch.",
ERR_SAVING_CHARTER: "Failed to save the DAO charter.",
ERR_CHARTER_TOO_SHORT: "The provided charter is too short.",
ERR_CHARTER_TOO_LONG: "The provided charter is too long.",
ERR_SAVING_MONARCH: "Failed to save the monarch history.",
},
},
ONCHAIN_MESSAGING: {
Expand Down
131 changes: 106 additions & 25 deletions contracts/dao/extensions/aibtc-dao-charter.clar
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;; title: aibtc-dao-charter
;; version: 1.0.0
;; summary: An extension that manages the DAO charter and records the DAO's mission and values on-chain.
;; version: 2.0.0
;; summary: An extension that allows a monarch to manage the DAO charter and records the DAO's mission and values on-chain.

;; traits
;;
Expand All @@ -19,20 +19,22 @@
(define-constant SELF (as-contract tx-sender))

;; error codes
(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1400))
(define-constant ERR_NOT_AUTHORIZED (err u1400))
(define-constant ERR_SAVING_CHARTER (err u1401))
(define-constant ERR_CHARTER_TOO_SHORT (err u1402))
(define-constant ERR_CHARTER_TOO_LONG (err u1403))
(define-constant ERR_SAVING_MONARCH (err u1404))

;; data vars
;;

(define-data-var currentVersion uint u0)
(define-data-var currentCharterIndex uint u0)
(define-data-var currentMonarchIndex uint u0)

;; data maps
;;

(define-map CharterVersions
(define-map Charters
uint ;; version number
{
burnHeight: uint, ;; burn block height
Expand All @@ -43,6 +45,18 @@
}
)

(define-map Monarchs
uint ;; version number
{
burnHeight: uint, ;; burn block height
createdAt: uint, ;; block height
caller: principal, ;; contract caller
sender: principal, ;; tx-sender
previousMonarch: principal, ;; previous monarch
newMonarch: principal, ;; new monarch
}
)

;; public functions
;;

Expand All @@ -55,20 +69,20 @@

(define-public (set-dao-charter (charter (string-utf8 16384)))
(let (
(newVersion (+ (var-get currentVersion) u1))
(previousCharter (match (map-get? CharterVersions (var-get currentVersion))
(newVersion (+ (var-get currentCharterIndex) u1))
(previousCharter (match (map-get? Charters (var-get currentCharterIndex))
cv (get charter cv)
u""
))
)
;; check if sender is dao or extension
(try! (is-dao-or-extension))
;; check if sender is dao, extension, or monarch
(asserts! (or (is-dao-or-extension) (is-monarch)) ERR_NOT_AUTHORIZED)
;; check length of charter
(asserts! (>= (len charter) u1) ERR_CHARTER_TOO_SHORT)
(asserts! (<= (len charter) u16384) ERR_CHARTER_TOO_LONG)
;; insert new charter version
(asserts!
(map-insert CharterVersions newVersion {
(map-insert Charters newVersion {
burnHeight: burn-block-height,
createdAt: stacks-block-height,
caller: contract-caller,
Expand All @@ -93,39 +107,106 @@
},
})
;; increment charter version
(var-set currentVersion newVersion)
(var-set currentCharterIndex newVersion)
;; return success
(ok true)
)
)

(define-public (set-dao-monarch (newMonarch principal))
(let (
(newIndex (+ (var-get currentMonarchIndex) u1))
;; default to tx-sender if no previous monarch (i.e. first monarch)
(previousMonarch (match (map-get? Monarchs (var-get currentMonarchIndex))
mv (get previousMonarch mv)
tx-sender
))
)
;; check if sender is dao, extension, or monarch
(asserts! (or (is-dao-or-extension) (is-monarch)) ERR_NOT_AUTHORIZED)
;; insert monarch history
(asserts!
(map-insert Monarchs newIndex {
burnHeight: burn-block-height,
createdAt: stacks-block-height,
caller: contract-caller,
sender: tx-sender,
previousMonarch: previousMonarch,
newMonarch: newMonarch,
})
ERR_SAVING_MONARCH
)
;; print monarch change info
(print {
;; /g/aibtc/dao_token_symbol
notification: "aibtc-dao-charter/set-dao-monarch",
payload: {
burnHeight: burn-block-height,
createdAt: stacks-block-height,
contractCaller: contract-caller,
txSender: tx-sender,
dao: SELF,
previousMonarch: previousMonarch,
newMonarch: newMonarch,
index: newIndex,
},
})
;; increment monarch index
(var-set currentMonarchIndex newIndex)
;; return success
(ok true)
)
)

;; read only functions
;;
(define-read-only (get-current-dao-charter-version)
(if (> (var-get currentVersion) u0)
(some (var-get currentVersion))
(define-read-only (get-current-dao-charter-index)
(if (> (var-get currentCharterIndex) u0)
(some (var-get currentCharterIndex))
none
)
)

(define-read-only (get-current-dao-charter)
(map-get? CharterVersions (var-get currentVersion))
(map-get? Charters (var-get currentCharterIndex))
)

(define-read-only (get-dao-charter (version uint))
(map-get? CharterVersions version)
(map-get? Charters version)
)

(define-read-only (get-current-dao-monarch-index)
(if (> (var-get currentMonarchIndex) u0)
(some (var-get currentMonarchIndex))
none
)
)

(define-read-only (get-current-dao-monarch)
(map-get? Monarchs (var-get currentMonarchIndex))
)

(define-read-only (get-dao-monarch (index uint))
(map-get? Monarchs index)
)

;; private functions
;;

;; auth functions simplified to bool outputs so that we can check
;; both versus just is-dao-or-extension like other contracts

(define-private (is-dao-or-extension)
(ok (asserts!
(or
;; /g/.aibtc-base-dao/dao_contract_base
(is-eq tx-sender .aibtc-base-dao)
;; /g/.aibtc-base-dao/dao_contract_base
(contract-call? .aibtc-base-dao is-extension contract-caller)
)
ERR_NOT_DAO_OR_EXTENSION
))
(or
;; /g/.aibtc-base-dao/dao_contract_base
(is-eq tx-sender .aibtc-base-dao)
;; /g/.aibtc-base-dao/dao_contract_base
(contract-call? .aibtc-base-dao is-extension contract-caller)
)
)

(define-private (is-monarch)
(let ((currentMonarch (map-get? Monarchs (var-get currentMonarchIndex))))
(and (is-some currentMonarch) (is-eq tx-sender (get newMonarch (unwrap-panic currentMonarch))))
)
)
4 changes: 4 additions & 0 deletions contracts/dao/proposals/aibtc-base-initialize-dao.clar
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

;; /g/Test/dao_manifest
(define-constant CFG_DAO_MANIFEST_TEXT u"Test")
;; /g/'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM/dao_monarch
(define-constant CFG_DAO_MONARCH 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM)
;; /g/.aibtc-faktory/dao_contract_token
(define-constant CFG_DAO_TOKEN .aibtc-faktory)
;; /g/'STV9K21TBFAK4KNRJXF5DFP8N7W46G4V9RJ5XDY2.sbtc-token/sbtc_token_contract
Expand Down Expand Up @@ -64,6 +66,8 @@
;; set DAO manifest in dao-charter extension
;; /g/.aibtc-dao-charter/dao_contract_charter
(try! (contract-call? .aibtc-dao-charter set-dao-charter CFG_DAO_MANIFEST_TEXT))
;; /g/.aibtc-dao-charter/dao_contract_charter
(try! (contract-call? .aibtc-dao-charter set-dao-monarch CFG_DAO_MONARCH))
;; print initialization data
(print {
;; /g/aibtc/dao_token_symbol
Expand Down
Loading
Loading