Skip to content

Adding liquidity with Uniswap CLMM connector fails for amounts greater than 1e20 #622

@BrentleyDrop

Description

@BrentleyDrop

Describe the bug

The Javascript number toString() method defaults to scientific notation for values greater than 1e20 (this could be an amount as low as 1,000 for a token with 18 decimals). However, the JSBI.BigInt constructor throws an error on these values because it does not recognize values in scientific notation. The error occurs in this block of code within src/connectors/uniswap/clmm-routes/openPosition.ts:

if (baseTokenAmount !== undefined) {
  const baseAmountRaw = Math.floor(baseTokenAmount * Math.pow(10, baseTokenObj.decimals));
  if (isBaseToken0) {
    token0Amount = CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(baseAmountRaw.toString()));
  } else {
    token1Amount = CurrencyAmount.fromRawAmount(token1, JSBI.BigInt(baseAmountRaw.toString()));
  }
}

Using .toLocaleString('fullwide', { useGrouping: false }) fixes it.

Steps to reproduce

  1. Start hummingbot with gateway and run the following command: gateway lp uniswap/clmm add-liquidity
  2. Specify an amount such that raw amount (amount * 10 ^ token_decimals) is greater than 1e20

Release version

dev-2.12.0

Type of installation

Source

Attach required files

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions