diff --git a/types/utils.go b/types/utils.go index 278507222..777c06daa 100644 --- a/types/utils.go +++ b/types/utils.go @@ -21,7 +21,7 @@ import ( // GetShareValue multiplies with truncation by receiving int amount and decimal ratio and returns int result. func GetShareValue(amount sdkmath.Int, ratio sdkmath.LegacyDec) sdkmath.Int { - return sdkmath.LegacyNewDec(amount.Int64()).MulTruncate(ratio).TruncateInt() + return amount.ToLegacyDec().MulTruncate(ratio).TruncateInt() } type StrIntMap map[string]sdkmath.Int diff --git a/x/liquidity/amm/match.go b/x/liquidity/amm/match.go index 2d645674e..a5594062d 100644 --- a/x/liquidity/amm/match.go +++ b/x/liquidity/amm/match.go @@ -344,8 +344,8 @@ func DistributeOrderAmountToOrders(orders []Order, amt sdkmath.Int, price sdkmat if matchableAmt.IsZero() { continue } - orderAmt := sdkmath.LegacyNewDec(order.GetAmount().Int64()) - proportion := orderAmt.QuoTruncate(sdkmath.LegacyNewDec(totalAmt.Int64())) + orderAmt := order.GetAmount().ToLegacyDec() + proportion := orderAmt.QuoTruncate(totalAmt.ToLegacyDec()) matchedAmt := sdkmath.MinInt(matchableAmt, proportion.MulInt(amt).TruncateInt()) if matchedAmt.IsPositive() { matchedAmtByOrder[order] = matchedAmt diff --git a/x/liquidity/amm/util.go b/x/liquidity/amm/util.go index 958308903..ccf0c00ee 100644 --- a/x/liquidity/amm/util.go +++ b/x/liquidity/amm/util.go @@ -36,7 +36,7 @@ func MatchableAmount(order Order, price sdkmath.LegacyDec) (matchableAmt sdkmath remainingOfferCoinAmt := order.GetOfferCoinAmount().Sub(order.GetPaidOfferCoinAmount()) matchableAmt = sdkmath.MinInt( order.GetOpenAmount(), - sdkmath.LegacyNewDec(remainingOfferCoinAmt.Int64()).QuoTruncate(price).TruncateInt(), + remainingOfferCoinAmt.ToLegacyDec().QuoTruncate(price).TruncateInt(), ) case Sell: matchableAmt = order.GetOpenAmount() diff --git a/x/liquidity/keeper/pool.go b/x/liquidity/keeper/pool.go index df74a5393..bbdf608b8 100644 --- a/x/liquidity/keeper/pool.go +++ b/x/liquidity/keeper/pool.go @@ -738,11 +738,11 @@ func (k Keeper) TransferFundsForSwapFeeDistribution(ctx sdk.Context, appID, requ } requestedPoolShare := poolLiquidityMap[requestedPoolID].Quo(totalLiquidity) - eligibleSwapFeeAmount := requestedPoolShare.Mul(sdkmath.LegacyNewDec(availableBalance.Amount.Int64())) + eligibleSwapFeeAmount := requestedPoolShare.Mul(availableBalance.Amount.ToLegacyDec()) availableBalance.Amount = eligibleSwapFeeAmount.RoundInt() } - burnAmount := sdkmath.LegacyNewDec(availableBalance.Amount.Int64()).MulTruncate(params.SwapFeeBurnRate).TruncateInt() + burnAmount := availableBalance.Amount.ToLegacyDec().MulTruncate(params.SwapFeeBurnRate).TruncateInt() burnCoin := sdk.NewCoin(availableBalance.Denom, burnAmount) if burnCoin.Amount.IsPositive() { @@ -798,12 +798,12 @@ func (k Keeper) WasmMsgAddEmissionPoolRewards(ctx sdk.Context, appID, cswapAppID moduleAddr := k.accountKeeper.GetModuleAddress(types.ModuleName) farmedCoins := k.bankKeeper.GetBalance(ctx, moduleAddr, pool.PoolCoinDenom) individualVote := votingRatio[j] - votingR := sdkmath.LegacyNewDec(individualVote.Int64()).Quo(sdkmath.LegacyNewDec(totalVote.Int64())) - shareByPool := votingR.Mul(sdkmath.LegacyNewDec(amount.Int64())) + votingR := individualVote.ToLegacyDec().Quo(totalVote.ToLegacyDec()) + shareByPool := votingR.Mul(amount.ToLegacyDec()) if farmedCoins.IsZero() { continue } - perUserShareByAmtDec := shareByPool.Quo(sdkmath.LegacyNewDec(farmedCoins.Amount.Int64())) + perUserShareByAmtDec := shareByPool.Quo(farmedCoins.Amount.ToLegacyDec()) allActiveFarmer := k.GetAllActiveFarmers(ctx, cswapAppID, extP) for _, farmerDetail := range allActiveFarmer { diff --git a/x/liquidity/keeper/swap.go b/x/liquidity/keeper/swap.go index 12e2c413e..7bd5313f4 100644 --- a/x/liquidity/keeper/swap.go +++ b/x/liquidity/keeper/swap.go @@ -15,7 +15,7 @@ import ( ) func CalculateSwapFeeAmount(ctx sdk.Context, params types.GenericParams, calculatedOfferCoinAmt sdkmath.Int) sdkmath.Int { - return sdkmath.LegacyNewDec(calculatedOfferCoinAmt.Int64()).MulTruncate(params.SwapFeeRate).TruncateInt() + return calculatedOfferCoinAmt.ToLegacyDec().MulTruncate(params.SwapFeeRate).TruncateInt() } func (k Keeper) PriceLimits(ctx sdk.Context, lastPrice sdkmath.LegacyDec, params types.GenericParams) (lowest, highest sdkmath.LegacyDec) { @@ -1002,7 +1002,7 @@ func (k Keeper) ConvertAccumulatedSwapFeesWithSwapDistrToken(ctx sdk.Context, ap switch orderDirection { case types.OrderDirectionBuy: maxPrice := lastPrice.Mul(sdkmath.LegacyOneDec().Add(params.MaxPriceLimitRatio)) - amount = sdkmath.LegacyNewDec(offerCoin.Amount.Int64()).Quo(maxPrice).TruncateInt() + amount = offerCoin.Amount.ToLegacyDec().Quo(maxPrice).TruncateInt() demandCoinDenom = swappablePair.BaseCoinDenom case types.OrderDirectionSell: amount = offerCoin.Amount diff --git a/x/liquidity/types/order.go b/x/liquidity/types/order.go index 41bafeef7..6862c9892 100644 --- a/x/liquidity/types/order.go +++ b/x/liquidity/types/order.go @@ -41,7 +41,7 @@ func NewUserOrder(order Order) *UserOrder { utils.SafeMath(func() { amt = sdk.MinInt( order.OpenAmount, - sdk.NewDec(order.RemainingOfferCoin.Amount.Int64()).QuoTruncate(order.Price).TruncateInt(), + order.RemainingOfferCoin.Amount.ToLegacyDec().QuoTruncate(order.Price).TruncateInt(), ) }, func() { amt = order.OpenAmount diff --git a/x/liquidity/types/util.go b/x/liquidity/types/util.go index 2fe43a878..a74ecdaf5 100644 --- a/x/liquidity/types/util.go +++ b/x/liquidity/types/util.go @@ -100,7 +100,7 @@ func NewPoolResponse(pool Pool, rx, ry sdk.Coin, poolCoinSupply sdk.Int) PoolRes // IsTooSmallOrderAmount returns whether the order amount is too small for // matching, based on the order price. func IsTooSmallOrderAmount(amt sdk.Int, price sdk.Dec) bool { - return amt.LT(amm.MinCoinAmount) || price.MulInt(amt).LT(sdk.NewDec(amm.MinCoinAmount.Int64())) + return amt.LT(amm.MinCoinAmount) || price.MulInt(amt).LT(amm.MinCoinAmount.ToLegacyDec()) } // PriceLimits returns the lowest and the highest price limits with given last price