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

CCIP-020: Graceful Protocol Shutdown #68

Merged
merged 35 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3ffeefa
feat: add most of ccip020, still needs work
whoabuddy Mar 30, 2024
4017dc7
fix: add getters for city vote data
whoabuddy Mar 31, 2024
8c128e9
fix: add is-executable code
whoabuddy Mar 31, 2024
e0e03a3
fix: add vote calc from CCIP-020
whoabuddy Mar 31, 2024
6755e70
fix: revert ccip014-pox-3.clar code to orig
whoabuddy Mar 31, 2024
9bfb2ed
fix: update code to pass clarinet check
whoabuddy Apr 1, 2024
61620ed
fix: outline key parts of redemption contract
whoabuddy Apr 1, 2024
c8a06dd
fix: add map to track redeemed balances per user
whoabuddy Apr 2, 2024
f5fbf13
fix: account for V1 and V2 in total supply and balances
whoabuddy Apr 2, 2024
3546ac5
fix: add legacy contracts for V1 tokens
whoabuddy Apr 2, 2024
8b52cd0
fix: add all legacy contracts, pass clarinet check
whoabuddy Apr 2, 2024
af92151
Merge branch 'main' into fix/implement-ccip-020
whoabuddy Apr 5, 2024
97112ba
fix: use correct from addr in STX xfer
whoabuddy Apr 8, 2024
46809b6
fix: use both v1 and v2 balances, expose more read-only fns
whoabuddy Apr 8, 2024
826b84b
fix: return redemptionAmount in redeem-mia
whoabuddy Apr 9, 2024
7be0b4f
fix: remove redemption contracts/refs
whoabuddy Apr 12, 2024
d4df368
fix: cleanup unused contract code
whoabuddy Apr 12, 2024
a9d94c3
fix: do not record a city vote if amount is 0
whoabuddy Apr 12, 2024
aa7bd97
fix: add tests and update related files
whoabuddy Apr 12, 2024
62b51ed
fix: adjust to min 25% of the yes vote
whoabuddy Apr 12, 2024
120263b
fix: add missing execute() tests
whoabuddy Apr 12, 2024
0044cc1
chore: merge main into ccip020
whoabuddy Apr 12, 2024
b0bb7b1
chore: cleanup typo, remove logging
whoabuddy Apr 12, 2024
85a82f1
chore: update action versions
whoabuddy Apr 13, 2024
5329e61
chore: revert codecov to v3, requires more setup
whoabuddy Apr 13, 2024
91aff59
fix: add 3rd account for minted tokens
whoabuddy Apr 15, 2024
ff7464a
fix: add vote-on-proposal() tests
whoabuddy Apr 15, 2024
48f4c62
fix: cleanup test formatting and check each step
whoabuddy Apr 15, 2024
9e3b194
fix: add read-only fn tests
whoabuddy Apr 16, 2024
9eabfcb
fix: add NYC to test proposal contract
whoabuddy Apr 16, 2024
c34744e
fix: add most of integration tests
whoabuddy Apr 16, 2024
4d78fe7
fix: add remaining integration tests
whoabuddy Apr 16, 2024
89d9796
fix: adjust expectedBalance in mining test
whoabuddy Apr 16, 2024
0320c60
chore: update codecov version, add token
whoabuddy Apr 16, 2024
8a1f4a2
fix: add github hash from ccip-020
whoabuddy Apr 16, 2024
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
5 changes: 3 additions & 2 deletions .github/workflows/test-contracts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: "Check contract syntax"
uses: docker://hirosystems/clarinet:1.8.0
with:
Expand All @@ -33,6 +33,7 @@ jobs:
with:
args: test --coverage
- name: "Upload code coverage"
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: ./coverage.lcov
token: ${{ secrets.CODECOV_TOKEN }}
43 changes: 43 additions & 0 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ path = "contracts/proposals/ccip017-extend-sunset-period.clar"
clarity_version = 2
epoch = 2.4

