Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const compile = async (sources: SourceCollection, ast: S.SourceUnit) => {
// Extract required version from pragma of ast
const version =
_.map(utils.pragmaNodes(ast).filter(({ name }) => name === 'solidity'), ({ value }) => value)[0] || 'latest';
// Get Solidity compiler
const compiler = await Solc.getSolcAsync(version);
// Solidity standard JSON input
// TODO: Typescript typings
// See: https://solidity.readthedocs.io/en/develop/using-the-compiler.html#compiler-input-and-output-json-description
const input = {
language: 'Solidity',
sources: {
...utils.objectMap(sources, ({ source: content }) => ({ content })),
TARGET_: { content: unparse(ast) },
},
settings: {
remappings: {
// TODO
},
},
outputSelection: {
compilerSettings: {
outputSelection: {
['*']: {
['*']: ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object'],
},
},
optimizer: {
enabled: runs ? true : false,
runs: runs
}
},
contracts: '*',
solcVersion: solcVersion,
};
const compiler = new Compiler(compilerOptions);
console.log('Preparing coverage environment and building artifacts...');
await compiler.compileAsync();
await overrideCoverageBytecodes(buildDirectory)
}
'evm',
'v0.5',
'contracts',
)
const contracts = join(root, 'contracts', 'v0.5')
const artifacts = join(root, 'artifacts')
console.warn(chalk.yellow('Removing contracts/v0.5 dir:', contracts))
rm('-rf', contracts)
console.warn(chalk.yellow('Removing artifacts dir:', artifacts))
rm('-r', artifacts)
console.log(
chalk.green(`Copying contracts from ${evmv05Contracts} to ${contracts}`),
)
cp('-r', evmv05Contracts, contracts)
const compiler = new Compiler({
artifactsDir: artifacts,
contracts: '*',
contractsDir: contracts,
solcVersion: '0.5.0',
useDockerisedSolc: false,
compilerSettings: {
outputSelection: {
'*': {
'*': [
'abi',
'evm.bytecode.object',
'evm.bytecode.sourceMap',
'evm.deployedBytecode.object',
'evm.deployedBytecode.sourceMap',
],
},
(async () => {
const packageDir = process.cwd();
const compilerJSON = readJSONFile('compiler.json');
const compiler = new Compiler(compilerJSON);
const contracts = compiler.getContractNamesToCompile();
const contractsDir = compilerJSON.contractsDir || DEFAULT_CONTRACTS_DIR;
const artifactsDir = compilerJSON.artifactsDir || DEFAULT_ARTIFACTS_DIR;
const wrappersDir = DEFAULT_WRAPPERS_DIR;
if (!_.isArray(contracts)) {
throw new Error('Unable to run the generator bacause contracts key in compiler.json is not of type array');
}
const prettierConfig = await prettier.resolveConfig(packageDir);
generateCompilerJSONContractsList(contracts, contractsDir, prettierConfig);
generateArtifactsTs(contracts, artifactsDir, prettierConfig);
generateWrappersTs(contracts, wrappersDir, prettierConfig);
generateTsConfigJSONFilesList(contracts, artifactsDir, prettierConfig);
generatePackageJSONABIConfig(contracts, artifactsDir, prettierConfig);
process.exit(0);
})().catch(err => {
logUtils.log(err);
public async generateSolDocAsync(
contractsDir: string,
contractsToDocument?: string[],
customTypeHashToName?: ObjectMap,
): Promise {
this._customTypeHashToName = customTypeHashToName;
const docWithDependencies: DocAgnosticFormat = {};
const compilerOptions = SolDoc._makeCompilerOptions(contractsDir, contractsToDocument);
const compiler = new Compiler(compilerOptions);
const compilerOutputs = await compiler.getCompilerOutputsAsync();
let structs: CustomType[] = [];
for (const compilerOutput of compilerOutputs) {
const contractFileNames = _.keys(compilerOutput.contracts);
for (const contractFileName of contractFileNames) {
const contractNameToOutput = compilerOutput.contracts[contractFileName];
const contractNames = _.keys(contractNameToOutput);
for (const contractName of contractNames) {
const compiledContract = contractNameToOutput[contractName];
if (compiledContract.abi === undefined) {
throw new Error('compiled contract did not contain ABI output');
}
docWithDependencies[contractName] = this._genDocSection(compiledContract, contractName);
structs = [...structs, ...this._extractStructs(compiledContract)];
}
'metadata',
],
},
},
...compilerSettingCopy,
},
contracts: '*',
contractsDir: join(contractsDir, subDir),
isOfflineMode: false,
shouldSaveStandardInput: false,
solcVersion,
useDockerisedSolc,
}
_d('Settings: %o', settings)
return new Compiler(settings)
}
this._assertSolidityVersionIsCorrect(truffleArtifactsDirectory);
const compilerOptions: CompilerOptions = {
contractsDir,
artifactsDir,
compilerSettings: {
...solcConfig,
outputSelection: {
['*']: {
['*']: ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object'],
},
},
},
contracts: '*',
solcVersion: this._solcVersion,
};
const compiler = new Compiler(compilerOptions);
await compiler.compileAsync();
const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(artifactsDir, contractsDir);
const contractsDataFrom0xArtifacts = await solCompilerArtifactAdapter.collectContractsDataAsync();
return contractsDataFrom0xArtifacts;
}
private _getTruffleConfig(): TruffleConfig {