Skip to content

Commit 65b2e38

Browse files
amityadav0avkr003
andauthored
[Amm]: Query fixes (#1273)
fixes Co-authored-by: Abhinav Kumar <57705190+avkr003@users.noreply.github.com>
1 parent fbf0f61 commit 65b2e38

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

x/amm/keeper/calc_in_route_spot_price.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (k Keeper) CalcInRouteSpotPrice(ctx sdk.Context,
8181
rebalanceTreasuryAddr := sdk.MustAccAddressFromBech32(pool.GetRebalanceTreasury())
8282
treasuryTokenAmount := k.bankKeeper.GetBalance(ctx, rebalanceTreasuryAddr, tokenOut.Denom).Amount
8383

84-
bonusTokenAmount := oracleOutAmount.Mul(weightBalanceBonus).Dec().TruncateInt()
84+
bonusTokenAmount = oracleOutAmount.Mul(weightBalanceBonus).Dec().TruncateInt()
8585

8686
if treasuryTokenAmount.LT(bonusTokenAmount) {
8787
weightBalanceBonus = osmomath.BigDecFromSDKInt(treasuryTokenAmount).Quo(oracleOutAmount)
@@ -114,7 +114,7 @@ func (k Keeper) CalcInRouteSpotPrice(ctx sdk.Context,
114114
poolAsset.Token.Amount = accAmount
115115
}
116116
availableLiquidity = poolAsset.Token
117-
weightBalance = weightBalanceBonus
117+
weightBalance = weightBalance.Add(weightBalanceBonus)
118118
slippage = slippage.Add(swapSlippage)
119119
}
120120

x/amm/keeper/calc_out_route_spot_price.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (k Keeper) CalcOutRouteSpotPrice(ctx sdk.Context, tokenOut sdk.Coin, routes
6262
rebalanceTreasuryAddr := sdk.MustAccAddressFromBech32(pool.GetRebalanceTreasury())
6363
treasuryTokenAmount := k.bankKeeper.GetBalance(ctx, rebalanceTreasuryAddr, tokenOut.Denom).Amount
6464

65-
bonusTokenAmount := osmomath.BigDecFromSDKInt(tokenOut.Amount).Mul(weightBalanceBonus).Dec().TruncateInt()
65+
bonusTokenAmount = osmomath.BigDecFromSDKInt(tokenOut.Amount).Mul(weightBalanceBonus).Dec().TruncateInt()
6666

6767
if treasuryTokenAmount.LT(bonusTokenAmount) {
6868
weightBalanceBonus = osmomath.BigDecFromSDKInt(treasuryTokenAmount).Quo(osmomath.BigDecFromSDKInt(tokenOut.Amount))
@@ -90,7 +90,7 @@ func (k Keeper) CalcOutRouteSpotPrice(ctx sdk.Context, tokenOut sdk.Coin, routes
9090
return osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), sdk.Coin{}, osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), sdk.Coin{}, osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), err
9191
}
9292
availableLiquidity = poolAsset.Token
93-
weightBonus = weightBalanceBonus
93+
weightBonus = weightBonus.Add(weightBalanceBonus)
9494
slippage = slippage.Add(swapSlippage)
9595
}
9696

x/amm/keeper/query_swap_estimation_by_denom.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package keeper
33
import (
44
"context"
55

6-
sdkmath "cosmossdk.io/math"
7-
86
errorsmod "cosmossdk.io/errors"
97
sdk "github.com/cosmos/cosmos-sdk/types"
108
"github.com/elys-network/elys/x/amm/types"
@@ -38,12 +36,6 @@ func (k Keeper) SwapEstimationByDenom(goCtx context.Context, req *types.QuerySwa
3836
if err != nil {
3937
return nil, err
4038
}
41-
recoveryReward := sdkmath.ZeroInt()
42-
if weightBonus.IsPositive() {
43-
recoveryReward = osmomath.BigDecFromSDKInt(amount.Amount).Mul(weightBonus).Dec().TruncateInt()
44-
}
45-
// Add weight balance amount here, not added in execution as out amount will be changed and that will impact the transfers
46-
amount.Amount = amount.Amount.Add(recoveryReward)
4739

4840
// Even when multiple routes, taker Fee per route is params.TakerFee/TotalRoutes, so net taker fee will be params.TakerFee
4941
takerFees := k.parameterKeeper.GetParams(ctx).TakerFees
@@ -60,7 +52,5 @@ func (k Keeper) SwapEstimationByDenom(goCtx context.Context, req *types.QuerySwa
6052
WeightBalanceRatio: weightBonus.Dec(),
6153
PriceImpact: priceImpact.Dec(),
6254
TakerFee: takerFees,
63-
// sdk.NewCoin() will panic in case of negative weightBonus
64-
WeightBalanceRewardAmount: sdk.Coin{Denom: amount.Denom, Amount: recoveryReward},
6555
}, nil
6656
}

0 commit comments

Comments
 (0)