[contracts.ccip020-graceful-protocol-shutdown]
path = "contracts/proposals/ccip020-graceful-protocol-shutdown.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
Expand Down Expand Up @@ -216,12 +221,33 @@ epoch = 2.4

# CITYCOINS LEGACY CONTRACTS

[contracts.citycoin-vrf]
path = "contracts/legacy/citycoin-vrf.clar"

[contracts.citycoin-core-trait]
path = "contracts/legacy/citycoin-core-trait.clar"

[contracts.citycoin-core-v2-trait]
path = "contracts/legacy/citycoin-core-v2-trait.clar"

[contracts.citycoin-token-trait]
path = "contracts/legacy/citycoin-token-trait.clar"

[contracts.citycoin-token-v2-trait]
path = "contracts/legacy/citycoin-token-v2-trait.clar"

[contracts.miamicoin-auth]
path = "contracts/legacy/miamicoin-auth.clar"

[contracts.miamicoin-core-v1]
path = "contracts/legacy/miamicoin-core-v1.clar"

[contracts.miamicoin-token]
path = "contracts/legacy/miamicoin-token.clar"

[contracts.miamicoin-core-v1-patch]
path = "contracts/legacy/miamicoin-core-v1-patch.clar"

[contracts.miamicoin-auth-v2]
path = "contracts/legacy/miamicoin-auth-v2.clar"

Expand All @@ -231,6 +257,18 @@ path = "contracts/legacy/miamicoin-core-v2.clar"
[contracts.miamicoin-token-v2]
path = "contracts/legacy/miamicoin-token-v2.clar"

[contracts.newyorkcitycoin-auth]
path = "contracts/legacy/newyorkcitycoin-auth.clar"

[contracts.newyorkcitycoin-core-v1]
path = "contracts/legacy/newyorkcitycoin-core-v1.clar"

[contracts.newyorkcitycoin-token]
path = "contracts/legacy/newyorkcitycoin-token.clar"

[contracts.newyorkcitycoin-core-v1-patch]
path = "contracts/legacy/newyorkcitycoin-core-v1-patch.clar"

[contracts.newyorkcitycoin-auth-v2]
path = "contracts/legacy/newyorkcitycoin-auth-v2.clar"

Expand Down Expand Up @@ -479,6 +517,11 @@ 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"

[contracts.test-ccip020-shutdown-001]
path = "tests/contracts/proposals/test-ccip020-shutdown-001.clar"
clarity_version = 2
epoch = 2.4

[repl]
costs_version = 2
parser_version = 2
Expand Down
35 changes: 35 additions & 0 deletions contracts/legacy/citycoin-core-trait.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;; CITYCOIN CORE TRAIT

(define-trait citycoin-core
(

(register-user ((optional (string-utf8 50)))
(response bool uint)
)

(mine-tokens (uint (optional (buff 34)))
(response bool uint)
)

(claim-mining-reward (uint)
(response bool uint)
)

(stack-tokens (uint uint)
(response bool uint)
)

(claim-stacking-reward (uint)
(response bool uint)
)

(set-city-wallet (principal)
(response bool uint)
)

(shutdown-contract (uint)
(response bool uint)
)

)
)
27 changes: 27 additions & 0 deletions contracts/legacy/citycoin-token-trait.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
;; CITYCOIN TOKEN TRAIT

(define-trait citycoin-token
(

(activate-token (principal uint)
(response bool uint)
)

(set-token-uri ((optional (string-utf8 256)))
(response bool uint)
)

(mint (uint principal)
(response bool uint)
)

(burn (uint principal)
(response bool uint)
)

(send-many ((list 200 { to: principal, amount: uint, memo: (optional (buff 34)) }))
(response bool uint)
)

)
)
83 changes: 83 additions & 0 deletions contracts/legacy/citycoin-vrf.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
;; CITYCOIN VRF CONTRACT

