added more checked math

This commit is contained in:
dd 2021-04-26 00:59:08 -04:00
parent 55883ef873
commit 2b7e619f48
2 changed files with 5 additions and 4 deletions

View File

@ -1889,7 +1889,7 @@ fn get_in_out_quantities(
liqor_max_in: u64
) -> MangoResult<(u64, u64)> {
let deficit_val = margin_account.get_partial_liq_deficit(&mango_group, &prices, open_orders_accs)? + ONE_U64F64;
let out_avail: U64F64 = margin_account.deposits[out_token_index] * mango_group.indexes[out_token_index].deposit;
let out_avail: U64F64 = margin_account.deposits[out_token_index].checked_mul(mango_group.indexes[out_token_index].deposit).unwrap();
let out_avail_val = out_avail * prices[out_token_index];
// liq incentive is max of 1/2 the dist between
@ -1900,7 +1900,8 @@ fn get_in_out_quantities(
// we know prices are not 0; if they are this will error;
let max_in: U64F64 = max_in_val / prices[in_token_index];
let native_borrow = margin_account.borrows[in_token_index] * mango_group.indexes[in_token_index].borrow;
let native_borrow = margin_account.borrows[in_token_index].checked_mul(
mango_group.indexes[in_token_index].borrow).unwrap();
// Can only deposit as much there is borrows to offset in in_token
let in_quantity = min(min(max_in, native_borrow), U64F64::from_num(liqor_max_in));
@ -1910,7 +1911,7 @@ fn get_in_out_quantities(
checked_sub_borrow(mango_group, margin_account, in_token_index, deposit)?;
// Withdraw incentive funds to liqor
let in_val: U64F64 = in_quantity * prices[in_token_index];
let in_val: U64F64 = in_quantity.checked_mul(prices[in_token_index]).unwrap();
let out_val: U64F64 = in_val * PARTIAL_LIQ_INCENTIVE;
let out_quantity: U64F64 = out_val / prices[out_token_index];

View File

@ -338,7 +338,7 @@ impl MarginAccount {
if liabs == ZERO_U64F64 {
Ok(U64F64::MAX)
} else {
Ok(assets / liabs)
Ok(assets.checked_div( liabs).unwrap())
}
}
pub fn get_total_assets(