Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sui] - docs #53

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions contexts/GlobalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
neutron,
neutrontestnet,
osmosis,
osmosistestnet5,
osmosistestnet,
seitestnet2,
} from "graz/chains";
import PythAbi from "../abis/IPyth.json";
Expand Down Expand Up @@ -152,7 +152,7 @@ const contractAbi = [...PythAbi, ...PythErrorsAbi];
const CHAINS = [mainnet, avalanche, arbitrum];
export const CosmosChains = [
osmosis,
osmosistestnet5,
osmosistestnet,
injective,
injectivetestnet,
seitestnet2,
Expand Down
4 changes: 4 additions & 0 deletions pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"CosmWasm": {
"title": "Cosmwasm Contract",
"href": "/cosmwasm"
},
"Sui": {
"title": "Sui Contract",
"href": "/sui"
}
}
},
Expand Down
70 changes: 70 additions & 0 deletions pages/sui/get-ema-price-no-older-than.mdx
Original file line number Diff line number Diff line change
@@ -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.

<div className="mt-6 overflow-x-auto">

| Argument | Input | Description |
| ------------------------------------------------------ | --------------------------------------------------------- | --------------------------------------------- |
| <Arg required={true} type="hex">price_identifier</Arg> | <Input id="price_identifier" format={InputFormats.Hex} /> | The ID of the price feed you want to read |
| <Arg required={true} type="int">max_age_secs</Arg> | <Input id="max_age_secs" /> | Maximum age of the on-chain price in seconds. |

</div>

<Examples>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
max_age_secs: () => 60,
}}
value="BTC/USD"
/>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
max_age_secs: () => 60,
}}
value="ETH/USD"
/>
</Examples>

## Example Code

<Tabs items={['Move']}>
<Tab>
<DynamicCode targets={{
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
"2222": (ctx) => ctx.get("max_age_secs", "<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
);
```
</DynamicCode>
</Tab>

</Tabs>
63 changes: 63 additions & 0 deletions pages/sui/get-ema-price-unsafe.mdx
Original file line number Diff line number Diff line change
@@ -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.

<div className="mt-6 overflow-x-auto">

| Argument | Input | Description |
| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- |
| <Arg required={true} type="hex">price_identifier</Arg> | <Input id="price_identifier" format={InputFormats.Hex} /> | The ID of the price feed you want to read |

</div>

<Examples>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
}}
value="BTC/USD"
/>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
}}
value="ETH/USD"
/>
</Examples>

## Example Code

<Tabs items={['Move']}>
<Tab>
<DynamicCode targets={{
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
}}>
```rust copy
use pyth::pyth;
use pyth::price_identifier;

pyth::get_ema_price_unsafe(price_identifier::from_byte_vec(x"1111"));
```
</DynamicCode>
</Tab>

</Tabs>
65 changes: 65 additions & 0 deletions pages/sui/get-ema-price.mdx
Original file line number Diff line number Diff line change
@@ -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.

<div className="mt-6 overflow-x-auto">

| Argument | Input | Description |
| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- |
| <Arg required={true} type="hex">price_identifier</Arg> | <Input id="price_identifier" format={InputFormats.Hex} /> | The ID of the price feed you want to read |

</div>

<Examples>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
}}
value="BTC/USD"
/>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
}}
value="ETH/USD"
/>
</Examples>

## Example Code

<Tabs items={['Move']}>
<Tab>
<DynamicCode targets={{
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
}}>
```rust copy
use pyth::pyth;
use pyth::price_identifier;

pyth::get_ema_price(price_identifier::from_byte_vec(x"1111"));
```
</DynamicCode>
</Tab>

</Tabs>
70 changes: 70 additions & 0 deletions pages/sui/get-price-no-older-than.mdx
Original file line number Diff line number Diff line change
@@ -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.

<div className="mt-6 overflow-x-auto">

| Argument | Input | Description |
| ------------------------------------------------------ | --------------------------------------------------------- | --------------------------------------------- |
| <Arg required={true} type="hex">price_identifier</Arg> | <Input id="price_identifier" format={InputFormats.Hex} /> | The ID of the price feed you want to read |
| <Arg required={true} type="int">max_age_secs</Arg> | <Input id="max_age_secs" /> | Maximum age of the on-chain price in seconds. |

</div>

<Examples>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
max_age_secs: () => 60,
}}
value="BTC/USD"
/>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
max_age_secs: () => 60,
}}
value="ETH/USD"
/>
</Examples>

## Example Code

<Tabs items={['Move']}>
<Tab>
<DynamicCode targets={{
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
"2222": (ctx) => ctx.get("max_age_secs", "<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
);
```
</DynamicCode>
</Tab>

</Tabs>
62 changes: 62 additions & 0 deletions pages/sui/get-price-unsafe.mdx
Original file line number Diff line number Diff line change
@@ -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.

<div className="mt-6 overflow-x-auto">

| Argument | Input | Description |
| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- |
| <Arg required={true} type="hex">price_identifier</Arg> | <Input id="price_identifier" format={InputFormats.Hex} /> | The ID of the price feed you want to read |

</div>

<Examples>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
}}
value="BTC/USD"
/>
<Example
keyValues={{
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
}}
value="ETH/USD"
/>
</Examples>

## Example Code

<Tabs items={['Move']}>
<Tab>
<DynamicCode targets={{
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
}}>
```rust copy
use pyth::pyth;
use pyth::price_identifier;

pyth::get_price_unsafe(price_identifier::from_byte_vec(x"1111"));
```
</DynamicCode>
</Tab>

</Tabs>
Loading
Loading