-
Notifications
You must be signed in to change notification settings - Fork 179
program: isolation position init #1757
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
base: crispheaney/rm-lp
Are you sure you want to change the base?
Conversation
programs/drift/src/controller/pnl.rs
Outdated
Some(meets_margin_requirement) => meets_margin_requirement, | ||
None => meets_settle_pnl_maintenance_margin_requirement( | ||
Some(meets_margin_requirement) if !isolated_position_market_index.is_some() => meets_margin_requirement, | ||
// TODO check margin for isolate position |
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.
need to redo margin check?
total_withdraws_after, | ||
market_index: spot_market_index, | ||
explanation: DepositExplanation::None, | ||
transfer_user: None, |
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.
are we planning on tracking isolated positions deposit/withdraws? might need something here
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.
yeah good question for lukas/kev
Ok(self | ||
.margin_requirement_plus_buffer | ||
.cast::<i128>()? | ||
.safe_sub(self.get_total_collateral_plus_buffer())? | ||
.unsigned_abs()) |
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.
i think how this function is used is safe, but it's semantically confusing since 'shortage' implies it should return a negative number that's abs'd. But since it abs everything, it can technically give a wrong result if there was a surplus. Same applies to the other impl of margin_shortage
This might be more safer:
Ok(self | |
.margin_requirement_plus_buffer | |
.cast::<i128>()? | |
.safe_sub(self.get_total_collateral_plus_buffer())? | |
.unsigned_abs()) | |
Ok(self | |
.margin_requirement_plus_buffer | |
.cast::<i128>()? | |
.safe_sub(self.get_total_collateral_plus_buffer())? | |
.max(0).cast::<u128>()?) |
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.
min?
for (_, isolated_margin_calculation) in &self.isolated_margin_calculations | ||
{ | ||
if !isolated_margin_calculation.meets_margin_requirement() { | ||
return false; | ||
} | ||
} |
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.
why does this use both cross and isolated? looks like it's used in liquidate_perp, so if the isolated position is still in liquidation it would prevent the user from exiting liquidation?
) -> DriftResult<(AssetTier, ContractTier)> { | ||
let contract_tier = perp_market_map.get_ref(&self.market_index)?.contract_tier; | ||
|
||
Ok((AssetTier::default(), contract_tier)) |
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.
this correct @0xbigz ?
perp_position, | ||
false, | ||
)?; | ||
} else { |
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 do this for settle_expired_position
too? or will it settle to the user's spot pos without a problem?
&perp_market_map, | ||
&spot_market_map, | ||
oracle_map, | ||
MarginRequirementType::Initial, |
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.
i wonder if these post-transfer margin checks should be maintenance rather than initial. I think using initial prevents the user from transfering from their iso->cross to improve the liquidation level on their main account, unless the transfer is large enough to meet initial margin requirements.
No description provided.