Skip to content

Commit 60157d3

Browse files
authored
Add perpetual fees event (#1351)
* add perpetual fees event * refactor and review fixes * trim fees usd value to legacy dec
1 parent eed38fd commit 60157d3

File tree

9 files changed

+138
-29
lines changed

9 files changed

+138
-29
lines changed

x/perpetual/keeper/amm.go

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
errorsmod "cosmossdk.io/errors"
77
"cosmossdk.io/math"
88
sdk "github.com/cosmos/cosmos-sdk/types"
9+
ammkeeper "github.com/elys-network/elys/v6/x/amm/keeper"
910
ammtypes "github.com/elys-network/elys/v6/x/amm/types"
1011
"github.com/elys-network/elys/v6/x/perpetual/types"
1112
"github.com/osmosis-labs/osmosis/osmomath"
@@ -31,9 +32,9 @@ func getWeightBreakingFee(weightBalanceBonus osmomath.BigDec) osmomath.BigDec {
3132
}
3233

3334
// Swap estimation using amm CalcOutAmtGivenIn function
34-
func (k Keeper) EstimateSwapGivenIn(ctx sdk.Context, tokenInAmount sdk.Coin, tokenOutDenom string, ammPool ammtypes.Pool, owner string) (math.Int, osmomath.BigDec, osmomath.BigDec, math.LegacyDec, math.LegacyDec, error) {
35+
func (k Keeper) EstimateSwapGivenIn(ctx sdk.Context, tokenInAmount sdk.Coin, tokenOutDenom string, ammPool ammtypes.Pool, owner string) (math.Int, osmomath.BigDec, osmomath.BigDec, osmomath.BigDec, math.LegacyDec, math.LegacyDec, error) {
3536
if tokenInAmount.IsZero() {
36-
return math.Int{}, osmomath.BigDec{}, osmomath.BigDec{}, math.LegacyDec{}, math.LegacyDec{}, fmt.Errorf("tokenInAmount is zero for EstimateSwapGivenIn")
37+
return math.Int{}, osmomath.BigDec{}, osmomath.BigDec{}, osmomath.BigDec{}, math.LegacyDec{}, math.LegacyDec{}, fmt.Errorf("tokenInAmount is zero for EstimateSwapGivenIn")
3738
}
3839
params := k.GetParams(ctx)
3940

@@ -47,21 +48,22 @@ func (k Keeper) EstimateSwapGivenIn(ctx sdk.Context, tokenInAmount sdk.Coin, tok
4748
// Estimate swap
4849
snapshot := k.amm.GetPoolWithAccountedBalance(ctx, ammPool.PoolId)
4950
tokensIn := sdk.Coins{tokenInAmount}
50-
tokenOut, slippage, _, weightBalanceBonus, _, _, err := k.amm.SwapOutAmtGivenIn(ctx, ammPool.PoolId, k.oracleKeeper, snapshot, tokensIn, tokenOutDenom, perpetualFees, params.GetBigDecWeightBreakingFeeFactor(), takersFee)
51+
tokenOut, slippage, slippageAmount, weightBalanceBonus, _, _, err := k.amm.SwapOutAmtGivenIn(ctx, ammPool.PoolId, k.oracleKeeper, snapshot, tokensIn, tokenOutDenom, perpetualFees, params.GetBigDecWeightBreakingFeeFactor(), takersFee)
5152
if err != nil {
52-
return math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyDec{}, math.LegacyDec{}, errorsmod.Wrapf(err, "unable to swap (EstimateSwapGivenIn) for in %s and out denom %s", tokenInAmount.String(), tokenOutDenom)
53+
return math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyDec{}, math.LegacyDec{}, errorsmod.Wrapf(err, "unable to swap (EstimateSwapGivenIn) for in %s and out denom %s", tokenInAmount.String(), tokenOutDenom)
5354
}
5455

5556
if tokenOut.IsZero() {
56-
return math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyDec{}, math.LegacyDec{}, errorsmod.Wrapf(types.ErrAmountTooLow, "tokenOut is zero for swap (EstimateSwapGivenIn) for in %s and out denom %s", tokenInAmount.String(), tokenOutDenom)
57+
return math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyDec{}, math.LegacyDec{}, errorsmod.Wrapf(types.ErrAmountTooLow, "tokenOut is zero for swap (EstimateSwapGivenIn) for in %s and out denom %s", tokenInAmount.String(), tokenOutDenom)
5758
}
58-
return tokenOut.Amount, slippage, getWeightBreakingFee(weightBalanceBonus), perpetualFees.Dec(), takersFee.Dec(), nil
59+
60+
return tokenOut.Amount, slippage, slippageAmount, getWeightBreakingFee(weightBalanceBonus), perpetualFees.Dec(), takersFee.Dec(), nil
5961
}
6062

6163
// Swap estimation using amm CalcInAmtGivenOut function
62-
func (k Keeper) EstimateSwapGivenOut(ctx sdk.Context, tokenOutAmount sdk.Coin, tokenInDenom string, ammPool ammtypes.Pool, owner string) (math.Int, osmomath.BigDec, osmomath.BigDec, math.LegacyDec, math.LegacyDec, error) {
64+
func (k Keeper) EstimateSwapGivenOut(ctx sdk.Context, tokenOutAmount sdk.Coin, tokenInDenom string, ammPool ammtypes.Pool, owner string) (math.Int, osmomath.BigDec, osmomath.BigDec, osmomath.BigDec, osmomath.BigDec, math.LegacyDec, math.LegacyDec, error) {
6365
if tokenOutAmount.IsZero() {
64-
return math.Int{}, osmomath.BigDec{}, osmomath.BigDec{}, math.LegacyDec{}, math.LegacyDec{}, fmt.Errorf("tokenOutAmount is zero for EstimateSwapGivenOut")
66+
return math.Int{}, osmomath.BigDec{}, osmomath.BigDec{}, osmomath.BigDec{}, osmomath.BigDec{}, math.LegacyDec{}, math.LegacyDec{}, fmt.Errorf("tokenOutAmount is zero for EstimateSwapGivenOut")
6567
}
6668
params := k.GetParams(ctx)
6769
tokensOut := sdk.Coins{tokenOutAmount}
@@ -76,13 +78,79 @@ func (k Keeper) EstimateSwapGivenOut(ctx sdk.Context, tokenOutAmount sdk.Coin, t
7678

7779
// Estimate swap
7880
snapshot := k.amm.GetPoolWithAccountedBalance(ctx, ammPool.PoolId)
79-
tokenIn, slippage, _, weightBalanceBonus, _, _, err := k.amm.SwapInAmtGivenOut(ctx, ammPool.PoolId, k.oracleKeeper, snapshot, tokensOut, tokenInDenom, perpetualFees, params.GetBigDecWeightBreakingFeeFactor(), takersFee)
81+
tokenIn, slippage, slippageAmount, weightBalanceBonus, oracleIn, _, err := k.amm.SwapInAmtGivenOut(ctx, ammPool.PoolId, k.oracleKeeper, snapshot, tokensOut, tokenInDenom, perpetualFees, params.GetBigDecWeightBreakingFeeFactor(), takersFee)
8082
if err != nil {
81-
return math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyDec{}, math.LegacyDec{}, errorsmod.Wrapf(err, "unable to swap (EstimateSwapGivenOut) for out %s and in denom %s", tokenOutAmount.String(), tokenInDenom)
83+
return math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyDec{}, math.LegacyDec{}, errorsmod.Wrapf(err, "unable to swap (EstimateSwapGivenOut) for out %s and in denom %s", tokenOutAmount.String(), tokenInDenom)
8284
}
8385

8486
if tokenIn.IsZero() {
85-
return math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyDec{}, math.LegacyDec{}, errorsmod.Wrapf(types.ErrAmountTooLow, "tokenIn is zero for swap (EstimateSwapGivenOut) for out %s and in denom %s", tokenOutAmount.String(), tokenInDenom)
87+
return math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyDec{}, math.LegacyDec{}, errorsmod.Wrapf(types.ErrAmountTooLow, "tokenIn is zero for swap (EstimateSwapGivenOut) for out %s and in denom %s", tokenOutAmount.String(), tokenInDenom)
88+
}
89+
90+
return tokenIn.Amount, slippage, slippageAmount, getWeightBreakingFee(weightBalanceBonus), oracleIn, perpetualFees.Dec(), takersFee.Dec(), nil
91+
}
92+
93+
func (k Keeper) CalculateAndEmitPerpetualFeesEvent(
94+
ctx sdk.Context,
95+
poolIsOracle bool,
96+
tokenIn sdk.Coin,
97+
tokenOut sdk.Coin,
98+
slippageAmount osmomath.BigDec,
99+
weightBreakingFee osmomath.BigDec,
100+
perpetualFees math.LegacyDec,
101+
takersFee math.LegacyDec,
102+
oracleInAmount osmomath.BigDec,
103+
isSwapGivenIn bool,
104+
) {
105+
106+
// Determine the source of fees based on isSwapGivenIn
107+
takeFeesFrom := sdk.Coins{tokenIn}
108+
if !isSwapGivenIn && poolIsOracle {
109+
takeFeesFrom = sdk.NewCoins(sdk.NewCoin(tokenIn.Denom, oracleInAmount.Dec().TruncateInt()))
110+
}
111+
112+
// Calculate perpetual fees in USD
113+
perpFeesValueInUSD := math.LegacyZeroDec()
114+
if perpetualFees.IsPositive() {
115+
perpetualFeesCoins := ammkeeper.PortionCoins(takeFeesFrom, osmomath.BigDecFromDec(perpetualFees))
116+
perpFeesValueInUSD = k.amm.CalculateCoinsUSDValue(ctx, perpetualFeesCoins).Dec()
117+
}
118+
119+
// Calculate taker fees in USD
120+
takerFeesAmountInUSD := math.LegacyZeroDec()
121+
if takersFee.IsPositive() {
122+
takerFeesInCoins := ammkeeper.PortionCoins(takeFeesFrom, osmomath.BigDecFromDec(takersFee))
123+
takerFeesAmountInUSD = k.amm.CalculateCoinsUSDValue(ctx, takerFeesInCoins).Dec()
124+
}
125+
126+
// Calculate slippage amount in USD
127+
slippageAmountInUSD := math.LegacyZeroDec()
128+
if isSwapGivenIn {
129+
slippageAmountInUSD = k.amm.CalculateUSDValue(ctx, tokenOut.Denom, slippageAmount.Dec().TruncateInt()).Dec()
130+
} else {
131+
slippageAmountInUSD = k.amm.CalculateUSDValue(ctx, tokenIn.Denom, slippageAmount.Dec().TruncateInt()).Dec()
132+
}
133+
134+
// Calculate weight breaking fees in USD
135+
weightBreakingFeesAmountInUSD := math.LegacyZeroDec()
136+
if !weightBreakingFee.IsZero() {
137+
var weightBreakingFeeAmount math.Int
138+
if isSwapGivenIn {
139+
weightBreakingFeeAmount = osmomath.BigDecFromSDKInt(tokenIn.Amount).Mul(weightBreakingFee).Dec().RoundInt()
140+
} else {
141+
weightBreakingFeeAmount = oracleInAmount.Mul(weightBreakingFee).Dec().RoundInt()
142+
}
143+
weightBreakingFeesAmountInUSD = k.amm.CalculateUSDValue(ctx, tokenIn.Denom, weightBreakingFeeAmount).Dec()
144+
}
145+
146+
// Emit the event if any fees are non-zero
147+
if !(perpFeesValueInUSD.IsZero() && slippageAmountInUSD.IsZero() && weightBreakingFeesAmountInUSD.IsZero() && takerFeesAmountInUSD.IsZero()) {
148+
types.EmitPerpetualFeesEvent(
149+
ctx,
150+
perpFeesValueInUSD.String(),
151+
slippageAmountInUSD.String(),
152+
weightBreakingFeesAmountInUSD.String(),
153+
takerFeesAmountInUSD.String(),
154+
)
86155
}
87-
return tokenIn.Amount, slippage, getWeightBreakingFee(weightBalanceBonus), perpetualFees.Dec(), takersFee.Dec(), nil
88156
}

x/perpetual/keeper/estimate_and_repay.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ func (k Keeper) EstimateAndRepay(ctx sdk.Context, mtp *types.MTP, pool *types.Po
2121
return math.Int{}, math.Int{}, fmt.Errorf("invalid closing ratio (%s)", closingRatio.String())
2222
}
2323

24-
repayAmount, payingLiabilities, _, _, err := k.CalcRepayAmount(ctx, mtp, ammPool, closingRatio)
24+
repayAmount, payingLiabilities, _, slippageAmount, weightBreakingFee, repayOracleAmount, perpetualFees, takerFees, err := k.CalcRepayAmount(ctx, mtp, ammPool, closingRatio)
2525
if err != nil {
2626
return math.ZeroInt(), math.ZeroInt(), err
2727
}
28+
k.CalculateAndEmitPerpetualFeesEvent(ctx, ammPool.PoolParams.UseOracle, sdk.NewCoin(mtp.CustodyAsset, repayAmount), sdk.NewCoin(mtp.LiabilitiesAsset, payingLiabilities), slippageAmount, weightBreakingFee, perpetualFees, takerFees, repayOracleAmount, false)
29+
2830
returnAmount, err := k.CalcReturnAmount(*mtp, repayAmount, closingRatio)
2931
if err != nil {
3032
return math.ZeroInt(), math.ZeroInt(), err
@@ -45,7 +47,7 @@ func (k Keeper) EstimateAndRepay(ctx sdk.Context, mtp *types.MTP, pool *types.Po
4547
}
4648

4749
// CalcRepayAmount repay amount is in custody asset for liabilities with closing ratio
48-
func (k Keeper) CalcRepayAmount(ctx sdk.Context, mtp *types.MTP, ammPool *ammtypes.Pool, closingRatio math.LegacyDec) (repayAmount, payingLiabilities math.Int, slippage, weightBreakingFee osmomath.BigDec, err error) {
50+
func (k Keeper) CalcRepayAmount(ctx sdk.Context, mtp *types.MTP, ammPool *ammtypes.Pool, closingRatio math.LegacyDec) (repayAmount, payingLiabilities math.Int, slippage, slippageAmount, weightBreakingFee, repayOracleAmount osmomath.BigDec, perpetualFees, takerFees math.LegacyDec, err error) {
4951
// init repay amount
5052
// For long this will be in trading asset (custody asset is trading asset)
5153
// For short this will be in USDC (custody asset is USDC)
@@ -58,17 +60,17 @@ func (k Keeper) CalcRepayAmount(ctx sdk.Context, mtp *types.MTP, ammPool *ammtyp
5860

5961
if mtp.Position == types.Position_LONG {
6062
liabilitiesWithClosingRatio := sdk.NewCoin(mtp.LiabilitiesAsset, payingLiabilities)
61-
repayAmount, slippage, weightBreakingFee, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesWithClosingRatio, mtp.CustodyAsset, *ammPool, mtp.Address)
63+
repayAmount, slippage, slippageAmount, weightBreakingFee, repayOracleAmount, perpetualFees, takerFees, err = k.EstimateSwapGivenOut(ctx, liabilitiesWithClosingRatio, mtp.CustodyAsset, *ammPool, mtp.Address)
6264
if err != nil {
63-
return math.ZeroInt(), math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), err
65+
return math.ZeroInt(), math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyZeroDec(), math.LegacyZeroDec(), err
6466
}
6567
}
6668
if mtp.Position == types.Position_SHORT {
6769
// if position is short, repay in custody asset which is base currency
6870
liabilitiesWithClosingRatio := sdk.NewCoin(mtp.LiabilitiesAsset, payingLiabilities)
69-
repayAmount, slippage, weightBreakingFee, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesWithClosingRatio, mtp.CustodyAsset, *ammPool, mtp.Address)
71+
repayAmount, slippage, slippageAmount, weightBreakingFee, repayOracleAmount, perpetualFees, takerFees, err = k.EstimateSwapGivenOut(ctx, liabilitiesWithClosingRatio, mtp.CustodyAsset, *ammPool, mtp.Address)
7072
if err != nil {
71-
return math.ZeroInt(), math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), err
73+
return math.ZeroInt(), math.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), math.LegacyZeroDec(), math.LegacyZeroDec(), err
7274
}
7375
}
7476

x/perpetual/keeper/keeper.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
pkeeper "github.com/elys-network/elys/v6/x/parameter/keeper"
1414
"github.com/elys-network/elys/v6/x/perpetual/types"
1515
tierkeeper "github.com/elys-network/elys/v6/x/tier/keeper"
16+
"github.com/osmosis-labs/osmosis/osmomath"
1617
)
1718

1819
type (
@@ -93,14 +94,17 @@ func (k Keeper) Borrow(ctx sdk.Context, collateralAmount math.Int, custodyAmount
9394
// If collateral asset is not base currency, should calculate liability in base currency with the given out.
9495
// For LONG, Liability has to be in base currency, CollateralAsset can be trading asset or base currency
9596
// For SHORT, Liability has to be in trading asset and CollateralAsset will be in base currency, so this if case only applies to LONG
97+
slippageAmount, weightBreakingFee, liabilitiesOracleAmount := osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec()
98+
perpetualFees, takerFees := math.LegacyZeroDec(), math.LegacyZeroDec()
9699
if mtp.CollateralAsset != baseCurrency {
97100
if !liabilities.IsZero() {
98101
liabilitiesInCollateralTokenOut := sdk.NewCoin(mtp.CollateralAsset, liabilitiesInCollateral)
99102
// Calculate base currency amount given atom out amount and we use it liabilty amount in base currency
100-
liabilities, _, _, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesInCollateralTokenOut, baseCurrency, *ammPool, mtp.Address)
103+
liabilities, _, slippageAmount, weightBreakingFee, liabilitiesOracleAmount, perpetualFees, takerFees, err = k.EstimateSwapGivenOut(ctx, liabilitiesInCollateralTokenOut, baseCurrency, *ammPool, mtp.Address)
101104
if err != nil {
102105
return err
103106
}
107+
k.CalculateAndEmitPerpetualFeesEvent(ctx, ammPool.PoolParams.UseOracle, sdk.NewCoin(baseCurrency, liabilities), liabilitiesInCollateralTokenOut, slippageAmount, weightBreakingFee, perpetualFees, takerFees, liabilitiesOracleAmount, false)
104108
}
105109
}
106110

@@ -109,10 +113,11 @@ func (k Keeper) Borrow(ctx sdk.Context, collateralAmount math.Int, custodyAmount
109113
// liabilities.IsZero() happens when we are consolidating with leverage 1 as eta = 0
110114
if !liabilities.IsZero() {
111115
liabilitiesInCollateralTokenIn := sdk.NewCoin(baseCurrency, liabilities)
112-
liabilities, _, _, _, _, err = k.EstimateSwapGivenOut(ctx, liabilitiesInCollateralTokenIn, mtp.LiabilitiesAsset, *ammPool, mtp.Address)
116+
liabilities, _, slippageAmount, weightBreakingFee, liabilitiesOracleAmount, perpetualFees, takerFees, err = k.EstimateSwapGivenOut(ctx, liabilitiesInCollateralTokenIn, mtp.LiabilitiesAsset, *ammPool, mtp.Address)
113117
if err != nil {
114118
return err
115119
}
120+
k.CalculateAndEmitPerpetualFeesEvent(ctx, ammPool.PoolParams.UseOracle, sdk.NewCoin(mtp.LiabilitiesAsset, liabilities), liabilitiesInCollateralTokenIn, slippageAmount, weightBreakingFee, perpetualFees, takerFees, liabilitiesOracleAmount, false)
116121
}
117122
}
118123

x/perpetual/keeper/process_open.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package keeper
22

33
import (
44
"fmt"
5+
56
ammtypes "github.com/elys-network/elys/v6/x/amm/types"
7+
"github.com/osmosis-labs/osmosis/osmomath"
68

79
errorsmod "cosmossdk.io/errors"
810
"cosmossdk.io/math"
@@ -25,7 +27,7 @@ func (k Keeper) ProcessOpen(ctx sdk.Context, pool *types.Pool, ammPool *ammtypes
2527
// If collateral is not base currency, calculate the borrowing amount in base currency and check the balance
2628
if mtp.CollateralAsset != baseCurrency {
2729
custodyAmtToken := sdk.NewCoin(mtp.CollateralAsset, leveragedAmount)
28-
borrowingAmount, _, _, _, _, err := k.EstimateSwapGivenOut(ctx, custodyAmtToken, baseCurrency, *ammPool, mtp.Address)
30+
borrowingAmount, _, _, _, _, _, _, err := k.EstimateSwapGivenOut(ctx, custodyAmtToken, baseCurrency, *ammPool, mtp.Address)
2931
if err != nil {
3032
return err
3133
}
@@ -41,10 +43,13 @@ func (k Keeper) ProcessOpen(ctx sdk.Context, pool *types.Pool, ammPool *ammtypes
4143
// If position is long, calculate custody amount in custody asset
4244
if mtp.CollateralAsset == baseCurrency {
4345
leveragedAmtTokenIn := sdk.NewCoin(mtp.CollateralAsset, leveragedAmount)
44-
custodyAmount, _, _, _, _, err = k.EstimateSwapGivenIn(ctx, leveragedAmtTokenIn, mtp.CustodyAsset, *ammPool, mtp.Address)
46+
slippageAmount, weightBreakingFee := osmomath.ZeroBigDec(), osmomath.ZeroBigDec()
47+
perpetualFees, takerFees := math.LegacyZeroDec(), math.LegacyZeroDec()
48+
custodyAmount, _, slippageAmount, weightBreakingFee, perpetualFees, takerFees, err = k.EstimateSwapGivenIn(ctx, leveragedAmtTokenIn, mtp.CustodyAsset, *ammPool, mtp.Address)
4549
if err != nil {
4650
return err
4751
}
52+
k.CalculateAndEmitPerpetualFeesEvent(ctx, ammPool.PoolParams.UseOracle, leveragedAmtTokenIn, sdk.NewCoin(mtp.CustodyAsset, custodyAmount), slippageAmount, weightBreakingFee, perpetualFees, takerFees, osmomath.ZeroBigDec(), true)
4853
}
4954
case types.Position_SHORT:
5055
if mtp.CollateralAsset != baseCurrency {

x/perpetual/keeper/query_close_estimation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (k Keeper) HandleCloseEstimation(ctx sdk.Context, req *types.QueryCloseEsti
7777
closingRatio = req.CloseAmount.ToLegacyDec().Quo(maxCloseAmount.ToLegacyDec())
7878
}
7979

80-
repayAmount, payingLiabilities, slippage, weightBreakingFee, err := k.CalcRepayAmount(ctx, &mtp, &ammPool, closingRatio)
80+
repayAmount, payingLiabilities, slippage, _, weightBreakingFee, _, _, _, err := k.CalcRepayAmount(ctx, &mtp, &ammPool, closingRatio)
8181
if err != nil {
8282
return &types.QueryCloseEstimationResponse{}, err
8383
}

x/perpetual/keeper/query_open_estimation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (k Keeper) HandleOpenEstimation(ctx sdk.Context, req *types.QueryOpenEstima
129129
//getting custody
130130
if mtp.CollateralAsset == baseCurrency {
131131
leveragedAmtTokenIn := sdk.NewCoin(mtp.CollateralAsset, leveragedAmount)
132-
custodyAmount, slippage, weightBreakingFee, swapFees, takerFees, err = k.EstimateSwapGivenIn(ctx, leveragedAmtTokenIn, mtp.CustodyAsset, ammPool, req.Address)
132+
custodyAmount, slippage, _, weightBreakingFee, swapFees, takerFees, err = k.EstimateSwapGivenIn(ctx, leveragedAmtTokenIn, mtp.CustodyAsset, ammPool, req.Address)
133133
if err != nil {
134134
return nil, err
135135
}
@@ -142,7 +142,7 @@ func (k Keeper) HandleOpenEstimation(ctx sdk.Context, req *types.QueryOpenEstima
142142
//getting Liabilities
143143
if mtp.CollateralAsset != baseCurrency {
144144
amountIn := eta.MulInt(req.Collateral.Amount).TruncateInt()
145-
liabilities, slippage, weightBreakingFee, swapFees, takerFees, err = k.EstimateSwapGivenOut(ctx, sdk.NewCoin(req.Collateral.Denom, amountIn), baseCurrency, ammPool, req.Address)
145+
liabilities, slippage, _, weightBreakingFee, _, swapFees, takerFees, err = k.EstimateSwapGivenOut(ctx, sdk.NewCoin(req.Collateral.Denom, amountIn), baseCurrency, ammPool, req.Address)
146146
if err != nil {
147147
return nil, err
148148
}
@@ -158,7 +158,7 @@ func (k Keeper) HandleOpenEstimation(ctx sdk.Context, req *types.QueryOpenEstima
158158
// Collateral will be in base currency
159159
amountOut := eta.MulInt(req.Collateral.Amount).TruncateInt()
160160
tokenOut := sdk.NewCoin(baseCurrency, amountOut)
161-
liabilities, slippage, weightBreakingFee, swapFees, takerFees, err = k.EstimateSwapGivenOut(ctx, tokenOut, mtp.LiabilitiesAsset, ammPool, mtp.Address)
161+
liabilities, slippage, _, weightBreakingFee, _, swapFees, takerFees, err = k.EstimateSwapGivenOut(ctx, tokenOut, mtp.LiabilitiesAsset, ammPool, mtp.Address)
162162
if err != nil {
163163
return nil, err
164164
}

0 commit comments

Comments
 (0)