From cb1753274ef771e36ba49a73103add038d2e4832 Mon Sep 17 00:00:00 2001 From: nuno Date: Fri, 29 Sep 2023 16:43:15 +0200 Subject: [PATCH] Fix order-book with Reason = () --- pallets/order-book/src/lib.rs | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/pallets/order-book/src/lib.rs b/pallets/order-book/src/lib.rs index 3ae915559e..0d1fb09aff 100644 --- a/pallets/order-book/src/lib.rs +++ b/pallets/order-book/src/lib.rs @@ -77,8 +77,6 @@ pub mod pallet { >; pub type BalanceOf = ::Balance; - type ReasonOf = ::AccountId>>::Reason; - /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); @@ -134,7 +132,7 @@ pub mod pallet { /// Type for currency orders can be made for type TradeableAsset: AssetInspect - + InspectHold + + InspectHold + MutateHold + Mutate; @@ -408,7 +406,6 @@ pub mod pallet { order_id: T::OrderIdNonce, buy_amount: T::Balance, price: T::SellRatio, - reason: ReasonOf, ) -> DispatchResult { let account_id = ensure_signed(origin)?; Self::inner_update_order( @@ -434,7 +431,6 @@ pub mod pallet { min_amount, ) }, - reason, ) } @@ -462,12 +458,12 @@ pub mod pallet { /// Fill an existing order, fulfilling the entire order. #[pallet::call_index(3)] #[pallet::weight(T::Weights::fill_order_full())] - pub fn fill_order_full(origin: OriginFor, order_id: T::OrderIdNonce, reason: ReasonOf) -> DispatchResult { + pub fn fill_order_full(origin: OriginFor, order_id: T::OrderIdNonce) -> DispatchResult { let account_id = ensure_signed(origin)?; let order = >::get(order_id)?; let buy_amount = order.buy_amount; - Self::fulfill_order_with_amount(order, buy_amount, account_id, reason) + Self::fulfill_order_with_amount(order, buy_amount, account_id) } /// Adds a valid trading pair. @@ -555,12 +551,12 @@ pub mod pallet { origin: OriginFor, order_id: T::OrderIdNonce, buy_amount: T::Balance, - reason: ReasonOf, + ) -> DispatchResult { let account_id = ensure_signed(origin)?; let order = >::get(order_id)?; - Self::fulfill_order_with_amount(order, buy_amount, account_id, reason) + Self::fulfill_order_with_amount(order, buy_amount, account_id) } } @@ -569,7 +565,7 @@ pub mod pallet { order: OrderOf, buy_amount: T::Balance, account_id: T::AccountId, - reason: ReasonOf, + ) -> DispatchResult { ensure!( buy_amount >= order.min_fulfillment_amount, @@ -577,7 +573,7 @@ pub mod pallet { ); ensure!( - T::TradeableAsset::can_hold(order.asset_in_id, &reason, &account_id, buy_amount), + T::TradeableAsset::can_hold(order.asset_in_id, &(), &account_id, buy_amount), Error::::InsufficientAssetFunds, ); @@ -604,7 +600,7 @@ pub mod pallet { } else { T::TradeableAsset::release( order.asset_out_id, - &reason, + &(), &order.placing_account, sell_amount, Precision::Exact, @@ -664,10 +660,10 @@ pub mod pallet { /// Unreserve funds for an order that is finished either /// through fulfillment or cancellation. - pub fn unreserve_order(order: &OrderOf, reason: ReasonOf) -> Result, DispatchError> { + pub fn unreserve_order(order: &OrderOf) -> Result, DispatchError> { T::TradeableAsset::release( order.asset_out_id, - &reason, + &(), &order.placing_account, order.max_sell_amount, Precision::Exact, @@ -751,7 +747,7 @@ pub mod pallet { sell_rate_limit: T::SellRatio, min_fulfillment_amount: T::Balance, validate: impl FnOnce(&OrderOf) -> DispatchResult, - reason: ReasonOf, + ) -> DispatchResult { let max_sell_amount = >::try_mutate_exists( order_id, @@ -774,7 +770,7 @@ pub mod pallet { max_sell_amount.ensure_sub(order.max_sell_amount)?; T::TradeableAsset::hold( order.asset_out_id, - &reason, + &(), &account, sell_reserve_diff, )?; @@ -783,7 +779,7 @@ pub mod pallet { order.max_sell_amount.ensure_sub(max_sell_amount)?; T::TradeableAsset::release( order.asset_out_id, - &reason, + &(), &account, sell_reserve_diff, Precision::Exact, @@ -841,7 +837,7 @@ pub mod pallet { let max_sell_amount = Self::convert_with_ratio(currency_in, currency_out, sell_rate_limit, buy_amount)?; - T::TradeableAsset::hold(currency_out, &account, max_sell_amount)?; + T::TradeableAsset::hold(currency_out, &(), &account, max_sell_amount)?; let order_id = >::get(); let new_order = Order { @@ -950,7 +946,7 @@ pub mod pallet { buy_amount: T::Balance, sell_rate_limit: T::SellRatio, min_fulfillment_amount: T::Balance, - reason: ReasonOf, + ) -> DispatchResult { Self::inner_update_order( account, @@ -972,7 +968,6 @@ pub mod pallet { T::Balance::zero(), ) }, - reason, ) }