#!/usr/bin/env node // extrage-artefact.mjs: the compiled AereComputeMarketV3 as ONE file beside this component, taken from the hardhat build-info of the // contracts project (roadmap point 28, 2026-10-02): abi, creation and runtime bytecode, the immutable references WITH their names (so a // reader can rebuild the exact runtime code of a deployment from its constructor arguments and compare it with eth_getCode), the // compiler and its settings, and the SHA-256 of the Solidity source the build-info holds (checked equal to the source in the tree). // Deterministic: the same build-info gives the same file. Refuses a build-info whose source differs from the tree. // node extrage-artefact.mjs writes AereComputeMarketV3.json import fs from 'node:fs'; import path from 'node:path'; import crypto from 'node:crypto'; import { fileURLToPath } from 'node:url'; const AICI = path.dirname(fileURLToPath(import.meta.url)); const RAD = path.resolve(AICI, '..', '..'); const SOL = 'contracts/depin/AereComputeMarketV3.sol'; const dbg = JSON.parse(fs.readFileSync(path.join(RAD, 'contracts', 'artifacts', SOL, 'AereComputeMarketV3.dbg.json'), 'utf8')); const bi = JSON.parse(fs.readFileSync(path.resolve(path.join(RAD, 'contracts', 'artifacts', SOL), dbg.buildInfo.replace(/\\/g, '/')), 'utf8')); const o = bi.output.contracts[SOL].AereComputeMarketV3; const src = bi.input.sources[SOL].content.replace(/\r\n/g, '\n'); const tree = fs.readFileSync(path.join(RAD, 'contracts', SOL), 'utf8').replace(/\r\n/g, '\n'); if (src !== tree) { console.log('REFUZ: the source in the build-info differs from contracts/' + SOL + ' (recompile first)'); process.exit(1); } const nume = {}; (function walk(x) { if (x && typeof x === 'object') { if (x.nodeType === 'VariableDeclaration' && x.mutability === 'immutable') nume[x.id] = { name: x.name, type: x.typeDescriptions.typeString }; for (const k in x) walk(x[k]); } })(bi.output.sources[SOL].ast); const refs = o.evm.deployedBytecode.immutableReferences || {}; const immutables = Object.fromEntries(Object.entries(refs).map(([id, pos]) => [nume[id].name, { type: nume[id].type, positions: pos }])); const art = { kind: 'aere-compute-market-v3-artifact', contract: 'AereComputeMarketV3', source: SOL, sourceSha256: '0x' + crypto.createHash('sha256').update(src).digest('hex'), solc: bi.solcLongVersion, optimizer: bi.input.settings.optimizer, evmVersion: bi.input.settings.evmVersion || 'default', abi: o.abi, bytecode: '0x' + o.evm.bytecode.object, deployedBytecode: '0x' + o.evm.deployedBytecode.object, immutables, note: 'runtime code of a deployment = deployedBytecode with each immutable written at its positions as a 32-byte word (addresses right-aligned, bytes4 left-aligned); compare with eth_getCode', }; fs.writeFileSync(path.join(AICI, 'AereComputeMarketV3.json'), JSON.stringify(art, null, 1) + '\n'); console.log(`AereComputeMarketV3.json: ${art.solc}, runtime ${(art.deployedBytecode.length - 2) / 2} bytes, immutables ${Object.keys(immutables).join(', ')}, source sha256 ${art.sourceSha256.slice(0, 18)}..`);