UNPKG

@morpho-labs/v2-deployment

Version:
129 lines 5.21 kB
#!/usr/bin/env node import { Command } from 'commander'; import { morphoEthereumFork } from './chains.js'; import { deployments, getContractAddress, getDeploymentInfo } from './index.js'; const program = new Command(); program .name('@morpho-labs/v2-deployment') .description('Morpho v2 deployment utilities') .version('0.1.0'); program .command('get') .description('Get deployment information') .argument('<type>', 'Type of information to get (addresses, forks)') .option('-c, --chain <chainId>', 'Chain ID to filter by') .option('-f, --format <format>', 'Output format (json, table)', 'table') .action((type, options) => { const chainId = options.chain ? parseInt(options.chain, 10) : undefined; switch (type) { case 'addresses': if (chainId) { const chainDeployments = deployments[chainId]; if (!chainDeployments) { console.error(`No deployments found for chain ${chainId}`); process.exit(1); } if (options.format === 'json') { console.log(JSON.stringify(chainDeployments, null, 2)); } else { console.log(`\nDeployments for Chain ${chainId}:`); console.log('─'.repeat(50)); Object.entries(chainDeployments).forEach(([contract, info]) => { console.log(`${contract.padEnd(15)} ${info.address}`); }); } } else { if (options.format === 'json') { console.log(JSON.stringify(deployments, null, 2)); } else { console.log('\nAll Deployments:'); console.log('─'.repeat(50)); Object.entries(deployments).forEach(([chainId, contracts]) => { console.log(`\nChain ${chainId}:`); Object.entries(contracts).forEach(([contract, info]) => { console.log(` ${contract.padEnd(13)} ${info.address}`); }); }); } } break; case 'forks': { // Return Morpho fork chain configurations const forks = [morphoEthereumFork]; if (options.format === 'json') { console.log(JSON.stringify(forks, null, 2)); } else { console.log('\nMorpho Fork Chains:'); console.log('─'.repeat(50)); forks.forEach((fork) => { console.log(`\nChain: ${fork.name} (ID: ${fork.id})`); console.log(`RPC: ${fork.rpcUrls.default.http[0]}`); console.log(`Explorer: ${fork.blockExplorers.default.url}`); console.log(`Currency: ${fork.nativeCurrency.name} (${fork.nativeCurrency.symbol})`); console.log(`Testnet: ${fork.testnet}`); if (fork.sourceId) { console.log(`Forked from: Chain ${fork.sourceId}`); } }); } break; } default: console.error(`Unknown type: ${type}. Use 'addresses' or 'forks'`); process.exit(1); } }); program .command('address') .description('Get contract address for specific chain and contract') .argument('<contract>', 'Contract name') .requiredOption('-c, --chain <chainId>', 'Chain ID') .action((contract, options) => { const chainId = parseInt(options.chain, 10); const address = getContractAddress(chainId, contract.toLowerCase()); if (address) { console.log(address); } else { console.error(`No deployment found for ${contract} on chain ${chainId}`); process.exit(1); } }); program .command('info') .description('Get full deployment info for specific chain and contract') .argument('<contract>', 'Contract name') .requiredOption('-c, --chain <chainId>', 'Chain ID') .option('-f, --format <format>', 'Output format (json, table)', 'table') .action((contract, options) => { const chainId = parseInt(options.chain, 10); const info = getDeploymentInfo(chainId, contract.toLowerCase()); if (info) { if (options.format === 'json') { console.log(JSON.stringify(info, null, 2)); } else { console.log(`\nDeployment Info for ${contract} on Chain ${chainId}:`); console.log('─'.repeat(50)); console.log(`Address: ${info.address}`); console.log(`Deployer: ${info.deployer}`); console.log(`Deployed At: ${info.deployedAt}`); if (info.deploymentBlock) { console.log(`Deployment Block: ${info.deploymentBlock}`); } } } else { console.error(`No deployment found for ${contract} on chain ${chainId}`); process.exit(1); } }); if (import.meta.main) { program.parse(); } export { program }; //# sourceMappingURL=cli.js.map