astar_primitives/oracle.rs
1// This file is part of Astar.
2
3// Copyright (C) Stake Technologies Pte.Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6// Astar is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// Astar is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with Astar. If not, see <http://www.gnu.org/licenses/>.
18
19use frame_support::{pallet_prelude::*, traits::Time};
20use sp_arithmetic::fixed_point::FixedU128;
21use sp_std::vec::Vec;
22
23/// Interface for fetching price of the native token.
24pub trait PriceProvider {
25 /// Get the price of the native token.
26 fn average_price() -> Price;
27}
28
29pub type Price = FixedU128;
30pub type CurrencyAmount = FixedU128;
31
32#[derive(
33 Encode,
34 Decode,
35 DecodeWithMemTracking,
36 MaxEncodedLen,
37 Clone,
38 Copy,
39 Debug,
40 PartialEq,
41 Eq,
42 TypeInfo,
43)]
44pub enum CurrencyId {
45 ASTR,
46 SDN,
47}
48
49type TimestampedValue<T, I = ()> =
50 orml_oracle::TimestampedValue<Price, <<T as orml_oracle::Config<I>>::Time as Time>::Moment>;
51
52/// A dummy implementation of `CombineData` trait that does nothing.
53pub struct DummyCombineData<T, I = ()>(PhantomData<(T, I)>);
54impl<T: orml_oracle::Config<I>, I> orml_traits::CombineData<CurrencyId, TimestampedValue<T, I>>
55 for DummyCombineData<T, I>
56{
57 fn combine_data(
58 _key: &CurrencyId,
59 _values: Vec<TimestampedValue<T, I>>,
60 _prev_value: Option<TimestampedValue<T, I>>,
61 ) -> Option<TimestampedValue<T, I>> {
62 None
63 }
64}