Skip to content

Commit

Permalink
chore: update cbtc example
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Dec 4, 2023
1 parent c051953 commit 340a25e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 33 deletions.
4 changes: 2 additions & 2 deletions example/cbtc/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ description = ""
telemetry = false

[[project.requirements]]
contract_id = "SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard"
contract_id = "SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-tokens-v1"

[[project.requirements]]
contract_id = "SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.pyth-oracle-dev-preview-1"
contract_id = "SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1"

[contracts.cbtc-token]
path = "contracts/cbtc-token.clar"
Expand Down
18 changes: 9 additions & 9 deletions example/cbtc/contracts/cbtc-pool.clar
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
(define-public (swap-stx-trustless (stx-in uint) (stx-price-feed (buff 2048)) (btc-price-feed (buff 2048)))
(let ((stx-price (try! (update-and-read-stx-price-from-pyth stx-price-feed)))
(btc-price (try! (update-and-read-btc-price-from-pyth btc-price-feed)))
(sat-price (* u100000000 btc-price))
(cbtc-sats-out (/ (* stx-in sat-price) (* stx-price))))
(sat-price (* u100000000 (to-uint (get price btc-price))))
(cbtc-sats-out (/ (* stx-in sat-price) (* (to-uint (get price stx-price))))))
(unwrap! (contract-call? .cbtc-token transfer cbtc-sats-out (as-contract tx-sender) tx-sender none) (err u1000))
(unwrap! (stx-transfer? stx-in tx-sender (as-contract tx-sender)) (err u1000))
(ok { stx-in: stx-in, cbtc-sats-out: cbtc-sats-out } )))

(define-private (update-and-read-stx-price-from-pyth (stx-price-feed (buff 2048)))
(let ((updated-prices-ids (unwrap! (contract-call? 'SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.pyth-oracle-dev-preview-1 update-prices-feeds (list stx-price-feed)) (err u0)))
(price-id (unwrap! (element-at? updated-prices-ids u0) (err u0))))
(read-price-from-pyth price-id)))
(let ((updated-prices-ids (unwrap! (contract-call? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 verify-and-update-price stx-price-feed) (err u0)))
(price (unwrap! (element-at? updated-prices-ids u0) (err u404))))
(ok price)))

(define-private (update-and-read-btc-price-from-pyth (btc-price-feed (buff 2048)))
(let ((updated-prices-ids (unwrap! (contract-call? 'SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.pyth-oracle-dev-preview-1 update-prices-feeds (list btc-price-feed)) (err u0)))
(price-id (unwrap! (element-at? updated-prices-ids u0) (err u0))))
(read-price-from-pyth price-id)))
(let ((updated-prices-ids (unwrap! (contract-call? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 verify-and-update-price btc-price-feed) (err u0)))
(price (unwrap! (element-at? updated-prices-ids u0) (err u404))))
(ok price)))

(define-private (read-stx-price-from-pyth)
(read-price-from-pyth 0xec7a775f46379b5e943c3526b1c8d54cd49749176b0b98e02dde68d1bd335c17))
Expand All @@ -53,6 +53,6 @@
(read-price-from-pyth 0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43))

(define-private (read-price-from-pyth (price-id (buff 32)))
(let ((feed (unwrap! (contract-call? 'SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.pyth-oracle-dev-preview-1 read-price-feed price-id) (err u0)))
(let ((feed (unwrap! (contract-call? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 read-price price-id) (err u0)))
(price (get price feed)))
(ok (to-uint price))))
2 changes: 1 addition & 1 deletion example/cbtc/contracts/cbtc-token.clar
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(impl-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait)
(impl-trait 'SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-tokens-v1.sip10-token)

(define-fungible-token cbtc)

Expand Down
69 changes: 48 additions & 21 deletions example/cbtc/deployments/default.simnet-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,59 @@ plan:
- id: 0
transactions:
- emulated-contract-publish:
contract-name: sip-010-trait-ft-standard
emulated-sender: SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE
path: ".cache/requirements/SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.clar"
clarity-version: 1
epoch: "2.0"
- id: 1
transactions:
- emulated-contract-publish:
contract-name: hk-cursor-v1
contract-name: hk-tokens-v1
emulated-sender: SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F
path: ".cache/requirements/SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-cursor-v1.clar"
path: ".cache/requirements/SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-tokens-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: wormhole-core-trait
emulated-sender: SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F
path: ".cache/requirements/SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.wormhole-core-trait.clar"
contract-name: wormhole-traits-v1
emulated-sender: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP
path: ".cache/requirements/SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.wormhole-traits-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: pyth-traits-v1
emulated-sender: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP
path: ".cache/requirements/SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-traits-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: wormhole-core-dev-preview-1
contract-name: hk-cursor-v2
emulated-sender: SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F
path: ".cache/requirements/SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.wormhole-core-dev-preview-1.clar"
path: ".cache/requirements/SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-cursor-v2.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: pyth-governance-v1
emulated-sender: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP
path: ".cache/requirements/SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-governance-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: pyth-oracle-v1
emulated-sender: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP
path: ".cache/requirements/SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-oracle-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: pyth-oracle-dev-preview-1
contract-name: hk-merkle-tree-keccak160-v1
emulated-sender: SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F
path: ".cache/requirements/SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.pyth-oracle-dev-preview-1.clar"
path: ".cache/requirements/SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-merkle-tree-keccak160-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: pyth-pnau-decoder-v1
emulated-sender: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP
path: ".cache/requirements/SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-pnau-decoder-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: pyth-store-v1
emulated-sender: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP
path: ".cache/requirements/SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-store-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: wormhole-core-v1
emulated-sender: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP
path: ".cache/requirements/SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.wormhole-core-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: pyth-helper-v1
emulated-sender: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP
path: ".cache/requirements/SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1.clar"
clarity-version: 2
- emulated-contract-publish:
contract-name: cbtc-token
Expand All @@ -87,10 +114,10 @@ plan:
path: contracts/cbtc-pool.clar
clarity-version: 2
epoch: "2.4"
- id: 2
- id: 1
transactions:
- emulated-contract-call:
contract-id: SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.wormhole-core-dev-preview-1
contract-id: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.wormhole-core-v1
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
method: update-guardians-set
parameters:
Expand Down Expand Up @@ -119,7 +146,7 @@ plan:
0x21f338444e96af31cf44958acf5764844efbddace3b823ed761c340c59ed2685d829818c83eebe8f00f783f1048a53515845536668a9e0c059ade7579a0f4204)'
cost: 5960
- emulated-contract-call:
contract-id: SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.wormhole-core-dev-preview-1
contract-id: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.wormhole-core-v1
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
method: update-guardians-set
parameters:
Expand Down Expand Up @@ -148,7 +175,7 @@ plan:
0x21f338444e96af31cf44958acf5764844efbddace3b823ed761c340c59ed2685d829818c83eebe8f00f783f1048a53515845536668a9e0c059ade7579a0f4204)'
cost: 5960
- emulated-contract-call:
contract-id: SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.wormhole-core-dev-preview-1
contract-id: SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.wormhole-core-v1
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
method: update-guardians-set
parameters:
Expand Down

0 comments on commit 340a25e

Please sign in to comment.