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

Port to Clarity V3 and fix tests #43

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6d43fd4
fix test
Oct 4, 2024
a48d1cf
add read-only function
vedhavyas Oct 9, 2024
3c3d8b7
expo override
Oct 10, 2024
55834b7
testnet utility function to set the price
Oct 16, 2024
fd4b72b
readme upgrade notes
Oct 16, 2024
ca9b04f
update testnet deployment
vedhavyas Oct 18, 2024
2b480eb
Merge branch 'clarity-v3' of cf.github.com:Trust-Machines/stacks-pyth…
vedhavyas Oct 18, 2024
a746a1f
update testnet plan
vedhavyas Oct 18, 2024
f11de17
update deployment
vedhavyas Oct 23, 2024
05f6d58
prepare storage contract changes
vedhavyas Oct 28, 2024
05b15da
Merge pull request #2 from Trust-Machines/prepare_storage_upgrade
hackercf Oct 28, 2024
1af2888
update deployments
vedhavyas Oct 30, 2024
0d478c9
update mainnetplan
vedhavyas Nov 5, 2024
f68832f
include additional block time in the staleness check
vedhavyas Nov 27, 2024
be2513d
allow emty price updates with zero fees charged
vedhavyas Nov 27, 2024
09ad91c
fix skipping over invalid uncompressed addresses
vedhavyas Dec 2, 2024
5b83ed6
Merge pull request #3 from Trust-Machines/GRNT-1112
hackercf Dec 2, 2024
a685a68
fix L-01
vedhavyas Dec 2, 2024
83084a2
Merge pull request #4 from Trust-Machines/GRNT-1113
hackercf Dec 2, 2024
d1f1c0a
Merge pull request #5 from Trust-Machines/GRNT-1136
hackercf Dec 2, 2024
b57b9da
ensure only deployer can update the first guardian set
vedhavyas Dec 2, 2024
9c8a660
ensure new emitter sequence is set when governance data source is upd…
vedhavyas Dec 3, 2024
b6a8476
set initial fee to 1
vedhavyas Dec 3, 2024
78bc3ec
Merge pull request #8 from Trust-Machines/GRNT-1153
hackercf Dec 3, 2024
30caebd
Merge pull request #6 from Trust-Machines/GRNT-1138
hackercf Dec 3, 2024
cd01e5b
Merge pull request #7 from Trust-Machines/GRNT-1152
hackercf Dec 4, 2024
5093342
fix L-03
vedhavyas Dec 4, 2024
96aee20
fix L-05
vedhavyas Dec 4, 2024
9521b79
fix L-06
vedhavyas Dec 4, 2024
15a9dbc
fix L-07
vedhavyas Dec 4, 2024
f63e6a0
Merge pull request #9 from Trust-Machines/GRNT-1159
hackercf Dec 5, 2024
ab30354
Merge pull request #11 from Trust-Machines/GRNT-1162
hackercf Dec 5, 2024
16fa29e
minor updates
vedhavyas Dec 5, 2024
75b14a0
Merge pull request #10 from Trust-Machines/GRNT-1160
hackercf Dec 5, 2024
566ad7f
additional overlay checks
vedhavyas Dec 5, 2024
0b863d3
fix L-10
vedhavyas Dec 5, 2024
d74dd20
further fixes
vedhavyas Dec 5, 2024
2f4ab60
Merge pull request #12 from Trust-Machines/GRNT-1164
hackercf Dec 6, 2024
b9ef90b
fix QA-01
vedhavyas Dec 6, 2024
af443cf
fix QA-02
vedhavyas Dec 6, 2024
139a31c
fix QA-03
vedhavyas Dec 6, 2024
7651431
fix QA-04
vedhavyas Dec 6, 2024
cee9e13
fix QA-06
vedhavyas Dec 6, 2024
03b3247
fix QA-07
vedhavyas Dec 6, 2024
fb36a24
fix QA-08
vedhavyas Dec 6, 2024
da575fb
fix QA-09
vedhavyas Dec 6, 2024
e5d622e
fix QA-10
vedhavyas Dec 6, 2024
e991db6
fix QA-11
vedhavyas Dec 6, 2024
2b2a6bc
fix QA-12
vedhavyas Dec 6, 2024
b373bb7
fix QA-13
vedhavyas Dec 6, 2024
b570adb
fix QA-14
vedhavyas Dec 6, 2024
5e1cf57
fix QA-10
vedhavyas Dec 9, 2024
66d98aa
fix QA-16
vedhavyas Dec 9, 2024
6f7cbb7
fix R-QA-01
vedhavyas Dec 9, 2024
a1f15b0
fix L-11
vedhavyas Dec 9, 2024
60d4d43
fix L-12
vedhavyas Dec 9, 2024
a6c5ccb
fix L-13
vedhavyas Dec 9, 2024
1c44f22
fix M-04 and QA-02
vedhavyas Dec 9, 2024
730fc00
fix typos
vedhavyas Dec 9, 2024
80ccd04
fix QA-10
vedhavyas Dec 9, 2024
c491c62
Merge pull request #13 from Trust-Machines/qa_fixes
hackercf Dec 9, 2024
a3a84b2
Merge pull request #14 from Trust-Machines/low_fixes
hackercf Dec 9, 2024
ba629c5
Merge pull request #15 from Trust-Machines/GRNT-1171
hackercf Dec 9, 2024
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.
Loading