github.com/ethereum-optimism/optimism@v1.7.2/packages/sdk/src/adapters/dai-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 DAI.
    11   */
    12  export class DAIBridgeAdapter extends StandardBridgeAdapter {
    13    public async supportsTokenPair(
    14      l1Token: AddressLike,
    15      l2Token: AddressLike
    16    ): Promise<boolean> {
    17      // Just need access to this ABI for this one function.
    18      const l1Bridge = new Contract(
    19        this.l1Bridge.address,
    20        [
    21          {
    22            inputs: [],
    23            name: 'l1Token' as const,
    24            outputs: [
    25              {
    26                internalType: 'address' as const,
    27                name: '' as const,
    28                type: 'address' as const,
    29              },
    30            ],
    31            stateMutability: 'view' as const,
    32            type: 'function' as const,
    33          },
    34          {
    35            inputs: [],
    36            name: 'l2Token' as const,
    37            outputs: [
    38              {
    39                internalType: 'address' as const,
    40                name: '' as const,
    41                type: 'address' as const,
    42              },
    43            ],
    44            stateMutability: 'view' as const,
    45            type: 'function' as const,
    46          },
    47        ],
    48        this.messenger.l1Provider
    49      )
    50  
    51      const allowedL1Token = await l1Bridge.l1Token()
    52      if (!hexStringEquals(allowedL1Token, toAddress(l1Token))) {
    53        return false
    54      }
    55  
    56      const allowedL2Token = await l1Bridge.l2Token()
    57      if (!hexStringEquals(allowedL2Token, toAddress(l2Token))) {
    58        return false
    59      }
    60  
    61      return true
    62    }
    63  }