Skip to content

Commit ce03e90

Browse files
committed
start sui docs
1 parent e7c5424 commit ce03e90

15 files changed

+762
-0
lines changed

pages/_meta.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
"CosmWasm": {
2424
"title": "Cosmwasm Contract",
2525
"href": "/cosmwasm"
26+
},
27+
"Sui": {
28+
"title": "Sui Contract",
29+
"href": "/sui"
2630
}
31+
2732
}
2833
},
2934
"guides": {
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import Input from "../../components/Input";
2+
import Arg from "../../components/Arg";
3+
import Example from "../../components/Example";
4+
import DynamicCode from "../../components/DynamicCode";
5+
import { InputFormats } from "../../utils/InputFormat";
6+
import { Tab, Tabs } from "nextra-theme-docs";
7+
import Examples from "../../components/Examples";
8+
9+
# Get EMA Price No Older Than
10+
11+
Get the latest exponentially-weighted moving average (EMA) price and confidence interval for the requested price feed id.
12+
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.
13+
The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result.
14+
For example, a price of 1234 with an exponent of -2 represents the number 12.34.
15+
The result also includes a `timestamp` which is the unix timestamp for the price update.
16+
The EMA methodology is described in more detail in this [blog post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1).
17+
18+
The caller provides a `max_age_secs` argument that specifies how old the price can be.
19+
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).
20+
21+
Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before
22+
reading it. This step ensures that the on-chain price is fresh and the call does not revert.
23+
24+
<div className="mt-6 overflow-x-auto">
25+
26+
| Argument | Input | Description |
27+
| ------------------------------------------------------ | --------------------------------------------------------- | --------------------------------------------- |
28+
| <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 |
29+
| <Arg required={true} type="int">max_age_secs</Arg> | <Input id="max_age_secs" /> | Maximum age of the on-chain price in seconds. |
30+
31+
</div>
32+
33+
<Examples>
34+
<Example
35+
keyValues={{
36+
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
37+
max_age_secs: () => 60,
38+
}}
39+
value="BTC/USD"
40+
/>
41+
<Example
42+
keyValues={{
43+
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
44+
max_age_secs: () => 60,
45+
}}
46+
value="ETH/USD"
47+
/>
48+
</Examples>
49+
50+
## Example Code
51+
52+
<Tabs items={['Move']}>
53+
<Tab>
54+
<DynamicCode targets={{
55+
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
56+
"2222": (ctx) => ctx.get("max_age_secs", "<max_age_secs>")
57+
}}>
58+
```rust copy
59+
use pyth::pyth;
60+
use pyth::price_identifier;
61+
62+
pyth::get_ema_price_no_older_than(
63+
price_identifier::from_byte_vec(x"1111"),
64+
2222
65+
);
66+
```
67+
</DynamicCode>
68+
</Tab>
69+
70+
</Tabs>

pages/sui/get-ema-price-unsafe.mdx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import Input from "../../components/Input";
2+
import Arg from "../../components/Arg";
3+
import Example from "../../components/Example";
4+
import DynamicCode from "../../components/DynamicCode";
5+
import { InputFormats } from "../../utils/InputFormat";
6+
import { Tab, Tabs } from "nextra-theme-docs";
7+
import Examples from "../../components/Examples";
8+
9+
# Get EMA Price Unsafe
10+
11+
Get the latest exponentially-weighted moving average (EMA) price and confidence interval for the requested price feed id.
12+
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.
13+
The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result.
14+
For example, a price of 1234 with an exponent of -2 represents the number 12.34.
15+
The result also includes a `timestamp` which is the unix timestamp for the price update.
16+
The EMA methodology is described in more detail in this [blog post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1).
17+
18+
**This function may return a price from arbitrarily far in the past.**
19+
It is the caller's responsibility to check the returned `timestamp` to ensure that the update is recent enough for their use case.
20+
21+
Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before
22+
reading it. This step ensures that the on-chain price is fresh.
23+
24+
<div className="mt-6 overflow-x-auto">
25+
26+
| Argument | Input | Description |
27+
| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- |
28+
| <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 |
29+
30+
</div>
31+
32+
<Examples>
33+
<Example
34+
keyValues={{
35+
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
36+
}}
37+
value="BTC/USD"
38+
/>
39+
<Example
40+
keyValues={{
41+
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
42+
}}
43+
value="ETH/USD"
44+
/>
45+
</Examples>
46+
47+
## Example Code
48+
49+
<Tabs items={['Move']}>
50+
<Tab>
51+
<DynamicCode targets={{
52+
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
53+
}}>
54+
```rust copy
55+
use pyth::pyth;
56+
use pyth::price_identifier;
57+
58+
pyth::get_ema_price_unsafe(price_identifier::from_byte_vec(x"1111"));
59+
```
60+
</DynamicCode>
61+
</Tab>
62+
63+
</Tabs>

