update contract_wrappers to use new artifacts and abi-gen wrappers packages

This commit is contained in:
Alex Browne 2018-10-04 14:40:58 -07:00
parent 8f0ceaf1d8
commit 2bd7b0f66b
15 changed files with 147 additions and 134 deletions

View File

@ -67,9 +67,10 @@
"web3-provider-engine": "14.0.6" "web3-provider-engine": "14.0.6"
}, },
"dependencies": { "dependencies": {
"@0xproject/contracts": "^2.1.48", "@0xproject/abi-gen-wrappers": "^1.0.0",
"@0xproject/assert": "^1.0.13", "@0xproject/assert": "^1.0.13",
"@0xproject/base-contract": "^3.0.1", "@0xproject/base-contract": "^3.0.1",
"@0xproject/contract-artifacts": "^1.0.0",
"@0xproject/fill-scenarios": "^1.0.7", "@0xproject/fill-scenarios": "^1.0.7",
"@0xproject/json-schemas": "^1.0.7", "@0xproject/json-schemas": "^1.0.7",
"@0xproject/order-utils": "^1.0.7", "@0xproject/order-utils": "^1.0.7",

View File

@ -1,4 +1,13 @@
import { artifacts } from '@0xproject/contracts'; import {
ERC20Proxy,
ERC20Token,
ERC721Proxy,
ERC721Token,
Exchange,
Forwarder,
OrderValidator,
WETH9,
} from '@0xproject/contract-artifacts';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider } from 'ethereum-types'; import { Provider } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
@ -71,14 +80,22 @@ export class ContractWrappers {
contractWrappersPrivateNetworkConfigSchema, contractWrappersPrivateNetworkConfigSchema,
contractWrappersPublicNetworkConfigSchema, contractWrappersPublicNetworkConfigSchema,
]); ]);
const artifactJSONs = _.values(artifacts);
const abiArrays = _.map(artifactJSONs, artifact => artifact.compilerOutput.abi);
const txDefaults = { const txDefaults = {
gasPrice: config.gasPrice, gasPrice: config.gasPrice,
}; };
this._web3Wrapper = new Web3Wrapper(provider, txDefaults); this._web3Wrapper = new Web3Wrapper(provider, txDefaults);
_.forEach(abiArrays, abi => { const artifactsArray = [
this._web3Wrapper.abiDecoder.addABI(abi); ERC20Proxy,
ERC20Token,
ERC721Proxy,
ERC721Token,
Exchange,
Forwarder,
OrderValidator,
WETH9,
];
_.forEach(artifactsArray, artifact => {
this._web3Wrapper.abiDecoder.addABI(artifact.compilerOutput.abi);
}); });
const blockPollingIntervalMs = _.isUndefined(config.blockPollingIntervalMs) const blockPollingIntervalMs = _.isUndefined(config.blockPollingIntervalMs)
? constants.DEFAULT_BLOCK_POLLING_INTERVAL ? constants.DEFAULT_BLOCK_POLLING_INTERVAL
@ -114,7 +131,6 @@ export class ContractWrappers {
* @param networkId The id of the network your provider is connected to * @param networkId The id of the network your provider is connected to
*/ */
public setProvider(provider: Provider): void { public setProvider(provider: Provider): void {
// TODO(albrow): Make sure all contract wrappers are called below.
this._web3Wrapper.setProvider(provider); this._web3Wrapper.setProvider(provider);
(this.exchange as any)._invalidateContractInstances(); (this.exchange as any)._invalidateContractInstances();
(this.erc20Token as any)._invalidateContractInstances(); (this.erc20Token as any)._invalidateContractInstances();

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { ERC20ProxyContract } from '@0xproject/abi-gen-wrappers';
import { ERC20Proxy } from '@0xproject/contract-artifacts';
import { AssetProxyId } from '@0xproject/types'; import { AssetProxyId } from '@0xproject/types';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { ContractAbi } from 'ethereum-types'; import { ContractAbi } from 'ethereum-types';
@ -12,9 +13,9 @@ import { ContractWrapper } from './contract_wrapper';
* This class includes the functionality related to interacting with the ERC20Proxy contract. * This class includes the functionality related to interacting with the ERC20Proxy contract.
*/ */
export class ERC20ProxyWrapper extends ContractWrapper { export class ERC20ProxyWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.ERC20Proxy.compilerOutput.abi; public abi: ContractAbi = ERC20Proxy.compilerOutput.abi;
public address: string; public address: string;
private _erc20ProxyContractIfExists?: wrappers.ERC20ProxyContract; private _erc20ProxyContractIfExists?: ERC20ProxyContract;
/** /**
* Instantiate ERC20ProxyWrapper * Instantiate ERC20ProxyWrapper
* @param web3Wrapper Web3Wrapper instance to use * @param web3Wrapper Web3Wrapper instance to use
@ -62,11 +63,11 @@ export class ERC20ProxyWrapper extends ContractWrapper {
private _invalidateContractInstance(): void { private _invalidateContractInstance(): void {
delete this._erc20ProxyContractIfExists; delete this._erc20ProxyContractIfExists;
} }
private _getERC20ProxyContract(): wrappers.ERC20ProxyContract { private _getERC20ProxyContract(): ERC20ProxyContract {
if (!_.isUndefined(this._erc20ProxyContractIfExists)) { if (!_.isUndefined(this._erc20ProxyContractIfExists)) {
return this._erc20ProxyContractIfExists; return this._erc20ProxyContractIfExists;
} }
const contractInstance = new wrappers.ERC20ProxyContract( const contractInstance = new ERC20ProxyContract(
this.abi, this.abi,
this.address, this.address,
this._web3Wrapper.getProvider(), this._web3Wrapper.getProvider(),

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { ERC20TokenContract, ERC20TokenEventArgs, ERC20TokenEvents } from '@0xproject/abi-gen-wrappers';
import { ERC20Token } from '@0xproject/contract-artifacts';
import { schemas } from '@0xproject/json-schemas'; import { schemas } from '@0xproject/json-schemas';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
@ -29,9 +30,9 @@ const removeUndefinedProperties = _.pickBy;
* to the 0x ERC20 Proxy smart contract. * to the 0x ERC20 Proxy smart contract.
*/ */
export class ERC20TokenWrapper extends ContractWrapper { export class ERC20TokenWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.ERC20Token.compilerOutput.abi; public abi: ContractAbi = ERC20Token.compilerOutput.abi;
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
private _tokenContractsByAddress: { [address: string]: wrappers.ERC20TokenContract }; private _tokenContractsByAddress: { [address: string]: ERC20TokenContract };
private _erc20ProxyWrapper: ERC20ProxyWrapper; private _erc20ProxyWrapper: ERC20ProxyWrapper;
/** /**
* Instantiate ERC20TokenWrapper * Instantiate ERC20TokenWrapper
@ -350,15 +351,15 @@ export class ERC20TokenWrapper extends ContractWrapper {
* @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered)
* @return Subscription token used later to unsubscribe * @return Subscription token used later to unsubscribe
*/ */
public subscribe<ArgsType extends wrappers.ERC20TokenEventArgs>( public subscribe<ArgsType extends ERC20TokenEventArgs>(
tokenAddress: string, tokenAddress: string,
eventName: wrappers.ERC20TokenEvents, eventName: ERC20TokenEvents,
indexFilterValues: IndexedFilterValues, indexFilterValues: IndexedFilterValues,
callback: EventCallback<ArgsType>, callback: EventCallback<ArgsType>,
isVerbose: boolean = false, isVerbose: boolean = false,
): string { ): string {
assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC20TokenEvents); assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback); assert.isFunction('callback', callback);
const normalizedTokenAddress = tokenAddress.toLowerCase(); const normalizedTokenAddress = tokenAddress.toLowerCase();
@ -366,7 +367,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
normalizedTokenAddress, normalizedTokenAddress,
eventName, eventName,
indexFilterValues, indexFilterValues,
artifacts.ERC20Token.compilerOutput.abi, ERC20Token.compilerOutput.abi,
callback, callback,
isVerbose, isVerbose,
); );
@ -395,14 +396,14 @@ export class ERC20TokenWrapper extends ContractWrapper {
* the value is the value you are interested in. E.g `{_from: aUserAddressHex}` * the value is the value you are interested in. E.g `{_from: aUserAddressHex}`
* @return Array of logs that match the parameters * @return Array of logs that match the parameters
*/ */
public async getLogsAsync<ArgsType extends wrappers.ERC20TokenEventArgs>( public async getLogsAsync<ArgsType extends ERC20TokenEventArgs>(
tokenAddress: string, tokenAddress: string,
eventName: wrappers.ERC20TokenEvents, eventName: ERC20TokenEvents,
blockRange: BlockRange, blockRange: BlockRange,
indexFilterValues: IndexedFilterValues, indexFilterValues: IndexedFilterValues,
): Promise<Array<LogWithDecodedArgs<ArgsType>>> { ): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC20TokenEvents); assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase(); const normalizedTokenAddress = tokenAddress.toLowerCase();
@ -411,7 +412,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
eventName, eventName,
blockRange, blockRange,
indexFilterValues, indexFilterValues,
artifacts.ERC20Token.compilerOutput.abi, ERC20Token.compilerOutput.abi,
); );
return logs; return logs;
} }
@ -422,7 +423,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
this.unsubscribeAll(); this.unsubscribeAll();
this._tokenContractsByAddress = {}; this._tokenContractsByAddress = {};
} }
private async _getTokenContractAsync(tokenAddress: string): Promise<wrappers.ERC20TokenContract> { private async _getTokenContractAsync(tokenAddress: string): Promise<ERC20TokenContract> {
const normalizedTokenAddress = tokenAddress.toLowerCase(); const normalizedTokenAddress = tokenAddress.toLowerCase();
let tokenContract = this._tokenContractsByAddress[normalizedTokenAddress]; let tokenContract = this._tokenContractsByAddress[normalizedTokenAddress];
if (!_.isUndefined(tokenContract)) { if (!_.isUndefined(tokenContract)) {
@ -434,7 +435,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
if (!doesContractExist) { if (!doesContractExist) {
throw new Error(ContractWrappersError.ERC20TokenContractDoesNotExist); throw new Error(ContractWrappersError.ERC20TokenContractDoesNotExist);
} }
const contractInstance = new wrappers.ERC20TokenContract( const contractInstance = new ERC20TokenContract(
this.abi, this.abi,
normalizedTokenAddress, normalizedTokenAddress,
this._web3Wrapper.getProvider(), this._web3Wrapper.getProvider(),

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { ERC721ProxyContract } from '@0xproject/abi-gen-wrappers';
import { ERC721Proxy } from '@0xproject/contract-artifacts';
import { AssetProxyId } from '@0xproject/types'; import { AssetProxyId } from '@0xproject/types';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { ContractAbi } from 'ethereum-types'; import { ContractAbi } from 'ethereum-types';
@ -12,9 +13,9 @@ import { ContractWrapper } from './contract_wrapper';
* This class includes the functionality related to interacting with the ERC721Proxy contract. * This class includes the functionality related to interacting with the ERC721Proxy contract.
*/ */
export class ERC721ProxyWrapper extends ContractWrapper { export class ERC721ProxyWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.ERC20Proxy.compilerOutput.abi; public abi: ContractAbi = ERC721Proxy.compilerOutput.abi;
public address: string; public address: string;
private _erc721ProxyContractIfExists?: wrappers.ERC721ProxyContract; private _erc721ProxyContractIfExists?: ERC721ProxyContract;
/** /**
* Instantiate ERC721ProxyWrapper * Instantiate ERC721ProxyWrapper
* @param web3Wrapper Web3Wrapper instance to use * @param web3Wrapper Web3Wrapper instance to use
@ -62,11 +63,11 @@ export class ERC721ProxyWrapper extends ContractWrapper {
private _invalidateContractInstance(): void { private _invalidateContractInstance(): void {
delete this._erc721ProxyContractIfExists; delete this._erc721ProxyContractIfExists;
} }
private _getERC721ProxyContract(): wrappers.ERC721ProxyContract { private _getERC721ProxyContract(): ERC721ProxyContract {
if (!_.isUndefined(this._erc721ProxyContractIfExists)) { if (!_.isUndefined(this._erc721ProxyContractIfExists)) {
return this._erc721ProxyContractIfExists; return this._erc721ProxyContractIfExists;
} }
const contractInstance = new wrappers.ERC721ProxyContract( const contractInstance = new ERC721ProxyContract(
this.abi, this.abi,
this.address, this.address,
this._web3Wrapper.getProvider(), this._web3Wrapper.getProvider(),

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { ERC721TokenContract, ERC721TokenEventArgs, ERC721TokenEvents } from '@0xproject/abi-gen-wrappers';
import { ERC721Token } from '@0xproject/contract-artifacts';
import { schemas } from '@0xproject/json-schemas'; import { schemas } from '@0xproject/json-schemas';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
@ -29,8 +30,8 @@ const removeUndefinedProperties = _.pickBy;
* to the 0x ERC721 Proxy smart contract. * to the 0x ERC721 Proxy smart contract.
*/ */
export class ERC721TokenWrapper extends ContractWrapper { export class ERC721TokenWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.ERC721Token.compilerOutput.abi; public abi: ContractAbi = ERC721Token.compilerOutput.abi;
private _tokenContractsByAddress: { [address: string]: wrappers.ERC721TokenContract }; private _tokenContractsByAddress: { [address: string]: ERC721TokenContract };
private _erc721ProxyWrapper: ERC721ProxyWrapper; private _erc721ProxyWrapper: ERC721ProxyWrapper;
/** /**
* Instantiate ERC721TokenWrapper * Instantiate ERC721TokenWrapper
@ -377,15 +378,15 @@ export class ERC721TokenWrapper extends ContractWrapper {
* @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered)
* @return Subscription token used later to unsubscribe * @return Subscription token used later to unsubscribe
*/ */
public subscribe<ArgsType extends wrappers.ERC721TokenEventArgs>( public subscribe<ArgsType extends ERC721TokenEventArgs>(
tokenAddress: string, tokenAddress: string,
eventName: wrappers.ERC721TokenEvents, eventName: ERC721TokenEvents,
indexFilterValues: IndexedFilterValues, indexFilterValues: IndexedFilterValues,
callback: EventCallback<ArgsType>, callback: EventCallback<ArgsType>,
isVerbose: boolean = false, isVerbose: boolean = false,
): string { ): string {
assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC721TokenEvents); assert.doesBelongToStringEnum('eventName', eventName, ERC721TokenEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback); assert.isFunction('callback', callback);
const normalizedTokenAddress = tokenAddress.toLowerCase(); const normalizedTokenAddress = tokenAddress.toLowerCase();
@ -393,7 +394,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
normalizedTokenAddress, normalizedTokenAddress,
eventName, eventName,
indexFilterValues, indexFilterValues,
artifacts.ERC721Token.compilerOutput.abi, ERC721Token.compilerOutput.abi,
callback, callback,
isVerbose, isVerbose,
); );
@ -422,14 +423,14 @@ export class ERC721TokenWrapper extends ContractWrapper {
* the value is the value you are interested in. E.g `{_from: aUserAddressHex}` * the value is the value you are interested in. E.g `{_from: aUserAddressHex}`
* @return Array of logs that match the parameters * @return Array of logs that match the parameters
*/ */
public async getLogsAsync<ArgsType extends wrappers.ERC721TokenEventArgs>( public async getLogsAsync<ArgsType extends ERC721TokenEventArgs>(
tokenAddress: string, tokenAddress: string,
eventName: wrappers.ERC721TokenEvents, eventName: ERC721TokenEvents,
blockRange: BlockRange, blockRange: BlockRange,
indexFilterValues: IndexedFilterValues, indexFilterValues: IndexedFilterValues,
): Promise<Array<LogWithDecodedArgs<ArgsType>>> { ): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC721TokenEvents); assert.doesBelongToStringEnum('eventName', eventName, ERC721TokenEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const normalizedTokenAddress = tokenAddress.toLowerCase(); const normalizedTokenAddress = tokenAddress.toLowerCase();
@ -438,7 +439,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
eventName, eventName,
blockRange, blockRange,
indexFilterValues, indexFilterValues,
artifacts.ERC721Token.compilerOutput.abi, ERC721Token.compilerOutput.abi,
); );
return logs; return logs;
} }
@ -449,7 +450,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
this.unsubscribeAll(); this.unsubscribeAll();
this._tokenContractsByAddress = {}; this._tokenContractsByAddress = {};
} }
private async _getTokenContractAsync(tokenAddress: string): Promise<wrappers.ERC721TokenContract> { private async _getTokenContractAsync(tokenAddress: string): Promise<ERC721TokenContract> {
const normalizedTokenAddress = tokenAddress.toLowerCase(); const normalizedTokenAddress = tokenAddress.toLowerCase();
let tokenContract = this._tokenContractsByAddress[normalizedTokenAddress]; let tokenContract = this._tokenContractsByAddress[normalizedTokenAddress];
if (!_.isUndefined(tokenContract)) { if (!_.isUndefined(tokenContract)) {
@ -461,7 +462,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
if (!doesContractExist) { if (!doesContractExist) {
throw new Error(ContractWrappersError.ERC721TokenContractDoesNotExist); throw new Error(ContractWrappersError.ERC721TokenContractDoesNotExist);
} }
const contractInstance = new wrappers.ERC721TokenContract( const contractInstance = new ERC721TokenContract(
this.abi, this.abi,
normalizedTokenAddress, normalizedTokenAddress,
this._web3Wrapper.getProvider(), this._web3Wrapper.getProvider(),

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { WETH9Contract, WETH9EventArgs, WETH9Events } from '@0xproject/abi-gen-wrappers';
import { WETH9 } from '@0xproject/contract-artifacts';
import { schemas } from '@0xproject/json-schemas'; import { schemas } from '@0xproject/json-schemas';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
@ -18,9 +19,9 @@ const removeUndefinedProperties = _.pickBy;
* The caller can convert ETH into the equivalent number of wrapped ETH ERC20 tokens and back. * The caller can convert ETH into the equivalent number of wrapped ETH ERC20 tokens and back.
*/ */
export class EtherTokenWrapper extends ContractWrapper { export class EtherTokenWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.WETH9.compilerOutput.abi; public abi: ContractAbi = WETH9.compilerOutput.abi;
private _etherTokenContractsByAddress: { private _etherTokenContractsByAddress: {
[address: string]: wrappers.WETH9Contract; [address: string]: WETH9Contract;
} = {}; } = {};
private _erc20TokenWrapper: ERC20TokenWrapper; private _erc20TokenWrapper: ERC20TokenWrapper;
/** /**
@ -120,15 +121,15 @@ export class EtherTokenWrapper extends ContractWrapper {
* the value is the value you are interested in. E.g `{_owner: aUserAddressHex}` * the value is the value you are interested in. E.g `{_owner: aUserAddressHex}`
* @return Array of logs that match the parameters * @return Array of logs that match the parameters
*/ */
public async getLogsAsync<ArgsType extends wrappers.WETH9EventArgs>( public async getLogsAsync<ArgsType extends WETH9EventArgs>(
etherTokenAddress: string, etherTokenAddress: string,
eventName: wrappers.WETH9Events, eventName: WETH9Events,
blockRange: BlockRange, blockRange: BlockRange,
indexFilterValues: IndexedFilterValues, indexFilterValues: IndexedFilterValues,
): Promise<Array<LogWithDecodedArgs<ArgsType>>> { ): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.isETHAddressHex('etherTokenAddress', etherTokenAddress); assert.isETHAddressHex('etherTokenAddress', etherTokenAddress);
const normalizedEtherTokenAddress = etherTokenAddress.toLowerCase(); const normalizedEtherTokenAddress = etherTokenAddress.toLowerCase();
assert.doesBelongToStringEnum('eventName', eventName, wrappers.WETH9Events); assert.doesBelongToStringEnum('eventName', eventName, WETH9Events);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const logs = await this._getLogsAsync<ArgsType>( const logs = await this._getLogsAsync<ArgsType>(
@ -136,7 +137,7 @@ export class EtherTokenWrapper extends ContractWrapper {
eventName, eventName,
blockRange, blockRange,
indexFilterValues, indexFilterValues,
artifacts.WETH9.compilerOutput.abi, WETH9.compilerOutput.abi,
); );
return logs; return logs;
} }
@ -150,23 +151,23 @@ export class EtherTokenWrapper extends ContractWrapper {
* @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered)
* @return Subscription token used later to unsubscribe * @return Subscription token used later to unsubscribe
*/ */
public subscribe<ArgsType extends wrappers.WETH9EventArgs>( public subscribe<ArgsType extends WETH9EventArgs>(
etherTokenAddress: string, etherTokenAddress: string,
eventName: wrappers.WETH9Events, eventName: WETH9Events,
indexFilterValues: IndexedFilterValues, indexFilterValues: IndexedFilterValues,
callback: EventCallback<ArgsType>, callback: EventCallback<ArgsType>,
isVerbose: boolean = false, isVerbose: boolean = false,
): string { ): string {
assert.isETHAddressHex('etherTokenAddress', etherTokenAddress); assert.isETHAddressHex('etherTokenAddress', etherTokenAddress);
const normalizedEtherTokenAddress = etherTokenAddress.toLowerCase(); const normalizedEtherTokenAddress = etherTokenAddress.toLowerCase();
assert.doesBelongToStringEnum('eventName', eventName, wrappers.WETH9Events); assert.doesBelongToStringEnum('eventName', eventName, WETH9Events);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback); assert.isFunction('callback', callback);
const subscriptionToken = this._subscribe<ArgsType>( const subscriptionToken = this._subscribe<ArgsType>(
normalizedEtherTokenAddress, normalizedEtherTokenAddress,
eventName, eventName,
indexFilterValues, indexFilterValues,
artifacts.WETH9.compilerOutput.abi, WETH9.compilerOutput.abi,
callback, callback,
isVerbose, isVerbose,
); );
@ -191,7 +192,7 @@ export class EtherTokenWrapper extends ContractWrapper {
this.unsubscribeAll(); this.unsubscribeAll();
this._etherTokenContractsByAddress = {}; this._etherTokenContractsByAddress = {};
} }
private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise<wrappers.WETH9Contract> { private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise<WETH9Contract> {
let etherTokenContract = this._etherTokenContractsByAddress[etherTokenAddress]; let etherTokenContract = this._etherTokenContractsByAddress[etherTokenAddress];
if (!_.isUndefined(etherTokenContract)) { if (!_.isUndefined(etherTokenContract)) {
return etherTokenContract; return etherTokenContract;
@ -203,7 +204,7 @@ export class EtherTokenWrapper extends ContractWrapper {
if (!doesContractExist) { if (!doesContractExist) {
throw new Error(ContractWrappersError.EtherTokenContractDoesNotExist); throw new Error(ContractWrappersError.EtherTokenContractDoesNotExist);
} }
const contractInstance = new wrappers.WETH9Contract( const contractInstance = new WETH9Contract(
this.abi, this.abi,
etherTokenAddress, etherTokenAddress,
this._web3Wrapper.getProvider(), this._web3Wrapper.getProvider(),

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from '@0xproject/abi-gen-wrappers';
import { Exchange } from '@0xproject/contract-artifacts';
import { schemas } from '@0xproject/json-schemas'; import { schemas } from '@0xproject/json-schemas';
import { import {
assetDataUtils, assetDataUtils,
@ -40,10 +41,10 @@ import { ERC721TokenWrapper } from './erc721_token_wrapper';
* events of the 0x V2 Exchange smart contract. * events of the 0x V2 Exchange smart contract.
*/ */
export class ExchangeWrapper extends ContractWrapper { export class ExchangeWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.Exchange.compilerOutput.abi; public abi: ContractAbi = Exchange.compilerOutput.abi;
public address: string; public address: string;
public zrxTokenAddress: string; public zrxTokenAddress: string;
private _exchangeContractIfExists?: wrappers.ExchangeContract; private _exchangeContractIfExists?: ExchangeContract;
private _erc721TokenWrapper: ERC721TokenWrapper; private _erc721TokenWrapper: ERC721TokenWrapper;
private _erc20TokenWrapper: ERC20TokenWrapper; private _erc20TokenWrapper: ERC20TokenWrapper;
/** /**
@ -1039,20 +1040,20 @@ export class ExchangeWrapper extends ContractWrapper {
* @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered)
* @return Subscription token used later to unsubscribe * @return Subscription token used later to unsubscribe
*/ */
public subscribe<ArgsType extends wrappers.ExchangeEventArgs>( public subscribe<ArgsType extends ExchangeEventArgs>(
eventName: wrappers.ExchangeEvents, eventName: ExchangeEvents,
indexFilterValues: IndexedFilterValues, indexFilterValues: IndexedFilterValues,
callback: EventCallback<ArgsType>, callback: EventCallback<ArgsType>,
isVerbose: boolean = false, isVerbose: boolean = false,
): string { ): string {
assert.doesBelongToStringEnum('eventName', eventName, wrappers.ExchangeEvents); assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback); assert.isFunction('callback', callback);
const subscriptionToken = this._subscribe<ArgsType>( const subscriptionToken = this._subscribe<ArgsType>(
this.address, this.address,
eventName, eventName,
indexFilterValues, indexFilterValues,
artifacts.Exchange.compilerOutput.abi, Exchange.compilerOutput.abi,
callback, callback,
isVerbose, isVerbose,
); );
@ -1079,12 +1080,12 @@ export class ExchangeWrapper extends ContractWrapper {
* the value is the value you are interested in. E.g `{_from: aUserAddressHex}` * the value is the value you are interested in. E.g `{_from: aUserAddressHex}`
* @return Array of logs that match the parameters * @return Array of logs that match the parameters
*/ */
public async getLogsAsync<ArgsType extends wrappers.ExchangeEventArgs>( public async getLogsAsync<ArgsType extends ExchangeEventArgs>(
eventName: wrappers.ExchangeEvents, eventName: ExchangeEvents,
blockRange: BlockRange, blockRange: BlockRange,
indexFilterValues: IndexedFilterValues, indexFilterValues: IndexedFilterValues,
): Promise<Array<LogWithDecodedArgs<ArgsType>>> { ): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.doesBelongToStringEnum('eventName', eventName, wrappers.ExchangeEvents); assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const logs = await this._getLogsAsync<ArgsType>( const logs = await this._getLogsAsync<ArgsType>(
@ -1092,7 +1093,7 @@ export class ExchangeWrapper extends ContractWrapper {
eventName, eventName,
blockRange, blockRange,
indexFilterValues, indexFilterValues,
artifacts.Exchange.compilerOutput.abi, Exchange.compilerOutput.abi,
); );
return logs; return logs;
} }
@ -1178,11 +1179,11 @@ export class ExchangeWrapper extends ContractWrapper {
delete this._exchangeContractIfExists; delete this._exchangeContractIfExists;
} }
// tslint:enable:no-unused-variable // tslint:enable:no-unused-variable
private async _getExchangeContractAsync(): Promise<wrappers.ExchangeContract> { private async _getExchangeContractAsync(): Promise<ExchangeContract> {
if (!_.isUndefined(this._exchangeContractIfExists)) { if (!_.isUndefined(this._exchangeContractIfExists)) {
return this._exchangeContractIfExists; return this._exchangeContractIfExists;
} }
const contractInstance = new wrappers.ExchangeContract( const contractInstance = new ExchangeContract(
this.abi, this.abi,
this.address, this.address,
this._web3Wrapper.getProvider(), this._web3Wrapper.getProvider(),

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { ForwarderContract } from '@0xproject/abi-gen-wrappers';
import { Forwarder } from '@0xproject/contract-artifacts';
import { schemas } from '@0xproject/json-schemas'; import { schemas } from '@0xproject/json-schemas';
import { AssetProxyId, SignedOrder } from '@0xproject/types'; import { AssetProxyId, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
@ -21,11 +22,11 @@ import { ContractWrapper } from './contract_wrapper';
* This class includes the functionality related to interacting with the Forwarder contract. * This class includes the functionality related to interacting with the Forwarder contract.
*/ */
export class ForwarderWrapper extends ContractWrapper { export class ForwarderWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.Forwarder.compilerOutput.abi; public abi: ContractAbi = Forwarder.compilerOutput.abi;
public address: string; public address: string;
public zrxTokenAddress: string; public zrxTokenAddress: string;
public etherTokenAddress: string; public etherTokenAddress: string;
private _forwarderContractIfExists?: wrappers.ForwarderContract; private _forwarderContractIfExists?: ForwarderContract;
// TODO(albrow): Make addresses optional? // TODO(albrow): Make addresses optional?
constructor(web3Wrapper: Web3Wrapper, address: string, zrxTokenAddress: string, etherTokenAddress: string) { constructor(web3Wrapper: Web3Wrapper, address: string, zrxTokenAddress: string, etherTokenAddress: string) {
super(web3Wrapper); super(web3Wrapper);
@ -215,11 +216,11 @@ export class ForwarderWrapper extends ContractWrapper {
private _invalidateContractInstance(): void { private _invalidateContractInstance(): void {
delete this._forwarderContractIfExists; delete this._forwarderContractIfExists;
} }
private async _getForwarderContractAsync(): Promise<wrappers.ForwarderContract> { private async _getForwarderContractAsync(): Promise<ForwarderContract> {
if (!_.isUndefined(this._forwarderContractIfExists)) { if (!_.isUndefined(this._forwarderContractIfExists)) {
return this._forwarderContractIfExists; return this._forwarderContractIfExists;
} }
const contractInstance = new wrappers.ForwarderContract( const contractInstance = new ForwarderContract(
this.abi, this.abi,
this.address, this.address,
this._web3Wrapper.getProvider(), this._web3Wrapper.getProvider(),

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { OrderValidatorContract } from '@0xproject/abi-gen-wrappers';
import { OrderValidator } from '@0xproject/contract-artifacts';
import { schemas } from '@0xproject/json-schemas'; import { schemas } from '@0xproject/json-schemas';
import { SignedOrder } from '@0xproject/types'; import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
@ -15,9 +16,9 @@ import { ContractWrapper } from './contract_wrapper';
* This class includes the functionality related to interacting with the OrderValidator contract. * This class includes the functionality related to interacting with the OrderValidator contract.
*/ */
export class OrderValidatorWrapper extends ContractWrapper { export class OrderValidatorWrapper extends ContractWrapper {
public abi: ContractAbi = artifacts.OrderValidator.compilerOutput.abi; public abi: ContractAbi = OrderValidator.compilerOutput.abi;
public address: string; public address: string;
private _orderValidatorContractIfExists?: wrappers.OrderValidatorContract; private _orderValidatorContractIfExists?: OrderValidatorContract;
/** /**
* Instantiate OrderValidatorWrapper * Instantiate OrderValidatorWrapper
* @param web3Wrapper Web3Wrapper instance to use. * @param web3Wrapper Web3Wrapper instance to use.
@ -172,11 +173,11 @@ export class OrderValidatorWrapper extends ContractWrapper {
private _invalidateContractInstance(): void { private _invalidateContractInstance(): void {
delete this._orderValidatorContractIfExists; delete this._orderValidatorContractIfExists;
} }
private async _getOrderValidatorContractAsync(): Promise<wrappers.OrderValidatorContract> { private async _getOrderValidatorContractAsync(): Promise<OrderValidatorContract> {
if (!_.isUndefined(this._orderValidatorContractIfExists)) { if (!_.isUndefined(this._orderValidatorContractIfExists)) {
return this._orderValidatorContractIfExists; return this._orderValidatorContractIfExists;
} }
const contractInstance = new wrappers.OrderValidatorContract( const contractInstance = new OrderValidatorContract(
this.abi, this.abi,
this.address, this.address,
this._web3Wrapper.getProvider(), this._web3Wrapper.getProvider(),

View File

@ -1,6 +0,0 @@
declare module '*.json' {
const json: any;
/* tslint:disable */
export default json;
/* tslint:enable */
}

View File

@ -1,4 +1,27 @@
import { wrappers } from '@0xproject/contracts'; export {
WETH9Events,
WETH9WithdrawalEventArgs,
WETH9ApprovalEventArgs,
WETH9EventArgs,
WETH9DepositEventArgs,
WETH9TransferEventArgs,
ERC20TokenTransferEventArgs,
ERC20TokenApprovalEventArgs,
ERC20TokenEvents,
ERC20TokenEventArgs,
ERC721TokenApprovalEventArgs,
ERC721TokenApprovalForAllEventArgs,
ERC721TokenTransferEventArgs,
ERC721TokenEvents,
ERC721TokenEventArgs,
ExchangeCancelUpToEventArgs,
ExchangeAssetProxyRegisteredEventArgs,
ExchangeSignatureValidatorApprovalEventArgs,
ExchangeFillEventArgs,
ExchangeCancelEventArgs,
ExchangeEventArgs,
ExchangeEvents,
} from '@0xproject/abi-gen-wrappers';
export { ContractWrappers } from './contract_wrappers'; export { ContractWrappers } from './contract_wrappers';
export { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper'; export { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper';
@ -56,32 +79,6 @@ export {
StateMutability, StateMutability,
} from 'ethereum-types'; } from 'ethereum-types';
export const WETH9Events = wrappers.WETH9Events;
export type WETH9WithdrawalEventArgs = wrappers.WETH9WithdrawalEventArgs;
export type WETH9ApprovalEventArgs = wrappers.WETH9ApprovalEventArgs;
export type WETH9EventArgs = wrappers.WETH9EventArgs;
export type WETH9DepositEventArgs = wrappers.WETH9DepositEventArgs;
export type WETH9TransferEventArgs = wrappers.WETH9TransferEventArgs;
export type ERC20TokenTransferEventArgs = wrappers.ERC20TokenTransferEventArgs;
export type ERC20TokenApprovalEventArgs = wrappers.ERC20TokenApprovalEventArgs;
export const ERC20TokenEvents = wrappers.ERC20TokenEvents;
export type ERC20TokenEventArgs = wrappers.ERC20TokenEventArgs;
export type ERC721TokenApprovalEventArgs = wrappers.ERC721TokenApprovalEventArgs;
export type ERC721TokenApprovalForAllEventArgs = wrappers.ERC721TokenApprovalForAllEventArgs;
export type ERC721TokenTransferEventArgs = wrappers.ERC721TokenTransferEventArgs;
export const ERC721TokenEvents = wrappers.ERC721TokenEvents;
export type ERC721TokenEventArgs = wrappers.ERC721TokenEventArgs;
export type ExchangeCancelUpToEventArgs = wrappers.ExchangeCancelUpToEventArgs;
export type ExchangeAssetProxyRegisteredEventArgs = wrappers.ExchangeAssetProxyRegisteredEventArgs;
export type ExchangeSignatureValidatorApprovalEventArgs = wrappers.ExchangeSignatureValidatorApprovalEventArgs;
export type ExchangeFillEventArgs = wrappers.ExchangeFillEventArgs;
export type ExchangeCancelEventArgs = wrappers.ExchangeCancelEventArgs;
export type ExchangeEventArgs = wrappers.ExchangeEventArgs;
export const ExchangeEvents = wrappers.ExchangeEvents;
export { AbstractBalanceAndProxyAllowanceFetcher, AbstractOrderFilledCancelledFetcher } from '@0xproject/order-utils'; export { AbstractBalanceAndProxyAllowanceFetcher, AbstractOrderFilledCancelledFetcher } from '@0xproject/order-utils';
export { AssetBalanceAndProxyAllowanceFetcher } from './fetchers/asset_balance_and_proxy_allowance_fetcher'; export { AssetBalanceAndProxyAllowanceFetcher } from './fetchers/asset_balance_and_proxy_allowance_fetcher';

View File

@ -1,4 +1,13 @@
import { wrappers } from '@0xproject/contracts'; import {
ERC20TokenEventArgs,
ERC20TokenEvents,
ERC721TokenEventArgs,
ERC721TokenEvents,
ExchangeEventArgs,
ExchangeEvents,
WETH9EventArgs,
WETH9Events,
} from '@0xproject/abi-gen-wrappers';
import { ContractAddresses, OrderState, SignedOrder } from '@0xproject/types'; import { ContractAddresses, OrderState, SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
@ -56,11 +65,7 @@ export interface ContractEvent {
args: ContractEventArgs; args: ContractEventArgs;
} }
export type ContractEventArgs = export type ContractEventArgs = ExchangeEventArgs | ERC20TokenEventArgs | ERC721TokenEventArgs | WETH9EventArgs;
| wrappers.ExchangeEventArgs
| wrappers.ERC20TokenEventArgs
| wrappers.ERC721TokenEventArgs
| wrappers.WETH9EventArgs;
// [address, name, symbol, decimals, ipfsHash, swarmHash] // [address, name, symbol, decimals, ipfsHash, swarmHash]
export type TokenMetadata = [string, string, string, number, string, string]; export type TokenMetadata = [string, string, string, number, string, string];
@ -83,11 +88,7 @@ export interface TokenAddressBySymbol {
[symbol: string]: string; [symbol: string]: string;
} }
export type ContractEvents = export type ContractEvents = ERC20TokenEvents | ERC721TokenEvents | ExchangeEvents | WETH9Events;
| wrappers.ERC20TokenEvents
| wrappers.ERC721TokenEvents
| wrappers.ExchangeEvents
| wrappers.WETH9Events;
export interface IndexedFilterValues { export interface IndexedFilterValues {
[index: string]: ContractEventArg; [index: string]: ContractEventArg;

View File

@ -1,4 +1,4 @@
import { wrappers } from '@0xproject/contracts'; import { ExchangeContract } from '@0xproject/abi-gen-wrappers';
import { schemas } from '@0xproject/json-schemas'; import { schemas } from '@0xproject/json-schemas';
import { eip712Utils } from '@0xproject/order-utils'; import { eip712Utils } from '@0xproject/order-utils';
@ -14,8 +14,8 @@ import { assert } from './assert';
* can submit this to the blockchain. The Exchange context executes as if UserA had directly submitted this transaction. * can submit this to the blockchain. The Exchange context executes as if UserA had directly submitted this transaction.
*/ */
export class TransactionEncoder { export class TransactionEncoder {
private readonly _exchangeInstance: wrappers.ExchangeContract; private readonly _exchangeInstance: ExchangeContract;
constructor(exchangeInstance: wrappers.ExchangeContract) { constructor(exchangeInstance: ExchangeContract) {
this._exchangeInstance = exchangeInstance; this._exchangeInstance = exchangeInstance;
} }
/** /**
@ -275,7 +275,7 @@ export class TransactionEncoder {
); );
return abiEncodedData; return abiEncodedData;
} }
private _getExchangeContract(): wrappers.ExchangeContract { private _getExchangeContract(): ExchangeContract {
return this._exchangeInstance; return this._exchangeInstance;
} }
} }

View File

@ -1,4 +1,5 @@
import { artifacts, wrappers } from '@0xproject/contracts'; import { DummyERC721TokenContract } from '@0xproject/abi-gen-wrappers';
import { DummyERC721Token } from '@0xproject/contract-artifacts';
import { generatePseudoRandomSalt } from '@0xproject/order-utils'; import { generatePseudoRandomSalt } from '@0xproject/order-utils';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
@ -25,12 +26,7 @@ export const tokenUtils = {
return DUMMY_ERC_721_ADRESSES; return DUMMY_ERC_721_ADRESSES;
}, },
async mintDummyERC721Async(address: string, tokenOwner: string): Promise<BigNumber> { async mintDummyERC721Async(address: string, tokenOwner: string): Promise<BigNumber> {
const erc721 = new wrappers.DummyERC721TokenContract( const erc721 = new DummyERC721TokenContract(DummyERC721Token.compilerOutput.abi, address, provider, txDefaults);
artifacts.DummyERC721Token.compilerOutput.abi,
address,
provider,
txDefaults,
);
const tokenId = generatePseudoRandomSalt(); const tokenId = generatePseudoRandomSalt();
const txHash = await erc721.mint.sendTransactionAsync(tokenOwner, tokenId); const txHash = await erc721.mint.sendTransactionAsync(tokenOwner, tokenId);
web3Wrapper.awaitTransactionSuccessAsync(txHash); web3Wrapper.awaitTransactionSuccessAsync(txHash);