Skip to content

Commit

Permalink
fix: handle density = 0 in Density.getMaximumGasForRawOutbound (#1803)
Browse files Browse the repository at this point in the history
  • Loading branch information
espendk authored Feb 26, 2024
1 parent 5bbf9bc commit d8ccd18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/util/Density.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d8ccd18

Please sign in to comment.