-
Notifications
You must be signed in to change notification settings - Fork 125
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
base: master
Are you sure you want to change the base?
Conversation
return Err(ErrorCode::InvalidLiquidation); | ||
} | ||
|
||
validate!( |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use the calculate swap price func from here for consistency?
liability_transfer.safe_sub(if_fee)?, | ||
&SpotBalanceType::Deposit, | ||
&mut liability_market, | ||
user.get_spot_position_mut(liability_market_index)?, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
No description provided.