simple-uniswap-sdk icon indicating copy to clipboard operation
simple-uniswap-sdk copied to clipboard

bug(avalanche): native token _ETH is not valid

Open mburger81 opened this issue 2 years ago • 4 comments

I'm using the simple-uniswap-sdk and your angular swap on the AVALANCHE main net. But there are problems with the NATIVE token.

My config is mainly this:

(customNetworkData = {
          nameNetwork: 'Avalanche',
          multicallContractAddress: '0xed386Fe855C1EFf2f843B910923Dd8846E45C5A4',
          nativeCurrency: {
              name: 'AVAX',
              symbol: 'AVAX',
          },
          nativeWrappedTokenInfo: {
              chainId: 43114,
              contractAddress: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
              decimals: 18,
              symbol: 'AVAX', // WAVAX
              name: 'AVAX' // Wrapped AVAX
          },
          baseTokens: {
              usdt: {
                  chainId: 43114,
                  contractAddress: '0xc7198437980c041c805A1EDcbA50c1Ce5db95118',
                  decimals: 6,
                  symbol: 'USDT.e',
                  name: 'USDT.e'
              },
              usdc: {
                  chainId: 43114,
                  contractAddress: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664',
                  decimals: 6,
                  symbol: 'USDC.e',
                  name: 'USDC.e'
              },
              wbtc: {
                  chainId: 43114,
                  contractAddress: '0x152b9d0fdc40c096757f570a51e494bd4b943e50',
                  decimals: 8,
                  symbol: 'BTC.b',
                  name: 'BTC.b'
              }
          }
      });

and

this.uniswapDappSharedLogicContext  = {
      supportedNetworkTokens: [
        {
          chainId: 43114,
          // 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7_ETH
          defaultInputToken: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', // USDC
          defaultOutputToken: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7_ETH', // FOOK
          supportedTokens: [
            { contractAddress: '0x95923F63dA09B4f7520f7C65a31F318D8228B744', tokenImageContext: { image: tokens.fook.logo , isSvg: false } }, // FOOK
            { contractAddress: '0x71124b9199B97E0E232Aee3909e3B0eC28402611', tokenImageContext: { image: tokens.fook.logo, isSvg: false } }, // FOOKF
            { contractAddress: '0x27301e48aF707F950765d5570d7279a6e3E3BC5B', tokenImageContext: { image: tokens.fookz.logo, isSvg: false } }, // FOOKZ
            { contractAddress: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', tokenImageContext: { image: tokens.usdc.logo, isSvg: false } }, // USDC
            { contractAddress: '0x152b9d0fdc40c096757f570a51e494bd4b943e50', tokenImageContext: { image: tokens.wbtc.logo, isSvg: false } }, // BTC.b
            // { contractAddress: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7_ETH', tokenImageContext: { image: tokens.avax.logo , isSvg: false } }, // AVAX
            { contractAddress: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', tokenImageContext: { image: tokens.avax.logo , isSvg: false } } // AVAX
            // { contractAddress: '0xc7198437980c041c805A1EDcbA50c1Ce5db95118' }, // USDT.e
            // { contractAddress: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664' } // USDC.e
          ]
        }
      ],
      ethereumAddress: userAddress,
      ethereumProvider: this.web3Service.provider,
      providerUrl: providerUrl,
      settings: new UniswapPairSettings({
          slippage: 0.005,
          deadlineMinutes: 15,
          disableMultihops: false,
          uniswapVersions: [UniswapVersion.v2],
          cloneUniswapContractDetails: targets,
          customNetwork: customNetworkData
      })
  }

It seems that the logic is adding a "_ETH" at the Wrapped WAVAX token address. But once I choose to use this "_ETH" token for the from or to token, so to swap AVAX to another tooken I run into the issue

ERROR Error: Uncaught (in promise): UniswapError: invalid from or to contract tokens
UniswapError: invalid from or to contract tokens
    at new UniswapError (uniswap-error.js:17:28)
    at TokensFactory.<anonymous> (tokens.factory.js:123:31)
    at step (tokens.factory.js:32:23)
    at Object.next (tokens.factory.js:13:53)

@joshstevens19 @liu-zhipeng @vm06007

mburger81 avatar Sep 09 '22 18:09 mburger81

can you supply me a full code snippet please

joshstevens19 avatar Sep 10 '22 12:09 joshstevens19

I found that, If I forked the lib and added new support for Avalanche main and test net, the issue from the SWAP libs are resolved. So I suggest I prepare the fork and the merge request

BTW without doing anything not all tests passed

Test Suites: 4 failed, 22 passed, 26 total
Tests:       16 failed, 3 skipped, 206 passed, 225 total
Snapshots:   0 total
Time:        168.614s
Ran all test suites.

mburger81 avatar Sep 10 '22 12:09 mburger81

sure do the PR and we can discuss.. tests pass now on master but can investigate if CI fails thanks

joshstevens19 avatar Sep 10 '22 12:09 joshstevens19

Honestly the error where already there on a clean fork from master

I created the PR #51, I updated dependencies and added just the chain infos for avalanche main and testnet

mburger81 avatar Sep 10 '22 12:09 mburger81