From 89bfdea6c5bbd1eb5c2176c632b3cb098ceae9ee Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Mon, 21 Apr 2025 05:47:55 -0700 Subject: [PATCH 01/17] fix: add operating fund, modify treasury withdraw functions STX and FT will now automatically go to OP_FUND based on period and logic defined in next commits. NFT stays the same for now. --- .../dao/extensions/aibtc-operating-fund.clar | 4 ++ contracts/dao/extensions/aibtc-treasury.clar | 43 ++++++++++++------- contracts/dao/traits/aibtc-dao-traits-v3.clar | 6 +-- 3 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 contracts/dao/extensions/aibtc-operating-fund.clar diff --git a/contracts/dao/extensions/aibtc-operating-fund.clar b/contracts/dao/extensions/aibtc-operating-fund.clar new file mode 100644 index 0000000..1553b7a --- /dev/null +++ b/contracts/dao/extensions/aibtc-operating-fund.clar @@ -0,0 +1,4 @@ +;; this contract receives 5% of total supply at launch + +;; this contract can receive DAO token, sBTC or STX from treasury +;; this contract can fund a timed vault when initialized diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 8a08c3f..2d38761 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -13,14 +13,25 @@ ;; constants ;; +(define-constant TREASURY (as-contract tx-sender)) +;; /g/.aibtc-operating-fund/operating_fund_contract +(define-constant OPERATING_FUND .aibtc-operating-fund) +(define-constant DEPLOYED_BURN_BLOCK burn-block-height) +(define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) +(define-constant SELF (as-contract tx-sender)) + +;; error messages (define-constant ERR_NOT_DAO_OR_EXTENSION (err u6000)) (define-constant ERR_UNKNOWN_ASSSET (err u6001)) -(define-constant TREASURY (as-contract tx-sender)) ;; data maps ;; +;; track allowed assets (define-map AllowedAssets principal bool) +;; track claims per period +(define-map StxClaims uint bool) +(define-map FtClaims uint bool) ;; public functions ;; @@ -63,12 +74,12 @@ payload: { amount: amount, contractCaller: contract-caller, - recipient: TREASURY, + recipient: SELF, txSender: tx-sender, - balance: (stx-get-balance TREASURY) + balance: (stx-get-balance SELF) } }) - (stx-transfer? amount tx-sender TREASURY) + (stx-transfer? amount tx-sender SELF) ) ) @@ -82,11 +93,11 @@ amount: amount, assetContract: (contract-of ft), contractCaller: contract-caller, - recipient: TREASURY, + recipient: SELF, txSender: tx-sender } }) - (contract-call? ft transfer amount tx-sender TREASURY none) + (contract-call? ft transfer amount tx-sender SELF none) ) ) @@ -99,17 +110,17 @@ payload: { assetContract: (contract-of nft), contractCaller: contract-caller, - recipient: TREASURY, + recipient: SELF, txSender: tx-sender, tokenId: id } }) - (contract-call? nft transfer id tx-sender TREASURY) + (contract-call? nft transfer id tx-sender SELF) ) ) ;; withdraw STX from the treasury -(define-public (withdraw-stx (amount uint) (recipient principal)) +(define-public (withdraw-stx (amount uint)) (begin (try! (is-dao-or-extension)) (print { @@ -117,17 +128,17 @@ payload: { amount: amount, contractCaller: contract-caller, - recipient: recipient, + recipient: OPERATING_FUND, txSender: tx-sender, - balance: (stx-get-balance TREASURY) + balance: (stx-get-balance SELF) } }) - (as-contract (stx-transfer? amount TREASURY recipient)) + (as-contract (stx-transfer? amount SELF OPERATING_FUND)) ) ) ;; withdraw FT from the treasury -(define-public (withdraw-ft (ft ) (amount uint) (recipient principal)) +(define-public (withdraw-ft (ft ) (amount uint)) (begin (try! (is-dao-or-extension)) (asserts! (is-allowed-asset (contract-of ft)) ERR_UNKNOWN_ASSSET) @@ -136,12 +147,12 @@ payload: { assetContract: (contract-of ft), contractCaller: contract-caller, - recipient: recipient, + recipient: OPERATING_FUND, txSender: tx-sender, amount: amount } }) - (as-contract (contract-call? ft transfer amount TREASURY recipient none)) + (as-contract (contract-call? ft transfer amount SELF OPERATING_FUND none)) ) ) @@ -161,7 +172,7 @@ amount: u1 } }) - (as-contract (contract-call? nft transfer id TREASURY recipient)) + (as-contract (contract-call? nft transfer id SELF recipient)) ) ) diff --git a/contracts/dao/traits/aibtc-dao-traits-v3.clar b/contracts/dao/traits/aibtc-dao-traits-v3.clar index e35b70c..2019ef2 100644 --- a/contracts/dao/traits/aibtc-dao-traits-v3.clar +++ b/contracts/dao/traits/aibtc-dao-traits-v3.clar @@ -1,5 +1,5 @@ ;; title: aibtc-dao-traits -;; version: 3.0.0 +;; version: 3.1.0 ;; summary: A collection of traits for all aibtc daos. ;; IMPORTS @@ -228,13 +228,13 @@ ;; @param amount amount of microSTX to withdraw ;; @param recipient the recipient of the STX ;; @returns (response bool uint) - (withdraw-stx (uint principal) (response bool uint)) + (withdraw-stx (uint) (response bool uint)) ;; withdraw FT from the treasury ;; @param ft the fungible token contract principal ;; @param amount amount of tokens to withdraw ;; @param recipient the recipient of the tokens ;; @returns (response bool uint) - (withdraw-ft ( uint principal) (response bool uint)) + (withdraw-ft ( uint) (response bool uint)) ;; withdraw NFT from the treasury ;; @param nft the non-fungible token contract principal ;; @param id the ID of the token to withdraw From a1b1c692dc2be318140f3b181d3f32f73955d849 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Mon, 21 Apr 2025 05:51:36 -0700 Subject: [PATCH 02/17] fix: rename and rearrange --- contracts/dao/extensions/aibtc-treasury.clar | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 2d38761..c8b8dc8 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -13,9 +13,7 @@ ;; constants ;; -(define-constant TREASURY (as-contract tx-sender)) -;; /g/.aibtc-operating-fund/operating_fund_contract -(define-constant OPERATING_FUND .aibtc-operating-fund) +;; contract names (define-constant DEPLOYED_BURN_BLOCK burn-block-height) (define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) (define-constant SELF (as-contract tx-sender)) @@ -24,6 +22,12 @@ (define-constant ERR_NOT_DAO_OR_EXTENSION (err u6000)) (define-constant ERR_UNKNOWN_ASSSET (err u6001)) +;; template variables +;; + +;; /g/.aibtc-operating-fund/operating_fund_contract +(define-constant CFG_OPERATING_FUND .aibtc-operating-fund) + ;; data maps ;; @@ -128,12 +132,12 @@ payload: { amount: amount, contractCaller: contract-caller, - recipient: OPERATING_FUND, + recipient: CFG_OPERATING_FUND, txSender: tx-sender, balance: (stx-get-balance SELF) } }) - (as-contract (stx-transfer? amount SELF OPERATING_FUND)) + (as-contract (stx-transfer? amount SELF CFG_OPERATING_FUND)) ) ) @@ -147,12 +151,12 @@ payload: { assetContract: (contract-of ft), contractCaller: contract-caller, - recipient: OPERATING_FUND, + recipient: CFG_OPERATING_FUND, txSender: tx-sender, amount: amount } }) - (as-contract (contract-call? ft transfer amount SELF OPERATING_FUND none)) + (as-contract (contract-call? ft transfer amount SELF CFG_OPERATING_FUND none)) ) ) From b14998d74db30127cea190be0c688592f76a9a0d Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Mon, 21 Apr 2025 06:12:51 -0700 Subject: [PATCH 03/17] fix: update withdraw logic to check if period claimed Need to verify that transfers are not possible outside these funcitons with tests and the treasury is officially locked down on an available 30day drip to the operating fund. --- contracts/dao/extensions/aibtc-treasury.clar | 48 ++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index c8b8dc8..fd40626 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -18,9 +18,13 @@ (define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) (define-constant SELF (as-contract tx-sender)) +;; track periods by BTC block height +(define-constant PERIOD_LENGTH u4320) ;; 30 days + ;; error messages (define-constant ERR_NOT_DAO_OR_EXTENSION (err u6000)) (define-constant ERR_UNKNOWN_ASSSET (err u6001)) +(define-constant ERR_PERIOD_ALREADY_CLAIMED (err u6002)) ;; template variables ;; @@ -33,6 +37,7 @@ ;; track allowed assets (define-map AllowedAssets principal bool) + ;; track claims per period (define-map StxClaims uint bool) (define-map FtClaims uint bool) @@ -127,6 +132,7 @@ (define-public (withdraw-stx (amount uint)) (begin (try! (is-dao-or-extension)) + (try! (update-stx-claim amount true)) (print { notification: "withdraw-stx", payload: { @@ -145,6 +151,7 @@ (define-public (withdraw-ft (ft ) (amount uint)) (begin (try! (is-dao-or-extension)) + (try! (update-ft-claim amount true)) (asserts! (is-allowed-asset (contract-of ft)) ERR_UNKNOWN_ASSSET) (print { notification: "withdraw-ft", @@ -229,6 +236,18 @@ (map-get? AllowedAssets assetContract) ) +(define-read-only (get-current-period) + (/ (- burn-block-height DEPLOYED_BURN_BLOCK) PERIOD_LENGTH) +) + +(define-read-only (get-stx-claim (period uint)) + (map-get? StxClaims period) +) + +(define-read-only (get-ft-claim (period uint)) + (map-get? FtClaims period) +) + ;; private functions ;; @@ -253,3 +272,32 @@ ) ) +(define-private (update-stx-claim (period uint) (claimed bool)) + (begin + (print { + notification: "update-stx-claim", + payload: { + period: period, + claimed: claimed, + contractCaller: contract-caller, + txSender: tx-sender + } + }) + (ok (asserts! (map-insert StxClaims period claimed) ERR_PERIOD_ALREADY_CLAIMED)) + ) +) + +(define-private (update-ft-claim (period uint) (claimed bool)) + (begin + (print { + notification: "update-ft-claim", + payload: { + period: period, + claimed: claimed, + contractCaller: contract-caller, + txSender: tx-sender + } + }) + (ok (asserts! (map-insert FtClaims period claimed) ERR_PERIOD_ALREADY_CLAIMED)) + ) +) From c746308b34e2668eb6c02f0a7973a71358d05a09 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Mon, 21 Apr 2025 06:55:18 -0700 Subject: [PATCH 04/17] fix: modify proposals based on latest changes --- contracts/dao/extensions/aibtc-treasury.clar | 14 +++++++++++++- ...aibtc-timed-vault-dao-initialize-new-vault.clar | 2 +- ...ibtc-timed-vault-sbtc-initialize-new-vault.clar | 2 +- ...aibtc-timed-vault-stx-initialize-new-vault.clar | 4 ++-- .../dao/proposals/aibtc-treasury-withdraw-ft.clar | 6 +----- .../dao/proposals/aibtc-treasury-withdraw-stx.clar | 5 +---- contracts/test/aibtc-treasury.clar | 4 ++-- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index fd40626..24d6bc8 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -151,8 +151,8 @@ (define-public (withdraw-ft (ft ) (amount uint)) (begin (try! (is-dao-or-extension)) - (try! (update-ft-claim amount true)) (asserts! (is-allowed-asset (contract-of ft)) ERR_UNKNOWN_ASSSET) + (try! (update-ft-claim amount true)) (print { notification: "withdraw-ft", payload: { @@ -248,6 +248,18 @@ (map-get? FtClaims period) ) +(define-read-only (get-contract-info) + { + self: SELF, + deployedBurnBlock: DEPLOYED_BURN_BLOCK, + deployedStacksBlock: DEPLOYED_STACKS_BLOCK, + currentPeriod: (get-current-period), + currentStxClaim: (get-stx-claim (get-current-period)), + currentFtClaim: (get-ft-claim (get-current-period)), + periodLength: PERIOD_LENGTH, + } +) + ;; private functions ;; diff --git a/contracts/dao/proposals/aibtc-timed-vault-dao-initialize-new-vault.clar b/contracts/dao/proposals/aibtc-timed-vault-dao-initialize-new-vault.clar index 7c298f9..0177211 100644 --- a/contracts/dao/proposals/aibtc-timed-vault-dao-initialize-new-vault.clar +++ b/contracts/dao/proposals/aibtc-timed-vault-dao-initialize-new-vault.clar @@ -16,7 +16,7 @@ (try! (contract-call? .aibtc-base-dao set-extension .aibtc-timed-vault-dao true)) ;; fund the extension from the treasury (and (> CFG_AMOUNT_TO_FUND_DAO u0) - (try! (contract-call? .aibtc-treasury withdraw-ft .aibtc-token CFG_AMOUNT_TO_FUND_DAO .aibtc-timed-vault-dao))) + (try! (contract-call? .aibtc-treasury withdraw-ft .aibtc-token CFG_AMOUNT_TO_FUND_DAO))) (ok true) ) ) diff --git a/contracts/dao/proposals/aibtc-timed-vault-sbtc-initialize-new-vault.clar b/contracts/dao/proposals/aibtc-timed-vault-sbtc-initialize-new-vault.clar index eb14796..5238962 100644 --- a/contracts/dao/proposals/aibtc-timed-vault-sbtc-initialize-new-vault.clar +++ b/contracts/dao/proposals/aibtc-timed-vault-sbtc-initialize-new-vault.clar @@ -16,7 +16,7 @@ (try! (contract-call? .aibtc-base-dao set-extension .aibtc-timed-vault-sbtc true)) ;; fund the extension from the treasury (and (> CFG_AMOUNT_TO_FUND_SBTC u0) - (try! (contract-call? .aibtc-treasury withdraw-ft 'STV9K21TBFAK4KNRJXF5DFP8N7W46G4V9RJ5XDY2.sbtc-token CFG_AMOUNT_TO_FUND_SBTC .aibtc-timed-vault-sbtc))) + (try! (contract-call? .aibtc-treasury withdraw-ft 'STV9K21TBFAK4KNRJXF5DFP8N7W46G4V9RJ5XDY2.sbtc-token CFG_AMOUNT_TO_FUND_SBTC))) (ok true) ) ) diff --git a/contracts/dao/proposals/aibtc-timed-vault-stx-initialize-new-vault.clar b/contracts/dao/proposals/aibtc-timed-vault-stx-initialize-new-vault.clar index 8354ac6..7148c3f 100644 --- a/contracts/dao/proposals/aibtc-timed-vault-stx-initialize-new-vault.clar +++ b/contracts/dao/proposals/aibtc-timed-vault-stx-initialize-new-vault.clar @@ -17,9 +17,9 @@ (try! (contract-call? .aibtc-base-dao set-extension .aibtc-timed-vault-stx true)) ;; CFG_BASE_DAO, CFG_NEW_TIMED_VAULT_CONTRACT ;; fund the extension from the treasury (and (> CFG_AMOUNT_TO_FUND_STX u0) - (try! (contract-call? .aibtc-treasury withdraw-stx CFG_AMOUNT_TO_FUND_STX .aibtc-timed-vault-stx))) ;; CFG_TREASURY_CONTRACT, CFG_NEW_TIMED_VAULT_CONTRACT + (try! (contract-call? .aibtc-treasury withdraw-stx CFG_AMOUNT_TO_FUND_STX))) ;; CFG_TREASURY_CONTRACT, CFG_NEW_TIMED_VAULT_CONTRACT (and (> CFG_AMOUNT_TO_FUND_FT u0) - (try! (contract-call? .aibtc-treasury withdraw-ft .aibtc-token CFG_AMOUNT_TO_FUND_FT .aibtc-timed-vault-stx))) ;; CFG_TREASURY_CONTRACT, CFG_TOKEN_CONTRACT, CFG_NEW_TIMED_VAULT_CONTRACT + (try! (contract-call? .aibtc-treasury withdraw-ft .aibtc-token CFG_AMOUNT_TO_FUND_FT))) ;; CFG_TREASURY_CONTRACT, CFG_TOKEN_CONTRACT, CFG_NEW_TIMED_VAULT_CONTRACT (ok true) ) ) diff --git a/contracts/dao/proposals/aibtc-treasury-withdraw-ft.clar b/contracts/dao/proposals/aibtc-treasury-withdraw-ft.clar index 84fab03..4276573 100644 --- a/contracts/dao/proposals/aibtc-treasury-withdraw-ft.clar +++ b/contracts/dao/proposals/aibtc-treasury-withdraw-ft.clar @@ -4,16 +4,12 @@ ;; (define-constant CFG_MESSAGE "Executed Core Proposal: Withdrew fungible tokens in the treasury extension") (define-constant CFG_TOKEN_AMOUNT u1000) ;; in microFT -(define-constant CFG_RECIPIENT 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM) -;; was CFG_MESSAGE_CONTRACT .aibtc-onchain-messaging -;; was CFG_TREASURY_CONTRACT .aibtc-treasury -;; was CFG_TOKEN_CONTRACT .aibtc-token (define-public (execute (sender principal)) (begin ;; send a message from the dao (try! (contract-call? .aibtc-onchain-messaging send CFG_MESSAGE true)) ;; withdraw fungible tokens from the treasury - (contract-call? .aibtc-treasury withdraw-ft .aibtc-token CFG_TOKEN_AMOUNT CFG_RECIPIENT) + (contract-call? .aibtc-treasury withdraw-ft .aibtc-token CFG_TOKEN_AMOUNT) ) ) diff --git a/contracts/dao/proposals/aibtc-treasury-withdraw-stx.clar b/contracts/dao/proposals/aibtc-treasury-withdraw-stx.clar index 9dd4575..e74cf98 100644 --- a/contracts/dao/proposals/aibtc-treasury-withdraw-stx.clar +++ b/contracts/dao/proposals/aibtc-treasury-withdraw-stx.clar @@ -4,15 +4,12 @@ ;; (define-constant CFG_MESSAGE "Executed Core Proposal: Withdrew STX in the treasury extension") (define-constant CFG_STX_AMOUNT u1000000) ;; in microSTX -(define-constant CFG_RECIPIENT 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM) -;; was CFG_MESSAGE_CONTRACT .aibtc-onchain-messaging -;; was CFG_TREASURY_CONTRACT .aibtc-treasury (define-public (execute (sender principal)) (begin ;; send a message from the dao (try! (contract-call? .aibtc-onchain-messaging send CFG_MESSAGE true)) ;; withdraw STX from the treasury - (contract-call? .aibtc-treasury withdraw-stx CFG_STX_AMOUNT CFG_RECIPIENT) + (contract-call? .aibtc-treasury withdraw-stx CFG_STX_AMOUNT) ) ) diff --git a/contracts/test/aibtc-treasury.clar b/contracts/test/aibtc-treasury.clar index d62b857..6a4a01c 100644 --- a/contracts/test/aibtc-treasury.clar +++ b/contracts/test/aibtc-treasury.clar @@ -29,11 +29,11 @@ (ok true) ) -(define-public (withdraw-stx (amount uint) (recipient principal)) +(define-public (withdraw-stx (amount uint)) (ok true) ) -(define-public (withdraw-ft (ft ) (amount uint) (recipient principal)) +(define-public (withdraw-ft (ft ) (amount uint)) (ok true) ) From c829f8f89417dbaf7ed81910b10b9bc7f93f8e45 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 22 Apr 2025 11:38:15 -0700 Subject: [PATCH 05/17] fix: remove allow-assets, can list multiple in proposal List support is nice but let's keep this as simple as possible. List can be in the proposal as lines of code instead of a literal list, and we're not expecting a long list of entries that would push the limits anytime soon. --- contracts/dao/extensions/aibtc-treasury.clar | 29 ++------------------ 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 24d6bc8..10c0f81 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -1,6 +1,6 @@ ;; title: aibtc-treasury -;; version: 1.0.0 -;; summary: An extension that manages STX, SIP-009 NFTs, and SIP-010 FTs. +;; version: 2.0.0 +;; summary: TBD ;; traits ;; @@ -19,6 +19,7 @@ (define-constant SELF (as-contract tx-sender)) ;; track periods by BTC block height +(define-constant PERIOD_BPS u200) ;; 2% of own supply (define-constant PERIOD_LENGTH u4320) ;; 30 days ;; error messages @@ -66,15 +67,6 @@ ) ) -;; add or update a list of assets to the allowed list -(define-public (allow-assets (allowList (list 100 {token: principal, enabled: bool}))) - (begin - (try! (is-dao-or-extension)) - (map allow-assets-iter allowList) - (ok true) - ) -) - ;; deposit STX to the treasury (define-public (deposit-stx (amount uint)) (begin @@ -269,21 +261,6 @@ )) ) -(define-private (allow-assets-iter (item {token: principal, enabled: bool})) - (begin - (print { - notification: "allow-asset", - payload: { - enabled: (get enabled item), - token: (get token item), - contractCaller: contract-caller, - txSender: tx-sender - } - }) - (map-set AllowedAssets (get token item) (get enabled item)) - ) -) - (define-private (update-stx-claim (period uint) (claimed bool)) (begin (print { From aab864a84f79d470a952572fc8304a321bbe2544 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 22 Apr 2025 11:39:01 -0700 Subject: [PATCH 06/17] fix: use only v3 trait, functions have diverged We might end up needing a blank/empty test file like this for each depending on where it was used, updated to just v3 for now to clear clarinet check errors. --- contracts/test/aibtc-treasury.clar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/test/aibtc-treasury.clar b/contracts/test/aibtc-treasury.clar index 6a4a01c..149980e 100644 --- a/contracts/test/aibtc-treasury.clar +++ b/contracts/test/aibtc-treasury.clar @@ -1,5 +1,5 @@ ;; test treasury contract implementing treasury trait -(impl-trait .aibtcdev-dao-traits-v1.treasury) +;; (impl-trait .aibtcdev-dao-traits-v1.treasury) (impl-trait .aibtc-dao-traits-v3.treasury) (use-trait ft-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait) From 9092df53b2c6628170ff579fb3975ff810f59aae Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 22 Apr 2025 11:39:30 -0700 Subject: [PATCH 07/17] feat: start filling in operating fund code --- .../dao/extensions/aibtc-operating-fund.clar | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/contracts/dao/extensions/aibtc-operating-fund.clar b/contracts/dao/extensions/aibtc-operating-fund.clar index 1553b7a..75bc6ce 100644 --- a/contracts/dao/extensions/aibtc-operating-fund.clar +++ b/contracts/dao/extensions/aibtc-operating-fund.clar @@ -1,4 +1,48 @@ -;; this contract receives 5% of total supply at launch +;; title: aibtc-operating-fund +;; version: 2.0.0 +;; summary: TBD +;; this contract receives 2% of total supply at launch ;; this contract can receive DAO token, sBTC or STX from treasury ;; this contract can fund a timed vault when initialized + +;; traits +;; +(impl-trait .aibtc-dao-traits-v3.extension) +(impl-trait .aibtc-dao-traits-v3.operating-fund) + +;; constants +;; + +(define-constant DEPLOYED_BURN_BLOCK burn-block-height) +(define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) +(define-constant SELF (as-contract tx-sender)) + +;; error messages +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u9000)) ;; TBD/check + +;; template variables +;; +;; /g/find/replace + +;; data maps +;; + +;; public functions +;; + +(define-public (callback (sender principal) (memo (buff 34))) + (ok true) +) + +;; read only functions +;; + +;; private functions +;; + +(define-private (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION + )) +) From 2fa4d31930c77a1449182e35ec3caf8c1242cb70 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 22 Apr 2025 12:31:39 -0700 Subject: [PATCH 08/17] fix: update withdrawal to transfer logic --- contracts/dao/extensions/aibtc-treasury.clar | 184 ++++++++++--------- 1 file changed, 95 insertions(+), 89 deletions(-) diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 10c0f81..32c7f25 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -30,18 +30,28 @@ ;; template variables ;; +;; /g/STV9K21TBFAK4KNRJXF5DFP8N7W46G4V9RJ5XDY2.sbtc-token/sbtc_token_contract +(define-constant CFG_SBTC_TOKEN 'STV9K21TBFAK4KNRJXF5DFP8N7W46G4V9RJ5XDY2.sbtc-token) +;; /g/.aibtc-token/dao_token_contract +(define-constant CFG_DAO_TOKEN .aibtc-token) ;; /g/.aibtc-operating-fund/operating_fund_contract (define-constant CFG_OPERATING_FUND .aibtc-operating-fund) ;; data maps ;; -;; track allowed assets +;; track allowed assets for deposit/transfer (define-map AllowedAssets principal bool) -;; track claims per period -(define-map StxClaims uint bool) -(define-map FtClaims uint bool) +;; track transfers per period +(define-map StxClaims + uint ;; period + bool ;; claimed +) +(define-map FtClaims + { contract: principal, period: uint } + bool ;; claimed +) ;; public functions ;; @@ -55,10 +65,10 @@ (begin (try! (is-dao-or-extension)) (print { - notification: "allow-asset", + notification: "treasury-allow-asset", payload: { - enabled: enabled, token: token, + enabled: enabled, contractCaller: contract-caller, txSender: tx-sender } @@ -68,16 +78,16 @@ ) ;; deposit STX to the treasury -(define-public (deposit-stx (amount uint)) +(define-public (deposit-stx (amount uint)) (begin + ;; no auth - anyone can deposit (print { - notification: "deposit-stx", + notification: "treasury-deposit-stx", payload: { amount: amount, - contractCaller: contract-caller, recipient: SELF, + contractCaller: contract-caller, txSender: tx-sender, - balance: (stx-get-balance SELF) } }) (stx-transfer? amount tx-sender SELF) @@ -87,14 +97,15 @@ ;; deposit FT to the treasury (define-public (deposit-ft (ft ) (amount uint)) (begin + ;; no auth - anyone can deposit if token allowed (asserts! (is-allowed-asset (contract-of ft)) ERR_UNKNOWN_ASSSET) (print { - notification: "deposit-ft", + notification: "treasury-deposit-ft", payload: { amount: amount, + recipient: SELF, assetContract: (contract-of ft), contractCaller: contract-caller, - recipient: SELF, txSender: tx-sender } }) @@ -102,80 +113,48 @@ ) ) -;; deposit NFT to the treasury -(define-public (deposit-nft (nft ) (id uint)) - (begin - (asserts! (is-allowed-asset (contract-of nft)) ERR_UNKNOWN_ASSSET) - (print { - notification: "deposit-nft", - payload: { - assetContract: (contract-of nft), - contractCaller: contract-caller, - recipient: SELF, - txSender: tx-sender, - tokenId: id - } - }) - (contract-call? nft transfer id tx-sender SELF) - ) -) - -;; withdraw STX from the treasury -(define-public (withdraw-stx (amount uint)) - (begin +;; transfer STX from treasury to operating fund +;; TODO - determine amount as 2% of balance +(define-public (transfer-stx-to-operating-fund) + (let + ( + (amount u0) + ) (try! (is-dao-or-extension)) - (try! (update-stx-claim amount true)) + (try! (update-claim-stx)) (print { - notification: "withdraw-stx", + notification: "treasury-transfer-stx-to-operating-fund", payload: { - amount: amount, - contractCaller: contract-caller, recipient: CFG_OPERATING_FUND, + contractCaller: contract-caller, txSender: tx-sender, - balance: (stx-get-balance SELF) } }) (as-contract (stx-transfer? amount SELF CFG_OPERATING_FUND)) ) ) -;; withdraw FT from the treasury -(define-public (withdraw-ft (ft ) (amount uint)) - (begin +;; transfer FT from treasury to operating fund +(define-public (transfer-ft-to-operating-fund (ft )) + (let + ( + (assetContract (contract-of ft)) + (amount u0) + ) (try! (is-dao-or-extension)) - (asserts! (is-allowed-asset (contract-of ft)) ERR_UNKNOWN_ASSSET) - (try! (update-ft-claim amount true)) + (asserts! (is-allowed-asset assetContract) ERR_UNKNOWN_ASSSET) + (try! (update-claim-ft assetContract)) (print { - notification: "withdraw-ft", + notification: "treasury-transfer-ft-to-operating-fund", payload: { - assetContract: (contract-of ft), - contractCaller: contract-caller, + amount: amount, + assetContract: assetContract, recipient: CFG_OPERATING_FUND, - txSender: tx-sender, - amount: amount - } - }) - (as-contract (contract-call? ft transfer amount SELF CFG_OPERATING_FUND none)) - ) -) - -;; withdraw NFT from the treasury -(define-public (withdraw-nft (nft ) (id uint) (recipient principal)) - (begin - (try! (is-dao-or-extension)) - (asserts! (is-allowed-asset (contract-of nft)) ERR_UNKNOWN_ASSSET) - (print { - notification: "withdraw-nft", - payload: { - assetContract: (contract-of nft), contractCaller: contract-caller, - recipient: recipient, txSender: tx-sender, - tokenId: id, - amount: u1 } }) - (as-contract (contract-call? nft transfer id SELF recipient)) + (as-contract (contract-call? ft transfer amount SELF CFG_OPERATING_FUND none)) ) ) @@ -232,24 +211,41 @@ (/ (- burn-block-height DEPLOYED_BURN_BLOCK) PERIOD_LENGTH) ) -(define-read-only (get-stx-claim (period uint)) +(define-read-only (get-claim-stx (period uint)) (map-get? StxClaims period) ) -(define-read-only (get-ft-claim (period uint)) - (map-get? FtClaims period) +(define-read-only (get-claim-ft (assetContract principal) (period uint)) + (map-get? FtClaims { contract: assetContract, period: period }) ) (define-read-only (get-contract-info) - { - self: SELF, - deployedBurnBlock: DEPLOYED_BURN_BLOCK, - deployedStacksBlock: DEPLOYED_STACKS_BLOCK, - currentPeriod: (get-current-period), - currentStxClaim: (get-stx-claim (get-current-period)), - currentFtClaim: (get-ft-claim (get-current-period)), - periodLength: PERIOD_LENGTH, - } + (let + ( + (currentPeriod (get-current-period)) + (lastPeriod (if (> currentPeriod u0) (- currentPeriod u1) u0)) + ) + ;; return contract info object + { + self: SELF, + deployedBurnBlock: DEPLOYED_BURN_BLOCK, + deployedStacksBlock: DEPLOYED_STACKS_BLOCK, + periodBps: PERIOD_BPS, + periodLength: PERIOD_LENGTH, + lastPeriod: { + period: lastPeriod, + btcClaimed: (get-claim-ft CFG_SBTC_TOKEN lastPeriod), + daoClaimed: (get-claim-ft CFG_DAO_TOKEN lastPeriod), + stxClaimed: (get-claim-stx lastPeriod), + }, + currentPeriod: { + period: currentPeriod, + btcClaimed: (get-claim-ft CFG_SBTC_TOKEN currentPeriod), + daoClaimed: (get-claim-ft CFG_DAO_TOKEN currentPeriod), + stxClaimed: (get-claim-stx currentPeriod), + }, + } + ) ) ;; private functions @@ -261,32 +257,42 @@ )) ) -(define-private (update-stx-claim (period uint) (claimed bool)) +;; helper that will update the claim status for STX +;; and error if the period was already claimed +(define-private (update-claim-stx) (begin (print { - notification: "update-stx-claim", + notification: "treasury-update-claim-stx", payload: { - period: period, - claimed: claimed, + period: (get-current-period), + claimed: true, contractCaller: contract-caller, txSender: tx-sender } }) - (ok (asserts! (map-insert StxClaims period claimed) ERR_PERIOD_ALREADY_CLAIMED)) + (ok (asserts! + (map-insert StxClaims (get-current-period) true) + ERR_PERIOD_ALREADY_CLAIMED + )) ) ) -(define-private (update-ft-claim (period uint) (claimed bool)) +;; helper that will update the claim status for FT +;; and error if the period was already claimed +(define-private (update-claim-ft (assetContract principal)) (begin (print { - notification: "update-ft-claim", + notification: "treasury-update-claim-ft", payload: { - period: period, - claimed: claimed, + period: (get-current-period), + claimed: true, contractCaller: contract-caller, txSender: tx-sender } }) - (ok (asserts! (map-insert FtClaims period claimed) ERR_PERIOD_ALREADY_CLAIMED)) + (ok (asserts! + (map-insert FtClaims { contract: contract-caller, period: (get-current-period) } true) + ERR_PERIOD_ALREADY_CLAIMED + )) ) ) From c675dcc88f0c600df3df2ef869ace900ecc83dad Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 22 Apr 2025 13:01:06 -0700 Subject: [PATCH 09/17] fix: finish helpers and calculations for transfer Also more specific on print statement contents and consistency to use in other contracts. --- contracts/dao/extensions/aibtc-treasury.clar | 76 ++++++++++++++------ 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 32c7f25..68f8a29 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -20,12 +20,15 @@ ;; track periods by BTC block height (define-constant PERIOD_BPS u200) ;; 2% of own supply -(define-constant PERIOD_LENGTH u4320) ;; 30 days +(define-constant PERIOD_LENGTH u4320) ;; 30 days in BTC blocks +(define-constant PERIOD_MIN_BTC u100) ;; 0.00000100 BTC or 100 sats (8 decimals) +(define-constant PERIOD_MIN_STX u1000000) ;; 1 STX (6 decimals) ;; error messages (define-constant ERR_NOT_DAO_OR_EXTENSION (err u6000)) -(define-constant ERR_UNKNOWN_ASSSET (err u6001)) -(define-constant ERR_PERIOD_ALREADY_CLAIMED (err u6002)) +(define-constant ERR_UNKNOWN_ASSET (err u6001)) +(define-constant ERR_FETCHING_ASSET (err u6002)) +(define-constant ERR_PERIOD_ALREADY_CLAIMED (err u6003)) ;; template variables ;; @@ -98,7 +101,7 @@ (define-public (deposit-ft (ft ) (amount uint)) (begin ;; no auth - anyone can deposit if token allowed - (asserts! (is-allowed-asset (contract-of ft)) ERR_UNKNOWN_ASSSET) + (asserts! (is-allowed-asset (contract-of ft)) ERR_UNKNOWN_ASSET) (print { notification: "treasury-deposit-ft", payload: { @@ -114,17 +117,17 @@ ) ;; transfer STX from treasury to operating fund -;; TODO - determine amount as 2% of balance (define-public (transfer-stx-to-operating-fund) (let ( - (amount u0) + (amount (unwrap-panic (get-stx-claim-amount))) ) (try! (is-dao-or-extension)) (try! (update-claim-stx)) (print { notification: "treasury-transfer-stx-to-operating-fund", payload: { + amount: amount, recipient: CFG_OPERATING_FUND, contractCaller: contract-caller, txSender: tx-sender, @@ -139,17 +142,17 @@ (let ( (assetContract (contract-of ft)) - (amount u0) + (amount (try! (get-ft-claim-amount ft))) ) (try! (is-dao-or-extension)) - (asserts! (is-allowed-asset assetContract) ERR_UNKNOWN_ASSSET) + (asserts! (is-allowed-asset assetContract) ERR_UNKNOWN_ASSET) (try! (update-claim-ft assetContract)) (print { notification: "treasury-transfer-ft-to-operating-fund", payload: { amount: amount, - assetContract: assetContract, recipient: CFG_OPERATING_FUND, + assetContract: assetContract, contractCaller: contract-caller, txSender: tx-sender, } @@ -159,19 +162,19 @@ ) ;; delegate STX for stacking -(define-public (delegate-stx (maxAmount uint) (to principal)) +(define-public (delegate-stx (maxAmount uint) (delegateTo principal)) (begin (try! (is-dao-or-extension)) (print { - notification: "delegate-stx", + notification: "treasury-delegate-stx", payload: { - amount: maxAmount, + maxAmount: maxAmount, + delegateTo: delegateTo, contractCaller: contract-caller, - delegate: to, txSender: tx-sender } }) - (match (as-contract (contract-call? 'SP000000000000000000002Q6VF78.pox-4 delegate-stx maxAmount to none none)) + (match (as-contract (contract-call? 'SP000000000000000000002Q6VF78.pox-4 delegate-stx maxAmount delegateTo none none)) success (ok success) err (err (to-uint err)) ) @@ -183,7 +186,7 @@ (begin (try! (is-dao-or-extension)) (print { - notification: "revoke-delegate-stx", + notification: "treasury-revoke-delegate-stx", payload: { contractCaller: contract-caller, txSender: tx-sender @@ -215,7 +218,7 @@ (map-get? StxClaims period) ) -(define-read-only (get-claim-ft (assetContract principal) (period uint)) +(define-read-only (get-claim-ft (period uint) (assetContract principal) ) (map-get? FtClaims { contract: assetContract, period: period }) ) @@ -234,14 +237,14 @@ periodLength: PERIOD_LENGTH, lastPeriod: { period: lastPeriod, - btcClaimed: (get-claim-ft CFG_SBTC_TOKEN lastPeriod), - daoClaimed: (get-claim-ft CFG_DAO_TOKEN lastPeriod), + btcClaimed: (get-claim-ft lastPeriod CFG_SBTC_TOKEN), + daoClaimed: (get-claim-ft lastPeriod CFG_DAO_TOKEN), stxClaimed: (get-claim-stx lastPeriod), }, currentPeriod: { period: currentPeriod, - btcClaimed: (get-claim-ft CFG_SBTC_TOKEN currentPeriod), - daoClaimed: (get-claim-ft CFG_DAO_TOKEN currentPeriod), + btcClaimed: (get-claim-ft currentPeriod CFG_SBTC_TOKEN), + daoClaimed: (get-claim-ft currentPeriod CFG_DAO_TOKEN), stxClaimed: (get-claim-stx currentPeriod), }, } @@ -277,6 +280,20 @@ ) ) +;; helper that will return 2% of the current balance for STX +(define-private (get-stx-claim-amount) + (let + ( + (balance (stx-get-balance SELF)) + (claimAmount (/ (* balance PERIOD_BPS) u10000)) + ) + (if (< claimAmount PERIOD_MIN_STX) + (ok PERIOD_MIN_STX) ;; 1 STX minimum + (ok claimAmount) ;; 2% of balance + ) + ) +) + ;; helper that will update the claim status for FT ;; and error if the period was already claimed (define-private (update-claim-ft (assetContract principal)) @@ -296,3 +313,22 @@ )) ) ) + +;; helper that will return 2% of the current balance for FT +(define-private (get-ft-claim-amount (ft )) + (let + ( + (balance (unwrap! (contract-call? ft get-balance SELF) ERR_FETCHING_ASSET)) + (decimals (unwrap! (contract-call? ft get-decimals) ERR_FETCHING_ASSET)) + (minAmount (if (is-eq (contract-of ft) CFG_SBTC_TOKEN) + PERIOD_MIN_BTC ;; 100 sats, specific to BTC + (pow u10 decimals) ;; 1 whole FT minimum otherwise + )) + (claimAmount (/ (* balance PERIOD_BPS) u10000)) + ) + (if (< claimAmount minAmount) + (ok minAmount) ;; 1 FT minimum + (ok claimAmount) ;; 2% of balance + ) + ) +) \ No newline at end of file From 0e87bcf9d107df7c34fd0e761752b8b650e73012 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 22 Apr 2025 13:06:33 -0700 Subject: [PATCH 10/17] fix: update trait to match treasury code --- contracts/dao/extensions/aibtc-treasury.clar | 2 +- contracts/dao/traits/aibtc-dao-traits-v3.clar | 27 +++---------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 68f8a29..b6eef56 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -1,6 +1,6 @@ ;; title: aibtc-treasury ;; version: 2.0.0 -;; summary: TBD +;; summary: A secure treasury contract that controls the funds of the DAO. ;; traits ;; diff --git a/contracts/dao/traits/aibtc-dao-traits-v3.clar b/contracts/dao/traits/aibtc-dao-traits-v3.clar index 2019ef2..9088a65 100644 --- a/contracts/dao/traits/aibtc-dao-traits-v3.clar +++ b/contracts/dao/traits/aibtc-dao-traits-v3.clar @@ -206,10 +206,6 @@ ;; @param enabled whether the asset is allowed ;; @returns (response bool uint) (allow-asset (principal bool) (response bool uint)) - ;; allow multiple assets for deposit/withdrawal - ;; @param allowList a list of asset contracts and enabled status - ;; @returns (response bool uint) - (allow-assets ((list 100 {token:principal,enabled:bool})) (response bool uint)) ;; deposit STX to the treasury ;; @param amount amount of microSTX to deposit ;; @returns (response bool uint) @@ -219,28 +215,13 @@ ;; @param amount amount of tokens to deposit ;; @returns (response bool uint) (deposit-ft ( uint) (response bool uint)) - ;; deposit NFT to the treasury - ;; @param nft the non-fungible token contract principal - ;; @param id the ID of the token to deposit - ;; @returns (response bool uint) - (deposit-nft ( uint) (response bool uint)) - ;; withdraw STX from the treasury - ;; @param amount amount of microSTX to withdraw - ;; @param recipient the recipient of the STX + ;; transfer STX from treasury to operating fund ;; @returns (response bool uint) - (withdraw-stx (uint) (response bool uint)) - ;; withdraw FT from the treasury + (transfer-stx-to-operating-fund () (response bool uint)) + ;; transfer FT from treasury to operating fund ;; @param ft the fungible token contract principal - ;; @param amount amount of tokens to withdraw - ;; @param recipient the recipient of the tokens - ;; @returns (response bool uint) - (withdraw-ft ( uint) (response bool uint)) - ;; withdraw NFT from the treasury - ;; @param nft the non-fungible token contract principal - ;; @param id the ID of the token to withdraw - ;; @param recipient the recipient of the token ;; @returns (response bool uint) - (withdraw-nft ( uint principal) (response bool uint)) + (transfer-ft-to-operating-fund () (response bool uint)) ;; delegate STX for stacking in PoX ;; @param amount max amount of microSTX that can be delegated ;; @param to the address to delegate to From fb00c9f50a1d9532201dc1be3fcf8fa972337493 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 22 Apr 2025 13:29:29 -0700 Subject: [PATCH 11/17] fix: update action contracts formatting to match other contracts Also updates error codes in prep for new extension, groups action errors with action proposals. --- ...ibtc-action-configure-timed-vault-dao.clar | 27 ++++++++++++++++--- ...btc-action-configure-timed-vault-sbtc.clar | 10 ++++--- ...ibtc-action-configure-timed-vault-stx.clar | 10 ++++--- .../aibtc-action-pmt-dao-add-resource.clar | 25 ++++++++++++++--- .../dao/extensions/aibtc-operating-fund.clar | 13 ++++++--- contracts/dao/extensions/aibtc-treasury.clar | 8 +++--- tests/error-codes.ts | 26 +++++++++++------- 7 files changed, 88 insertions(+), 31 deletions(-) diff --git a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-dao.clar b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-dao.clar index 93a647f..9f3d8eb 100644 --- a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-dao.clar +++ b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-dao.clar @@ -1,10 +1,26 @@ +;; title: aibtc-action-configure-timed-vault-dao +;; version: 1.0.0 +;; summary: A predefined action to configure the DAO timed vaults. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) -(define-constant CFG_MESSAGE "Executed Action Proposal: Updated configuration in <%= it.dao_token_name %> timed vault extension") +;; template variables +;; + +(define-constant CFG_MESSAGE "Executed Action Proposal: Updated configuration in DAO timed vault extension") + +;; public functions +;; (define-public (callback (sender principal) (memo (buff 34))) (ok true)) @@ -49,8 +65,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-sbtc.clar b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-sbtc.clar index 72f884c..03e26c6 100644 --- a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-sbtc.clar +++ b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-sbtc.clar @@ -1,8 +1,12 @@ +;; title: aibtc-action-configure-timed-vault-sbtc +;; version: 1.0.0 +;; summary: A predefined action to configure the BTC timed vaults. + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) (define-constant CFG_MESSAGE "Executed Action Proposal: Updated configuration in BTC timed vault extension") @@ -51,6 +55,6 @@ (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-stx.clar b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-stx.clar index dce93dd..a3579cd 100644 --- a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-stx.clar +++ b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-stx.clar @@ -1,8 +1,12 @@ +;; title: aibtc-action-configure-timed-vault-stx +;; version: 1.0.0 +;; summary: A predefined action to configure the STX timed vaults. + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) (define-constant CFG_MESSAGE "Executed Action Proposal: Updated configuration in STX timed vault extension") @@ -51,6 +55,6 @@ (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-pmt-dao-add-resource.clar b/contracts/dao/extensions/actions/aibtc-action-pmt-dao-add-resource.clar index e18b29f..45d9b56 100644 --- a/contracts/dao/extensions/actions/aibtc-action-pmt-dao-add-resource.clar +++ b/contracts/dao/extensions/actions/aibtc-action-pmt-dao-add-resource.clar @@ -1,11 +1,27 @@ +;; title: aibtc-action-pmt-dao-add-resource +;; version: 1.0.0 +;; summary: A predefined action to add a resource in the DAO payment processor extension. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) + +;; template variables +;; (define-constant CFG_MESSAGE "Executed Action Proposal: Added a resource in the DAO payment processor extension") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -22,8 +38,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/aibtc-operating-fund.clar b/contracts/dao/extensions/aibtc-operating-fund.clar index 75bc6ce..c4b6170 100644 --- a/contracts/dao/extensions/aibtc-operating-fund.clar +++ b/contracts/dao/extensions/aibtc-operating-fund.clar @@ -1,25 +1,32 @@ ;; title: aibtc-operating-fund ;; version: 2.0.0 -;; summary: TBD +;; summary: An operations fund for the dao with a 2% allocation of the total supply. +;; TODO - remove notes ;; this contract receives 2% of total supply at launch ;; this contract can receive DAO token, sBTC or STX from treasury ;; this contract can fund a timed vault when initialized ;; traits ;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.operating-fund) +(use-trait ft-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait) + ;; constants ;; +;; contract details (define-constant DEPLOYED_BURN_BLOCK burn-block-height) (define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) (define-constant SELF (as-contract tx-sender)) ;; error messages (define-constant ERR_NOT_DAO_OR_EXTENSION (err u9000)) ;; TBD/check +(define-constant ERR_UNKNOWN_ASSET (err u9001)) +(define-constant ERR_FETCHING_ASSET (err u9002)) ;; template variables ;; @@ -31,9 +38,7 @@ ;; public functions ;; -(define-public (callback (sender principal) (memo (buff 34))) - (ok true) -) +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) ;; read only functions ;; diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index b6eef56..9bf4684 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -4,16 +4,16 @@ ;; traits ;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.treasury) (use-trait ft-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait) -(use-trait nft-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait) ;; constants ;; -;; contract names +;; contract details (define-constant DEPLOYED_BURN_BLOCK burn-block-height) (define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) (define-constant SELF (as-contract tx-sender)) @@ -59,9 +59,7 @@ ;; public functions ;; -(define-public (callback (sender principal) (memo (buff 34))) - (ok true) -) +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) ;; add or update an asset to the allowed list (define-public (allow-asset (token principal) (enabled bool)) diff --git a/tests/error-codes.ts b/tests/error-codes.ts index ff767ef..fa92124 100644 --- a/tests/error-codes.ts +++ b/tests/error-codes.ts @@ -41,7 +41,7 @@ export enum ActionProposalsV2ErrCode { } export enum ActionErrCode { - ERR_UNAUTHORIZED = 10001, + ERR_UNAUTHORIZED = 1100, ERR_INVALID_PARAMS, } @@ -113,7 +113,9 @@ export enum PaymentProcessorErrCode { export enum TreasuryErrCode { ERR_NOT_DAO_OR_EXTENSION = 6000, - ERR_UNKNOWN_ASSSET, + ERR_UNKNOWN_ASSET, + ERR_FETCHING_ASSET, + ERR_PERIOD_ALREADY_CLAIMED, } export enum TokenOwnerErrCode { @@ -127,6 +129,19 @@ export enum DaoCharterErrCode { ERR_CHARTER_TOO_LONG, } +export enum UserAgentAccountErrCode { + ERR_UNAUTHORIZED = 9000, + ERR_UNKNOWN_ASSET, + ERR_OPERATION_FAILED, + ERR_BUY_SELL_NOT_ALLOWED, +} + +export enum OperatingFundErrCode { + ERR_NOT_DAO_OR_EXTENSION = 10000, + ERR_UNKNOWN_ASSET, + ERR_FETCHING_ASSET, +} + export enum TokenFaktoryErrCode { ERR_NOT_AUTHORIZED = 401, ERR_NOT_OWNER, @@ -141,10 +156,3 @@ export enum TokenFaktoryDexErrCode { ERR_FETCHING_SELL_INFO, ERR_TOKEN_NOT_AUTH = 401, } - -export enum UserAgentAccountErrCode { - ERR_UNAUTHORIZED = 9000, - ERR_UNKNOWN_ASSET, - ERR_OPERATION_FAILED, - ERR_BUY_SELL_NOT_ALLOWED, -} From 7802d5565b41b7bd7b22f6707dd2023514f7ae82 Mon Sep 17 00:00:00 2001 From: "Jason Schrader (aider)" Date: Tue, 22 Apr 2025 13:33:41 -0700 Subject: [PATCH 12/17] style: Standardize formatting for action contracts --- ...btc-action-configure-timed-vault-sbtc.clar | 15 +++++++++++ ...ibtc-action-configure-timed-vault-stx.clar | 15 +++++++++++ .../aibtc-action-pmt-dao-toggle-resource.clar | 25 ++++++++++++++++--- .../aibtc-action-pmt-sbtc-add-resource.clar | 25 ++++++++++++++++--- ...aibtc-action-pmt-sbtc-toggle-resource.clar | 25 ++++++++++++++++--- .../aibtc-action-pmt-stx-add-resource.clar | 25 ++++++++++++++++--- .../aibtc-action-pmt-stx-toggle-resource.clar | 25 ++++++++++++++++--- .../actions/aibtc-action-send-message.clar | 25 ++++++++++++++++--- .../aibtc-action-treasury-allow-asset.clar | 25 ++++++++++++++++--- 9 files changed, 184 insertions(+), 21 deletions(-) diff --git a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-sbtc.clar b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-sbtc.clar index 03e26c6..64e39d5 100644 --- a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-sbtc.clar +++ b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-sbtc.clar @@ -2,14 +2,26 @@ ;; version: 1.0.0 ;; summary: A predefined action to configure the BTC timed vaults. +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) +;; constants +;; + (define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) (define-constant ERR_INVALID_PARAMS (err u1101)) +;; template variables +;; + (define-constant CFG_MESSAGE "Executed Action Proposal: Updated configuration in BTC timed vault extension") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -53,6 +65,9 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION diff --git a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-stx.clar b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-stx.clar index a3579cd..bdd31cf 100644 --- a/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-stx.clar +++ b/contracts/dao/extensions/actions/aibtc-action-configure-timed-vault-stx.clar @@ -2,14 +2,26 @@ ;; version: 1.0.0 ;; summary: A predefined action to configure the STX timed vaults. +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) +;; constants +;; + (define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) (define-constant ERR_INVALID_PARAMS (err u1101)) +;; template variables +;; + (define-constant CFG_MESSAGE "Executed Action Proposal: Updated configuration in STX timed vault extension") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -53,6 +65,9 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION diff --git a/contracts/dao/extensions/actions/aibtc-action-pmt-dao-toggle-resource.clar b/contracts/dao/extensions/actions/aibtc-action-pmt-dao-toggle-resource.clar index 133b870..5ca2df5 100644 --- a/contracts/dao/extensions/actions/aibtc-action-pmt-dao-toggle-resource.clar +++ b/contracts/dao/extensions/actions/aibtc-action-pmt-dao-toggle-resource.clar @@ -1,11 +1,27 @@ +;; title: aibtc-action-pmt-dao-toggle-resource +;; version: 1.0.0 +;; summary: A predefined action to toggle a resource in the DAO payment processor extension. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) + +;; template variables +;; (define-constant CFG_MESSAGE "Executed Action Proposal: Toggled resource status by name in the DAO payment processor extension") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -19,8 +35,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-pmt-sbtc-add-resource.clar b/contracts/dao/extensions/actions/aibtc-action-pmt-sbtc-add-resource.clar index df9fe17..5a39d39 100644 --- a/contracts/dao/extensions/actions/aibtc-action-pmt-sbtc-add-resource.clar +++ b/contracts/dao/extensions/actions/aibtc-action-pmt-sbtc-add-resource.clar @@ -1,11 +1,27 @@ +;; title: aibtc-action-pmt-sbtc-add-resource +;; version: 1.0.0 +;; summary: A predefined action to add a resource in the BTC payment processor extension. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) + +;; template variables +;; (define-constant CFG_MESSAGE "Executed Action Proposal: Added a resource in the BTC payment processor extension") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -22,8 +38,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-pmt-sbtc-toggle-resource.clar b/contracts/dao/extensions/actions/aibtc-action-pmt-sbtc-toggle-resource.clar index 505d8c9..b50c74c 100644 --- a/contracts/dao/extensions/actions/aibtc-action-pmt-sbtc-toggle-resource.clar +++ b/contracts/dao/extensions/actions/aibtc-action-pmt-sbtc-toggle-resource.clar @@ -1,11 +1,27 @@ +;; title: aibtc-action-pmt-sbtc-toggle-resource +;; version: 1.0.0 +;; summary: A predefined action to toggle a resource in the BTC payment processor extension. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) + +;; template variables +;; (define-constant CFG_MESSAGE "Executed Action Proposal: Toggled resource status by name in the BTC payment processor extension") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -19,8 +35,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-pmt-stx-add-resource.clar b/contracts/dao/extensions/actions/aibtc-action-pmt-stx-add-resource.clar index baac0e9..1dd6aff 100644 --- a/contracts/dao/extensions/actions/aibtc-action-pmt-stx-add-resource.clar +++ b/contracts/dao/extensions/actions/aibtc-action-pmt-stx-add-resource.clar @@ -1,11 +1,27 @@ +;; title: aibtc-action-pmt-stx-add-resource +;; version: 1.0.0 +;; summary: A predefined action to add a resource in the STX payment processor extension. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) + +;; template variables +;; (define-constant CFG_MESSAGE "Executed Action Proposal: Added a resource in the STX payment processor extension") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -22,8 +38,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-pmt-stx-toggle-resource.clar b/contracts/dao/extensions/actions/aibtc-action-pmt-stx-toggle-resource.clar index 6372dcb..44b6c71 100644 --- a/contracts/dao/extensions/actions/aibtc-action-pmt-stx-toggle-resource.clar +++ b/contracts/dao/extensions/actions/aibtc-action-pmt-stx-toggle-resource.clar @@ -1,11 +1,27 @@ +;; title: aibtc-action-pmt-stx-toggle-resource +;; version: 1.0.0 +;; summary: A predefined action to toggle a resource in the STX payment processor extension. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) + +;; template variables +;; (define-constant CFG_MESSAGE "Executed Action Proposal: Toggled resource status by name in the STX payment processor extension") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -19,8 +35,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-send-message.clar b/contracts/dao/extensions/actions/aibtc-action-send-message.clar index d264728..e9528b1 100644 --- a/contracts/dao/extensions/actions/aibtc-action-send-message.clar +++ b/contracts/dao/extensions/actions/aibtc-action-send-message.clar @@ -1,8 +1,24 @@ +;; title: aibtc-action-send-message +;; version: 1.0.0 +;; summary: A predefined action to send a message through the onchain messaging system. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) + +;; template variables +;; + +;; public functions +;; (define-public (callback (sender principal) (memo (buff 34))) (ok true)) @@ -16,8 +32,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-treasury-allow-asset.clar b/contracts/dao/extensions/actions/aibtc-action-treasury-allow-asset.clar index 740fdff..7fd1521 100644 --- a/contracts/dao/extensions/actions/aibtc-action-treasury-allow-asset.clar +++ b/contracts/dao/extensions/actions/aibtc-action-treasury-allow-asset.clar @@ -1,11 +1,27 @@ +;; title: aibtc-action-treasury-allow-asset +;; version: 1.0.0 +;; summary: A predefined action to allow or enable an asset for use in the treasury. + +;; traits +;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.action) -(define-constant ERR_UNAUTHORIZED (err u10001)) -(define-constant ERR_INVALID_PARAMS (err u10002)) +;; constants +;; + +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) +(define-constant ERR_INVALID_PARAMS (err u1101)) + +;; template variables +;; (define-constant CFG_MESSAGE "Executed Action Proposal: Allowed or enabled asset for use in the treasury") +;; public functions +;; + (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) @@ -19,8 +35,11 @@ ) ) +;; private functions +;; + (define-private (is-dao-or-extension) (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION )) ) From d36eac0870051172de2fc72fed985430488bf34d Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 22 Apr 2025 15:27:49 -0700 Subject: [PATCH 13/17] fix: small changes --- .../dao/extensions/actions/aibtc-action-send-message.clar | 3 --- .../extensions/actions/aibtc-action-treasury-allow-asset.clar | 2 +- contracts/dao/extensions/aibtc-treasury.clar | 3 ++- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/contracts/dao/extensions/actions/aibtc-action-send-message.clar b/contracts/dao/extensions/actions/aibtc-action-send-message.clar index e9528b1..fa4e47d 100644 --- a/contracts/dao/extensions/actions/aibtc-action-send-message.clar +++ b/contracts/dao/extensions/actions/aibtc-action-send-message.clar @@ -14,9 +14,6 @@ (define-constant ERR_NOT_DAO_OR_EXTENSION (err u1100)) (define-constant ERR_INVALID_PARAMS (err u1101)) -;; template variables -;; - ;; public functions ;; diff --git a/contracts/dao/extensions/actions/aibtc-action-treasury-allow-asset.clar b/contracts/dao/extensions/actions/aibtc-action-treasury-allow-asset.clar index 7fd1521..cbf45cf 100644 --- a/contracts/dao/extensions/actions/aibtc-action-treasury-allow-asset.clar +++ b/contracts/dao/extensions/actions/aibtc-action-treasury-allow-asset.clar @@ -17,7 +17,7 @@ ;; template variables ;; -(define-constant CFG_MESSAGE "Executed Action Proposal: Allowed or enabled asset for use in the treasury") +(define-constant CFG_MESSAGE "Executed Action Proposal: Allowed or updated asset for use in the treasury") ;; public functions ;; diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 9bf4684..1e4111e 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -47,6 +47,7 @@ (define-map AllowedAssets principal bool) ;; track transfers per period +;; TODO - track amount instead of bool? (define-map StxClaims uint ;; period bool ;; claimed @@ -329,4 +330,4 @@ (ok claimAmount) ;; 2% of balance ) ) -) \ No newline at end of file +) From 4eca2da5654b33a570364c77099269f245500c42 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Wed, 23 Apr 2025 11:46:26 -0700 Subject: [PATCH 14/17] fix: create dao-registry from common patterns Should help with a few checks we're doing in separate contracts. --- Clarinet.toml | 15 ++-- .../dao/extensions/aibtc-dao-registry.clar | 86 +++++++++++++++++++ .../dao/extensions/aibtc-operating-fund.clar | 20 ++++- contracts/dao/extensions/aibtc-treasury.clar | 18 ++-- tests/error-codes.ts | 4 + 5 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 contracts/dao/extensions/aibtc-dao-registry.clar diff --git a/Clarinet.toml b/Clarinet.toml index d8b1e58..95b5c0e 100644 --- a/Clarinet.toml +++ b/Clarinet.toml @@ -83,11 +83,6 @@ path = 'contracts/dao/extensions/aibtc-action-proposals-v2.clar' clarity_version = 3 epoch = 3.1 -[contracts.aibtc-dao-charter] -path = 'contracts/dao/extensions/aibtc-dao-charter.clar' -clarity_version = 3 -epoch = 3.1 - [contracts.aibtc-core-proposals] path = 'contracts/dao/extensions/aibtc-core-proposals.clar' clarity_version = 2 @@ -98,6 +93,16 @@ path = 'contracts/dao/extensions/aibtc-core-proposals-v2.clar' clarity_version = 3 epoch = 3.1 +[contracts.aibtc-dao-charter] +path = 'contracts/dao/extensions/aibtc-dao-charter.clar' +clarity_version = 3 +epoch = 3.1 + +[contracts.aibtc-dao-registry] +path = 'contracts/dao/extensions/aibtc-dao-registry.clar' +clarity_version = 3 +epoch = 3.1 + [contracts.aibtc-onchain-messaging] path = 'contracts/dao/extensions/aibtc-onchain-messaging.clar' clarity_version = 3 diff --git a/contracts/dao/extensions/aibtc-dao-registry.clar b/contracts/dao/extensions/aibtc-dao-registry.clar new file mode 100644 index 0000000..ceb9408 --- /dev/null +++ b/contracts/dao/extensions/aibtc-dao-registry.clar @@ -0,0 +1,86 @@ +;; title: aibtc-operating-fund +;; version: 1.0.0 +;; summary: A registry for the DAO that tracks common values used by DAO contracts. + +;; TODO - remove notes +;; tracks current epoch since deployment +;; tracks allowed assets within the dao +;; tracks users that interact at the dao level + +;; traits +;; + +(impl-trait .aibtc-dao-traits-v3.extension) +;; TODO - add dao-registry trait +;; (impl-trait .aibtc-dao-traits-v3.dao-registry) + +;; constants +;; + +;; contract details +(define-constant DEPLOYED_BURN_BLOCK burn-block-height) +(define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) +(define-constant SELF (as-contract tx-sender)) + +;; track epochs by BTC block height +(define-constant EPOCH_LENGTH u4320) ;; 30 days in BTC blocks + +;; error messages +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u11000)) + +;; template variables +;; +;; /g/find/replace + +;; data maps +;; + +;; track allowed assets for use with the DAO +(define-map AllowedAssetContracts principal bool) + +;; public functions +;; + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +;; enable or disable asset on the allowed list +(define-public (configure-dao-asset (assetContract principal) (enabled bool)) + (begin + (try! (is-dao-or-extension)) + (print { + notification: "dao-registry-configure-dao-asset", + payload: { + assetContract: assetContract, + enabled: enabled, + contractCaller: contract-caller, + txSender: tx-sender + } + }) + (ok (map-set AllowedAssetContracts assetContract enabled)) + ) +) + +;; read only functions +;; + +;; returns ok if the caller is the DAO or an extension or err if not +(define-read-only (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION + )) +) + +;; returns boolean if the asset is allowed +(define-read-only (is-allowed-asset (assetContract principal)) + (default-to false (get-allowed-asset assetContract)) +) + +;; returns (some boolean) if the asset is registered or none if unknown +(define-read-only (get-allowed-asset (assetContract principal)) + (map-get? AllowedAssetContracts assetContract) +) + +;; returns the current epoch since deployment +(define-read-only (get-current-dao-epoch) + (/ (- burn-block-height DEPLOYED_BURN_BLOCK) EPOCH_LENGTH) +) diff --git a/contracts/dao/extensions/aibtc-operating-fund.clar b/contracts/dao/extensions/aibtc-operating-fund.clar index c4b6170..782efe2 100644 --- a/contracts/dao/extensions/aibtc-operating-fund.clar +++ b/contracts/dao/extensions/aibtc-operating-fund.clar @@ -24,9 +24,9 @@ (define-constant SELF (as-contract tx-sender)) ;; error messages -(define-constant ERR_NOT_DAO_OR_EXTENSION (err u9000)) ;; TBD/check -(define-constant ERR_UNKNOWN_ASSET (err u9001)) -(define-constant ERR_FETCHING_ASSET (err u9002)) +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u10000)) +(define-constant ERR_UNKNOWN_ASSET (err u10001)) +(define-constant ERR_FETCHING_ASSET (err u10002)) ;; template variables ;; @@ -35,6 +35,20 @@ ;; data maps ;; +;; track allowed assets for deposit/transfer +(define-map AllowedAssets principal bool) + +;; track transfers per period +;; TODO - track amount instead of bool? +(define-map StxClaims + uint ;; period + uint ;; claimed amount +) +(define-map FtClaims + { contract: principal, period: uint } + uint ;; claimed amount +) + ;; public functions ;; diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 1e4111e..3bb0d83 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -47,14 +47,13 @@ (define-map AllowedAssets principal bool) ;; track transfers per period -;; TODO - track amount instead of bool? (define-map StxClaims uint ;; period - bool ;; claimed + uint ;; claimed amount ) (define-map FtClaims { contract: principal, period: uint } - bool ;; claimed + uint ;; claimed amount ) ;; public functions @@ -122,7 +121,7 @@ (amount (unwrap-panic (get-stx-claim-amount))) ) (try! (is-dao-or-extension)) - (try! (update-claim-stx)) + (try! (update-claim-stx amount)) (print { notification: "treasury-transfer-stx-to-operating-fund", payload: { @@ -145,7 +144,7 @@ ) (try! (is-dao-or-extension)) (asserts! (is-allowed-asset assetContract) ERR_UNKNOWN_ASSET) - (try! (update-claim-ft assetContract)) + (try! (update-claim-ft amount assetContract)) (print { notification: "treasury-transfer-ft-to-operating-fund", payload: { @@ -221,6 +220,7 @@ (map-get? FtClaims { contract: assetContract, period: period }) ) +;; TODO: consider splitting dynamic/static info, easier to cache on client side (define-read-only (get-contract-info) (let ( @@ -261,7 +261,7 @@ ;; helper that will update the claim status for STX ;; and error if the period was already claimed -(define-private (update-claim-stx) +(define-private (update-claim-stx (amount uint)) (begin (print { notification: "treasury-update-claim-stx", @@ -273,7 +273,7 @@ } }) (ok (asserts! - (map-insert StxClaims (get-current-period) true) + (map-insert StxClaims (get-current-period) amount) ERR_PERIOD_ALREADY_CLAIMED )) ) @@ -295,7 +295,7 @@ ;; helper that will update the claim status for FT ;; and error if the period was already claimed -(define-private (update-claim-ft (assetContract principal)) +(define-private (update-claim-ft (amount uint) (assetContract principal)) (begin (print { notification: "treasury-update-claim-ft", @@ -307,7 +307,7 @@ } }) (ok (asserts! - (map-insert FtClaims { contract: contract-caller, period: (get-current-period) } true) + (map-insert FtClaims { contract: contract-caller, period: (get-current-period) } amount) ERR_PERIOD_ALREADY_CLAIMED )) ) diff --git a/tests/error-codes.ts b/tests/error-codes.ts index fa92124..c27b762 100644 --- a/tests/error-codes.ts +++ b/tests/error-codes.ts @@ -142,6 +142,10 @@ export enum OperatingFundErrCode { ERR_FETCHING_ASSET, } +export enum DaoRegistryErrCode { + ERR_NOT_DAO_OR_EXTENSION = 11000, +} + export enum TokenFaktoryErrCode { ERR_NOT_AUTHORIZED = 401, ERR_NOT_OWNER, From b9dfd20825f156a7430d9c37541e1a38c7ed088e Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Wed, 23 Apr 2025 16:52:06 -0700 Subject: [PATCH 15/17] feat: test out dao-registry with operating-fund --- contracts/dao/extensions/aibtc-dao-registry.clar | 5 +++++ .../dao/extensions/aibtc-operating-fund.clar | 15 ++++++++------- contracts/dao/extensions/aibtc-treasury.clar | 13 +++++++------ 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/contracts/dao/extensions/aibtc-dao-registry.clar b/contracts/dao/extensions/aibtc-dao-registry.clar index ceb9408..069bcf0 100644 --- a/contracts/dao/extensions/aibtc-dao-registry.clar +++ b/contracts/dao/extensions/aibtc-dao-registry.clar @@ -84,3 +84,8 @@ (define-read-only (get-current-dao-epoch) (/ (- burn-block-height DEPLOYED_BURN_BLOCK) EPOCH_LENGTH) ) + +;; returns the epoch length +(define-read-only (get-dao-epoch-length) + EPOCH_LENGTH +) \ No newline at end of file diff --git a/contracts/dao/extensions/aibtc-operating-fund.clar b/contracts/dao/extensions/aibtc-operating-fund.clar index 782efe2..a27bbd4 100644 --- a/contracts/dao/extensions/aibtc-operating-fund.clar +++ b/contracts/dao/extensions/aibtc-operating-fund.clar @@ -18,15 +18,19 @@ ;; constants ;; +;; error messages +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u10000)) +(define-constant ERR_UNKNOWN_ASSET (err u10001)) +(define-constant ERR_FETCHING_ASSET (err u10002)) + ;; contract details (define-constant DEPLOYED_BURN_BLOCK burn-block-height) (define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) (define-constant SELF (as-contract tx-sender)) -;; error messages -(define-constant ERR_NOT_DAO_OR_EXTENSION (err u10000)) -(define-constant ERR_UNKNOWN_ASSET (err u10001)) -(define-constant ERR_FETCHING_ASSET (err u10002)) +;; track epochs by BTC block height +(define-constant EPOCH_BPS u5000) ;; 50% of own supply +(define-constant EPOCH_BPS_DIVISOR u10000) ;; 10000 BP = 100% ;; template variables ;; @@ -35,9 +39,6 @@ ;; data maps ;; -;; track allowed assets for deposit/transfer -(define-map AllowedAssets principal bool) - ;; track transfers per period ;; TODO - track amount instead of bool? (define-map StxClaims diff --git a/contracts/dao/extensions/aibtc-treasury.clar b/contracts/dao/extensions/aibtc-treasury.clar index 3bb0d83..a0a1426 100644 --- a/contracts/dao/extensions/aibtc-treasury.clar +++ b/contracts/dao/extensions/aibtc-treasury.clar @@ -13,6 +13,12 @@ ;; constants ;; +;; error messages +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u6000)) +(define-constant ERR_UNKNOWN_ASSET (err u6001)) +(define-constant ERR_FETCHING_ASSET (err u6002)) +(define-constant ERR_PERIOD_ALREADY_CLAIMED (err u6003)) + ;; contract details (define-constant DEPLOYED_BURN_BLOCK burn-block-height) (define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) @@ -20,16 +26,11 @@ ;; track periods by BTC block height (define-constant PERIOD_BPS u200) ;; 2% of own supply +(define-constant PERIOD_BPS_DIVISOR u10000) ;; 10000 BP = 100% (define-constant PERIOD_LENGTH u4320) ;; 30 days in BTC blocks (define-constant PERIOD_MIN_BTC u100) ;; 0.00000100 BTC or 100 sats (8 decimals) (define-constant PERIOD_MIN_STX u1000000) ;; 1 STX (6 decimals) -;; error messages -(define-constant ERR_NOT_DAO_OR_EXTENSION (err u6000)) -(define-constant ERR_UNKNOWN_ASSET (err u6001)) -(define-constant ERR_FETCHING_ASSET (err u6002)) -(define-constant ERR_PERIOD_ALREADY_CLAIMED (err u6003)) - ;; template variables ;; From 49d5817dffb54a9727c9b5203aeda9bf104dec52 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Thu, 24 Apr 2025 06:39:48 -0700 Subject: [PATCH 16/17] fix: add user tracking features Considering splitting this into three distinct contracts with a specific purpose. --- .../dao/extensions/aibtc-dao-registry.clar | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/contracts/dao/extensions/aibtc-dao-registry.clar b/contracts/dao/extensions/aibtc-dao-registry.clar index 069bcf0..b2ffda7 100644 --- a/contracts/dao/extensions/aibtc-dao-registry.clar +++ b/contracts/dao/extensions/aibtc-dao-registry.clar @@ -32,12 +32,28 @@ ;; ;; /g/find/replace +;; data vars +;; + +(define-data-var userCount uint u0) ;; total number of users + ;; data maps ;; -;; track allowed assets for use with the DAO +;; central tracking for DAO allowed assets (define-map AllowedAssetContracts principal bool) +;; central tracking for DAO users +(define-map UserIndexes principal uint) +(define-map UserData + uint ;; user index + { + address: principal, + createdAt: uint, + reputation: uint, ;; increases/decreases from proposals + } +) + ;; public functions ;; @@ -60,6 +76,10 @@ ) ) +(define-public (get-or-create-user (address principal)) + (ok true) +) + ;; read only functions ;; @@ -80,7 +100,7 @@ (map-get? AllowedAssetContracts assetContract) ) -;; returns the current epoch since deployment +;; returns the current epoch based on deployed burn block (define-read-only (get-current-dao-epoch) (/ (- burn-block-height DEPLOYED_BURN_BLOCK) EPOCH_LENGTH) ) @@ -88,4 +108,24 @@ ;; returns the epoch length (define-read-only (get-dao-epoch-length) EPOCH_LENGTH -) \ No newline at end of file +) + +;; returns the unique user count +(define-read-only (get-user-count) + (var-get userCount) +) + +;; returns (some data) if the user exists or none if unknown +(define-read-only (get-user-index (address principal)) + (map-get? UserIndexes address) +) + +;; returns (some data) if the user exists or none if unknown +(define-read-only (get-user-data-by-index (userIndex uint)) + (map-get? UserData userIndex) +) + +;; returns (some data) if the user exists or none if unknown +(define-read-only (get-user-data-by-address (address principal)) + (get-user-data-by-index (unwrap! (get-user-index address) none)) +) From 191aac2cdb6168e0010d04a6fe38e00582c10d60 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Thu, 24 Apr 2025 06:56:08 -0700 Subject: [PATCH 17/17] fix: split registry into individual contracts --- Clarinet.toml | 14 +- .../dao/extensions/aibtc-dao-assets.clar | 71 ++++++++++ .../dao/extensions/aibtc-dao-charter.clar | 16 ++- contracts/dao/extensions/aibtc-dao-epoch.clar | 38 +++++ .../dao/extensions/aibtc-dao-registry.clar | 131 ------------------ contracts/dao/extensions/aibtc-dao-users.clar | 85 ++++++++++++ 6 files changed, 216 insertions(+), 139 deletions(-) create mode 100644 contracts/dao/extensions/aibtc-dao-assets.clar create mode 100644 contracts/dao/extensions/aibtc-dao-epoch.clar delete mode 100644 contracts/dao/extensions/aibtc-dao-registry.clar create mode 100644 contracts/dao/extensions/aibtc-dao-users.clar diff --git a/Clarinet.toml b/Clarinet.toml index 95b5c0e..5822f23 100644 --- a/Clarinet.toml +++ b/Clarinet.toml @@ -98,8 +98,18 @@ path = 'contracts/dao/extensions/aibtc-dao-charter.clar' clarity_version = 3 epoch = 3.1 -[contracts.aibtc-dao-registry] -path = 'contracts/dao/extensions/aibtc-dao-registry.clar' +[contracts.aibtc-dao-epoch] +path = 'contracts/dao/extensions/aibtc-dao-epoch.clar' +clarity_version = 3 +epoch = 3.1 + +[contracts.aibtc-dao-assets] +path = 'contracts/dao/extensions/aibtc-dao-assets.clar' +clarity_version = 3 +epoch = 3.1 + +[contracts.aibtc-dao-users] +path = 'contracts/dao/extensions/aibtc-dao-users.clar' clarity_version = 3 epoch = 3.1 diff --git a/contracts/dao/extensions/aibtc-dao-assets.clar b/contracts/dao/extensions/aibtc-dao-assets.clar new file mode 100644 index 0000000..fe34872 --- /dev/null +++ b/contracts/dao/extensions/aibtc-dao-assets.clar @@ -0,0 +1,71 @@ +;; title: aibtc-dao-assets +;; version: 1.0.0 +;; summary: An extension that tracks the allowed asset contracts for the DAO. + +;; traits +;; + +(impl-trait .aibtc-dao-traits-v3.extension) +;; TODO - add dao-assets trait (impl-trait .aibtc-dao-traits-v3.dao-assets) + +;; constants +;; + +;; contract details +(define-constant DEPLOYED_BURN_BLOCK burn-block-height) +(define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) +(define-constant SELF (as-contract tx-sender)) + +;; error messages +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u8200)) ;; similar to dao-charter + +;; data maps +;; + +;; central tracking for DAO allowed assets +(define-map AllowedAssetContracts principal bool) + +;; public functions +;; + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +;; enable or disable asset on the allowed list +(define-public (configure-dao-asset (assetContract principal) (enabled bool)) + (begin + (try! (is-dao-or-extension)) + (print { + notification: "dao-assets-configure-dao-asset", + payload: { + assetContract: assetContract, + enabled: enabled, + contractCaller: contract-caller, + txSender: tx-sender + } + }) + (ok (map-set AllowedAssetContracts assetContract enabled)) + ) +) + +;; read only functions +;; + +;; returns boolean if the asset is allowed +(define-read-only (is-allowed-asset (assetContract principal)) + (default-to false (get-allowed-asset assetContract)) +) + +;; returns (some boolean) if the asset is registered or none if unknown +(define-read-only (get-allowed-asset (assetContract principal)) + (map-get? AllowedAssetContracts assetContract) +) + +;; private functions +;; + +;; returns ok if the caller is the DAO or an extension or err if not +(define-private (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION + )) +) \ No newline at end of file diff --git a/contracts/dao/extensions/aibtc-dao-charter.clar b/contracts/dao/extensions/aibtc-dao-charter.clar index 5ea9179..714e2ae 100644 --- a/contracts/dao/extensions/aibtc-dao-charter.clar +++ b/contracts/dao/extensions/aibtc-dao-charter.clar @@ -1,16 +1,19 @@ ;; 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. -;; description: This contract allows the DAO to define its mission and values on-chain, which can be used to guide decision-making and proposals. -;; The charter is editable by the DAO through proposal with revisions stored on-chain. ;; traits ;; + (impl-trait .aibtc-dao-traits-v3.extension) (impl-trait .aibtc-dao-traits-v3.charter) ;; constants ;; + +;; contract details +(define-constant DEPLOYED_BURN_BLOCK burn-block-height) +(define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) (define-constant SELF (as-contract tx-sender)) ;; error codes @@ -21,11 +24,13 @@ ;; data vars ;; + (define-data-var daoCharter (string-ascii 4096) "") (define-data-var currentVersion uint u0) ;; data maps ;; + (define-map CharterVersions uint ;; version number { @@ -40,9 +45,8 @@ ;; public functions ;; -(define-public (callback (sender principal) (memo (buff 34))) - (ok true) -) + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (set-dao-charter (charter (string-ascii 4096)) (inscriptionId (optional (buff 33)))) (let @@ -65,7 +69,7 @@ }) ERR_SAVING_CHARTER) ;; print charter info (print { - notification: "set-dao-charter", + notification: "dao-charter-set-dao-charter", payload: { burnHeight: burn-block-height, createdAt: stacks-block-height, diff --git a/contracts/dao/extensions/aibtc-dao-epoch.clar b/contracts/dao/extensions/aibtc-dao-epoch.clar new file mode 100644 index 0000000..1e24b2b --- /dev/null +++ b/contracts/dao/extensions/aibtc-dao-epoch.clar @@ -0,0 +1,38 @@ +;; title: aibtc-dao-epoch +;; version: 1.0.0 +;; summary: An extension that tracks the current epoch of the DAO. + +;; traits +;; + +(impl-trait .aibtc-dao-traits-v3.extension) +;; TODO - add dao-epoch trait (impl-trait .aibtc-dao-traits-v3.dao-epoch) + +;; constants +;; + +;; contract details +(define-constant DEPLOYED_BURN_BLOCK burn-block-height) +(define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) +(define-constant SELF (as-contract tx-sender)) + +;; track epochs by BTC block height +(define-constant EPOCH_LENGTH u4320) ;; 30 days in BTC blocks + +;; public functions +;; + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +;; read only functions +;; + +;; returns the current epoch based on deployed burn block +(define-read-only (get-current-dao-epoch) + (/ (- burn-block-height DEPLOYED_BURN_BLOCK) EPOCH_LENGTH) +) + +;; returns the epoch length +(define-read-only (get-dao-epoch-length) + EPOCH_LENGTH +) diff --git a/contracts/dao/extensions/aibtc-dao-registry.clar b/contracts/dao/extensions/aibtc-dao-registry.clar deleted file mode 100644 index b2ffda7..0000000 --- a/contracts/dao/extensions/aibtc-dao-registry.clar +++ /dev/null @@ -1,131 +0,0 @@ -;; title: aibtc-operating-fund -;; version: 1.0.0 -;; summary: A registry for the DAO that tracks common values used by DAO contracts. - -;; TODO - remove notes -;; tracks current epoch since deployment -;; tracks allowed assets within the dao -;; tracks users that interact at the dao level - -;; traits -;; - -(impl-trait .aibtc-dao-traits-v3.extension) -;; TODO - add dao-registry trait -;; (impl-trait .aibtc-dao-traits-v3.dao-registry) - -;; constants -;; - -;; contract details -(define-constant DEPLOYED_BURN_BLOCK burn-block-height) -(define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) -(define-constant SELF (as-contract tx-sender)) - -;; track epochs by BTC block height -(define-constant EPOCH_LENGTH u4320) ;; 30 days in BTC blocks - -;; error messages -(define-constant ERR_NOT_DAO_OR_EXTENSION (err u11000)) - -;; template variables -;; -;; /g/find/replace - -;; data vars -;; - -(define-data-var userCount uint u0) ;; total number of users - -;; data maps -;; - -;; central tracking for DAO allowed assets -(define-map AllowedAssetContracts principal bool) - -;; central tracking for DAO users -(define-map UserIndexes principal uint) -(define-map UserData - uint ;; user index - { - address: principal, - createdAt: uint, - reputation: uint, ;; increases/decreases from proposals - } -) - -;; public functions -;; - -(define-public (callback (sender principal) (memo (buff 34))) (ok true)) - -;; enable or disable asset on the allowed list -(define-public (configure-dao-asset (assetContract principal) (enabled bool)) - (begin - (try! (is-dao-or-extension)) - (print { - notification: "dao-registry-configure-dao-asset", - payload: { - assetContract: assetContract, - enabled: enabled, - contractCaller: contract-caller, - txSender: tx-sender - } - }) - (ok (map-set AllowedAssetContracts assetContract enabled)) - ) -) - -(define-public (get-or-create-user (address principal)) - (ok true) -) - -;; read only functions -;; - -;; returns ok if the caller is the DAO or an extension or err if not -(define-read-only (is-dao-or-extension) - (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) - (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION - )) -) - -;; returns boolean if the asset is allowed -(define-read-only (is-allowed-asset (assetContract principal)) - (default-to false (get-allowed-asset assetContract)) -) - -;; returns (some boolean) if the asset is registered or none if unknown -(define-read-only (get-allowed-asset (assetContract principal)) - (map-get? AllowedAssetContracts assetContract) -) - -;; returns the current epoch based on deployed burn block -(define-read-only (get-current-dao-epoch) - (/ (- burn-block-height DEPLOYED_BURN_BLOCK) EPOCH_LENGTH) -) - -;; returns the epoch length -(define-read-only (get-dao-epoch-length) - EPOCH_LENGTH -) - -;; returns the unique user count -(define-read-only (get-user-count) - (var-get userCount) -) - -;; returns (some data) if the user exists or none if unknown -(define-read-only (get-user-index (address principal)) - (map-get? UserIndexes address) -) - -;; returns (some data) if the user exists or none if unknown -(define-read-only (get-user-data-by-index (userIndex uint)) - (map-get? UserData userIndex) -) - -;; returns (some data) if the user exists or none if unknown -(define-read-only (get-user-data-by-address (address principal)) - (get-user-data-by-index (unwrap! (get-user-index address) none)) -) diff --git a/contracts/dao/extensions/aibtc-dao-users.clar b/contracts/dao/extensions/aibtc-dao-users.clar new file mode 100644 index 0000000..e1d61af --- /dev/null +++ b/contracts/dao/extensions/aibtc-dao-users.clar @@ -0,0 +1,85 @@ +;; title: aibtc-dao-users +;; version: 1.0.0 +;; summary: An extension that tracks the current users and their reputation in the DAO. + +;; traits +;; + +(impl-trait .aibtc-dao-traits-v3.extension) +;; TODO - add dao-users trait (impl-trait .aibtc-dao-traits-v3.dao-users) + +;; constants +;; + +;; contract details +(define-constant DEPLOYED_BURN_BLOCK burn-block-height) +(define-constant DEPLOYED_STACKS_BLOCK stacks-block-height) +(define-constant SELF (as-contract tx-sender)) + +;; error messages +(define-constant ERR_NOT_DAO_OR_EXTENSION (err u8100)) ;; similar to dao-charter + +;; data vars +;; + +(define-data-var userCount uint u0) ;; total number of users + +;; data maps +;; + +;; central tracking for DAO users +(define-map UserIndexes principal uint) +(define-map UserData + uint ;; user index + { + address: principal, + createdAt: uint, + reputation: int, ;; increases/decreases from proposal bonds + } +) + +;; public functions +;; + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +(define-public (get-or-create-user (address principal)) + (ok true) +) + +(define-public (update-user-reputation (address principal) (amount int)) + (ok true) +) + +;; read only functions +;; + +;; returns the unique user count +(define-read-only (get-user-count) + (var-get userCount) +) + +;; returns (some data) if the user exists or none if unknown +(define-read-only (get-user-index (address principal)) + (map-get? UserIndexes address) +) + +;; returns (some data) if the user exists or none if unknown +(define-read-only (get-user-data-by-index (userIndex uint)) + (map-get? UserData userIndex) +) + +;; returns (some data) if the user exists or none if unknown +(define-read-only (get-user-data-by-address (address principal)) + (get-user-data-by-index (unwrap! (get-user-index address) none)) +) + +;; private functions +;; + +;; returns ok if the caller is the DAO or an extension or err if not +(define-private (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtc-base-dao) + (contract-call? .aibtc-base-dao is-extension contract-caller)) ERR_NOT_DAO_OR_EXTENSION + )) +) \ No newline at end of file