Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pox-3 #59

Merged
merged 48 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a053d6f
fix: add template for new contracts based on originals
whoabuddy Mar 30, 2023
30802fb
fix: update delegate/revoke to pox-3
whoabuddy May 5, 2023
0fee8c6
fix: update mining cityinfo call to mining-v2
whoabuddy May 5, 2023
c13c516
fix: update ccip-014 proposal name and code
whoabuddy May 5, 2023
28e79b4
fix: add mining-v2 and fix ccip014 in toml
whoabuddy May 10, 2023
105afd9
fix: add mock pox-3 contract
whoabuddy May 10, 2023
295c640
fix: add mining shutdown to ccip-014
whoabuddy May 12, 2023
db5bcb1
fix: add mainnet/testnet constants
whoabuddy May 16, 2023
c7d5d1d
fix: update to use testnet pox3 and fix check errors
whoabuddy May 16, 2023
34eed16
chore: bump clarinet version in tests
whoabuddy May 16, 2023
f53389e
fix: add voting fn similar to ccip-011
whoabuddy May 18, 2023
2322ab5
fix: add voting block heights
whoabuddy May 18, 2023
62d8b66
chore: incorporate upstream changes
whoabuddy May 19, 2023
2642b73
Merge branch 'fix/support-pox-2' of github.com:citycoins/protocol int…
whoabuddy May 19, 2023
479fbff
fix: make clarinet check pass
whoabuddy May 19, 2023
204b259
fix: update mining tests for claims
whoabuddy May 19, 2023
f826fcb
fix: bump epoch in Clarinet.toml to 2.4
whoabuddy May 23, 2023
0568700
fix: add mia and nyc voting calculations
whoabuddy May 23, 2023
81067f9
fix: correct block heights and add BTC/STX equiv
whoabuddy May 23, 2023
a7d7f60
fix: add check that vote passed to execute
whoabuddy May 23, 2023
b121315
fix: clone mining models and test for v2
whoabuddy May 23, 2023
941e8fd
fix: update mining tests to use same model
whoabuddy May 23, 2023
773475d
fix: clone test proposals and update utils
whoabuddy May 23, 2023
01fdf62
fix: remove checks for before vote starts
whoabuddy May 24, 2023
866d44d
fix: add trait for ccip-011 vote function
whoabuddy May 24, 2023
2f349c8
fix: update ccip-011 ref to ccip-015
whoabuddy May 24, 2023
e013b98
fix: minor cleanup/changes
whoabuddy May 25, 2023
5f12ade
fix: add var to track vote active
whoabuddy May 25, 2023
6b0ae28
fix: add idea for test abstraction
whoabuddy May 26, 2023
62fb43d
fix: prep model and common for ccip014 tests
whoabuddy May 27, 2023
9b3e4f3
fix: add initial ccip-014 tests
whoabuddy May 27, 2023
e58dff1
fix: add ccip-014 tests, fixes #62
whoabuddy May 27, 2023
835dd3f
fix: add tests for mining before/after
whoabuddy May 27, 2023
d2855e5
fix: add missed cycle payouts and related tests
whoabuddy May 27, 2023
66786a2
fix: update pool operator for payouts
whoabuddy May 27, 2023
7f7eccd
fix: skip mining-v2 check since not enabled yet
whoabuddy May 27, 2023
188d41c
fix: remove v2 mining tests in favor of ccip-014 testing
whoabuddy May 27, 2023
2da6808
fix: add commit hash for ccip-014
whoabuddy May 27, 2023
cf74cd2
fix: disable ccd006-v2 until ccip014 activates
whoabuddy May 27, 2023
70ec80c
fix: create clone of ccip-014 as v2
whoabuddy May 29, 2023
c5d60f4
chore: use latest version of code
whoabuddy May 29, 2023
366fe99
fix: remove past cycle payout code
whoabuddy May 29, 2023
1ab5334
fix: remove vote related code
whoabuddy May 29, 2023
a5d3056
fix: cleanup code and add check to ccip014 voting data
whoabuddy May 29, 2023
4b043b6
fix: add models and tests for ccip014-pox-3-v2
whoabuddy Aug 30, 2023
f1ff69e
fix: add ccd006-citycoin-mining-v2 tests
whoabuddy Aug 30, 2023
478dc48
fix: add ccd002-treasury-v2 tests
whoabuddy Aug 30, 2023
da0d488
fix: add read-only tests to ccip014-pox-3
whoabuddy Aug 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 102 additions & 7 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ path = "contracts/extensions/ccd001-direct-execute.clar"
[contracts.ccd002-treasury-mia-mining]
path = "contracts/extensions/ccd002-treasury.clar"

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

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

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

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

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

Expand All @@ -110,6 +116,9 @@ path = "contracts/extensions/ccd005-city-data.clar"
[contracts.ccd006-citycoin-mining]
path = "contracts/extensions/ccd006-citycoin-mining.clar"

[contracts.ccd006-citycoin-mining-v2]
path = "contracts/extensions/ccd006-citycoin-mining-v2.clar"

[contracts.ccd007-citycoin-stacking]
path = "contracts/extensions/ccd007-citycoin-stacking.clar"

Expand All @@ -134,6 +143,16 @@ path = "contracts/proposals/ccip013-migration.clar"
[contracts.ccip013-activation]
path = "contracts/proposals/ccip013-activation.clar"

[contracts.ccip014-pox-3]
path = "contracts/proposals/ccip014-pox-3.clar"
clarity_version = 2
epoch = 2.4

