From d8ccd18c313a1b2fa74c2fe82d64f0ff37379a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20H=C3=B8jsgaard?= Date: Mon, 26 Feb 2024 16:45:42 +0100 Subject: [PATCH] fix: handle density = 0 in Density.getMaximumGasForRawOutbound (#1803) --- CHANGELOG.md | 1 + src/util/Density.ts | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2891b241..795ff3d72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Next version - Remove amplifier as param to class `MangroveAmplifier` +- fix: `Density.getMaximumGasForRawOutbound` can now handle density = 0 # 2.0.5-16 diff --git a/src/util/Density.ts b/src/util/Density.ts index 56260c5f8..b739c2584 100644 --- a/src/util/Density.ts +++ b/src/util/Density.ts @@ -1,5 +1,5 @@ import Big from "big.js"; -import { BigNumber, BigNumberish } from "ethers"; +import { BigNumber, BigNumberish, constants } from "ethers"; import * as DensityLib from "./coreCalculations/DensityLib"; const _2pow32 = Big(2).pow(32); @@ -131,6 +131,9 @@ export class Density { * @returns the maximum amount of gas an offer may require for the given raw amount of outbound tokens */ getMaximumGasForRawOutbound(rawOutboundAmt: BigNumberish): BigNumber { + if (this.isZero()) { + return constants.MaxUint256; + } const density96X32 = DensityLib.to96X32(this.#rawDensity); const densityDecimal = Big(density96X32.toString()).div(_2pow32); return BigNumber.from(