From d6b4121900f6047abe6704f61f5d0a2d836b3c4b Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 07:19:33 -0700 Subject: [PATCH 1/3] feat: add all v1 actions as contracts --- Clarinet.toml | 25 +++++++++++++++++ .../actions/aibtc-action-add-resource.clar | 26 ++++++++++++++++++ .../actions/aibtc-action-allow-asset.clar | 20 ++++++++++++++ .../actions/aibtc-action-send-message.clar | 2 +- .../aibtc-action-set-account-holder.clar | 2 +- .../aibtc-action-set-withdrawal-amount.clar | 27 +++++++++++++++++++ .../aibtc-action-set-withdrawal-period.clar | 27 +++++++++++++++++++ .../aibtc-action-toggle-resource-by-name.clar | 20 ++++++++++++++ 8 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 contracts/dao/extensions/actions/aibtc-action-add-resource.clar create mode 100644 contracts/dao/extensions/actions/aibtc-action-allow-asset.clar create mode 100644 contracts/dao/extensions/actions/aibtc-action-set-withdrawal-amount.clar create mode 100644 contracts/dao/extensions/actions/aibtc-action-set-withdrawal-period.clar create mode 100644 contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar diff --git a/Clarinet.toml b/Clarinet.toml index 089074c..fc59880 100644 --- a/Clarinet.toml +++ b/Clarinet.toml @@ -110,6 +110,16 @@ epoch = 3.0 # dao actions (as extensions) +[contracts.aibtc-action-add-resource] +path = 'contracts/dao/extensions/actions/aibtc-action-add-resource.clar' +clarity_version = 2 +epoch = 3.0 + +[contracts.aibtc-action-allow-asset] +path = 'contracts/dao/extensions/actions/aibtc-action-allow-asset.clar' +clarity_version = 2 +epoch = 3.0 + [contracts.aibtc-action-send-message] path = 'contracts/dao/extensions/actions/aibtc-action-send-message.clar' clarity_version = 2 @@ -120,6 +130,21 @@ path = 'contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar' clarity_version = 2 epoch = 3.0 +[contracts.aibtc-action-set-withdrawal-amount] +path = 'contracts/dao/extensions/actions/aibtc-action-set-withdrawal-amount.clar' +clarity_version = 2 +epoch = 3.0 + +[contracts.aibtc-action-set-withdrawal-period] +path = 'contracts/dao/extensions/actions/aibtc-action-set-withdrawal-period.clar' +clarity_version = 2 +epoch = 3.0 + +[contracts.aibtc-action-toggle-resource-by-name] +path = 'contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar' +clarity_version = 2 +epoch = 3.0 + # dao proposals [contracts.aibtc-bank-account-deposit-stx] diff --git a/contracts/dao/extensions/actions/aibtc-action-add-resource.clar b/contracts/dao/extensions/actions/aibtc-action-add-resource.clar new file mode 100644 index 0000000..8737dd8 --- /dev/null +++ b/contracts/dao/extensions/actions/aibtc-action-add-resource.clar @@ -0,0 +1,26 @@ +(impl-trait .aibtcdev-dao-traits-v1.extension) +(impl-trait .aibtcdev-dao-traits-v1.action) + +(define-constant ERR_UNAUTHORIZED (err u10001)) +(define-constant ERR_INVALID_PARAMS (err u10002)) + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +(define-public (run (parameters (buff 2048))) + (let + ( + (paramsTuple (unwrap! (from-consensus-buff? + { name: (string-utf8 50), description: (string-utf8 255), price: uint, url: (optional (string-utf8 255)) } + parameters) ERR_INVALID_PARAMS)) + ) + (try! (is-dao-or-extension)) + (try! (contract-call? .aibtc-payments-invoices add-resource (get name paramsTuple) (get description paramsTuple) (get price paramsTuple) (get url paramsTuple))) + (ok true) + ) +) + +(define-private (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtcdev-base-dao) + (contract-call? .aibtcdev-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + )) +) diff --git a/contracts/dao/extensions/actions/aibtc-action-allow-asset.clar b/contracts/dao/extensions/actions/aibtc-action-allow-asset.clar new file mode 100644 index 0000000..47c3926 --- /dev/null +++ b/contracts/dao/extensions/actions/aibtc-action-allow-asset.clar @@ -0,0 +1,20 @@ +(impl-trait .aibtcdev-dao-traits-v1.extension) +(impl-trait .aibtcdev-dao-traits-v1.action) + +(define-constant ERR_UNAUTHORIZED (err u10001)) +(define-constant ERR_INVALID_PARAMS (err u10002)) + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +(define-public (run (parameters (buff 2048))) + (begin + (try! (is-dao-or-extension)) + (contract-call? .aibtc-treasury allow-asset (unwrap! (from-consensus-buff? principal parameters) ERR_INVALID_PARAMS) true) + ) +) + +(define-private (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtcdev-base-dao) + (contract-call? .aibtcdev-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + )) +) diff --git a/contracts/dao/extensions/actions/aibtc-action-send-message.clar b/contracts/dao/extensions/actions/aibtc-action-send-message.clar index 1fe5d82..c332b68 100644 --- a/contracts/dao/extensions/actions/aibtc-action-send-message.clar +++ b/contracts/dao/extensions/actions/aibtc-action-send-message.clar @@ -17,4 +17,4 @@ (ok (asserts! (or (is-eq tx-sender .aibtcdev-base-dao) (contract-call? .aibtcdev-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED )) -) \ No newline at end of file +) diff --git a/contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar b/contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar index f254c80..e89b323 100644 --- a/contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar +++ b/contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar @@ -17,4 +17,4 @@ (ok (asserts! (or (is-eq tx-sender .aibtcdev-base-dao) (contract-call? .aibtcdev-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED )) -) \ No newline at end of file +) diff --git a/contracts/dao/extensions/actions/aibtc-action-set-withdrawal-amount.clar b/contracts/dao/extensions/actions/aibtc-action-set-withdrawal-amount.clar new file mode 100644 index 0000000..41cc444 --- /dev/null +++ b/contracts/dao/extensions/actions/aibtc-action-set-withdrawal-amount.clar @@ -0,0 +1,27 @@ +(impl-trait .aibtcdev-dao-traits-v1.extension) +(impl-trait .aibtcdev-dao-traits-v1.action) + +(define-constant ERR_UNAUTHORIZED (err u10001)) +(define-constant ERR_INVALID_PARAMS (err u10002)) +(define-constant ERR_PARAMS_OUT_OF_RANGE (err u10003)) + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +(define-public (run (parameters (buff 2048))) + (let + ( + (amount (unwrap! (from-consensus-buff? uint parameters) ERR_INVALID_PARAMS)) + ) + (try! (is-dao-or-extension)) + ;; verify within limits for low quorum + ;; more than 0, less than 100 STX (100_000_000) + (asserts! (and (> amount u0) (< amount u100000000)) ERR_INVALID_PARAMS) + (contract-call? .aibtc-bank-account set-withdrawal-amount amount) + ) +) + +(define-private (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtcdev-base-dao) + (contract-call? .aibtcdev-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + )) +) diff --git a/contracts/dao/extensions/actions/aibtc-action-set-withdrawal-period.clar b/contracts/dao/extensions/actions/aibtc-action-set-withdrawal-period.clar new file mode 100644 index 0000000..6dfe1df --- /dev/null +++ b/contracts/dao/extensions/actions/aibtc-action-set-withdrawal-period.clar @@ -0,0 +1,27 @@ +(impl-trait .aibtcdev-dao-traits-v1.extension) +(impl-trait .aibtcdev-dao-traits-v1.action) + +(define-constant ERR_UNAUTHORIZED (err u10001)) +(define-constant ERR_INVALID_PARAMS (err u10002)) +(define-constant ERR_PARAMS_OUT_OF_RANGE (err u10003)) + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +(define-public (run (parameters (buff 2048))) + (let + ( + (period (unwrap! (from-consensus-buff? uint parameters) ERR_INVALID_PARAMS)) + ) + (try! (is-dao-or-extension)) + ;; verify within limits for low quorum + ;; more than 6 blocks (1hr), less than 1008 blocks (~1 week) + (asserts! (and (> period u6) (< period u1008)) ERR_PARAMS_OUT_OF_RANGE) + (contract-call? .aibtc-bank-account set-withdrawal-period period) + ) +) + +(define-private (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtcdev-base-dao) + (contract-call? .aibtcdev-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + )) +) diff --git a/contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar b/contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar new file mode 100644 index 0000000..5922d6b --- /dev/null +++ b/contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar @@ -0,0 +1,20 @@ +(impl-trait .aibtcdev-dao-traits-v1.extension) +(impl-trait .aibtcdev-dao-traits-v1.action) + +(define-constant ERR_UNAUTHORIZED (err u10001)) +(define-constant ERR_INVALID_PARAMS (err u10002)) + +(define-public (callback (sender principal) (memo (buff 34))) (ok true)) + +(define-public (run (parameters (buff 2048))) + (begin + (try! (is-dao-or-extension)) + (contract-call? .aibtc-payments-invoices toggle-resource-by-name (unwrap! (from-consensus-buff? (string-utf8 50) parameters) ERR_INVALID_PARAMS)) + ) +) + +(define-private (is-dao-or-extension) + (ok (asserts! (or (is-eq tx-sender .aibtcdev-base-dao) + (contract-call? .aibtcdev-base-dao is-extension contract-caller)) ERR_UNAUTHORIZED + )) +) From 2ada232fc93fc51c9256111bcd885c3d48e93ec6 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 07:26:24 -0700 Subject: [PATCH 2/3] fix: add actions to bootstrap init --- .../aibtc-base-bootstrap-initialization.clar | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/contracts/dao/proposals/aibtc-base-bootstrap-initialization.clar b/contracts/dao/proposals/aibtc-base-bootstrap-initialization.clar index d8f372b..f28cb4b 100644 --- a/contracts/dao/proposals/aibtc-base-bootstrap-initialization.clar +++ b/contracts/dao/proposals/aibtc-base-bootstrap-initialization.clar @@ -4,7 +4,7 @@ (define-public (execute (sender principal)) (begin - ;; set initial extensions list + ;; set initial dao extensions list (try! (contract-call? .aibtcdev-base-dao set-extensions (list {extension: .aibtc-action-proposals, enabled: true} @@ -16,6 +16,18 @@ {extension: .aibtc-treasury, enabled: true} ) )) + ;; set initial action proposals list + (try! (contract-call? .aibtcdev-base-dao set-extensions + (list + {extension: .aibtc-action-add-resource, enabled: true} + {extension: .aibtc-action-allow-asset, enabled: true} + {extension: .aibtc-action-send-message, enabled: true} + {extension: .aibtc-action-set-account-holder, enabled: true} + {extension: .aibtc-action-set-withdrawal-amount, enabled: true} + {extension: .aibtc-action-set-withdrawal-period, enabled: true} + {extension: .aibtc-action-toggle-resource-by-name, enabled: true} + ) + )) ;; initialize action proposals (try! (contract-call? .aibtc-action-proposals set-protocol-treasury .aibtc-treasury)) ;; initialize core proposals From edc179e774efcb756635f0d5364d17e6145e0146 Mon Sep 17 00:00:00 2001 From: Jason Schrader Date: Tue, 14 Jan 2025 07:37:33 -0700 Subject: [PATCH 3/3] fix: use let for clearer params and fn calls --- .../dao/extensions/actions/aibtc-action-allow-asset.clar | 7 +++++-- .../dao/extensions/actions/aibtc-action-send-message.clar | 7 +++++-- .../actions/aibtc-action-set-account-holder.clar | 7 +++++-- .../actions/aibtc-action-toggle-resource-by-name.clar | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/contracts/dao/extensions/actions/aibtc-action-allow-asset.clar b/contracts/dao/extensions/actions/aibtc-action-allow-asset.clar index 47c3926..41ebae4 100644 --- a/contracts/dao/extensions/actions/aibtc-action-allow-asset.clar +++ b/contracts/dao/extensions/actions/aibtc-action-allow-asset.clar @@ -7,9 +7,12 @@ (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) - (begin + (let + ( + (asset (unwrap! (from-consensus-buff? principal parameters) ERR_INVALID_PARAMS)) + ) (try! (is-dao-or-extension)) - (contract-call? .aibtc-treasury allow-asset (unwrap! (from-consensus-buff? principal parameters) ERR_INVALID_PARAMS) true) + (contract-call? .aibtc-treasury allow-asset asset true) ) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-send-message.clar b/contracts/dao/extensions/actions/aibtc-action-send-message.clar index c332b68..419c96e 100644 --- a/contracts/dao/extensions/actions/aibtc-action-send-message.clar +++ b/contracts/dao/extensions/actions/aibtc-action-send-message.clar @@ -7,9 +7,12 @@ (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) - (begin + (let + ( + (message (unwrap! (from-consensus-buff? (string-ascii 2043) parameters) ERR_INVALID_PARAMS)) + ) (try! (is-dao-or-extension)) - (contract-call? .aibtc-onchain-messaging send (unwrap! (from-consensus-buff? (string-ascii 2043) parameters) ERR_INVALID_PARAMS) true) + (contract-call? .aibtc-onchain-messaging send message true) ) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar b/contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar index e89b323..3877f4c 100644 --- a/contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar +++ b/contracts/dao/extensions/actions/aibtc-action-set-account-holder.clar @@ -7,9 +7,12 @@ (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) - (begin + (let + ( + (accountHolder (unwrap! (from-consensus-buff? principal parameters) ERR_INVALID_PARAMS)) + ) (try! (is-dao-or-extension)) - (contract-call? .aibtc-bank-account set-account-holder (unwrap! (from-consensus-buff? principal parameters) ERR_INVALID_PARAMS)) + (contract-call? .aibtc-bank-account set-account-holder accountHolder) ) ) diff --git a/contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar b/contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar index 5922d6b..93c86dc 100644 --- a/contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar +++ b/contracts/dao/extensions/actions/aibtc-action-toggle-resource-by-name.clar @@ -7,9 +7,12 @@ (define-public (callback (sender principal) (memo (buff 34))) (ok true)) (define-public (run (parameters (buff 2048))) - (begin + (let + ( + (resourceName (unwrap! (from-consensus-buff? (string-utf8 50) parameters) ERR_INVALID_PARAMS)) + ) (try! (is-dao-or-extension)) - (contract-call? .aibtc-payments-invoices toggle-resource-by-name (unwrap! (from-consensus-buff? (string-utf8 50) parameters) ERR_INVALID_PARAMS)) + (contract-call? .aibtc-payments-invoices toggle-resource-by-name resourceName) ) )