-
Notifications
You must be signed in to change notification settings - Fork 23
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
chore: Fix liquidation migration script for coordinator leverage = 1 #2373
Conversation
@@ -2,4 +2,5 @@ ALTER TABLE "positions" | |||
ADD COLUMN coordinator_liquidation_price REAL NOT NULL DEFAULT 0; | |||
|
|||
UPDATE positions SET coordinator_liquidation_price = average_entry_price * coordinator_leverage / (coordinator_leverage + 1) where trader_direction='short'; | |||
UPDATE positions SET coordinator_liquidation_price = average_entry_price * coordinator_leverage / (coordinator_leverage - 1) where trader_direction='long'; | |||
UPDATE positions SET coordinator_liquidation_price = average_entry_price * coordinator_leverage / (coordinator_leverage - 1) where trader_direction='long' and coordinator_leverage > 1; | |||
UPDATE positions SET coordinator_liquidation_price = average_entry_price * coordinator_leverage where trader_direction='long' and coordinator_leverage = 1; |
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.
🤔 The formula doesn't look right to me. Elsewhere we've set the liquidation price of a party going short at 1x leverage to the maximum price the oracle can attest to. I'm not sure if that's correct either though cc @bonomat.
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.
Yea, if a party goes short
with a leverage of 1 he basically never gets liquidated. So we can set this to a very high number.
On the contrary, if a party goes long
with a leverage of 1 his liquidation price is at about 50%, i.e.
(average_entry_price*leverage)/((leverage+1-(maintenance_margin*leverage)))
--> average_entry_price/2
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 I get an approval then? 🙂
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.
It still looks wrong to me though. AFAICT, you're setting the coordinator's liquidation price to
average_entry_price * 1
if the coordinator goes short. To be consistent with our internal formulas, I think we want to set this to BTCUSD_MAX_PRICE
.
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.
Here we go, this should fix it:
UPDATE positions SET coordinator_liquidation_price = average_entry_price * coordinator_leverage where trader_direction='long' and coordinator_leverage = 1; | |
UPDATE positions SET coordinator_liquidation_price = 21_000_000 where trader_direction='long' and coordinator_leverage = 1; |
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.
fair, I will adapt that.
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.
@bonomat I used the const from the code, to be consistent with our implementation.
pub const BTCUSD_MAX_PRICE: u64 = 1_048_575;
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.
Not sure about the formula.
coordinator/migrations/2024-04-03-105900_add_coordinator_liquidation_price/up.sql
Outdated
Show resolved
Hide resolved
dd07890
to
3a14b78
Compare
3a14b78
to
013a4db
Compare
013a4db
to
2c55074
Compare
follow up to review remarks on #2354