chains.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // The following listing does not pretend to be exhaustive or even accurate. It SHOULD NOT be used in production.
  2. const { ethers } = require('hardhat');
  3. const { mapValues } = require('./iterate');
  4. const { addressCoder } = require('interoperable-addresses');
  5. // EVM (https://axelarscan.io/resources/chains?type=evm)
  6. const ethereum = {
  7. Ethereum: 1n,
  8. optimism: 10n,
  9. binance: 56n,
  10. Polygon: 137n,
  11. Fantom: 250n,
  12. fraxtal: 252n,
  13. filecoin: 314n,
  14. Moonbeam: 1284n,
  15. centrifuge: 2031n,
  16. kava: 2222n,
  17. mantle: 5000n,
  18. base: 8453n,
  19. immutable: 13371n,
  20. arbitrum: 42161n,
  21. celo: 42220n,
  22. Avalanche: 43114n,
  23. linea: 59144n,
  24. blast: 81457n,
  25. scroll: 534352n,
  26. aurora: 1313161554n,
  27. };
  28. const solana = {
  29. Mainnet: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d',
  30. };
  31. const format = ({ namespace, reference }) => ({
  32. namespace,
  33. reference: reference.toString(),
  34. caip2: `${namespace}:${reference}`,
  35. erc7930: addressCoder.encode({ chainType: namespace, reference }),
  36. toCaip10: other => `${namespace}:${reference}:${ethers.getAddress(other.target ?? other.address ?? other)}`,
  37. toErc7930: other =>
  38. addressCoder.encode({ chainType: namespace, reference, address: other.target ?? other.address ?? other }),
  39. });
  40. module.exports = {
  41. CHAINS: mapValues(
  42. Object.assign(
  43. mapValues(ethereum, reference => ({ namespace: 'eip155', reference })),
  44. mapValues(solana, reference => ({ namespace: 'solana', reference })),
  45. ),
  46. format,
  47. ),
  48. getLocalChain: () =>
  49. ethers.provider.getNetwork().then(({ chainId }) => format({ namespace: 'eip155', reference: chainId })),
  50. };