diff --git a/state-chain/amm/src/lib.rs b/state-chain/amm/src/lib.rs index 3ebe853331..5938d7239f 100644 --- a/state-chain/amm/src/lib.rs +++ b/state-chain/amm/src/lib.rs @@ -57,6 +57,12 @@ impl PoolState { }) } + /// Returns the Range Order sub-pool's current price. + /// SwapDirection is ignored as the price are the same for both directions. + pub fn current_range_order_pool_price(&mut self) -> SqrtPriceQ64F96 { + self.range_orders.raw_current_sqrt_price() + } + /// Returns the current sqrt price for a given direction of swap. The price is measured in units /// of the specified Pairs argument pub fn current_sqrt_price(&mut self, order: Side) -> Option { diff --git a/state-chain/amm/src/range_orders.rs b/state-chain/amm/src/range_orders.rs index 5ef908da12..9140cff2d7 100644 --- a/state-chain/amm/src/range_orders.rs +++ b/state-chain/amm/src/range_orders.rs @@ -521,6 +521,11 @@ impl PoolState { SD::further_liquidity(self.current_tick).then_some(self.current_sqrt_price) } + /// Returns the raw current sqrt price of the pool, without liquidity checks. + pub(super) fn raw_current_sqrt_price(&self) -> SqrtPriceQ64F96 { + self.current_sqrt_price + } + /// Calculates the fees owed to the specified position, resets the fees owed for that position /// to zero, calls `try_debit` passing the Amounts required to add the `minted_liquidity` to the /// position. If `try_debit` returns `Ok(t)` the position will be created if it didn't already diff --git a/state-chain/pallets/cf-pools/src/lib.rs b/state-chain/pallets/cf-pools/src/lib.rs index 5f6771bb14..954c4a5a73 100644 --- a/state-chain/pallets/cf-pools/src/lib.rs +++ b/state-chain/pallets/cf-pools/src/lib.rs @@ -1193,6 +1193,7 @@ pub struct PoolPriceV1 { pub struct PoolPriceV2 { pub sell: Option, pub buy: Option, + pub range_order: SqrtPriceQ64F96, } impl Pallet { @@ -1558,6 +1559,7 @@ impl Pallet { Ok(PoolPriceV2 { sell: pool.pool_state.current_price(Side::Sell).map(|(_, sqrt_price, _)| sqrt_price), buy: pool.pool_state.current_price(Side::Buy).map(|(_, sqrt_price, _)| sqrt_price), + range_order: pool.pool_state.current_range_order_pool_price(), }) }