smart-order-router icon indicating copy to clipboard operation
smart-order-router copied to clipboard

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

Open fritzschoff opened this issue 3 years ago • 9 comments

  • I'm submitting a ... [ x ] bug report [ ] feature request [ ] question about the decisions made in the repository [ ] question about how to use this project

  • Summary

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?

  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
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)

fritzschoff avatar Jan 31 '22 13:01 fritzschoff

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

willpote avatar Feb 02 '22 15:02 willpote

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

fritzschoff avatar Feb 02 '22 21:02 fritzschoff

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

shreyaspapi avatar Mar 04 '22 20:03 shreyaspapi

Same issue, any solutions?

hrishibhattu avatar Mar 05 '22 06:03 hrishibhattu

@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 😄

hrishibhattu avatar Mar 05 '22 09:03 hrishibhattu

any updates?

hack3r-0m avatar Apr 27 '22 04:04 hack3r-0m

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

hack3r-0m avatar Apr 27 '22 10:04 hack3r-0m

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

vaske avatar Feb 01 '23 12:02 vaske

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.

Luca-Blight avatar Jun 04 '24 23:06 Luca-Blight