[contracts.ccip014-pox-3-v2]
path = "contracts/proposals/ccip014-pox-3-v2.clar"
clarity_version = 2
epoch = 2.4

# CITYCOINS PROTOCOL TRAITS

[contracts.extension-trait]
Expand All @@ -154,6 +173,9 @@ path = "contracts/traits/ccd006-trait.clar"
[contracts.ccd007-trait]
path = "contracts/traits/ccd007-trait.clar"

[contracts.ccip-015-trait]
path = "contracts/traits/ccip-015-trait.clar"

# CITYCOINS EXTERNAL CONTRACTS

[contracts.citycoin-vrf-v2]
Expand All @@ -171,6 +193,11 @@ path = "tests/contracts/external/test-ccext-nft-mia.clar"
[contracts.test-ccext-nft-nyc]
path = "tests/contracts/external/test-ccext-nft-nyc.clar"

[contracts.mock-pox-3]
path = "tests/contracts/external/mock-pox-3.clar"
clarity_version = 2
epoch = 2.4

# CITYCOINS LEGACY CONTRACTS

[contracts.citycoin-core-v2-trait]
Expand Down Expand Up @@ -244,6 +271,42 @@ path = "tests/contracts/proposals/test-ccd002-treasury-011.clar"
[contracts.test-ccd002-treasury-012]
path = "tests/contracts/proposals/test-ccd002-treasury-012.clar"

[contracts.test-ccd002-treasury-v2-001]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-001.clar"

[contracts.test-ccd002-treasury-v2-002]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-002.clar"

[contracts.test-ccd002-treasury-v2-003]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-003.clar"

[contracts.test-ccd002-treasury-v2-004]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-004.clar"

[contracts.test-ccd002-treasury-v2-005]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-005.clar"

[contracts.test-ccd002-treasury-v2-006]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-006.clar"

[contracts.test-ccd002-treasury-v2-007]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-007.clar"

[contracts.test-ccd002-treasury-v2-008]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-008.clar"

[contracts.test-ccd002-treasury-v2-009]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-009.clar"

[contracts.test-ccd002-treasury-v2-010]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-010.clar"

[contracts.test-ccd002-treasury-v2-011]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-011.clar"

[contracts.test-ccd002-treasury-v2-012]
path = "tests/contracts/proposals/test-ccd002-treasury-v2-012.clar"

[contracts.test-ccd003-user-registry-001]
path = "tests/contracts/proposals/test-ccd003-user-registry-001.clar"

Expand Down Expand Up @@ -316,6 +379,9 @@ path = "tests/contracts/proposals/test-ccd005-city-data-018.clar"
[contracts.test-ccd005-city-data-019]
path = "tests/contracts/proposals/test-ccd005-city-data-019.clar"

[contracts.test-ccd005-city-data-020]
path = "tests/contracts/proposals/test-ccd005-city-data-020.clar"

[contracts.test-ccd006-citycoin-mining-001]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-001.clar"

Expand All @@ -331,6 +397,27 @@ path = "tests/contracts/proposals/test-ccd006-citycoin-mining-004.clar"
[contracts.test-ccd006-citycoin-mining-005]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-005.clar"

[contracts.test-ccd006-citycoin-mining-v2-001]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-v2-001.clar"

[contracts.test-ccd006-citycoin-mining-v2-002]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-v2-002.clar"

[contracts.test-ccd006-citycoin-mining-v2-003]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-v2-003.clar"

[contracts.test-ccd006-citycoin-mining-v2-004]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-v2-004.clar"

[contracts.test-ccd006-citycoin-mining-v2-005]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-v2-005.clar"

[contracts.test-ccd006-citycoin-mining-v2-006]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-v2-006.clar"

[contracts.test-ccd006-citycoin-mining-v2-007]
path = "tests/contracts/proposals/test-ccd006-citycoin-mining-v2-007.clar"

[contracts.test-ccd007-citycoin-stacking-001]
path = "tests/contracts/proposals/test-ccd007-citycoin-stacking-001.clar"

Expand Down Expand Up @@ -370,15 +457,23 @@ path = "tests/contracts/proposals/test-ccd007-citycoin-stacking-012.clar"
[contracts.test-ccd011-stacking-payouts-001]
path = "tests/contracts/proposals/test-ccd011-stacking-payouts-001.clar"

[contracts.test-ccip014-pox-3-001]
path = "tests/contracts/proposals/test-ccip014-pox-3-001.clar"

[contracts.test-ccip014-pox-3-002]
path = "tests/contracts/proposals/test-ccip014-pox-3-002.clar"

[repl]
costs_version = 2
parser_version = 2

[repl.analysis]
passes = ["check_checker"]
# TEMPORARILY DISABLED

# [repl.analysis]
# passes = ["check_checker"]

[repl.analysis.check_checker]
strict = false
trusted_sender = false
trusted_caller = false
callee_filter = true
# [repl.analysis.check_checker]
# strict = false
# trusted_sender = false
# trusted_caller = false
# callee_filter = true
206 changes: 206 additions & 0 deletions contracts/extensions/ccd002-treasury-v2.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
;; Title: CCD002 Treasury
;; Version: 2.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-3
;; TESTNET: 'ST000000000000000000002AMW42H.pox-3
(match (as-contract (contract-call? 'ST000000000000000000002AMW42H.pox-3 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-3
;; TESTNET: 'ST000000000000000000002AMW42H.pox-3
(match (as-contract (contract-call? 'ST000000000000000000002AMW42H.pox-3 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