import { ethers } from 'ethers' ; import { xapps } from '@optics-xyz/ts-interface' ; import { Contracts } from '../../contracts' ; type Address = string ; interface ProxyInfo { proxy : Address ; } interface BridgeInfo { id : number ; bridgeRouter : Address | ProxyInfo ; ethHelper ? : Address ; } export class BridgeContracts extends Contracts { domain : number ; bridgeRouter : xapps . BridgeRouter ; ethHelper ? : xapps . ETHHelper ; constructor ( domain , bridgeRouter , ethHelper ? , signer ? ) { super ( domain , bridgeRouter , ethHelper , signer ) ; this . domain = domain ; this . bridgeRouter = new xapps . BridgeRouter__factory ( signer ) . attach ( bridgeRouter ) ; if ( ethHelper ) { this . ethHelper = new xapps . ETHHelper__factory ( signer ) . attach ( ethHelper ) ; } } connect ( providerOrSigner ) { this . bridgeRouter = this . bridgeRouter . connect ( providerOrSigner ) ; if ( this . ethHelper ) { this . ethHelper = this . ethHelper . connect ( providerOrSigner ) ; } } static fromObject ( data , signer ? ) { const { id , bridgeRouter , ethHelper } = data ; if ( ! id || ! bridgeRouter ) { throw new Error ( 'missing domain or bridgeRouter address' ) ; } const router = typeof bridgeRouter === 'string' ? bridgeRouter : bridgeRouter . proxy ; return new BridgeContracts ( id , router , ethHelper , signer ) ; } toObject ( ) { const bridge = { id : this . domain , bridgeRouter : this . bridgeRouter . address , } ; if ( this . ethHelper ) { bridge . ethHelper = this . ethHelper . address ; } return bridge ; } }