|
| 1 | +import { task } from 'hardhat/config' |
| 2 | +import { cliOpts } from '../../cli/defaults' |
| 3 | +import { ethers } from 'ethers' |
| 4 | +import { Table } from 'console-table-printer' |
| 5 | + |
| 6 | +export const TASK_BRIDGE_WITHDRAWALS = 'bridge:withdrawals' |
| 7 | + |
| 8 | +task(TASK_BRIDGE_WITHDRAWALS, 'List withdrawals initiated on L2GraphTokenGateway') |
| 9 | + .addOptionalParam('addressBook', cliOpts.addressBook.description) |
| 10 | + .addOptionalParam( |
| 11 | + 'arbitrumAddressBook', |
| 12 | + cliOpts.arbitrumAddressBook.description, |
| 13 | + cliOpts.arbitrumAddressBook.default, |
| 14 | + ) |
| 15 | + .addOptionalParam('l1GraphConfig', cliOpts.graphConfig.description) |
| 16 | + .addOptionalParam('l2GraphConfig', cliOpts.graphConfig.description) |
| 17 | + .addOptionalParam('startBlock', 'Start block for the search') |
| 18 | + .addOptionalParam('endBlock', 'End block for the search') |
| 19 | + .setAction(async (taskArgs, hre) => { |
| 20 | + console.log('> L2GraphTokenGateway withdrawals') |
| 21 | + |
| 22 | + const graph = hre.graph(taskArgs) |
| 23 | + const gateway = graph.l2.contracts.L2GraphTokenGateway |
| 24 | + console.log(`Tracking 'WithdrawalInitiated' events on ${gateway.address}`) |
| 25 | + |
| 26 | + const startBlock = taskArgs.startBlock ? parseInt(taskArgs.startBlock) : 0 |
| 27 | + const endBlock = taskArgs.endBlock ? parseInt(taskArgs.endBlock) : 'latest' |
| 28 | + console.log(`Searching blocks from ${startBlock} to ${endBlock}`) |
| 29 | + |
| 30 | + const events = ( |
| 31 | + await gateway.queryFilter(gateway.filters.WithdrawalInitiated(), startBlock, endBlock) |
| 32 | + ).map((e) => ({ |
| 33 | + blockNumber: e.blockNumber, |
| 34 | + transactionHash: e.transactionHash, |
| 35 | + from: e.args.from, |
| 36 | + to: e.args.to, |
| 37 | + amount: ethers.utils.formatEther(e.args.amount), |
| 38 | + })) |
| 39 | + |
| 40 | + printEvents(events) |
| 41 | + }) |
| 42 | + |
| 43 | +function printEvents(events: any[]) { |
| 44 | + const tablePrinter = new Table({ |
| 45 | + columns: [ |
| 46 | + { name: 'blockNumber', color: 'green' }, |
| 47 | + { |
| 48 | + name: 'transactionHash', |
| 49 | + color: 'green', |
| 50 | + }, |
| 51 | + { name: 'from', color: 'green' }, |
| 52 | + { name: 'to', color: 'green' }, |
| 53 | + { name: 'amount', color: 'green' }, |
| 54 | + ], |
| 55 | + }) |
| 56 | + |
| 57 | + events.map((e) => tablePrinter.addRow(e)) |
| 58 | + tablePrinter.printTable() |
| 59 | +} |
0 commit comments