Skip to content

Commit

Permalink
add div by zero check
Browse files Browse the repository at this point in the history
  • Loading branch information
99adarsh committed Dec 9, 2024
1 parent 72b5aa5 commit 4d6a756
Showing 1 changed file with 4 additions and 0 deletions.
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 @@ func MaximalExactRatioJoin(p *Pool, tokensIn sdk.Coins) (numShares sdkmath.Int,
// 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

0 comments on commit 4d6a756

Please sign in to comment.