Skip to content

Commit

Permalink
chore: update cbtc example
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Feb 19, 2024
1 parent 3afb7a8 commit 733a15e
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 42 deletions.
14 changes: 13 additions & 1 deletion example/cbtc/Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ telemetry = false
contract_id = "SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-tokens-v1"

[[project.requirements]]
contract_id = "SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1"
contract_id = "ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2"

[[project.requirements]]
contract_id = "ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.wormhole-core-v1"

[[project.requirements]]
contract_id = "ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.wormhole-core-v2"

[[project.requirements]]
contract_id = 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1'

[[project.requirements]]
contract_id = 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-pnau-decoder-v1'

[contracts.cbtc-token]
path = "contracts/cbtc-token.clar"
Expand Down
22 changes: 19 additions & 3 deletions example/cbtc/contracts/cbtc-pool.clar
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,28 @@
(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? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 verify-and-update-price stx-price-feed) (err u0)))
(let ((updated-prices-ids (unwrap!
(contract-call? 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2 verify-and-update-price-feeds
stx-price-feed
{
pyth-storage-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1,
pyth-decoder-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-pnau-decoder-v1,
wormhole-core-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.wormhole-core-v2
})
(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? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 verify-and-update-price btc-price-feed) (err u0)))
(let ((updated-prices-ids (unwrap!
(contract-call? 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2 verify-and-update-price-feeds
btc-price-feed
{
pyth-storage-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1,
pyth-decoder-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-pnau-decoder-v1,
wormhole-core-contract: 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.wormhole-core-v2
})
(err u0)))
(price (unwrap! (element-at? updated-prices-ids u0) (err u404))))
(ok price)))

Expand All @@ -53,6 +69,6 @@
(read-price-from-pyth 0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43))

(define-private (read-price-from-pyth (price-id (buff 32)))
(let ((feed (unwrap! (contract-call? 'SP19F0S4GN8CJQ4K9PKWRBVE00G2C86QTPTRXZ7GP.pyth-helper-v1 read-price price-id) (err u0)))
(let ((feed (unwrap! (contract-call? 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2 read-price-feed price-id 'ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-store-v1) (err u0)))
(price (get price feed)))
(ok (to-uint price))))
Loading

0 comments on commit 733a15e

Please sign in to comment.