2
2
use crate :: {
3
3
error:: DexError ,
4
4
state:: { CallBackInfo , DexState , FeeTier , Order , UserAccount } ,
5
+ utils:: check_account_owner,
5
6
utils:: { check_account_key, check_signer} ,
6
- utils:: { check_account_owner, fp32_mul} ,
7
7
} ;
8
8
use agnostic_orderbook:: error:: AoError ;
9
9
use agnostic_orderbook:: state:: Side ;
@@ -235,8 +235,6 @@ pub(crate) fn process(
235
235
let mut user_account_data = accounts. user . data . borrow_mut ( ) ;
236
236
let mut user_account = accounts. load_user_account ( & mut user_account_data) ?;
237
237
238
- let max_base_qty_scaled = max_base_qty / market_state. base_currency_multiplier ;
239
-
240
238
// Check the order size
241
239
if max_base_qty < & market_state. min_base_order_size {
242
240
msg ! ( "The base order size is too small." ) ;
@@ -262,11 +260,10 @@ pub(crate) fn process(
262
260
// We make sure to leave enough quote quantity to pay for taker fees in the worst case
263
261
max_quote_qty = fee_tier. remove_taker_fee ( max_quote_qty) ;
264
262
}
265
- let max_quote_qty_scaled = max_quote_qty / market_state. quote_currency_multiplier ;
266
263
267
264
let invoke_params = agnostic_orderbook:: instruction:: new_order:: Params {
268
- max_base_qty : max_base_qty_scaled ,
269
- max_quote_qty : max_quote_qty_scaled ,
265
+ max_base_qty : market_state . scale_base_amount ( * max_base_qty ) ,
266
+ max_quote_qty : market_state . scale_quote_amount ( max_quote_qty ) ,
270
267
limit_price : * limit_price,
271
268
side : FromPrimitive :: from_u8 ( * side) . unwrap ( ) ,
272
269
match_limit : * match_limit,
@@ -294,25 +291,18 @@ pub(crate) fn process(
294
291
Ok ( s) => s,
295
292
} ;
296
293
297
- order_summary. total_base_qty = order_summary
298
- . total_base_qty
299
- . checked_mul ( market_state. base_currency_multiplier )
300
- . unwrap ( ) ;
301
- order_summary. total_base_qty_posted = order_summary
302
- . total_base_qty_posted
303
- . checked_mul ( market_state. base_currency_multiplier )
294
+ market_state
295
+ . unscale_order_summary ( & mut order_summary)
304
296
. unwrap ( ) ;
305
- order_summary . total_quote_qty = order_summary
306
- . total_quote_qty
307
- . checked_mul ( market_state . quote_currency_multiplier )
297
+
298
+ let posted_quote_qty = market_state
299
+ . get_quote_from_base ( order_summary . total_base_qty_posted , * limit_price )
308
300
. unwrap ( ) ;
309
301
310
302
let ( qty_to_transfer, transfer_destination, referral_fee) =
311
303
match FromPrimitive :: from_u8 ( * side) . unwrap ( ) {
312
304
Side :: Bid => {
313
305
// We update the order summary to properly handle the FOK order type
314
- let posted_quote_qty =
315
- fp32_mul ( order_summary. total_base_qty_posted , * limit_price) . unwrap ( ) ;
316
306
let matched_quote_qty = order_summary. total_quote_qty - posted_quote_qty;
317
307
let taker_fee = fee_tier. taker_fee ( matched_quote_qty) ;
318
308
let royalties_fees = matched_quote_qty
@@ -343,8 +333,6 @@ pub(crate) fn process(
343
333
. base_token_free
344
334
. saturating_sub ( order_summary. total_base_qty ) ;
345
335
user_account. header . base_token_locked += order_summary. total_base_qty_posted ;
346
- let posted_quote_qty =
347
- fp32_mul ( order_summary. total_base_qty_posted , * limit_price) . unwrap ( ) ;
348
336
let taken_quote_qty = order_summary. total_quote_qty - posted_quote_qty;
349
337
let taker_fee = fee_tier. taker_fee ( taken_quote_qty) ;
350
338
let royalties_fees = taken_quote_qty
@@ -439,7 +427,7 @@ pub(crate) fn process(
439
427
. saturating_sub ( order_summary. total_base_qty_posted ) ;
440
428
user_account. header . accumulated_taker_quote_volume += order_summary
441
429
. total_quote_qty
442
- . saturating_sub ( fp32_mul ( order_summary . total_base_qty_posted , * limit_price ) . unwrap ( ) ) ;
430
+ . saturating_sub ( posted_quote_qty ) ;
443
431
444
432
Ok ( ( ) )
445
433
}
0 commit comments