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

chore: update cbtc example #36

Merged
merged 7 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 21 additions & 3 deletions .github/workflows/run-unit-tests.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,29 @@ on:
branches: [ "main" ]

jobs:
build:
unit-tests:
runs-on: ubuntu-latest


strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test

cbtc-unit-tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
Expand All @@ -26,4 +42,6 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
working-directory: ./example/cbtc
- run: npm test
working-directory: ./example/cbtc
9 changes: 9 additions & 0 deletions example/cbtc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@
**/settings/Testnet.toml
.requirements/
history.txt

# Ignore Node and NPM files. Added by the clarinet-sdk migration.
logs
*.log
npm-debug.log*
coverage
*.info
costs-reports.json
node_modules
7 changes: 3 additions & 4 deletions example/cbtc/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

{
"deno.enable": true,
"files.eol": "\n"
}
"deno.enable": false,
"files.eol": "\n"
}
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
9 changes: 9 additions & 0 deletions example/cbtc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,12 @@ and
```bash
clarinet deployment apply -p deployments/unwrap-btc.devnet-plan.yaml
```

## Run the unit tests

Install the npm dependencies and run the test:

```bash
npm install
npm test
```
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))))
180 changes: 69 additions & 111 deletions example/cbtc/deployments/default.simnet-plan.yaml

Large diffs are not rendered by default.

Loading
Loading