pages/sui/get-ema-price.mdx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import Input from "../../components/Input";
2+
import Arg from "../../components/Arg";
3+
import { InputFormats } from "../../utils/InputFormat";
4+
import Example from "../../components/Example";
5+
import DynamicCode from "../../components/DynamicCode";
6+
import { Tab, Tabs } from "nextra-theme-docs";
7+
import Examples from "../../components/Examples";
8+
9+
# Get EMA Price
10+
11+
Get the latest exponentially-weighted moving average (EMA) price and confidence interval for the requested price feed id.
12+
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.
13+
The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result.
14+
For example, a price of 1234 with an exponent of -2 represents the number 12.34.
15+
The result also includes a `timestamp` which is the unix timestamp for the price update.
16+
The EMA methodology is described in more detail in this [blog post](https://pythnetwork.medium.com/whats-in-a-name-302a03e6c3e1).
17+
18+
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.
19+
The default valid time period is set to a reasonable default on each chain and is typically around 1 minute.
20+
If you would like to configure the valid time period, see [get_ema_price_no_older_than](get-ema-price-no-older-than).
21+
If you want the latest price regardless of when it was updated, see [get_ema_price_unsafe](get-ema-price-unsafe).
22+
23+
Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before
24+
reading it. This step ensures that the on-chain price is fresh.
25+
26+
<div className="mt-6 overflow-x-auto">
27+
28+
| Argument | Input | Description |
29+
| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- |
30+
| <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 |
31+
32+
</div>
33+
34+
<Examples>
35+
<Example
36+
keyValues={{
37+
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
38+
}}
39+
value="BTC/USD"
40+
/>
41+
<Example
42+
keyValues={{
43+
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
44+
}}
45+
value="ETH/USD"
46+
/>
47+
</Examples>
48+
49+
## Example Code
50+
51+
<Tabs items={['Move']}>
52+
<Tab>
53+
<DynamicCode targets={{
54+
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
55+
}}>
56+
```rust copy
57+
use pyth::pyth;
58+
use pyth::price_identifier;
59+
60+
pyth::get_ema_price(price_identifier::from_byte_vec(x"1111"));
61+
```
62+
</DynamicCode>
63+
</Tab>
64+
65+
</Tabs>

pages/sui/get-price-no-older-than.mdx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import Input from "../../components/Input";
2+
import Arg from "../../components/Arg";
3+
import Example from "../../components/Example";
4+
import DynamicCode from "../../components/DynamicCode";
5+
import { InputFormats } from "../../utils/InputFormat";
6+
import EvmCall from "../../components/EvmCall";
7+
import { Tab, Tabs } from "nextra-theme-docs";
8+
import Examples from "../../components/Examples";
9+
10+
# Get Price No Older Than
11+
12+
Get the latest price and confidence interval for the requested price feed id, if it has been updated sufficiently recently.
13+
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.
14+
The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result.
15+
For example, a price of 1234 with an exponent of -2 represents the number 12.34.
16+
The result also includes a `timestamp` which is the unix timestamp for the price update.
17+
18+
The caller provides a `max_age_secs` argument that specifies how old the price can be.
19+
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).
20+
21+
Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before
22+
reading it. This step ensures that the on-chain price is fresh and the call does not revert.
23+
24+
<div className="mt-6 overflow-x-auto">
25+
26+
| Argument | Input | Description |
27+
| ------------------------------------------------------ | --------------------------------------------------------- | --------------------------------------------- |
28+
| <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 |
29+
| <Arg required={true} type="int">max_age_secs</Arg> | <Input id="max_age_secs" /> | Maximum age of the on-chain price in seconds. |
30+
31+
</div>
32+
33+
<Examples>
34+
<Example
35+
keyValues={{
36+
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
37+
max_age_secs: () => 60,
38+
}}
39+
value="BTC/USD"
40+
/>
41+
<Example
42+
keyValues={{
43+
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
44+
max_age_secs: () => 60,
45+
}}
46+
value="ETH/USD"
47+
/>
48+
</Examples>
49+
50+
## Example Code
51+
52+
<Tabs items={['Move']}>
53+
<Tab>
54+
<DynamicCode targets={{
55+
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
56+
"2222": (ctx) => ctx.get("max_age_secs", "<max_age_secs>")
57+
}}>
58+
```rust copy
59+
use pyth::pyth;
60+
use pyth::price_identifier;
61+
62+
pyth::get_price_no_older_than(
63+
price_identifier::from_byte_vec(x"1111"),
64+
2222
65+
);
66+
```
67+
</DynamicCode>
68+
</Tab>
69+
70+
</Tabs>

