Skip to content

Commit

Permalink
feat: add optimism withdrawal finalize time
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 committed Jul 23, 2024
1 parent 6eaa98b commit 0ae3414
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Knex } from 'knex';
import { OptimismWithdrawal } from '../../src/models';

export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable(OptimismWithdrawal.tableName, (table) => {
table.timestamp('finalize_time');
});
}

export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable(OptimismWithdrawal.tableName, (table) => {
table.dropColumn('finalize_time');
});
}
2 changes: 2 additions & 0 deletions src/models/optimism_withdrawal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class OptimismWithdrawal extends BaseModel {

evm_tx_id!: number;

finalize_time!: Date;

static get tableName() {
return 'optimism_withdrawal';
}
Expand Down
15 changes: 12 additions & 3 deletions src/services/evm/optimism/withdrawal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ export default class HandleOptimismWithdrawalEVMService extends BullableService
evmEvent.withdrawalStatus = status;
})
);
const optimismWithdrawals: OptimismWithdrawal[] = evmEvents.map(
(evmEvent) => {
const optimismWithdrawals: OptimismWithdrawal[] = await Promise.all(
evmEvents.map(async (evmEvent) => {
const [nonce, ,] = decodeAbiParameters(
this.ABI_MESSAGE_PASSED_INDEXED,
(evmEvent.topic1 +
Expand All @@ -117,6 +117,14 @@ export default class HandleOptimismWithdrawalEVMService extends BullableService
this.ABI_MESSAGE_PASSED_NON_INDEXED,
`0x${evmEvent.data.toString('hex')}`
);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const finalizeTime = await this.viemClientL1.getTimeToFinalize({
withdrawalHash,
targetChain: getViemChainById(this.l2Chain.EVMchainId),
});

return OptimismWithdrawal.fromJson({
l2_tx_hash: evmEvent.evm_transaction.hash,
l2_block: evmEvent.evm_transaction.height,
Expand All @@ -127,8 +135,9 @@ export default class HandleOptimismWithdrawalEVMService extends BullableService
status: evmEvent.withdrawalStatus,
evm_event_id: evmEvent.id,
evm_tx_id: evmEvent.evm_tx_id,
finalize_time: new Date(finalizeTime.timestamp),
});
}
})
);
await knex.transaction(async (trx) => {
if (optimismWithdrawals.length > 0) {
Expand Down

0 comments on commit 0ae3414

Please sign in to comment.