pancakeswap / pancake-frontend

:pancakes: Pancake main features (farms, pools, IFO, lottery, profiles)
https://pancakeswap.finance
GNU General Public License v3.0
2.65k stars 3.51k forks source link

SmartRouter onChainProvider client Type mismatch #9704

Open S1nPur1ty opened 2 months ago

S1nPur1ty commented 2 months ago

I am trying to solve the following:

Imports:

import {
  SmartRouter
} from "@pancakeswap/smart-router";

import { createPublicClient, http } from "viem";

import { bsc } from "viem/chains";

In here, I have my client var with the bsc info.

const client = createPublicClient({
  chain: bsc,
  transport: http("https://bsc-dataseed.binance.org/"),
  batch: {
    multicall: {
      batchSize: 1024 * 200,
    },
  },
});

And I call it like this:

const quoteProvider = SmartRouter.createQuoteProvider({
  onChainProvider: () => client,
});

However, I get to see this weird warning:

Type '{ account: undefined; batch?: { multicall?: boolean | { batchSize?: number | undefined; wait?: number | undefined; } | undefined; } | undefined; cacheTime: number; chain: Assign<{ readonly id: 56; ... 5 more ...; readonly contracts: { ...; }; }, ChainConfig<...>>; ... 53 more ...; extend: <const client extends { ......' is not assignable to type '{ account: undefined; batch?: { multicall?: boolean | { batchSize?: number | undefined; wait?: number | undefined; } | undefined; } | undefined; cacheTime: number; chain: Chain | undefined; ... 53 more ...; extend: <const client extends { ...; } & Partial<...>>(fn: (client: Client<...>) => client) => Client<...>; }'.
  Types of property 'chain' are incompatible.
    Type 'Assign<{ readonly id: 56; readonly name: "BNB Smart Chain"; readonly network: "bsc"; readonly nativeCurrency: { readonly decimals: 18; readonly name: "BNB"; readonly symbol: "BNB"; }; readonly rpcUrls: { ...; }; readonly blockExplorers: { ...; }; readonly contracts: { ...; }; }, ChainConfig<...>>' is not assignable to type 'Chain | undefined'.
      Type 'Assign<{ readonly id: 56; readonly name: "BNB Smart Chain"; readonly network: "bsc"; readonly nativeCurrency: { readonly decimals: 18; readonly name: "BNB"; readonly symbol: "BNB"; }; readonly rpcUrls: { ...; }; readonly blockExplorers: { ...; }; readonly contracts: { ...; }; }, ChainConfig<...>>' is not assignable to type 'Chain'.
        Type 'Assign<{ readonly id: 56; readonly name: "BNB Smart Chain"; readonly network: "bsc"; readonly nativeCurrency: { readonly decimals: 18; readonly name: "BNB"; readonly symbol: "BNB"; }; readonly rpcUrls: { ...; }; readonly blockExplorers: { ...; }; readonly contracts: { ...; }; }, ChainConfig<...>>' is not assignable to type 'ChainConfig<ChainFormatters | undefined>'.
          Types of property 'fees' are incompatible.
            Type 'ChainFees<undefined> | undefined' is not assignable to type 'ChainFees<ChainFormatters | undefined> | undefined'.
              Type 'ChainFees<undefined>' is not assignable to type 'ChainFees<ChainFormatters | undefined>'.
                Types of property 'baseFeeMultiplier' are incompatible.
                  Type 'number | ((args: ChainFeesFnParameters<undefined>) => number | Promise<number>) | undefined' is not assignable to type 'number | ((args: ChainFeesFnParameters<ChainFormatters | undefined>) => number | Promise<number>) | undefined'.
                    Type '(args: ChainFeesFnParameters<undefined>) => number | Promise<number>' is not assignable to type 'number | ((args: ChainFeesFnParameters<ChainFormatters | undefined>) => number | Promise<number>) | undefined'.
                      Type '(args: ChainFeesFnParameters<undefined>) => number | Promise<number>' is not assignable to type '(args: ChainFeesFnParameters<ChainFormatters | undefined>) => number | Promise<number>'.
                        Types of parameters 'args' and 'args' are incompatible.
                          Type 'ChainFeesFnParameters<ChainFormatters | undefined>' is not assignable to type 'ChainFeesFnParameters<undefined>'.
                            Types of property 'client' are incompatible.
                              Type 'import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/@pancakeswap/smart-router/node_modules/viem/_types/clients/createClient").Client<import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/@pancakeswap/smart-router/node_modules/viem/_types/clients/transports/createTransport"...' is not assignable to type 'import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/viem/_types/clients/createClient").Client<import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/viem/_types/clients/transports/createTransport").Transport, import("/Users/singular/Development/HappyGames/happy-game-web/nod...'.
                                Type 'Client<Transport, Chain<ChainFormatters | undefined>>' is not assignable to type 'Client_Base<Transport, Chain<ChainFormatters | undefined>, Account | undefined, undefined>'.
                                  Types of property 'account' are incompatible.
                                    Type 'import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/@pancakeswap/smart-router/node_modules/viem/_types/accounts/types").Account | undefined' is not assignable to type 'import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/viem/_types/accounts/types").Account | undefined'.
                                      Type 'LocalAccount<string, `0x${string}`>' is not assignable to type 'Account | undefined'.
                                        Type 'import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/@pancakeswap/smart-router/node_modules/viem/_types/accounts/types").LocalAccount<string, `0x${string}`>' is not assignable to type 'import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/viem/_types/accounts/types").LocalAccount<string, `0x${string}`>'.
                                          Type 'LocalAccount<string, `0x${string}`>' is not assignable to type 'CustomSource'.
                                            Types of property 'signTypedData' are incompatible.
                                              Type '<const TTypedData extends { [x: string]: readonly import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/viem/node_modules/abitype/dist/types/abi").TypedDataParameter[]; [x: `string[${string}]`]: undefined; [x: `function[${string}]`]: undefined; [x: `address[${string}]`]: undefined; [x: `bool[${s...' is not assignable to type '<const TTypedData extends { [x: string]: readonly import("/Users/singular/Development/HappyGames/happy-game-web/node_modules/viem/node_modules/abitype/dist/types/abi").TypedDataParameter[]; [x: `string[${string}]`]: undefined; [x: `function[${string}]`]: undefined; [x: `address[${string}]`]: undefined; [x: `bool[${s...'. Two different types with this name exist, but they are unrelated.
                                                Types of parameters 'typedData' and 'typedData' are incompatible.
                                                  Type 'TypedDataDefinition<TTypedData, TPrimaryType>' is not assignable to type 'TypedDataDefinition<TTypedData, string>'.
                                                    Type 'TypedDataDefinition<TTypedData, TPrimaryType>' is not assignable to type '{ [key_3: string]: any; } extends (TTypedData extends { [x: string]: readonly TypedDataParameter[]; [x: `string[${string}]`]: undefined; [x: `function[${string}]`]: undefined; [x: `address[${string}]`]: undefined; [x: `bool[${string}]`]: undefined; [x: `bytes[${string}]`]: undefined; [x: `bytes9[${string}]`]: undefi...'.ts(2322)
providers.d.ts(37, 31): The expected type comes from the return type of this signature.
Codeium: Explain Problem

const client: {
    account: undefined;
    batch?: {
        multicall?: boolean | {
            batchSize?: number | undefined;
            wait?: number | undefined;
        } | undefined;
    } | undefined;
    cacheTime: number;
    chain: Assign<{
        readonly id: 56;
        ... 5 more ...;
        readonly contracts: {
            ...;
        };
    }, ChainConfig<...>>;
    ... 53 more ...;
    extend: <const client extends {
        ...;
    } & Partial<...>>(fn: (client: Client<...>) => client) => Client<...>;
}

@chefjackson can you please take a look

chefjackson commented 1 month ago

Should be type mismatch after upgrading to viem v2

PancakeSwap-bot commented 3 weeks ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 2 days.