Skip to content

Commit

Permalink
Merge pull request #69 from citycoins/feat/ccip-021
Browse files Browse the repository at this point in the history
CCIP-021: Extend Direct Execution Sunset Period 2

Thank you @friedger!

[Deployment for the proposal](https://explorer.hiro.so/txid/0x7f1b839ec29d50354fd3d3ce61c8826dc7271e567edf22bd7ec78f99cafb3aa9?chain=mainnet)
  • Loading branch information
whoabuddy authored Apr 6, 2024
2 parents 27a0c8f + 01b13a2 commit 379ddaa
Show file tree
Hide file tree
Showing 6 changed files with 1,151 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ path = "contracts/extensions/ccd002-treasury.clar"
[contracts.ccd002-treasury-mia-mining-v2]
path = "contracts/extensions/ccd002-treasury-v2.clar"

# [contracts.ccd002-treasury-mia-mining-v3]
# path = "contracts/extensions/ccd002-treasury-v3.clar"

[contracts.ccd002-treasury-mia-stacking]
path = "contracts/extensions/ccd002-treasury.clar"

Expand All @@ -101,6 +104,9 @@ path = "contracts/extensions/ccd002-treasury.clar"
[contracts.ccd002-treasury-nyc-mining-v2]
path = "contracts/extensions/ccd002-treasury-v2.clar"

# [contracts.ccd002-treasury-nyc-mining-v3]
# path = "contracts/extensions/ccd002-treasury-v3.clar"

[contracts.ccd002-treasury-nyc-stacking]
path = "contracts/extensions/ccd002-treasury.clar"

Expand Down Expand Up @@ -158,6 +164,11 @@ path = "contracts/proposals/ccip017-extend-sunset-period.clar"
clarity_version = 2
epoch = 2.4

[contracts.ccip021-extend-sunset-period-2]
path = "contracts/proposals/ccip021-extend-sunset-period-2.clar"
clarity_version = 2
epoch = 2.4

# CITYCOINS PROTOCOL TRAITS

[contracts.extension-trait]
Expand Down
211 changes: 211 additions & 0 deletions contracts/extensions/ccd002-treasury-v3.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
;; Title: CCD002 Treasury
;; Version: 3.0.0
;; Summary: A treasury contract that can manage STX, SIP-009 NFTs, and SIP-010 FTs.
;; Description: An extension contract that holds assets on behalf of the DAO.
;; SIP-009 and SIP-010 assets must be allowed before they are supported.
;; Deposits can be made by anyone either by transferring to the contract or
;; using a deposit function below.
;; Withdrawals are restricted to the DAO through either extensions or proposals.
;; Stacking is enabled through PoX.

;; TRAITS

(impl-trait .extension-trait.extension-trait)
(impl-trait .stacking-trait.stacking-trait)
(impl-trait .ccd002-trait.ccd002-treasury-trait)
;; MAINNET: 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait
(use-trait ft-trait 'ST1NXBK3K5YYMD6FD41MVNP3JS1GABZ8TRVX023PT.sip-010-trait-ft-standard.sip-010-trait)
;; MAINNET: 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait
(use-trait nft-trait 'ST1NXBK3K5YYMD6FD41MVNP3JS1GABZ8TRVX023PT.nft-trait.nft-trait)

;; CONSTANTS

(define-constant ERR_UNAUTHORIZED (err u2000))
(define-constant ERR_UNKNOWN_ASSSET (err u2001))
(define-constant TREASURY (as-contract tx-sender))

;; DATA MAPS

(define-map AllowedAssets principal bool)

;; PUBLIC FUNCTIONS

(define-public (is-dao-or-extension)
(ok (asserts! (or (is-eq tx-sender .base-dao)
(contract-call? .base-dao is-extension contract-caller)) ERR_UNAUTHORIZED
))
)

(define-public (callback (sender principal) (memo (buff 34)))
(ok true)
)

(define-public (set-allowed (token principal) (enabled bool))
(begin
(try! (is-dao-or-extension))
(print {
event: "allow-asset",
enabled: enabled,
token: token
})
(ok (map-set AllowedAssets token enabled))
)
)

(define-public (set-allowed-list (allowList (list 100 {token: principal, enabled: bool})))
(begin
(try! (is-dao-or-extension))
(ok (map set-allowed-iter allowList))
)
)

(define-public (deposit-stx (amount uint))
(begin
(print {
event: "deposit-stx",
amount: amount,
caller: contract-caller,
recipient: TREASURY,
sender: tx-sender
})
(stx-transfer? amount tx-sender TREASURY)
)
)

(define-public (deposit-ft (ft <ft-trait>) (amount uint))
(begin
(asserts! (is-allowed (contract-of ft)) ERR_UNKNOWN_ASSSET)
(print {
event: "deposit-ft",
amount: amount,
assetContract: (contract-of ft),
caller: contract-caller,
recipient: TREASURY,
sender: tx-sender
})
(contract-call? ft transfer amount tx-sender TREASURY none)
)
)

(define-public (deposit-nft (nft <nft-trait>) (id uint))
(begin
(asserts! (is-allowed (contract-of nft)) ERR_UNKNOWN_ASSSET)
(print {
event: "deposit-nft",
assetContract: (contract-of nft),
caller: contract-caller,
recipient: TREASURY,
sender: tx-sender,
tokenId: id,
})
(contract-call? nft transfer id tx-sender TREASURY)
)
)

(define-public (withdraw-stx (amount uint) (recipient principal))
(begin
(try! (is-dao-or-extension))
(print {
event: "withdraw-stx",
amount: amount,
caller: contract-caller,
recipient: recipient,
sender: tx-sender
})
(as-contract (stx-transfer? amount TREASURY recipient))
)
)

(define-public (withdraw-ft (ft <ft-trait>) (amount uint) (recipient principal))
(begin
(try! (is-dao-or-extension))
(asserts! (is-allowed (contract-of ft)) ERR_UNKNOWN_ASSSET)
(print {
event: "withdraw-ft",
assetContract: (contract-of ft),
caller: contract-caller,
recipient: recipient,
sender: tx-sender
})
(as-contract (contract-call? ft transfer amount TREASURY recipient none))
)
)

(define-public (withdraw-nft (nft <nft-trait>) (id uint) (recipient principal))
(begin
(try! (is-dao-or-extension))
(asserts! (is-allowed (contract-of nft)) ERR_UNKNOWN_ASSSET)
(print {
event: "withdraw-nft",
assetContract: (contract-of nft),
caller: contract-caller,
recipient: recipient,
sender: tx-sender,
tokenId: id
})
(as-contract (contract-call? nft transfer id TREASURY recipient))
)
)

(define-public (delegate-stx (maxAmount uint) (to principal))
(begin
(try! (is-dao-or-extension))
(print {
event: "delegate-stx",
amount: maxAmount,
caller: contract-caller,
delegate: to,
sender: tx-sender
})
;; MAINNET: 'SP000000000000000000002Q6VF78.pox-4
;; TESTNET: 'ST000000000000000000002AMW42H.pox-4
(match (as-contract (contract-call? 'ST000000000000000000002AMW42H.pox-4 delegate-stx maxAmount to none none))
success (ok success)
err (err (to-uint err))
)
)
)

(define-public (revoke-delegate-stx)
(begin
(try! (is-dao-or-extension))
(print {
event: "revoke-delegate-stx",
caller: contract-caller,
sender: tx-sender
})
;; MAINNET: 'SP000000000000000000002Q6VF78.pox-4
;; TESTNET: 'ST000000000000000000002AMW42H.pox-4
(match (as-contract (contract-call? 'ST000000000000000000002AMW42H.pox-4 revoke-delegate-stx))
success (ok success)
err (err (to-uint err))
)
)
)

;; READ ONLY FUNCTIONS

(define-read-only (is-allowed (assetContract principal))
(default-to false (get-allowed-asset assetContract))
)

(define-read-only (get-allowed-asset (assetContract principal))
(map-get? AllowedAssets assetContract)
)

(define-read-only (get-balance-stx)
(stx-get-balance TREASURY)
)

;; PRIVATE FUNCTIONS

(define-private (set-allowed-iter (item {token: principal, enabled: bool}))
(begin
(print {
event: "allow-asset",
enabled: (get enabled item),
token: (get token item)
})
(map-set AllowedAssets (get token item) (get enabled item))
)
)
Loading

0 comments on commit 379ddaa

Please sign in to comment.