Skip to content

Commit 34b4f88

Browse files
authored
fixing int and dec conversions (#1240)
* fixing int and dec conversions * changes for devnet
1 parent fa76c0c commit 34b4f88

12 files changed

+13
-15
lines changed

app/setup_handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (app *ElysApp) setUpgradeHandler() {
7777
//}
7878

7979
// Set cosmwasm params
80-
if !strings.Contains(plan.Name, "v3-rc") && plan.Name != "v999999" {
80+
if plan.Name == "v3" {
8181
wasmParams := wasmTypes.DefaultParams()
8282
wasmParams.CodeUploadAccess = wasmTypes.AllowNobody
8383
wasmParams.InstantiateDefaultPermission = wasmTypes.AccessTypeNobody
@@ -104,7 +104,7 @@ func (app *ElysApp) setUpgradeStore() {
104104

105105
app.Logger().Debug("Upgrade info", "info", upgradeInfo)
106106

107-
if shouldLoadUpgradeStore(app, upgradeInfo) && !strings.Contains(upgradeInfo.Name, "v3-rc") && upgradeInfo.Name != "v999999" {
107+
if shouldLoadUpgradeStore(app, upgradeInfo) && upgradeInfo.Name == "v3" {
108108
storeUpgrades := storetypes.StoreUpgrades{
109109
Added: []string{wasmTypes.StoreKey},
110110
//Added: []string{},

x/amm/keeper/apply_join_pool_state_change.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (k Keeper) ApplyJoinPoolStateChange(
8484

8585
// Track amount in pool
8686
weightRecoveryFeeForPool := weightBalanceBonus.Abs().Mul(sdkmath.LegacyOneDec().Sub(params.WeightBreakingFeePortion))
87-
k.TrackWeightBreakingSlippage(ctx, pool.PoolId, sdk.NewCoin(coin.Denom, sdkmath.Int(weightRecoveryFeeForPool.Mul(weightRecoveryFeeAmount.ToLegacyDec()))))
87+
k.TrackWeightBreakingSlippage(ctx, pool.PoolId, sdk.NewCoin(coin.Denom, weightRecoveryFeeForPool.Mul(coin.Amount.ToLegacyDec()).TruncateInt()))
8888
}
8989
}
9090
}

x/amm/keeper/create_multihop_expected_swap_outs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (k Keeper) createMultihopExpectedSwapOuts(
3232
return nil, err
3333
}
3434

35-
insExpected[i] = math.Int(tokenIn.Amount)
35+
insExpected[i] = tokenIn.Amount
3636
tokenOut = tokenIn
3737
}
3838

x/amm/keeper/msg_server_swap_exact_amount_in.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package keeper
33
import (
44
"context"
55

6-
sdkmath "cosmossdk.io/math"
76
sdk "github.com/cosmos/cosmos-sdk/types"
87
"github.com/elys-network/elys/x/amm/types"
98
)
@@ -35,7 +34,7 @@ func (k Keeper) SwapExactAmountIn(ctx sdk.Context, msg *types.MsgSwapExactAmount
3534
}
3635
// Try executing the tx on cached context environment, to filter invalid transactions out
3736
cacheCtx, _ := ctx.CacheContext()
38-
tokenOutAmount, swapFee, discount, err := k.RouteExactAmountIn(cacheCtx, sender, recipient, msg.Routes, msg.TokenIn, sdkmath.Int(msg.TokenOutMinAmount))
37+
tokenOutAmount, swapFee, discount, err := k.RouteExactAmountIn(cacheCtx, sender, recipient, msg.Routes, msg.TokenIn, msg.TokenOutMinAmount)
3938
if err != nil {
4039
return nil, err
4140
}

x/amm/keeper/msg_server_upfront_swap_exact_amount_in.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"slices"
77

8-
sdkmath "cosmossdk.io/math"
98
sdk "github.com/cosmos/cosmos-sdk/types"
109
"github.com/elys-network/elys/x/amm/types"
1110
)
@@ -37,7 +36,7 @@ func (k Keeper) UpFrontSwapExactAmountIn(ctx sdk.Context, msg *types.MsgUpFrontS
3736
return nil, types.ErrUnauthorizedUpFrontSwap
3837
}
3938

40-
tokenOutAmount, swapFee, discount, err := k.RouteExactAmountIn(ctx, sender, sender, msg.Routes, msg.TokenIn, sdkmath.Int(msg.TokenOutMinAmount))
39+
tokenOutAmount, swapFee, discount, err := k.RouteExactAmountIn(ctx, sender, sender, msg.Routes, msg.TokenIn, msg.TokenOutMinAmount)
4140
if err != nil {
4241
return nil, err
4342
}

x/amm/keeper/msg_server_upfront_swap_exact_amount_in_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (suite *AmmKeeperTestSuite) TestUpFrontSwapExactAmountIn() {
2727
Sender: "cosmos1xv9tklw7d82sezh9haa573wufgy59vmwe6xxe5",
2828
Routes: []types.SwapAmountInRoute{},
2929
TokenIn: sdk.NewCoin("tokenA", sdkmath.NewInt(100)),
30-
TokenOutMinAmount: sdkmath.Int(sdkmath.LegacyMustNewDecFromStr("50")),
30+
TokenOutMinAmount: sdkmath.NewInt(50),
3131
}
3232
_, err := suite.app.AmmKeeper.UpFrontSwapExactAmountIn(suite.ctx, msg)
3333
return err

x/amm/keeper/update_pool_for_swap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (k Keeper) UpdatePoolForSwap(
193193

194194
// convert the fees into USD
195195
swapFeeValueInUSD := k.CalculateCoinsUSDValue(ctx, swapFeeInCoins).String()
196-
slippageAmountInUSD := k.CalculateUSDValue(ctx, tokenIn.Denom, sdkmath.Int(slippageAmount)).String()
196+
slippageAmountInUSD := k.CalculateUSDValue(ctx, tokenIn.Denom, slippageAmount.TruncateInt()).String()
197197
weightRecoveryFeeAmountInUSD := k.CalculateUSDValue(ctx, tokenIn.Denom, weightRecoveryFeeAmount).String()
198198
bonusTokenAmountInUSD := k.CalculateUSDValue(ctx, tokenOut.Denom, bonusTokenAmount).String()
199199
takerFeesAmountInUSD := k.CalculateCoinsUSDValue(ctx, takerFeesInCoins).String()

x/leveragelp/keeper/position_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func TestIteratePoolPosIdsStopLossSorted(t *testing.T) {
204204
Liabilities: math.NewInt(0),
205205
AmmPoolId: info.PoolId,
206206
PositionHealth: math.LegacyNewDec(0),
207-
StopLossPrice: math.LegacyDec(info.StopLossPrice),
207+
StopLossPrice: info.StopLossPrice,
208208
}
209209
leveragelp.SetPosition(ctx, &position)
210210
}

x/leveragelp/keeper/query_get_position_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (suite *KeeperTestSuite) TestQueryGetPosition() {
109109
PositionUsdValue: sdkmath.LegacyMustNewDecFromStr("0.004940470091100279"),
110110
},
111111
InterestRateHour: sdkmath.LegacyMustNewDecFromStr("0.000017123287671233"),
112-
InterestRateHourUsd: sdkmath.LegacyZeroDec(),
112+
InterestRateHourUsd: sdkmath.LegacyMustNewDecFromStr("0.000000068493152000"),
113113
}
114114
pos_for_address_res, _ := k.QueryPositionsForAddress(suite.ctx, &types.PositionsForAddressRequest{Address: addr.String(), Pagination: nil})
115115

x/leveragelp/keeper/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (k Keeper) GetInterestRateUsd(ctx sdk.Context, positions []*types.QueryPosi
130130
price := k.oracleKeeper.GetAssetPriceFromDenom(ctx, position.Position.Collateral.Denom)
131131
interestRateHour := pool.InterestRate.Quo(hours)
132132
positionAndInterest.InterestRateHour = interestRateHour
133-
positionAndInterest.InterestRateHourUsd = interestRateHour.Mul(sdkmath.LegacyDec(position.Position.Liabilities.Mul(price.RoundInt())))
133+
positionAndInterest.InterestRateHourUsd = interestRateHour.Mul(price).Mul(position.Position.Liabilities.ToLegacyDec())
134134
positions_and_interest = append(positions_and_interest, &positionAndInterest)
135135
}
136136

0 commit comments

Comments
 (0)