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

add div by zero check #1051

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
4 changes: 4 additions & 0 deletions x/amm/types/pool_calc_join_pool_no_swap_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
// Note: QuoInt implements floor division, unlike Quo
// This is because it calls the native golang routine big.Int.Quo
// https://pkg.go.dev/math/big#Int.Quo
// Division by zero check
if poolLiquidity.AmountOfNoDenomValidation(coin.Denom).IsZero() {
return numShares, remCoins, errors.New("pool liquidity is zero for denom: " + coin.Denom)
}

Check warning on line 37 in x/amm/types/pool_calc_join_pool_no_swap_shares.go

View check run for this annotation

Codecov / codecov/patch

x/amm/types/pool_calc_join_pool_no_swap_shares.go#L34-L37

Added lines #L34 - L37 were not covered by tests
shareRatio := sdkmath.LegacyNewDecFromBigInt(coin.Amount.BigInt()).QuoInt(poolLiquidity.AmountOfNoDenomValidation(coin.Denom))
if shareRatio.LT(minShareRatio) {
minShareRatio = shareRatio
Expand Down
Loading