Return raw position index from get_mut()
This commit is contained in:
parent
0ff269c38c
commit
31831454b4
|
@ -87,8 +87,7 @@ pub fn liq_token_bankruptcy(
|
|||
|
||||
let liab_bank = bank_ais[0].load::<Bank>()?;
|
||||
let liab_deposit_index = liab_bank.deposit_index;
|
||||
let (liqee_liab, liqee_raw_token_index, _) =
|
||||
liqee.tokens.get_mut_or_create(liab_token_index)?;
|
||||
let (liqee_liab, liqee_raw_token_index) = liqee.tokens.get_mut(liab_token_index)?;
|
||||
let mut remaining_liab_loss = -liqee_liab.native(&liab_bank);
|
||||
require_gt!(remaining_liab_loss, I80F48::ZERO);
|
||||
drop(liab_bank);
|
||||
|
|
|
@ -116,7 +116,7 @@ pub fn liq_token_with_token(
|
|||
let asset_transfer = cm!(liab_transfer * liab_price_adjusted / asset_price);
|
||||
|
||||
// Apply the balance changes to the liqor and liqee accounts
|
||||
liab_bank.deposit(liqee.tokens.get_mut(liab_token_index)?, liab_transfer)?;
|
||||
liab_bank.deposit(liqee.tokens.get_mut(liab_token_index)?.0, liab_transfer)?;
|
||||
liab_bank.withdraw_with_fee(
|
||||
liqor.tokens.get_mut_or_create(liab_token_index)?.0,
|
||||
liab_transfer,
|
||||
|
@ -127,7 +127,7 @@ pub fn liq_token_with_token(
|
|||
asset_transfer,
|
||||
)?;
|
||||
asset_bank
|
||||
.withdraw_without_fee(liqee.tokens.get_mut(asset_token_index)?, asset_transfer)?;
|
||||
.withdraw_without_fee(liqee.tokens.get_mut(asset_token_index)?.0, asset_transfer)?;
|
||||
|
||||
// Update the health cache
|
||||
liqee_health_cache.adjust_token_balance(liab_token_index, liab_transfer)?;
|
||||
|
@ -158,6 +158,7 @@ pub fn liq_token_with_token(
|
|||
indexed_position: liqee
|
||||
.tokens
|
||||
.get_mut(asset_token_index)?
|
||||
.0
|
||||
.indexed_position
|
||||
.to_bits(),
|
||||
deposit_index: asset_bank.deposit_index.to_bits(),
|
||||
|
@ -171,6 +172,7 @@ pub fn liq_token_with_token(
|
|||
indexed_position: liqee
|
||||
.tokens
|
||||
.get_mut(liab_token_index)?
|
||||
.0
|
||||
.indexed_position
|
||||
.to_bits(),
|
||||
deposit_index: liab_bank.deposit_index.to_bits(),
|
||||
|
@ -184,6 +186,7 @@ pub fn liq_token_with_token(
|
|||
indexed_position: liqor
|
||||
.tokens
|
||||
.get_mut(asset_token_index)?
|
||||
.0
|
||||
.indexed_position
|
||||
.to_bits(),
|
||||
deposit_index: asset_bank.deposit_index.to_bits(),
|
||||
|
@ -197,6 +200,7 @@ pub fn liq_token_with_token(
|
|||
indexed_position: liqor
|
||||
.tokens
|
||||
.get_mut(liab_token_index)?
|
||||
.0
|
||||
.indexed_position
|
||||
.to_bits(),
|
||||
deposit_index: liab_bank.deposit_index.to_bits(),
|
||||
|
|
|
@ -143,14 +143,14 @@ pub fn serum3_liq_force_cancel_orders(
|
|||
let mut account = ctx.accounts.account.load_mut()?;
|
||||
|
||||
let mut base_bank = ctx.accounts.base_bank.load_mut()?;
|
||||
let base_position = account.tokens.get_mut(base_bank.token_index)?;
|
||||
let base_position = account.tokens.get_mut(base_bank.token_index)?.0;
|
||||
base_bank.deposit(
|
||||
base_position,
|
||||
I80F48::from(after_base_vault) - I80F48::from(before_base_vault),
|
||||
)?;
|
||||
|
||||
let mut quote_bank = ctx.accounts.quote_bank.load_mut()?;
|
||||
let quote_position = account.tokens.get_mut(quote_bank.token_index)?;
|
||||
let quote_position = account.tokens.get_mut(quote_bank.token_index)?.0;
|
||||
quote_bank.deposit(
|
||||
quote_position,
|
||||
I80F48::from(after_quote_vault) - I80F48::from(before_quote_vault),
|
||||
|
|
|
@ -318,11 +318,11 @@ pub fn apply_vault_difference(
|
|||
// charged if an order executes and the loan materializes? Otherwise MMs that place
|
||||
// an order without having the funds will be charged for each place_order!
|
||||
|
||||
let base_position = account.tokens.get_mut(base_bank.token_index)?;
|
||||
let base_position = account.tokens.get_mut(base_bank.token_index)?.0;
|
||||
let base_change = I80F48::from(after_base_vault) - I80F48::from(before_base_vault);
|
||||
base_bank.change_with_fee(base_position, base_change)?;
|
||||
|
||||
let quote_position = account.tokens.get_mut(quote_bank.token_index)?;
|
||||
let quote_position = account.tokens.get_mut(quote_bank.token_index)?.0;
|
||||
let quote_change = I80F48::from(after_quote_vault) - I80F48::from(before_quote_vault);
|
||||
quote_bank.change_with_fee(quote_position, quote_change)?;
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ pub fn charge_maybe_fees(
|
|||
serum3_account.previous_native_coin_reserved = after_oo.native_coin_reserved();
|
||||
|
||||
// loan origination fees
|
||||
let coin_token_account = account.tokens.get_mut(coin_bank.token_index)?;
|
||||
let coin_token_account = account.tokens.get_mut(coin_bank.token_index)?.0;
|
||||
let coin_token_native = coin_token_account.native(&coin_bank);
|
||||
|
||||
if coin_token_native.is_negative() {
|
||||
|
@ -209,7 +209,7 @@ pub fn charge_maybe_fees(
|
|||
serum3_account.previous_native_pc_reserved = after_oo.native_pc_reserved();
|
||||
|
||||
// loan origination fees
|
||||
let pc_token_account = account.tokens.get_mut(pc_bank.token_index)?;
|
||||
let pc_token_account = account.tokens.get_mut(pc_bank.token_index)?.0;
|
||||
let pc_token_native = pc_token_account.native(&pc_bank);
|
||||
|
||||
if pc_token_native.is_negative() {
|
||||
|
|
|
@ -128,10 +128,15 @@ impl MangoAccountTokenPositions {
|
|||
.ok_or_else(|| error!(MangoError::SomeError)) // TODO: not found error
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, token_index: TokenIndex) -> Result<&mut TokenPosition> {
|
||||
/// Returns
|
||||
/// - the position
|
||||
/// - the raw index into the token positions list (for use with get_raw/deactivate)
|
||||
pub fn get_mut(&mut self, token_index: TokenIndex) -> Result<(&mut TokenPosition, usize)> {
|
||||
self.values
|
||||
.iter_mut()
|
||||
.find(|p| p.is_active_for_token(token_index))
|
||||
.enumerate()
|
||||
.find(|(_, p)| p.is_active_for_token(token_index))
|
||||
.map(|(raw_index, p)| (p, raw_index))
|
||||
.ok_or_else(|| error!(MangoError::SomeError)) // TODO: not found error
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue