diff --git a/contexts/GlobalContext.tsx b/contexts/GlobalContext.tsx index 59a5ce66..1c5ed395 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"; @@ -152,7 +152,7 @@ const contractAbi = [...PythAbi, ...PythErrorsAbi]; const CHAINS = [mainnet, avalanche, arbitrum]; export const CosmosChains = [ osmosis, - osmosistestnet5, + osmosistestnet, injective, injectivetestnet, seitestnet2, diff --git a/pages/_meta.json b/pages/_meta.json index da1d9c37..ce7a51cc 100644 --- a/pages/_meta.json +++ b/pages/_meta.json @@ -23,6 +23,10 @@ "CosmWasm": { "title": "Cosmwasm Contract", "href": "/cosmwasm" + }, + "Sui": { + "title": "Sui Contract", + "href": "/sui" } } }, 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..ae4606cd --- /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(pyth_state); + ``` + + + + 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..fb3a4ce0 --- /dev/null +++ b/pages/sui/index.mdx @@ -0,0 +1,13 @@ +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. 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](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](sui/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..32ac854f --- /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..bfbcdc6d --- /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 Sui. +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..6ca04e8c --- /dev/null +++ b/pages/sui/sdks.mdx @@ -0,0 +1,40 @@ +import { Tab, Tabs } from "nextra-theme-docs"; + +# SDKs + +Sui 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/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 sui-cli sui 1.0.0-09b208149. + + Next, add the following named addresses to the `[addresses]` section of `Move.toml`: + + ```toml + [addresses] + 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 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: + + ```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..b529a2dd --- /dev/null +++ b/pages/sui/update-single-price-feed.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"; + +# 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 | +| ---------------------------------------------------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------- | +| 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). + + + + JSON.stringify( + Array.from( + Buffer.from( + (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa, + "base64" + ) + ) + ), + fee: async (ctx) => { + let vaa = (await ctx.getLatestPriceFeed("Crypto.BTC/USD")).vaa; + return await ctx.getEthUpdateFee([vaa]); + }, + }} + Example + TBA + /> +