diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-02 12:47:05 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-02 13:31:50 +0800 |
commit | eb667f653c4ee87132390844afaecf409c7575c8 (patch) | |
tree | d2d3c9b1a44bc9a93442617b0e2892cc901c5612 /packages/0x.js/src/contract_wrappers | |
parent | 6cbd0d4537be3e51866c407dc01fb0efca0b50c2 (diff) | |
download | dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.gz dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.bz2 dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.lz dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.xz dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.zst dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.zip |
Adjust 0x.js to use generated wrappers
Diffstat (limited to 'packages/0x.js/src/contract_wrappers')
6 files changed, 31 insertions, 15 deletions
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 8c92931b4..5e5a38f8c 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -90,11 +90,13 @@ export class ContractWrapper { const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log); return logWithDecodedArgs; } - protected async _instantiateContractIfExistsAsync<ContractType extends Web3.ContractInstance>( - artifact: Artifact, addressIfExists?: string): Promise<ContractType> { - const contractInstance = - await this._web3Wrapper.getContractInstanceFromArtifactAsync<ContractType>(artifact, addressIfExists); - return contractInstance; + protected async _instantiateContractIfExistsAsync( + artifact: Artifact, addressIfExists?: string, + ): Promise<Web3.ContractInstance> { + const web3ContractInstance = await this._web3Wrapper.getContractInstanceFromArtifactAsync( + artifact, addressIfExists, + ); + return web3ContractInstance; } protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string { if (_.isUndefined(addressIfExists)) { diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index ede0460bd..26025f6f9 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -2,11 +2,12 @@ import BigNumber from 'bignumber.js'; import * as _ from 'lodash'; import {artifacts} from '../artifacts'; -import {EtherTokenContract, TransactionOpts, ZeroExError} from '../types'; +import {TransactionOpts, ZeroExError} from '../types'; import {assert} from '../utils/assert'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {EtherTokenContract} from './generated/ether_token'; import {TokenWrapper} from './token_wrapper'; /** @@ -92,9 +93,10 @@ export class EtherTokenWrapper extends ContractWrapper { if (!_.isUndefined(this._etherTokenContractIfExists)) { return this._etherTokenContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync<EtherTokenContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.EtherTokenArtifact, this._contractAddressIfExists, ); + const contractInstance = new EtherTokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults()); this._etherTokenContractIfExists = contractInstance; return this._etherTokenContractIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 273b348ff..aaf6256a3 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -9,7 +9,6 @@ import { DecodedLogArgs, ECSignature, EventCallback, - ExchangeContract, ExchangeContractErrCodes, ExchangeContractErrs, ExchangeContractEventArgs, @@ -40,6 +39,7 @@ import {utils} from '../utils/utils'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {ExchangeContract} from './generated/exchange'; import {TokenWrapper} from './token_wrapper'; const SHOULD_VALIDATE_BY_DEFAULT = true; @@ -789,9 +789,10 @@ export class ExchangeWrapper extends ContractWrapper { if (!_.isUndefined(this._exchangeContractIfExists)) { return this._exchangeContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync<ExchangeContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.ExchangeArtifact, this._contractAddressIfExists, ); + const contractInstance = new ExchangeContract(web3ContractInstance, this._web3Wrapper.getContractDefaults()); this._exchangeContractIfExists = contractInstance; return this._exchangeContractIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts index 35337fa35..27ecb8bde 100644 --- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts @@ -1,12 +1,13 @@ import * as _ from 'lodash'; import {artifacts} from '../artifacts'; -import {Token, TokenMetadata, TokenRegistryContract, ZeroExError} from '../types'; +import {Token, TokenMetadata, ZeroExError} from '../types'; import {assert} from '../utils/assert'; import {constants} from '../utils/constants'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {TokenRegistryContract} from './generated/token_registry'; /** * This class includes all the functionality related to interacting with the 0x Token Registry smart contract. @@ -116,9 +117,12 @@ export class TokenRegistryWrapper extends ContractWrapper { if (!_.isUndefined(this._tokenRegistryContractIfExists)) { return this._tokenRegistryContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync<TokenRegistryContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.TokenRegistryArtifact, this._contractAddressIfExists, ); + const contractInstance = new TokenRegistryContract( + web3ContractInstance, this._web3Wrapper.getContractDefaults(), + ); this._tokenRegistryContractIfExists = contractInstance; return this._tokenRegistryContractIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts index c3df7d3eb..edc702672 100644 --- a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts @@ -1,10 +1,11 @@ import * as _ from 'lodash'; import {artifacts} from '../artifacts'; -import {TokenTransferProxyContract, ZeroExError} from '../types'; +import {ZeroExError} from '../types'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {TokenTransferProxyContract} from './generated/token_transfer_proxy'; /** * This class includes the functionality related to interacting with the TokenTransferProxy contract. @@ -53,9 +54,12 @@ export class TokenTransferProxyWrapper extends ContractWrapper { if (!_.isUndefined(this._tokenTransferProxyContractIfExists)) { return this._tokenTransferProxyContractIfExists; } - const contractInstance = await this._instantiateContractIfExistsAsync<TokenTransferProxyContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.TokenTransferProxyArtifact, this._contractAddressIfExists, ); + const contractInstance = new TokenTransferProxyContract( + web3ContractInstance, this._web3Wrapper.getContractDefaults(), + ); this._tokenTransferProxyContractIfExists = contractInstance; return this._tokenTransferProxyContractIfExists; } diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts index 4a1dfcf8d..630ab6e3b 100644 --- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts @@ -9,7 +9,6 @@ import { LogWithDecodedArgs, MethodOpts, SubscriptionOpts, - TokenContract, TokenContractEventArgs, TokenEvents, TransactionOpts, @@ -21,6 +20,7 @@ import {constants} from '../utils/constants'; import {Web3Wrapper} from '../web3_wrapper'; import {ContractWrapper} from './contract_wrapper'; +import {TokenContract} from './generated/token'; import {TokenTransferProxyWrapper} from './token_transfer_proxy_wrapper'; const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 47275; @@ -313,9 +313,12 @@ export class TokenWrapper extends ContractWrapper { if (!_.isUndefined(tokenContract)) { return tokenContract; } - const contractInstance = await this._instantiateContractIfExistsAsync<TokenContract>( + const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.TokenArtifact, tokenAddress, ); + const contractInstance = new TokenContract( + web3ContractInstance, this._web3Wrapper.getContractDefaults(), + ); tokenContract = contractInstance; this._tokenContractsByAddress[tokenAddress] = tokenContract; return tokenContract; |