diff --git a/README.md b/README.md index 16e861a..d0ec160 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Note that the configuration formatted as either a single `Object`, or an `Array` bytecodeExporter: { path: './data', runOnCompile: true, + includeDeployed: true, clear: true, flat: true, only: [':ERC20$'], diff --git a/index.js b/index.js index 3c440fb..59871f2 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ require('./tasks/compile.js'); const DEFAULT_CONFIG = { path: './bytecode', runOnCompile: false, + includeDeployed: false, clear: false, flat: false, only: [], @@ -34,6 +35,7 @@ extendConfig(function (config, userConfig) { const conf = Object.assign({}, DEFAULT_CONFIG, el); validate(conf, 'path', 'string'); validate(conf, 'runOnCompile', 'boolean'); + validate(conf, "includeDeployed", 'boolean'); validate(conf, 'clear', 'boolean'); validate(conf, 'flat', 'boolean'); validate(conf, 'only', 'array'); diff --git a/tasks/export_bytecode.js b/tasks/export_bytecode.js index d2c8ceb..cb1adfc 100644 --- a/tasks/export_bytecode.js +++ b/tasks/export_bytecode.js @@ -45,9 +45,10 @@ subtask( if (config.only.length && !config.only.some(m => fullName.match(m))) return; if (config.except.length && config.except.some(m => fullName.match(m))) return; - let { bytecode, sourceName, contractName } = await hre.artifacts.readArtifact(fullName); + let { bytecode, deployedBytecode, sourceName, contractName } = await hre.artifacts.readArtifact(fullName); bytecode = bytecode.replace(/^0x/, ''); + deployedBytecode = deployedBytecode.replace(/^0x/, ""); if (!bytecode.length) return; @@ -56,7 +57,13 @@ subtask( config.rename(sourceName, contractName) ) + '.bin'; - outputData.push({ bytecode, destination }); + const deployedDestination = path.resolve( + outputDirectory, + "deployed", + config.rename(sourceName, contractName) + ) + ".bin-runtime"; + + outputData.push({ bytecode, destination, deployedBytecode, deployedDestination }); })); outputData.reduce(function (acc, { destination }) { @@ -72,8 +79,13 @@ subtask( await hre.run('clear-bytecode-group', { path: config.path }); } - await Promise.all(outputData.map(async function ({ bytecode, destination }) { + await Promise.all(outputData.map(async function ({ bytecode, destination, deployedBytecode, deployedDestination }) { await fs.promises.mkdir(path.dirname(destination), { recursive: true }); await fs.promises.writeFile(destination, bytecode, { flag: 'w' }); + + if (config.includeDeployed) { + await fs.promises.mkdir(path.dirname(deployedDestination), {recursive: true}); + await fs.promises.writeFile(deployedDestination, deployedBytecode, {flag: "w"}); + } })); });