From ce03e909ecd3e3115c6c42c9557dd15f92e00bf2 Mon Sep 17 00:00:00 2001 From: optke3 Date: Fri, 4 Aug 2023 22:30:33 +0000 Subject: [PATCH 01/11] start sui docs --- pages/_meta.json | 5 ++ pages/sui/get-ema-price-no-older-than.mdx | 70 ++++++++++++++++++ pages/sui/get-ema-price-unsafe.mdx | 63 ++++++++++++++++ pages/sui/get-ema-price.mdx | 65 ++++++++++++++++ pages/sui/get-price-no-older-than.mdx | 70 ++++++++++++++++++ pages/sui/get-price-unsafe.mdx | 62 ++++++++++++++++ pages/sui/get-price.mdx | 64 ++++++++++++++++ pages/sui/get-stale-price-threshold-secs.mdx | 24 ++++++ pages/sui/get-update-fee.mdx | 60 +++++++++++++++ pages/sui/index.mdx | 13 ++++ pages/sui/meta.json | 23 ++++++ pages/sui/price-feed-exists.mdx | 55 ++++++++++++++ pages/sui/sdks.mdx | 41 ++++++++++ pages/sui/update-price-feeds-with-funder.mdx | 69 +++++++++++++++++ pages/sui/update-single-price-feed.mdx | 78 ++++++++++++++++++++ 15 files changed, 762 insertions(+) create mode 100644 pages/sui/get-ema-price-no-older-than.mdx create mode 100644 pages/sui/get-ema-price-unsafe.mdx create mode 100644 pages/sui/get-ema-price.mdx create mode 100644 pages/sui/get-price-no-older-than.mdx create mode 100644 pages/sui/get-price-unsafe.mdx create mode 100644 pages/sui/get-price.mdx create mode 100644 pages/sui/get-stale-price-threshold-secs.mdx create mode 100644 pages/sui/get-update-fee.mdx create mode 100644 pages/sui/index.mdx create mode 100644 pages/sui/meta.json create mode 100644 pages/sui/price-feed-exists.mdx create mode 100644 pages/sui/sdks.mdx create mode 100644 pages/sui/update-price-feeds-with-funder.mdx create mode 100644 pages/sui/update-single-price-feed.mdx diff --git a/pages/_meta.json b/pages/_meta.json index da1d9c37..cf9bf624 100644 --- a/pages/_meta.json +++ b/pages/_meta.json @@ -23,7 +23,12 @@ "CosmWasm": { "title": "Cosmwasm Contract", "href": "/cosmwasm" + }, + "Sui": { + "title": "Sui Contract", + "href": "/sui" } + } }, "guides": { diff --git a/pages/sui/get-ema-price-no-older-than.mdx b/pages/sui/get-ema-price-no-older-than.mdx new file mode 100644 index 00000000..df391aac --- /dev/null +++ b/pages/sui/get-ema-price-no-older-than.mdx @@ -0,0 +1,70 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import Example from "../../components/Example"; +import DynamicCode from "../../components/DynamicCode"; +import { InputFormats } from "../../utils/InputFormat"; +import { Tab, Tabs } from "nextra-theme-docs"; +import Examples from "../../components/Examples"; + +# Get EMA Price No Older Than + +Get the latest exponentially-weighted moving average (EMA) price and confidence interval for the requested price feed id. +The price feed id is a 32-byte id written as a hexadecimal string; see the [price feed ids](https://pyth.network/developers/price-feed-ids) page to look up the id for a given symbol. +The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result. +For example, a price of 1234 with an exponent of -2 represents the number 12.34. +The result also includes a `timestamp` which is the unix timestamp for the price update. +The EMA methodology is described in more detail in this [blog post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1). + +The caller provides a `max_age_secs` argument that specifies how old the price can be. +The call reverts if the on-chain price is from more than `max_age_secs` seconds in the past (with respect to the current on-chain timestamp). + +Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before +reading it. This step ensures that the on-chain price is fresh and the call does not revert. + +
+ +| Argument | Input | Description | +| ------------------------------------------------------ | --------------------------------------------------------- | --------------------------------------------- | +| price_identifier | | The ID of the price feed you want to read | +| max_age_secs | | Maximum age of the on-chain price in seconds. | + +
+ + + ctx.getFeedId("Crypto.BTC/USD"), + max_age_secs: () => 60, + }} + value="BTC/USD" + /> + ctx.getFeedId("Crypto.ETH/USD"), + max_age_secs: () => 60, + }} + value="ETH/USD" + /> + + +## Example Code + + + + `"${ctx.get("price_identifier", "")}"`, + "2222": (ctx) => ctx.get("max_age_secs", "") + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::get_ema_price_no_older_than( + price_identifier::from_byte_vec(x"1111"), + 2222 + ); + ``` + + + + diff --git a/pages/sui/get-ema-price-unsafe.mdx b/pages/sui/get-ema-price-unsafe.mdx new file mode 100644 index 00000000..0965862d --- /dev/null +++ b/pages/sui/get-ema-price-unsafe.mdx @@ -0,0 +1,63 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import Example from "../../components/Example"; +import DynamicCode from "../../components/DynamicCode"; +import { InputFormats } from "../../utils/InputFormat"; +import { Tab, Tabs } from "nextra-theme-docs"; +import Examples from "../../components/Examples"; + +# Get EMA Price Unsafe + +Get the latest exponentially-weighted moving average (EMA) price and confidence interval for the requested price feed id. +The price feed id is a 32-byte id written as a hexadecimal string; see the [price feed ids](https://pyth.network/developers/price-feed-ids) page to look up the id for a given symbol. +The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result. +For example, a price of 1234 with an exponent of -2 represents the number 12.34. +The result also includes a `timestamp` which is the unix timestamp for the price update. +The EMA methodology is described in more detail in this [blog post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1). + +**This function may return a price from arbitrarily far in the past.** +It is the caller's responsibility to check the returned `timestamp` to ensure that the update is recent enough for their use case. + +Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before +reading it. This step ensures that the on-chain price is fresh. + +
+ +| Argument | Input | Description | +| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- | +| price_identifier | | The ID of the price feed you want to read | + +
+ + + ctx.getFeedId("Crypto.BTC/USD"), + }} + value="BTC/USD" + /> + ctx.getFeedId("Crypto.ETH/USD"), + }} + value="ETH/USD" + /> + + +## Example Code + + + + `"${ctx.get("price_identifier", "")}"`, + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::get_ema_price_unsafe(price_identifier::from_byte_vec(x"1111")); + ``` + + + + diff --git a/pages/sui/get-ema-price.mdx b/pages/sui/get-ema-price.mdx new file mode 100644 index 00000000..704a6d60 --- /dev/null +++ b/pages/sui/get-ema-price.mdx @@ -0,0 +1,65 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import { InputFormats } from "../../utils/InputFormat"; +import Example from "../../components/Example"; +import DynamicCode from "../../components/DynamicCode"; +import { Tab, Tabs } from "nextra-theme-docs"; +import Examples from "../../components/Examples"; + +# Get EMA Price + +Get the latest exponentially-weighted moving average (EMA) price and confidence interval for the requested price feed id. +The price feed id is a 32-byte id written as a hexadecimal string; see the [price feed ids](https://pyth.network/developers/price-feed-ids) page to look up the id for a given symbol. +The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result. +For example, a price of 1234 with an exponent of -2 represents the number 12.34. +The result also includes a `timestamp` which is the unix timestamp for the price update. +The EMA methodology is described in more detail in this [blog post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1). + +This function reverts if the on-chain price has not been updated within the last [get_stale_price_threshold_secs](get-stale-price-threshold-secs) seconds. +The default valid time period is set to a reasonable default on each chain and is typically around 1 minute. +If you would like to configure the valid time period, see [get_ema_price_no_older_than](get-ema-price-no-older-than). +If you want the latest price regardless of when it was updated, see [get_ema_price_unsafe](get-ema-price-unsafe). + +Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before +reading it. This step ensures that the on-chain price is fresh. + +
+ +| Argument | Input | Description | +| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- | +| price_identifier | | The ID of the price feed you want to read | + +
+ + + ctx.getFeedId("Crypto.BTC/USD"), + }} + value="BTC/USD" + /> + ctx.getFeedId("Crypto.ETH/USD"), + }} + value="ETH/USD" + /> + + +## Example Code + + + + `"${ctx.get("price_identifier", "")}"`, + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::get_ema_price(price_identifier::from_byte_vec(x"1111")); + ``` + + + + diff --git a/pages/sui/get-price-no-older-than.mdx b/pages/sui/get-price-no-older-than.mdx new file mode 100644 index 00000000..3db0d5ac --- /dev/null +++ b/pages/sui/get-price-no-older-than.mdx @@ -0,0 +1,70 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import Example from "../../components/Example"; +import DynamicCode from "../../components/DynamicCode"; +import { InputFormats } from "../../utils/InputFormat"; +import EvmCall from "../../components/EvmCall"; +import { Tab, Tabs } from "nextra-theme-docs"; +import Examples from "../../components/Examples"; + +# Get Price No Older Than + +Get the latest price and confidence interval for the requested price feed id, if it has been updated sufficiently recently. +The price feed id is a 32-byte id written as a hexadecimal string; see the [price feed ids](https://pyth.network/developers/price-feed-ids) page to look up the id for a given symbol. +The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result. +For example, a price of 1234 with an exponent of -2 represents the number 12.34. +The result also includes a `timestamp` which is the unix timestamp for the price update. + +The caller provides a `max_age_secs` argument that specifies how old the price can be. +The call reverts if the on-chain price is from more than `max_age_secs` seconds in the past (with respect to the current on-chain timestamp). + +Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before +reading it. This step ensures that the on-chain price is fresh and the call does not revert. + +
+ +| Argument | Input | Description | +| ------------------------------------------------------ | --------------------------------------------------------- | --------------------------------------------- | +| price_identifier | | The ID of the price feed you want to read | +| max_age_secs | | Maximum age of the on-chain price in seconds. | + +
+ + + ctx.getFeedId("Crypto.BTC/USD"), + max_age_secs: () => 60, + }} + value="BTC/USD" + /> + ctx.getFeedId("Crypto.ETH/USD"), + max_age_secs: () => 60, + }} + value="ETH/USD" + /> + + +## Example Code + + + + `"${ctx.get("price_identifier", "")}"`, + "2222": (ctx) => ctx.get("max_age_secs", "") + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::get_price_no_older_than( + price_identifier::from_byte_vec(x"1111"), + 2222 + ); + ``` + + + + diff --git a/pages/sui/get-price-unsafe.mdx b/pages/sui/get-price-unsafe.mdx new file mode 100644 index 00000000..44300048 --- /dev/null +++ b/pages/sui/get-price-unsafe.mdx @@ -0,0 +1,62 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import Example from "../../components/Example"; +import Examples from "../../components/Examples"; +import DynamicCode from "../../components/DynamicCode"; +import { InputFormats } from "../../utils/InputFormat"; +import { Tab, Tabs } from "nextra-theme-docs"; + +# Get Price Unsafe + +Get the latest price and confidence interval for the requested price feed id. +The price feed id is a 32-byte id written as a hexadecimal string; see the [price feed ids](https://pyth.network/developers/price-feed-ids) page to look up the id for a given symbol. +The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result. +For example, a price of 1234 with an exponent of -2 represents the number 12.34. +The result also includes a `timestamp` which is the unix timestamp for the price update. + +**This function may return a price from arbitrarily far in the past.** +It is the caller's responsibility to check the returned `timestamp` to ensure that the update is recent enough for their use case. + +Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before +reading it. This step ensures that the on-chain price is fresh. + +
+ +| Argument | Input | Description | +| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- | +| price_identifier | | The ID of the price feed you want to read | + +
+ + + ctx.getFeedId("Crypto.BTC/USD"), + }} + value="BTC/USD" + /> + ctx.getFeedId("Crypto.ETH/USD"), + }} + value="ETH/USD" + /> + + +## Example Code + + + + `"${ctx.get("price_identifier", "")}"`, + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::get_price_unsafe(price_identifier::from_byte_vec(x"1111")); + ``` + + + + diff --git a/pages/sui/get-price.mdx b/pages/sui/get-price.mdx new file mode 100644 index 00000000..1397bd07 --- /dev/null +++ b/pages/sui/get-price.mdx @@ -0,0 +1,64 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import { InputFormats } from "../../utils/InputFormat"; +import Example from "../../components/Example"; +import Examples from "../../components/Examples"; +import DynamicCode from "../../components/DynamicCode"; +import { Tab, Tabs } from "nextra-theme-docs"; + +# Get Price + +Get the latest price and confidence interval for the requested price feed id. +The price feed id is a 32-byte id written as a hexadecimal string; see the [price feed ids](https://pyth.network/developers/price-feed-ids) page to look up the id for a given symbol. +The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result. +For example, a price of 1234 with an exponent of -2 represents the number 12.34. +The result also includes a `timestamp` which is the unix timestamp for the price update. + +This function reverts if the on-chain price has not been updated within the last [get_stale_price_threshold_secs](get-stale-price-threshold-secs) seconds. +The default valid time period is set to a reasonable default on each chain and is typically around 1 minute. +If you would like to configure the valid time period, see [get_price_no_older_than](get-price-no-older-than). +If you want the latest price regardless of when it was updated, see [get_price_unsafe](get-price-unsafe). + +Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before +reading it. This step ensures that the on-chain price is fresh. + +
+ +| Argument | Input | Description | +| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- | +| price_identifier | | The ID of the price feed you want to read | + +
+ + + ctx.getFeedId("Crypto.BTC/USD"), + }} + value="BTC/USD" + /> + ctx.getFeedId("Crypto.ETH/USD"), + }} + value="ETH/USD" + /> + + +## Example Code + + + + `"${ctx.get("price_identifier", "")}"`, + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::get_price(price_identifier::from_byte_vec(x"1111")); + ``` + + + + diff --git a/pages/sui/get-stale-price-threshold-secs.mdx b/pages/sui/get-stale-price-threshold-secs.mdx new file mode 100644 index 00000000..63d6d526 --- /dev/null +++ b/pages/sui/get-stale-price-threshold-secs.mdx @@ -0,0 +1,24 @@ +import DynamicCode from "../../components/DynamicCode"; +import { Tab, Tabs } from "nextra-theme-docs"; + +# Get Stale Price Threshold Secs + +Get the default stale price threshold in seconds. +This quantity is the maximum age of price updates returned by functions like [get_price](get-price) and [get_ema_price](get-ema-price); +these functions revert if the current on-chain price is older than this threshold. + +## Example Code + + + + + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::get_stale_price_threshold_secs(); + ``` + + + + diff --git a/pages/sui/get-update-fee.mdx b/pages/sui/get-update-fee.mdx new file mode 100644 index 00000000..47352d28 --- /dev/null +++ b/pages/sui/get-update-fee.mdx @@ -0,0 +1,60 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import { InputFormats } from "../../utils/InputFormat"; +import Example from "../../components/Example"; +import Examples from "../../components/Examples"; +import DynamicCode from "../../components/DynamicCode"; +import { Tab, Tabs } from "nextra-theme-docs"; + +# Get Update Fee + +Get the fee required to update the on-chain price feeds with the provided `update_data`. +The returned number of Octa should be sent as the transaction value when calling [update_price_feeds](update-price-feeds). + +The `update_data` can be retrieved from the price service API. +By default, the data is returned as a base64-encoded string that you must deserialize into a vector of bytes before calling this method. + +
+ +| Argument | Input | Description | +| ---------------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------- | +| update_data | | The price updates that you would like to submit to [update_price_feeds](update-price-feeds) | + +
+ + + + JSON.stringify( + Array.from( + Buffer.from( + (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + "base64" + ) + ) + ), + }} + value="Latest BTC/USD update data" + /> + + +## Example Code + + + + ctx.get("update_data", ""), + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::get_update_fee( + vec![1] + ); + ``` + + + + diff --git a/pages/sui/index.mdx b/pages/sui/index.mdx new file mode 100644 index 00000000..af61e567 --- /dev/null +++ b/pages/sui/index.mdx @@ -0,0 +1,13 @@ +The Pyth Network Aptos contract allows users to submit price updates for verification and store them for later use. +Please see the documentation section on [Pull Updates](documentation/pythnet-price-feeds/on-demand) if you haven't already; +this section will explain the differences between Pyth Network and other oracles, and help you understand the expected usage patterns. + +Users of the Pyth contract will typically need to perform two operations: + +- Update the on-chain price -- In off-chain code, retrieve a verified price update from the + [price service](documentation/pythnet-price-feeds/price-service) and submit it to the contract + for verification. This operation makes the price available for on-chain use. + You will typically call [update_price_feeds](aptos/update-price-feeds) to do this. +- Read the on-chain price -- After updating the price, your on-chain contract can call one of the + many getter functions on the contract to get the price. See [get_price](aptos/get-price) and its variants + for more information. diff --git a/pages/sui/meta.json b/pages/sui/meta.json new file mode 100644 index 00000000..6b598ed1 --- /dev/null +++ b/pages/sui/meta.json @@ -0,0 +1,23 @@ +{ + "--- Sui Contract": { + "title": "Sui Contract", + "type": "separator" + }, + "index": "Introduction", + "sdks": "SDKs", + "--- Methods": { + "title": "Methods", + "type": "separator" + }, + + "get-price": "get_price", + "get-price-unsafe": "get_price_unsafe", + "get-price-no-older-than": "get_price_no_older_than", + "get-ema-price": "get_ema_price", + "get-ema-price-unsafe": "get_ema_price_unsafe", + "get-ema-price-no-older-than": "get_ema_price_no_older_than", + "get-update-fee": "get_update_fee", + "get-stale-price-threshold-secs": "get_stale_price_threshold_secs", + "price-feed-exists": "price_feed_exists", + "update-price-feeds": "update_single_price_feed" + } diff --git a/pages/sui/price-feed-exists.mdx b/pages/sui/price-feed-exists.mdx new file mode 100644 index 00000000..efaf1cfc --- /dev/null +++ b/pages/sui/price-feed-exists.mdx @@ -0,0 +1,55 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import Example from "../../components/Example"; +import DynamicCode from "../../components/DynamicCode"; +import { InputFormats } from "../../utils/InputFormat"; +import { Tab, Tabs } from "nextra-theme-docs"; +import Examples from "../../components/Examples"; + +# Price Feed Exists + +Determine if a price feed for the given `price_identifier` exists. +Returns `true` if there has been at least one on-chain update of this feed in the past. +Note that a `false` answer may mean that the feed exists, but simply has never been updated on Aptos. +In this case, you can invoke [update_price_feeds](update-price-feeds) to pull an update on-chain. + +
+ +| Argument | Input | Description | +| ------------------------------------------------------ | --------------------------------------------------------- | --------------------------------- | +| price_identifier | | The ID of the price feed to check | + +
+ + + ctx.getFeedId("Crypto.BTC/USD"), + }} + value="BTC/USD" + /> + ctx.getFeedId("Crypto.ETH/USD"), + }} + value="ETH/USD" + /> + + +## Example Code + + + + `"${ctx.get("price_identifier", "")}"`, + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::price_feed_exists(price_identifier::from_byte_vec(x"1111")); + ``` + + + + diff --git a/pages/sui/sdks.mdx b/pages/sui/sdks.mdx new file mode 100644 index 00000000..68d6236e --- /dev/null +++ b/pages/sui/sdks.mdx @@ -0,0 +1,41 @@ +import { Tab, Tabs } from "nextra-theme-docs"; + +# SDKs + +Aptos contracts can program against the Pyth contract's interface by including it as a project dependency. + +## Installation Instructions + + + + First, add the Pyth contract to your project dependencies by adding the following line to the `[dependencies]` section of `Move.toml`: + + ```toml + [dependencies] + Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "target_chains/aptos/contracts", rev = "main" } + ``` + + Note that this dependency references the latest version of the Pyth contract code. + You can also choose the most recent git sha in order to have a repeatable build. + This contract was compiled with [aptos-cli v1.0.4](https://github.com/aptos-labs/aptos-core/releases/tag/aptos-cli-v1.0.4). + + Next, add the following named addresses to the `[addresses]` section of `Move.toml`: + + ```toml + [addresses] + pyth = "0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387" + deployer = "0xb31e712b26fd295357355f6845e77c888298636609e93bc9b05f0f604049f434" + wormhole = "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625" + ``` + + These lines allow you to reference Pyth resources as `pyth` instead of manually writing the contract address. + The contract addresses provided above are for both Aptos mainnet and testnet -- the Pyth contract has the same address in both cases. + + You can now import the Pyth interfaces in Move code as follows: + + ```rust copy + use pyth::pyth; + ``` + + + diff --git a/pages/sui/update-price-feeds-with-funder.mdx b/pages/sui/update-price-feeds-with-funder.mdx new file mode 100644 index 00000000..f63c34e7 --- /dev/null +++ b/pages/sui/update-price-feeds-with-funder.mdx @@ -0,0 +1,69 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import { InputFormats } from "../../utils/InputFormat"; +import Example from "../../components/Example"; +import Examples from "../../components/Examples"; +import DynamicCode from "../../components/DynamicCode"; +import { Tab, Tabs } from "nextra-theme-docs"; + +# Update Price Feeds with Funder + +Update the on-chain price feeds using the provided `update_data`, which contains serialized and signed price update data from Pyth Network. +This function updates the on-chain price if the provided update is more recent than the current on-chain price. +Otherwise, the provided update will be ignored. +The function call will succeed even if the update is ignored. + +You can retrieve the latest price `update_data` for a given set of price feeds from the price service API. +By default, the data is returned as a base64-encoded string that you must deserialize into a vector of bytes before calling this method. + +This function requires the caller to pay a fee to perform the update. +The required fee for the provided updates will automatically be transferred from the provided `account`. + +Reverts if the `account` does not have a sufficient balance or `update_data` is incorrectly signed or formatted. + +
+ +| Argument | Input | Description | +| ---------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------- | +| account | | The account paying the fee. | +| update_data | | The price update data for the contract to verify. | + +
+ + + + JSON.stringify( + Array.from( + Buffer.from( + (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + "base64" + ) + ) + ), + }} + value="Latest BTC/USD update data" + /> + + +## Example Code + + + + ctx.get("update_data", ""), + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + pyth::update_price_feeds_with_funder( + funder, + vec![1] + ); + ``` + + + + diff --git a/pages/sui/update-single-price-feed.mdx b/pages/sui/update-single-price-feed.mdx new file mode 100644 index 00000000..a1e5d8ac --- /dev/null +++ b/pages/sui/update-single-price-feed.mdx @@ -0,0 +1,78 @@ +import Input from "../../components/Input"; +import Arg from "../../components/Arg"; +import { InputFormats } from "../../utils/InputFormat"; +import Example from "../../components/Example"; +import Examples from "../../components/Examples"; +import DynamicCode from "../../components/DynamicCode"; +import { Tab, Tabs } from "nextra-theme-docs"; + +# Update Price Feeds + +Update the on-chain price feeds using the provided `update_data`, which contains serialized and signed price update data from Pyth Network. +This function updates the on-chain price if the provided update is more recent than the current on-chain price. +Otherwise, the provided update will be ignored. +The function call will succeed even if the update is ignored. + +You can retrieve the latest price `update_data` for a given set of price feeds from the price service API. +By default, the data is returned as a base64-encoded string that you must deserialize into a vector of bytes before calling this method. + +This function requires the caller to pay a fee to perform the update. +The required fee for a given set of updates can be computed by passing them to [get_update_fee](get-update-fee). + +Reverts if the required fee is not paid, or the `update_data` is incorrectly signed or formatted. + +
+ +| Argument | Input | Description | +| ---------------------------------------------------------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | +| update_data | | The price update data for the contract to verify. | +| fee | | The update fee in octa. This fee is transferred to the Pyth contract as an effect of the transaction. | + +
+ + + + JSON.stringify( + Array.from( + Buffer.from( + (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + "base64" + ) + ) + ), + fee: async (ctx) => { + // NOTE: this technically could get the update fee for a different VAA than the one above. + // This shouldn't affect the update fee as long as the fee is only dependent on the price feed ids + // and not the specific content of the price update. + let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa; + return await ctx.getEthUpdateFee([vaa]); + }, + }} + value="Latest BTC/USD update data" + /> + + +## Example Code + + + + ctx.get("update_data", ""), + "2": (ctx) => ctx.get("fee", ""), + }}> + ```rust copy + use pyth::pyth; + use pyth::price_identifier; + + let coins = coin::withdraw(payer, 2) + pyth::update_price_feeds( + vec![1], + coins + ); + ``` + + + + From e7dac5490e773d0116d1a1051e36f9ee80ffbac0 Mon Sep 17 00:00:00 2001 From: optke3 <108488464+optke3@users.noreply.github.com> Date: Mon, 7 Aug 2023 14:05:49 -0400 Subject: [PATCH 02/11] Update index.mdx --- pages/sui/index.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/sui/index.mdx b/pages/sui/index.mdx index af61e567..fb3a4ce0 100644 --- a/pages/sui/index.mdx +++ b/pages/sui/index.mdx @@ -1,13 +1,13 @@ -The Pyth Network Aptos contract allows users to submit price updates for verification and store them for later use. +The Pyth Network Sui contract allows users to submit price updates for verification and store them for later use. Please see the documentation section on [Pull Updates](documentation/pythnet-price-feeds/on-demand) if you haven't already; -this section will explain the differences between Pyth Network and other oracles, and help you understand the expected usage patterns. +this section will explain the differences between Pyth Network and other oracles, and help you understand the expected usage patterns. Pyth on Sui also automatically pushes prices on-chain for a subset of symbols. More information on this TBA. Users of the Pyth contract will typically need to perform two operations: - Update the on-chain price -- In off-chain code, retrieve a verified price update from the [price service](documentation/pythnet-price-feeds/price-service) and submit it to the contract for verification. This operation makes the price available for on-chain use. - You will typically call [update_price_feeds](aptos/update-price-feeds) to do this. + You will typically call [update_price_feeds](sui/update-price-feeds) to do this. - Read the on-chain price -- After updating the price, your on-chain contract can call one of the - many getter functions on the contract to get the price. See [get_price](aptos/get-price) and its variants + many getter functions on the contract to get the price. See [get_price](sui/get-price) and its variants for more information. From 3d8314995d6e1c403a0b3e4d28724f91e6b696dc Mon Sep 17 00:00:00 2001 From: optke3 <108488464+optke3@users.noreply.github.com> Date: Mon, 7 Aug 2023 14:10:13 -0400 Subject: [PATCH 03/11] Update sdks.mdx --- pages/sui/sdks.mdx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pages/sui/sdks.mdx b/pages/sui/sdks.mdx index 68d6236e..6ca04e8c 100644 --- a/pages/sui/sdks.mdx +++ b/pages/sui/sdks.mdx @@ -2,7 +2,7 @@ import { Tab, Tabs } from "nextra-theme-docs"; # SDKs -Aptos contracts can program against the Pyth contract's interface by including it as a project dependency. +Sui contracts can program against the Pyth contract's interface by including it as a project dependency. ## Installation Instructions @@ -12,24 +12,23 @@ Aptos contracts can program against the Pyth contract's interface by including i ```toml [dependencies] - Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "target_chains/aptos/contracts", rev = "main" } + Pyth = { git = "https://github.com/pyth-network/pyth-crosschain.git", subdir = "target_chains/sui/contracts", rev = "main" } ``` Note that this dependency references the latest version of the Pyth contract code. You can also choose the most recent git sha in order to have a repeatable build. - This contract was compiled with [aptos-cli v1.0.4](https://github.com/aptos-labs/aptos-core/releases/tag/aptos-cli-v1.0.4). + This contract was compiled with sui-cli sui 1.0.0-09b208149. Next, add the following named addresses to the `[addresses]` section of `Move.toml`: ```toml [addresses] - pyth = "0x7e783b349d3e89cf5931af376ebeadbfab855b3fa239b7ada8f5a92fbea6b387" - deployer = "0xb31e712b26fd295357355f6845e77c888298636609e93bc9b05f0f604049f434" - wormhole = "0x5bc11445584a763c1fa7ed39081f1b920954da14e04b32440cba863d03e19625" + pyth = TBA + wormhole = TBA ``` These lines allow you to reference Pyth resources as `pyth` instead of manually writing the contract address. - The contract addresses provided above are for both Aptos mainnet and testnet -- the Pyth contract has the same address in both cases. + The contract addresses provided above are for both Sui mainnet -- the Pyth contract has a different address on testnet (contract addresses on Sui are not generated deterministically). You can now import the Pyth interfaces in Move code as follows: From ea45314f8adf8ba058db51398ef0adfadd5bf5bd Mon Sep 17 00:00:00 2001 From: optke3 <108488464+optke3@users.noreply.github.com> Date: Mon, 7 Aug 2023 15:28:28 -0400 Subject: [PATCH 04/11] Update price-feed-exists.mdx --- pages/sui/price-feed-exists.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/sui/price-feed-exists.mdx b/pages/sui/price-feed-exists.mdx index efaf1cfc..bfbcdc6d 100644 --- a/pages/sui/price-feed-exists.mdx +++ b/pages/sui/price-feed-exists.mdx @@ -10,7 +10,7 @@ import Examples from "../../components/Examples"; Determine if a price feed for the given `price_identifier` exists. Returns `true` if there has been at least one on-chain update of this feed in the past. -Note that a `false` answer may mean that the feed exists, but simply has never been updated on Aptos. +Note that a `false` answer may mean that the feed exists, but simply has never been updated on Sui. In this case, you can invoke [update_price_feeds](update-price-feeds) to pull an update on-chain.
From 8e9e2d0bf7e3ff209bb69aa721b85c741ddefecc Mon Sep 17 00:00:00 2001 From: optke3 <108488464+optke3@users.noreply.github.com> Date: Mon, 7 Aug 2023 15:33:38 -0400 Subject: [PATCH 05/11] Update update-single-price-feed.mdx --- pages/sui/update-single-price-feed.mdx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pages/sui/update-single-price-feed.mdx b/pages/sui/update-single-price-feed.mdx index a1e5d8ac..500496d1 100644 --- a/pages/sui/update-single-price-feed.mdx +++ b/pages/sui/update-single-price-feed.mdx @@ -25,9 +25,11 @@ Reverts if the required fee is not paid, or the `update_data` is incorrectly sig | Argument | Input | Description | | ---------------------------------------------------------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -| update_data | | The price update data for the contract to verify. | -| fee | | The update fee in octa. This fee is transferred to the Pyth contract as an effect of the transaction. | - +| pyth_state | | The Pyth state object. | +| price_updates | | vector of authenticated price updates | +| price_info_object | | PriceInfoObject is a shared Sui object containing the price feed to be updated. | +| fee | | Fee coins. | +| clock | | clock is a Sui shared object used to tell time and record timestamps |
From cf747323d8a64c455b22b552d5dd07ae7776143a Mon Sep 17 00:00:00 2001 From: optke3 <108488464+optke3@users.noreply.github.com> Date: Mon, 7 Aug 2023 15:41:30 -0400 Subject: [PATCH 06/11] Update update-single-price-feed.mdx --- pages/sui/update-single-price-feed.mdx | 31 ++++---------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/pages/sui/update-single-price-feed.mdx b/pages/sui/update-single-price-feed.mdx index 500496d1..4a8caa0c 100644 --- a/pages/sui/update-single-price-feed.mdx +++ b/pages/sui/update-single-price-feed.mdx @@ -32,6 +32,9 @@ Reverts if the required fee is not paid, or the `update_data` is incorrectly sig | clock | | clock is a Sui shared object used to tell time and record timestamps | +# Warning: do not hardcode price feed updates in your contract +`update_single_price_feed` is meant to be called in a chain of programmable transactions, rather than hardcoded in a contract. This is because when a Sui contract upgrades, the upgraded version lives at a different address. When this happens the previous callsite gets bricked, or becomes un-callable. It is up to the user to use the correct call-site (we also have a helper function for finding the latest call-site given the Pyth state object ID, which is unchanged between upgrades). + { - // NOTE: this technically could get the update fee for a different VAA than the one above. - // This shouldn't affect the update fee as long as the fee is only dependent on the price feed ids - // and not the specific content of the price update. let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa; return await ctx.getEthUpdateFee([vaa]); }, }} - value="Latest BTC/USD update data" + Example TBA /> - -## Example Code - - - - ctx.get("update_data", ""), - "2": (ctx) => ctx.get("fee", ""), - }}> - ```rust copy - use pyth::pyth; - use pyth::price_identifier; - - let coins = coin::withdraw(payer, 2) - pyth::update_price_feeds( - vec![1], - coins - ); - ``` - - - - From efb52ec4862912f8b92b1346e4a4d8f1d9da815d Mon Sep 17 00:00:00 2001 From: optke3 Date: Tue, 8 Aug 2023 15:37:34 +0000 Subject: [PATCH 07/11] run precommit on all files --- pages/_meta.json | 1 - pages/sui/meta.json | 42 +++++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/pages/_meta.json b/pages/_meta.json index cf9bf624..ce7a51cc 100644 --- a/pages/_meta.json +++ b/pages/_meta.json @@ -28,7 +28,6 @@ "title": "Sui Contract", "href": "/sui" } - } }, "guides": { diff --git a/pages/sui/meta.json b/pages/sui/meta.json index 6b598ed1..32ac854f 100644 --- a/pages/sui/meta.json +++ b/pages/sui/meta.json @@ -1,23 +1,23 @@ { - "--- Sui Contract": { - "title": "Sui Contract", - "type": "separator" - }, - "index": "Introduction", - "sdks": "SDKs", - "--- Methods": { - "title": "Methods", - "type": "separator" - }, + "--- Sui Contract": { + "title": "Sui Contract", + "type": "separator" + }, + "index": "Introduction", + "sdks": "SDKs", + "--- Methods": { + "title": "Methods", + "type": "separator" + }, - "get-price": "get_price", - "get-price-unsafe": "get_price_unsafe", - "get-price-no-older-than": "get_price_no_older_than", - "get-ema-price": "get_ema_price", - "get-ema-price-unsafe": "get_ema_price_unsafe", - "get-ema-price-no-older-than": "get_ema_price_no_older_than", - "get-update-fee": "get_update_fee", - "get-stale-price-threshold-secs": "get_stale_price_threshold_secs", - "price-feed-exists": "price_feed_exists", - "update-price-feeds": "update_single_price_feed" - } + "get-price": "get_price", + "get-price-unsafe": "get_price_unsafe", + "get-price-no-older-than": "get_price_no_older_than", + "get-ema-price": "get_ema_price", + "get-ema-price-unsafe": "get_ema_price_unsafe", + "get-ema-price-no-older-than": "get_ema_price_no_older_than", + "get-update-fee": "get_update_fee", + "get-stale-price-threshold-secs": "get_stale_price_threshold_secs", + "price-feed-exists": "price_feed_exists", + "update-price-feeds": "update_single_price_feed" +} From e894e6ad4eb79e2da0ba01d90d9cb35fd1b2327b Mon Sep 17 00:00:00 2001 From: optke3 Date: Tue, 8 Aug 2023 15:38:11 +0000 Subject: [PATCH 08/11] precommit on all files --- pages/sui/update-single-price-feed.mdx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pages/sui/update-single-price-feed.mdx b/pages/sui/update-single-price-feed.mdx index 4a8caa0c..b529a2dd 100644 --- a/pages/sui/update-single-price-feed.mdx +++ b/pages/sui/update-single-price-feed.mdx @@ -23,17 +23,19 @@ Reverts if the required fee is not paid, or the `update_data` is incorrectly sig
-| Argument | Input | Description | -| ---------------------------------------------------------------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -| pyth_state | | The Pyth state object. | -| price_updates | | vector of authenticated price updates | -| price_info_object | | PriceInfoObject is a shared Sui object containing the price feed to be updated. | -| fee | | Fee coins. | -| clock | | clock is a Sui shared object used to tell time and record timestamps | +| Argument | Input | Description | +| ---------------------------------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------- | +| pyth_state | | The Pyth state object. | +| price_updates | | vector of authenticated price updates | +| price_info_object | | PriceInfoObject is a shared Sui object containing the price feed to be updated. | +| fee | | Fee coins. | +| clock | | clock is a Sui shared object used to tell time and record timestamps | +
# Warning: do not hardcode price feed updates in your contract -`update_single_price_feed` is meant to be called in a chain of programmable transactions, rather than hardcoded in a contract. This is because when a Sui contract upgrades, the upgraded version lives at a different address. When this happens the previous callsite gets bricked, or becomes un-callable. It is up to the user to use the correct call-site (we also have a helper function for finding the latest call-site given the Pyth state object ID, which is unchanged between upgrades). + +`update_single_price_feed` is meant to be called in a chain of programmable transactions, rather than hardcoded in a contract. This is because when a Sui contract upgrades, the upgraded version lives at a different address. When this happens the previous callsite gets bricked, or becomes un-callable. It is up to the user to use the correct call-site (we also have a helper function for finding the latest call-site given the Pyth state object ID, which is unchanged between upgrades). From a86d570ec15ec1ec9b75c91608934b26599c9828 Mon Sep 17 00:00:00 2001 From: optke3 Date: Tue, 8 Aug 2023 15:58:40 +0000 Subject: [PATCH 09/11] trigger rebuild --- pages/sui/get-stale-price-threshold-secs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/sui/get-stale-price-threshold-secs.mdx b/pages/sui/get-stale-price-threshold-secs.mdx index 63d6d526..ae4606cd 100644 --- a/pages/sui/get-stale-price-threshold-secs.mdx +++ b/pages/sui/get-stale-price-threshold-secs.mdx @@ -16,7 +16,7 @@ these functions revert if the current on-chain price is older than this threshol use pyth::pyth; use pyth::price_identifier; - pyth::get_stale_price_threshold_secs(); + pyth::get_stale_price_threshold_secs(pyth_state); ``` From 6c744de11e4aa41e2b54f294d79a66c832ad194f Mon Sep 17 00:00:00 2001 From: optke3 Date: Tue, 8 Aug 2023 16:00:39 +0000 Subject: [PATCH 10/11] fix broken import --- contexts/GlobalContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contexts/GlobalContext.tsx b/contexts/GlobalContext.tsx index 59a5ce66..0c74ae5c 100644 --- a/contexts/GlobalContext.tsx +++ b/contexts/GlobalContext.tsx @@ -16,7 +16,7 @@ import { neutron, neutrontestnet, osmosis, - osmosistestnet5, + osmosistestnet, seitestnet2, } from "graz/chains"; import PythAbi from "../abis/IPyth.json"; From 5c665bb5e0e1de0c661d3577194ca229a3db9660 Mon Sep 17 00:00:00 2001 From: optke3 Date: Tue, 8 Aug 2023 16:05:31 +0000 Subject: [PATCH 11/11] fix another broken import --- contexts/GlobalContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contexts/GlobalContext.tsx b/contexts/GlobalContext.tsx index 0c74ae5c..1c5ed395 100644 --- a/contexts/GlobalContext.tsx +++ b/contexts/GlobalContext.tsx @@ -152,7 +152,7 @@ const contractAbi = [...PythAbi, ...PythErrorsAbi]; const CHAINS = [mainnet, avalanche, arbitrum]; export const CosmosChains = [ osmosis, - osmosistestnet5, + osmosistestnet, injective, injectivetestnet, seitestnet2,