Skip to content

Commit

Permalink
Merge pull request #18 from aibtcdev/feat/add-remaining-actions
Browse files Browse the repository at this point in the history
Add remaining action proposals
  • Loading branch information
whoabuddy authored Jan 14, 2025
2 parents 86248e8 + edc179e commit 64dad86
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 7 deletions.
25 changes: 25 additions & 0 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
26 changes: 26 additions & 0 deletions contracts/dao/extensions/actions/aibtc-action-add-resource.clar
Original file line number Diff line number Diff line change
@@ -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
))
)
23 changes: 23 additions & 0 deletions contracts/dao/extensions/actions/aibtc-action-allow-asset.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(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
(
(asset (unwrap! (from-consensus-buff? principal parameters) ERR_INVALID_PARAMS))
)
(try! (is-dao-or-extension))
(contract-call? .aibtc-treasury allow-asset asset 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
))
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
(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)
)
)

(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
))
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
(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)
)
)

(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
))
)
)
Original file line number Diff line number Diff line change
@@ -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
))
)
Original file line number Diff line number Diff line change
@@ -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
))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(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
(
(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 resourceName)
)
)

(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
))
)
14 changes: 13 additions & 1 deletion contracts/dao/proposals/aibtc-base-bootstrap-initialization.clar
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down

0 comments on commit 64dad86

Please sign in to comment.