osmosis_std/types/osmosis/twap/
v1beta1.rs

1use osmosis_std_derive::CosmwasmExt;
2/// A TWAP record should be indexed in state by pool_id, (asset pair), timestamp
3/// The asset pair assets should be lexicographically sorted.
4/// Technically (pool_id, asset_0_denom, asset_1_denom, height) do not need to
5/// appear in the struct however we view this as the wrong performance tradeoff
6/// given SDK today. Would rather we optimize for readability and correctness,
7/// than an optimal state storage format. The system bottleneck is elsewhere for
8/// now.
9#[allow(clippy::derive_partial_eq_without_eq)]
10#[derive(
11    Clone,
12    PartialEq,
13    Eq,
14    ::prost::Message,
15    ::serde::Serialize,
16    ::serde::Deserialize,
17    ::schemars::JsonSchema,
18    CosmwasmExt,
19)]
20#[proto_message(type_url = "/osmosis.twap.v1beta1.TwapRecord")]
21pub struct TwapRecord {
22    #[prost(uint64, tag = "1")]
23    #[serde(alias = "poolID")]
24    #[serde(
25        serialize_with = "crate::serde::as_str::serialize",
26        deserialize_with = "crate::serde::as_str::deserialize"
27    )]
28    pub pool_id: u64,
29    /// Lexicographically smaller denom of the pair
30    #[prost(string, tag = "2")]
31    pub asset0_denom: ::prost::alloc::string::String,
32    /// Lexicographically larger denom of the pair
33    #[prost(string, tag = "3")]
34    pub asset1_denom: ::prost::alloc::string::String,
35    /// height this record corresponds to, for debugging purposes
36    #[prost(int64, tag = "4")]
37    #[serde(
38        serialize_with = "crate::serde::as_str::serialize",
39        deserialize_with = "crate::serde::as_str::deserialize"
40    )]
41    pub height: i64,
42    /// This field should only exist until we have a global registry in the state
43    /// machine, mapping prior block heights within {TIME RANGE} to times.
44    #[prost(message, optional, tag = "5")]
45    pub time: ::core::option::Option<crate::shim::Timestamp>,
46    /// We store the last spot prices in the struct, so that we can interpolate
47    /// accumulator values for times between when accumulator records are stored.
48    #[prost(string, tag = "6")]
49    pub p0_last_spot_price: ::prost::alloc::string::String,
50    #[prost(string, tag = "7")]
51    pub p1_last_spot_price: ::prost::alloc::string::String,
52    #[prost(string, tag = "8")]
53    pub p0_arithmetic_twap_accumulator: ::prost::alloc::string::String,
54    #[prost(string, tag = "9")]
55    pub p1_arithmetic_twap_accumulator: ::prost::alloc::string::String,
56    #[prost(string, tag = "10")]
57    pub geometric_twap_accumulator: ::prost::alloc::string::String,
58    /// This field contains the time in which the last spot price error occurred.
59    /// It is used to alert the caller if they are getting a potentially erroneous
60    /// TWAP, due to an unforeseen underlying error.
61    #[prost(message, optional, tag = "11")]
62    pub last_error_time: ::core::option::Option<crate::shim::Timestamp>,
63}
64/// PruningState allows us to spread out the pruning of TWAP records over time,
65/// instead of pruning all at once at the end of the epoch.
66#[allow(clippy::derive_partial_eq_without_eq)]
67#[derive(
68    Clone,
69    PartialEq,
70    Eq,
71    ::prost::Message,
72    ::serde::Serialize,
73    ::serde::Deserialize,
74    ::schemars::JsonSchema,
75    CosmwasmExt,
76)]
77#[proto_message(type_url = "/osmosis.twap.v1beta1.PruningState")]
78pub struct PruningState {
79    /// is_pruning is true if the pruning process is ongoing.
80    /// This tells the module to continue pruning the TWAP records
81    /// at the EndBlock.
82    #[prost(bool, tag = "1")]
83    pub is_pruning: bool,
84    /// last_kept_time is the time of the last kept TWAP record.
85    /// This is used to determine all TWAP records that are older than
86    /// last_kept_time and should be pruned.
87    #[prost(message, optional, tag = "2")]
88    pub last_kept_time: ::core::option::Option<crate::shim::Timestamp>,
89    /// Deprecated: This field is deprecated.
90    #[deprecated]
91    #[prost(bytes = "vec", tag = "3")]
92    #[serde(
93        serialize_with = "crate::serde::as_base64_encoded_string::serialize",
94        deserialize_with = "crate::serde::as_base64_encoded_string::deserialize"
95    )]
96    pub last_key_seen: ::prost::alloc::vec::Vec<u8>,
97    /// last_seen_pool_id is the pool_id that we will begin pruning in the next
98    /// block. This value starts at the highest pool_id at time of epoch, and
99    /// decreases until it reaches 1. When it reaches 1, the pruning
100    /// process is complete.
101    #[prost(uint64, tag = "4")]
102    #[serde(alias = "last_seen_poolID")]
103    #[serde(
104        serialize_with = "crate::serde::as_str::serialize",
105        deserialize_with = "crate::serde::as_str::deserialize"
106    )]
107    pub last_seen_pool_id: u64,
108}
109/// Params holds parameters for the twap module
110#[allow(clippy::derive_partial_eq_without_eq)]
111#[derive(
112    Clone,
113    PartialEq,
114    Eq,
115    ::prost::Message,
116    ::serde::Serialize,
117    ::serde::Deserialize,
118    ::schemars::JsonSchema,
119    CosmwasmExt,
120)]
121#[proto_message(type_url = "/osmosis.twap.v1beta1.Params")]
122pub struct Params {
123    #[prost(string, tag = "1")]
124    #[serde(alias = "prune_epochIDentifier")]
125    pub prune_epoch_identifier: ::prost::alloc::string::String,
126    #[prost(message, optional, tag = "2")]
127    pub record_history_keep_period: ::core::option::Option<crate::shim::Duration>,
128}
129/// GenesisState defines the twap module's genesis state.
130#[allow(clippy::derive_partial_eq_without_eq)]
131#[derive(
132    Clone,
133    PartialEq,
134    Eq,
135    ::prost::Message,
136    ::serde::Serialize,
137    ::serde::Deserialize,
138    ::schemars::JsonSchema,
139    CosmwasmExt,
140)]
141#[proto_message(type_url = "/osmosis.twap.v1beta1.GenesisState")]
142pub struct GenesisState {
143    /// twaps is the collection of all twap records.
144    #[prost(message, repeated, tag = "1")]
145    pub twaps: ::prost::alloc::vec::Vec<TwapRecord>,
146    /// params is the container of twap parameters.
147    #[prost(message, optional, tag = "2")]
148    pub params: ::core::option::Option<Params>,
149}
150#[allow(clippy::derive_partial_eq_without_eq)]
151#[derive(
152    Clone,
153    PartialEq,
154    Eq,
155    ::prost::Message,
156    ::serde::Serialize,
157    ::serde::Deserialize,
158    ::schemars::JsonSchema,
159    CosmwasmExt,
160)]
161#[proto_message(type_url = "/osmosis.twap.v1beta1.ArithmeticTwapRequest")]
162#[proto_query(
163    path = "/osmosis.twap.v1beta1.Query/ArithmeticTwap",
164    response_type = ArithmeticTwapResponse
165)]
166pub struct ArithmeticTwapRequest {
167    #[prost(uint64, tag = "1")]
168    #[serde(alias = "poolID")]
169    #[serde(
170        serialize_with = "crate::serde::as_str::serialize",
171        deserialize_with = "crate::serde::as_str::deserialize"
172    )]
173    pub pool_id: u64,
174    #[prost(string, tag = "2")]
175    pub base_asset: ::prost::alloc::string::String,
176    #[prost(string, tag = "3")]
177    pub quote_asset: ::prost::alloc::string::String,
178    #[prost(message, optional, tag = "4")]
179    pub start_time: ::core::option::Option<crate::shim::Timestamp>,
180    #[prost(message, optional, tag = "5")]
181    pub end_time: ::core::option::Option<crate::shim::Timestamp>,
182}
183#[allow(clippy::derive_partial_eq_without_eq)]
184#[derive(
185    Clone,
186    PartialEq,
187    Eq,
188    ::prost::Message,
189    ::serde::Serialize,
190    ::serde::Deserialize,
191    ::schemars::JsonSchema,
192    CosmwasmExt,
193)]
194#[proto_message(type_url = "/osmosis.twap.v1beta1.ArithmeticTwapResponse")]
195pub struct ArithmeticTwapResponse {
196    #[prost(string, tag = "1")]
197    pub arithmetic_twap: ::prost::alloc::string::String,
198}
199#[allow(clippy::derive_partial_eq_without_eq)]
200#[derive(
201    Clone,
202    PartialEq,
203    Eq,
204    ::prost::Message,
205    ::serde::Serialize,
206    ::serde::Deserialize,
207    ::schemars::JsonSchema,
208    CosmwasmExt,
209)]
210#[proto_message(type_url = "/osmosis.twap.v1beta1.ArithmeticTwapToNowRequest")]
211#[proto_query(
212    path = "/osmosis.twap.v1beta1.Query/ArithmeticTwapToNow",
213    response_type = ArithmeticTwapToNowResponse
214)]
215pub struct ArithmeticTwapToNowRequest {
216    #[prost(uint64, tag = "1")]
217    #[serde(alias = "poolID")]
218    #[serde(
219        serialize_with = "crate::serde::as_str::serialize",
220        deserialize_with = "crate::serde::as_str::deserialize"
221    )]
222    pub pool_id: u64,
223    #[prost(string, tag = "2")]
224    pub base_asset: ::prost::alloc::string::String,
225    #[prost(string, tag = "3")]
226    pub quote_asset: ::prost::alloc::string::String,
227    #[prost(message, optional, tag = "4")]
228    pub start_time: ::core::option::Option<crate::shim::Timestamp>,
229}
230#[allow(clippy::derive_partial_eq_without_eq)]
231#[derive(
232    Clone,
233    PartialEq,
234    Eq,
235    ::prost::Message,
236    ::serde::Serialize,
237    ::serde::Deserialize,
238    ::schemars::JsonSchema,
239    CosmwasmExt,
240)]
241#[proto_message(type_url = "/osmosis.twap.v1beta1.ArithmeticTwapToNowResponse")]
242pub struct ArithmeticTwapToNowResponse {
243    #[prost(string, tag = "1")]
244    pub arithmetic_twap: ::prost::alloc::string::String,
245}
246#[allow(clippy::derive_partial_eq_without_eq)]
247#[derive(
248    Clone,
249    PartialEq,
250    Eq,
251    ::prost::Message,
252    ::serde::Serialize,
253    ::serde::Deserialize,
254    ::schemars::JsonSchema,
255    CosmwasmExt,
256)]
257#[proto_message(type_url = "/osmosis.twap.v1beta1.GeometricTwapRequest")]
258#[proto_query(
259    path = "/osmosis.twap.v1beta1.Query/GeometricTwap",
260    response_type = GeometricTwapResponse
261)]
262pub struct GeometricTwapRequest {
263    #[prost(uint64, tag = "1")]
264    #[serde(alias = "poolID")]
265    #[serde(
266        serialize_with = "crate::serde::as_str::serialize",
267        deserialize_with = "crate::serde::as_str::deserialize"
268    )]
269    pub pool_id: u64,
270    #[prost(string, tag = "2")]
271    pub base_asset: ::prost::alloc::string::String,
272    #[prost(string, tag = "3")]
273    pub quote_asset: ::prost::alloc::string::String,
274    #[prost(message, optional, tag = "4")]
275    pub start_time: ::core::option::Option<crate::shim::Timestamp>,
276    #[prost(message, optional, tag = "5")]
277    pub end_time: ::core::option::Option<crate::shim::Timestamp>,
278}
279#[allow(clippy::derive_partial_eq_without_eq)]
280#[derive(
281    Clone,
282    PartialEq,
283    Eq,
284    ::prost::Message,
285    ::serde::Serialize,
286    ::serde::Deserialize,
287    ::schemars::JsonSchema,
288    CosmwasmExt,
289)]
290#[proto_message(type_url = "/osmosis.twap.v1beta1.GeometricTwapResponse")]
291pub struct GeometricTwapResponse {
292    #[prost(string, tag = "1")]
293    pub geometric_twap: ::prost::alloc::string::String,
294}
295#[allow(clippy::derive_partial_eq_without_eq)]
296#[derive(
297    Clone,
298    PartialEq,
299    Eq,
300    ::prost::Message,
301    ::serde::Serialize,
302    ::serde::Deserialize,
303    ::schemars::JsonSchema,
304    CosmwasmExt,
305)]
306#[proto_message(type_url = "/osmosis.twap.v1beta1.GeometricTwapToNowRequest")]
307#[proto_query(
308    path = "/osmosis.twap.v1beta1.Query/GeometricTwapToNow",
309    response_type = GeometricTwapToNowResponse
310)]
311pub struct GeometricTwapToNowRequest {
312    #[prost(uint64, tag = "1")]
313    #[serde(alias = "poolID")]
314    #[serde(
315        serialize_with = "crate::serde::as_str::serialize",
316        deserialize_with = "crate::serde::as_str::deserialize"
317    )]
318    pub pool_id: u64,
319    #[prost(string, tag = "2")]
320    pub base_asset: ::prost::alloc::string::String,
321    #[prost(string, tag = "3")]
322    pub quote_asset: ::prost::alloc::string::String,
323    #[prost(message, optional, tag = "4")]
324    pub start_time: ::core::option::Option<crate::shim::Timestamp>,
325}
326#[allow(clippy::derive_partial_eq_without_eq)]
327#[derive(
328    Clone,
329    PartialEq,
330    Eq,
331    ::prost::Message,
332    ::serde::Serialize,
333    ::serde::Deserialize,
334    ::schemars::JsonSchema,
335    CosmwasmExt,
336)]
337#[proto_message(type_url = "/osmosis.twap.v1beta1.GeometricTwapToNowResponse")]
338pub struct GeometricTwapToNowResponse {
339    #[prost(string, tag = "1")]
340    pub geometric_twap: ::prost::alloc::string::String,
341}
342#[allow(clippy::derive_partial_eq_without_eq)]
343#[derive(
344    Clone,
345    PartialEq,
346    Eq,
347    ::prost::Message,
348    ::serde::Serialize,
349    ::serde::Deserialize,
350    ::schemars::JsonSchema,
351    CosmwasmExt,
352)]
353#[proto_message(type_url = "/osmosis.twap.v1beta1.ParamsRequest")]
354#[proto_query(
355    path = "/osmosis.twap.v1beta1.Query/Params",
356    response_type = ParamsResponse
357)]
358pub struct ParamsRequest {}
359#[allow(clippy::derive_partial_eq_without_eq)]
360#[derive(
361    Clone,
362    PartialEq,
363    Eq,
364    ::prost::Message,
365    ::serde::Serialize,
366    ::serde::Deserialize,
367    ::schemars::JsonSchema,
368    CosmwasmExt,
369)]
370#[proto_message(type_url = "/osmosis.twap.v1beta1.ParamsResponse")]
371pub struct ParamsResponse {
372    #[prost(message, optional, tag = "1")]
373    pub params: ::core::option::Option<Params>,
374}
375pub struct TwapQuerier<'a, Q: cosmwasm_std::CustomQuery> {
376    querier: &'a cosmwasm_std::QuerierWrapper<'a, Q>,
377}
378impl<'a, Q: cosmwasm_std::CustomQuery> TwapQuerier<'a, Q> {
379    pub fn new(querier: &'a cosmwasm_std::QuerierWrapper<'a, Q>) -> Self {
380        Self { querier }
381    }
382    pub fn params(&self) -> Result<ParamsResponse, cosmwasm_std::StdError> {
383        ParamsRequest {}.query(self.querier)
384    }
385    pub fn arithmetic_twap(
386        &self,
387        pool_id: u64,
388        base_asset: ::prost::alloc::string::String,
389        quote_asset: ::prost::alloc::string::String,
390        start_time: ::core::option::Option<crate::shim::Timestamp>,
391        end_time: ::core::option::Option<crate::shim::Timestamp>,
392    ) -> Result<ArithmeticTwapResponse, cosmwasm_std::StdError> {
393        ArithmeticTwapRequest {
394            pool_id,
395            base_asset,
396            quote_asset,
397            start_time,
398            end_time,
399        }
400        .query(self.querier)
401    }
402    pub fn arithmetic_twap_to_now(
403        &self,
404        pool_id: u64,
405        base_asset: ::prost::alloc::string::String,
406        quote_asset: ::prost::alloc::string::String,
407        start_time: ::core::option::Option<crate::shim::Timestamp>,
408    ) -> Result<ArithmeticTwapToNowResponse, cosmwasm_std::StdError> {
409        ArithmeticTwapToNowRequest {
410            pool_id,
411            base_asset,
412            quote_asset,
413            start_time,
414        }
415        .query(self.querier)
416    }
417    pub fn geometric_twap(
418        &self,
419        pool_id: u64,
420        base_asset: ::prost::alloc::string::String,
421        quote_asset: ::prost::alloc::string::String,
422        start_time: ::core::option::Option<crate::shim::Timestamp>,
423        end_time: ::core::option::Option<crate::shim::Timestamp>,
424    ) -> Result<GeometricTwapResponse, cosmwasm_std::StdError> {
425        GeometricTwapRequest {
426            pool_id,
427            base_asset,
428            quote_asset,
429            start_time,
430            end_time,
431        }
432        .query(self.querier)
433    }
434    pub fn geometric_twap_to_now(
435        &self,
436        pool_id: u64,
437        base_asset: ::prost::alloc::string::String,
438        quote_asset: ::prost::alloc::string::String,
439        start_time: ::core::option::Option<crate::shim::Timestamp>,
440    ) -> Result<GeometricTwapToNowResponse, cosmwasm_std::StdError> {
441        GeometricTwapToNowRequest {
442            pool_id,
443            base_asset,
444            quote_asset,
445            start_time,
446        }
447        .query(self.querier)
448    }
449}