Skip to content

Commit 20d8eec

Browse files
authored
Update sui docs and refer to docs page to avoid duplication (#1023)
1 parent 5a71466 commit 20d8eec

File tree

1 file changed

+5
-134
lines changed

1 file changed

+5
-134
lines changed

target_chains/sui/README.md

Lines changed: 5 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,9 @@
11
# Pyth on Sui
22

3-
### Contents
3+
This directory contains the Pyth contract for Sui and utilities to deploy and use it.
44

5-
1. Background
6-
2. How to Update and Consume Price Feeds
7-
3. Examples
8-
4. Contracts Registry (addresses)
9-
5. Common Questions how How to Integrate with Pyth on Sui
5+
- `cli` folder contains tools for deploying and upgrading the Pyth contract.
6+
- `contracts` folder contains the Pyth contract source code in Move.
7+
- `sdk` folder contains the Pyth javascript SDK for Sui that should be used by dApp developers.
108

11-
# 1. Background
12-
13-
Pyth price feeds on Sui are uniquely represented in the global store as `PriceInfoObjects`. These objects have the `key` ability and serve as wrappers around the `PriceInfo` object, which in turn contains the price info: namely the `PriceFeed`, the arrival time of the latest price update, and the attestation time of the latest update.
14-
15-
`PriceInfoObject`s are central to Pyth on Sui, since they are in unique correspondence with each Pyth price feed and must be passed in to functions that update price feeds or which query info about price feeds, e.g.
16-
17-
- `update_single_price_feed`
18-
- `update_single_price_feeds_if_fresh`
19-
- `get_price`
20-
21-
# 2. How to Update and Consume Price Feeds
22-
23-
We demo how to update and then consume a price feed by building a Sui [programmable transaction](https://docs.sui.io/build/prog-trans-ts-sdk) off-chain, and then executing it to update a price feed and get an updated price.
24-
25-
As with other chains, one first obtains a batch price attestation VAA (of type `vector<u8>`) from a Pyth price service endpoint, which encodes update price information for a feed.
26-
27-
### 1. `wormhole::vaa::parse_and_verify`
28-
29-
Call `parse_and_verify` on the batch attestation VAA bytes to obtain a `VAA` hot potato object.
30-
31-
```Rust
32-
public fun parse_and_verify(
33-
wormhole_state: &State,
34-
buf: vector<u8>, // price update VAA bytes
35-
the_clock: &Clock
36-
): VAA
37-
```
38-
39-
### 2. `pyth::pyth::update_single_price_feed`
40-
41-
Use the verified VAA and create a hot potato vector containing the latest price updates.
42-
43-
```Rust
44-
public fun create_price_infos_hot_potato(
45-
pyth_state: &PythState,
46-
verified_vaas: vector<VAA>,
47-
clock: &Clock
48-
): HotPotatoVector<PriceInfo>
49-
```
50-
51-
### 3.`pyth::pyth::update_single_price_feed`
52-
53-
Use the hot potato price updates vector to update a price feed.
54-
55-
Note that conventional Pyth price IDs are found [here](https://pyth.network/developers/price-feed-ids#pyth-evm-mainnet).
56-
However, instead of passing in a Pyth price feed ID to update the price feed (which is what is done on other chains), one must pass in a `PriceInfoObject` ID instead.
57-
58-
The `PriceInfoObject` IDs are distinct from Pyth price feed IDs, and are stored in a map on-chain (Pyth price feed ID => PriceInfoObject ID). The `PriceInfoObject` ID can queried on-chain by calling the `pyth::state::get_price_info_object_id` found in the Pyth package and off-chain by using the js sdk. See the common questions section below for more info.
59-
60-
```Rust
61-
public fun update_single_price_feed(
62-
pyth_state: &PythState,
63-
price_updates: HotPotatoVector<PriceInfo>,
64-
price_info_object: &mut PriceInfoObject,
65-
fee: Coin<SUI>,
66-
clock: &Clock
67-
): HotPotatoVector<PriceInfo>
68-
```
69-
70-
### 4.`pyth::hot_potato_vector::destroy`
71-
72-
Drop the hot potato. (You must call this function to drop the potato).
73-
74-
```Rust
75-
public fun destroy<T: copy + drop>(
76-
hot_potato_vector: HotPotatoVector<T>
77-
)
78-
```
79-
80-
### 5. `pyth::pyth::get_price`
81-
82-
Finally, get the price of the updated price feed in `PriceInfoObject` 🎉🎉🎉.
83-
84-
```Rust
85-
public fun get_price(
86-
state: &PythState,
87-
price_info_object: &PriceInfoObject,
88-
clock: &Clock
89-
): Price
90-
```
91-
92-
# 3. Examples
93-
94-
See the `cli` folder for examples of programmable transactions for creating price feeds and updating price feeds.
95-
96-
- [Demo for updating a price feed](cli/src/update_price_feeds.ts)
97-
98-
# 4. Contracts Registry
99-
100-
## Pyth on Testnet
101-
102-
- PYTH_STATE_ID: [0xd8afde3a48b4ff7212bd6829a150f43f59043221200d63504d981f62bff2e27a](https://explorer.sui.io/object/0xd8afde3a48b4ff7212bd6829a150f43f59043221200d63504d981f62bff2e27a?network=testnet)
103-
104-
## Wormhole on Testnet
105-
106-
- WORMHOLE_STATE_ID: [0xebba4cc4d614f7a7cdbe883acc76d1cc767922bc96778e7b68be0d15fce27c02](https://explorer.sui.io/object/0xebba4cc4d614f7a7cdbe883acc76d1cc767922bc96778e7b68be0d15fce27c02?network=testnet)
107-
108-
## Pyth on Mainnet
109-
110-
- PYTH_STATE_ID: [0xf9ff3ef935ef6cdfb659a203bf2754cebeb63346e29114a535ea6f41315e5a3f](https://explorer.sui.io/object/0xf9ff3ef935ef6cdfb659a203bf2754cebeb63346e29114a535ea6f41315e5a3f?network=https%3A%2F%2Ffullnode.mainnet.sui.io%3A443)
111-
112-
## Wormhole on Mainnet
113-
114-
- WORMHOLE_STATE_ID: [0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c](https://explorer.sui.io/object/0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c)
115-
116-
# 5. Common Questions on How to Integrate with Pyth on Sui
117-
118-
## 1. What is up with the "sui rev"? (`09b2081498366df936abae26eea4b2d5cafb2788`). Why does it point to a specific commit hash instead of "main" or "devnet"?
119-
120-
Our Pyth `Move.toml` file contains the following dependencies. It depends on specific versions of the [Sui Framework](https://github.com/MystenLabs/sui) as well as [Wormhole](https://github.com/wormhole-foundation/wormhole). To make your Sui package compatible, you must also specify the following dependencies verbatim in your `Move.toml` file. We are locked in to this specific `rev` because our package depends on Wormhole, which [uses the `rev` `09b2081498366df936abae26eea4b2d5cafb2788`](https://github.com/wormhole-foundation/wormhole/blob/main/sui/wormhole/Move.mainnet.toml).
121-
122-
```
123-
[dependencies.Sui]
124-
git = "https://github.com/MystenLabs/sui.git"
125-
subdir = "crates/sui-framework/packages/sui-framework"
126-
rev = "09b2081498366df936abae26eea4b2d5cafb2788"
127-
128-
[dependencies.Wormhole]
129-
git = "https://github.com/wormhole-foundation/wormhole.git"
130-
subdir = "sui/wormhole"
131-
rev = "d050ad1d67a5b7da9fb65030aad12ef5d774ccad"
132-
```
133-
134-
## 2. How do I find the Sui Object ID of a PriceInfoObject for a Pyth Price Feed?
135-
136-
This mapping is stored on-chain, and can be queried on-chain using the getter function `pyth::state::get_price_info_object_id` defined in the Pyth package.
137-
138-
You can also use the sdk utility functions to find the object Ids off-chain.
9+
For more information regarding Pyth integration on Sui please refer to our [docs](https://docs.pyth.network/documentation/pythnet-price-feeds/sui).

0 commit comments

Comments
 (0)