|
| 1 | +# Pyth on Sui |
| 2 | + |
| 3 | +## 1. Background |
| 4 | + |
| 5 | +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 wraps around the `PriceFeed`, the arrival time of the latest price update, and the attestation time of the latest update. |
| 6 | + |
| 7 | +`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. |
| 8 | + |
| 9 | +- `update_price_feeds` |
| 10 | +- `update_price_feed_from_single_vaa` |
| 11 | +- `update_price_feeds_if_fresh` |
| 12 | + |
| 13 | +## 2. How to Update and Consume Price Feeds |
| 14 | + |
| 15 | +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). |
| 16 | + |
| 17 | +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: |
| 18 | + |
| 19 | +### 1. `wormhole::parse_and_verify` |
| 20 | + |
| 21 | +Call `parse_and_verify` on the batch attestation VAA bytes to obtain a `VAA` hot potato object. |
| 22 | + |
| 23 | +```Rust |
| 24 | +public fun parse_and_verify( |
| 25 | + wormhole_state: &State, |
| 26 | + buf: vector<u8>, |
| 27 | + the_clock: &Clock |
| 28 | + ): VAA |
| 29 | +``` |
| 30 | + |
| 31 | +### 2.`pyth:update_price_feeds` |
| 32 | + |
| 33 | +Vectorize the `VAA` from the previous step and pass it to `update_price_feeds`. |
| 34 | + |
| 35 | +```Rust |
| 36 | + public fun update_price_feeds( |
| 37 | + pyth_state: &PythState, |
| 38 | + verified_vaas: vector<VAA>, |
| 39 | + price_info_objects: &mut vector<PriceInfoObject>, |
| 40 | + fee: Coin<SUI>, |
| 41 | + clock: &Clock |
| 42 | + ) |
| 43 | +``` |
| 44 | + |
| 45 | +### 3. `pyth::get_price` |
| 46 | + |
| 47 | +Finally, get the price of the updated price feed in `PriceInfoObject`. |
| 48 | + |
| 49 | +```Rust |
| 50 | +public fun get_price( |
| 51 | + state: &PythState, |
| 52 | + price_info_object: &PriceInfoObject, |
| 53 | + clock: &Clock |
| 54 | +): Price |
| 55 | +``` |
| 56 | + |
| 57 | +Fetch the price of the updated Price Info Object. |
| 58 | + |
| 59 | +## 3. Examples |
| 60 | + |
| 61 | +See the `./scripts` folder for examples of programmable transactions for creating price feeds, updating price feeds, and deploying contracts. |
| 62 | + |
| 63 | +To build and test the contracts, run the following |
| 64 | + |
| 65 | +``` |
| 66 | +$ make test |
| 67 | +$ make build |
| 68 | +``` |
| 69 | + |
| 70 | +## 4. Contracts Registry |
| 71 | + |
| 72 | +## Pyth on Testnet |
| 73 | + |
| 74 | +- PYTH_PACKAGE_ID: [0x7c017b047a3c9db5a8f4586d347c54869b761b6d6b0882a179823e8642faf7b9](https://explorer.sui.io/object/0x7c017b047a3c9db5a8f4586d347c54869b761b6d6b0882a179823e8642faf7b9) |
| 75 | +- PYTH_STATE_ID: [0x3fc17e66d5ced3bf62f3fe8289cb2cb78c311a1e1c9700727ecd278d242e9e88](https://explorer.sui.io/object/0x3fc17e66d5ced3bf62f3fe8289cb2cb78c311a1e1c9700727ecd278d242e9e88) |
| 76 | + |
| 77 | +## Wormhole on Testnet |
| 78 | + |
| 79 | +- WORMHOLE_PACKAGE_ID: [0x80c60bff35fe5026e319cf3d66ae671f2b4e12923c92c45df75eaf4de79e3ce7](https://explorer.sui.io/object/0x80c60bff35fe5026e319cf3d66ae671f2b4e12923c92c45df75eaf4de79e3ce7) |
| 80 | +- WORMHOLE_STATE_ID: [0x79ab4d569f7eb1efdcc1f25b532f8593cda84776206772e33b490694cb8fc07a](https://explorer.sui.io/object/0x79ab4d569f7eb1efdcc1f25b532f8593cda84776206772e33b490694cb8fc07a) |
| 81 | + |
| 82 | +## Pyth on Mainnet |
| 83 | + |
| 84 | +- PYTH_PACKAGE_ID: [0xa446c4a37c0bb69d03357c1a52d60da0b434048226d5f3feffdb693586bea861](https://explorer.sui.io/object/0xa446c4a37c0bb69d03357c1a52d60da0b434048226d5f3feffdb693586bea861?network=https%3A%2F%2Ffullnode.mainnet.sui.io%3A443) |
| 85 | +- PYTH_STATE_ID: [0x428b5795904d5256d1eea5991df672934315fb8dcf8f6111134c1a52afd005ca](https://explorer.sui.io/object/0x428b5795904d5256d1eea5991df672934315fb8dcf8f6111134c1a52afd005ca?network=https%3A%2F%2Ffullnode.mainnet.sui.io%3A443) |
| 86 | + |
| 87 | +## Wormhole on Mainnet |
| 88 | + |
| 89 | +- WORMHOLE_PACKAGE_ID: [0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a](https://explorer.sui.io/object/0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a) |
| 90 | +- WORMHOLE_STATE_ID: [0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c](https://explorer.sui.io/object/0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c) |
0 commit comments