diff options
Diffstat (limited to 'packages/deployer/src/deployer.ts')
-rw-r--r-- | packages/deployer/src/deployer.ts | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/packages/deployer/src/deployer.ts b/packages/deployer/src/deployer.ts index ad05417b1..fe959e405 100644 --- a/packages/deployer/src/deployer.ts +++ b/packages/deployer/src/deployer.ts @@ -2,6 +2,7 @@ import { AbiType, ConstructorAbi, ContractAbi, Provider, TxData } from '@0xproje import { logUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; +import * as solc from 'solc'; import * as Web3 from 'web3'; import { Contract } from './utils/contract'; @@ -28,7 +29,20 @@ export class Deployer { private _artifactsDir: string; private _networkId: number; private _defaults: Partial<TxData>; - + /** + * Gets data for current version stored in artifact. + * @param contractArtifact The contract artifact. + * @return Version specific contract data. + */ + private static _getContractCompilerOutputFromArtifactIfExists( + contractArtifact: ContractArtifact, + ): solc.StandardContractOutput { + const compilerOutputIfExists = contractArtifact.compilerOutput; + if (_.isUndefined(compilerOutputIfExists)) { + throw new Error(`Compiler output not found in artifact for contract: ${contractArtifact.contractName}`); + } + return compilerOutputIfExists; + } /** * Instantiate a new instance of the Deployer class. * @param opts Deployer options, including either an RPC url or Provider instance. @@ -58,10 +72,8 @@ export class Deployer { */ public async deployAsync(contractName: string, args: any[] = []): Promise<Web3.ContractInstance> { const contractArtifactIfExists: ContractArtifact = this._loadContractArtifactIfExists(contractName); - const contractNetworkDataIfExists: ContractNetworkData = this._getContractNetworkDataFromArtifactIfExists( - contractArtifactIfExists, - ); - const data = contractNetworkDataIfExists.bytecode; + const compilerOutput = Deployer._getContractCompilerOutputFromArtifactIfExists(contractArtifactIfExists); + const data = compilerOutput.evm.bytecode.object; const from = await this._getFromAddressAsync(); const gas = await this._getAllowableGasEstimateAsync(data); const txData = { @@ -70,7 +82,7 @@ export class Deployer { data, gas, }; - const abi = contractNetworkDataIfExists.abi; + const abi = compilerOutput.abi; const constructorAbi = _.find(abi, { type: AbiType.Constructor }) as ConstructorAbi; const constructorArgs = _.isUndefined(constructorAbi) ? [] : constructorAbi.inputs; if (constructorArgs.length !== args.length) { @@ -138,15 +150,13 @@ export class Deployer { args: any[], ): Promise<void> { const contractArtifactIfExists: ContractArtifact = this._loadContractArtifactIfExists(contractName); - const contractNetworkDataIfExists: ContractNetworkData = this._getContractNetworkDataFromArtifactIfExists( - contractArtifactIfExists, - ); - const abi = contractNetworkDataIfExists.abi; + const compilerOutput = Deployer._getContractCompilerOutputFromArtifactIfExists(contractArtifactIfExists); + const abi = compilerOutput.abi; const encodedConstructorArgs = encoder.encodeConstructorArgsFromAbi(args, abi); - const newContractData = { - ...contractNetworkDataIfExists, + const newContractData: ContractNetworkData = { address: contractAddress, - constructor_args: encodedConstructorArgs, + links: {}, + constructorArgs: encodedConstructorArgs, }; const newArtifact = { ...contractArtifactIfExists, @@ -174,18 +184,6 @@ export class Deployer { } } /** - * Gets data for current networkId stored in artifact. - * @param contractArtifact The contract artifact. - * @return Network specific contract data. - */ - private _getContractNetworkDataFromArtifactIfExists(contractArtifact: ContractArtifact): ContractNetworkData { - const contractNetworkDataIfExists = contractArtifact.networks[this._networkId]; - if (_.isUndefined(contractNetworkDataIfExists)) { - throw new Error(`Data not found in artifact for contract: ${contractArtifact.contract_name}`); - } - return contractNetworkDataIfExists; - } - /** * Gets the address to use for sending a transaction. * @return The default from address. If not specified, returns the first address accessible by web3. */ |