Uniswap / smart-order-router

GNU General Public License v3.0
413 stars 420 forks source link

call router.route(), get TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) #659

Closed OneMore14 closed 3 months ago

OneMore14 commented 3 months ago

and here is my codes

const USDT_TOKEN = new Token(
    42161,
    '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', // https://arbiscan.io/address/0xaf88d065e77c8cc2239327c5edb3a432268e5831
    6,
    'USDT',
    'Tether USD'
)

const WETH_TOKEN = new Token(
    42161,  // a1 chain ID
    '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', // https://arbiscan.io/address/0x82af49447d8a07e3bd95bd0d56f35241523fbab1
    18,
    'WETH',
    'Wrapped Ether'
)

const rpcUrl = "https://arbitrum-mainnet.infura.io/v3/MY-TOKEN";

export async function v3() {
    const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
    const tokenA = USDT_TOKEN;
    const tokenB = WETH_TOKEN;

    const chainId = 42161;
    const router = new AlphaRouter({
        chainId: chainId,
        provider: provider,
    });
    const options: SwapOptionsUniversalRouter = {
        recipient: walletAddress,
        slippageTolerance: new Percent(50, 10_000),
        deadlineOrPreviousBlockhash: Math.floor(Date.now() / 1000 + 1800),
        type: SwapType.UNIVERSAL_ROUTER,
    }
    const route = await router.route(
        CurrencyAmount.fromRawAmount(tokenA, 10000000),
        tokenB,
        TradeType.EXACT_INPUT,
        options
    );
    console.log(route);
}

hope to get some hints about why it does not work, thanks

jfbloom22 commented 3 months ago

running into a similar error when trying to use this with Base Chain.

yusufseyrek commented 3 months ago

Same here.

I updated the package to v3.40.0 and it fixed the issue for me.

OneMore14 commented 3 months ago

Same here.

I updated the package to v3.40.0 and it fixed the issue for me.

It really helps! thank you !