From 026ad1f9a10359723eed54f37c067ee2a61d8fcd Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 1 Oct 2018 18:22:42 -0700 Subject: Update contract-wrappers package to use new contracts package for generated files --- .../src/contract_wrappers/erc20_token_wrapper.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts') 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( + public subscribe( tokenAddress: string, - eventName: ERC20TokenEvents, + eventName: wrappers.ERC20TokenEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback, 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( + public async getLogsAsync( tokenAddress: string, - eventName: ERC20TokenEvents, + eventName: wrappers.ERC20TokenEvents, blockRange: BlockRange, indexFilterValues: IndexedFilterValues, ): Promise>> { 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 { + private async _getTokenContractAsync(tokenAddress: string): Promise { 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(), -- cgit v1.2.3 From 3a7bb97ad1182eb9c718797bda8dca5eb5d7f9cd Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 3 Oct 2018 16:21:17 -0700 Subject: Remove artifacts from migrations package and update contract-wrappers accordingly --- .../src/contract_wrappers/erc20_token_wrapper.ts | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts') 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 3be5bcaee..53cda5d08 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -36,17 +36,11 @@ export class ERC20TokenWrapper extends ContractWrapper { /** * Instantiate ERC20TokenWrapper * @param web3Wrapper Web3Wrapper instance to use - * @param networkId Desired networkId * @param erc20ProxyWrapper The ERC20ProxyWrapper instance to use * @param blockPollingIntervalMs The block polling interval to use for active subscriptions */ - constructor( - web3Wrapper: Web3Wrapper, - networkId: number, - erc20ProxyWrapper: ERC20ProxyWrapper, - blockPollingIntervalMs?: number, - ) { - super(web3Wrapper, networkId, blockPollingIntervalMs); + constructor(web3Wrapper: Web3Wrapper, erc20ProxyWrapper: ERC20ProxyWrapper, blockPollingIntervalMs?: number) { + super(web3Wrapper, blockPollingIntervalMs); this._tokenContractsByAddress = {}; this._erc20ProxyWrapper = erc20ProxyWrapper; } @@ -188,7 +182,7 @@ export class ERC20TokenWrapper extends ContractWrapper { ownerAddress: string, methodOpts: MethodOpts = {}, ): Promise { - const proxyAddress = this._erc20ProxyWrapper.getContractAddress(); + const proxyAddress = this._erc20ProxyWrapper.address; const allowanceInBaseUnits = await this.getAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, methodOpts); return allowanceInBaseUnits; } @@ -208,7 +202,7 @@ export class ERC20TokenWrapper extends ContractWrapper { amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}, ): Promise { - const proxyAddress = this._erc20ProxyWrapper.getContractAddress(); + const proxyAddress = this._erc20ProxyWrapper.address; const txHash = await this.setAllowanceAsync( tokenAddress, ownerAddress, @@ -434,13 +428,15 @@ export class ERC20TokenWrapper extends ContractWrapper { if (!_.isUndefined(tokenContract)) { return tokenContract; } - const [abi, address] = await this._getContractAbiAndAddressFromArtifactsAsync( - artifacts.ERC20Token, - normalizedTokenAddress, - ); + // TODO(albrow): Do we really still need this check? The default error + // looks okay to me. + const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(tokenAddress); + if (!doesContractExist) { + throw new Error(ContractWrappersError.ERC20TokenContractDoesNotExist); + } const contractInstance = new wrappers.ERC20TokenContract( - abi, - address, + this.abi, + normalizedTokenAddress, this._web3Wrapper.getProvider(), this._web3Wrapper.getContractDefaults(), ); -- cgit v1.2.3 From 2bd7b0f66bd28792281ba025cf005c666e7f767e Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Thu, 4 Oct 2018 14:40:58 -0700 Subject: update contract_wrappers to use new artifacts and abi-gen wrappers packages --- .../src/contract_wrappers/erc20_token_wrapper.ts | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts') 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 53cda5d08..68928e71f 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -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 { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -29,9 +30,9 @@ const removeUndefinedProperties = _.pickBy; * to the 0x ERC20 Proxy smart contract. */ 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; - private _tokenContractsByAddress: { [address: string]: wrappers.ERC20TokenContract }; + private _tokenContractsByAddress: { [address: string]: ERC20TokenContract }; private _erc20ProxyWrapper: ERC20ProxyWrapper; /** * Instantiate ERC20TokenWrapper @@ -350,15 +351,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( + public subscribe( tokenAddress: string, - eventName: wrappers.ERC20TokenEvents, + eventName: ERC20TokenEvents, indexFilterValues: IndexedFilterValues, callback: EventCallback, isVerbose: boolean = false, ): string { assert.isETHAddressHex('tokenAddress', tokenAddress); - assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC20TokenEvents); + assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.isFunction('callback', callback); const normalizedTokenAddress = tokenAddress.toLowerCase(); @@ -366,7 +367,7 @@ export class ERC20TokenWrapper extends ContractWrapper { normalizedTokenAddress, eventName, indexFilterValues, - artifacts.ERC20Token.compilerOutput.abi, + ERC20Token.compilerOutput.abi, callback, isVerbose, ); @@ -395,14 +396,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( + public async getLogsAsync( tokenAddress: string, - eventName: wrappers.ERC20TokenEvents, + eventName: ERC20TokenEvents, blockRange: BlockRange, indexFilterValues: IndexedFilterValues, ): Promise>> { assert.isETHAddressHex('tokenAddress', tokenAddress); - assert.doesBelongToStringEnum('eventName', eventName, wrappers.ERC20TokenEvents); + assert.doesBelongToStringEnum('eventName', eventName, ERC20TokenEvents); assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); const normalizedTokenAddress = tokenAddress.toLowerCase(); @@ -411,7 +412,7 @@ export class ERC20TokenWrapper extends ContractWrapper { eventName, blockRange, indexFilterValues, - artifacts.ERC20Token.compilerOutput.abi, + ERC20Token.compilerOutput.abi, ); return logs; } @@ -422,7 +423,7 @@ export class ERC20TokenWrapper extends ContractWrapper { this.unsubscribeAll(); this._tokenContractsByAddress = {}; } - private async _getTokenContractAsync(tokenAddress: string): Promise { + private async _getTokenContractAsync(tokenAddress: string): Promise { const normalizedTokenAddress = tokenAddress.toLowerCase(); let tokenContract = this._tokenContractsByAddress[normalizedTokenAddress]; if (!_.isUndefined(tokenContract)) { @@ -434,7 +435,7 @@ export class ERC20TokenWrapper extends ContractWrapper { if (!doesContractExist) { throw new Error(ContractWrappersError.ERC20TokenContractDoesNotExist); } - const contractInstance = new wrappers.ERC20TokenContract( + const contractInstance = new ERC20TokenContract( this.abi, normalizedTokenAddress, this._web3Wrapper.getProvider(), -- cgit v1.2.3 From 1e9ea09f087c7b3120e758d931a88812b655da08 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 9 Oct 2018 23:10:33 -0700 Subject: Introduce new contract-addresses package and use it everywhere --- .../src/contract_wrappers/erc20_token_wrapper.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts') 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 68928e71f..2db0165bc 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -37,11 +37,17 @@ export class ERC20TokenWrapper extends ContractWrapper { /** * Instantiate ERC20TokenWrapper * @param web3Wrapper Web3Wrapper instance to use + * @param networkId Desired networkId * @param erc20ProxyWrapper The ERC20ProxyWrapper instance to use * @param blockPollingIntervalMs The block polling interval to use for active subscriptions */ - constructor(web3Wrapper: Web3Wrapper, erc20ProxyWrapper: ERC20ProxyWrapper, blockPollingIntervalMs?: number) { - super(web3Wrapper, blockPollingIntervalMs); + constructor( + web3Wrapper: Web3Wrapper, + networkId: number, + erc20ProxyWrapper: ERC20ProxyWrapper, + blockPollingIntervalMs?: number, + ) { + super(web3Wrapper, networkId, blockPollingIntervalMs); this._tokenContractsByAddress = {}; this._erc20ProxyWrapper = erc20ProxyWrapper; } -- cgit v1.2.3 From 6f8e98e53727a1efc08800017cf2bde38884c982 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 15 Oct 2018 17:35:25 -0700 Subject: In contract-wrappers, remove setProvider and add unsubscribeAll method. --- .../contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts | 7 ------- 1 file changed, 7 deletions(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts') 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 2db0165bc..97043bd19 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -422,13 +422,6 @@ export class ERC20TokenWrapper extends ContractWrapper { ); return logs; } - // HACK: We don't want this method to be visible to the other units within that package but not to the end user. - // TS doesn't give that possibility and therefore we make it private and access it over an any cast. Because of that tslint sees it as unused. - // tslint:disable-next-line:no-unused-variable - private _invalidateContractInstances(): void { - this.unsubscribeAll(); - this._tokenContractsByAddress = {}; - } private async _getTokenContractAsync(tokenAddress: string): Promise { const normalizedTokenAddress = tokenAddress.toLowerCase(); let tokenContract = this._tokenContractsByAddress[normalizedTokenAddress]; -- cgit v1.2.3 From 5bdfad9b415fc183102d5f5a7f3a08782921f003 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 16 Oct 2018 00:11:58 -0700 Subject: Remove ContractNotFound errors in contract-wrappers --- .../contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts | 6 ------ 1 file changed, 6 deletions(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts') 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 97043bd19..192eaf0a7 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -428,12 +428,6 @@ export class ERC20TokenWrapper extends ContractWrapper { if (!_.isUndefined(tokenContract)) { return tokenContract; } - // TODO(albrow): Do we really still need this check? The default error - // looks okay to me. - const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(tokenAddress); - if (!doesContractExist) { - throw new Error(ContractWrappersError.ERC20TokenContractDoesNotExist); - } const contractInstance = new ERC20TokenContract( this.abi, normalizedTokenAddress, -- cgit v1.2.3