// Deploys StubCertificateVerifier and IgneumStateOracle(stub, Devnet 3 EVM chain id) to Sepolia with EIP-1559 // transactions, waits for each receipt and writes deployment.json. Refuses to redeploy over an existing // deployment.json unless --force is given; --oracle-only keeps the stub from deployment.json and redeploys the oracle. import { writeFileSync, existsSync } from 'node:fs'; import path from 'node:path'; import { here, artifact, publicClient, walletClient, deployerAccount, EVM_CHAIN_ID, ukTime, deployment } from './lib.mjs'; const out = path.join(here, 'deployment.json'); if (existsSync(out) && !process.argv.includes('--force')) { const d = deployment(); console.log('deployment.json exists (stub', d.stub.address, 'oracle', d.oracle.address + '); pass --force to redeploy'); process.exit(0); } const account = deployerAccount(); const pub = publicClient(); const wallet = walletClient(account); const bal = await pub.getBalance({ address: account.address }); console.log(ukTime(), 'UK deployer', account.address, 'balance', Number(bal) / 1e18, 'ETH'); async function deploy(name, args) { const art = artifact(name); const hash = await wallet.deployContract({ abi: art.abi, bytecode: art.bytecode, args }); console.log(ukTime(), 'UK', name, 'sent', hash); const r = await pub.waitForTransactionReceipt({ hash, timeout: 180_000 }); if (r.status !== 'success') throw new Error(name + ' deployment reverted in ' + hash); console.log(ukTime(), 'UK', name, 'at', r.contractAddress, 'block', r.blockNumber, 'gas', r.gasUsed); return { address: r.contractAddress, tx: hash, block: Number(r.blockNumber), gasUsed: Number(r.gasUsed) }; } const oracleOnly = process.argv.includes('--oracle-only'); const previous = existsSync(out) ? deployment() : null; const stub = oracleOnly && previous ? previous.stub : await deploy('StubCertificateVerifier', []); const oracle = await deploy('IgneumStateOracle', [stub.address, EVM_CHAIN_ID]); const after = await pub.getBalance({ address: account.address }); const d = { network: 'sepolia', chainId: 11155111, rpc: 'https://ethereum-sepolia-rpc.publicnode.com', deployer: account.address, evmChainId: EVM_CHAIN_ID, verifier: 'stub', stub, oracle, deployedAt: new Date().toISOString(), spentWei: (bal - after).toString(), previous: previous ? [...(previous.previous || []), { stub: previous.stub, oracle: previous.oracle, deployedAt: previous.deployedAt, writes: previous.writes || [] }] : [], }; writeFileSync(out, JSON.stringify(d, null, 1) + '\n'); console.log(ukTime(), 'UK wrote', out, 'spent', Number(bal - after) / 1e18, 'ETH');