|
@@ -6,15 +6,14 @@ Pyth price feeds on Sui are uniquely represented in the global store as `PriceIn
|
|
|
|
|
|
|
|
`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 act on price feeds, e.g.
|
|
`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 act on price feeds, e.g.
|
|
|
|
|
|
|
|
-- `update_price_feeds`
|
|
|
|
|
-- `update_price_feed_from_single_vaa`
|
|
|
|
|
-- `update_price_feeds_if_fresh`
|
|
|
|
|
|
|
+- `update_single_price_feed`
|
|
|
|
|
+- `update_single_pric_feeds_if_fresh`
|
|
|
|
|
|
|
|
## 2. How to Update and Consume Price Feeds
|
|
## 2. How to Update and Consume Price Feeds
|
|
|
|
|
|
|
|
To update and then consume a price feed, one needs to build a Sui [programmable transaction](https://docs.sui.io/build/prog-trans-ts-sdk).
|
|
To update and then consume a price feed, one needs to build a Sui [programmable transaction](https://docs.sui.io/build/prog-trans-ts-sdk).
|
|
|
|
|
|
|
|
-As with other chains, one first obtains a batch price attestation VAA (of type `vector<u8>`) off-chain for a Price Info Object whose feed is to be used. Assume the ID is `PRICE_INFO_OBJECT_ID`. Then, chain together the following sequence of function calls to update a price feed.
|
|
|
|
|
|
|
+As with other chains, one first obtains a batch price attestation VAA (of type `vector<u8>`) off-chain for a Price Info Object whose feed is to be used. Then, chain together the following sequence of function calls to update a price feed.
|
|
|
|
|
|
|
|
### 1. `wormhole::wormhole::parse_and_verify`
|
|
### 1. `wormhole::wormhole::parse_and_verify`
|
|
|
|
|
|
|
@@ -28,7 +27,7 @@ public fun parse_and_verify(
|
|
|
): VAA
|
|
): VAA
|
|
|
```
|
|
```
|
|
|
### 2. `pyth::pyth::update_single_price_feed`
|
|
### 2. `pyth::pyth::update_single_price_feed`
|
|
|
-Use the verified VAA and create a hot potato containing price updates.
|
|
|
|
|
|
|
+Use the verified VAA and create a hot potato vector containing the latest price updates.
|
|
|
```Rust
|
|
```Rust
|
|
|
public fun create_price_infos_hot_potato(
|
|
public fun create_price_infos_hot_potato(
|
|
|
pyth_state: &PythState,
|
|
pyth_state: &PythState,
|
|
@@ -38,7 +37,7 @@ public fun create_price_infos_hot_potato(
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
### 3.`pyth::pyth::update_single_price_feed`
|
|
### 3.`pyth::pyth::update_single_price_feed`
|
|
|
-Use the hot potato to update a price feed.
|
|
|
|
|
|
|
+Use the hot potato price updates vector to update a price feed.
|
|
|
|
|
|
|
|
```Rust
|
|
```Rust
|
|
|
public fun update_single_price_feed(
|
|
public fun update_single_price_feed(
|
|
@@ -58,7 +57,7 @@ public fun destroy<T: copy + drop>(
|
|
|
)
|
|
)
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-### 5. `pyth::get_price`
|
|
|
|
|
|
|
+### 5. `pyth::pyth::get_price`
|
|
|
Finally, get the price of the updated price feed in `PriceInfoObject` 🎉🎉🎉.
|
|
Finally, get the price of the updated price feed in `PriceInfoObject` 🎉🎉🎉.
|
|
|
```Rust
|
|
```Rust
|
|
|
public fun get_price(
|
|
public fun get_price(
|
|
@@ -67,14 +66,12 @@ public fun get_price(
|
|
|
clock: &Clock
|
|
clock: &Clock
|
|
|
): Price
|
|
): Price
|
|
|
```
|
|
```
|
|
|
-
|
|
|
|
|
-Fetch the price of the updated Price Info Object.
|
|
|
|
|
|
|
+This looks like a long sequence of calls to update a price feed, but programmable transactions make it easy. (See demos below).
|
|
|
|
|
|
|
|
## 3. Examples
|
|
## 3. Examples
|
|
|
|
|
|
|
|
See the `./scripts` folder for examples of programmable transactions for creating price feeds and updating price feeds.
|
|
See the `./scripts` folder for examples of programmable transactions for creating price feeds and updating price feeds.
|
|
|
- [Demo for updating a price feed](./scripts/pyth/update_price_feeds.ts)
|
|
- [Demo for updating a price feed](./scripts/pyth/update_price_feeds.ts)
|
|
|
-- [Demo for creating new price feeds](./scripts/pyth/create_all_price_feeds.ts)
|
|
|
|
|
|
|
|
|
|
To build and test the contracts, run the following
|
|
To build and test the contracts, run the following
|
|
|
```
|
|
```
|