Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/dependencies #198

Merged
merged 22 commits into from Jul 31, 2019
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Reintroducing our customization.

  • Loading branch information
Freydal committed Jul 30, 2019
commit b3a3318098c7c5e85b4a32bc91313172207fb844
@@ -0,0 +1,152 @@
// tslint:disable:no-consecutive-blank-lines ordered-imports align trailing-comma
// tslint:disable:whitespace no-unbound-method no-trailing-whitespace
// tslint:disable:no-unused-variable
import { BaseContract, PromiseWithTransactionHash } from '@0x/base-contract';
import { schemas } from '@0x/json-schemas';
import {
BlockParam,
BlockParamLiteral,
CallData,
ContractAbi,
ContractArtifact,
DecodedLogArgs,
MethodAbi,
TransactionReceiptWithDecodedLogs,
TxData,
TxDataPayable,
SupportedProvider,
} from 'ethereum-types';
import { BigNumber, classUtils, logUtils, providerUtils } from '@0x/utils';
import { SimpleContractArtifact } from '@0x/types';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { assert } from '@0x/assert';
import * as ethers from 'ethers';
// tslint:enable:no-unused-variable

{{#if events}}
export type {{contractName}}EventArgs =
{{#each events}}
| {{@root.contractName}}{{name}}EventArgs{{#if @last}};{{/if}}
{{/each}}

export enum {{contractName}}Events {
{{#each events}}
{{name}} = '{{name}}',
{{/each}}
}

{{#each events}}
{{> event}}

{{/each}}
{{/if}}

/* istanbul ignore next */
// tslint:disable:no-parameter-reassignment
// tslint:disable-next-line:class-name
export class {{contractName}}Contract extends BaseContract {
txReceipt: TransactionReceiptWithDecodedLogs
{{#each methods}}
{{#this.constant}}
{{> call contractName=../contractName}}
{{/this.constant}}
{{^this.constant}}
{{> tx contractName=../contractName}}
{{/this.constant}}
{{/each}}
public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact,
supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>,
{{> typed_params inputs=ctor.inputs}}
): Promise<{{contractName}}Contract> {
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (artifact.compilerOutput === undefined) {
throw new Error('Compiler output not found in the artifact file');
}
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const bytecode = artifact.compilerOutput.evm.bytecode.object;
const abi = artifact.compilerOutput.abi;
return {{contractName}}Contract.deployAsync(bytecode, abi, provider, txDefaults, {{> params inputs=ctor.inputs}});
}
public static async deployAsync(
bytecode: string,
abi: ContractAbi,
supportedProvider: SupportedProvider,
txDefaults: Partial<TxData>,
{{> typed_params inputs=ctor.inputs}}
): Promise<{{contractName}}Contract> {
assert.isHexString('bytecode', bytecode);
assert.doesConformToSchema('txDefaults', txDefaults, schemas.txDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const constructorAbi = BaseContract._lookupConstructorAbi(abi);
[{{> params inputs=ctor.inputs}}] = BaseContract._formatABIDataItemList(
constructorAbi.inputs,
[{{> params inputs=ctor.inputs}}],
BaseContract._bigNumberToString,
);
const iface = new ethers.utils.Interface(abi);
const deployInfo = iface.deployFunction;
const txData = deployInfo.encode(bytecode, [{{> params inputs=ctor.inputs}}]);
const web3Wrapper = new Web3Wrapper(provider);
const txDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{data: txData},
txDefaults,
web3Wrapper.estimateGasAsync.bind(web3Wrapper),
);
const txHash = await web3Wrapper.sendTransactionAsync(txDataWithDefaults);
logUtils.log(`transactionHash: ${txHash}`);
const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash);
logUtils.log(`{{contractName}} successfully deployed at ${txReceipt.contractAddress}`);
const contractInstance = new {{contractName}}Contract(txReceipt.contractAddress as string, provider, txDefaults);
contractInstance.constructorArgs = [{{> params inputs=ctor.inputs}}];
contractInstance.txReceipt = txReceipt
return contractInstance;
}


/**
* @returns The contract ABI
*/
public static ABI(): ContractAbi {
const abi = [
{{#each ABI}}
{ {{#if (isDefined this.constant)}}
constant: {{constant}},{{/if}}{{#if (isDefined this.anonymous)}}
anonymous: {{anonymous}},{{/if}}
inputs: [
{{#each inputs}}
{{> abi_type this}}
{{/each}}
],{{#this.name}}
name: '{{{this}}}',{{/this.name}}
outputs: [
{{#each outputs}}
{{> abi_type this}}
{{/each}}
],{{#if (isDefined this.payable)}}
payable: {{payable}},{{/if}}{{#this.stateMutability}}
stateMutability: '{{this}}',{{/this.stateMutability}}
type: '{{type}}',
},
{{/each}}
] as ContractAbi;
return abi;
}
constructor(address: string, supportedProvider: SupportedProvider, txDefaults?: Partial<TxData>) {
super('{{contractName}}', {{contractName}}Contract.ABI(), address, supportedProvider, txDefaults);
classUtils.bindAll(this, ['_abiEncoderByFunctionSignature', 'address', '_web3Wrapper']);
}
}

// tslint:disable:max-file-line-count
// tslint:enable:no-unbound-method no-parameter-reassignment no-consecutive-blank-lines ordered-imports align
// tslint:enable:trailing-comma whitespace no-trailing-whitespace
@@ -33,7 +33,7 @@
"prettier:deployedAddresses": "prettier --write src/deployedAddresses.json --config ../../.prettierrc",
"ganache_rpc": "docker run --rm -p 8545:8545 ${npm_package_config_kosu_ganache_image}",
"ganache_rpc:detached": "docker run --rm -d -p 8545:8545 ${npm_package_config_kosu_ganache_image}",
"generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output generated-wrappers --backend ethers",
"generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ./abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output generated-wrappers --backend ethers",
"docs": "node devdoc.js ./generated-artifacts ./docs "
},
"config": {
@@ -66,7 +66,7 @@
"devDependencies": {
"0x.js": "^6.0.9",
"@0x/abi-gen": "^3.1.1",
"@0x/abi-gen-templates": "^2.0.2",
"@0x/abi-gen-templates": "^2.3.0",
"@0x/contracts-gen": "^1.0.8",
"@0x/contracts-test-utils": "^3.1.2",
"@0x/migrations": "^4.1.6",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.