pages/sui/get-price-unsafe.mdx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import Input from "../../components/Input";
2+
import Arg from "../../components/Arg";
3+
import Example from "../../components/Example";
4+
import Examples from "../../components/Examples";
5+
import DynamicCode from "../../components/DynamicCode";
6+
import { InputFormats } from "../../utils/InputFormat";
7+
import { Tab, Tabs } from "nextra-theme-docs";
8+
9+
# Get Price Unsafe
10+
11+
Get the latest price and confidence interval for the requested price feed id.
12+
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.
13+
The returned price and confidence are decimal numbers written in the form `a * 10^e`, where `e` is an exponent included in the result.
14+
For example, a price of 1234 with an exponent of -2 represents the number 12.34.
15+
The result also includes a `timestamp` which is the unix timestamp for the price update.
16+
17+
**This function may return a price from arbitrarily far in the past.**
18+
It is the caller's responsibility to check the returned `timestamp` to ensure that the update is recent enough for their use case.
19+
20+
Users of this method will typically invoke [update_price_feeds](update-price-feeds) to update the on-chain price before
21+
reading it. This step ensures that the on-chain price is fresh.
22+
23+
<div className="mt-6 overflow-x-auto">
24+
25+
| Argument | Input | Description |
26+
| ------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------- |
27+
| <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 |
28+
29+
</div>
30+
31+
<Examples>
32+
<Example
33+
keyValues={{
34+
price_identifier: (ctx) => ctx.getFeedId("Crypto.BTC/USD"),
35+
}}
36+
value="BTC/USD"
37+
/>
38+
<Example
39+
keyValues={{
40+
price_identifier: (ctx) => ctx.getFeedId("Crypto.ETH/USD"),
41+
}}
42+
value="ETH/USD"
43+
/>
44+
</Examples>
45+
46+
## Example Code
47+
48+
<Tabs items={['Move']}>
49+
<Tab>
50+
<DynamicCode targets={{
51+
"\"1111\"": (ctx) => `"${ctx.get("price_identifier", "<price_identifier>")}"`,
52+
}}>
53+
```rust copy
54+
use pyth::pyth;
55+
use pyth::price_identifier;
56+
57+
pyth::get_price_unsafe(price_identifier::from_byte_vec(x"1111"));
58+
```
59+
</DynamicCode>
60+
</Tab>
61+
62+
</Tabs>

0 commit comments

Comments
 (0)