How to use @0x/sol-compiler - 7 common examples

To help you get started, we’ve selected a few @0x/sol-compiler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / sol-meta / src / solc_wrapper.ts View on Github external
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: {
github LimeChain / etherlime / packages / etherlime / cli-commands / etherlime-test / etherlime-coverage.js View on Github external
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)

}
github smartcontractkit / chainlink / integration-scripts / src / common.ts View on Github external
'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',
          ],
        },
github 0xProject / 0x-monorepo / packages / contracts-gen / src / contracts-gen.ts View on Github external
(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);
github 0xProject / 0x-monorepo / packages / sol-doc / src / sol_doc.ts View on Github external
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)];
                }
github smartcontractkit / chainlink / belt / src / services / compilers / solc.ts View on Github external
'metadata',
          ],
        },
      },
      ...compilerSettingCopy,
    },
    contracts: '*',
    contractsDir: join(contractsDir, subDir),
    isOfflineMode: false,
    shouldSaveStandardInput: false,
    solcVersion,
    useDockerisedSolc,
  }
  _d('Settings: %o', settings)

  return new Compiler(settings)
}
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / artifact_adapters / truffle_artifact_adapter.ts View on Github external
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 {

@0x/sol-compiler

Solidity compiler wrapper and artifactor

Apache-2.0
Latest version published 1 year ago

Package Health Score

55 / 100
Full package analysis

Similar packages