From 889c3d817a5b2574c05fbb2da04d3a37dc28146f Mon Sep 17 00:00:00 2001 From: lemunozm Date: Mon, 11 Mar 2024 11:58:33 +0100 Subject: [PATCH] ensure symmetric ratios for orderbook --- pallets/order-book/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pallets/order-book/src/lib.rs b/pallets/order-book/src/lib.rs index 047a9959e4..e296dbf8b8 100644 --- a/pallets/order-book/src/lib.rs +++ b/pallets/order-book/src/lib.rs @@ -644,8 +644,13 @@ pub mod pallet { ) -> Result { let feeder = MarketFeederId::::get()?; - T::RatioProvider::get(&feeder, &(currency_from, currency_to))? - .ok_or(Error::::MarketRatioNotFound.into()) + if currency_to < currency_from { + T::RatioProvider::get(&feeder, &(currency_to, currency_from))? + .map(|ratio| ratio.reciprocal().unwrap_or(Zero::zero())) + } else { + T::RatioProvider::get(&feeder, &(currency_from, currency_to))? + } + .ok_or(Error::::MarketRatioNotFound.into()) } /// `ratio` is the value you multiply `amount_from` to obtain