Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Port to Clarity V3 and fix tests #43

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6d43fd4
fix test
Oct 4, 2024
83fa8c7
add read-only function
hackercf Oct 9, 2024
ce0fec1
update testnet deployment
hackercf Oct 18, 2024
e2ee006
expo override
Oct 10, 2024
7068d3e
testnet utility function to set the price
Oct 16, 2024
727e58a
readme upgrade notes
Oct 16, 2024
dc20d1d
update testnet plan
hackercf Oct 18, 2024
3180314
update deployment
hackercf Oct 23, 2024
fcd10fa
prepare storage contract changes
hackercf Oct 28, 2024
0acefea
update deployments
hackercf Oct 30, 2024
29d576a
update mainnetplan
hackercf Nov 5, 2024
68b7ea5
include additional block time in the staleness check
hackercf Nov 27, 2024
3abec48
allow emty price updates with zero fees charged
hackercf Nov 27, 2024
67b2e81
fix L-01
hackercf Dec 2, 2024
fa309ab
fix skipping over invalid uncompressed addresses
hackercf Dec 2, 2024
b8a8452
set initial fee to 1
hackercf Dec 3, 2024
0b1f808
ensure only deployer can update the first guardian set
hackercf Dec 2, 2024
57433bf
ensure new emitter sequence is set when governance data source is upd…
hackercf Dec 3, 2024
cb16381
fix L-03
hackercf Dec 4, 2024
de6f73c
fix L-07
hackercf Dec 4, 2024
81c991c
fix L-05
hackercf Dec 4, 2024
2b0cf3f
fix L-06
hackercf Dec 4, 2024
3260a00
minor updates
hackercf Dec 5, 2024
638985f
additional overlay checks
hackercf Dec 5, 2024
dcb24c1
fix L-10
hackercf Dec 5, 2024
73a2ac4
further fixes
hackercf Dec 5, 2024
f9322c7
fix QA-01
hackercf Dec 6, 2024
f65bd34
fix QA-02
hackercf Dec 6, 2024
e354771
fix QA-03
hackercf Dec 6, 2024
90878a9
fix QA-04
hackercf Dec 6, 2024
0ec1468
fix QA-06
hackercf Dec 6, 2024
e449d67
fix QA-07
hackercf Dec 6, 2024
b0f8a7a
fix QA-08
hackercf Dec 6, 2024
1731803
fix QA-09
hackercf Dec 6, 2024
6b3bb72
fix QA-10
hackercf Dec 6, 2024
821c9f2
fix QA-11
hackercf Dec 6, 2024
bbd4fc0
fix QA-12
hackercf Dec 6, 2024
bf5c9c7
fix QA-13
hackercf Dec 6, 2024
8d1635e
fix QA-14
hackercf Dec 6, 2024
261afb1
fix QA-10
hackercf Dec 9, 2024
9bb51f5
fix QA-16
hackercf Dec 9, 2024
32320e0
fix R-QA-01
hackercf Dec 9, 2024
4f5b261
fix L-11
hackercf Dec 9, 2024
972a6b9
fix L-12
hackercf Dec 9, 2024
0141219
fix L-13
hackercf Dec 9, 2024
ef05980
fix M-04 and QA-02
hackercf Dec 9, 2024
5a7b525
fix typos
hackercf Dec 9, 2024
ad57219
fix QA-10
hackercf Dec 9, 2024
086fff0
Adding 'audits' folder
blaizew Dec 16, 2024
2dad5c4
update helper functions
hackercf Dec 18, 2024
eaae239
deploy pyth to mainnet
hackercf Jan 7, 2025
6f90fa3
Merge pull request #16 from Trust-Machines/pyth_mainnet
hackercf Jan 7, 2025
bea7ebf
Add files via upload
blaizew Jan 9, 2025
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
54 changes: 27 additions & 27 deletions Clarinet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,40 @@ contract_id = 'SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-ecc-v1'
[[project.requirements]]
contract_id = 'SP2J933XB2CP2JQ1A4FGN8JA968BBG3NK3EKZ7Q9F.hk-merkle-tree-keccak160-v1'

[contracts.pyth-governance-v1]
path = 'contracts/pyth-governance-v1.clar'
clarity_version = 2
epoch = 2.4

[contracts.pyth-oracle-v2]
path = 'contracts/pyth-oracle-v2.clar'
clarity_version = 2
epoch = 2.4

[contracts.pyth-store-v1]
path = 'contracts/pyth-store-v1.clar'
clarity_version = 2
epoch = 2.4

[contracts.pyth-pnau-decoder-v1]
path = 'contracts/pyth-pnau-decoder-v1.clar'
clarity_version = 2
epoch = 2.4
[contracts.pyth-governance-v2]
path = 'contracts/pyth-governance-v2.clar'
clarity_version = 3
epoch = 3.0

[contracts.pyth-oracle-v3]
path = 'contracts/pyth-oracle-v3.clar'
clarity_version = 3
epoch = 3.0

[contracts.pyth-storage-v3]
path = 'contracts/pyth-storage-v3.clar'
clarity_version = 3
epoch = 3.0

