-
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
Changes from 36 commits
9257369
88005e6
1f4b94b
f91263c
661112d
b04c477
ab52440
333264a
301747f
46a83d2
c659730
219d11d
3870a44
e80af39
ee66bf3
f4bd17a
cc61cb6
3dac929
59b818e
03e7d47
5887bdd
13c61d2
02cfb9d
6956d7b
c5c106f
b5bf535
68fa718
ef0b46b
be99984
a91e677
eacdaba
a956ae6
f48546c
b2473b0
9a446fa
faaa18a
23b3e95
21d527e
c22af4a
55ce020
c4d0f45
0791bf8
d419542
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
**/settings/Mainnet.toml | ||
**/settings/Testnet.toml | ||
.cache/** | ||
history.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
{ | ||
"deno.enable": true, | ||
"files.eol": "\n" | ||
} |
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" | ||
} | ||
] | ||
} |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
|
||
;; 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) (memo (string-ascii 72))) | ||
(begin | ||
(asserts! (is-coordinator) (err err-invalid-caller)) | ||
(ft-mint? sbtc amount tx-sender) | ||
) | ||
) | ||
|
||
(define-public (burn! (amount uint) (memo (string-ascii 72))) | ||
(begin | ||
(asserts! (is-coordinator) (err err-invalid-caller)) | ||
(ft-burn? sbtc amount tx-sender) | ||
) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These methods should take an additional principal as an argument, since the coordinator will mint & burn tokens for arbitrary stacks principals. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done @netrome There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See below @igorsyl , I used peg-in/out-txid for mint/burn |
||
|
||
(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 ? |
||
(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))) | ||
) |
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.
can we instead of calling it
memo
call itpeg_out_txid
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.
Done, used peg-in/out-txid for mint/burn