Skip to content

Commit

Permalink
Adding check for possible 0 values which can cause decimal division b…
Browse files Browse the repository at this point in the history
…y 0 error in pricing service. (#745)

Signed-off-by: Nikolay Nedkov <[email protected]>

Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Nikolay Nedkov authored Sep 29, 2022
1 parent e5a685c commit 8403d45
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/services/pricing/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,17 @@ func (s *Service) updateHbarPrice(results fetchResults) error {
}

func (s *Service) calculateMinAmountWithFee(nativeAsset *asset.NativeAsset, decimals uint8, priceInUsd decimal.Decimal) (minAmountWithFee *big.Int, err error) {
if priceInUsd.Cmp(decimal.NewFromFloat(0.0)) <= 0 {
return nil, fmt.Errorf("price in USD [%s] for NativeAsset [%s] must be a positive number", priceInUsd.String(), nativeAsset.Asset)
}
if nativeAsset.MinFeeAmountInUsd.Equal(decimal.NewFromFloat(0.0)) {
return big.NewInt(0), nil
}

feePercentageBigInt := big.NewInt(nativeAsset.FeePercentage)
if feePercentageBigInt.Cmp(big.NewInt(0)) <= 0 {
return nil, fmt.Errorf("FeePercentage [%d] for NativeAsset [%s] must be a positive number", nativeAsset.FeePercentage, nativeAsset.Asset)
}
minFeeAmountMultiplier, err := decimal.NewFromString(big.NewInt(0).Div(constants.FeeMaxPercentageBigInt, feePercentageBigInt).String())
if err != nil {
return nil, err
Expand Down

0 comments on commit 8403d45

Please sign in to comment.