Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slippage amount and APR nan fixes #1050

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/amm/keeper/keeper_swap_exact_amount_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountIn() {

track := suite.app.AmmKeeper.GetSlippageTrack(suite.ctx, 1, uint64(suite.ctx.BlockTime().Unix()))
if tc.isOraclePool {
suite.Require().Equal(track.Tracked.String(), "25uusdc")
suite.Require().Equal(track.Tracked.String(), "50uusdc")
} else {
suite.Require().Equal(track.Tracked.String(), "")
}
Expand Down
2 changes: 1 addition & 1 deletion x/amm/keeper/keeper_swap_exact_amount_out_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (suite *AmmKeeperTestSuite) TestSwapExactAmountOut() {

track := suite.app.AmmKeeper.GetSlippageTrack(suite.ctx, 1, uint64(suite.ctx.BlockTime().Unix()))
if tc.isOraclePool {
suite.Require().Equal(track.Tracked.String(), "11112uusda")
suite.Require().Equal(track.Tracked.String(), "22224uusda")
} else {
suite.Require().Equal(track.Tracked.String(), "")
}
Expand Down
2 changes: 1 addition & 1 deletion x/amm/keeper/query_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (k Keeper) PoolExtraInfo(ctx sdk.Context, pool types.Pool) types.PoolExtraI
avg := k.GetWeightBreakingSlippageAvg(ctx, pool.PoolId)
apr := math.LegacyZeroDec()
if tvl.IsPositive() {
apr = avg.Mul(math.LegacyNewDec(52)).Quo(tvl)
apr = avg.Mul(math.LegacyNewDec(365)).Quo(tvl)
}
return types.PoolExtraInfo{
Tvl: tvl,
Expand Down
3 changes: 2 additions & 1 deletion x/amm/types/swap_in_amt_given_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func (p *Pool) SwapInAmtGivenOut(
return sdk.Coin{}, sdkmath.LegacyOneDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), err
}
inAmountAfterSlippage := oracleInAmount.Add(slippageAmount.Mul(externalLiquidityRatio))
slippage = slippageAmount.Mul(externalLiquidityRatio).Quo(oracleInAmount)
slippageAmount = slippageAmount.Mul(externalLiquidityRatio)
slippage = slippageAmount.Quo(oracleInAmount)

// calculate weight distance difference to calculate bonus/cut on the operation
newAssetPools, err := p.NewPoolAssetsAfterSwap(ctx,
Expand Down
3 changes: 2 additions & 1 deletion x/amm/types/swap_out_amt_given_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ func (p *Pool) SwapOutAmtGivenIn(
return sdk.Coin{}, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), err
}
outAmountAfterSlippage := oracleOutAmount.Sub(slippageAmount.Mul(externalLiquidityRatio))
slippage = slippageAmount.Mul(externalLiquidityRatio).Quo(oracleOutAmount)
slippageAmount = slippageAmount.Mul(externalLiquidityRatio)
slippage = slippageAmount.Quo(oracleOutAmount)

// oracleOutAmount = 100 ATOM
// BalancerOutAmount = 95 ATOM
Expand Down
8 changes: 6 additions & 2 deletions x/masterchef/keeper/apr_denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@
return math.LegacyZeroDec(), nil
}

// Mutiply by 52 to get yearly rewards
yearlyDexRewardAmount := usdcAmount.Mul(math.LegacyNewDec(52))
// Mutiply by 365 to get yearly rewards
entry, found := k.assetProfileKeeper.GetEntry(ctx, ptypes.BaseCurrency)
if !found {
return math.LegacyZeroDec(), assetprofiletypes.ErrAssetProfileNotFound
}
yearlyDexRewardAmount := usdcAmount.Mul(math.LegacyNewDec(365)).Quo(math.LegacyNewDec(int64(entry.Decimals)))

Check warning on line 111 in x/masterchef/keeper/apr_denom.go

View check run for this annotation

Codecov / codecov/patch

x/masterchef/keeper/apr_denom.go#L107-L111

Added lines #L107 - L111 were not covered by tests

apr := yearlyDexRewardAmount.
Quo(edenDenomPrice).
Expand Down
Loading