Skip to content

Commit 27e6db5

Browse files
stacks updated contract (#841)
1 parent 2c2ee9b commit 27e6db5

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pages/price-feeds/use-real-time-data/stacks.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This guide explains how to use real-time Pyth data in [Clarity](https://clarity-
1313
## Write Contract Code
1414

1515
The Pyth protocol integration for Stacks is available as a Beta on both testnet and mainnet networks, to help developers test, give feedback, and ensure the reliability and stability of the integration.
16-
Unlike other smart contract languages, there is no importing modules into Clarity smart contracts for certain security reasons. So the Pyth integration on Stacks is implemented as its own set of Clarity contracts where developers will invoke a `contract-call?` to the main Pyth Clarity [contract](https://explorer.hiro.so/txid/SP3R4F6C1J3JQWWCVZ3S7FRRYPMYG6ZW6RZK31FXY.pyth-oracle-v3?chain=mainnet).
16+
Unlike other smart contract languages, there is no importing modules into Clarity smart contracts for certain security reasons. So the Pyth integration on Stacks is implemented as its own set of Clarity contracts where developers will invoke a `contract-call?` to the main Pyth Clarity [contract](https://explorer.hiro.so/txid/SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.pyth-oracle-v4?chain=mainnet).
1717

1818
<Callout type="info" emoji="ℹ️">
1919
Currently, the Pyth protocol integration is currently maintained by Trust
@@ -28,7 +28,7 @@ For our example, we will imagine a contract that mints an NFT in exchange for $1
2828

2929
<Callout type="info" emoji="ℹ️">
3030
The maintained Pyth integration contract for Stacks is called
31-
[`.pyth-oracle-v3`](https://explorer.hiro.so/txid/0x745a0e07ef9487ebb2190da515bda60f1531299553420750b33b3ba4a97729e1?chain=mainnet).
31+
[`.pyth-oracle-v4`](https://explorer.hiro.so/txid/SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.pyth-oracle-v4?chain=mainnet).
3232
This contract serves as the main entry point for updating and getting price
3333
feed data.
3434
</Callout>
@@ -45,24 +45,24 @@ You'll notice in the Clarity snippet below we open up `let` bindings of our func
4545
;; To verify & update price feeds is to participate in the pull price model of Pyth's decentralization.
4646
;; A VAA signed message is pulled from Wormhole via the Hermes API. This VAA signed message is what
4747
;; gets passed into this function to verify & update the price data of a particular price feed.
48-
(update-status (try! (contract-call? 'SP3R4F6C1J3JQWWCVZ3S7FRRYPMYG6ZW6RZK31FXY.pyth-oracle-v3
48+
(update-status (try! (contract-call? 'SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.pyth-oracle-v4
4949
verify-and-update-price-feeds price-feed-bytes {
50-
pyth-storage-contract: 'SP3R4F6C1J3JQWWCVZ3S7FRRYPMYG6ZW6RZK31FXY.pyth-storage-v3,
51-
pyth-decoder-contract: 'SP3R4F6C1J3JQWWCVZ3S7FRRYPMYG6ZW6RZK31FXY.pyth-pnau-decoder-v2,
52-
wormhole-core-contract: 'SP3R4F6C1J3JQWWCVZ3S7FRRYPMYG6ZW6RZK31FXY.wormhole-core-v3,
50+
pyth-storage-contract: 'SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.pyth-storage-v4,
51+
pyth-decoder-contract: 'SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.pyth-pnau-decoder-v3,
52+
wormhole-core-contract: 'SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.wormhole-core-v4,
5353
})))
5454
;; The price data returned will be fresh from the VAA signed message data we passed in above.
55-
(price-data (try! (contract-call? 'SP3R4F6C1J3JQWWCVZ3S7FRRYPMYG6ZW6RZK31FXY.pyth-oracle-v3
55+
(price-data (try! (contract-call? 'SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.pyth-oracle-v4
5656
get-price
5757
;; The official BTC price feed id.
5858
0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
59-
'SP3R4F6C1J3JQWWCVZ3S7FRRYPMYG6ZW6RZK31FXY.pyth-storage-v3
59+
'SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.pyth-storage-v4
6060
)))
6161
;; --snip--
6262
```
6363

6464
After updating & verifying the price feed in question, and then getting the updated price feed data, we'll need to handle the price feed data and its properties.
65-
The price feed data returned from invoking the `get-price` function of the `.pyth-oracle-v3` contract looks like the below:
65+
The price feed data returned from invoking the `get-price` function of the `.pyth-oracle-v4` contract looks like the below:
6666

6767
```bash
6868
{
@@ -114,11 +114,11 @@ We can then determine the USD amount of sBTC the user owns and decide if it is e
114114
```
115115

116116
<Callout type="warning" emoji="⚠️">
117-
The `verify-and-update-price-feeds` of the `.pyth-oracle-v3` contract applies
117+
The `verify-and-update-price-feeds` of the `.pyth-oracle-v4` contract applies
118118
a fee of 1 uSTX, or 1 micro-stx, which is 0.000001 STX.
119119
</Callout>
120120

121-
Alternatively, developers can just invoke the `read-price-feed` public function of the `pyth-oracle-v3.clar` contract. This will simply return the price feed from the last updated feed. But it's always encouraged to determine if a staleness check is viable for your application.
121+
Alternatively, developers can just invoke the `read-price-feed` public function of the `pyth-oracle-v4.clar` contract. This will simply return the price feed from the last updated feed. But it's always encouraged to determine if a staleness check is viable for your application.
122122

123123
## Write Front-End Code
124124

@@ -164,7 +164,7 @@ const response = await request("stx_callContract", {
164164
});
165165
```
166166

167-
If you noticed, we set a post-condition statement of our user transferring less than or equal to 1 uSTX, which is 0.000001 STX. This is because the `verify-and-update-price-feeds` of the `.pyth-oracle-v3` contract applies a fee for this. Setting a separate post-condition statement on the actual sbtc token transfer in our example will also be needed. Beforehand, you could invoke the `decode-price-feeds` function with the `latestVaaHex` to simply have the contained price data decoded and returned. From there you could pre-determine the estimated amount of sbtc tokens to be transferred and set in a separate post-condition.
167+
If you noticed, we set a post-condition statement of our user transferring less than or equal to 1 uSTX, which is 0.000001 STX. This is because the `verify-and-update-price-feeds` of the `.pyth-oracle-v4` contract applies a fee for this. Setting a separate post-condition statement on the actual sbtc token transfer in our example will also be needed. Beforehand, you could invoke the `decode-price-feeds` function with the `latestVaaHex` to simply have the contained price data decoded and returned. From there you could pre-determine the estimated amount of sbtc tokens to be transferred and set in a separate post-condition.
168168

169169
## Additional Resources
170170

@@ -173,4 +173,4 @@ You may find these additional resources helpful for developing your Stacks appli
173173
- **[Hiro Docs](https://docs.hiro.so/resources/guides/using-pyth-price-feeds):** Check out the dedicated guide for using Pyth in Stacks applications in Hiro's documentation. In this guide you'll see a visual architecture overview of using Pyth in Stacks, how you can test your implementation, how to fetch VAAs on the front-end, learn best practices, and more.
174174
- **[Hiro How-To Tutorial](https://youtu.be/eybqQVRh_hw?si=KNfUp3RS3CnaST91):** Watch the dedicated video tutorial on using Pyth in Stacks and learn how a major Stacks DeFi app, Granite, is using Pyth.
175175
- **[Trust Machine's Pyth Github](https://github.com/Trust-Machines/stacks-pyth-bridge):** Check out the open-source repo for the Pyth integration Clarity contracts.
176-
- **[pyth-oracle-v3.clar](https://explorer.hiro.so/txid/SP3R4F6C1J3JQWWCVZ3S7FRRYPMYG6ZW6RZK31FXY.pyth-oracle-v3?chain=mainnet):** The latest Pyth integration contract on Stacks' mainnet.
176+
- **[pyth-oracle-v4.clar](https://explorer.hiro.so/txid/SP1CGXWEAMG6P6FT04W66NVGJ7PQWMDAC19R7PJ0Y.pyth-oracle-v4?chain=mainnet):** The latest Pyth integration contract on Stacks' mainnet.

0 commit comments

Comments
 (0)