()
| 104 | |
| 105 | //function to compile yulp contracts |
| 106 | async function yulLog() { |
| 107 | let framework = ""; |
| 108 | if (process.argv.indexOf("hardhat") > -1) { |
| 109 | framework = "hardhat"; |
| 110 | await execPromise("npx hardhat compile"); |
| 111 | } else if (process.argv.indexOf("truffle") > -1) { |
| 112 | framework = "truffle"; |
| 113 | await execPromise("truffle compile"); |
| 114 | } |
| 115 | fs.readdir("./Yul+ Contracts/", (err, files) => { |
| 116 | files.forEach((file) => { |
| 117 | fs.readFile("./Yul+ Contracts/" + file, "utf8", function (err, data) { |
| 118 | if (err) { |
| 119 | return console.log(err); |
| 120 | } |
| 121 | let filename = file.split("."); |
| 122 | let source = yulp.compile(data); |
| 123 | let output = JSON.parse( |
| 124 | solc.compile( |
| 125 | JSON.stringify({ |
| 126 | language: "Yul", |
| 127 | sources: { |
| 128 | "Target.yul": { content: yulp.print(source.results) }, |
| 129 | }, |
| 130 | settings: { |
| 131 | outputSelection: { "*": { "*": ["*"], "": ["*"] } }, |
| 132 | optimizer: { |
| 133 | enabled: true, |
| 134 | runs: 0, |
| 135 | details: { |
| 136 | yul: true, |
| 137 | }, |
| 138 | }, |
| 139 | }, |
| 140 | }) |
| 141 | ) |
| 142 | ); |
| 143 | let contractObjects = Object.keys(output.contracts["Target.yul"]); |
| 144 | let abi = source.signatures |
| 145 | .map((v) => v.abi.slice(4, -1)) |
| 146 | .concat(source.topics.map((v) => v.abi.slice(6, -1))); |
| 147 | let bytecode = |
| 148 | "0x" + |
| 149 | output.contracts["Target.yul"][contractObjects[0]]["evm"]["bytecode"][ |
| 150 | "object" |
| 151 | ]; |
| 152 | let deployedBytecode = |
| 153 | "0x" + |
| 154 | output.contracts["Target.yul"][contractObjects[0]]["evm"][ |
| 155 | "deployedBytecode" |
| 156 | ]["object"]; |
| 157 | if (framework == "hardhat") { |
| 158 | // if hardhat flag is present |
| 159 | // Still very experimental and breaks a LOT |
| 160 | // But this does technically create a hardhat artifact |
| 161 | // that does work |
| 162 | var hardhatCompiled = { |
| 163 | _format: "hh-sol-artifact-1", |
no test coverage detected