-
Notifications
You must be signed in to change notification settings - Fork 677
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
sBTC Alpha Testnet Contract #3499
Closed
Closed
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
9257369
first pass sbtc key admin contract
xoloki 88005e6
get-coordinator-key was returning a signer key
xoloki 1f4b94b
add unit tests
xoloki f91263c
add ft trait
xoloki 661112d
remove trait-impl since it isn't working
xoloki b04c477
start renaming
xoloki ab52440
keep renaming
xoloki 333264a
keep renaming
xoloki 301747f
finish renaming
xoloki 46a83d2
keep renaming
xoloki c659730
finish renaming
xoloki 219d11d
add delete-signer-key and a test for it
xoloki 3870a44
impl ft trait
xoloki e80af39
remove mint func in favor of trait token-credit
xoloki ee66bf3
still need mint
xoloki f4bd17a
add test for mint
xoloki cc61cb6
check for 0 balance before mint
xoloki 3dac929
check result from mint
xoloki 59b818e
enforce BTC max satoshi limit
xoloki 03e7d47
add token uri
xoloki 5887bdd
add burn! function; store principal and pubkey for coordinator and si…
xoloki 13c61d2
define err constants to just be the uints, and explicitly add the err…
xoloki 02cfb9d
add burn test to make sure it fails if balance is insufficient
xoloki 6956d7b
make 1 sBTC = 1 BTC; assert valid caller don't use if/else; add separ…
xoloki c5c106f
fix is-coordinator to use optional match syntax
xoloki b5bf535
gate mint/burn on coordinator not contract owner; set coordinator in …
xoloki 68fa718
update token-uri to point to whitepaper not repo
xoloki ef0b46b
add vars num-keys num-parties and threshold; add setters
xoloki be99984
add getters and tests for num-keys/num-parties/threshold
xoloki a91e677
add func to test for valid signer id; assert valid signer id in set/d…
xoloki eacdaba
make contract owner var not const, and allow setting it by current co…
xoloki a956ae6
use different error code for invalid-signer-id
xoloki f48546c
add bitcoin-payout-address with accesors and a test
xoloki b2473b0
change btc addr name to bitcoin-wallet-address
xoloki 9a446fa
gate btc wallet addr setter on coordinator
xoloki faaa18a
add accessors for trading-halted; add test for r/w of trading-halted;…
xoloki 23b3e95
rename memo field for mint/burn and log it
xoloki 21d527e
add dst/src principals to mint/burn; update mint/burn/transfer tests
xoloki c22af4a
rewrote test and now it's passing
xoloki 55ce020
add more checks in trading halted test
xoloki c4d0f45
uncomment memo print
xoloki 0791bf8
check bob balance after transfer
xoloki d419542
Merge branch 'next' into sbt-key-admin
jcnelson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
**/settings/Mainnet.toml | ||
**/settings/Testnet.toml | ||
.cache/** | ||
history.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
{ | ||
"deno.enable": true, | ||
"files.eol": "\n" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "check contracts", | ||
"group": "test", | ||
"type": "shell", | ||
"command": "clarinet check" | ||
}, | ||
{ | ||
"label": "test contracts", | ||
"group": "test", | ||
"type": "shell", | ||
"command": "clarinet test" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[project] | ||
name = 'sbtc-token-key-admin' | ||
description = '' | ||
authors = [] | ||
telemetry = true | ||
cache_dir = './.cache' | ||
|
||
[[project.requirements]] | ||
contract_id = "SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard" | ||
|
||
[contracts.sbtc-token-key-admin] | ||
path = 'contracts/sbtc-token-key-admin.clar' | ||
clarity_version = 1 | ||
epoch = 2.0 | ||
|
||
[repl.analysis] | ||
passes = ['check_checker'] | ||
|
||
[repl.analysis.check_checker] | ||
strict = false | ||
trusted_sender = false | ||
trusted_caller = false | ||
callee_filter = false |
202 changes: 202 additions & 0 deletions
202
contrib/sbtc/token-key-admin/contracts/sbtc-token-key-admin.clar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
|
||
;; title: sbtc-token-key-admin | ||
;; version: | ||
;; summary: | ||
;; description: | ||
|
||
;; traits | ||
;; | ||
(impl-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait) | ||
|
||
;; token definitions | ||
;; | ||
(define-fungible-token sbtc u21000000) | ||
|
||
;; constants | ||
;; | ||
(define-constant err-invalid-caller u1) | ||
(define-constant err-invalid-signer-id u2) | ||
(define-constant err-not-token-owner u3) | ||
(define-constant err-trading-halted u4) | ||
|
||
;; data vars | ||
;; | ||
(define-data-var contract-owner principal tx-sender) | ||
(define-data-var coordinator (optional {addr: principal, key: (buff 33)}) none) | ||
(define-data-var num-keys uint u4000) | ||
(define-data-var num-parties uint u4000) | ||
(define-data-var threshold uint u2800) | ||
(define-data-var bitcoin-wallet-address (optional (string-ascii 72)) none) | ||
(define-data-var trading-halted bool false) | ||
|
||
;; data maps | ||
;; | ||
(define-map signers uint {addr: principal, key: (buff 33)}) | ||
|
||
;; public functions | ||
;; | ||
(define-public (set-contract-owner (owner principal)) | ||
(begin | ||
(asserts! (is-contract-owner) (err err-invalid-caller)) | ||
(ok (var-set contract-owner owner)) | ||
) | ||
) | ||
|
||
(define-public (set-coordinator-data (data {addr: principal, key: (buff 33)})) | ||
(begin | ||
(asserts! (is-contract-owner) (err err-invalid-caller)) | ||
(ok (var-set coordinator (some data))) | ||
) | ||
) | ||
|
||
(define-public (set-num-keys (n uint)) | ||
(begin | ||
(asserts! (is-contract-owner) (err err-invalid-caller)) | ||
(ok (var-set num-keys n)) | ||
) | ||
) | ||
|
||
(define-public (set-num-parties (n uint)) | ||
(begin | ||
(asserts! (is-contract-owner) (err err-invalid-caller)) | ||
(ok (var-set num-parties n)) | ||
) | ||
) | ||
|
||
(define-public (set-threshold (n uint)) | ||
(begin | ||
(asserts! (is-contract-owner) (err err-invalid-caller)) | ||
(ok (var-set threshold n)) | ||
) | ||
) | ||
|
||
(define-public (set-trading-halted (b bool)) | ||
(begin | ||
(asserts! (is-coordinator) (err err-invalid-caller)) | ||
(ok (var-set trading-halted b)) | ||
) | ||
) | ||
|
||
(define-public (set-signer-data (id uint) (data {addr: principal, key: (buff 33)})) | ||
(begin | ||
(asserts! (is-contract-owner) (err err-invalid-caller)) | ||
(asserts! (is-valid-signer-id id) (err err-invalid-signer-id)) | ||
(ok (map-set signers id data)) | ||
) | ||
) | ||
|
||
(define-public (delete-signer-data (id uint)) | ||
(begin | ||
(asserts! (is-contract-owner) (err err-invalid-caller)) | ||
(asserts! (is-valid-signer-id id) (err err-invalid-signer-id)) | ||
(ok (map-delete signers id)) | ||
) | ||
) | ||
|
||
(define-public (set-bitcoin-wallet-address (addr (string-ascii 72))) | ||
(begin | ||
(asserts! (is-coordinator) (err err-invalid-caller)) | ||
(ok (var-set bitcoin-wallet-address (some addr))) | ||
) | ||
) | ||
|
||
(define-public (mint! (amount uint) (dst principal) (peg-in-txid (string-ascii 72))) | ||
(begin | ||
(asserts! (is-coordinator) (err err-invalid-caller)) | ||
(print peg-in-txid) | ||
(ft-mint? sbtc amount dst) | ||
) | ||
) | ||
|
||
(define-public (burn! (amount uint) (src principal) (peg-out-txid (string-ascii 72))) | ||
(begin | ||
(asserts! (is-coordinator) (err err-invalid-caller)) | ||
(print peg-out-txid) | ||
(ft-burn? sbtc amount src) | ||
) | ||
) | ||
|
||
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) | ||
(begin | ||
(asserts! (is-eq tx-sender sender) (err err-not-token-owner)) | ||
igorsyl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(asserts! (is-eq (var-get trading-halted) false) (err err-trading-halted)) | ||
(try! (ft-transfer? sbtc amount sender recipient)) | ||
(match memo to-print (print to-print) 0x) | ||
(ok true) | ||
) | ||
) | ||
|
||
;; read only functions | ||
;; | ||
(define-read-only (get-coordinator-data) | ||
(var-get coordinator) | ||
) | ||
|
||
(define-read-only (get-num-keys) | ||
(var-get num-keys) | ||
) | ||
|
||
(define-read-only (get-num-parties) | ||
(var-get num-parties) | ||
) | ||
|
||
(define-read-only (get-threshold) | ||
(var-get threshold) | ||
) | ||
|
||
(define-read-only (get-trading-halted) | ||
(var-get trading-halted) | ||
) | ||
|
||
(define-read-only (get-bitcoin-wallet-address) | ||
(var-get bitcoin-wallet-address) | ||
) | ||
|
||
(define-read-only (get-signer-data (signer uint)) | ||
(map-get? signers signer) | ||
) | ||
|
||
;;(define-read-only (get-signers) | ||
jcnelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
;; (map-get? signers) | ||
;;) | ||
|
||
(define-read-only (get-name) | ||
(ok "sBTC") | ||
) | ||
|
||
(define-read-only (get-symbol) | ||
(ok "sBTC") | ||
) | ||
|
||
(define-read-only (get-decimals) | ||
(ok u8) | ||
) | ||
|
||
(define-read-only (get-balance (who principal)) | ||
(ok (ft-get-balance sbtc who)) | ||
) | ||
|
||
(define-read-only (get-total-supply) | ||
(ok (ft-get-supply sbtc)) | ||
) | ||
|
||
(define-read-only (get-token-uri) | ||
(ok (some u"https://assets.stacks.co/sbtc.pdf")) | ||
) | ||
|
||
;; private functions | ||
;; | ||
(define-private (is-contract-owner) | ||
(is-eq (var-get contract-owner) tx-sender) | ||
) | ||
|
||
(define-private (is-coordinator) | ||
(match (var-get coordinator) cdata | ||
(is-eq (get addr cdata) tx-sender) | ||
false | ||
) | ||
) | ||
|
||
(define-private (is-valid-signer-id (id uint)) | ||
(and (>= id u0) (< id (var-get num-keys))) | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a trading halt boolean member variable gated to contract owner if we need to disable trading for any reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this var with a r/w test, and another test that actually tries to transfer when halted. The first test passes, but the second test goes into what appears to be an infinite recursion loop when we try to do the first transfer.
Can you look and see if I've done something obviously wrong @igorsyl @jcnelson ?