Uniswap / v3-sdk

🛠 An SDK for building applications on top of Uniswap V3
MIT License
555 stars 431 forks source link

NonfungiblePositionManager.removeCallParameters() assumes the position liquidity is a fraction #87

Open eliotstock opened 3 years ago

eliotstock commented 3 years ago

Partial stack trace:

/home/e/r/node_modules/@uniswap/sdk-core/src/entities/fractions/fraction.ts:38
    throw new Error('Could not parse fraction')
          ^
Error: Could not parse fraction
    at Function.tryParseFraction (/home/e/r/node_modules/@uniswap/sdk-core/src/entities/fractions/fraction.ts:38:11)
    at Percent.multiply (/home/e/r/node_modules/@uniswap/sdk-core/src/entities/fractions/fraction.ts:108:34)
    at Percent.multiply (/home/e/r/node_modules/@uniswap/sdk-core/src/entities/fractions/percent.ts:30:21)
    at Function.removeCallParameters (/home/e/r/node_modules/@uniswap/v3-sdk/src/nonfungiblePositionManager.ts:364:46)

Steps to repro:

Also note that the docs don't explain how to get hold of an existing v3 position for passing to removeCallParameters()

jwthanh commented 3 years ago

@eliotstock did you resolve the issue or get more information?

eliotstock commented 3 years ago

I did not resolve the issue, nor get more info, sorry.

jwthanh commented 3 years ago

I did not resolve the issue, nor get more info, sorry.

@eliotstock Could you provide more detail your first step when you create v3 position programmatically? Are you using the factory contract which is deployed by Uniswap or you deploy your own contract?

eliotstock commented 2 years ago

Sure. Here's what I do to create the position:

      const position = Position.fromAmounts({
        pool: rangeOrderPool,
        tickLower: this.minTick,
        tickUpper: this.maxTick,
        amount0: availableUsdc,
        amount1: availableWeth,
        useFullPrecision: true
      })

      const mintOptions: MintOptions = {
        slippageTolerance: CHAIN_CONFIG.slippageTolerance,
        deadline: moment().unix() + DEADLINE_SECONDS,
        recipient: wallet.address,
        createPool: false
      }

      const { calldata, value } = NonfungiblePositionManager.addCallParameters(position, mintOptions)

      const nonce = await wallet.getTransactionCount("latest")

      const txRequest = {
        from: wallet.address,
        to: CHAIN_CONFIG.addrPositionManager,
        value: VALUE_ZERO_ETHER,
        nonce: nonce,
        gasLimit: CHAIN_CONFIG.gasLimit,
        gasPrice: CHAIN_CONFIG.gasPrice,
        data: calldata
      }

      const txResponse: TransactionResponse = await wallet.sendTransaction(txRequest)

      const txReceipt: TransactionReceipt = await txResponse.wait()
marktoda commented 2 years ago

Hey EliotStock - I know it's been awhile, but are you still having this issue? If so, it would be helpful to know what version of the SDK you're using

eliotstock commented 2 years ago

Haven't been running this code lately, sorry. At the time I was using these versions:

  "dependencies": {
    "@uniswap/sdk-core": "^3.0.1",
    "@uniswap/v3-core": "^1.0.0",
    "@uniswap/v3-sdk": "^3.5.1",
   ...
  },
bfinance commented 1 year ago

im having issues minting a position with nonfungiblePositionManager. and this dont work for me on mainnet hardhat fork: const { Pool, Position, Route, TickMath, nearestUsableTick, tickSpacing } = require('@uniswap/v3-sdk');