|
| 1 | +import chalk from 'chalk'; |
| 2 | +import yargs from 'yargs'; |
| 3 | + |
| 4 | +import { |
| 5 | + LogFormat, |
| 6 | + LogLevel, |
| 7 | + configureRootLogger, |
| 8 | + rootLogger, |
| 9 | +} from '@hyperlane-xyz/utils'; |
| 10 | + |
| 11 | +import { squadsConfigs } from '../../src/config/squads.js'; |
| 12 | +import { |
| 13 | + SquadsTransaction, |
| 14 | + SquadsTransactionReader, |
| 15 | +} from '../../src/tx/squads-transaction-reader.js'; |
| 16 | +import { processGovernorReaderResult } from '../../src/tx/utils.js'; |
| 17 | +import { |
| 18 | + getPendingProposalsForChains, |
| 19 | + logProposals, |
| 20 | +} from '../../src/utils/squads.js'; |
| 21 | +import { withChains } from '../agent-utils.js'; |
| 22 | +import { getEnvironmentConfig } from '../core-utils.js'; |
| 23 | + |
| 24 | +const environment = 'mainnet3'; |
| 25 | + |
| 26 | +async function main() { |
| 27 | + const { chains } = await withChains( |
| 28 | + yargs(process.argv.slice(2)), |
| 29 | + Object.keys(squadsConfigs), |
| 30 | + ).argv; |
| 31 | + configureRootLogger(LogFormat.Pretty, LogLevel.Info); |
| 32 | + |
| 33 | + // Get the multiprovider for the environment |
| 34 | + const config = getEnvironmentConfig(environment); |
| 35 | + const mpp = await config.getMultiProtocolProvider(); |
| 36 | + |
| 37 | + // Initialize the transaction reader |
| 38 | + const reader = new SquadsTransactionReader(environment, mpp); |
| 39 | + |
| 40 | + // Get the pending proposals for the relevant chains |
| 41 | + const chainsToCheck = |
| 42 | + !chains || chains.length === 0 ? Object.keys(squadsConfigs) : chains; |
| 43 | + |
| 44 | + const pendingProposals = await getPendingProposalsForChains( |
| 45 | + chainsToCheck, |
| 46 | + mpp, |
| 47 | + ); |
| 48 | + |
| 49 | + if (pendingProposals.length === 0) { |
| 50 | + rootLogger.info(chalk.green('No pending proposals found!')); |
| 51 | + process.exit(0); |
| 52 | + } |
| 53 | + |
| 54 | + logProposals(pendingProposals); |
| 55 | + |
| 56 | + // Parse each proposal and collect results |
| 57 | + const chainResultEntries = await Promise.all( |
| 58 | + pendingProposals.map( |
| 59 | + async ({ |
| 60 | + chain, |
| 61 | + nonce, |
| 62 | + fullTxHash, |
| 63 | + }): Promise<[string, SquadsTransaction]> => { |
| 64 | + rootLogger.info( |
| 65 | + chalk.gray.italic( |
| 66 | + `Parsing proposal ${nonce} (${fullTxHash}) on ${chain}...`, |
| 67 | + ), |
| 68 | + ); |
| 69 | + |
| 70 | + try { |
| 71 | + const result = await reader.read(chain, nonce); |
| 72 | + rootLogger.info( |
| 73 | + chalk.blue(`Finished parsing proposal ${nonce} on ${chain}`), |
| 74 | + ); |
| 75 | + return [`${chain}-${nonce}-${fullTxHash}`, result]; |
| 76 | + } catch (error) { |
| 77 | + rootLogger.error( |
| 78 | + chalk.red(`Error parsing proposal ${nonce} on ${chain}:`), |
| 79 | + error, |
| 80 | + ); |
| 81 | + return [`${chain}-${nonce}-${fullTxHash}`, { chain, error }]; |
| 82 | + } |
| 83 | + }, |
| 84 | + ), |
| 85 | + ); |
| 86 | + |
| 87 | + // Process results and write to file |
| 88 | + processGovernorReaderResult( |
| 89 | + chainResultEntries, |
| 90 | + reader.errors, |
| 91 | + 'squads-tx-parse-results', |
| 92 | + ); |
| 93 | +} |
| 94 | + |
| 95 | +main().catch((err) => { |
| 96 | + rootLogger.error('Error:', err); |
| 97 | + process.exit(1); |
| 98 | +}); |
0 commit comments