diff --git a/src/lib/monitor/l1.ts b/src/lib/monitor/l1.ts index 08233f3..2dd027a 100644 --- a/src/lib/monitor/l1.ts +++ b/src/lib/monitor/l1.ts @@ -1,5 +1,10 @@ import { Monitor } from './monitor' -import { Coin, Msg, MsgFinalizeTokenDeposit } from '@initia/initia.js' +import { + Coin, + Msg, + MsgFinalizeTokenDeposit, + MsgSetBridgeInfo +} from '@initia/initia.js' import { ExecutorDepositTxEntity, ExecutorUnconfirmedTxEntity, @@ -30,6 +35,23 @@ export class L1Monitor extends Monitor { return 'executor_l1_monitor' } + public async prepareMonitor(): Promise { + const bridgeInfoL1 = await config.l1lcd.ophost.bridgeInfo(config.BRIDGE_ID) + try { + await this.executor.lcd.opchild.bridgeInfo() + } catch (err) { + const errMsg = err.response?.data + ? JSON.stringify(err.response?.data) + : err.toString() + if (errMsg.includes('bridge info not found')) { + const l2Msgs = [ + new MsgSetBridgeInfo(this.executor.key.accAddress, bridgeInfoL1) + ] + this.executor.transaction(l2Msgs) + } + } + } + public async handleInitiateTokenDeposit( manager: EntityManager, data: { [key: string]: string } diff --git a/src/lib/monitor/monitor.ts b/src/lib/monitor/monitor.ts index 915475b..f7e56b3 100644 --- a/src/lib/monitor/monitor.ts +++ b/src/lib/monitor/monitor.ts @@ -69,6 +69,7 @@ export abstract class Monitor { } public async monitor(): Promise { + await this.prepareMonitor() while (this.isRunning) { try { const latestHeight = this.socket.latestHeight @@ -127,6 +128,9 @@ export abstract class Monitor { // eslint-disable-next-line public async handleBlock(manager: EntityManager): Promise {} + // eslint-disable-next-line + public async prepareMonitor(): Promise {} + // eslint-disable-next-line public name(): string { return ''