github.com/ethereum-optimism/optimism@v1.7.2/packages/sdk/src/adapters/eco-bridge.ts (about)

     1  /* eslint-disable @typescript-eslint/no-unused-vars */
     2  import { Contract } from 'ethers'
     3  import { hexStringEquals } from '@eth-optimism/core-utils'
     4  
     5  import { AddressLike } from '../interfaces'
     6  import { toAddress } from '../utils'
     7  import { StandardBridgeAdapter } from './standard-bridge'
     8  
     9  /**
    10   * Bridge adapter for ECO.
    11   * ECO bridge requires a separate adapter as exposes different functions than our standard bridge
    12   */
    13  export class ECOBridgeAdapter extends StandardBridgeAdapter {
    14    public async supportsTokenPair(
    15      l1Token: AddressLike,
    16      l2Token: AddressLike
    17    ): Promise<boolean> {
    18      const l1Bridge = new Contract(
    19        this.l1Bridge.address,
    20        [
    21          {
    22            inputs: [],
    23            name: 'l1Eco',
    24            outputs: [
    25              {
    26                internalType: 'address',
    27                name: '',
    28                type: 'address',
    29              },
    30            ],
    31            stateMutability: 'view',
    32            type: 'function',
    33          },
    34        ],
    35        this.messenger.l1Provider
    36      )
    37  
    38      const l2Bridge = new Contract(
    39        this.l2Bridge.address,
    40        [
    41          {
    42            inputs: [],
    43            name: 'l2Eco',
    44            outputs: [
    45              {
    46                internalType: 'contract L2ECO',
    47                name: '',
    48                type: 'address',
    49              },
    50            ],
    51            stateMutability: 'view',
    52            type: 'function',
    53          },
    54        ],
    55        this.messenger.l2Provider
    56      )
    57  
    58      const [remoteL1Token, remoteL2Token] = await Promise.all([
    59        l1Bridge.l1Eco(),
    60        l2Bridge.l2Eco(),
    61      ])
    62  
    63      if (!hexStringEquals(remoteL1Token, toAddress(l1Token))) {
    64        return false
    65      }
    66  
    67      if (!hexStringEquals(remoteL2Token, toAddress(l2Token))) {
    68        return false
    69      }
    70  
    71      return true
    72    }
    73  }