Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

program: liquidate spot with swap #1402

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

crispheaney
Copy link
Member

No description provided.

return Err(ErrorCode::InvalidLiquidation);
}

validate!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to fail the tx here or allow the swap up to the max?

msg!("margin calculation: {:?}", margin_calculation);
return Err(ErrorCode::SufficientCollateral);
} else if user.is_being_liquidated() && margin_calculation.can_exit_liquidation()? {
user.exit_liquidation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will user still exit liquidation if error is returned right after?

let asset_precision = 10_u128.pow(asset_decimals);
let liability_precision = 10_u128.pow(liability_decimals);

let swap_price = liability_transfer
Copy link
Member

@NourAlharithi NourAlharithi Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

liability_transfer.safe_sub(if_fee)?,
&SpotBalanceType::Deposit,
&mut liability_market,
user.get_spot_position_mut(liability_market_index)?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead of explicit open position checks (which look missing here) we can use .expect here so bots dont get a generic error.

{
let mut liability_market = spot_market_map.get_ref_mut(&liability_market_index)?;

update_spot_balances_and_cumulative_deposits(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to call update_spot_balances_and_cumulative_deposits for the liquidator?

pub fn liquidate_spot_with_swap_begin(
asset_market_index: u16,
liability_market_index: u16,
swap_amount: u64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename to swap_amount_in

pub fn handle_liquidate_spot_with_swap_end<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, LiquidateSpotWithSwap<'info>>,
asset_market_index: u16,
liability_market_index: u16,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be a good idea to add min_amount_out so liquidator has some control over worst case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants