af_oracle/
lib.rs

1#![cfg_attr(all(doc, not(doctest)), feature(doc_auto_cfg))]
2
3//! Move types for Aftermath's `AfOracle` package
4
5use af_utilities::types::IFixed;
6use sui_framework_sdk::object::{ID, UID};
7
8pub mod errors;
9pub mod event_ext;
10pub mod event_instance;
11#[cfg(feature = "graphql")]
12pub mod graphql;
13
14af_sui_pkg_sdk::sui_pkg_sdk!(af_oracle {
15    module oracle {
16        // =========================================================================
17        //  Objects
18        // =========================================================================
19
20        /// Capability object required to create/remove price feeds.
21        ///
22        /// Created as a single-writer object, unique.
23        struct AuthorityCap has key, store {
24            id: UID,
25        }
26
27        /// Object that stores all the price feeds for this aggregation.
28        struct PriceFeedStorage has key, store {
29            id: UID,
30            /// Symbol for this price feed storage
31            symbol: String,
32            /// Amount of decimals for this price feed storage.
33            decimals: u64,
34            /// List of source wrapper ids having a feed in this storage.
35            /// Each ID is used as key for the dynamic field containing the price feed
36            source_wrapper_ids: vector<ID>,
37        }
38
39        /// Object that identifies a price feed for a single source.
40        struct PriceFeed has key, store {
41            id: UID,
42            /// Price value.
43            price: IFixed,
44            /// Price timestamp.
45            timestamp: u64,
46            /// Allowed gap between current
47            /// and provided timestamp.
48            time_tolerance: u64,
49        }
50
51        /// Signals a package's capability to act as a price feed source.
52        struct SourceCap has store {}
53    }
54
55    module keys {
56        /// Key type for accessing price feed for particular source.
57        struct PriceFeedForSource has copy, drop, store {
58            source_wrapper_id: ID,
59        }
60
61        /// For attaching a capability to an app.
62        ///
63        /// This ensures only this package has access to this dynamic field since the key can only be
64        /// constructed here.
65        struct Authorization has copy, drop, store {}
66    }
67
68    module events {
69        struct CreatedPriceFeedStorage has copy, drop {
70            price_feed_storage_id: ID,
71            symbol: String,
72            decimals: u64
73        }
74
75        struct AddedAuthorization has copy, drop {
76            source_wrapper_id: ID,
77        }
78
79        struct RemovedAuthorization has copy, drop {
80            source_wrapper_id: ID,
81        }
82
83        struct CreatedPriceFeed has copy, drop {
84            price_feed_storage_id: ID,
85            source_wrapper_id: ID,
86            price: IFixed,
87            timestamp: u64,
88            time_tolerance: u64,
89        }
90
91        struct RemovedPriceFeed has copy, drop {
92            price_feed_storage_id: ID,
93            source_wrapper_id: ID,
94        }
95
96        struct UpdatedPriceFeed has copy, drop {
97            price_feed_storage_id: ID,
98            source_wrapper_id: ID,
99            old_price: IFixed,
100            old_timestamp: u64,
101            new_price: IFixed,
102            new_timestamp: u64,
103        }
104
105        struct UpdatedPriceFeedTimeTolerance has copy, drop {
106            price_feed_storage_id: ID,
107            source_wrapper_id: ID,
108            old_time_tolerance: u64,
109            new_time_tolerance: u64,
110        }
111    }
112});