[contracts.pyth-pnau-decoder-v2]
path = 'contracts/pyth-pnau-decoder-v2.clar'
clarity_version = 3
epoch = 3.0

[contracts.pyth-traits-v1]
path = 'contracts/pyth-traits-v1.clar'
clarity_version = 2
epoch = 2.4
clarity_version = 3
epoch = 3.0

[contracts.wormhole-core-v2]
path = 'contracts/wormhole/wormhole-core-v2.clar'
clarity_version = 2
epoch = 2.4
[contracts.wormhole-core-v3]
path = 'contracts/wormhole/wormhole-core-v3.clar'
clarity_version = 3
epoch = 3.0

[contracts.wormhole-traits-v1]
path = 'contracts/wormhole/wormhole-traits-v1.clar'
clarity_version = 2
epoch = 2.4
clarity_version = 3
epoch = 3.0

[repl.analysis]
passes = ['check_checker']
Expand Down
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Stacks <> Pyth - edited by Granite team

/ / ▶ Stacks Pyth Bridge
/ --- / Bridging Pyth price feeds to the Stacks blockchain.
/ / Retrieve trading pairs (BTC-USD, STX-USD, etc.) from Clarity smart contracts.
Expand Down Expand Up @@ -43,12 +45,12 @@ $ npm test

| network | address |
| ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| testnet | [ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v2](https://explorer.hiro.so/txid/0x59dc127b983fcb8027706191b62138eb73a3ade8ecdbad5e99df4d2bfbbd6dfb?chain=testnet) |
| mainnet | [SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-oracle-v2](https://explorer.hiro.so/txid/0xee803f98e61c1d46d36d130c29d4a78099c8fb5700528226f3dc5a104954ffeb?chain=mainnet) |
| testnet | [ST2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY1JKX06E.pyth-oracle-v3](https://explorer.hiro.so/txid/0x59dc127b983fcb8027706191b62138eb73a3ade8ecdbad5e99df4d2bfbbd6dfb?chain=testnet) |
| mainnet | [SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-oracle-v3](https://explorer.hiro.so/txid/0xee803f98e61c1d46d36d130c29d4a78099c8fb5700528226f3dc5a104954ffeb?chain=mainnet) |

### Onchain

The `pyth-oracle-v2` contract is exposing the following method:
The `pyth-oracle-v3` contract is exposing the following method:

```clarity
(define-public (read-price-feed
Expand All @@ -60,10 +62,10 @@ That can be consumed with the following invocation:

```clarity
(contract-call?
'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-oracle-v2 ;; Address of the helper contract
'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-oracle-v3 ;; Address of the helper contract
read-price-feed
0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43 ;; BTC-USD price identifier
'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-store-v1)
'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-storage-v1)
```

The authenticity of the price feeds is verified during their ingestion, making the cost of queries as light as possible.
Expand All @@ -78,7 +80,7 @@ The full list of prices is available [here](https://pyth.network/price-feeds/).

### Offchain

For every new price recorded and stored on chain, the `pyth-store-v1` is emitting an event with the following shape:
For every new price recorded and stored on chain, the `pyth-storage-v1` is emitting an event with the following shape:

```clarity
{
Expand Down Expand Up @@ -115,19 +117,19 @@ $ curl https://hermes.pyth.network/api/latest_price_feeds?ids[]=ec7a775f46379b5e
504e41550100000003b8...a7b10321ad7c2404a910
```

This sequence of bytes is a Verified Action Approvals (VAA) including the price informations including its cryptographic elements helping the Pyth contract ensuring the authenticity of the data.
This sequence of bytes is a Verified Action Approvals (VAA) including the price information including its cryptographic elements helping the Pyth contract ensuring the authenticity of the data.

This VAA can be encoded as a Clarity buffer, and submitted to the Pyth contract using the following:

```clarity
(contract-call?
'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-oracle-v2 ;; Address of the helper contract
'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-oracle-v3 ;; Address of the helper contract
verify-and-update-price
0x504e41550100000003b8...a7b10321ad7c2404a910 ;; BTC-USD price update
{
pyth-storage-contract: 'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-store-v1,
pyth-decoder-contract: 'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-pnau-decoder-v1,
wormhole-core-contract: 'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.wormhole-core-v2
pyth-storage-contract: 'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-storage-v1,
pyth-decoder-contract: 'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.pyth-pnau-decoder-v2,
wormhole-core-contract: 'SP2T5JKWWP3FYYX4YRK8GK5BG2YCNGEAEY2P2PKN0.wormhole-core-v3
})
```

Expand All @@ -150,3 +152,9 @@ If the VAA is valid, the contract call will return a payload with the following

Including all the prices successfully updating the oracle.
All of the implementation details can be found in [Pyth documentation](https://docs.pyth.network/documentation/how-pyth-works).

# Upgrades

- Ported the codebase to Clarity V3
- bump up nodejs dependencies
- introduced a utility function `set-price-testnet` in the `pyth-storage-v1` contract to set the price data for a specific feed without the need to produce a valid attestation. This function will only work on testnet.
1 change: 1 addition & 0 deletions audits/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Loading