Uniswap / token-list-bridge-utils

GNU General Public License v3.0
131 stars 66 forks source link

check that a L2 token contract exists for a L2 token address before adding mapping to list #3

Closed matteenm closed 2 years ago

matteenm commented 2 years ago

Currently, the cross-chain list being generated using this package contains Arbitrum addresses that, while provided to us in the L1->L2 mappings from the Arbitrum sdk, do not actually exist as tokens on the Arbitrum chain. example: This address for Adventure Gold (AGLD).

This PR adds a check to only add L2 addresses to the list if they exist as Token contracts on the corresponding L2 chain. This is done by performing a call to the symbol method of the address's contract (using web3 library), and if that call does not throw an error, we assume the token contract exists.

The drawback of adding this check is that it did add ~20-30 seconds to the runtime of generating the cross-chain list from the uniswap default list. However I believe it is worth it as it prevents the resulting list from containing token entries that don't actually exist.

This change was tested by running it on the Uniswap default list locally and confirming that the prior non-existing arbitrum tokens are no longer included in the list.

chunxi commented 2 years ago

@matteenm Can you double check the RPC Url? Everything else LGTM.

In the getRpcUrl function. Both rinkeby and optimism point to optimism.io?

    case ChainId.RINKEBY:
    case ChainId.OPTIMISM:
      return 'https://mainnet.optimism.io'
matteenm commented 2 years ago

@matteenm Can you double check the RPC Url? Everything else LGTM.

In the getRpcUrl function. Both rinkeby and optimism point to optimism.io?

    case ChainId.RINKEBY:
    case ChainId.OPTIMISM:
      return 'https://mainnet.optimism.io'

@chunxi good catch! We currently dont create mappings for testnets so I will remove it for now. If we add support for it in the future then we will need to find a Rinkeby RPC to use.