;; VRF

;; Read the on-chain VRF and turn the lower 16 bytes into a uint, in order to sample the set of miners and determine
;; which one may claim the token batch for the given block height.
(define-read-only (get-random-uint-at-block (stacksBlock uint))
(let (
(vrf-lower-uint-opt
(match (get-block-info? vrf-seed stacksBlock)
vrf-seed (some (buff-to-uint-le (lower-16-le vrf-seed)))
none))
)
vrf-lower-uint-opt)
)

;; UTILITIES

;; lookup table for converting 1-byte buffers to uints via index-of
(define-constant BUFF_TO_BYTE (list
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f
0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f
0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f
0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f
0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4a 0x4b 0x4c 0x4d 0x4e 0x4f
0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5f
0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f
0x70 0x71 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7a 0x7b 0x7c 0x7d 0x7e 0x7f
0x80 0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f
0x90 0x91 0x92 0x93 0x94 0x95 0x96 0x97 0x98 0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f
0xa0 0xa1 0xa2 0xa3 0xa4 0xa5 0xa6 0xa7 0xa8 0xa9 0xaa 0xab 0xac 0xad 0xae 0xaf
0xb0 0xb1 0xb2 0xb3 0xb4 0xb5 0xb6 0xb7 0xb8 0xb9 0xba 0xbb 0xbc 0xbd 0xbe 0xbf
0xc0 0xc1 0xc2 0xc3 0xc4 0xc5 0xc6 0xc7 0xc8 0xc9 0xca 0xcb 0xcc 0xcd 0xce 0xcf
0xd0 0xd1 0xd2 0xd3 0xd4 0xd5 0xd6 0xd7 0xd8 0xd9 0xda 0xdb 0xdc 0xdd 0xde 0xdf
0xe0 0xe1 0xe2 0xe3 0xe4 0xe5 0xe6 0xe7 0xe8 0xe9 0xea 0xeb 0xec 0xed 0xee 0xef
0xf0 0xf1 0xf2 0xf3 0xf4 0xf5 0xf6 0xf7 0xf8 0xf9 0xfa 0xfb 0xfc 0xfd 0xfe 0xff
))

;; Convert a 1-byte buffer into its uint representation.
(define-private (buff-to-u8 (byte (buff 1)))
(unwrap-panic (index-of BUFF_TO_BYTE byte))
)

;; Convert a little-endian 16-byte buff into a uint.
(define-private (buff-to-uint-le (word (buff 16)))
(get acc
(fold add-and-shift-uint-le (list u0 u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11 u12 u13 u14 u15) { acc: u0, data: word })
)
)

;; Inner fold function for converting a 16-byte buff into a uint.
(define-private (add-and-shift-uint-le (idx uint) (input { acc: uint, data: (buff 16) }))
(let (
(acc (get acc input))
(data (get data input))
(byte (buff-to-u8 (unwrap-panic (element-at data idx))))
)
{
;; acc = byte * (2**(8 * (15 - idx))) + acc
acc: (+ (* byte (pow u2 (* u8 (- u15 idx)))) acc),
data: data
})
)

;; Convert the lower 16 bytes of a buff into a little-endian uint.
(define-private (lower-16-le (input (buff 32)))
(get acc
(fold lower-16-le-closure (list u16 u17 u18 u19 u20 u21 u22 u23 u24 u25 u26 u27 u28 u29 u30 u31) { acc: 0x, data: input })
)
)

;; Inner closure for obtaining the lower 16 bytes of a 32-byte buff
(define-private (lower-16-le-closure (idx uint) (input { acc: (buff 16), data: (buff 32) }))
(let (
(acc (get acc input))
(data (get data input))
(byte (unwrap-panic (element-at data idx)))
)
{
acc: (unwrap-panic (as-max-len? (concat acc byte) u16)),
data: data
})
)
Loading