Uniswap / smart-order-router

GNU General Public License v3.0
406 stars 404 forks source link

Error: Convert JSBI instances to native numbers using `toNumber`. #58

Open fritzschoff opened 2 years ago

fritzschoff commented 2 years ago

If you are using the smart-order-router and calling the route function, when the router calculates the gas price by converting the liquidity in the pool into a number, it throws an error. See error stack V3HeuristicGasModelFactory.getHighestLiquidityUSDPool Pool address where this error ocurse is: 0x9957c4795ab663622db54fc48fda874da59150ff ChainId is 1

I assume the number is bigger than Number.MAX_SAFE_INTEGER?

Call Stack
JSBI.valueOf
node_modules/jsbi/dist/jsbi.mjs (1:1233)
baseGt
node_modules/@uniswap/smart-order-router/node_modules/lodash/lodash.js (3124:0)
baseExtremum
node_modules/@uniswap/smart-order-router/node_modules/lodash/lodash.js (2909:0)
Function.maxBy
node_modules/@uniswap/smart-order-router/node_modules/lodash/lodash.js (16407:0)
V3HeuristicGasModelFactory.getHighestLiquidityUSDPool
node_modules/@uniswap/smart-order-router/build/module/src/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.js (201:25)
async V3HeuristicGasModelFactory.buildGasModel
node_modules/@uniswap/smart-order-router/build/module/src/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.js (67:0)
async AlphaRouter.getV3Quotes
node_modules/@uniswap/smart-order-router/build/module/src/routers/alpha-router/alpha-router.js (370:0)
async AlphaRouter.route
node_modules/@uniswap/smart-order-router/build/module/src/routers/alpha-router/alpha-router.js (293:0)
willpote commented 2 years ago

Hmm any way I can reproduce this locally? Can you share your tokenIn/tokenOut/amount and any other config you are using

fritzschoff commented 2 years ago

follow this guide: https://docs.uniswap.org/sdk/guides/auto-router but with the pool address I provided

shreyaspapi commented 2 years ago

I am getting the same error, has anyone got a solution?

hrishibhattu commented 2 years ago

Same issue, any solutions?

hrishibhattu commented 2 years ago

@willpote I'm also following the guide: https://docs.uniswap.org/sdk/guides/auto-router

Here's some of my code:

import { AlphaRouter } from '@uniswap/smart-order-router';
import { Token, CurrencyAmount, TradeType, Percent } from '@uniswap/sdk-core';
import { JSBI } from '@uniswap/sdk';

const provider = new ethers.providers.JsonRpcProvider('https://polygon-mainnet<...link>', 137);
const router = new AlphaRouter({ chainId: 137, provider });

const typedValueParsed = '10000000000000';
const usdcxAmount = CurrencyAmount.fromRawAmount(MATIC, JSBI.BigInt(typedValueParsed));

const route = router.route(
    usdcxAmount,
    USDC,
    TradeType.EXACT_INPUT,
    {
      recipient: address,
      slippageTolerance: new Percent(5, 100),
      deadline: 100,
    },
);

The error I get is:

Uncaught (in promise) Error: Convert JSBI instances to native numbers using `toNumber`.
    at a.value (jsbi.mjs:79:1)
    at baseGt (lodash.js:3124:1)
    at baseExtremum (lodash.js:2907:1)
    at Function.maxBy (lodash.js:16406:1)
    at V3HeuristicGasModelFactory.getHighestLiquidityUSDPool (v3-heuristic-gas-model.ts:429:1)
    at async V3HeuristicGasModelFactory.buildGasModel (v3-heuristic-gas-model.ts:67:1)
    at async AlphaRouter.route (alpha-router.ts:814:1)

Any help would be greatly appreciated 😄

hack3r-0m commented 2 years ago

any updates?

hack3r-0m commented 2 years ago

Apparently, when you explicitly install JSBI, the major version is v4 while one compatible with uniswap SDK is v3, downgrading fixed the issue for me. consider adding it to peerDependencies

vaske commented 1 year ago

Any news about this one? Still getting it with v3 SDK version 🤔

Luca-Blight commented 3 months ago

Same issue came up for me using Trade.bestTradeExactIn, as pointed out earlier downgrading jsbi to version 3 solved the issue. Specifically I am using v3.2.5.