pyth_sui_sdk/lib.rs
1#![cfg_attr(all(doc, not(doctest)), feature(doc_cfg))]
2
3//! Sdk for Pyth's Sui package.
4
5use af_sui_pkg_sdk::sui_pkg_sdk;
6use sui_framework_sdk::object::UID;
7use sui_framework_sdk::package::UpgradeCap;
8use wormhole_sui_sdk::consumed_vaas::ConsumedVAAs;
9use wormhole_sui_sdk::external_address::ExternalAddress;
10
11#[cfg(feature = "pyth-sdk")]
12mod pyth_sdk;
13#[cfg(feature = "json-rpc")]
14pub mod read;
15#[cfg(feature = "ptb")]
16pub mod update;
17
18sui_pkg_sdk!(pyth {
19 module state {
20 /// Capability reflecting that the current build version is used to invoke
21 /// state methods.
22 struct LatestOnly has drop {}
23
24 struct State has key, store {
25 id: UID,
26 governance_data_source: data_source::DataSource,
27 stale_price_threshold: u64,
28 base_update_fee: u64,
29 fee_recipient_address: address,
30 last_executed_governance_sequence: u64,
31 consumed_vaas: ConsumedVAAs,
32
33 // Upgrade capability.
34 upgrade_cap: UpgradeCap
35 }
36 }
37
38 module data_source {
39 struct DataSource has copy, drop, store {
40 emitter_chain: u64,
41 emitter_address: ExternalAddress,
42 }
43 }
44
45 module price_info {
46 /// Sui object version of PriceInfo.
47 /// Has a key ability, is unique for each price identifier, and lives in global store.
48 struct PriceInfoObject has key, store {
49 id: UID,
50 price_info: PriceInfo
51 }
52
53 /// Copyable and droppable.
54 struct PriceInfo has copy, drop, store {
55 attestation_time: u64,
56 arrival_time: u64,
57 price_feed: price_feed::PriceFeed,
58 }
59 }
60
61 module price_feed {
62 /// PriceFeed represents a current aggregate price for a particular product.
63 struct PriceFeed has copy, drop, store {
64 /// The price identifier
65 price_identifier: price_identifier::PriceIdentifier,
66 /// The current aggregate price
67 price: price::Price,
68 /// The current exponentially moving average aggregate price
69 ema_price: price::Price,
70 }
71 }
72
73 module price_identifier {
74 struct PriceIdentifier has copy, drop, store {
75 bytes: vector<u8>,
76 }
77 }
78
79 module price {
80 /// A price with a degree of uncertainty, represented as a price +- a confidence interval.
81 ///
82 /// The confidence interval roughly corresponds to the standard error of a normal distribution.
83 /// Both the price and confidence are stored in a fixed-point numeric representation,
84 /// `x * (10^expo)`, where `expo` is the exponent.
85 //
86 /// Please refer to the documentation at https://docs.pyth.network/documentation/pythnet-price-feeds/best-practices for how
87 /// to how this price safely.
88 struct Price has copy, drop, store {
89 price: i64::I64,
90 /// Confidence interval around the price
91 conf: u64,
92 /// The exponent
93 expo: i64::I64,
94 /// Unix timestamp of when this price was computed
95 timestamp: u64,
96 }
97 }
98
99 module i64 {
100 /// As Move does not support negative numbers natively, we use our own internal
101 /// representation.
102 ///
103 /// To consume these values, first call `get_is_negative()` to determine if the I64
104 /// represents a negative or positive value. Then call `get_magnitude_if_positive()` or
105 /// `get_magnitude_if_negative()` to get the magnitude of the number in unsigned u64 format.
106 /// This API forces consumers to handle positive and negative numbers safely.
107 struct I64 has copy, drop, store {
108 negative: bool,
109 magnitude: u64,
110 }
111 }
112});