diff options
Diffstat (limited to 'packages/contract-wrappers/src')
13 files changed, 104 insertions, 142 deletions
diff --git a/packages/contract-wrappers/src/artifacts.ts b/packages/contract-wrappers/src/artifacts.ts deleted file mode 100644 index 925f34162..000000000 --- a/packages/contract-wrappers/src/artifacts.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { ContractArtifact } from 'ethereum-types'; - -import * as DummyERC20Token from './artifacts/DummyERC20Token.json'; -import * as DummyERC721Token from './artifacts/DummyERC721Token.json'; -import * as ERC20Proxy from './artifacts/ERC20Proxy.json'; -import * as ERC20Token from './artifacts/ERC20Token.json'; -import * as ERC721Proxy from './artifacts/ERC721Proxy.json'; -import * as ERC721Token from './artifacts/ERC721Token.json'; -import * as Exchange from './artifacts/Exchange.json'; -import * as Forwarder from './artifacts/Forwarder.json'; -import * as OrderValidator from './artifacts/OrderValidator.json'; -import * as EtherToken from './artifacts/WETH9.json'; -import * as ZRXToken from './artifacts/ZRXToken.json'; - -export const artifacts = { - ZRXToken: (ZRXToken as any) as ContractArtifact, - DummyERC20Token: (DummyERC20Token as any) as ContractArtifact, - DummyERC721Token: (DummyERC721Token as any) as ContractArtifact, - ERC20Token: (ERC20Token as any) as ContractArtifact, - ERC721Token: (ERC721Token as any) as ContractArtifact, - Exchange: (Exchange as any) as ContractArtifact, - EtherToken: (EtherToken as any) as ContractArtifact, - ERC20Proxy: (ERC20Proxy as any) as ContractArtifact, - ERC721Proxy: (ERC721Proxy as any) as ContractArtifact, - Forwarder: (Forwarder as any) as ContractArtifact, - OrderValidator: (OrderValidator as any) as ContractArtifact, -}; diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts index 89402029b..b272fabda 100644 --- a/packages/contract-wrappers/src/contract_wrappers.ts +++ b/packages/contract-wrappers/src/contract_wrappers.ts @@ -1,10 +1,8 @@ +import { artifacts } from '@0xproject/contracts'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Provider } from 'ethereum-types'; import * as _ from 'lodash'; -import { constants } from './utils/constants'; - -import { artifacts } from './artifacts'; import { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper'; import { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper'; import { ERC721ProxyWrapper } from './contract_wrappers/erc721_proxy_wrapper'; @@ -18,6 +16,7 @@ import { contractWrappersPrivateNetworkConfigSchema } from './schemas/contract_w import { contractWrappersPublicNetworkConfigSchema } from './schemas/contract_wrappers_public_network_config_schema'; import { ContractWrappersConfig } from './types'; import { assert } from './utils/assert'; +import { constants } from './utils/constants'; /** * The ContractWrappers class contains smart contract wrappers helpful when building on 0x protocol. */ diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts index ff027d78a..5900f0502 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_proxy_wrapper.ts @@ -1,20 +1,19 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; import { AssetProxyId } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { ContractAbi } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { assert } from '../utils/assert'; import { ContractWrapper } from './contract_wrapper'; -import { ERC20ProxyContract } from './generated/erc20_proxy'; /** * This class includes the functionality related to interacting with the ERC20Proxy contract. */ export class ERC20ProxyWrapper extends ContractWrapper { public abi: ContractAbi = artifacts.ERC20Proxy.compilerOutput.abi; - private _erc20ProxyContractIfExists?: ERC20ProxyContract; + private _erc20ProxyContractIfExists?: wrappers.ERC20ProxyContract; private _contractAddressIfExists?: string; /** * Instantiate ERC20ProxyWrapper @@ -72,7 +71,7 @@ export class ERC20ProxyWrapper extends ContractWrapper { private _invalidateContractInstance(): void { delete this._erc20ProxyContractIfExists; } - private async _getERC20ProxyContractAsync(): Promise<ERC20ProxyContract> { + private async _getERC20ProxyContractAsync(): Promise<wrappers.ERC20ProxyContract> { if (!_.isUndefined(this._erc20ProxyContractIfExists)) { return this._erc20ProxyContractIfExists; } @@ -80,7 +79,7 @@ export class ERC20ProxyWrapper extends ContractWrapper { artifacts.ERC20Proxy, this._contractAddressIfExists, ); - const contractInstance = new ERC20ProxyContract( + const contractInstance = new wrappers.ERC20ProxyContract( abi, address, this._web3Wrapper.getProvider(), diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts index 4625cef6a..3be5bcaee 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -1,10 +1,10 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; import { schemas } from '@0xproject/json-schemas'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { ContractAbi, LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { methodOptsSchema } from '../schemas/method_opts_schema'; import { txOptsSchema } from '../schemas/tx_opts_schema'; import { @@ -20,7 +20,6 @@ import { constants } from '../utils/constants'; import { ContractWrapper } from './contract_wrapper'; import { ERC20ProxyWrapper } from './erc20_proxy_wrapper'; -import { ERC20TokenContract, ERC20TokenEventArgs, ERC20TokenEvents } from './generated/erc20_token'; const removeUndefinedProperties = _.pickBy; @@ -32,7 +31,7 @@ const removeUndefinedProperties = _.pickBy; export class ERC20TokenWrapper extends ContractWrapper { public abi: ContractAbi = artifacts.ERC20Token.compilerOutput.abi; public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; - private _tokenContractsByAddress: { [address: string]: ERC20TokenContract }; + private _tokenContractsByAddress: { [address: string]: wrappers.ERC20TokenContract }; private _erc20ProxyWrapper: ERC20ProxyWrapper; /** * Instantiate ERC20TokenWrapper @@ -357,15 +356,15 @@ export class ERC20TokenWrapper extends ContractWrapper { * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @return Subscription token used later to unsubscribe */ - public subscribe<ArgsType extends ERC20TokenEventArgs>( + public subscribe<ArgsType extends wrappers.ERC20TokenEventArgs>( tokenAddress: string, - eventName: ERC20TokenEvents, + eventName: wrappers.ERC20TokenEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback<ArgsType>, isVerbose: boolean = false, ): string { assert.isETHAddressHex('tokenAddress', tokenAddress); - assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents); + assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC20TokenEvents); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.isFunction('callback', callback); const normalizedTokenAddress = tokenAddress.toLowerCase(); @@ -402,14 +401,14 @@ export class ERC20TokenWrapper extends ContractWrapper { * the value is the value you are interested in. E.g `{_from: aUserAddressHex}` * @return Array of logs that match the parameters */ - public async getLogsAsync<ArgsType extends ERC20TokenEventArgs>( + public async getLogsAsync<ArgsType extends wrappers.ERC20TokenEventArgs>( tokenAddress: string, - eventName: ERC20TokenEvents, + eventName: wrappers.ERC20TokenEvents, blockRange: BlockRange, indexFilterValues: IndexedFilterValues, ): Promise<Array<LogWithDecodedArgs<ArgsType>>> { assert.isETHAddressHex('tokenAddress', tokenAddress); - assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents); + assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC20TokenEvents); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); const normalizedTokenAddress = tokenAddress.toLowerCase(); @@ -429,7 +428,7 @@ export class ERC20TokenWrapper extends ContractWrapper { this.unsubscribeAll(); this._tokenContractsByAddress = {}; } - private async _getTokenContractAsync(tokenAddress: string): Promise<ERC20TokenContract> { + private async _getTokenContractAsync(tokenAddress: string): Promise<wrappers.ERC20TokenContract> { const normalizedTokenAddress = tokenAddress.toLowerCase(); let tokenContract = this._tokenContractsByAddress[normalizedTokenAddress]; if (!_.isUndefined(tokenContract)) { @@ -439,7 +438,7 @@ export class ERC20TokenWrapper extends ContractWrapper { artifacts.ERC20Token, normalizedTokenAddress, ); - const contractInstance = new ERC20TokenContract( + const contractInstance = new wrappers.ERC20TokenContract( abi, address, this._web3Wrapper.getProvider(), diff --git a/packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts index 933c1dc27..6ba162213 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc721_proxy_wrapper.ts @@ -1,20 +1,19 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; import { AssetProxyId } from '@0xproject/types'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { ContractAbi } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { assert } from '../utils/assert'; import { ContractWrapper } from './contract_wrapper'; -import { ERC721ProxyContract } from './generated/erc721_proxy'; /** * This class includes the functionality related to interacting with the ERC721Proxy contract. */ export class ERC721ProxyWrapper extends ContractWrapper { public abi: ContractAbi = artifacts.ERC20Proxy.compilerOutput.abi; - private _erc721ProxyContractIfExists?: ERC721ProxyContract; + private _erc721ProxyContractIfExists?: wrappers.ERC721ProxyContract; private _contractAddressIfExists?: string; /** * Instantiate ERC721ProxyWrapper @@ -72,7 +71,7 @@ export class ERC721ProxyWrapper extends ContractWrapper { private _invalidateContractInstance(): void { delete this._erc721ProxyContractIfExists; } - private async _getERC721ProxyContractAsync(): Promise<ERC721ProxyContract> { + private async _getERC721ProxyContractAsync(): Promise<wrappers.ERC721ProxyContract> { if (!_.isUndefined(this._erc721ProxyContractIfExists)) { return this._erc721ProxyContractIfExists; } @@ -80,7 +79,7 @@ export class ERC721ProxyWrapper extends ContractWrapper { artifacts.ERC721Proxy, this._contractAddressIfExists, ); - const contractInstance = new ERC721ProxyContract( + const contractInstance = new wrappers.ERC721ProxyContract( abi, address, this._web3Wrapper.getProvider(), diff --git a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts index 590dbbf74..23b335710 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc721_token_wrapper.ts @@ -1,10 +1,10 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; import { schemas } from '@0xproject/json-schemas'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { ContractAbi, LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { methodOptsSchema } from '../schemas/method_opts_schema'; import { txOptsSchema } from '../schemas/tx_opts_schema'; import { @@ -20,7 +20,6 @@ import { constants } from '../utils/constants'; import { ContractWrapper } from './contract_wrapper'; import { ERC721ProxyWrapper } from './erc721_proxy_wrapper'; -import { ERC721TokenContract, ERC721TokenEventArgs, ERC721TokenEvents } from './generated/erc721_token'; const removeUndefinedProperties = _.pickBy; @@ -31,7 +30,7 @@ const removeUndefinedProperties = _.pickBy; */ export class ERC721TokenWrapper extends ContractWrapper { public abi: ContractAbi = artifacts.ERC721Token.compilerOutput.abi; - private _tokenContractsByAddress: { [address: string]: ERC721TokenContract }; + private _tokenContractsByAddress: { [address: string]: wrappers.ERC721TokenContract }; private _erc721ProxyWrapper: ERC721ProxyWrapper; /** * Instantiate ERC721TokenWrapper @@ -384,15 +383,15 @@ export class ERC721TokenWrapper extends ContractWrapper { * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @return Subscription token used later to unsubscribe */ - public subscribe<ArgsType extends ERC721TokenEventArgs>( + public subscribe<ArgsType extends wrappers.ERC721TokenEventArgs>( tokenAddress: string, - eventName: ERC721TokenEvents, + eventName: wrappers.ERC721TokenEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback<ArgsType>, isVerbose: boolean = false, ): string { assert.isETHAddressHex('tokenAddress', tokenAddress); - assert.doesBelongToStringEnum('eventName', eventName, ERC721TokenEvents); + assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC721TokenEvents); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.isFunction('callback', callback); const normalizedTokenAddress = tokenAddress.toLowerCase(); @@ -429,14 +428,14 @@ export class ERC721TokenWrapper extends ContractWrapper { * the value is the value you are interested in. E.g `{_from: aUserAddressHex}` * @return Array of logs that match the parameters */ - public async getLogsAsync<ArgsType extends ERC721TokenEventArgs>( + public async getLogsAsync<ArgsType extends wrappers.ERC721TokenEventArgs>( tokenAddress: string, - eventName: ERC721TokenEvents, + eventName: wrappers.ERC721TokenEvents, blockRange: BlockRange, indexFilterValues: IndexedFilterValues, ): Promise<Array<LogWithDecodedArgs<ArgsType>>> { assert.isETHAddressHex('tokenAddress', tokenAddress); - assert.doesBelongToStringEnum('eventName', eventName, ERC721TokenEvents); + assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC721TokenEvents); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); const normalizedTokenAddress = tokenAddress.toLowerCase(); @@ -456,7 +455,7 @@ export class ERC721TokenWrapper extends ContractWrapper { this.unsubscribeAll(); this._tokenContractsByAddress = {}; } - private async _getTokenContractAsync(tokenAddress: string): Promise<ERC721TokenContract> { + private async _getTokenContractAsync(tokenAddress: string): Promise<wrappers.ERC721TokenContract> { const normalizedTokenAddress = tokenAddress.toLowerCase(); let tokenContract = this._tokenContractsByAddress[normalizedTokenAddress]; if (!_.isUndefined(tokenContract)) { @@ -466,7 +465,7 @@ export class ERC721TokenWrapper extends ContractWrapper { artifacts.ERC721Token, normalizedTokenAddress, ); - const contractInstance = new ERC721TokenContract( + const contractInstance = new wrappers.ERC721TokenContract( abi, address, this._web3Wrapper.getProvider(), diff --git a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts index 1ac01812e..30653adf2 100644 --- a/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/ether_token_wrapper.ts @@ -1,16 +1,15 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; import { schemas } from '@0xproject/json-schemas'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { ContractAbi, LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { BlockRange, ContractWrappersError, EventCallback, IndexedFilterValues, TransactionOpts } from '../types'; import { assert } from '../utils/assert'; import { ContractWrapper } from './contract_wrapper'; import { ERC20TokenWrapper } from './erc20_token_wrapper'; -import { WETH9Contract, WETH9EventArgs, WETH9Events } from './generated/weth9'; const removeUndefinedProperties = _.pickBy; @@ -19,9 +18,9 @@ const removeUndefinedProperties = _.pickBy; * The caller can convert ETH into the equivalent number of wrapped ETH ERC20 tokens and back. */ export class EtherTokenWrapper extends ContractWrapper { - public abi: ContractAbi = artifacts.EtherToken.compilerOutput.abi; + public abi: ContractAbi = artifacts.WETH9.compilerOutput.abi; private _etherTokenContractsByAddress: { - [address: string]: WETH9Contract; + [address: string]: wrappers.WETH9Contract; } = {}; private _erc20TokenWrapper: ERC20TokenWrapper; /** @@ -126,15 +125,15 @@ export class EtherTokenWrapper extends ContractWrapper { * the value is the value you are interested in. E.g `{_owner: aUserAddressHex}` * @return Array of logs that match the parameters */ - public async getLogsAsync<ArgsType extends WETH9EventArgs>( + public async getLogsAsync<ArgsType extends wrappers.WETH9EventArgs>( etherTokenAddress: string, - eventName: WETH9Events, + eventName: wrappers.WETH9Events, blockRange: BlockRange, indexFilterValues: IndexedFilterValues, ): Promise<Array<LogWithDecodedArgs<ArgsType>>> { assert.isETHAddressHex('etherTokenAddress', etherTokenAddress); const normalizedEtherTokenAddress = etherTokenAddress.toLowerCase(); - assert.doesBelongToStringEnum('eventName', eventName, WETH9Events); + assert.doesBelongToStringEnum('eventName', eventName, wrappers.WETH9Events); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); const logs = await this._getLogsAsync<ArgsType>( @@ -142,7 +141,7 @@ export class EtherTokenWrapper extends ContractWrapper { eventName, blockRange, indexFilterValues, - artifacts.EtherToken.compilerOutput.abi, + artifacts.WETH9.compilerOutput.abi, ); return logs; } @@ -156,23 +155,23 @@ export class EtherTokenWrapper extends ContractWrapper { * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @return Subscription token used later to unsubscribe */ - public subscribe<ArgsType extends WETH9EventArgs>( + public subscribe<ArgsType extends wrappers.WETH9EventArgs>( etherTokenAddress: string, - eventName: WETH9Events, + eventName: wrappers.WETH9Events, indexFilterValues: IndexedFilterValues, callback: EventCallback<ArgsType>, isVerbose: boolean = false, ): string { assert.isETHAddressHex('etherTokenAddress', etherTokenAddress); const normalizedEtherTokenAddress = etherTokenAddress.toLowerCase(); - assert.doesBelongToStringEnum('eventName', eventName, WETH9Events); + assert.doesBelongToStringEnum('eventName', eventName, wrappers.WETH9Events); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.isFunction('callback', callback); const subscriptionToken = this._subscribe<ArgsType>( normalizedEtherTokenAddress, eventName, indexFilterValues, - artifacts.EtherToken.compilerOutput.abi, + artifacts.WETH9.compilerOutput.abi, callback, isVerbose, ); @@ -199,7 +198,7 @@ export class EtherTokenWrapper extends ContractWrapper { * @returns The Ethereum address of the EtherToken contract or undefined. */ public getContractAddressIfExists(): string | undefined { - const networkSpecificArtifact = artifacts.EtherToken.networks[this._networkId]; + const networkSpecificArtifact = artifacts.WETH9.networks[this._networkId]; const contractAddressIfExists = _.isUndefined(networkSpecificArtifact) ? undefined : networkSpecificArtifact.address; @@ -210,16 +209,16 @@ export class EtherTokenWrapper extends ContractWrapper { this.unsubscribeAll(); this._etherTokenContractsByAddress = {}; } - private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise<WETH9Contract> { + private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise<wrappers.WETH9Contract> { let etherTokenContract = this._etherTokenContractsByAddress[etherTokenAddress]; if (!_.isUndefined(etherTokenContract)) { return etherTokenContract; } const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync( - artifacts.EtherToken, + artifacts.WETH9, etherTokenAddress, ); - const contractInstance = new WETH9Contract( + const contractInstance = new wrappers.WETH9Contract( abi, address, this._web3Wrapper.getProvider(), diff --git a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts index dc9ffcbf7..613747720 100644 --- a/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/exchange_wrapper.ts @@ -1,3 +1,4 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; import { schemas } from '@0xproject/json-schemas'; import { assetDataUtils, @@ -11,7 +12,6 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { BlockParamLiteral, ContractAbi, LogWithDecodedArgs } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { AssetBalanceAndProxyAllowanceFetcher } from '../fetchers/asset_balance_and_proxy_allowance_fetcher'; import { OrderFilledCancelledFetcher } from '../fetchers/order_filled_cancelled_fetcher'; import { methodOptsSchema } from '../schemas/method_opts_schema'; @@ -35,7 +35,6 @@ import { TransactionEncoder } from '../utils/transaction_encoder'; import { ContractWrapper } from './contract_wrapper'; import { ERC20TokenWrapper } from './erc20_token_wrapper'; import { ERC721TokenWrapper } from './erc721_token_wrapper'; -import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated/exchange'; /** * This class includes all the functionality related to calling methods, sending transactions and subscribing to @@ -43,7 +42,7 @@ import { ExchangeContract, ExchangeEventArgs, ExchangeEvents } from './generated */ export class ExchangeWrapper extends ContractWrapper { public abi: ContractAbi = artifacts.Exchange.compilerOutput.abi; - private _exchangeContractIfExists?: ExchangeContract; + private _exchangeContractIfExists?: wrappers.ExchangeContract; private _erc721TokenWrapper: ERC721TokenWrapper; private _erc20TokenWrapper: ERC20TokenWrapper; private _contractAddressIfExists?: string; @@ -1042,13 +1041,13 @@ export class ExchangeWrapper extends ContractWrapper { * @param isVerbose Enable verbose subscription warnings (e.g recoverable network issues encountered) * @return Subscription token used later to unsubscribe */ - public subscribe<ArgsType extends ExchangeEventArgs>( - eventName: ExchangeEvents, + public subscribe<ArgsType extends wrappers.ExchangeEventArgs>( + eventName: wrappers.ExchangeEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback<ArgsType>, isVerbose: boolean = false, ): string { - assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); + assert.doesBelongToStringEnum('eventName', eventName, wrappers.ExchangeEvents); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.isFunction('callback', callback); const exchangeContractAddress = this.getContractAddress(); @@ -1083,12 +1082,12 @@ export class ExchangeWrapper extends ContractWrapper { * the value is the value you are interested in. E.g `{_from: aUserAddressHex}` * @return Array of logs that match the parameters */ - public async getLogsAsync<ArgsType extends ExchangeEventArgs>( - eventName: ExchangeEvents, + public async getLogsAsync<ArgsType extends wrappers.ExchangeEventArgs>( + eventName: wrappers.ExchangeEvents, blockRange: BlockRange, indexFilterValues: IndexedFilterValues, ): Promise<Array<LogWithDecodedArgs<ArgsType>>> { - assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); + assert.doesBelongToStringEnum('eventName', eventName, wrappers.ExchangeEvents); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); const exchangeContractAddress = this.getContractAddress(); @@ -1201,7 +1200,7 @@ export class ExchangeWrapper extends ContractWrapper { delete this._exchangeContractIfExists; } // tslint:enable:no-unused-variable - private async _getExchangeContractAsync(): Promise<ExchangeContract> { + private async _getExchangeContractAsync(): Promise<wrappers.ExchangeContract> { if (!_.isUndefined(this._exchangeContractIfExists)) { return this._exchangeContractIfExists; } @@ -1209,7 +1208,7 @@ export class ExchangeWrapper extends ContractWrapper { artifacts.Exchange, this._contractAddressIfExists, ); - const contractInstance = new ExchangeContract( + const contractInstance = new wrappers.ExchangeContract( abi, address, this._web3Wrapper.getProvider(), diff --git a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts index c19edf188..854a8381b 100644 --- a/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/forwarder_wrapper.ts @@ -1,3 +1,4 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; import { schemas } from '@0xproject/json-schemas'; import { AssetProxyId, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; @@ -5,7 +6,6 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { ContractAbi } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema'; import { txOptsSchema } from '../schemas/tx_opts_schema'; import { OrderTransactionOpts } from '../types'; @@ -16,14 +16,13 @@ import { decorators } from '../utils/decorators'; import { utils } from '../utils/utils'; import { ContractWrapper } from './contract_wrapper'; -import { ForwarderContract } from './generated/forwarder'; /** * This class includes the functionality related to interacting with the Forwarder contract. */ export class ForwarderWrapper extends ContractWrapper { public abi: ContractAbi = artifacts.Forwarder.compilerOutput.abi; - private _forwarderContractIfExists?: ForwarderContract; + private _forwarderContractIfExists?: wrappers.ForwarderContract; private _contractAddressIfExists?: string; private _zrxContractAddressIfExists?: string; constructor( @@ -242,7 +241,7 @@ export class ForwarderWrapper extends ContractWrapper { * @return Address of Ether token */ public getEtherTokenAddress(): string { - const contractAddress = this._getContractAddress(artifacts.EtherToken); + const contractAddress = this._getContractAddress(artifacts.WETH9); return contractAddress; } // HACK: We don't want this method to be visible to the other units within that package but not to the end user. @@ -251,7 +250,7 @@ export class ForwarderWrapper extends ContractWrapper { private _invalidateContractInstance(): void { delete this._forwarderContractIfExists; } - private async _getForwarderContractAsync(): Promise<ForwarderContract> { + private async _getForwarderContractAsync(): Promise<wrappers.ForwarderContract> { if (!_.isUndefined(this._forwarderContractIfExists)) { return this._forwarderContractIfExists; } @@ -259,7 +258,7 @@ export class ForwarderWrapper extends ContractWrapper { artifacts.Forwarder, this._contractAddressIfExists, ); - const contractInstance = new ForwarderContract( + const contractInstance = new wrappers.ForwarderContract( abi, address, this._web3Wrapper.getProvider(), diff --git a/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts index 1da88f624..02f9dd4de 100644 --- a/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/order_validator_wrapper.ts @@ -1,3 +1,4 @@ +import { artifacts, wrappers } from '@0xproject/contracts'; import { schemas } from '@0xproject/json-schemas'; import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; @@ -5,19 +6,17 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { ContractAbi } from 'ethereum-types'; import * as _ from 'lodash'; -import { artifacts } from '../artifacts'; import { BalanceAndAllowance, OrderAndTraderInfo, TraderInfo } from '../types'; import { assert } from '../utils/assert'; import { ContractWrapper } from './contract_wrapper'; -import { OrderValidatorContract } from './generated/order_validator'; /** * This class includes the functionality related to interacting with the OrderValidator contract. */ export class OrderValidatorWrapper extends ContractWrapper { public abi: ContractAbi = artifacts.OrderValidator.compilerOutput.abi; - private _orderValidatorContractIfExists?: OrderValidatorContract; + private _orderValidatorContractIfExists?: wrappers.OrderValidatorContract; /** * Instantiate OrderValidatorWrapper * @param web3Wrapper Web3Wrapper instance to use @@ -170,12 +169,12 @@ export class OrderValidatorWrapper extends ContractWrapper { private _invalidateContractInstance(): void { delete this._orderValidatorContractIfExists; } - private async _getOrderValidatorContractAsync(): Promise<OrderValidatorContract> { + private async _getOrderValidatorContractAsync(): Promise<wrappers.OrderValidatorContract> { if (!_.isUndefined(this._orderValidatorContractIfExists)) { return this._orderValidatorContractIfExists; } const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync(artifacts.OrderValidator); - const contractInstance = new OrderValidatorContract( + const contractInstance = new wrappers.OrderValidatorContract( abi, address, this._web3Wrapper.getProvider(), diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index e8a53170e..659394eb6 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -1,3 +1,5 @@ +import { wrappers } from '@0xproject/contracts'; + export { ContractWrappers } from './contract_wrappers'; export { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper'; export { ERC721TokenWrapper } from './contract_wrappers/erc721_token_wrapper'; @@ -54,39 +56,31 @@ export { StateMutability, } from 'ethereum-types'; -export { - WETH9Events, - WETH9WithdrawalEventArgs, - WETH9ApprovalEventArgs, - WETH9EventArgs, - WETH9DepositEventArgs, - WETH9TransferEventArgs, -} from './contract_wrappers/generated/weth9'; +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 { - ERC20TokenTransferEventArgs, - ERC20TokenApprovalEventArgs, - ERC20TokenEvents, - ERC20TokenEventArgs, -} from './contract_wrappers/generated/erc20_token'; +export type ERC20TokenTransferEventArgs = wrappers.ERC20TokenTransferEventArgs; +export type ERC20TokenApprovalEventArgs = wrappers.ERC20TokenApprovalEventArgs; +export const ERC20TokenEvents = wrappers.ERC20TokenEvents; +export type ERC20TokenEventArgs = wrappers.ERC20TokenEventArgs; -export { - ERC721TokenApprovalEventArgs, - ERC721TokenApprovalForAllEventArgs, - ERC721TokenTransferEventArgs, - ERC721TokenEvents, - ERC721TokenEventArgs, -} from './contract_wrappers/generated/erc721_token'; +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 { - ExchangeCancelUpToEventArgs, - ExchangeAssetProxyRegisteredEventArgs, - ExchangeSignatureValidatorApprovalEventArgs, - ExchangeFillEventArgs, - ExchangeCancelEventArgs, - ExchangeEventArgs, - ExchangeEvents, -} from './contract_wrappers/generated/exchange'; +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'; diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index e0b12b7c9..0ac5f05e4 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -1,13 +1,9 @@ +import { wrappers } from '@0xproject/contracts'; import { BigNumber } from '@0xproject/utils'; import { OrderState, SignedOrder } from '@0xproject/types'; import { BlockParam, ContractEventArg, DecodedLogArgs, LogEntryEvent, LogWithDecodedArgs } from 'ethereum-types'; -import { ERC20TokenEventArgs, ERC20TokenEvents } from './contract_wrappers/generated/erc20_token'; -import { ERC721TokenEventArgs, ERC721TokenEvents } from './contract_wrappers/generated/erc721_token'; -import { ExchangeEventArgs, ExchangeEvents } from './contract_wrappers/generated/exchange'; -import { WETH9EventArgs, WETH9Events } from './contract_wrappers/generated/weth9'; - export enum ExchangeWrapperError { AssetDataMismatch = 'ASSET_DATA_MISMATCH', } @@ -60,7 +56,11 @@ export interface ContractEvent { args: ContractEventArgs; } -export type ContractEventArgs = ExchangeEventArgs | ERC20TokenEventArgs | ERC721TokenEventArgs | WETH9EventArgs; +export type ContractEventArgs = + | wrappers.ExchangeEventArgs + | wrappers.ERC20TokenEventArgs + | wrappers.ERC721TokenEventArgs + | wrappers.WETH9EventArgs; // [address, name, symbol, decimals, ipfsHash, swarmHash] export type TokenMetadata = [string, string, string, number, string, string]; @@ -83,7 +83,11 @@ export interface TokenAddressBySymbol { [symbol: string]: string; } -export type ContractEvents = ERC20TokenEvents | ERC721TokenEvents | ExchangeEvents | WETH9Events; +export type ContractEvents = + | wrappers.ERC20TokenEvents + | wrappers.ERC721TokenEvents + | wrappers.ExchangeEvents + | wrappers.WETH9Events; export interface IndexedFilterValues { [index: string]: ContractEventArg; diff --git a/packages/contract-wrappers/src/utils/transaction_encoder.ts b/packages/contract-wrappers/src/utils/transaction_encoder.ts index 33086944b..f4c6de97f 100644 --- a/packages/contract-wrappers/src/utils/transaction_encoder.ts +++ b/packages/contract-wrappers/src/utils/transaction_encoder.ts @@ -1,11 +1,11 @@ +import { wrappers } from '@0xproject/contracts'; + import { schemas } from '@0xproject/json-schemas'; import { eip712Utils } from '@0xproject/order-utils'; import { Order, SignedOrder } from '@0xproject/types'; import { BigNumber, signTypedDataUtils } from '@0xproject/utils'; import _ = require('lodash'); -import { ExchangeContract } from '../contract_wrappers/generated/exchange'; - import { assert } from './assert'; /** @@ -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. */ export class TransactionEncoder { - private readonly _exchangeInstance: ExchangeContract; - constructor(exchangeInstance: ExchangeContract) { + private readonly _exchangeInstance: wrappers.ExchangeContract; + constructor(exchangeInstance: wrappers.ExchangeContract) { this._exchangeInstance = exchangeInstance; } /** @@ -275,7 +275,7 @@ export class TransactionEncoder { ); return abiEncodedData; } - private _getExchangeContract(): ExchangeContract { + private _getExchangeContract(): wrappers.ExchangeContract { return this._exchangeInstance; } } |