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

Open Beginner friendly
#622 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
typescript
Domain
blockchain

Research direction

Read src/connectors/uniswap/clmm-routes/openPosition.ts and reproduce the issue with gateway lp uniswap/clmm add-liquidity using an amount whose raw value exceeds 1e20. Trace the raw amount conversion and verify that adding liquidity succeeds for values that previously produced scientific notation.

Written by the indexing model from the issue text.

Description

bug
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

Dominant language
TypeScript
Stars
261
Forks
289
Avg merge
4d 1h
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from hummingbot/gateway

All issues in hummingbot/gateway

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.