diff --git a/xpallets/dex/spot/src/benchmarking.rs b/xpallets/dex/spot/src/benchmarking.rs index 383af4bbd..d7484f376 100644 --- a/xpallets/dex/spot/src/benchmarking.rs +++ b/xpallets/dex/spot/src/benchmarking.rs @@ -88,7 +88,7 @@ benchmarks! { set_price_fluctuation { }: _(RawOrigin::Root, PAIR_ID, 1000) verify { - assert_eq!(PriceFluctuationOf::get(PAIR_ID), 1000); + assert_eq!(PriceFluctuationOf::::get(PAIR_ID), 1000); } add_trading_pair { diff --git a/xpallets/dex/spot/src/execution/asset.rs b/xpallets/dex/spot/src/execution/asset.rs index a7803f442..06563ed11 100644 --- a/xpallets/dex/spot/src/execution/asset.rs +++ b/xpallets/dex/spot/src/execution/asset.rs @@ -5,7 +5,7 @@ use super::*; use xpallet_assets::AssetType::{self, ReservedDexSpot, Usable}; -impl Module { +impl Pallet { /// Delivery the assets to maker and taker respectively when executing the order. pub(super) fn delivery_asset_to_each_other( maker_order_side: Side, diff --git a/xpallets/dex/spot/src/execution/mod.rs b/xpallets/dex/spot/src/execution/mod.rs index 30be6c67b..8a5c6d618 100644 --- a/xpallets/dex/spot/src/execution/mod.rs +++ b/xpallets/dex/spot/src/execution/mod.rs @@ -9,7 +9,7 @@ use frame_support::log::debug; use super::*; use crate::types::*; -impl Module { +impl Pallet { fn check_bid_price( quote: T::Price, lowest_ask: T::Price, diff --git a/xpallets/dex/spot/src/execution/order.rs b/xpallets/dex/spot/src/execution/order.rs index 693fef20e..544d92361 100644 --- a/xpallets/dex/spot/src/execution/order.rs +++ b/xpallets/dex/spot/src/execution/order.rs @@ -6,7 +6,7 @@ use super::*; use sp_runtime::traits::CheckedAdd; use sp_std::cmp::Ordering; -impl Module { +impl Pallet { /// When the price is far from the current handicap, i.e., /// - buy: less than the lowest_ask /// - sell: larger than the highest_bid @@ -353,7 +353,7 @@ impl Module { let pair = Self::trading_pair(pair_id)?; let trading_history_idx = Self::trading_history_index_of(pair_id); - TradingHistoryIndexOf::insert(pair_id, trading_history_idx + 1); + TradingHistoryIndexOf::::insert(pair_id, trading_history_idx + 1); Self::update_order_on_execute(maker_order, &turnover, trading_history_idx); Self::update_order_on_execute(taker_order, &turnover, trading_history_idx); diff --git a/xpallets/dex/spot/src/execution/state.rs b/xpallets/dex/spot/src/execution/state.rs index 0f19fa385..a5051940e 100644 --- a/xpallets/dex/spot/src/execution/state.rs +++ b/xpallets/dex/spot/src/execution/state.rs @@ -7,7 +7,7 @@ use crate::types::Side::{Buy, Sell}; use sp_runtime::traits::{CheckedAdd, CheckedSub}; /// Internal mutables -impl Module { +impl Pallet { /// It's worth noting that the handicap is not always related to some real orders, i.e., /// current lowest_ask(or highest_bid) is suprious. /// diff --git a/xpallets/dex/spot/src/lib.rs b/xpallets/dex/spot/src/lib.rs index 0ff481b83..d5d746c3d 100644 --- a/xpallets/dex/spot/src/lib.rs +++ b/xpallets/dex/spot/src/lib.rs @@ -27,7 +27,6 @@ use sp_std::prelude::*; use sp_std::{cmp, fmt::Debug}; use frame_support::{ - decl_error, decl_event, decl_module, decl_storage, dispatch::{DispatchError, DispatchResult}, ensure, log::info, @@ -72,101 +71,195 @@ pub type OrderInfo = Order< pub type HandicapInfo = Handicap<::Price>; -pub trait Config: xpallet_assets::Config { - /// The overarching event type. - type Event: From> + Into<::Event>; - - /// The price of an order. - type Price: Parameter - + Member - + AtLeast32BitUnsigned - + Codec - + Default - + Copy - + MaybeSerializeDeserialize - + Debug; - - type WeightInfo: WeightInfo; -} +pub use pallet::*; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + use frame_support::pallet_prelude::*; + use frame_system::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config + xpallet_assets::Config { + /// The overarching event type. + type Event: From> + IsType<::Event>; + + /// The price of an order. + type Price: Parameter + + Member + + AtLeast32BitUnsigned + + Codec + + Default + + Copy + + MaybeSerializeDeserialize + + Debug; + + type WeightInfo: WeightInfo; + } -decl_storage! { - trait Store for Module as XSpot { - /// How many trading pairs so far. - pub TradingPairCount get(fn trading_pair_count): TradingPairId; + #[pallet::pallet] + #[pallet::generate_store(pub(crate) trait Store)] + pub struct Pallet(PhantomData); - /// Record the exact balance of reserved native coins in Spot. - pub NativeReserves get(fn native_reserves): - map hasher(twox_64_concat) T::AccountId => BalanceOf; + #[pallet::call] + impl Pallet { + #[pallet::weight(::WeightInfo::put_order())] + pub fn put_order( + origin: OriginFor, + #[pallet::compact] pair_id: TradingPairId, + order_type: OrderType, + side: Side, + #[pallet::compact] amount: BalanceOf, + #[pallet::compact] price: T::Price, + ) -> DispatchResult { + let who = ensure_signed(origin)?; - /// The map from trading pair id to its static profile. - pub TradingPairOf get(fn trading_pair_of): - map hasher(twox_64_concat) TradingPairId => Option; + ensure!(!price.is_zero(), Error::::InvalidPrice); + ensure!(!amount.is_zero(), Error::::ZeroAmount); + ensure!(order_type == OrderType::Limit, Error::::InvalidOrderType); - /// (latest price, last update height) of trading pair - pub TradingPairInfoOf get(fn trading_pair_info_of): - map hasher(twox_64_concat) TradingPairId => Option>; + let pair = Self::trading_pair(pair_id)?; - /// Total transactions has been made for a trading pair. - pub TradingHistoryIndexOf get(fn trading_history_index_of): - map hasher(twox_64_concat) TradingPairId => TradingHistoryIndex; + ensure!(pair.tradable, Error::::TradingPairUntradable); + ensure!(pair.is_valid_price(price), Error::::InvalidPrice); - /// Total orders made by an account. - pub OrderCountOf get(fn order_count_of): - map hasher(twox_64_concat) T::AccountId => OrderId; + Self::is_valid_quote(price, side, pair_id)?; + Self::has_too_many_backlog_orders(pair_id, price, side)?; - /// Details of an user order given the account ID and order ID. - pub OrderInfoOf get(fn order_info_of): - double_map hasher(twox_64_concat) T::AccountId, hasher(twox_64_concat) OrderId - => Option>; + // Reserve the token according to the order side. + let (reserve_asset, reserve_amount) = match side { + Side::Buy => ( + pair.quote(), + Self::convert_base_to_quote(amount, price, &pair)?, + ), + Side::Sell => (pair.base(), amount), + }; + Self::put_order_reserve(&who, reserve_asset, reserve_amount)?; + Self::apply_put_order( + who, + pair_id, + order_type, + side, + amount, + price, + reserve_amount, + )?; + Ok(()) + } - /// All the accounts and the order number given the trading pair ID and price. - pub QuotationsOf get(fn quotations_of): - double_map hasher(twox_64_concat) TradingPairId, hasher(twox_64_concat) T::Price - => Vec<(T::AccountId, OrderId)>; + #[pallet::weight(::WeightInfo::cancel_order())] + pub fn cancel_order( + origin: OriginFor, + #[pallet::compact] pair_id: TradingPairId, + #[pallet::compact] order_id: OrderId, + ) -> DispatchResult { + let who = ensure_signed(origin)?; + Self::do_cancel_order(&who, pair_id, order_id)?; + Ok(()) + } - /// TradingPairId => (highest_bid, lowest_ask) - pub HandicapOf get(fn handicap_of): - map hasher(twox_64_concat) TradingPairId => HandicapInfo; + /// Force cancel an order. + #[pallet::weight(::WeightInfo::force_cancel_order())] + fn force_cancel_order( + origin: OriginFor, + who: ::Source, + #[pallet::compact] pair_id: TradingPairId, + #[pallet::compact] order_id: OrderId, + ) -> DispatchResult { + ensure_root(origin)?; + let who = T::Lookup::lookup(who)?; + Self::do_cancel_order(&who, pair_id, order_id)?; + Ok(()) + } - /// The map of trading pair ID to the price fluctuation. Use with caution! - pub PriceFluctuationOf get(fn price_fluctuation_of): - map hasher(twox_64_concat) TradingPairId => PriceFluctuation = DEFAULT_FLUCTUATION; - } + #[pallet::weight(::WeightInfo::set_handicap())] + pub fn set_handicap( + origin: OriginFor, + #[pallet::compact] pair_id: TradingPairId, + new: Handicap, + ) -> DispatchResult { + ensure_root(origin)?; + info!(target: "runtime::dex::spot", "[set_handicap] pair_id:{:?}, new handicap:{:?}", pair_id, new); + HandicapOf::::insert(pair_id, new); + Ok(()) + } - add_extra_genesis { - config(trading_pairs): Vec<(AssetId, AssetId, u32, u32, T::Price, bool)>; - build(|config| { - for (base, quote, pip_decimals, tick_decimals, price, tradable) in config.trading_pairs.iter() { - Module::::apply_add_trading_pair( - CurrencyPair::new(*base, *quote), - *pip_decimals, - *tick_decimals, - *price, - *tradable - ); - } - }) + #[pallet::weight(::WeightInfo::set_price_fluctuation())] + pub fn set_price_fluctuation( + origin: OriginFor, + #[pallet::compact] pair_id: TradingPairId, + #[pallet::compact] new: PriceFluctuation, + ) -> DispatchResult { + ensure_root(origin)?; + PriceFluctuationOf::::insert(pair_id, new); + Self::deposit_event(Event::::PriceFluctuationUpdated(pair_id, new)); + Ok(()) + } + + /// Add a new trading pair. + #[pallet::weight(::WeightInfo::add_trading_pair())] + pub fn add_trading_pair( + origin: OriginFor, + currency_pair: CurrencyPair, + #[pallet::compact] pip_decimals: u32, + #[pallet::compact] tick_decimals: u32, + #[pallet::compact] latest_price: T::Price, + tradable: bool, + ) -> DispatchResult { + ensure_root(origin)?; + ensure!( + Self::get_trading_pair_by_currency_pair(¤cy_pair).is_none(), + Error::::TradingPairAlreadyExists + ); + Self::apply_add_trading_pair( + currency_pair, + pip_decimals, + tick_decimals, + latest_price, + tradable, + ); + Ok(()) + } + + /// Update the trading pair profile. + #[pallet::weight(::WeightInfo::update_trading_pair())] + pub fn update_trading_pair( + origin: OriginFor, + #[pallet::compact] pair_id: TradingPairId, + #[pallet::compact] tick_decimals: u32, + tradable: bool, + ) -> DispatchResult { + ensure_root(origin)?; + let pair = Self::trading_pair(pair_id)?; + ensure!( + tick_decimals >= pair.tick_decimals, + Error::::InvalidTickdecimals + ); + Self::apply_update_trading_pair(pair_id, tick_decimals, tradable); + Ok(()) + } } -} -decl_event!( - pub enum Event - where - Balance = BalanceOf, - ::AccountId, - ::BlockNumber, - ::Price, - { + #[pallet::event] + #[pallet::metadata(BalanceOf = "Balance", T::AccountId = "AccountId", T::BlockNumber = "BlockNumber", T::Price = "Price")] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { /// A new order was created. [order_info] - NewOrder(Order), + NewOrder(Order, T::Price, T::BlockNumber>), /// There was an update to the order due to it gets executed. [maker_order_info] - MakerOrderUpdated(Order), + MakerOrderUpdated( + Order, T::Price, T::BlockNumber>, + ), /// There was an update to the order due to it gets executed. [taker_order_info] - TakerOrderUpdated(Order), + TakerOrderUpdated( + Order, T::Price, T::BlockNumber>, + ), /// Overall information about the maker and taker orders when there was an order execution. [order_executed_info] - OrderExecuted(OrderExecutedInfo), + OrderExecuted(OrderExecutedInfo, T::BlockNumber, T::Price>), /// There is an update to the order due to it gets canceled. [order_info] - CanceledOrderUpdated(Order), + CanceledOrderUpdated( + Order, T::Price, T::BlockNumber>, + ), /// A new trading pair is added. [pair_profile] TradingPairAdded(TradingPairProfile), /// Trading pair profile has been updated. [pair_profile] @@ -174,11 +267,10 @@ decl_event!( /// Price fluctuation of trading pair has been updated. [pair_id, price_fluctuation] PriceFluctuationUpdated(TradingPairId, PriceFluctuation), } -); -decl_error! { /// Error for the spot module. - pub enum Error for Module { + #[pallet::error] + pub enum Error { /// Price can not be zero, and must be an integer multiple of the tick decimals. InvalidPrice, /// The bid price can not higher than the PriceVolatility of current lowest ask. @@ -216,142 +308,133 @@ decl_error! { /// Error from assets module. AssetError, } -} -impl From for Error { - fn from(_: AssetErr) -> Self { - Self::AssetError + /// How many trading pairs so far. + #[pallet::storage] + #[pallet::getter(fn trading_pair_count)] + pub(crate) type TradingPairCount = StorageValue<_, TradingPairId, ValueQuery>; + + /// Record the exact balance of reserved native coins in Spot. + #[pallet::storage] + #[pallet::getter(fn native_reserves)] + pub(crate) type NativeReserves = + StorageMap<_, Twox64Concat, T::AccountId, BalanceOf, ValueQuery>; + + /// The map from trading pair id to its static profile. + #[pallet::storage] + #[pallet::getter(fn trading_pair_of)] + pub(crate) type TradingPairOf = + StorageMap<_, Twox64Concat, TradingPairId, TradingPairProfile>; + + /// (latest price, last update height) of trading pair + #[pallet::storage] + #[pallet::getter(fn trading_pair_info_of)] + pub(crate) type TradingPairInfoOf = + StorageMap<_, Twox64Concat, TradingPairId, TradingPairInfo>; + + /// Total transactions has been made for a trading pair. + #[pallet::storage] + #[pallet::getter(fn trading_history_index_of)] + pub(crate) type TradingHistoryIndexOf = + StorageMap<_, Twox64Concat, TradingPairId, TradingHistoryIndex, ValueQuery>; + + /// Total orders made by an account. + #[pallet::storage] + #[pallet::getter(fn order_count_of)] + pub(crate) type OrderCountOf = + StorageMap<_, Twox64Concat, T::AccountId, OrderId, ValueQuery>; + + /// Details of an user order given the account ID and order ID. + #[pallet::storage] + #[pallet::getter(fn order_info_of)] + pub(crate) type OrderInfoOf = + StorageDoubleMap<_, Twox64Concat, T::AccountId, Twox64Concat, OrderId, OrderInfo>; + + /// All the accounts and the order number given the trading pair ID and price. + #[pallet::storage] + #[pallet::getter(fn quotations_of)] + pub(crate) type QuotationsOf = StorageDoubleMap< + _, + Twox64Concat, + TradingPairId, + Twox64Concat, + T::Price, + Vec<(T::AccountId, OrderId)>, + ValueQuery, + >; + + /// TradingPairId => (highest_bid, lowest_ask) + #[pallet::storage] + #[pallet::getter(fn handicap_of)] + pub(crate) type HandicapOf = + StorageMap<_, Twox64Concat, TradingPairId, HandicapInfo, ValueQuery>; + + #[pallet::type_value] + pub fn DefaultForPriceFluctuationOf() -> PriceFluctuation { + DEFAULT_FLUCTUATION } -} - -decl_module! { - pub struct Module for enum Call where origin: T::Origin { - - type Error = Error; - fn deposit_event() = default; - - #[weight = ::WeightInfo::put_order()] - pub fn put_order( - origin, - #[compact] pair_id: TradingPairId, - order_type: OrderType, - side: Side, - #[compact] amount: BalanceOf, - #[compact] price: T::Price - ) { - let who = ensure_signed(origin)?; - - ensure!(!price.is_zero(), Error::::InvalidPrice); - ensure!(!amount.is_zero(), Error::::ZeroAmount); - ensure!(order_type == OrderType::Limit, Error::::InvalidOrderType); - - let pair = Self::trading_pair(pair_id)?; - - ensure!(pair.tradable, Error::::TradingPairUntradable); - ensure!(pair.is_valid_price(price), Error::::InvalidPrice); - - Self::is_valid_quote(price, side, pair_id)?; - Self::has_too_many_backlog_orders(pair_id, price, side)?; - - // Reserve the token according to the order side. - let (reserve_asset, reserve_amount) = match side { - Side::Buy => (pair.quote(), Self::convert_base_to_quote(amount, price, &pair)?), - Side::Sell => (pair.base(), amount) - }; - Self::put_order_reserve(&who, reserve_asset, reserve_amount)?; - Self::apply_put_order(who, pair_id, order_type, side, amount, price, reserve_amount)?; - } - - #[weight = ::WeightInfo::cancel_order()] - pub fn cancel_order( - origin, - #[compact] pair_id: TradingPairId, - #[compact] order_id: OrderId - ) { - let who = ensure_signed(origin)?; - Self::do_cancel_order(&who, pair_id, order_id)?; - } - - /// Force cancel an order. - #[weight = ::WeightInfo::force_cancel_order()] - fn force_cancel_order( - origin, - who: ::Source, - #[compact] pair_id: TradingPairId, - #[compact] order_id: OrderId - ) { - ensure_root(origin)?; - let who = T::Lookup::lookup(who)?; - Self::do_cancel_order(&who, pair_id, order_id)?; - } - - #[weight = ::WeightInfo::set_handicap()] - fn set_handicap(origin, #[compact] pair_id: TradingPairId, new: Handicap< T::Price>) { - ensure_root(origin)?; - info!(target: "runtime::dex::spot", "[set_handicap] pair_id:{:?}, new handicap:{:?}", pair_id, new); - HandicapOf::::insert(pair_id, new); - } + /// The map of trading pair ID to the price fluctuation. Use with caution! + #[pallet::storage] + #[pallet::getter(fn price_fluctuation_of)] + pub(crate) type PriceFluctuationOf = StorageMap< + _, + Twox64Concat, + TradingPairId, + PriceFluctuation, + ValueQuery, + DefaultForPriceFluctuationOf, + >; + + #[pallet::genesis_config] + pub struct GenesisConfig { + pub trading_pairs: Vec<(AssetId, AssetId, u32, u32, T::Price, bool)>, + } - #[weight = ::WeightInfo::set_price_fluctuation()] - fn set_price_fluctuation( - origin, - #[compact] pair_id: TradingPairId, - #[compact] new: PriceFluctuation - ) { - ensure_root(origin)?; - PriceFluctuationOf::insert(pair_id, new); - Self::deposit_event(Event::::PriceFluctuationUpdated(pair_id, new)); + #[cfg(feature = "std")] + impl Default for GenesisConfig { + fn default() -> Self { + Self { + trading_pairs: Default::default(), + } } + } - /// Add a new trading pair. - #[weight = ::WeightInfo::add_trading_pair()] - pub fn add_trading_pair( - origin, - currency_pair: CurrencyPair, - #[compact] pip_decimals: u32, - #[compact] tick_decimals: u32, - #[compact] latest_price: T::Price, - tradable: bool, - ) { - ensure_root(origin)?; - ensure!( - Self::get_trading_pair_by_currency_pair(¤cy_pair).is_none(), - Error::::TradingPairAlreadyExists - ); - Self::apply_add_trading_pair( - currency_pair, - pip_decimals, - tick_decimals, - latest_price, - tradable - ); + #[pallet::genesis_build] + impl GenesisBuild for GenesisConfig { + fn build(&self) { + let extra_genesis_builder: fn(&Self) = |config| { + for (base, quote, pip_decimals, tick_decimals, price, tradable) in + config.trading_pairs.iter() + { + Pallet::::apply_add_trading_pair( + CurrencyPair::new(*base, *quote), + *pip_decimals, + *tick_decimals, + *price, + *tradable, + ); + } + }; + extra_genesis_builder(self); } + } +} - /// Update the trading pair profile. - #[weight = ::WeightInfo::update_trading_pair()] - pub fn update_trading_pair( - origin, - #[compact] pair_id: TradingPairId, - #[compact] tick_decimals: u32, - tradable: bool - ) { - ensure_root(origin)?; - let pair = Self::trading_pair(pair_id)?; - ensure!(tick_decimals >= pair.tick_decimals, Error::::InvalidTickdecimals); - Self::apply_update_trading_pair(pair_id, tick_decimals, tradable); - } +impl From for Error { + fn from(_: AssetErr) -> Self { + Self::AssetError } } -impl Module { +impl Pallet { /// Public mutables pub fn get_trading_pair_by_currency_pair( currency_pair: &CurrencyPair, ) -> Option { - let pair_count = TradingPairCount::get(); + let pair_count = TradingPairCount::::get(); for i in 0..pair_count { - if let Some(pair) = TradingPairOf::get(i) { + if let Some(pair) = TradingPairOf::::get(i) { if pair.base() == currency_pair.base && pair.quote() == currency_pair.quote { return Some(pair); } @@ -362,7 +445,7 @@ impl Module { #[inline] fn trading_pair(pair_id: TradingPairId) -> Result> { - TradingPairOf::get(pair_id).ok_or(Error::::InvalidTradingPair) + TradingPairOf::::get(pair_id).ok_or(Error::::InvalidTradingPair) } fn get_order(who: &T::AccountId, order_id: OrderId) -> Result, Error> { @@ -377,7 +460,7 @@ impl Module { latest_price: T::Price, tradable: bool, ) { - let pair_id = TradingPairCount::get(); + let pair_id = TradingPairCount::::get(); let pair = TradingPairProfile { id: pair_id, @@ -389,7 +472,7 @@ impl Module { info!(target: "runtime::dex::spot", "New trading pair: {:?}", pair); - TradingPairOf::insert(pair_id, &pair); + TradingPairOf::::insert(pair_id, &pair); TradingPairInfoOf::::insert( pair_id, TradingPairInfo { @@ -398,7 +481,7 @@ impl Module { }, ); - TradingPairCount::put(pair_id + 1); + TradingPairCount::::put(pair_id + 1); Self::deposit_event(Event::::TradingPairAdded(pair)); } @@ -409,7 +492,7 @@ impl Module { "[update_trading_pair] pair_id: {:}, tick_decimals: {:}, tradable:{:}", pair_id, tick_decimals, tradable ); - TradingPairOf::mutate(pair_id, |pair| { + TradingPairOf::::mutate(pair_id, |pair| { if let Some(pair) = pair { pair.tick_decimals = tick_decimals; pair.tradable = tradable; @@ -498,14 +581,14 @@ impl Module { } } -impl xpallet_assets_registrar::RegistrarHandler for Module { +impl xpallet_assets_registrar::RegistrarHandler for Pallet { fn on_deregister(token: &AssetId) -> DispatchResult { - let pair_len = TradingPairCount::get(); + let pair_len = TradingPairCount::::get(); for i in 0..pair_len { - if let Some(mut pair) = TradingPairOf::get(i) { + if let Some(mut pair) = TradingPairOf::::get(i) { if pair.base().eq(token) || pair.quote().eq(token) { pair.tradable = false; - TradingPairOf::insert(i, &pair); + TradingPairOf::::insert(i, &pair); Self::deposit_event(Event::::TradingPairUpdated(pair)); } } diff --git a/xpallets/dex/spot/src/mock.rs b/xpallets/dex/spot/src/mock.rs index 2d85711ce..c68376518 100644 --- a/xpallets/dex/spot/src/mock.rs +++ b/xpallets/dex/spot/src/mock.rs @@ -5,7 +5,11 @@ use std::{ collections::{BTreeMap, HashSet}, }; -use frame_support::{parameter_types, traits::Get, weights::Weight}; +use frame_support::{ + parameter_types, + traits::{GenesisBuild, Get}, + weights::Weight, +}; use sp_core::H256; use sp_runtime::{ testing::Header, diff --git a/xpallets/dex/spot/src/rpc.rs b/xpallets/dex/spot/src/rpc.rs index 546b4faae..4312d5863 100644 --- a/xpallets/dex/spot/src/rpc.rs +++ b/xpallets/dex/spot/src/rpc.rs @@ -57,7 +57,7 @@ pub struct Depth { pub bids: Vec<(Price, Balance)>, } -impl Module { +impl Pallet { /// Returns the range of a valid quotation for a trading pair. fn get_quotation_range(profile: &TradingPairProfile) -> (T::Price, T::Price) { let handicap = Self::handicap_of(profile.id); diff --git a/xpallets/dex/spot/src/types.rs b/xpallets/dex/spot/src/types.rs index 10a6aea92..114598ea5 100644 --- a/xpallets/dex/spot/src/types.rs +++ b/xpallets/dex/spot/src/types.rs @@ -205,7 +205,7 @@ impl TradingPairProfile { /// The maximum ticks that the price can deviate from the handicap. pub fn calc_fluctuation(&self) -> Tick { - let price_fluctuation = >::price_fluctuation_of(self.id); + let price_fluctuation = >::price_fluctuation_of(self.id); price_fluctuation .saturated_into::() .saturating_mul(self.tick())