1#![cfg_attr(all(doc, not(doctest)), feature(doc_auto_cfg))]
2
3use af_sui_types::Address;
6use af_utilities::types::IFixed;
7use sui_framework_sdk::object::{ID, UID};
8use sui_framework_sdk::{Field, FieldTypeTag};
9
10pub mod errors;
11pub mod event_ext;
12pub mod event_instance;
13#[cfg(feature = "graphql")]
14pub mod graphql;
15
16pub use self::oracle::{PriceFeed, PriceFeedStorage, PriceFeedStorageTypeTag, PriceFeedTypeTag};
18
19pub type PriceFeedDf = Field<keys::PriceFeedForSource, PriceFeed>;
21
22af_sui_pkg_sdk::sui_pkg_sdk!(af_oracle {
23 module oracle {
24 struct AuthorityCap has key, store {
32 id: UID,
33 }
34
35 struct PriceFeedStorage has key, store {
37 id: UID,
38 symbol: String,
40 decimals: u64,
42 source_wrapper_ids: vector<ID>,
45 }
46
47 struct PriceFeed has key, store {
49 id: UID,
50 price: IFixed,
52 timestamp: u64,
54 time_tolerance: u64,
57 }
58
59 struct SourceCap has store {}
61 }
62
63 module keys {
64 struct PriceFeedForSource has copy, drop, store {
66 source_wrapper_id: ID,
67 }
68
69 struct Authorization has copy, drop, store {}
74 }
75
76 module events {
77 struct CreatedPriceFeedStorage has copy, drop {
78 price_feed_storage_id: ID,
79 symbol: String,
80 decimals: u64
81 }
82
83 struct AddedAuthorization has copy, drop {
84 source_wrapper_id: ID,
85 }
86
87 struct RemovedAuthorization has copy, drop {
88 source_wrapper_id: ID,
89 }
90
91 struct CreatedPriceFeed has copy, drop {
92 price_feed_storage_id: ID,
93 source_wrapper_id: ID,
94 price: IFixed,
95 timestamp: u64,
96 time_tolerance: u64,
97 }
98
99 struct RemovedPriceFeed has copy, drop {
100 price_feed_storage_id: ID,
101 source_wrapper_id: ID,
102 }
103
104 struct UpdatedPriceFeed has copy, drop {
105 price_feed_storage_id: ID,
106 source_wrapper_id: ID,
107 old_price: IFixed,
108 old_timestamp: u64,
109 new_price: IFixed,
110 new_timestamp: u64,
111 }
112
113 struct UpdatedPriceFeedTimeTolerance has copy, drop {
114 price_feed_storage_id: ID,
115 source_wrapper_id: ID,
116 old_time_tolerance: u64,
117 new_time_tolerance: u64,
118 }
119 }
120});
121
122impl PriceFeedStorage {
123 pub fn price_feed_df_type(
125 package: Address,
126 ) -> FieldTypeTag<self::keys::PriceFeedForSource, PriceFeed> {
127 Field::type_(
128 self::keys::PriceFeedForSource::type_(package),
129 PriceFeed::type_(package),
130 )
131 }
132}