Skip to content

Commit

Permalink
query fixes (#891)
Browse files Browse the repository at this point in the history
* code review changes

* code review changes
  • Loading branch information
avkr003 authored Oct 28, 2024
1 parent 886da31 commit 3a4d28c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions x/perpetual/keeper/mtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,15 @@ func (k Keeper) GetLiquidationPrice(ctx sdk.Context, mtp types.MTP) sdk.Dec {
// calculate liquidation price
if mtp.Position == types.Position_LONG {
// liquidation_price = (safety_factor * liabilities) / custody
liquidationPrice = params.SafetyFactor.Mul(mtp.Liabilities.ToLegacyDec()).Quo(mtp.Custody.ToLegacyDec())
if !mtp.Custody.IsZero() {
liquidationPrice = params.SafetyFactor.Mul(mtp.Liabilities.ToLegacyDec()).Quo(mtp.Custody.ToLegacyDec())
}
}
if mtp.Position == types.Position_SHORT {
// liquidation_price = Custody / (Liabilities * safety_factor)
liquidationPrice = mtp.Custody.ToLegacyDec().Quo(mtp.Liabilities.ToLegacyDec().Mul(params.SafetyFactor))
if !mtp.Liabilities.IsZero() {
liquidationPrice = mtp.Custody.ToLegacyDec().Quo(mtp.Liabilities.ToLegacyDec().Mul(params.SafetyFactor))
}
}

return liquidationPrice
Expand Down
4 changes: 3 additions & 1 deletion x/perpetual/keeper/query_close_estimation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func (k Keeper) HandleCloseEstimation(ctx sdk.Context, req *types.QueryCloseEsti
return &types.QueryCloseEstimationResponse{}, err
}
}
maxCloseAmount := mtp.Custody.Sub(borrowInterestPaymentInCustody)
mtp.Custody = mtp.Custody.Sub(borrowInterestPaymentInCustody)

maxCloseAmount := mtp.Custody
if mtp.Position == types.Position_SHORT {
maxCloseAmount = mtp.Liabilities
}
Expand Down

0 comments on commit 3a4d28c

Please sign in to comment.