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: scale down init asset weights past threshold #575

Merged
merged 43 commits into from
Sep 6, 2023

Conversation

crispheaney
Copy link
Member

@crispheaney crispheaney commented Aug 12, 2023

main todos are double checking all the places that have logic based on asset weights:
calc worst case base amounts
calculating which margin type to check after fill/swap
calculating max leverage order size for spot order


// when orders are placed in bulk, only need to check margin on last place
if options.enforce_margin_check {
// Order fails if it's risk increasing and it brings the user collateral below the margin requirement
let meets_initial_margin_requirement = meets_place_order_margin_requirement(
meets_place_order_margin_requirement(
Copy link
Member Author

Choose a reason for hiding this comment

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

previously skipped if order wasn't risk increasing. now it will check maintenance if not risk increasing

@crispheaney crispheaney force-pushed the crispheaney/scale-asset-weight branch from 2fac946 to 2289506 Compare August 30, 2023 14:20
let risk_decreasing = worst_case_token_amount_after.unsigned_abs()
<= worst_case_token_amount_before.unsigned_abs()
&& order_risk_decreasing;
let risk_increasing = free_collateral_contribution_after < free_collateral_contribution_before;
Copy link
Member

Choose a reason for hiding this comment

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

is it dumb to just have a function is_risk_increasing(free_collateral_contribution_before, free_collateral_contribution_after) since i've seen this line more than once?

Copy link
Member Author

Choose a reason for hiding this comment

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

nah, can do that

)?;

// Need to recalculate weighted_token_value if user_custom_margin_ratio != 0
if user_custom_margin_ratio != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

should this live in the get_worst_case_token_amount function?

Copy link
Member Author

Choose a reason for hiding this comment

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

was thinking we don't want the user margin ratio to effect other conditional logic that depends on get_worst_case_token_amount, wdyt?

@crispheaney crispheaney merged commit 4ebd00b into master Sep 6, 2023
7 of 9 checks passed
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.

None yet

2 participants