@@ -9,33 +9,34 @@ import (
99 "github.com/elys-network/elys/v6/x/perpetual/types"
1010)
1111
12- func (k Keeper ) ClosePosition (ctx sdk.Context , msg * types.MsgClose ) (types.MTP , math.Int , math.LegacyDec , math.Int , math.Int , math.Int , math.Int , math.Int , bool , bool , error ) {
12+ func (k Keeper ) ClosePosition (ctx sdk.Context , msg * types.MsgClose ) (types.MTP , math.Int , math.LegacyDec , math.Int , math.Int , math.Int , math.Int , math.Int , bool , bool , types. PerpetualFees , error ) {
1313 // Retrieve MTP
1414 creator := sdk .MustAccAddressFromBech32 (msg .Creator )
15+ zeroPerpFees := types .NewPerpetualFeesWithEmptyCoins ()
1516 mtp , err := k .GetMTP (ctx , msg .PoolId , creator , msg .Id )
1617 if err != nil {
17- return types.MTP {}, math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), false , false , err
18+ return types.MTP {}, math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), false , false , zeroPerpFees , err
1819 }
1920
2021 pool , found := k .GetPool (ctx , mtp .AmmPoolId )
2122 if ! found {
22- return mtp , math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), false , false , errorsmod .Wrap (types .ErrPoolDoesNotExist , fmt .Sprintf ("poolId: %d" , mtp .AmmPoolId ))
23+ return mtp , math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), false , false , zeroPerpFees , errorsmod .Wrap (types .ErrPoolDoesNotExist , fmt .Sprintf ("poolId: %d" , mtp .AmmPoolId ))
2324 }
2425
2526 // Retrieve AmmPool
2627 ammPool , err := k .GetAmmPool (ctx , mtp .AmmPoolId )
2728 if err != nil {
28- return mtp , math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), false , false , err
29+ return mtp , math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), false , false , zeroPerpFees , err
2930 }
3031
3132 // this also handles edge case where bot is unable to close position in time.
32- repayAmt , returnAmt , fundingFeeAmt , fundingAmtDistributed , interestAmt , insuranceAmt , allInterestsPaid , forceClosed , err := k .MTPTriggerChecksAndUpdates (ctx , & mtp , & pool , & ammPool )
33+ repayAmt , returnAmt , fundingFeeAmt , fundingAmtDistributed , interestAmt , insuranceAmt , allInterestsPaid , forceClosed , perpetualFeesCoins , err := k .MTPTriggerChecksAndUpdates (ctx , & mtp , & pool , & ammPool )
3334 if err != nil {
34- return types.MTP {}, math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), false , false , err
35+ return types.MTP {}, math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), false , false , zeroPerpFees , err
3536 }
3637
3738 if forceClosed {
38- return mtp , repayAmt , math .LegacyOneDec (), returnAmt , fundingFeeAmt , fundingAmtDistributed , interestAmt , insuranceAmt , allInterestsPaid , forceClosed , nil
39+ return mtp , repayAmt , math .LegacyOneDec (), returnAmt , fundingFeeAmt , fundingAmtDistributed , interestAmt , insuranceAmt , allInterestsPaid , forceClosed , perpetualFeesCoins , nil
3940 }
4041
4142 // Should be declared after SettleMTPBorrowInterestUnpaidLiability and settling funding
@@ -48,18 +49,19 @@ func (k Keeper) ClosePosition(ctx sdk.Context, msg *types.MsgClose) (types.MTP,
4849 }
4950
5051 // Estimate swap and repay
51- repayAmt , returnAmt , err = k .EstimateAndRepay (ctx , & mtp , & pool , & ammPool , closingRatio )
52+ repayAmt , returnAmt , perpFees , err : = k .EstimateAndRepay (ctx , & mtp , & pool , & ammPool , closingRatio )
5253 if err != nil {
53- return mtp , math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), allInterestsPaid , forceClosed , err
54+ return mtp , math .ZeroInt (), math .LegacyZeroDec (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), math .ZeroInt (), allInterestsPaid , forceClosed , perpetualFeesCoins , err
5455 }
56+ perpetualFeesCoins = perpetualFeesCoins .Add (perpFees )
5557
5658 // EpochHooks after perpetual position closed
5759 if k .hooks != nil {
5860 err = k .hooks .AfterPerpetualPositionClosed (ctx , ammPool , pool , creator , closingRatio , mtp .Id )
5961 if err != nil {
60- return mtp , math.Int {}, math.LegacyDec {}, math.Int {}, math.Int {}, math.Int {}, math.Int {}, math.Int {}, allInterestsPaid , forceClosed , err
62+ return mtp , math.Int {}, math.LegacyDec {}, math.Int {}, math.Int {}, math.Int {}, math.Int {}, math.Int {}, allInterestsPaid , forceClosed , zeroPerpFees , err
6163 }
6264 }
6365
64- return mtp , repayAmt , closingRatio , returnAmt , fundingFeeAmt , fundingAmtDistributed , interestAmt , insuranceAmt , allInterestsPaid , forceClosed , nil
66+ return mtp , repayAmt , closingRatio , returnAmt , fundingFeeAmt , fundingAmtDistributed , interestAmt , insuranceAmt , allInterestsPaid , forceClosed , perpetualFeesCoins , nil
6567}
0 commit comments