Skip to content

Commit 7f801d1

Browse files
committed
updating logic for add collateral and close position
1 parent d4667e5 commit 7f801d1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

x/perpetual/keeper/close_position.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ func (k Keeper) ClosePosition(ctx sdk.Context, msg *types.MsgClose) (types.MTP,
4747
return types.MTP{}, math.ZeroInt(), math.LegacyZeroDec(), math.ZeroInt(), math.ZeroInt(), math.ZeroInt(), math.ZeroInt(), math.ZeroInt(), false, false, zeroPerpFees, math.LegacyZeroDec(), initialCollateral, initialCustody, initialLiabilities, err
4848
}
4949

50-
// user didn't want close position fully & it got only partially closed, we return as the value user wanted to close is different now
51-
if !userClosingRatio.Equal(math.LegacyOneDec()) && forceClosed && !closingRatio.Equal(math.LegacyOneDec()) {
52-
return mtp, repayAmt, closingRatio, returnAmt, fundingFeeAmt, fundingAmtDistributed, interestAmt, insuranceAmt, allInterestsPaid, forceClosed, perpetualFeesCoins, closingPrice, initialCollateral, initialCustody, initialLiabilities, nil
50+
if forceClosed {
51+
// user didn't want close position fully and it got only partially closed, we return as the value user wanted to close is different now
52+
// OR it got fully liquidated
53+
if (!userClosingRatio.Equal(math.LegacyOneDec()) && !closingRatio.Equal(math.LegacyOneDec())) || closingRatio.Equal(math.LegacyOneDec()) {
54+
return mtp, repayAmt, closingRatio, returnAmt, fundingFeeAmt, fundingAmtDistributed, interestAmt, insuranceAmt, allInterestsPaid, forceClosed, perpetualFeesCoins, closingPrice, initialCollateral, initialCustody, initialLiabilities, nil
55+
}
5356
}
5457

5558
// Should be reset after MTPTriggerChecksAndUpdates

0 commit comments

Comments
 (0)