joshstevens19 / simple-uniswap-sdk

Uniswap SDK which handles the routes automatically for you, changes in trade quotes reactive subscriptions, exposure to formatted easy to understand information, bringing back the best trade quotes automatically, generating transactions for you and much more.
MIT License
188 stars 95 forks source link

How to use native currency on custom network (Arbitrum 42161, Sepolia 11155111, Arbitrum Sepolia 421614) #59

Open YauhenPachankou opened 2 months ago

YauhenPachankou commented 2 months ago

Failed to trade ETH on custom network. Does anybody know where might be a problem ?

Tried to add _ETH to Sepolia WETH contract (0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14_ETH), but it didn't help.

This is Sepolia network config:

{ chainId: 11155111, layerZeroChainId: 10161, network: 'sepolia', currency: 'ETH', networkName: 'Sepolia Testnet', networkNameForAllEnv: NetworksEnum.Sepolia, explorerUrl: 'https://sepolia.etherscan.io', apiEndpoint: 'https://api-dev.dev-landx.be/api', infuraApiKey: 'aaabaa1e74ac4192859455ead7ca6cdd', providerUrl: 'https://sepolia.infura.io/v3/aaabaa1e74ac4192859455ead7ca6cdd', contracts: sepoliaDev, rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com', isDefault: true, isTradeShown: true, lndxSwapTokensList: [TOKENS.ETH, TOKENS.USDC, TOKENS.USDT], customChain: { cloneUniswapContractDetails: { v3Override: { routerAddress: '0x9990933B23c0D4e23dA4cb8096A478D42e687CE8', factoryAddress: '0x0227628f3F023bb0B980b67D528571c95c6DaC1c', quoterAddress: '0x6Aab9B15DA9Df02b22C8E79a0a5527E520E7D009', }, }, customNetwork: { nameNetwork: 'Sepolia', multicallContractAddress: '0xcA11bde05977b3631167028862bE2a173976CA11', nativeCurrency: { name: 'ETH Token', symbol: 'ETH', }, nativeWrappedTokenInfo: { chainId: 11155111, contractAddress: '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14', decimals: 18, symbol: 'WETH', name: 'Wrapped ETH', }, }, }, },

===========

This is Trade method:

public tradeInfo( chainId: number, amount: number, fromTokenContractAddress: string, toTokenContractAddress: string, ethereumAddress: string, network: NetworkInterface, tradeDirection: TradeDirection = TradeDirection.input, ): Observable { return new Observable((subscriber: Subscriber) => { (async () => { try { let uniswapPair: UniswapPair;

      if (network?.customChain) {
        uniswapPair = new UniswapPair({
          fromTokenContractAddress,
          toTokenContractAddress,
          ethereumAddress,
          ethereumProvider: this.walletConnectService.walletProvider,
          settings: new UniswapPairSettings({
            slippage: 0.005,
            deadlineMinutes: 20,
            disableMultihops: false,
            uniswapVersions: [UniswapVersion.v3],
            cloneUniswapContractDetails: network.customChain.cloneUniswapContractDetails,
            customNetwork: network.customChain.customNetwork,
          }),
        });
      } else {
        uniswapPair = new UniswapPair({
          fromTokenContractAddress,
          toTokenContractAddress,
          ethereumAddress,
          chainId,
          settings: new UniswapPairSettings({
            slippage: 0.005,
            deadlineMinutes: 20,
            disableMultihops: false,
            uniswapVersions: [UniswapVersion.v2, UniswapVersion.v3],
          }),
        });
      }

      uniswapPair.createFactory()
        .then((factory) => factory.trade(amount.toString(), tradeDirection).catch((error) => {
          console.log(error);
          subscriber.error(error);
          return undefined;
        })).catch((error) => {
          console.log(error);
          subscriber.error(error);
          return undefined;
        })
        .then((trade) => {
          subscriber.next(trade);
          if (trade) {
            trade.destroy();
          }
        })
        .catch((error) => {
          console.log(error);
          subscriber.error(error);
        });
    } catch (error) {
      console.log(error);
      subscriber.error(new Error('errors.contract_error'));
    }
  })();
});

}