From 7a05e8c08b0890ba53d71f456a7c16f0cdf4358e Mon Sep 17 00:00:00 2001 From: Cosmic Vagabond <121588426+cosmic-vagabond@users.noreply.github.com> Date: Mon, 12 Feb 2024 11:02:07 +0100 Subject: [PATCH] fix: negative amount set to decimal coin (#369) --- x/amm/keeper/calc_swap_estimation_by_denom.go | 2 +- x/incentive/keeper/keeper.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/x/amm/keeper/calc_swap_estimation_by_denom.go b/x/amm/keeper/calc_swap_estimation_by_denom.go index 5810de7a5..890832070 100644 --- a/x/amm/keeper/calc_swap_estimation_by_denom.go +++ b/x/amm/keeper/calc_swap_estimation_by_denom.go @@ -36,7 +36,7 @@ func (k Keeper) CalcSwapEstimationByDenom( // Initialize return variables inRoute, outRoute = nil, nil outAmount, availableLiquidity = sdk.Coin{}, sdk.Coin{} - spotPrice, swapFeeOut, discountOut, weightBonus, priceImpact = sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec() + spotPrice, swapFeeOut, discountOut, weightBonus, priceImpact = sdk.ZeroDec(), sdk.ZeroDec(), discount, sdk.ZeroDec(), sdk.ZeroDec() // Determine the correct route based on the amount's denom if amount.Denom == denomIn { diff --git a/x/incentive/keeper/keeper.go b/x/incentive/keeper/keeper.go index c78ede5e6..eff4f1314 100644 --- a/x/incentive/keeper/keeper.go +++ b/x/incentive/keeper/keeper.go @@ -286,6 +286,15 @@ func (k Keeper) UpdateStakersRewardsUnclaimed(ctx sdk.Context, stakeIncentive ty edenRemained := edenAmountPerEpochStakersPerDistribution.Sub(totalEdenGiven) dexRewardsRemained := dexRevenueStakersAmtPerDistribution.Sub(sdk.NewDecFromInt(totalRewardsGiven)) + // if edenRemained is negative, override it with zero + if edenRemained.IsNegative() { + edenRemained = sdk.ZeroInt() + } + // if dexRewardsRemained is negative, override it with zero + if dexRewardsRemained.IsNegative() { + dexRewardsRemained = sdk.ZeroDec() + } + // Fund community the remain coins // ---------------------------------- edenRemainedCoin := sdk.NewDecCoin(ptypes.Eden, edenRemained)