From 98dc2dd3cc19b1a7e5e7cb633ab71f1472c93b91 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Fri, 8 Dec 2023 14:58:02 +0300 Subject: [PATCH 01/10] order book Signed-off-by: Mikhail Tagirov --- pallets/order-book/benchmarking/src/lib.rs | 1 - .../benchmarking/src/periphery/preparation.rs | 3 - pallets/order-book/src/cache_data_layer.rs | 14 ++- pallets/order-book/src/lib.rs | 39 +++----- pallets/order-book/src/order_book.rs | 8 +- pallets/order-book/src/scheduler.rs | 10 +-- pallets/order-book/src/storage_data_layer.rs | 14 ++- pallets/order-book/src/tests/pallet.rs | 18 ++-- pallets/order-book/src/tests/types.rs | 38 ++++---- pallets/order-book/src/types.rs | 89 ++++++++----------- 10 files changed, 108 insertions(+), 126 deletions(-) diff --git a/pallets/order-book/benchmarking/src/lib.rs b/pallets/order-book/benchmarking/src/lib.rs index 237a8e7406..29caee1da8 100644 --- a/pallets/order-book/benchmarking/src/lib.rs +++ b/pallets/order-book/benchmarking/src/lib.rs @@ -433,7 +433,6 @@ mod benchmarks_inner { } verify {} - // TODO: benchmark worst case service_single_expiration { // very similar to cancel_limit_order let order_book_id = OrderBookId::, T::DEXId> { diff --git a/pallets/order-book/benchmarking/src/periphery/preparation.rs b/pallets/order-book/benchmarking/src/periphery/preparation.rs index 878fc944ef..031dd5cad3 100644 --- a/pallets/order-book/benchmarking/src/periphery/preparation.rs +++ b/pallets/order-book/benchmarking/src/periphery/preparation.rs @@ -30,9 +30,6 @@ //! General preparation logic for the benchmarking. -// TODO #167: fix clippy warnings -#![allow(clippy::all)] - // TODO: rename to `order_book` after upgrading to nightly-2023-07-01+ #[cfg(test)] use framenode_runtime::order_book as order_book_imported; diff --git a/pallets/order-book/src/cache_data_layer.rs b/pallets/order-book/src/cache_data_layer.rs index 4cd592d800..67cfa80f78 100644 --- a/pallets/order-book/src/cache_data_layer.rs +++ b/pallets/order-book/src/cache_data_layer.rs @@ -79,6 +79,12 @@ pub struct CacheDataLayer { >, } +impl Default for CacheDataLayer { + fn default() -> Self { + Self::new() + } +} + impl CacheDataLayer { pub fn new() -> Self { Self { @@ -180,7 +186,7 @@ impl CacheDataLayer { if let Some(agg_bids) = self.aggregated_bids.get_mut(order_book_id) { let volume = agg_bids .get(price) - .map(|x| *x) + .copied() .unwrap_or_default() .checked_add(value) .ok_or(())?; @@ -204,7 +210,7 @@ impl CacheDataLayer { value: &OrderVolume, ) -> Result<(), ()> { if let Some(agg_bids) = self.aggregated_bids.get_mut(order_book_id) { - let volume = agg_bids.get(price).map(|x| *x).unwrap_or_default(); + let volume = agg_bids.get(price).copied().unwrap_or_default(); let volume = volume.checked_sub(value).ok_or(())?; if volume.is_zero() { agg_bids.remove(price); @@ -235,7 +241,7 @@ impl CacheDataLayer { if let Some(agg_asks) = self.aggregated_asks.get_mut(order_book_id) { let volume = agg_asks .get(price) - .map(|x| *x) + .copied() .unwrap_or_default() .checked_add(value) .ok_or(())?; @@ -259,7 +265,7 @@ impl CacheDataLayer { value: &OrderVolume, ) -> Result<(), ()> { if let Some(agg_asks) = self.aggregated_asks.get_mut(order_book_id) { - let volume = agg_asks.get(price).map(|x| *x).unwrap_or_default(); + let volume = agg_asks.get(price).copied().unwrap_or_default(); let volume = volume.checked_sub(value).ok_or(())?; if volume.is_zero() { agg_asks.remove(price); diff --git a/pallets/order-book/src/lib.rs b/pallets/order-book/src/lib.rs index 0b18fff7c7..932cb79214 100644 --- a/pallets/order-book/src/lib.rs +++ b/pallets/order-book/src/lib.rs @@ -29,9 +29,8 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #![cfg_attr(not(feature = "std"), no_std)] -#![allow(dead_code)] // todo (m.tagirov) remove -// TODO #167: fix clippy warnings -#![allow(clippy::all)] +#![allow(clippy::type_complexity)] +#![allow(clippy::too_many_arguments)] #![feature(int_roundings)] use assets::AssetIdOf; @@ -582,7 +581,7 @@ pub mod pallet { order_book_id, creator: maybe_who, }); - Ok(().into()) + Ok(()) } #[pallet::call_index(1)] @@ -620,7 +619,7 @@ pub mod pallet { >::remove(order_book_id); Self::deposit_event(Event::::OrderBookDeleted { order_book_id }); - Ok(().into()) + Ok(()) } #[pallet::call_index(2)] @@ -685,7 +684,7 @@ pub mod pallet { } >::set(order_book_id, Some(order_book)); Self::deposit_event(Event::::OrderBookUpdated { order_book_id }); - Ok(().into()) + Ok(()) } #[pallet::call_index(3)] @@ -703,7 +702,7 @@ pub mod pallet { && status != OrderBookStatus::OnlyCancel && status != OrderBookStatus::Stop { - return Err(Error::::OrderBookIsLocked.into()); + return Err(Error::::OrderBookIsLocked); } order_book.status = status; @@ -713,7 +712,7 @@ pub mod pallet { order_book_id, new_status: status, }); - Ok(().into()) + Ok(()) } #[pallet::call_index(4)] @@ -741,7 +740,7 @@ pub mod pallet { }; let order = LimitOrder::::new( order_id, - who.clone(), + who, side, OrderPrice::divisible(price), amount, @@ -864,7 +863,7 @@ pub mod pallet { order_book.execute_market_order(market_order, &mut data)?; data.commit(); - Ok(().into()) + Ok(()) } } } @@ -877,12 +876,7 @@ impl CurrencyLocker Result<(), DispatchError> { let tech_account = Self::tech_account_for_order_book(order_book_id); - technical::Pallet::::transfer_in( - asset_id, - account, - &tech_account, - (*amount.balance()).into(), - ) + technical::Pallet::::transfer_in(asset_id, account, &tech_account, *amount.balance()) } } @@ -894,12 +888,7 @@ impl CurrencyUnlocker Result<(), DispatchError> { let tech_account = Self::tech_account_for_order_book(order_book_id); - technical::Pallet::::transfer_out( - asset_id, - &tech_account, - account, - (*amount.balance()).into(), - ) + technical::Pallet::::transfer_out(asset_id, &tech_account, account, *amount.balance()) } fn unlock_liquidity_batch( @@ -1123,8 +1112,8 @@ impl Pallet { T::AssetInfoProvider::ensure_asset_exists(&order_book_id.base)?; T::EnsureTradingPairExists::ensure_trading_pair_exists( &order_book_id.dex_id, - &order_book_id.quote.into(), - &order_book_id.base.into(), + &order_book_id.quote, + &order_book_id.base, )?; ensure!( @@ -1342,7 +1331,7 @@ impl LiquiditySource::new(sender.clone(), direction, order_book_id, amount, to.clone()); + MarketOrder::::new(sender.clone(), direction, order_book_id, amount, to); let (input_amount, output_amount, executed_orders_count) = order_book.execute_market_order(market_order, &mut data)?; diff --git a/pallets/order-book/src/order_book.rs b/pallets/order-book/src/order_book.rs index fbc412c9f3..ca912943cb 100644 --- a/pallets/order-book/src/order_book.rs +++ b/pallets/order-book/src/order_book.rs @@ -686,7 +686,7 @@ impl OrderBook { }; let average_price = OrderAmount::average_price(input_amount, output_amount) - .map_err(|_| Error::::PriceCalculationFailed)?; + .ok_or(Error::::PriceCalculationFailed)?; Ok(DealInfo::> { input_asset_id: *input_asset_id, @@ -1109,7 +1109,7 @@ impl OrderBook { volume } - pub fn cross_spread<'a>( + pub fn cross_spread( &self, limit_order: LimitOrder, data: &mut impl DataLayer, @@ -1162,11 +1162,11 @@ impl OrderBook { } if !limit_amount.is_zero() { - let mut new_limit_order = limit_order.clone(); + let mut new_limit_order = limit_order; new_limit_order.amount = limit_amount; market_change .merge(self.calculate_limit_order_impact(new_limit_order)?) - .map_err(|_| Error::::AmountCalculationFailed)?; + .ok_or(Error::::AmountCalculationFailed)?; } Ok(market_change) diff --git a/pallets/order-book/src/scheduler.rs b/pallets/order-book/src/scheduler.rs index be59921492..00f1a4dfe4 100644 --- a/pallets/order-book/src/scheduler.rs +++ b/pallets/order-book/src/scheduler.rs @@ -66,7 +66,7 @@ impl Pallet { ); // in `release` will emit event Self::deposit_event(Event::::ExpirationFailure { - order_book_id: order_book_id.clone(), + order_book_id: *order_book_id, order_id, error, }); @@ -77,7 +77,7 @@ impl Pallet { debug_assert!(false, "apparently removal of order book did not cleanup expiration schedule; \ order {:?} is set to expire but corresponding order book {:?} is not found", order_id, order_book_id); Self::deposit_event(Event::::ExpirationFailure { - order_book_id: order_book_id.clone(), + order_book_id: *order_book_id, order_id, error: Error::::UnknownOrderBook.into(), }); @@ -96,7 +96,7 @@ impl Pallet { order_id, error ); Self::deposit_event(Event::::ExpirationFailure { - order_book_id: order_book_id.clone(), + order_book_id: *order_book_id, order_id, error, }); @@ -250,7 +250,7 @@ impl AlignmentScheduler for Pallet { let Some(order_book) = >::get(order_book_id) else { debug_assert!(false, "order-book {order_book_id:?} was not found during alignment"); Self::deposit_event(Event::::AlignmentFailure { - order_book_id: order_book_id.clone(), + order_book_id, error: Error::::UnknownOrderBook.into(), }); return; @@ -286,7 +286,7 @@ impl AlignmentScheduler for Pallet { "Error {error:?} occurs during the alignment of order-book {order_book_id:?}" ); Self::deposit_event(Event::::AlignmentFailure { - order_book_id: order_book_id, + order_book_id, error, }); return; diff --git a/pallets/order-book/src/storage_data_layer.rs b/pallets/order-book/src/storage_data_layer.rs index 0677847518..069037750f 100644 --- a/pallets/order-book/src/storage_data_layer.rs +++ b/pallets/order-book/src/storage_data_layer.rs @@ -46,6 +46,12 @@ pub struct StorageDataLayer { _phantom: PhantomData, } +impl Default for StorageDataLayer { + fn default() -> Self { + Self::new() + } +} + impl StorageDataLayer { pub fn new() -> Self { Self { @@ -93,7 +99,7 @@ impl StorageDataLayer { >::mutate(order_book_id, |bids| { let volume = bids .get(price) - .map(|x| *x) + .copied() .unwrap_or_default() .checked_add(value) .ok_or(())?; @@ -110,7 +116,7 @@ impl StorageDataLayer { >::mutate(order_book_id, |agg_bids| { let volume = agg_bids .get(price) - .map(|x| *x) + .copied() .ok_or(())? .checked_sub(value) .ok_or(())?; @@ -131,7 +137,7 @@ impl StorageDataLayer { >::mutate(order_book_id, |asks| { let volume = asks .get(price) - .map(|x| *x) + .copied() .unwrap_or_default() .checked_add(value) .ok_or(())?; @@ -148,7 +154,7 @@ impl StorageDataLayer { >::mutate(order_book_id, |agg_asks| { let volume = agg_asks .get(price) - .map(|x| *x) + .copied() .ok_or(())? .checked_sub(value) .ok_or(())?; diff --git a/pallets/order-book/src/tests/pallet.rs b/pallets/order-book/src/tests/pallet.rs index 5e1d6f1020..54ba340b00 100644 --- a/pallets/order-book/src/tests/pallet.rs +++ b/pallets/order-book/src/tests/pallet.rs @@ -51,6 +51,7 @@ use framenode_runtime::{Runtime, RuntimeOrigin}; use sp_runtime::traits::UniqueSaturatedInto; use sp_std::collections::btree_map::BTreeMap; +#[test] fn should_register_technical_account() { ext().execute_with(|| { framenode_runtime::frame_system::Pallet::::inc_providers(&accounts::alice::< @@ -68,7 +69,7 @@ fn should_register_technical_account() { ) .unwrap(); - let accounts = [ + let order_books = [ OrderBookId::, DEXId> { dex_id: DEX.into(), base: VAL.into(), @@ -82,19 +83,13 @@ fn should_register_technical_account() { ]; // register (on order book creation) - for order_book_id in accounts { - OrderBookPallet::register_tech_account(order_book_id).expect(&format!( - "Could not register account for order_book_id: {:?}", - order_book_id, - )); + for order_book_id in order_books { + assert_ok!(OrderBookPallet::register_tech_account(order_book_id)); } // deregister (on order book removal) - for order_book_id in accounts { - OrderBookPallet::deregister_tech_account(order_book_id).expect(&format!( - "Could not deregister account for order_book_id: {:?}", - order_book_id, - )); + for order_book_id in order_books { + assert_ok!(OrderBookPallet::deregister_tech_account(order_book_id)); } }); } @@ -940,6 +935,7 @@ fn should_emit_event_on_expiration_failure() { }) } +#[test] fn should_assemble_order_book_id() { ext().execute_with(|| { let polkaswap_order_book_id = OrderBookId::, DEXId> { diff --git a/pallets/order-book/src/tests/types.rs b/pallets/order-book/src/tests/types.rs index 3dbfe7e759..95290ca8f6 100644 --- a/pallets/order-book/src/tests/types.rs +++ b/pallets/order-book/src/tests/types.rs @@ -33,7 +33,7 @@ use crate::test_utils::*; use assets::AssetIdOf; use common::{balance, PriceVariant, DAI, VAL, XOR}; -use frame_support::{assert_err, assert_ok}; +use frame_support::assert_ok; use framenode_chain_spec::ext; use framenode_runtime::order_book::{ CancelReason, Config, DealInfo, LimitOrder, MarketChange, OrderAmount, OrderBookId, @@ -96,8 +96,8 @@ fn check_order_amount() { (quote + quote2).unwrap(), OrderAmount::Quote(quote_balance + quote_balance2) ); - assert_err!(base + quote, ()); - assert_err!(quote + base, ()); + assert_eq!(base + quote, None); + assert_eq!(quote + base, None); assert_eq!( (base - base2).unwrap(), @@ -107,8 +107,8 @@ fn check_order_amount() { (quote - quote2).unwrap(), OrderAmount::Quote(quote_balance - quote_balance2) ); - assert_err!(base - quote, ()); - assert_err!(quote - base, ()); + assert_eq!(base - quote, None); + assert_eq!(quote - base, None); } #[test] @@ -330,7 +330,7 @@ fn should_fail_payment_merge() { quote: XOR.into(), }; - assert_err!( + assert_eq!( Payment { order_book_id, to_lock: BTreeMap::from([( @@ -353,7 +353,7 @@ fn should_fail_payment_merge() { BTreeMap::from([(accounts::bob::(), balance!(50).into())]) )]) }), - () + None ); } @@ -438,7 +438,7 @@ fn check_payment_merge() { }; let mut payment = origin.clone(); - assert_ok!(payment.merge(&different)); + assert_eq!(payment.merge(&different), Some(())); assert_eq!( payment, Payment { @@ -523,7 +523,7 @@ fn check_payment_merge() { }; payment = origin.clone(); - assert_ok!(payment.merge(&partial_match)); + assert_eq!(payment.merge(&partial_match), Some(())); assert_eq!( payment, Payment { @@ -604,7 +604,7 @@ fn check_payment_merge() { }; payment = origin.clone(); - assert_ok!(payment.merge(&full_match)); + assert_eq!(payment.merge(&full_match), Some(())); assert_eq!( payment, Payment { @@ -651,7 +651,7 @@ fn check_payment_merge() { }; payment = origin.clone(); - assert_ok!(payment.merge(&empty)); + assert_eq!(payment.merge(&empty), Some(())); assert_eq!(payment, origin); } @@ -883,19 +883,19 @@ fn should_fail_market_change_merge() { let mut diff_deal_input = origin.clone(); diff_deal_input.deal_input = Some(OrderAmount::Quote(balance!(50).into())); - assert_err!(market_change.merge(diff_deal_input), ()); + assert_eq!(market_change.merge(diff_deal_input), None); let mut diff_deal_output = origin.clone(); diff_deal_output.deal_output = Some(OrderAmount::Base(balance!(50).into())); - assert_err!(market_change.merge(diff_deal_output), ()); + assert_eq!(market_change.merge(diff_deal_output), None); let mut diff_market_input = origin.clone(); diff_market_input.market_input = Some(OrderAmount::Quote(balance!(50).into())); - assert_err!(market_change.merge(diff_market_input), ()); + assert_eq!(market_change.merge(diff_market_input), None); let mut diff_market_output = origin.clone(); diff_market_output.market_output = Some(OrderAmount::Base(balance!(50).into())); - assert_err!(market_change.merge(diff_market_output), ()); + assert_eq!(market_change.merge(diff_market_output), None); } #[test] @@ -1136,7 +1136,7 @@ fn check_market_change_merge() { }; let mut market_change = origin.clone(); - assert_ok!(market_change.merge(different)); + assert_eq!(market_change.merge(different), Some(())); assert_eq!( market_change, MarketChange { @@ -1267,7 +1267,7 @@ fn check_market_change_merge() { }; market_change = origin.clone(); - assert_ok!(market_change.merge(partial_match)); + assert_eq!(market_change.merge(partial_match), Some(())); assert_eq!( market_change, MarketChange { @@ -1387,7 +1387,7 @@ fn check_market_change_merge() { }; market_change = origin.clone(); - assert_ok!(market_change.merge(full_match)); + assert_eq!(market_change.merge(full_match), Some(())); assert_eq!( market_change, MarketChange { @@ -1458,7 +1458,7 @@ fn check_market_change_merge() { }; market_change = origin.clone(); - assert_ok!(market_change.merge(empty)); + assert_eq!(market_change.merge(empty), Some(())); assert_eq!(market_change, origin); } diff --git a/pallets/order-book/src/types.rs b/pallets/order-book/src/types.rs index d116b43877..5d9af48176 100644 --- a/pallets/order-book/src/types.rs +++ b/pallets/order-book/src/types.rs @@ -32,7 +32,6 @@ use crate::traits::{CurrencyLocker, CurrencyUnlocker}; use codec::{Decode, Encode, MaxEncodedLen}; use common::prelude::BalanceUnit; use common::{PriceVariant, TradingPair}; -use frame_support::ensure; use frame_support::sp_runtime::DispatchError; use frame_support::{BoundedBTreeMap, BoundedVec}; use sp_runtime::traits::{CheckedAdd, CheckedDiv, CheckedSub, Saturating, Zero}; @@ -124,10 +123,10 @@ impl OrderAmount { } pub fn is_same(&self, other: &Self) -> bool { - match (self, other) { - (Self::Base(..), Self::Base(..)) | (Self::Quote(..), Self::Quote(..)) => true, - _ => false, - } + matches!( + (self, other), + (Self::Base(..), Self::Base(..)) | (Self::Quote(..), Self::Quote(..)) + ) } pub fn copy_type(&self, amount: OrderVolume) -> Self { @@ -147,36 +146,38 @@ impl OrderAmount { } } - pub fn average_price(input: OrderAmount, output: OrderAmount) -> Result { + pub fn average_price(input: OrderAmount, output: OrderAmount) -> Option { if input.is_quote() { - input.value().checked_div(output.value()).ok_or(()) + input.value().checked_div(output.value()) } else { - output.value().checked_div(input.value()).ok_or(()) + output.value().checked_div(input.value()) } } } impl Add for OrderAmount { - type Output = Result; + type Output = Option; fn add(self, other: Self) -> Self::Output { - ensure!(self.is_same(&other), ()); - let Some(result) = self.value().checked_add(other.value()) else { - return Err(()); - }; - Ok(self.copy_type(result)) + if !self.is_same(&other) { + return None; + } + + let result = self.value().checked_add(other.value())?; + Some(self.copy_type(result)) } } impl Sub for OrderAmount { - type Output = Result; + type Output = Option; fn sub(self, other: Self) -> Self::Output { - ensure!(self.is_same(&other), ()); - let Some(result) = self.value().checked_sub(other.value()) else { - return Err(()); - }; - Ok(self.copy_type(result)) + if !self.is_same(&other) { + return None; + } + + let result = self.value().checked_sub(other.value())?; + Some(self.copy_type(result)) } } @@ -210,16 +211,6 @@ pub struct OrderBookId { pub quote: AssetId, } -impl OrderBookId { - fn from_trading_pair(trading_pair: TradingPair, dex_id: DEXId) -> Self { - Self { - dex_id, - base: trading_pair.target_asset_id, - quote: trading_pair.base_asset_id, - } - } -} - impl From> for TradingPair { fn from(order_book_id: OrderBookId) -> Self { Self { @@ -240,6 +231,7 @@ pub struct DealInfo { } impl DealInfo { + #[allow(clippy::nonminimal_bool)] pub fn is_valid(&self) -> bool { self.input_asset_id != self.output_asset_id && !(self.input_amount.is_base() && self.output_amount.is_base()) @@ -290,8 +282,10 @@ where } } - pub fn merge(&mut self, other: &Self) -> Result<(), ()> { - ensure!(self.order_book_id == other.order_book_id, ()); + pub fn merge(&mut self, other: &Self) -> Option<()> { + if self.order_book_id != other.order_book_id { + return None; + } for (map, to_merge) in [ (&mut self.to_lock, &other.to_lock), @@ -300,7 +294,7 @@ where Self::merge_asset_map(map, to_merge); } - Ok(()) + Some(()) } fn merge_account_map( @@ -424,18 +418,17 @@ where } } - pub fn merge(&mut self, mut other: Self) -> Result<(), ()> { - let join = |lhs: Option, - rhs: Option| - -> Result, ()> { - let result = match (lhs, rhs) { - (Some(left_amount), Some(right_amount)) => Some((left_amount + right_amount)?), - (Some(left_amount), None) => Some(left_amount), - (None, Some(right_amount)) => Some(right_amount), - (None, None) => None, + pub fn merge(&mut self, mut other: Self) -> Option<()> { + let join = + |lhs: Option, rhs: Option| -> Option> { + let result = match (lhs, rhs) { + (Some(left_amount), Some(right_amount)) => Some((left_amount + right_amount)?), + (Some(left_amount), None) => Some(left_amount), + (None, Some(right_amount)) => Some(right_amount), + (None, None) => None, + }; + Some(result) }; - Ok(result) - }; self.deal_input = join(self.deal_input, other.deal_input)?; self.deal_output = join(self.deal_output, other.deal_output)?; @@ -453,7 +446,7 @@ where self.ignore_unschedule_error = self.ignore_unschedule_error || other.ignore_unschedule_error; - Ok(()) + Some(()) } pub fn average_deal_price(&self) -> Option { @@ -461,11 +454,7 @@ where return None; }; - let Ok(price) = OrderAmount::average_price(input, output) else { - return None; - }; - - Some(price) + OrderAmount::average_price(input, output) } pub fn deal_base_amount(&self) -> Option { From db2fc0b08903919655f1e199016a57d733628840 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Sat, 9 Dec 2023 03:01:15 +0300 Subject: [PATCH 02/10] qa-tools Signed-off-by: Mikhail Tagirov --- pallets/qa-tools/src/lib.rs | 4 ++-- .../qa-tools/src/pallet_tools/order_book.rs | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pallets/qa-tools/src/lib.rs b/pallets/qa-tools/src/lib.rs index a8dc146c93..4f7e7e863b 100644 --- a/pallets/qa-tools/src/lib.rs +++ b/pallets/qa-tools/src/lib.rs @@ -29,8 +29,8 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #![cfg_attr(not(feature = "std"), no_std)] -// TODO #167: fix clippy warnings -#![allow(clippy::all)] +#![allow(clippy::type_complexity)] +#![allow(clippy::too_many_arguments)] pub use pallet::*; diff --git a/pallets/qa-tools/src/pallet_tools/order_book.rs b/pallets/qa-tools/src/pallet_tools/order_book.rs index 72ab65e70a..6484d530cd 100644 --- a/pallets/qa-tools/src/pallet_tools/order_book.rs +++ b/pallets/qa-tools/src/pallet_tools/order_book.rs @@ -143,16 +143,16 @@ pub fn create_multiple_empty_unchecked( for (order_book_id, _) in &to_create_ids { if !T::TradingPairSourceManager::is_trading_pair_enabled( &order_book_id.dex_id, - &order_book_id.quote.into(), - &order_book_id.base.into(), + &order_book_id.quote, + &order_book_id.base, )? { T::TradingPairSourceManager::register_pair( order_book_id.dex_id, - order_book_id.quote.into(), - order_book_id.base.into(), + order_book_id.quote, + order_book_id.base, )?; } - order_book::Pallet::::verify_create_orderbook_params(&order_book_id)?; + order_book::Pallet::::verify_create_orderbook_params(order_book_id)?; } for (order_book_id, attributes) in to_create_ids { @@ -232,7 +232,7 @@ fn verify_fill_side_price_params( ); ensure!( - params.orders_per_price <= ::MaxLimitOrdersForPrice::get().into() + params.orders_per_price <= ::MaxLimitOrdersForPrice::get() && prices_count.saturating_mul(params.orders_per_price as u128) <= ::SOFT_MIN_MAX_RATIO as u128, crate::Error::::TooManyOrders @@ -296,7 +296,6 @@ fn fill_order_book( let buy_prices = buy_prices.into_iter().rev(); let buy_amount_non_empty_range = bids_settings .amount_range_inclusive - .clone() .unwrap_or_else(|| max_amount_range(&order_book)) .as_non_empty_inclusive_range() .ok_or(crate::Error::::EmptyRandomRange)?; @@ -328,7 +327,7 @@ fn fill_order_book( place_multiple_orders( data, &mut order_book, - bids_owner.clone(), + bids_owner, PriceVariant::Buy, buy_orders.into_iter(), now, @@ -349,7 +348,6 @@ fn fill_order_book( let sell_amount_non_empty_range = asks_settings .amount_range_inclusive - .clone() .unwrap_or_else(|| max_amount_range(&order_book)) .as_non_empty_inclusive_range() .ok_or(crate::Error::::EmptyRandomRange)?; @@ -378,7 +376,7 @@ fn fill_order_book( place_multiple_orders( data, &mut order_book, - asks_owner.clone(), + asks_owner, PriceVariant::Sell, sell_orders.into_iter(), now, From c96e19be819cbe873ce984799cc177031f3d6209 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Sat, 9 Dec 2023 03:26:19 +0300 Subject: [PATCH 03/10] tests & benchmarks Signed-off-by: Mikhail Tagirov --- pallets/order-book/benchmarking/src/lib.rs | 1 + .../benchmarking/src/periphery/preparation.rs | 38 ++++++++----------- pallets/order-book/src/test_utils/accounts.rs | 2 +- .../order-book/src/test_utils/fill_tools.rs | 8 ++-- pallets/order-book/src/test_utils/mod.rs | 12 ++---- 5 files changed, 25 insertions(+), 36 deletions(-) diff --git a/pallets/order-book/benchmarking/src/lib.rs b/pallets/order-book/benchmarking/src/lib.rs index 29caee1da8..bec504a69e 100644 --- a/pallets/order-book/benchmarking/src/lib.rs +++ b/pallets/order-book/benchmarking/src/lib.rs @@ -42,6 +42,7 @@ #![cfg(feature = "runtime-benchmarks")] // order-book #![cfg(feature = "ready-to-test")] +#![allow(clippy::type_complexity)] // too many benchmarks, doesn't compile otherwise #![recursion_limit = "512"] #![feature(int_roundings)] diff --git a/pallets/order-book/benchmarking/src/periphery/preparation.rs b/pallets/order-book/benchmarking/src/periphery/preparation.rs index 031dd5cad3..69a3edb6f4 100644 --- a/pallets/order-book/benchmarking/src/periphery/preparation.rs +++ b/pallets/order-book/benchmarking/src/periphery/preparation.rs @@ -165,7 +165,7 @@ fn prepare_order_execute_worst_case( debug!("Filling a side of the order book for worst-case execution"); fill_order_book_side( data, - fill_settings.clone(), + fill_settings, order_book, orders_side, orders_amount, @@ -304,17 +304,13 @@ pub fn place_limit_order_without_cross_spread( fill_expiration_settings.max_expiring_orders_per_block -= 1; // mint other base asset as well let mut users = users.inspect(move |user| { - assets::Pallet::::mint_unchecked( - &order_book_id_2.base, - &user, - *order_amount_2.balance(), - ) - .unwrap(); + assets::Pallet::::mint_unchecked(&order_book_id_2.base, user, *order_amount_2.balance()) + .unwrap(); }); fill_expiration_schedule( &mut data_layer, - fill_expiration_settings.clone(), + fill_expiration_settings, &mut order_book_2, PriceVariant::Sell, order_amount_2, @@ -341,7 +337,7 @@ pub fn place_limit_order_without_cross_spread( order_book_id, Some(expected_user_orders), Some((fill_settings.max_orders_per_price - 1) as usize), - Some((author.clone(), expected_user_orders)), + Some((author, expected_user_orders)), Some(( lifespan, (fill_settings.max_expiring_orders_per_block - 1) as usize, @@ -484,21 +480,17 @@ pub fn cancel_limit_order( .expect("failed to create an order book"); let mut order_book_2 = >::get(order_book_id_2).unwrap(); let order_amount_2 = sp_std::cmp::max(order_book_2.step_lot_size, order_book_2.min_lot_size); - let mut fill_expiration_settings = fill_settings.clone(); + let mut fill_expiration_settings = fill_settings; // we add one more separately fill_expiration_settings.max_expiring_orders_per_block -= 1; // mint other base asset as well let mut users = users.inspect(move |user| { - assets::Pallet::::mint_unchecked( - &order_book_id_2.base, - &user, - *order_amount_2.balance(), - ) - .unwrap(); + assets::Pallet::::mint_unchecked(&order_book_id_2.base, user, *order_amount_2.balance()) + .unwrap(); }); fill_expiration_schedule( &mut data_layer, - fill_expiration_settings.clone(), + fill_expiration_settings, &mut order_book_2, PriceVariant::Sell, order_amount_2, @@ -540,7 +532,7 @@ pub fn quote( let mut data_layer = CacheDataLayer::::new(); // fill aggregated bids - let mut buy_settings = fill_settings.clone(); + let mut buy_settings = fill_settings; buy_settings.max_orders_per_price = 1; let _ = fill_order_book_worst_case::( buy_settings, @@ -628,11 +620,11 @@ pub fn market_order_execution( let id = OrderBookId::, T::DEXId> { dex_id: DEX.into(), - base: nft.clone(), + base: nft, quote: XOR.into(), }; trading_pair::Pallet::::register( - RawOrigin::Signed(creator.clone()).into(), + RawOrigin::Signed(creator).into(), DEX.into(), id.quote, id.base, @@ -660,7 +652,7 @@ pub fn market_order_execution( let (_, _, amount, side) = prepare_order_execute_worst_case::( &mut data_layer, &mut order_book, - fill_settings.clone(), + fill_settings, true, ); @@ -734,7 +726,7 @@ pub fn align_single_order( let (price, _) = aggregated_side.iter().nth(prices_count / 2).unwrap(); debug!("Filling the price of the aligned order"); - let mut price_settings = fill_settings.clone(); + let mut price_settings = fill_settings; price_settings.max_orders_per_price -= 2; let amount = order_book.min_lot_size; fill_price( @@ -748,7 +740,7 @@ pub fn align_single_order( &mut lifespans, ); - let orders = data_layer.get_bids(&order_book_id, &price).unwrap(); + let orders = data_layer.get_bids(&order_book_id, price).unwrap(); let order_id_to_align = orders[orders.len() / 2]; let order_to_align = data_layer .get_limit_order(&order_book_id, order_id_to_align) diff --git a/pallets/order-book/src/test_utils/accounts.rs b/pallets/order-book/src/test_utils/accounts.rs index 9e5f3cacad..4315be9fbe 100644 --- a/pallets/order-book/src/test_utils/accounts.rs +++ b/pallets/order-book/src/test_utils/accounts.rs @@ -57,7 +57,7 @@ pub fn generate_account( let mut id = 0; while value != 0 { adr[31 - id] = (value % 256) as u8; - value = value / 256; + value /= 256; id += 1; } diff --git a/pallets/order-book/src/test_utils/fill_tools.rs b/pallets/order-book/src/test_utils/fill_tools.rs index cb472939d5..b53d2972ae 100644 --- a/pallets/order-book/src/test_utils/fill_tools.rs +++ b/pallets/order-book/src/test_utils/fill_tools.rs @@ -79,13 +79,13 @@ pub fn users_iterator( .inspect(move |user| { assets::Pallet::::mint_unchecked( &order_book_id.base, - &user, + user, *mint_per_user.balance(), ) .unwrap(); assets::Pallet::::mint_unchecked( &order_book_id.quote, - &user, + user, *max_price.checked_mul(&mint_per_user).unwrap().balance(), ) .unwrap(); @@ -368,7 +368,7 @@ fn fill_price_inner( side, price, orders_amount, - settings.now.clone(), + settings.now, lifespan.saturated_into(), current_block, ); @@ -397,7 +397,7 @@ fn fill_price_inner( side, price, orders_amount, - settings.now.clone(), + settings.now, lifespan, current_block, ) diff --git a/pallets/order-book/src/test_utils/mod.rs b/pallets/order-book/src/test_utils/mod.rs index a5481e6f9b..292ad007bb 100644 --- a/pallets/order-book/src/test_utils/mod.rs +++ b/pallets/order-book/src/test_utils/mod.rs @@ -85,11 +85,7 @@ pub fn fill_balance( pub fn get_last_order_id( order_book_id: OrderBookId, DexIdOf>, ) -> Option<::OrderId> { - if let Some(order_book) = Pallet::::order_books(order_book_id) { - Some(order_book.last_order_id) - } else { - None - } + Pallet::::order_books(order_book_id).map(|order_book| order_book.last_order_id) } pub fn update_orderbook_unchecked( @@ -328,7 +324,7 @@ pub fn create_and_fill_order_book( fn slice_to_price_orders( v: &[u32], ) -> PriceOrders { - v.into_iter() + v.iter() .map(|id| T::OrderId::from(*id)) .collect::>() .try_into() @@ -363,7 +359,7 @@ pub fn create_and_fill_order_book( ); assert_eq!( - Pallet::::aggregated_bids(&order_book_id), + Pallet::::aggregated_bids(order_book_id), BTreeMap::from([ (bp1.into(), amount1.into()), (bp2.into(), (amount2 + amount3).into()), @@ -371,7 +367,7 @@ pub fn create_and_fill_order_book( ]) ); assert_eq!( - Pallet::::aggregated_asks(&order_book_id), + Pallet::::aggregated_asks(order_book_id), BTreeMap::from([ (sp1.into(), amount7.into()), (sp2.into(), (amount8 + amount9).into()), From 2d3e4dbc12171bb05e4310e713086df010c18dff Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Mon, 11 Dec 2023 13:23:46 +0300 Subject: [PATCH 04/10] common Signed-off-by: Mikhail Tagirov --- common/src/balance_unit.rs | 2 +- common/src/cache_storage/cache_double_map.rs | 20 ++- common/src/cache_storage/cache_map.rs | 22 ++- common/src/lib.rs | 7 +- common/src/primitives.rs | 151 +++++++++---------- common/src/serialization.rs | 2 + common/src/swap_amount.rs | 6 +- common/src/traits.rs | 28 +--- common/src/utils.rs | 5 +- 9 files changed, 111 insertions(+), 132 deletions(-) diff --git a/common/src/balance_unit.rs b/common/src/balance_unit.rs index 426c9bd153..ab0e21abae 100644 --- a/common/src/balance_unit.rs +++ b/common/src/balance_unit.rs @@ -74,7 +74,7 @@ impl Ord for BalanceUnit { impl PartialOrd for BalanceUnit { fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(&other)) + Some(self.cmp(other)) } } diff --git a/common/src/cache_storage/cache_double_map.rs b/common/src/cache_storage/cache_double_map.rs index 649961bae6..c07b20a0cd 100644 --- a/common/src/cache_storage/cache_double_map.rs +++ b/common/src/cache_storage/cache_double_map.rs @@ -47,6 +47,18 @@ where _phantom: PhantomData, } +impl Default for CacheStorageDoubleMap +where + Key1: Ord + FullCodec + Clone, + Key2: Ord + FullCodec + Clone, + Value: FullCodec + Clone + PartialEq, + Storage: IterableStorageDoubleMap, +{ + fn default() -> Self { + Self::new() + } +} + impl CacheStorageDoubleMap where Key1: Ord + FullCodec + Clone, @@ -170,13 +182,7 @@ where } } - second_map.retain(|_, v| { - if let Some(Item::Original(_)) = v { - true - } else { - false - } - }); + second_map.retain(|_, v| matches!(v, Some(Item::Original(_)))); } } diff --git a/common/src/cache_storage/cache_map.rs b/common/src/cache_storage/cache_map.rs index 4fb13bc43f..1367ca36ac 100644 --- a/common/src/cache_storage/cache_map.rs +++ b/common/src/cache_storage/cache_map.rs @@ -46,7 +46,18 @@ where _phantom: PhantomData, } -impl CacheStorageMap +impl Default for CacheStorageMap +where + Key: Ord + FullEncode + Clone, + Value: FullCodec + Clone + PartialEq, + Storage: StorageMap, +{ + fn default() -> Self { + Self::new() + } +} + +impl CacheStorageMap where Key: Ord + FullEncode + Clone, Value: FullCodec + Clone + PartialEq, @@ -134,13 +145,8 @@ where } } } - self.cache.retain(|_, v| { - if let Some(Item::Original(_)) = v { - true - } else { - false - } - }); + self.cache + .retain(|_, v| matches!(v, Some(Item::Original(_)))); } /// Resets the cache diff --git a/common/src/lib.rs b/common/src/lib.rs index b00fffdb13..24915c7984 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -29,8 +29,7 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #![cfg_attr(not(feature = "std"), no_std)] -// TODO #167: fix clippy warnings -#![allow(clippy::all)] +#![allow(clippy::type_complexity)] #[macro_use] extern crate alloc; @@ -191,13 +190,13 @@ pub fn convert_block_number_to_timestamp( let num_of_seconds: u32 = ((unlocking_block - current_block) * 6u32.into()).unique_saturated_into(); let mut timestamp: T::Moment = num_of_seconds.into(); - timestamp = timestamp * 1000u32.into(); + timestamp *= 1000u32.into(); current_timestamp + timestamp } else { let num_of_seconds: u32 = ((current_block - unlocking_block) * 6u32.into()).unique_saturated_into(); let mut timestamp: T::Moment = num_of_seconds.into(); - timestamp = timestamp * 1000u32.into(); + timestamp *= 1000u32.into(); current_timestamp - timestamp } } diff --git a/common/src/primitives.rs b/common/src/primitives.rs index b0e5adc5a9..36d8a41580 100644 --- a/common/src/primitives.rs +++ b/common/src/primitives.rs @@ -359,12 +359,14 @@ where PartialOrd, Ord, RuntimeDebug, + Default, scale_info::TypeInfo, MaxEncodedLen, )] #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash))] #[repr(u8)] pub enum DEXId { + #[default] Polkaswap = 0, PolkaswapXSTUSD = 1, } @@ -375,12 +377,6 @@ impl From for u32 { } } -impl Default for DEXId { - fn default() -> Self { - DEXId::Polkaswap - } -} - pub type BalancePrecision = u8; pub const DEFAULT_BALANCE_PRECISION: BalancePrecision = crate::FIXED_PRECISION as u8; @@ -426,7 +422,7 @@ impl IsValid for AssetSymbol { && self .0 .iter() - .all(|byte| (b'A'..=b'Z').contains(&byte) || (b'0'..=b'9').contains(&byte)) + .all(|byte| byte.is_ascii_uppercase() || byte.is_ascii_digit()) } } @@ -470,16 +466,25 @@ impl IsValid for AssetName { !self.0.is_empty() && self.0.len() <= ASSET_NAME_MAX_LENGTH && self.0.iter().all(|byte| { - (b'A'..=b'Z').contains(&byte) - || (b'a'..=b'z').contains(&byte) - || (b'0'..=b'9').contains(&byte) + byte.is_ascii_uppercase() + || byte.is_ascii_lowercase() + || byte.is_ascii_digit() || byte == &b' ' }) } } #[derive( - Encode, Decode, Eq, PartialEq, Clone, Ord, PartialOrd, RuntimeDebug, scale_info::TypeInfo, + Encode, + Decode, + Eq, + PartialEq, + Clone, + Ord, + PartialOrd, + RuntimeDebug, + Default, + scale_info::TypeInfo, )] #[cfg_attr(feature = "std", derive(Hash))] pub struct ContentSource(pub Vec); @@ -502,12 +507,6 @@ impl Display for ContentSource { } } -impl Default for ContentSource { - fn default() -> Self { - Self(Vec::new()) - } -} - impl IsValid for ContentSource { fn is_valid(&self) -> bool { self.0.is_ascii() && self.0.len() <= ASSET_CONTENT_SOURCE_MAX_LENGTH @@ -515,7 +514,16 @@ impl IsValid for ContentSource { } #[derive( - Encode, Decode, Eq, PartialEq, Clone, Ord, PartialOrd, RuntimeDebug, scale_info::TypeInfo, + Encode, + Decode, + Eq, + PartialEq, + Clone, + Ord, + PartialOrd, + RuntimeDebug, + Default, + scale_info::TypeInfo, )] #[cfg_attr(feature = "std", derive(Hash))] pub struct Description(pub Vec); @@ -538,12 +546,6 @@ impl Display for Description { } } -impl Default for Description { - fn default() -> Self { - Self(Vec::new()) - } -} - impl IsValid for Description { fn is_valid(&self) -> bool { self.0.len() <= ASSET_DESCRIPTION_MAX_LENGTH @@ -551,7 +553,16 @@ impl IsValid for Description { } #[derive( - Encode, Decode, Eq, PartialEq, Clone, Ord, PartialOrd, RuntimeDebug, scale_info::TypeInfo, + Encode, + Decode, + Eq, + PartialEq, + Clone, + Ord, + PartialOrd, + RuntimeDebug, + Default, + scale_info::TypeInfo, )] #[cfg_attr(feature = "std", derive(Hash))] pub struct SymbolName(pub Vec); @@ -579,12 +590,6 @@ impl Display for SymbolName { } } -impl Default for SymbolName { - fn default() -> Self { - Self(Vec::new()) - } -} - impl IsValid for SymbolName { /// Same as for AssetSymbol fn is_valid(&self) -> bool { @@ -593,14 +598,23 @@ impl IsValid for SymbolName { && self .0 .iter() - .all(|byte| (b'A'..=b'Z').contains(&byte) || (b'0'..=b'9').contains(&byte)) + .all(|byte| byte.is_ascii_uppercase() || byte.is_ascii_digit()) } } const CROWDLOAN_TAG_MAX_LENGTH: u32 = 128; #[derive( - Encode, Decode, Eq, PartialEq, Clone, Ord, PartialOrd, RuntimeDebug, scale_info::TypeInfo, + Encode, + Decode, + Eq, + PartialEq, + Clone, + Ord, + PartialOrd, + RuntimeDebug, + Default, + scale_info::TypeInfo, )] pub struct CrowdloanTag(pub BoundedVec>); @@ -627,12 +641,6 @@ impl Display for CrowdloanTag { } } -impl Default for CrowdloanTag { - fn default() -> Self { - Self(Default::default()) - } -} - impl IsValid for CrowdloanTag { /// Same as for AssetSymbol fn is_valid(&self) -> bool { @@ -758,24 +766,15 @@ impl LiquiditySourceId PureOrWrapped for TechAssetId { fn is_pure(&self) -> bool { - match self { - TechAssetId::Wrapped(_) => false, - _ => true, - } + !matches!(self, TechAssetId::Wrapped(_)) } fn is_wrapped(&self) -> bool { - match self { - TechAssetId::Wrapped(_) => true, - _ => false, - } + matches!(self, TechAssetId::Wrapped(_)) } fn is_wrapped_regular(&self) -> bool { - match self { - TechAssetId::Wrapped(_) => true, - _ => false, - } + matches!(self, TechAssetId::Wrapped(_)) } } @@ -783,6 +782,7 @@ impl PureOrWrapped for TechAssetId { #[derive(Encode, Decode, Eq, PartialEq, Clone, PartialOrd, Ord, Debug, scale_info::TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[repr(u8)] +#[allow(clippy::unnecessary_cast)] pub enum TechPurpose { FeeCollector = 0, FeeCollectorForPair(TradingPair) = 1, @@ -794,7 +794,9 @@ pub enum TechPurpose { /// Enum encoding of technical account id, pure and wrapped records. /// Enum record `WrappedRepr` is wrapped represention of `Pure` variant of enum, this is useful then /// representation is known but backward mapping is not known. -#[derive(Encode, Decode, Eq, PartialEq, Clone, PartialOrd, Ord, Debug, scale_info::TypeInfo)] +#[derive( + Encode, Decode, Eq, PartialEq, Clone, PartialOrd, Ord, Debug, Default, scale_info::TypeInfo, +)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum TechAccountId { Pure(DEXId, TechPurpose), @@ -802,16 +804,14 @@ pub enum TechAccountId { Generic(Vec, Vec), Wrapped(AccountId), WrappedRepr(AccountId), + #[default] None, } /// Implementation of `IsRepresentation` for `TechAccountId`, because is has `WrappedRepr`. impl IsRepresentation for TechAccountId { fn is_representation(&self) -> bool { - match self { - TechAccountId::WrappedRepr(_) => true, - _ => false, - } + matches!(self, TechAccountId::WrappedRepr(_)) } } @@ -825,12 +825,6 @@ impl crate::traits::FromGenericPair } } -impl Default for TechAccountId { - fn default() -> Self { - TechAccountId::None - } -} - impl crate::traits::WrappedRepr for TechAccountId { @@ -844,13 +838,9 @@ impl crate::traits::ToFeeAccount { fn to_fee_account(&self) -> Option { match self { - TechAccountId::Pure(dex, purpose) => match purpose { - TechPurpose::XykLiquidityKeeper(tpair) => Some(TechAccountId::Pure( - dex.clone(), - TechPurpose::FeeCollectorForPair(tpair.clone()), - )), - _ => None, - }, + TechAccountId::Pure(dex, TechPurpose::XykLiquidityKeeper(tpair)) => Some( + TechAccountId::Pure(dex.clone(), TechPurpose::FeeCollectorForPair(tpair.clone())), + ), _ => None, } } @@ -914,24 +904,19 @@ where AccountId: IsRepresentation, { fn is_pure(&self) -> bool { - match self { - TechAccountId::Pure(_, _) => true, - TechAccountId::Generic(_, _) => true, - _ => false, - } + matches!( + self, + TechAccountId::Pure(_, _) | TechAccountId::Generic(_, _) + ) } fn is_wrapped_regular(&self) -> bool { - match self { - TechAccountId::Wrapped(_) => true, - _ => false, - } + matches!(self, TechAccountId::Wrapped(_)) } fn is_wrapped(&self) -> bool { - match self { - TechAccountId::Pure(_, _) => false, - TechAccountId::Generic(_, _) => false, - _ => true, - } + !matches!( + self, + TechAccountId::Pure(_, _) | TechAccountId::Generic(_, _) + ) } } diff --git a/common/src/serialization.rs b/common/src/serialization.rs index cb9f9185d0..8175565297 100644 --- a/common/src/serialization.rs +++ b/common/src/serialization.rs @@ -1,3 +1,5 @@ +#![allow(clippy::redundant_closure)] + #[cfg(feature = "std")] use super::*; #[cfg(feature = "std")] diff --git a/common/src/swap_amount.rs b/common/src/swap_amount.rs index 20efe40a69..48a48d58a1 100644 --- a/common/src/swap_amount.rs +++ b/common/src/swap_amount.rs @@ -173,7 +173,7 @@ impl CheckedAdd for QuoteAmount { Self::WithDesiredInput { desired_amount_in: in_b, }, - ) => Some(Self::with_desired_input(in_a.checked_add(&in_b)?)), + ) => Some(Self::with_desired_input(in_a.checked_add(in_b)?)), ( Self::WithDesiredOutput { desired_amount_out: out_a, @@ -181,7 +181,7 @@ impl CheckedAdd for QuoteAmount { Self::WithDesiredOutput { desired_amount_out: out_b, }, - ) => Some(Self::with_desired_output(out_a.checked_add(&out_b)?)), + ) => Some(Self::with_desired_output(out_a.checked_add(out_b)?)), (_, _) => None, } } @@ -545,7 +545,7 @@ where T: Copy + Into + From, { fn mul_assign(&mut self, rhs: Fixed) { - match self.clone() { + match *self { SwapAmount::WithDesiredInput { desired_amount_in, min_amount_out, diff --git a/common/src/traits.rs b/common/src/traits.rs index 95c336f7ce..3aa67897d4 100644 --- a/common/src/traits.rs +++ b/common/src/traits.rs @@ -247,18 +247,18 @@ pub trait LiquiditySource { /// Implements trading pairs LockedLiquiditySources storage pub trait LockedLiquiditySourcesManager { fn get() -> Vec; - fn set(liquidity_source_types: Vec) -> (); - fn append(liquidity_source_type: LiquiditySourceType) -> (); + fn set(liquidity_source_types: Vec); + fn append(liquidity_source_type: LiquiditySourceType); } /// Implements trading pair EnabledSources storage pub trait EnabledSourcesManager { - fn mutate_remove(dex_id: &DEXId, base_asset_id: &AssetId, target_asset_id: &AssetId) -> (); + fn mutate_remove(dex_id: &DEXId, base_asset_id: &AssetId, target_asset_id: &AssetId); } impl EnabledSourcesManager for () { - fn mutate_remove(_dex_id: &DEXId, _baset_asset_id: &AssetId, _target_asset_id: &AssetId) -> () { - todo!() + fn mutate_remove(_dex_id: &DEXId, _baset_asset_id: &AssetId, _target_asset_id: &AssetId) { + unimplemented!() } } @@ -318,7 +318,7 @@ pub trait OnSymbolDisabled { impl OnSymbolDisabled for () { fn disable_symbol(_symbol: &Symbol) { - () + unimplemented!() } } @@ -619,22 +619,6 @@ pub trait ToFeeAccount: Sized { fn to_fee_account(&self) -> Option; } -pub trait ToMarkerAsset: Sized { - fn to_marker_asset(&self, lst_id: LstId) -> Option; -} - -pub trait GetTechAssetWithLstTag: Sized { - fn get_tech_asset_with_lst_tag(tag: LstId, asset_id: AssetId) -> Result; -} - -pub trait GetLstIdAndTradingPairFromTechAsset { - fn get_lst_id_and_trading_pair_from_tech_asset(&self) -> Option<(LstId, TradingPair)>; -} - -pub trait ToTechUnitFromDEXAndAsset: Sized { - fn to_tech_unit_from_dex_and_asset(dex_id: DEXId, asset_id: AssetId) -> Self; -} - pub trait ToXykTechUnitFromDEXAndTradingPair: Sized { fn to_xyk_tech_unit_from_dex_and_trading_pair(dex_id: DEXId, trading_pair: TradingPair) -> Self; diff --git a/common/src/utils.rs b/common/src/utils.rs index de3cebe673..619333b062 100644 --- a/common/src/utils.rs +++ b/common/src/utils.rs @@ -47,10 +47,7 @@ const BASIS_POINTS_RANGE: u16 = 10000; /// Check if value belongs valid range of basis points. /// Returns true if range is valid, false otherwise. pub fn in_basis_points_range>(value: BP) -> bool { - match value.into() { - 0..=BASIS_POINTS_RANGE => true, - _ => false, - } + matches!(value.into(), 0..=BASIS_POINTS_RANGE) } /// Create fraction as Fixed from BasisPoints value. From 353adf37257a629bb09ca7d50e508864ff2944ef Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Mon, 11 Dec 2023 14:15:35 +0300 Subject: [PATCH 05/10] fix comments Signed-off-by: Mikhail Tagirov --- pallets/order-book/src/lib.rs | 4 +--- pallets/qa-tools/src/lib.rs | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pallets/order-book/src/lib.rs b/pallets/order-book/src/lib.rs index 932cb79214..4308371b7f 100644 --- a/pallets/order-book/src/lib.rs +++ b/pallets/order-book/src/lib.rs @@ -483,9 +483,7 @@ pub mod pallet { InvalidMaxLotSize, /// Tick size & step lot size are too big and their multiplication overflows Balance TickSizeAndStepLotSizeAreTooBig, - /// Product of tick and step lot sizes goes out of precision. It must be accurately - /// represented by fixed-precision float to prevent rounding errors. I.e. the product - /// should not have more than 18 digits after the comma. + /// Product of tick and step lot sizes goes out of precision. It must be accurately represented by fixed-precision float to prevent rounding errors. I.e. the product should not have more than 18 digits after the comma. TickSizeAndStepLotSizeLosePrecision, /// Max lot size cannot be more that total supply of base asset MaxLotSizeIsMoreThanTotalSupply, diff --git a/pallets/qa-tools/src/lib.rs b/pallets/qa-tools/src/lib.rs index 4f7e7e863b..bb7432f67f 100644 --- a/pallets/qa-tools/src/lib.rs +++ b/pallets/qa-tools/src/lib.rs @@ -83,13 +83,11 @@ pub mod pallet { NotInWhitelist, // order_book pallet errors - /// Did not find an order book with given id to fill. Likely an error with - /// order book creation. + /// Did not find an order book with given id to fill. Likely an error with order book creation. CannotFillUnknownOrderBook, /// Order Book already exists OrderBookAlreadyExists, - /// Price step, best price, and worst price must be a multiple of - /// order book's tick size. Price step must also be non-zero. + /// Price step, best price, and worst price must be a multiple of order book's tick size. Price step must also be non-zero. IncorrectPrice, /// Provided range is incorrect, check that lower bound is less or equal than the upper one. EmptyRandomRange, From 4da041b69d074174c5e9848293ac3c0d0344ae00 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Mon, 11 Dec 2023 14:48:25 +0300 Subject: [PATCH 06/10] common tests Signed-off-by: Mikhail Tagirov --- common/src/primitives.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/primitives.rs b/common/src/primitives.rs index 36d8a41580..16970f362e 100644 --- a/common/src/primitives.rs +++ b/common/src/primitives.rs @@ -1040,7 +1040,7 @@ mod tests { ); // should not panic - serde_json::to_value(&asset_id).unwrap(); + serde_json::to_value(asset_id).unwrap(); } #[test] @@ -1057,7 +1057,7 @@ mod tests { assert_eq!(unwrapped, balance); // should not panic - serde_json::to_value(&BalanceWrapper(balance)).unwrap(); + serde_json::to_value(BalanceWrapper(balance)).unwrap(); } } From eeba63133519a52c839b2b86f80c6420e6c1cfb9 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Mon, 11 Dec 2023 15:00:39 +0300 Subject: [PATCH 07/10] order-book tests Signed-off-by: Mikhail Tagirov --- pallets/order-book/src/tests/data_layer.rs | 100 ++-- pallets/order-book/src/tests/extrinsics.rs | 520 ++++++++++----------- pallets/order-book/src/tests/order_book.rs | 284 ++++++----- pallets/order-book/src/tests/orders.rs | 8 +- pallets/order-book/src/tests/pallet.rs | 282 +++++------ pallets/order-book/src/tests/types.rs | 56 +-- 6 files changed, 619 insertions(+), 631 deletions(-) diff --git a/pallets/order-book/src/tests/data_layer.rs b/pallets/order-book/src/tests/data_layer.rs index 6c3af478f8..03f64bcb10 100644 --- a/pallets/order-book/src/tests/data_layer.rs +++ b/pallets/order-book/src/tests/data_layer.rs @@ -73,8 +73,8 @@ fn should_work_as_cache() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_id = 1; @@ -168,8 +168,8 @@ fn should_work_as_storage() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_id = 1; @@ -253,8 +253,8 @@ fn should_get_all_limit_orders(data: &mut (impl DataLayer + StoragePush ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_buy_id1 = 1; @@ -313,7 +313,7 @@ fn should_get_all_limit_orders(data: &mut (impl DataLayer + StoragePush let order_sell3 = LimitOrder::::new( order_sell_id3, - owner.clone(), + owner, PriceVariant::Sell, price2, amount, @@ -363,8 +363,8 @@ fn should_insert_limit_order(data: &mut (impl DataLayer + StoragePush)) ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_buy_id = 1; @@ -516,8 +516,8 @@ fn should_not_insert_limit_order(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let owner = accounts::alice::(); @@ -526,7 +526,7 @@ fn should_not_insert_limit_order(data: &mut impl DataLayer) { let mut order = LimitOrder::::new( 0, - owner.clone(), + owner, PriceVariant::Sell, price, amount, @@ -569,8 +569,8 @@ fn should_delete_limit_order(data: &mut (impl DataLayer + StoragePush)) ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_buy_id1 = 1; @@ -1060,8 +1060,8 @@ fn should_not_delete_unknown_limit_order(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_id = 1; @@ -1089,8 +1089,8 @@ fn should_update_limit_order(data: &mut (impl DataLayer + StoragePush)) ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_id = 1; @@ -1230,8 +1230,8 @@ fn should_update_limit_order_with_zero_amount(data: &mut (impl DataLayer, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_id = 1; @@ -1355,8 +1355,8 @@ fn should_not_update_unknown_limit_order(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_id = 1; @@ -1385,8 +1385,8 @@ fn should_not_update_equal_limit_order(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_id = 1; @@ -1431,8 +1431,8 @@ fn should_not_update_limit_order_with_bigger_amount(data: &mut impl DataLayer, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_id = 1; @@ -1475,8 +1475,8 @@ fn get_limit_orders_by_price(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let buy_price = balance!(10).into(); @@ -1509,16 +1509,16 @@ fn get_user_limit_orders(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); let empty_order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: PSWAP.into(), - quote: XOR.into(), + base: PSWAP, + quote: XOR, }; create_empty_order_book::(empty_order_book_id); @@ -1552,24 +1552,24 @@ fn get_all_user_limit_orders(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id1 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id1); let order_book_id2 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: PSWAP.into(), - quote: XOR.into(), + base: PSWAP, + quote: XOR, }; create_and_fill_order_book::(order_book_id2); let empty_order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: ETH.into(), - quote: XOR.into(), + base: ETH, + quote: XOR, }; create_empty_order_book::(empty_order_book_id); @@ -1595,8 +1595,8 @@ fn best_bid_should_work_multiple_prices(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = create_and_fill_order_book::(order_book_id); @@ -1633,7 +1633,7 @@ fn best_bid_should_work_multiple_prices(data: &mut impl DataLayer) { let new_best_price = BalanceUnit::divisible(balance!(10.7)); let order2 = LimitOrder::::new( order_book.next_order_id(), - owner.clone(), + owner, PriceVariant::Buy, new_best_price, order_amount, @@ -1669,8 +1669,8 @@ fn best_ask_should_work_multiple_prices(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = create_and_fill_order_book::(order_book_id); @@ -1707,7 +1707,7 @@ fn best_ask_should_work_multiple_prices(data: &mut impl DataLayer) { let new_best_price = BalanceUnit::divisible(balance!(10.3)); let order2 = LimitOrder::::new( order_book.next_order_id(), - owner.clone(), + owner, PriceVariant::Sell, new_best_price, order_amount, @@ -1799,8 +1799,8 @@ fn is_bid_price_full_works(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_empty_order_book::(order_book_id); let price = order_book.tick_size; @@ -1818,8 +1818,8 @@ fn is_ask_price_full_works(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_empty_order_book::(order_book_id); let price = order_book.tick_size; @@ -1861,8 +1861,8 @@ fn is_user_limit_orders_full_works(data: &mut impl DataLayer) { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = create_empty_order_book::(order_book_id); let user = accounts::alice::(); diff --git a/pallets/order-book/src/tests/extrinsics.rs b/pallets/order-book/src/tests/extrinsics.rs index 9631fe3eeb..70c8a7adb5 100644 --- a/pallets/order-book/src/tests/extrinsics.rs +++ b/pallets/order-book/src/tests/extrinsics.rs @@ -63,8 +63,8 @@ fn should_not_create_order_book_with_disallowed_dex_id() { ext().execute_with(|| { let mut order_book_id = OrderBookId::, DEXId> { dex_id: common::DEXId::PolkaswapXSTUSD.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_err!( @@ -86,8 +86,8 @@ fn should_create_order_book_with_correct_dex_id() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_ok!(OrderBookPallet::create_orderbook( @@ -117,8 +117,8 @@ fn should_not_create_order_book_with_same_assets() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: XOR.into(), - quote: XOR.into(), + base: XOR, + quote: XOR, }; assert_err!( @@ -140,8 +140,8 @@ fn should_not_create_order_book_with_wrong_quote_asset() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: XOR.into(), - quote: VAL.into(), + base: XOR, + quote: VAL, }; assert_err!( @@ -156,8 +156,8 @@ fn should_create_order_book_with_synthetic_base_asset() { ext().execute_with(|| { let xstusd_order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: XSTUSD.into(), - quote: XOR.into(), + base: XSTUSD, + quote: XOR, }; if !TradingPair::is_trading_pair_enabled( @@ -195,8 +195,8 @@ fn should_create_order_book_with_synthetic_base_asset() { // it should work with synthetic base asset - XST as well let xst_order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: XST.into(), - quote: XOR.into(), + base: XST, + quote: XOR, }; if !TradingPair::is_trading_pair_enabled( @@ -242,8 +242,8 @@ fn should_not_create_order_book_with_non_existed_asset() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: wrong_asset.into(), - quote: XOR.into(), + base: wrong_asset, + quote: XOR, }; assert_err!( @@ -280,8 +280,8 @@ fn should_not_create_order_book_with_non_existed_trading_pair() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: new_asset.into(), - quote: XOR.into(), + base: new_asset, + quote: XOR, }; assert_err!( @@ -296,8 +296,8 @@ fn should_create_order_book_for_regular_assets() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_ok!(OrderBookPallet::create_orderbook( @@ -327,8 +327,8 @@ fn should_not_create_order_book_that_already_exists() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_ok!(OrderBookPallet::create_orderbook( @@ -376,11 +376,11 @@ fn should_not_create_order_book_for_user_without_nft() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }; assert_ok!(TradingPair::register( - RawOrigin::Signed(creator.clone()).into(), + RawOrigin::Signed(creator).into(), DEX.into(), order_book_id.quote, order_book_id.base @@ -422,7 +422,7 @@ fn should_not_create_order_book_for_nft_owner_without_nft() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }; assert_ok!(TradingPair::register( @@ -474,7 +474,7 @@ fn should_create_order_book_for_nft() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }; assert_ok!(TradingPair::register( @@ -511,8 +511,8 @@ fn should_check_permissions_for_delete_order_book() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -582,8 +582,8 @@ fn should_not_delete_unknown_order_book() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_err!( @@ -598,8 +598,8 @@ fn should_not_delete_order_book_with_wrong_status() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -633,8 +633,8 @@ fn should_not_delete_order_book_with_orders() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -657,15 +657,15 @@ fn should_delete_order_book() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); let owner = accounts::bob::(); let tech_account = technical::Pallet::::tech_account_id_to_account_id( - &OrderBookPallet::tech_account_for_order_book(order_book_id.clone()), + &OrderBookPallet::tech_account_for_order_book(order_book_id), ) .unwrap(); @@ -681,8 +681,8 @@ fn should_delete_order_book() { order_book_id )); - assert!(OrderBookPallet::aggregated_bids(&order_book_id).is_empty()); - assert!(OrderBookPallet::aggregated_asks(&order_book_id).is_empty()); + assert!(OrderBookPallet::aggregated_bids(order_book_id).is_empty()); + assert!(OrderBookPallet::aggregated_asks(order_book_id).is_empty()); assert_eq!( OrderBookPallet::user_limit_orders(&owner, &order_book_id), None @@ -704,8 +704,8 @@ fn should_check_permissions_for_update_order_book() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -792,8 +792,8 @@ fn should_not_update_unknown_order_book() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_err!( @@ -815,8 +815,8 @@ fn should_not_update_order_book_with_wrong_tech_status() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -841,8 +841,8 @@ fn should_not_update_order_book_with_wrong_status() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -928,8 +928,8 @@ fn should_not_update_order_book_with_zero_attributes() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -999,8 +999,8 @@ fn should_not_update_order_book_with_simple_mistakes() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -1078,8 +1078,8 @@ fn should_not_update_order_book_with_wrong_min_deal_amount() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -1189,8 +1189,8 @@ fn should_not_update_order_book_when_attributes_exceed_total_supply() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -1227,8 +1227,8 @@ fn should_update_order_book_with_regular_asset() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -1337,7 +1337,7 @@ fn should_update_order_book_with_nft() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }; assert_ok!(TradingPair::register( @@ -1390,8 +1390,8 @@ fn should_align_limit_orders_when_update_order_book() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -1533,20 +1533,20 @@ fn should_align_a_lot_of_limit_orders() { ext().execute_with(|| { let order_book_id1 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book_id2 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: PSWAP.into(), - quote: XOR.into(), + base: PSWAP, + quote: XOR, }; let order_book_id3 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: ETH.into(), - quote: XOR.into(), + base: ETH, + quote: XOR, }; let order_book1 = create_empty_order_book::(order_book_id1); @@ -1671,8 +1671,8 @@ fn should_check_permissions_for_change_order_book_status() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -1735,8 +1735,8 @@ fn should_not_change_status_of_unknown_order_book() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_err!( @@ -1755,8 +1755,8 @@ fn should_not_change_status_with_updating_tech_status() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -1799,8 +1799,8 @@ fn should_change_order_book_status() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -1861,8 +1861,8 @@ fn should_not_place_limit_order_in_unknown_order_book() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_err!( @@ -1885,8 +1885,8 @@ fn should_place_limit_order() { let caller = accounts::alice::(); let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -1901,8 +1901,8 @@ fn should_place_limit_order() { Timestamp::set_timestamp(now); // fix state before - let bids_before = OrderBookPallet::bids(&order_book_id, &price).unwrap_or_default(); - let agg_bids_before = OrderBookPallet::aggregated_bids(&order_book_id); + let bids_before = OrderBookPallet::bids(order_book_id, &price).unwrap_or_default(); + let agg_bids_before = OrderBookPallet::aggregated_bids(order_book_id); let price_volume_before = agg_bids_before.get(&price).cloned().unwrap_or_default(); let user_orders_before = OrderBookPallet::user_limit_orders(&caller, &order_book_id).unwrap_or_default(); @@ -1941,22 +1941,22 @@ fn should_place_limit_order() { expected_order ); - let mut expected_bids = bids_before.clone(); + let mut expected_bids = bids_before; assert_ok!(expected_bids.try_push(order_id)); assert_eq!( - OrderBookPallet::bids(&order_book_id, &price).unwrap(), + OrderBookPallet::bids(order_book_id, &price).unwrap(), expected_bids ); let expected_price_volume = price_volume_before + amount; - let mut expected_agg_bids = agg_bids_before.clone(); + let mut expected_agg_bids = agg_bids_before; assert_ok!(expected_agg_bids.try_insert(price, expected_price_volume)); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), expected_agg_bids ); - let mut expected_user_orders = user_orders_before.clone(); + let mut expected_user_orders = user_orders_before; assert_ok!(expected_user_orders.try_push(order_id)); assert_eq!( OrderBookPallet::user_limit_orders(&caller, &order_book_id).unwrap(), @@ -1997,7 +1997,7 @@ fn should_place_limit_order_with_nft() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }; assert_ok!(TradingPair::register( @@ -2053,11 +2053,11 @@ fn should_place_limit_order_with_nft() { ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &price).unwrap(), + OrderBookPallet::asks(order_book_id, &price).unwrap(), vec![order_id] ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([(price, amount)]) ); assert_eq!( @@ -2075,8 +2075,8 @@ fn should_place_limit_order_out_of_spread() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -2100,33 +2100,33 @@ fn should_place_limit_order_out_of_spread() { // check state before assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), vec![10, 11, 12] ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (bid_price1, balance!(168.5).into()), (bid_price2, balance!(139.9).into()), @@ -2134,7 +2134,7 @@ fn should_place_limit_order_out_of_spread() { ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([ (ask_price1, balance!(176.3).into()), (ask_price2, balance!(178.6).into()), @@ -2155,33 +2155,33 @@ fn should_place_limit_order_out_of_spread() { // check state assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), vec![10, 11, 12] ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (bid_price1, balance!(168.5).into()), (bid_price2, balance!(139.9).into()), @@ -2189,7 +2189,7 @@ fn should_place_limit_order_out_of_spread() { ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([ (ask_price1, balance!(150).into()), (ask_price2, balance!(178.6).into()), @@ -2212,34 +2212,34 @@ fn should_place_limit_order_out_of_spread() { let buy_order_id2 = get_last_order_id::(order_book_id).unwrap(); assert_eq!( - OrderBookPallet::bids(&order_book_id, &new_bid_price).unwrap(), + OrderBookPallet::bids(order_book_id, &new_bid_price).unwrap(), vec![buy_order_id2] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), vec![10, 11, 12] ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (new_bid_price, balance!(150).into()), (bid_price1, balance!(168.5).into()), @@ -2248,7 +2248,7 @@ fn should_place_limit_order_out_of_spread() { ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([ (ask_price2, balance!(178.6).into()), (ask_price3, balance!(255.8).into()) @@ -2275,30 +2275,30 @@ fn should_place_limit_order_out_of_spread() { // check state assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), vec![10, 11, 12] ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (bid_price1, balance!(150).into()), (bid_price2, balance!(139.9).into()), @@ -2306,7 +2306,7 @@ fn should_place_limit_order_out_of_spread() { ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([ (ask_price2, balance!(178.6).into()), (ask_price3, balance!(255.8).into()) @@ -2327,39 +2327,39 @@ fn should_place_limit_order_out_of_spread() { let sell_order_id2 = get_last_order_id::(order_book_id).unwrap(); - assert_eq!(OrderBookPallet::bids(&order_book_id, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price1), None); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &new_ask_price).unwrap(), + OrderBookPallet::asks(order_book_id, &new_ask_price).unwrap(), vec![sell_order_id2] ); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), vec![10, 11, 12] ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (bid_price2, balance!(139.9).into()), (bid_price3, balance!(261.3).into()) ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([ (new_ask_price, balance!(150).into()), (ask_price2, balance!(178.6).into()), @@ -2374,8 +2374,8 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -2397,33 +2397,33 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { // check state before assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), vec![10, 11, 12] ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (bid_price1, balance!(168.5).into()), (bid_price2, balance!(139.9).into()), @@ -2431,7 +2431,7 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([ (ask_price1, balance!(176.3).into()), (ask_price2, balance!(178.6).into()), @@ -2453,30 +2453,30 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { // check state assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), vec![10, 11, 12] ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (bid_price1, balance!(168.5).into()), (bid_price2, balance!(139.9).into()), @@ -2484,7 +2484,7 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([ (ask_price2, balance!(177.9).into()), (ask_price3, balance!(255.8).into()) @@ -2504,24 +2504,24 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { // check state assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price1), None); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price2), None); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price3), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price2), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price3), None); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (bid_price1, balance!(168.5).into()), (bid_price2, balance!(139.9).into()), @@ -2529,7 +2529,7 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([]) ); @@ -2545,29 +2545,29 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { )); // check state - assert_eq!(OrderBookPallet::bids(&order_book_id, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price1), None); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price1), None); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price2), None); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price3), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price2), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price3), None); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([ (bid_price2, balance!(139.4).into()), (bid_price3, balance!(261.3).into()) ]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([]) ); @@ -2583,20 +2583,20 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { )); // check state - assert_eq!(OrderBookPallet::bids(&order_book_id, &bid_price1), None); - assert_eq!(OrderBookPallet::bids(&order_book_id, &bid_price2), None); - assert_eq!(OrderBookPallet::bids(&order_book_id, &bid_price3), None); + assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price2), None); + assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price3), None); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price1), None); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price2), None); - assert_eq!(OrderBookPallet::asks(&order_book_id, &ask_price3), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price2), None); + assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price3), None); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), BTreeMap::from([]) ); assert_eq!( - OrderBookPallet::aggregated_asks(&order_book_id), + OrderBookPallet::aggregated_asks(order_book_id), BTreeMap::from([]) ); }); @@ -2607,8 +2607,8 @@ fn should_place_a_lot_of_orders() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_ok!(OrderBookPallet::create_orderbook( @@ -2667,8 +2667,8 @@ fn should_not_cancel_unknown_limit_order() { let caller = accounts::alice::(); let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -2692,8 +2692,8 @@ fn should_not_cancel_not_own_limit_order() { let caller = accounts::alice::(); // but owner is Bob let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -2716,8 +2716,8 @@ fn should_cancel_limit_order() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -2727,8 +2727,8 @@ fn should_cancel_limit_order() { let order = OrderBookPallet::limit_orders(order_book_id, order_id).unwrap(); // fix state before - let bids_before = OrderBookPallet::bids(&order_book_id, &order.price).unwrap_or_default(); - let agg_bids_before = OrderBookPallet::aggregated_bids(&order_book_id); + let bids_before = OrderBookPallet::bids(order_book_id, &order.price).unwrap_or_default(); + let agg_bids_before = OrderBookPallet::aggregated_bids(order_book_id); let price_volume_before = agg_bids_before .get(&order.price) .cloned() @@ -2747,22 +2747,22 @@ fn should_cancel_limit_order() { let deal_amount = *order.deal_amount(MarketRole::Taker, None).unwrap().value(); // check - let mut expected_bids = bids_before.clone(); + let mut expected_bids = bids_before; expected_bids.retain(|&id| id != order.id); assert_eq!( - OrderBookPallet::bids(&order_book_id, &order.price).unwrap(), + OrderBookPallet::bids(order_book_id, &order.price).unwrap(), expected_bids ); let expected_price_volume = price_volume_before - order.amount; - let mut expected_agg_bids = agg_bids_before.clone(); + let mut expected_agg_bids = agg_bids_before; assert_ok!(expected_agg_bids.try_insert(order.price, expected_price_volume)); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), expected_agg_bids ); - let mut expected_user_orders = user_orders_before.clone(); + let mut expected_user_orders = user_orders_before; expected_user_orders.retain(|&id| id != order.id); assert_eq!( OrderBookPallet::user_limit_orders(&order.owner, &order_book_id).unwrap(), @@ -2780,16 +2780,16 @@ fn should_not_cancel_not_own_limit_orders_batch() { ext().execute_with(|| { let order_book_id1 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id1); let order_book_id2 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: PSWAP.into(), - quote: XOR.into(), + base: PSWAP, + quote: XOR, }; create_and_fill_order_book::(order_book_id2); @@ -2815,16 +2815,16 @@ fn should_not_cancel_unknown_limit_orders_batch() { ext().execute_with(|| { let order_book_id1 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id1); let order_book_id2 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: PSWAP.into(), - quote: XOR.into(), + base: PSWAP, + quote: XOR, }; create_and_fill_order_book::(order_book_id2); @@ -2850,24 +2850,24 @@ fn should_not_cancel_limit_orders_batch_in_stopped_order_book() { ext().execute_with(|| { let order_book_id1 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id1); let order_book_id2 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: PSWAP.into(), - quote: XOR.into(), + base: PSWAP, + quote: XOR, }; create_and_fill_order_book::(order_book_id2); let order_book_id3 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: ETH.into(), - quote: XOR.into(), + base: ETH, + quote: XOR, }; create_and_fill_order_book::(order_book_id3); @@ -2912,16 +2912,16 @@ fn should_cancel_all_user_limit_orders_batch() { ext().execute_with(|| { let order_book_id1 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id1); let order_book_id2 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: PSWAP.into(), - quote: XOR.into(), + base: PSWAP, + quote: XOR, }; create_and_fill_order_book::(order_book_id2); @@ -2938,55 +2938,55 @@ fn should_cancel_all_user_limit_orders_batch() { // order book 1 assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price3).unwrap(), vec![10, 11, 12] ); // order book 2 assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price3).unwrap(), vec![10, 11, 12] ); @@ -3005,44 +3005,44 @@ fn should_cancel_all_user_limit_orders_batch() { // check state after // order book 1 - assert_eq!(OrderBookPallet::bids(&order_book_id1, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id1, &bid_price1), None); assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price2).unwrap(), vec![2] ); assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price3).unwrap(), vec![4, 6] ); - assert_eq!(OrderBookPallet::asks(&order_book_id1, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id1, &ask_price1), None); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price2).unwrap(), vec![8] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price3).unwrap(), vec![10, 12] ); // order book 2 - assert_eq!(OrderBookPallet::bids(&order_book_id2, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id2, &bid_price1), None); assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price2).unwrap(), vec![2] ); assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price3).unwrap(), vec![4, 6] ); - assert_eq!(OrderBookPallet::asks(&order_book_id2, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id2, &ask_price1), None); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price2).unwrap(), vec![8] ); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price3).unwrap(), vec![10, 12] ); }); @@ -3053,16 +3053,16 @@ fn should_cancel_part_of_all_user_limit_orders_batch() { ext().execute_with(|| { let order_book_id1 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id1); let order_book_id2 = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: PSWAP.into(), - quote: XOR.into(), + base: PSWAP, + quote: XOR, }; create_and_fill_order_book::(order_book_id2); @@ -3079,55 +3079,55 @@ fn should_cancel_part_of_all_user_limit_orders_batch() { // order book 1 assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price3).unwrap(), vec![10, 11, 12] ); // order book 2 assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price3).unwrap(), vec![10, 11, 12] ); @@ -3146,50 +3146,50 @@ fn should_cancel_part_of_all_user_limit_orders_batch() { // check state after // order book 1 - assert_eq!(OrderBookPallet::bids(&order_book_id1, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id1, &bid_price1), None); assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(&order_book_id1, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id1, &bid_price3).unwrap(), vec![4, 6] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price2).unwrap(), vec![8] ); assert_eq!( - OrderBookPallet::asks(&order_book_id1, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id1, &ask_price3).unwrap(), vec![10, 11, 12] ); // order book 2 assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price2).unwrap(), vec![2] ); assert_eq!( - OrderBookPallet::bids(&order_book_id2, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id2, &bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(&order_book_id2, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id2, &ask_price1), None); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(&order_book_id2, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id2, &ask_price3).unwrap(), vec![10, 12] ); }); @@ -3200,8 +3200,8 @@ fn should_not_execute_market_order_with_divisible_asset() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -3249,7 +3249,7 @@ fn should_execute_market_order_with_indivisible_asset() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }; fill_balance::(accounts::alice::(), order_book_id); diff --git a/pallets/order-book/src/tests/order_book.rs b/pallets/order-book/src/tests/order_book.rs index a724d001ca..ca1165546c 100644 --- a/pallets/order-book/src/tests/order_book.rs +++ b/pallets/order-book/src/tests/order_book.rs @@ -53,8 +53,8 @@ use sp_std::iter::repeat; fn should_create_new() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let expected = OrderBook:: { @@ -84,8 +84,8 @@ fn should_create_new() { fn should_increment_order_id() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = OrderBook::::new( @@ -114,8 +114,8 @@ fn should_place_limit_order() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -152,7 +152,7 @@ fn should_place_limit_order() { assert_eq!(order_book.place_limit_order(order, &mut data).unwrap(), 0); // check - let mut expected_bids = bids_before.clone(); + let mut expected_bids = bids_before; assert_ok!(expected_bids.try_push(order_id)); assert_eq!( data.get_bids(&order_book_id, &price).unwrap(), @@ -160,11 +160,11 @@ fn should_place_limit_order() { ); let expected_price_volume = price_volume_before + amount; - let mut expected_agg_bids = agg_bids_before.clone(); + let mut expected_agg_bids = agg_bids_before; assert_ok!(expected_agg_bids.try_insert(price, expected_price_volume)); assert_eq!(data.get_aggregated_bids(&order_book_id), expected_agg_bids); - let mut expected_user_orders = user_orders_before.clone(); + let mut expected_user_orders = user_orders_before; assert_ok!(expected_user_orders.try_push(order_id)); assert_eq!( data.get_user_limit_orders(&owner, &order_book_id).unwrap(), @@ -207,7 +207,7 @@ fn should_place_nft_limit_order() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }; let order_book = OrderBook::::new( @@ -265,8 +265,8 @@ fn should_place_limit_order_out_of_spread() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -642,8 +642,8 @@ fn should_not_place_limit_order_when_status_doesnt_allow() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = OrderBook::::new( @@ -685,7 +685,7 @@ fn should_not_place_limit_order_when_status_doesnt_allow() { order_book.status = OrderBookStatus::Trade; order.id = 2; - assert_ok!(order_book.place_limit_order(order.clone(), &mut data)); + assert_ok!(order_book.place_limit_order(order, &mut data)); }); } @@ -696,8 +696,8 @@ fn should_not_place_invalid_limit_order() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = OrderBook::::new( @@ -740,7 +740,7 @@ fn should_not_place_invalid_limit_order() { E::InvalidOrderAmount ); - let mut wrong_amount_order = order.clone(); + let mut wrong_amount_order = order; wrong_amount_order.amount = (balance!(100) + order_book.step_lot_size.balance() / 100).into(); assert_err!( @@ -771,7 +771,7 @@ fn should_not_place_invalid_nft_limit_order() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }; let order_book = OrderBook::::new( @@ -807,7 +807,7 @@ fn should_not_place_invalid_nft_limit_order() { E::InvalidOrderAmount ); - let mut too_big_amount_order = order.clone(); + let mut too_big_amount_order = order; too_big_amount_order.amount = order_book.max_lot_size + OrderVolume::indivisible(1); assert_err!( order_book.place_limit_order(too_big_amount_order, &mut data), @@ -823,8 +823,8 @@ fn should_not_place_limit_order_that_doesnt_meet_restrictions_for_user() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = OrderBook::::new( @@ -887,8 +887,8 @@ fn should_not_place_limit_order_that_doesnt_meet_restrictions_for_orders_in_pric let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = OrderBook::::new( @@ -965,8 +965,8 @@ fn should_not_place_limit_order_that_doesnt_meet_restrictions_for_side() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = OrderBook::::new( @@ -1049,8 +1049,8 @@ fn should_not_place_limit_order_that_doesnt_meet_restrictions_for_price() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1114,8 +1114,8 @@ fn should_not_place_limit_order_that_doesnt_meet_restrictions_for_price() { (best_ask_price - max_price_shift * best_ask_price - order_book.tick_size.balance()) .into(); - assert_ok!(order_book.place_limit_order(buy_order.clone(), &mut data)); - assert_ok!(order_book.place_limit_order(sell_order.clone(), &mut data)); + assert_ok!(order_book.place_limit_order(buy_order, &mut data)); + assert_ok!(order_book.place_limit_order(sell_order, &mut data)); }) } @@ -1126,8 +1126,8 @@ fn should_not_place_limit_order_in_spread() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = create_and_fill_order_book::(order_book_id); @@ -1179,8 +1179,8 @@ fn should_cancel_limit_order() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1207,7 +1207,7 @@ fn should_cancel_limit_order() { let deal_amount = *order.deal_amount(MarketRole::Taker, None).unwrap().value(); // check - let mut expected_bids = bids_before.clone(); + let mut expected_bids = bids_before; expected_bids.retain(|&id| id != order.id); assert_eq!( data.get_bids(&order_book_id, &order.price).unwrap(), @@ -1215,11 +1215,11 @@ fn should_cancel_limit_order() { ); let expected_price_volume = price_volume_before - order.amount; - let mut expected_agg_bids = agg_bids_before.clone(); + let mut expected_agg_bids = agg_bids_before; assert_ok!(expected_agg_bids.try_insert(order.price, expected_price_volume)); assert_eq!(data.get_aggregated_bids(&order_book_id), expected_agg_bids); - let mut expected_user_orders = user_orders_before.clone(); + let mut expected_user_orders = user_orders_before; expected_user_orders.retain(|&id| id != order.id); assert_eq!( data.get_user_limit_orders(&order.owner, &order_book_id) @@ -1240,8 +1240,8 @@ fn should_not_cancel_unknown_limit_order() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1271,8 +1271,8 @@ fn should_not_cancel_limit_order_when_status_doesnt_allow() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = create_and_fill_order_book::(order_book_id); @@ -1306,14 +1306,14 @@ fn should_cancel_all_limit_orders() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); let tech_account = technical::Pallet::::tech_account_id_to_account_id( - &OrderBookPallet::tech_account_for_order_book(order_book_id.clone()), + &OrderBookPallet::tech_account_for_order_book(order_book_id), ) .unwrap(); @@ -1378,8 +1378,8 @@ fn should_not_get_best_bid_from_empty_order_book() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_empty_order_book::(order_book_id); @@ -1395,8 +1395,8 @@ fn should_get_best_bid() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1415,8 +1415,8 @@ fn should_not_get_best_ask_from_empty_order_book() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_empty_order_book::(order_book_id); @@ -1432,8 +1432,8 @@ fn should_get_best_ask() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1450,8 +1450,8 @@ fn should_not_get_direction_if_any_asset_is_not_in_order_book_id() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1469,8 +1469,8 @@ fn should_get_direction() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1491,8 +1491,8 @@ fn should_align_amount() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_empty_order_book::(order_book_id); @@ -1544,8 +1544,8 @@ fn should_not_sum_market_if_limit_is_greater_than_liquidity() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1588,8 +1588,8 @@ fn should_sum_market_with_zero_limit() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1649,8 +1649,8 @@ fn should_sum_market() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1901,8 +1901,8 @@ fn should_not_calculate_deal_with_small_amount() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1911,7 +1911,7 @@ fn should_not_calculate_deal_with_small_amount() { order_book.calculate_deal( &XOR, &VAL, - QuoteAmount::with_desired_input(balance!(0.000001).into()), + QuoteAmount::with_desired_input(balance!(0.000001)), &mut data ), E::InvalidOrderAmount @@ -1920,7 +1920,7 @@ fn should_not_calculate_deal_with_small_amount() { order_book.calculate_deal( &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(0.000001).into()), + QuoteAmount::with_desired_output(balance!(0.000001)), &mut data ), E::InvalidOrderAmount @@ -1929,7 +1929,7 @@ fn should_not_calculate_deal_with_small_amount() { order_book.calculate_deal( &VAL, &XOR, - QuoteAmount::with_desired_input(balance!(0.000001).into()), + QuoteAmount::with_desired_input(balance!(0.000001)), &mut data ), E::InvalidOrderAmount @@ -1938,7 +1938,7 @@ fn should_not_calculate_deal_with_small_amount() { order_book.calculate_deal( &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(0.000001).into()), + QuoteAmount::with_desired_output(balance!(0.000001)), &mut data ), E::InvalidOrderAmount @@ -1953,8 +1953,8 @@ fn should_calculate_deal() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -1964,7 +1964,7 @@ fn should_calculate_deal() { .calculate_deal( &XOR, &VAL, - QuoteAmount::with_desired_input(balance!(3000).into()), + QuoteAmount::with_desired_input(balance!(3000)), &mut data ) .unwrap(), @@ -1982,7 +1982,7 @@ fn should_calculate_deal() { .calculate_deal( &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), &mut data ) .unwrap(), @@ -2000,7 +2000,7 @@ fn should_calculate_deal() { .calculate_deal( &VAL, &XOR, - QuoteAmount::with_desired_input(balance!(200).into()), + QuoteAmount::with_desired_input(balance!(200)), &mut data ) .unwrap(), @@ -2018,7 +2018,7 @@ fn should_calculate_deal() { .calculate_deal( &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), &mut data ) .unwrap(), @@ -2041,8 +2041,8 @@ fn should_not_execute_market_order_with_non_trade_status() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = create_and_fill_order_book::(order_book_id); @@ -2069,7 +2069,7 @@ fn should_not_execute_market_order_with_non_trade_status() { order_book.status = OrderBookStatus::Stop; assert_err!( - order_book.execute_market_order(order.clone(), &mut data), + order_book.execute_market_order(order, &mut data), E::TradingIsForbidden ); }); @@ -2082,8 +2082,8 @@ fn should_not_execute_market_order_with_empty_amount() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -2111,14 +2111,14 @@ fn should_not_execute_market_order_with_invalid_order_book_id() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let wrong_order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: DOT.into(), - quote: XOR.into(), + base: DOT, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -2145,8 +2145,8 @@ fn should_not_execute_market_order_with_invalid_amount() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -2173,7 +2173,7 @@ fn should_not_execute_market_order_with_invalid_amount() { E::InvalidOrderAmount ); - let mut too_big_amount_order = order.clone(); + let mut too_big_amount_order = order; too_big_amount_order.amount = (order_book.max_lot_size.balance() + 1).into(); assert_err!( order_book.execute_market_order(too_big_amount_order, &mut data), @@ -2189,8 +2189,8 @@ fn should_execute_market_order_and_transfer_to_owner() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -2630,7 +2630,7 @@ fn should_execute_market_order_and_transfer_to_owner() { assert_eq!( order_book - .execute_market_order(buy_order.clone(), &mut data) + .execute_market_order(buy_order, &mut data) .unwrap(), ( OrderAmount::Quote(balance!(1848.05).into()), @@ -2640,7 +2640,7 @@ fn should_execute_market_order_and_transfer_to_owner() { ); assert_eq!( order_book - .execute_market_order(sell_order.clone(), &mut data) + .execute_market_order(sell_order, &mut data) .unwrap(), ( OrderAmount::Base(balance!(119.7).into()), @@ -2685,8 +2685,8 @@ fn should_execute_market_order_and_transfer_to_another_account() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -3209,7 +3209,7 @@ fn should_execute_market_order_and_transfer_to_another_account() { assert_eq!( order_book - .execute_market_order(buy_order.clone(), &mut data) + .execute_market_order(buy_order, &mut data) .unwrap(), ( OrderAmount::Quote(balance!(1848.05).into()), @@ -3219,7 +3219,7 @@ fn should_execute_market_order_and_transfer_to_another_account() { ); assert_eq!( order_book - .execute_market_order(sell_order.clone(), &mut data) + .execute_market_order(sell_order, &mut data) .unwrap(), ( OrderAmount::Base(balance!(119.7).into()), @@ -3271,8 +3271,8 @@ fn should_align_limit_orders() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = create_and_fill_order_book::(order_book_id); @@ -3348,8 +3348,8 @@ fn should_not_calculate_market_order_impact_with_empty_side() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_empty_order_book::(order_book_id); @@ -3390,8 +3390,8 @@ fn should_not_calculate_market_order_impact_if_liquidity_is_not_enough() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -3432,8 +3432,8 @@ fn should_calculate_market_order_impact() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -3702,12 +3702,12 @@ fn should_calculate_market_order_impact() { to_place: BTreeMap::from([]), to_part_execute: BTreeMap::from([]), to_full_execute: BTreeMap::from([ - (7, limit_order7.clone()), - (8, limit_order8.clone()), - (9, limit_order9.clone()), - (10, limit_order10.clone()), - (11, limit_order11.clone()), - (12, limit_order12.clone()), + (7, limit_order7), + (8, limit_order8), + (9, limit_order9), + (10, limit_order10), + (11, limit_order11), + (12, limit_order12), ]), to_cancel: BTreeMap::from([]), to_force_update: BTreeMap::from([]), @@ -3984,12 +3984,12 @@ fn should_calculate_market_order_impact() { to_place: BTreeMap::from([]), to_part_execute: BTreeMap::from([]), to_full_execute: BTreeMap::from([ - (1, limit_order1.clone()), - (2, limit_order2.clone()), - (3, limit_order3.clone()), - (4, limit_order4.clone()), - (5, limit_order5.clone()), - (6, limit_order6.clone()), + (1, limit_order1), + (2, limit_order2), + (3, limit_order3), + (4, limit_order4), + (5, limit_order5), + (6, limit_order6), ]), to_cancel: BTreeMap::from([]), to_force_update: BTreeMap::from([]), @@ -4027,8 +4027,8 @@ fn should_calculate_limit_order_impact() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_empty_order_book::(order_book_id); @@ -4115,8 +4115,8 @@ fn should_calculate_cancellation_limit_order_impact() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -4277,8 +4277,8 @@ fn should_calculate_cancellation_of_all_limit_orders_impact() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -4356,8 +4356,8 @@ fn should_calculate_align_limit_orders_impact() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = create_and_fill_order_book::(order_book_id); @@ -4564,8 +4564,8 @@ fn should_apply_market_change() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -4681,23 +4681,11 @@ fn should_apply_market_change() { (new_order_id2, new_limit_order2.clone()), ]), to_part_execute: BTreeMap::from([ - ( - 1, - ( - limit_order1.clone(), - OrderAmount::Base(balance!(68.5).into()), - ), - ), - ( - 7, - ( - limit_order7.clone(), - OrderAmount::Base(balance!(76.3).into()), - ), - ), + (1, (limit_order1, OrderAmount::Base(balance!(68.5).into()))), + (7, (limit_order7, OrderAmount::Base(balance!(76.3).into()))), ]), - to_full_execute: BTreeMap::from([(8, limit_order8.clone())]), - to_cancel: BTreeMap::from([(2, (limit_order2.clone(), CancelReason::Manual))]), + to_full_execute: BTreeMap::from([(8, limit_order8)]), + to_cancel: BTreeMap::from([(2, (limit_order2, CancelReason::Manual))]), to_force_update: BTreeMap::from([]), payment: Payment { order_book_id, @@ -4818,8 +4806,8 @@ fn should_calculate_market_depth_to_price() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_and_fill_order_book::(order_book_id); @@ -4997,8 +4985,8 @@ fn should_cross_spread() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); @@ -5228,8 +5216,8 @@ fn should_cross_spread_with_small_remaining_amount() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_and_fill_order_book::(order_book_id); diff --git a/pallets/order-book/src/tests/orders.rs b/pallets/order-book/src/tests/orders.rs index 42169802a8..e85e8f68ae 100644 --- a/pallets/order-book/src/tests/orders.rs +++ b/pallets/order-book/src/tests/orders.rs @@ -88,8 +88,8 @@ fn should_return_error_for_invalid_limit_order_amount() { fn should_return_error_for_invalid_market_order_amount() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let wrong_amount = balance!(0).into(); @@ -150,8 +150,8 @@ fn should_pass_valid_limit_order() { fn should_pass_valid_market_order() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let amount = balance!(10).into(); diff --git a/pallets/order-book/src/tests/pallet.rs b/pallets/order-book/src/tests/pallet.rs index 54ba340b00..2c37ad4f75 100644 --- a/pallets/order-book/src/tests/pallet.rs +++ b/pallets/order-book/src/tests/pallet.rs @@ -72,13 +72,13 @@ fn should_register_technical_account() { let order_books = [ OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }, OrderBookId::, DEXId> { dex_id: DEX.into(), base: nft, - quote: XOR.into(), + quote: XOR, }, ]; @@ -226,8 +226,8 @@ fn should_lock_unlock_base_asset() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -274,8 +274,8 @@ fn should_lock_unlock_other_asset() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -319,8 +319,8 @@ fn should_lock_unlock_indivisible_nft() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: nft.clone(), - quote: XOR.into(), + base: nft, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -359,8 +359,8 @@ fn should_lock_unlock_multiple_indivisible_nfts() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: nft.clone(), - quote: XOR.into(), + base: nft, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -390,8 +390,8 @@ fn should_not_lock_insufficient_base_asset() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -421,8 +421,8 @@ fn should_not_lock_insufficient_other_asset() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -459,8 +459,8 @@ fn should_not_lock_insufficient_nft() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: nft.clone(), - quote: XOR.into(), + base: nft, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -491,8 +491,8 @@ fn should_not_unlock_more_base_that_tech_account_has() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -530,8 +530,8 @@ fn should_not_unlock_more_other_that_tech_account_has() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -575,8 +575,8 @@ fn should_not_unlock_more_nft_that_tech_account_has() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: nft.clone(), - quote: XOR.into(), + base: nft, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -598,8 +598,8 @@ fn should_expire_order() { let caller = accounts::alice::(); let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -633,7 +633,7 @@ fn should_expire_order() { // check let expected_order = LimitOrder::::new( order_id, - caller.clone(), + caller, PriceVariant::Buy, price, amount, @@ -670,8 +670,8 @@ fn should_cleanup_on_expiring() { let caller = accounts::alice::(); let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; create_empty_order_book::(order_book_id); @@ -690,8 +690,8 @@ fn should_cleanup_on_expiring() { pallet_timestamp::Pallet::::set_timestamp(now); // fix state before - let bids_before = OrderBookPallet::bids(&order_book_id, &price).unwrap_or_default(); - let agg_bids_before = OrderBookPallet::aggregated_bids(&order_book_id); + let bids_before = OrderBookPallet::bids(order_book_id, &price).unwrap_or_default(); + let agg_bids_before = OrderBookPallet::aggregated_bids(order_book_id); let price_volume_before = agg_bids_before.get(&price).cloned().unwrap_or_default(); let user_orders_before = OrderBookPallet::user_limit_orders(&caller, &order_book_id).unwrap_or_default(); @@ -735,7 +735,7 @@ fn should_cleanup_on_expiring() { let mut bids_with_order = bids_before.clone(); assert_ok!(bids_with_order.try_push(order_id)); assert_eq!( - OrderBookPallet::bids(&order_book_id, &price).unwrap(), + OrderBookPallet::bids(order_book_id, &price).unwrap(), bids_with_order ); @@ -743,7 +743,7 @@ fn should_cleanup_on_expiring() { let mut agg_bids_with_order = agg_bids_before.clone(); assert_ok!(agg_bids_with_order.try_insert(price, price_volume_with_order)); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), agg_bids_with_order ); @@ -769,11 +769,11 @@ fn should_cleanup_on_expiring() { expected_order ); assert_eq!( - OrderBookPallet::bids(&order_book_id, &price).unwrap(), + OrderBookPallet::bids(order_book_id, &price).unwrap(), bids_with_order ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), agg_bids_with_order ); assert_eq!( @@ -792,11 +792,11 @@ fn should_cleanup_on_expiring() { // The order is removed, state returned to original assert!(OrderBookPallet::limit_orders(order_book_id, order_id).is_none()); assert_eq!( - OrderBookPallet::bids(&order_book_id, &price).unwrap_or_default(), + OrderBookPallet::bids(order_book_id, &price).unwrap_or_default(), bids_before ); assert_eq!( - OrderBookPallet::aggregated_bids(&order_book_id), + OrderBookPallet::aggregated_bids(order_book_id), agg_bids_before ); assert_eq!( @@ -815,8 +815,8 @@ fn should_enforce_expiration_and_weight_limits() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let order_book = create_empty_order_book::(order_book_id); @@ -855,7 +855,7 @@ fn should_enforce_expiration_and_weight_limits() { fill_balance::(caller.clone(), order_book_id); assert_err!( OrderBookPallet::place_limit_order( - RawOrigin::Signed(caller.clone()).into(), + RawOrigin::Signed(caller).into(), order_book_id, price, amount, @@ -917,7 +917,7 @@ fn should_emit_event_on_expiration_failure() { quote: VAL, }; let non_existent_order_id = 1; - let expiration_block = 2u32.into(); + let expiration_block = 2u32; assert_ok!(OrderBookPallet::schedule_expiration( expiration_block, non_existent_order_book_id, @@ -940,14 +940,14 @@ fn should_assemble_order_book_id() { ext().execute_with(|| { let polkaswap_order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let polkaswap_xstusd_order_book_id = OrderBookId::, DEXId> { dex_id: common::DEXId::PolkaswapXSTUSD.into(), - base: VAL.into(), - quote: XSTUSD.into(), + base: VAL, + quote: XSTUSD, }; assert_eq!( @@ -1044,8 +1044,8 @@ fn can_exchange() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_empty_order_book::(order_book_id); @@ -1068,8 +1068,8 @@ fn cannot_exchange_with_not_trade_status() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let mut order_book = OrderBook::::new( @@ -1097,7 +1097,7 @@ fn cannot_exchange_with_not_trade_status() { // success for Trade status order_book.status = OrderBookStatus::Trade; - order_book::OrderBooks::::insert(order_book_id, order_book.clone()); + order_book::OrderBooks::::insert(order_book_id, order_book); assert!(OrderBookPallet::can_exchange(&DEX.into(), &XOR, &VAL)); assert!(OrderBookPallet::can_exchange(&DEX.into(), &VAL, &XOR)); }); @@ -1108,8 +1108,8 @@ fn should_quote() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_and_fill_order_book::(order_book_id); @@ -1120,12 +1120,12 @@ fn should_quote() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_input(balance!(3000).into()), + QuoteAmount::with_desired_input(balance!(3000)), false ) .unwrap() .0, - SwapOutcome::new(balance!(271.00535).into(), 0) + SwapOutcome::new(balance!(271.00535), 0) ); assert_eq!( @@ -1133,12 +1133,12 @@ fn should_quote() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), false ) .unwrap() .0, - SwapOutcome::new(balance!(2204.74).into(), 0) + SwapOutcome::new(balance!(2204.74), 0) ); assert_eq!( @@ -1146,12 +1146,12 @@ fn should_quote() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_input(balance!(200).into()), + QuoteAmount::with_desired_input(balance!(200)), false ) .unwrap() .0, - SwapOutcome::new(balance!(1993.7).into(), 0) + SwapOutcome::new(balance!(1993.7), 0) ); assert_eq!( @@ -1159,12 +1159,12 @@ fn should_quote() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), false ) .unwrap() .0, - SwapOutcome::new(balance!(251.66326).into(), 0) + SwapOutcome::new(balance!(251.66326), 0) ); // with fee @@ -1173,12 +1173,12 @@ fn should_quote() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_input(balance!(3000).into()), + QuoteAmount::with_desired_input(balance!(3000)), true ) .unwrap() .0, - SwapOutcome::new(balance!(271.00535).into(), 0) + SwapOutcome::new(balance!(271.00535), 0) ); assert_eq!( @@ -1186,12 +1186,12 @@ fn should_quote() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), true ) .unwrap() .0, - SwapOutcome::new(balance!(2204.74).into(), 0) + SwapOutcome::new(balance!(2204.74), 0) ); assert_eq!( @@ -1199,12 +1199,12 @@ fn should_quote() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_input(balance!(200).into()), + QuoteAmount::with_desired_input(balance!(200)), true ) .unwrap() .0, - SwapOutcome::new(balance!(1993.7).into(), 0) + SwapOutcome::new(balance!(1993.7), 0) ); assert_eq!( @@ -1212,12 +1212,12 @@ fn should_quote() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), true ) .unwrap() .0, - SwapOutcome::new(balance!(251.66326).into(), 0) + SwapOutcome::new(balance!(251.66326), 0) ); }); } @@ -1230,7 +1230,7 @@ fn should_not_quote_with_non_existed_order_book() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), true ), E::UnknownOrderBook @@ -1241,7 +1241,7 @@ fn should_not_quote_with_non_existed_order_book() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), true ), E::UnknownOrderBook @@ -1254,8 +1254,8 @@ fn should_not_quote_with_empty_side() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_empty_order_book::(order_book_id); @@ -1265,7 +1265,7 @@ fn should_not_quote_with_empty_side() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), true ), E::NotEnoughLiquidityInOrderBook @@ -1276,7 +1276,7 @@ fn should_not_quote_with_empty_side() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), true ), E::NotEnoughLiquidityInOrderBook @@ -1289,8 +1289,8 @@ fn should_not_quote_with_small_amount() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_and_fill_order_book::(order_book_id); @@ -1300,7 +1300,7 @@ fn should_not_quote_with_small_amount() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(0.000001).into()), + QuoteAmount::with_desired_output(balance!(0.000001)), true ), E::InvalidOrderAmount @@ -1311,7 +1311,7 @@ fn should_not_quote_with_small_amount() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(0).into()), + QuoteAmount::with_desired_output(balance!(0)), true ), E::InvalidOrderAmount @@ -1322,7 +1322,7 @@ fn should_not_quote_with_small_amount() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(0.000001).into()), + QuoteAmount::with_desired_output(balance!(0.000001)), true ), E::InvalidOrderAmount @@ -1333,7 +1333,7 @@ fn should_not_quote_with_small_amount() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(0).into()), + QuoteAmount::with_desired_output(balance!(0)), true ), E::InvalidOrderAmount @@ -1346,8 +1346,8 @@ fn should_not_quote_if_amount_is_greater_than_liquidity() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_and_fill_order_book::(order_book_id); @@ -1357,7 +1357,7 @@ fn should_not_quote_if_amount_is_greater_than_liquidity() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(1000).into()), + QuoteAmount::with_desired_output(balance!(1000)), true ), E::NotEnoughLiquidityInOrderBook @@ -1368,7 +1368,7 @@ fn should_not_quote_if_amount_is_greater_than_liquidity() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(10000).into()), + QuoteAmount::with_desired_output(balance!(10000)), true ), E::NotEnoughLiquidityInOrderBook @@ -1381,8 +1381,8 @@ fn should_quote_without_impact() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_and_fill_order_book::(order_book_id); @@ -1393,11 +1393,11 @@ fn should_quote_without_impact() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_input(balance!(3000).into()), + QuoteAmount::with_desired_input(balance!(3000)), false ) .unwrap(), - SwapOutcome::new(balance!(272.72727).into(), 0) + SwapOutcome::new(balance!(272.72727), 0) ); assert_eq!( @@ -1405,11 +1405,11 @@ fn should_quote_without_impact() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), false ) .unwrap(), - SwapOutcome::new(balance!(2200).into(), 0) + SwapOutcome::new(balance!(2200), 0) ); assert_eq!( @@ -1417,11 +1417,11 @@ fn should_quote_without_impact() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_input(balance!(200).into()), + QuoteAmount::with_desired_input(balance!(200)), false ) .unwrap(), - SwapOutcome::new(balance!(2000).into(), 0) + SwapOutcome::new(balance!(2000), 0) ); assert_eq!( @@ -1429,11 +1429,11 @@ fn should_quote_without_impact() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), false ) .unwrap(), - SwapOutcome::new(balance!(250).into(), 0) + SwapOutcome::new(balance!(250), 0) ); // with fee @@ -1442,11 +1442,11 @@ fn should_quote_without_impact() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_input(balance!(3000).into()), + QuoteAmount::with_desired_input(balance!(3000)), true ) .unwrap(), - SwapOutcome::new(balance!(272.72727).into(), 0) + SwapOutcome::new(balance!(272.72727), 0) ); assert_eq!( @@ -1454,11 +1454,11 @@ fn should_quote_without_impact() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), true ) .unwrap(), - SwapOutcome::new(balance!(2200).into(), 0) + SwapOutcome::new(balance!(2200), 0) ); assert_eq!( @@ -1466,11 +1466,11 @@ fn should_quote_without_impact() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_input(balance!(200).into()), + QuoteAmount::with_desired_input(balance!(200)), true ) .unwrap(), - SwapOutcome::new(balance!(2000).into(), 0) + SwapOutcome::new(balance!(2000), 0) ); assert_eq!( @@ -1478,11 +1478,11 @@ fn should_quote_without_impact() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), true ) .unwrap(), - SwapOutcome::new(balance!(250).into(), 0) + SwapOutcome::new(balance!(250), 0) ); }); } @@ -1495,7 +1495,7 @@ fn should_not_quote_without_impact_with_non_existed_order_book() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), true ), E::UnknownOrderBook @@ -1506,7 +1506,7 @@ fn should_not_quote_without_impact_with_non_existed_order_book() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), true ), E::UnknownOrderBook @@ -1519,8 +1519,8 @@ fn should_not_quote_without_impact_with_empty_side() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_empty_order_book::(order_book_id); @@ -1530,7 +1530,7 @@ fn should_not_quote_without_impact_with_empty_side() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(200).into()), + QuoteAmount::with_desired_output(balance!(200)), true ), E::NotEnoughLiquidityInOrderBook @@ -1541,7 +1541,7 @@ fn should_not_quote_without_impact_with_empty_side() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(2500).into()), + QuoteAmount::with_desired_output(balance!(2500)), true ), E::NotEnoughLiquidityInOrderBook @@ -1554,8 +1554,8 @@ fn should_not_quote_without_impact_with_small_amount() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_and_fill_order_book::(order_book_id); @@ -1565,7 +1565,7 @@ fn should_not_quote_without_impact_with_small_amount() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(0.000001).into()), + QuoteAmount::with_desired_output(balance!(0.000001)), true ), E::InvalidOrderAmount @@ -1576,7 +1576,7 @@ fn should_not_quote_without_impact_with_small_amount() { &DEX.into(), &XOR, &VAL, - QuoteAmount::with_desired_output(balance!(0).into()), + QuoteAmount::with_desired_output(balance!(0)), true ), E::InvalidOrderAmount @@ -1587,7 +1587,7 @@ fn should_not_quote_without_impact_with_small_amount() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(0.000001).into()), + QuoteAmount::with_desired_output(balance!(0.000001)), true ), E::InvalidOrderAmount @@ -1598,7 +1598,7 @@ fn should_not_quote_without_impact_with_small_amount() { &DEX.into(), &VAL, &XOR, - QuoteAmount::with_desired_output(balance!(0).into()), + QuoteAmount::with_desired_output(balance!(0)), true ), E::InvalidOrderAmount @@ -1611,8 +1611,8 @@ fn should_exchange_and_transfer_to_owner() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_and_fill_order_book::(order_book_id); @@ -1631,11 +1631,11 @@ fn should_exchange_and_transfer_to_owner() { &DEX.into(), &XOR, &VAL, - SwapAmount::with_desired_output(balance!(200).into(), balance!(2500).into()), + SwapAmount::with_desired_output(balance!(200), balance!(2500)), ) .unwrap() .0, - SwapOutcome::new(balance!(2204.74).into(), 0) + SwapOutcome::new(balance!(2204.74), 0) ); assert_eq!( @@ -1660,11 +1660,11 @@ fn should_exchange_and_transfer_to_owner() { &DEX.into(), &XOR, &VAL, - SwapAmount::with_desired_input(balance!(2000).into(), balance!(150).into()), + SwapAmount::with_desired_input(balance!(2000), balance!(150)), ) .unwrap() .0, - SwapOutcome::new(balance!(177.95391).into(), 0) + SwapOutcome::new(balance!(177.95391), 0) ); assert_eq!( @@ -1689,11 +1689,11 @@ fn should_exchange_and_transfer_to_owner() { &DEX.into(), &VAL, &XOR, - SwapAmount::with_desired_output(balance!(2000).into(), balance!(210).into()), + SwapAmount::with_desired_output(balance!(2000), balance!(210)), ) .unwrap() .0, - SwapOutcome::new(balance!(200.64285).into(), 0) + SwapOutcome::new(balance!(200.64285), 0) ); assert_eq!( @@ -1718,11 +1718,11 @@ fn should_exchange_and_transfer_to_owner() { &DEX.into(), &VAL, &XOR, - SwapAmount::with_desired_input(balance!(200).into(), balance!(210).into()), + SwapAmount::with_desired_input(balance!(200), balance!(210)), ) .unwrap() .0, - SwapOutcome::new(balance!(1932.327145).into(), 0) + SwapOutcome::new(balance!(1932.327145), 0) ); assert_eq!( @@ -1741,8 +1741,8 @@ fn should_exchange_and_transfer_to_another_account() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_and_fill_order_book::(order_book_id); @@ -1766,11 +1766,11 @@ fn should_exchange_and_transfer_to_another_account() { &DEX.into(), &XOR, &VAL, - SwapAmount::with_desired_output(balance!(200).into(), balance!(2500).into()), + SwapAmount::with_desired_output(balance!(200), balance!(2500)), ) .unwrap() .0, - SwapOutcome::new(balance!(2204.74).into(), 0) + SwapOutcome::new(balance!(2204.74), 0) ); assert_eq!( @@ -1809,11 +1809,11 @@ fn should_exchange_and_transfer_to_another_account() { &DEX.into(), &XOR, &VAL, - SwapAmount::with_desired_input(balance!(2000).into(), balance!(150).into()), + SwapAmount::with_desired_input(balance!(2000), balance!(150)), ) .unwrap() .0, - SwapOutcome::new(balance!(177.95391).into(), 0) + SwapOutcome::new(balance!(177.95391), 0) ); assert_eq!( @@ -1852,11 +1852,11 @@ fn should_exchange_and_transfer_to_another_account() { &DEX.into(), &VAL, &XOR, - SwapAmount::with_desired_output(balance!(2000).into(), balance!(210).into()), + SwapAmount::with_desired_output(balance!(2000), balance!(210)), ) .unwrap() .0, - SwapOutcome::new(balance!(200.64285).into(), 0) + SwapOutcome::new(balance!(200.64285), 0) ); assert_eq!( @@ -1895,11 +1895,11 @@ fn should_exchange_and_transfer_to_another_account() { &DEX.into(), &VAL, &XOR, - SwapAmount::with_desired_input(balance!(200).into(), balance!(210).into()), + SwapAmount::with_desired_input(balance!(200), balance!(210)), ) .unwrap() .0, - SwapOutcome::new(balance!(1932.327145).into(), 0) + SwapOutcome::new(balance!(1932.327145), 0) ); assert_eq!( @@ -1932,7 +1932,7 @@ fn should_not_exchange_with_non_existed_order_book() { &DEX.into(), &XOR, &VAL, - SwapAmount::with_desired_output(balance!(200).into(), balance!(1800).into()), + SwapAmount::with_desired_output(balance!(200), balance!(1800)), ), E::UnknownOrderBook ); @@ -1944,7 +1944,7 @@ fn should_not_exchange_with_non_existed_order_book() { &DEX.into(), &VAL, &XOR, - SwapAmount::with_desired_output(balance!(2500).into(), balance!(200).into()), + SwapAmount::with_desired_output(balance!(2500), balance!(200)), ), E::UnknownOrderBook ); @@ -1956,8 +1956,8 @@ fn should_not_exchange_with_invalid_slippage() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let _ = create_and_fill_order_book::(order_book_id); @@ -1970,7 +1970,7 @@ fn should_not_exchange_with_invalid_slippage() { &DEX.into(), &XOR, &VAL, - SwapAmount::with_desired_output(balance!(200).into(), balance!(1800).into()), + SwapAmount::with_desired_output(balance!(200), balance!(1800)), ), E::SlippageLimitExceeded ); @@ -1982,7 +1982,7 @@ fn should_not_exchange_with_invalid_slippage() { &DEX.into(), &XOR, &VAL, - SwapAmount::with_desired_input(balance!(2000).into(), balance!(210).into()), + SwapAmount::with_desired_input(balance!(2000), balance!(210)), ), E::SlippageLimitExceeded ); @@ -1994,7 +1994,7 @@ fn should_not_exchange_with_invalid_slippage() { &DEX.into(), &VAL, &XOR, - SwapAmount::with_desired_output(balance!(2000).into(), balance!(180).into()), + SwapAmount::with_desired_output(balance!(2000), balance!(180)), ), E::SlippageLimitExceeded ); @@ -2006,7 +2006,7 @@ fn should_not_exchange_with_invalid_slippage() { &DEX.into(), &VAL, &XOR, - SwapAmount::with_desired_input(balance!(200).into(), balance!(2100).into()), + SwapAmount::with_desired_input(balance!(200), balance!(2100)), ), E::SlippageLimitExceeded ); diff --git a/pallets/order-book/src/tests/types.rs b/pallets/order-book/src/tests/types.rs index 95290ca8f6..140ecd8278 100644 --- a/pallets/order-book/src/tests/types.rs +++ b/pallets/order-book/src/tests/types.rs @@ -75,8 +75,8 @@ fn check_order_amount() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; assert_eq!(*base.associated_asset(&order_book_id), VAL); @@ -320,14 +320,14 @@ fn check_deal_info_amounts() { fn should_fail_payment_merge() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let other_order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: DAI.into(), - quote: XOR.into(), + base: DAI, + quote: XOR, }; assert_eq!( @@ -361,8 +361,8 @@ fn should_fail_payment_merge() { fn check_payment_merge() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let origin = Payment { @@ -660,8 +660,8 @@ fn check_payment_execute_all() { ext().execute_with(|| { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; OrderBookPallet::register_tech_account(order_book_id).unwrap(); @@ -755,8 +755,8 @@ fn check_payment_execute_all() { fn should_fail_market_change_merge() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let payment = Payment { @@ -893,7 +893,7 @@ fn should_fail_market_change_merge() { diff_market_input.market_input = Some(OrderAmount::Quote(balance!(50).into())); assert_eq!(market_change.merge(diff_market_input), None); - let mut diff_market_output = origin.clone(); + let mut diff_market_output = origin; diff_market_output.market_output = Some(OrderAmount::Base(balance!(50).into())); assert_eq!(market_change.merge(diff_market_output), None); } @@ -902,8 +902,8 @@ fn should_fail_market_change_merge() { fn check_market_change_merge() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let payment = Payment { @@ -1206,7 +1206,7 @@ fn check_market_change_merge() { (order_id1, order1_origin.clone()), (order_id2, order2_origin.clone()), (order_id3, order3_origin.clone()), - (order_id4, order4_origin.clone()), + (order_id4, order4_origin), (order_id5, order5_origin.clone()), ]), payment: payment.clone(), @@ -1318,16 +1318,16 @@ fn check_market_change_merge() { (order_id5, order5_origin.clone()), ]), to_cancel: BTreeMap::from([ - (order_id1, (order1_origin.clone(), CancelReason::Manual)), + (order_id1, (order1_origin, CancelReason::Manual)), (order_id2, (order2_origin.clone(), CancelReason::Manual)), (order_id3, (order3_origin.clone(), CancelReason::Manual)), (order_id5, (order5_origin.clone(), CancelReason::Manual)), ]), to_force_update: BTreeMap::from([ (order_id1, order1_other.clone()), - (order_id2, order2_origin.clone()), - (order_id3, order3_origin.clone()), - (order_id5, order5_origin.clone()), + (order_id2, order2_origin), + (order_id3, order3_origin), + (order_id5, order5_origin), ]), payment: payment.clone(), ignore_unschedule_error: false @@ -1434,11 +1434,11 @@ fn check_market_change_merge() { (order_id3, (order3_other.clone(), CancelReason::Manual)), ]), to_force_update: BTreeMap::from([ - (order_id1, order1_other.clone()), - (order_id2, order2_other.clone()), - (order_id3, order3_other.clone()), + (order_id1, order1_other), + (order_id2, order2_other), + (order_id3, order3_other), ]), - payment: payment.clone(), + payment: payment, ignore_unschedule_error: false } ); @@ -1453,7 +1453,7 @@ fn check_market_change_merge() { to_full_execute: BTreeMap::new(), to_cancel: BTreeMap::new(), to_force_update: BTreeMap::new(), - payment: empty_payment.clone(), + payment: empty_payment, ignore_unschedule_error: false, }; @@ -1466,8 +1466,8 @@ fn check_market_change_merge() { fn check_market_change_count_of_executed_orders() { let order_book_id = OrderBookId::, DEXId> { dex_id: DEX.into(), - base: VAL.into(), - quote: XOR.into(), + base: VAL, + quote: XOR, }; let empty_payment = @@ -1714,7 +1714,7 @@ fn check_market_change_count_of_executed_orders() { (LimitOrder::, CancelReason), >::new(), to_force_update: BTreeMap::<::OrderId, LimitOrder::>::new(), - payment: empty_payment.clone(), + payment: empty_payment, ignore_unschedule_error: false, } .count_of_executed_orders(), From ecf596b2ede1066bd32b0b9e0d0d183343345614 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Mon, 11 Dec 2023 15:06:29 +0300 Subject: [PATCH 08/10] order-book tests Signed-off-by: Mikhail Tagirov --- pallets/order-book/src/tests/extrinsics.rs | 230 ++++++++++----------- pallets/order-book/src/tests/pallet.rs | 8 +- pallets/order-book/src/tests/types.rs | 2 +- 3 files changed, 120 insertions(+), 120 deletions(-) diff --git a/pallets/order-book/src/tests/extrinsics.rs b/pallets/order-book/src/tests/extrinsics.rs index 70c8a7adb5..fde2a166b8 100644 --- a/pallets/order-book/src/tests/extrinsics.rs +++ b/pallets/order-book/src/tests/extrinsics.rs @@ -1901,7 +1901,7 @@ fn should_place_limit_order() { Timestamp::set_timestamp(now); // fix state before - let bids_before = OrderBookPallet::bids(order_book_id, &price).unwrap_or_default(); + let bids_before = OrderBookPallet::bids(order_book_id, price).unwrap_or_default(); let agg_bids_before = OrderBookPallet::aggregated_bids(order_book_id); let price_volume_before = agg_bids_before.get(&price).cloned().unwrap_or_default(); let user_orders_before = @@ -1944,7 +1944,7 @@ fn should_place_limit_order() { let mut expected_bids = bids_before; assert_ok!(expected_bids.try_push(order_id)); assert_eq!( - OrderBookPallet::bids(order_book_id, &price).unwrap(), + OrderBookPallet::bids(order_book_id, price).unwrap(), expected_bids ); @@ -2053,7 +2053,7 @@ fn should_place_limit_order_with_nft() { ); assert_eq!( - OrderBookPallet::asks(order_book_id, &price).unwrap(), + OrderBookPallet::asks(order_book_id, price).unwrap(), vec![order_id] ); assert_eq!( @@ -2100,28 +2100,28 @@ fn should_place_limit_order_out_of_spread() { // check state before assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -2155,28 +2155,28 @@ fn should_place_limit_order_out_of_spread() { // check state assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -2212,29 +2212,29 @@ fn should_place_limit_order_out_of_spread() { let buy_order_id2 = get_last_order_id::(order_book_id).unwrap(); assert_eq!( - OrderBookPallet::bids(order_book_id, &new_bid_price).unwrap(), + OrderBookPallet::bids(order_book_id, new_bid_price).unwrap(), vec![buy_order_id2] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price1), None); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -2275,25 +2275,25 @@ fn should_place_limit_order_out_of_spread() { // check state assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price1), None); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -2327,27 +2327,27 @@ fn should_place_limit_order_out_of_spread() { let sell_order_id2 = get_last_order_id::(order_book_id).unwrap(); - assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id, bid_price1), None); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &new_ask_price).unwrap(), + OrderBookPallet::asks(order_book_id, new_ask_price).unwrap(), vec![sell_order_id2] ); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price1), None); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -2397,28 +2397,28 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { // check state before assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -2453,25 +2453,25 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { // check state assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price1), None); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -2504,21 +2504,21 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { // check state assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price2), None); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price3), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price2), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price3), None); assert_eq!( OrderBookPallet::aggregated_bids(order_book_id), @@ -2545,19 +2545,19 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { )); // check state - assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id, bid_price1), None); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id, bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price2), None); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price3), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price2), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price3), None); assert_eq!( OrderBookPallet::aggregated_bids(order_book_id), @@ -2583,13 +2583,13 @@ fn should_place_limit_order_out_of_spread_with_small_remaining_amount() { )); // check state - assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price1), None); - assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price2), None); - assert_eq!(OrderBookPallet::bids(order_book_id, &bid_price3), None); + assert_eq!(OrderBookPallet::bids(order_book_id, bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id, bid_price2), None); + assert_eq!(OrderBookPallet::bids(order_book_id, bid_price3), None); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price1), None); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price2), None); - assert_eq!(OrderBookPallet::asks(order_book_id, &ask_price3), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price2), None); + assert_eq!(OrderBookPallet::asks(order_book_id, ask_price3), None); assert_eq!( OrderBookPallet::aggregated_bids(order_book_id), @@ -2727,7 +2727,7 @@ fn should_cancel_limit_order() { let order = OrderBookPallet::limit_orders(order_book_id, order_id).unwrap(); // fix state before - let bids_before = OrderBookPallet::bids(order_book_id, &order.price).unwrap_or_default(); + let bids_before = OrderBookPallet::bids(order_book_id, order.price).unwrap_or_default(); let agg_bids_before = OrderBookPallet::aggregated_bids(order_book_id); let price_volume_before = agg_bids_before .get(&order.price) @@ -2750,7 +2750,7 @@ fn should_cancel_limit_order() { let mut expected_bids = bids_before; expected_bids.retain(|&id| id != order.id); assert_eq!( - OrderBookPallet::bids(order_book_id, &order.price).unwrap(), + OrderBookPallet::bids(order_book_id, order.price).unwrap(), expected_bids ); @@ -2938,55 +2938,55 @@ fn should_cancel_all_user_limit_orders_batch() { // order book 1 assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price3).unwrap(), vec![10, 11, 12] ); // order book 2 assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -3005,44 +3005,44 @@ fn should_cancel_all_user_limit_orders_batch() { // check state after // order book 1 - assert_eq!(OrderBookPallet::bids(order_book_id1, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id1, bid_price1), None); assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price2).unwrap(), vec![2] ); assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price3).unwrap(), vec![4, 6] ); - assert_eq!(OrderBookPallet::asks(order_book_id1, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id1, ask_price1), None); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price2).unwrap(), vec![8] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price3).unwrap(), vec![10, 12] ); // order book 2 - assert_eq!(OrderBookPallet::bids(order_book_id2, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id2, bid_price1), None); assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price2).unwrap(), vec![2] ); assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price3).unwrap(), vec![4, 6] ); - assert_eq!(OrderBookPallet::asks(order_book_id2, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id2, ask_price1), None); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price2).unwrap(), vec![8] ); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price3).unwrap(), vec![10, 12] ); }); @@ -3079,55 +3079,55 @@ fn should_cancel_part_of_all_user_limit_orders_batch() { // order book 1 assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price3).unwrap(), vec![10, 11, 12] ); // order book 2 assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price3).unwrap(), vec![4, 5, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price3).unwrap(), vec![10, 11, 12] ); @@ -3146,50 +3146,50 @@ fn should_cancel_part_of_all_user_limit_orders_batch() { // check state after // order book 1 - assert_eq!(OrderBookPallet::bids(order_book_id1, &bid_price1), None); + assert_eq!(OrderBookPallet::bids(order_book_id1, bid_price1), None); assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price2).unwrap(), vec![2, 3] ); assert_eq!( - OrderBookPallet::bids(order_book_id1, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id1, bid_price3).unwrap(), vec![4, 6] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price1).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price1).unwrap(), vec![7] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price2).unwrap(), vec![8] ); assert_eq!( - OrderBookPallet::asks(order_book_id1, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id1, ask_price3).unwrap(), vec![10, 11, 12] ); // order book 2 assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price1).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price1).unwrap(), vec![1] ); assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price2).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price2).unwrap(), vec![2] ); assert_eq!( - OrderBookPallet::bids(order_book_id2, &bid_price3).unwrap(), + OrderBookPallet::bids(order_book_id2, bid_price3).unwrap(), vec![4, 5, 6] ); - assert_eq!(OrderBookPallet::asks(order_book_id2, &ask_price1), None); + assert_eq!(OrderBookPallet::asks(order_book_id2, ask_price1), None); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price2).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price2).unwrap(), vec![8, 9] ); assert_eq!( - OrderBookPallet::asks(order_book_id2, &ask_price3).unwrap(), + OrderBookPallet::asks(order_book_id2, ask_price3).unwrap(), vec![10, 12] ); }); diff --git a/pallets/order-book/src/tests/pallet.rs b/pallets/order-book/src/tests/pallet.rs index 2c37ad4f75..8a6393c9f0 100644 --- a/pallets/order-book/src/tests/pallet.rs +++ b/pallets/order-book/src/tests/pallet.rs @@ -690,7 +690,7 @@ fn should_cleanup_on_expiring() { pallet_timestamp::Pallet::::set_timestamp(now); // fix state before - let bids_before = OrderBookPallet::bids(order_book_id, &price).unwrap_or_default(); + let bids_before = OrderBookPallet::bids(order_book_id, price).unwrap_or_default(); let agg_bids_before = OrderBookPallet::aggregated_bids(order_book_id); let price_volume_before = agg_bids_before.get(&price).cloned().unwrap_or_default(); let user_orders_before = @@ -735,7 +735,7 @@ fn should_cleanup_on_expiring() { let mut bids_with_order = bids_before.clone(); assert_ok!(bids_with_order.try_push(order_id)); assert_eq!( - OrderBookPallet::bids(order_book_id, &price).unwrap(), + OrderBookPallet::bids(order_book_id, price).unwrap(), bids_with_order ); @@ -769,7 +769,7 @@ fn should_cleanup_on_expiring() { expected_order ); assert_eq!( - OrderBookPallet::bids(order_book_id, &price).unwrap(), + OrderBookPallet::bids(order_book_id, price).unwrap(), bids_with_order ); assert_eq!( @@ -792,7 +792,7 @@ fn should_cleanup_on_expiring() { // The order is removed, state returned to original assert!(OrderBookPallet::limit_orders(order_book_id, order_id).is_none()); assert_eq!( - OrderBookPallet::bids(order_book_id, &price).unwrap_or_default(), + OrderBookPallet::bids(order_book_id, price).unwrap_or_default(), bids_before ); assert_eq!( diff --git a/pallets/order-book/src/tests/types.rs b/pallets/order-book/src/tests/types.rs index 140ecd8278..65f25bb6f6 100644 --- a/pallets/order-book/src/tests/types.rs +++ b/pallets/order-book/src/tests/types.rs @@ -1438,7 +1438,7 @@ fn check_market_change_merge() { (order_id2, order2_other), (order_id3, order3_other), ]), - payment: payment, + payment, ignore_unschedule_error: false } ); From 12821a004dd95ef06e8eaba441f04e35bc00f2c2 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Mon, 11 Dec 2023 15:15:32 +0300 Subject: [PATCH 09/10] qa-tools tests Signed-off-by: Mikhail Tagirov --- pallets/qa-tools/src/tests.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pallets/qa-tools/src/tests.rs b/pallets/qa-tools/src/tests.rs index 4ba7f47539..5610cbc82e 100644 --- a/pallets/qa-tools/src/tests.rs +++ b/pallets/qa-tools/src/tests.rs @@ -124,7 +124,7 @@ fn test_creates_orderbook( price_step, orders_per_price, lifespan: None, - amount_range_inclusive: Some(amount_range.clone()) + amount_range_inclusive: Some(amount_range) }), asks: Some(settings::SideFill { highest_price: best_ask_price + (steps - 1) as u128 * price_step, @@ -132,7 +132,7 @@ fn test_creates_orderbook( price_step, orders_per_price, lifespan: None, - amount_range_inclusive: Some(amount_range.clone()) + amount_range_inclusive: Some(amount_range) }), random_seed: None, } @@ -275,7 +275,7 @@ fn should_respect_orderbook_seed() { price_step, orders_per_price, lifespan: None, - amount_range_inclusive: Some(amount_range.clone()), + amount_range_inclusive: Some(amount_range), }), asks: Some(settings::SideFill { highest_price: best_ask_price + (steps - 1) as u128 * price_step, @@ -309,9 +309,7 @@ fn should_respect_orderbook_seed() { let mut limit_orders_1 = data.get_all_limit_orders(&order_book_id_1); let mut limit_orders_2 = data.get_all_limit_orders(&order_book_id_2); fn cmp_by_id(a: &LimitOrder, b: &LimitOrder) -> sp_std::cmp::Ordering { - let a = u128::try_from(a.id).unwrap(); - let b = u128::try_from(b.id).unwrap(); - a.cmp(&b) + a.id.cmp(&b.id) } limit_orders_1.sort_by(cmp_by_id); limit_orders_2.sort_by(cmp_by_id); @@ -346,7 +344,7 @@ fn should_keep_orderbook_randomness_independent() { price_step, orders_per_price, lifespan: None, - amount_range_inclusive: Some(amount_range.clone()), + amount_range_inclusive: Some(amount_range), }), asks: Some(settings::SideFill { highest_price: best_ask_price + (steps - 1) as u128 * price_step, @@ -392,9 +390,7 @@ fn should_keep_orderbook_randomness_independent() { .filter(|order| order.side == PriceVariant::Sell) .collect(); fn cmp_by_id(a: &LimitOrder, b: &LimitOrder) -> sp_std::cmp::Ordering { - let a = u128::try_from(a.id).unwrap(); - let b = u128::try_from(b.id).unwrap(); - a.cmp(&b) + a.id.cmp(&b.id) } asks_1.sort_by(cmp_by_id); asks_2.sort_by(cmp_by_id); From 358643c8c097ef02cc5e96b41e7ec555e0c96be7 Mon Sep 17 00:00:00 2001 From: Mikhail Tagirov Date: Mon, 11 Dec 2023 16:01:17 +0300 Subject: [PATCH 10/10] fix Signed-off-by: Mikhail Tagirov --- common/src/traits.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/common/src/traits.rs b/common/src/traits.rs index 3aa67897d4..a887bd69e4 100644 --- a/common/src/traits.rs +++ b/common/src/traits.rs @@ -317,9 +317,7 @@ pub trait OnSymbolDisabled { } impl OnSymbolDisabled for () { - fn disable_symbol(_symbol: &Symbol) { - unimplemented!() - } + fn disable_symbol(_symbol: &Symbol) {} } impl LiquiditySource