Anish-Agnihotri / pool-sniper

Uniswap V2-styled router new pool sniping in under 250 LOC.
The Unlicense
445 stars 130 forks source link

UniswapError: chainId can not be found on the provider #2

Closed JanOwiesniak closed 2 years ago

JanOwiesniak commented 3 years ago

node version v14.18.0

npm version v6.14.15

issue running npm run-script dev results in

UniswapError: chainId can not be found on the provider
...
at Sniper.<anonymous> (pool-sniper/src/sniper.ts:88:43)
marvinkruse commented 3 years ago

Could this be related to your RPC provider value in the config? Which one did you put in the env file?

JanOwiesniak commented 3 years ago

using this provider

RPC_ENDPOINT="https://rpc-mainnet.matic.network"

tested those RPC endpoints as well and ran into the same issue:

JanOwiesniak commented 3 years ago

Maybe related to the patch?

IDE tells me that property POLYGON is missing:

Screenshot 2021-10-18 at 14 11 03

Which is not the case. I ran postinstall manually after npm install and patch seems to be applied:

Screenshot 2021-10-18 at 14 11 17

Anish-Agnihotri commented 3 years ago

Very weird—I'll add an extra step to manually run postinstall anyways. Thank you for flagging!

JanOwiesniak commented 3 years ago

@Anish-Agnihotri please reopen. This did not fixed my initial issue :)

UniswapError: chainId can not be found on the provider
Anish-Agnihotri commented 3 years ago

Ah, damn sorry. Thought that had resolved the issue. Reopening, will diagnose shortly.

JanOwiesniak commented 3 years ago

@Anish-Agnihotri i added a purchase function to test submitPurchaseTx in isolation from PairCreated and purchase DAI with USDC. Maybe something is just wrong with my test setup?

.env

TOKEN_ADDRESS=0x8f3cf7ad23cd3cadbd9735aff958023239c6a063
FACTORY_ADDRESS=0xc35dadb65012ec5796536bd9864ed8773abc74c4
RPC_ENDPOINT="https://rpc-mainnet.matic.network"

sniper.ts

   async purchase(): Promise<void> {
    const USDC_TOKEN_ADDRESS: string="0x2791bca1f2de4661ed88a30c99a7a9449aa84174";
    const DAI_TOKEN_ADDRESS: string="0x8f3cf7ad23cd3cadbd9735aff958023239c6a063";

    const token0 = DAI_TOKEN_ADDRESS;
    const token1 = USDC_TOKEN_ADDRESS;

    logger.info(`Purchase token: ${token0} with ${token1}`);
    await this.submitPurchaseTx(token0, token1);
    process.exit(0);
  }

app.ts

  await sniper.purchase();
Anish-Agnihotri commented 3 years ago

Tried testing a few more times today and I can't seem to duplicate across either Node 14 or 16. Very weird.

joshstevens19 commented 3 years ago

Hey I’m the author of simple-uniswap-sdk I’m happy to support polygon natively so you don’t need this patch. Will take a look this week (tomorrow probably) for you guys, this could remove any need to do the patch script!

Also the sdk is about to support any custom network with config so that can cover any other custom networks in future.

Super open to support any networks in the sdk so please raise any issues if you want any others supported!

joshstevens19 commented 3 years ago

ahh i see your using SushiSwap contracts on here ok this will be one for the custom network logic which will be in this lib very soon! will post a guide on here when it's done 👍

joshstevens19 commented 3 years ago

PR for pool sniper with the new sdk > https://github.com/Anish-Agnihotri/pool-sniper/pull/4

MohitKumar1991 commented 3 years ago

@Anish-Agnihotri Did this approach work for Klima ? We could build a simple webapp that uses a DAO model to allow everybody to do this.

Anish-Agnihotri commented 2 years ago

Closing kudos to @joshstevens19's help on native support for Polygon!

@MohitKumar1991 the approach did work—please feel free to use the code in any way.