@@ -237,18 +237,6 @@ pub mod pallet {
237237 #[ pallet:: storage]
238238 pub type NextPoolAssetId < T : Config > = StorageValue < _ , T :: PoolAssetId , OptionQuery > ;
239239
240- /// Stores the `Hold` assets for limit order
241- #[ pallet:: storage]
242- pub type FrozenAssets < T : Config > = StorageDoubleMap <
243- _ ,
244- Twox64Concat ,
245- T :: AccountId ,
246- Twox64Concat ,
247- T :: AssetKind ,
248- T :: Unit ,
249- OptionQuery ,
250- > ;
251-
252240 // Pallet's events.
253241 #[ pallet:: event]
254242 #[ pallet:: generate_deposit( pub ( super ) fn deposit_event) ]
@@ -530,9 +518,10 @@ pub mod pallet {
530518 T :: PoolAssets :: touch ( lp_token. clone ( ) , & pool_account, & sender) ?
531519 } ;
532520
533- let pool = Pool :: < T > :: new ( lp_token. clone ( ) , taker_fee_rate, tick_size, lot_size) ;
534- Pools :: < T > :: insert ( pool_id. clone ( ) , pool) ;
535-
521+ Pools :: < T > :: insert (
522+ pool_id. clone ( ) ,
523+ Pool :: < T > :: new ( lp_token. clone ( ) , taker_fee_rate, tick_size, lot_size) ,
524+ ) ;
536525 Self :: deposit_event ( Event :: PoolCreated {
537526 creator : sender,
538527 pool_id,
@@ -942,15 +931,11 @@ pub mod pallet {
942931 // quote asset would be released.
943932 let released = if is_bid { q } else { p * q } ;
944933 // 1. Release the frozen asset
945- FrozenAssets :: < T > :: try_mutate (
946- & owner,
934+ T :: AssetsFreezer :: decrease_frozen (
947935 asset1. clone ( ) ,
948- |maybe_balance| -> DispatchResult {
949- let mut new = maybe_balance. take ( ) . ok_or ( Error :: < T > :: NoOps ) ?;
950- new = new. saturating_sub ( released) ;
951- * maybe_balance = Some ( new) ;
952- Ok ( ( ) )
953- } ,
936+ & FreezeReason :: LimitOrder . into ( ) ,
937+ & owner,
938+ released,
954939 ) ?;
955940 // 2. Transfer assets between orderer and owner of limit order
956941 let ( transfer1, transfer2) = if is_bid { ( q, released) } else { ( released, q) } ;
@@ -1294,7 +1279,7 @@ pub mod pallet {
12941279 /// Pool price
12951280 ///
12961281 /// 1 * quote_reserve / base_reserve
1297- pub ( crate ) fn pool_price (
1282+ pub fn pool_price (
12981283 base_asset : & T :: AssetKind ,
12991284 quote_asset : & T :: AssetKind ,
13001285 ) -> Result < T :: Unit , Error < T > > {
@@ -2002,7 +1987,7 @@ pub mod pallet {
20021987sp_api:: decl_runtime_apis! {
20031988 /// This runtime api allows people to query the size of the liquidity pools
20041989 /// and quote prices for swaps.
2005- pub trait AssetConversionApi <Balance , AssetId >
1990+ pub trait HybridOrderbookApi <Balance , AssetId >
20061991 where
20071992 Balance : frame_support:: traits:: tokens:: Balance + MaybeDisplay ,
20081993 AssetId : Codec ,
@@ -2031,6 +2016,9 @@ sp_api::decl_runtime_apis! {
20312016
20322017 /// Returns the size of the liquidity pool for the given asset pair.
20332018 fn get_reserves( asset1: AssetId , asset2: AssetId ) -> Option <( Balance , Balance ) >;
2019+
2020+ /// Returns the price of the given asset pair.
2021+ fn get_pool_price( base: AssetId , quote: AssetId ) -> Option <Balance >;
20342022 }
20352023}
20362024
0 commit comments