Skip to content

Commit c3f3523

Browse files
committed
edit decimal adjustment
1 parent 63f5a73 commit c3f3523

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

pallets/hybrid-orderbook/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,15 +1324,15 @@ pub mod pallet {
13241324
quote_decimals_adjustment: Option<u8>,
13251325
) -> Result<T::Unit, Error<T>> {
13261326
let (base_reserve, quote_reserve) = Self::get_reserves(base_asset, quote_asset)?;
1327-
1328-
Ok(
1329-
Self::quote(
1330-
&One::one(),
1331-
&base_reserve.normalize(base_decimals_adjustment),
1332-
&quote_reserve.normalize(quote_decimals_adjustment),
1333-
)?
1334-
.normalize(pool_decimals)
1335-
)
1327+
let base_norm = base_reserve.normalize(base_decimals_adjustment);
1328+
let quote_norm = quote_reserve.normalize(quote_decimals_adjustment);
1329+
let amount: T::Unit = One::one();
1330+
let pool_price = Self::quote(
1331+
&amount.normalize(pool_decimals),
1332+
&base_norm,
1333+
&quote_norm,
1334+
)?;
1335+
Ok(pool_price)
13361336
}
13371337

13381338
/// Find the closest swap quantity for the given order quantity. `order_quantity` is always

pallets/hybrid-orderbook/src/tests.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,45 @@ fn create_pool_works() {
289289
});
290290
}
291291

292+
#[test]
293+
fn pool_price_works() {
294+
new_test_ext().execute_with(|| {
295+
let user: MockAccountId = 1;
296+
let base = NativeOrWithId::WithId(1);
297+
let quote = NativeOrWithId::WithId(2);
298+
let pool_id = (base.clone(), quote.clone());
299+
create_tokens(user, vec![base.clone(), quote.clone()]);
300+
assert_ok!(Balances::force_set_balance(
301+
RuntimeOrigin::root(),
302+
user,
303+
1000
304+
));
305+
assert_ok!(HybridOrderbook::create_pool(
306+
RuntimeOrigin::signed(user),
307+
Box::new(base.clone()),
308+
9,
309+
Box::new(quote.clone()),
310+
6,
311+
Permill::zero(),
312+
5,
313+
1,
314+
2
315+
));
316+
assert_ok!(HybridOrderbook::add_liquidity(
317+
RuntimeOrigin::signed(user),
318+
Box::new(base.clone()),
319+
Box::new(quote.clone()),
320+
10000000 * (10u64.pow(9)),
321+
41500000 * (10u64.pow(6)),
322+
10000000 * (10u64.pow(9)),
323+
41500000 * (10u64.pow(6)),
324+
user,
325+
));
326+
let pool_price = HybridOrderbook::pool_price(&base, None, None, &quote, None).unwrap();
327+
println!("Pool price => {:?}", pool_price);
328+
})
329+
}
330+
292331
#[test]
293332
fn add_liquidity_works() {
294333
new_test_ext().execute_with(|| {

0 commit comments

Comments
 (0)