Export newly refactored contracts from contract-wrappers and index.ts

This commit is contained in:
Leonid Logvinov 2018-06-27 11:51:42 +03:00
parent c466ab6cf2
commit 9fcf9f2504
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4
2 changed files with 50 additions and 70 deletions

View File

@ -1,13 +1,13 @@
import { Provider } from '@0xproject/types';
import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Web3Wrapper } from '@0xproject/web3-wrapper';
import { Provider } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { artifacts } from './artifacts'; 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';
import { ERC721TokenWrapper } from './contract_wrappers/erc721_token_wrapper';
import { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper'; import { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper';
import { ExchangeWrapper } from './contract_wrappers/exchange_wrapper';
import { TokenRegistryWrapper } from './contract_wrappers/token_registry_wrapper';
import { TokenTransferProxyWrapper } from './contract_wrappers/token_transfer_proxy_wrapper';
import { TokenWrapper } from './contract_wrappers/token_wrapper';
import { ContractWrappersConfigSchema } from './schemas/contract_wrappers_config_schema'; import { ContractWrappersConfigSchema } from './schemas/contract_wrappers_config_schema';
import { contractWrappersPrivateNetworkConfigSchema } from './schemas/contract_wrappers_private_network_config_schema'; import { contractWrappersPrivateNetworkConfigSchema } from './schemas/contract_wrappers_private_network_config_schema';
import { contractWrappersPublicNetworkConfigSchema } from './schemas/contract_wrappers_public_network_config_schema'; import { contractWrappersPublicNetworkConfigSchema } from './schemas/contract_wrappers_public_network_config_schema';
@ -18,28 +18,28 @@ import { assert } from './utils/assert';
*/ */
export class ContractWrappers { export class ContractWrappers {
/** /**
* An instance of the ExchangeWrapper class containing methods for interacting with the 0x Exchange smart contract. * An instance of the ERC20TokenWrapper class containing methods for interacting with any ERC20 token smart contract.
*/ */
public exchange: ExchangeWrapper; public erc20Token: ERC20TokenWrapper;
/** /**
* An instance of the TokenRegistryWrapper class containing methods for interacting with the 0x * An instance of the ERC721TokenWrapper class containing methods for interacting with any ERC721 token smart contract.
* TokenRegistry smart contract.
*/ */
public tokenRegistry: TokenRegistryWrapper; public erc721Token: ERC721TokenWrapper;
/**
* An instance of the TokenWrapper class containing methods for interacting with any ERC20 token smart contract.
*/
public token: TokenWrapper;
/** /**
* An instance of the EtherTokenWrapper class containing methods for interacting with the * An instance of the EtherTokenWrapper class containing methods for interacting with the
* wrapped ETH ERC20 token smart contract. * wrapped ETH ERC20 token smart contract.
*/ */
public etherToken: EtherTokenWrapper; public etherToken: EtherTokenWrapper;
/** /**
* An instance of the TokenTransferProxyWrapper class containing methods for interacting with the * An instance of the ERC20ProxyWrapper class containing methods for interacting with the
* tokenTransferProxy smart contract. * erc20Proxy smart contract.
*/ */
public proxy: TokenTransferProxyWrapper; public erc20Proxy: ERC20ProxyWrapper;
/**
* An instance of the ERC721ProxyWrapper class containing methods for interacting with the
* erc721Proxy smart contract.
*/
public erc721Proxy: ERC721ProxyWrapper;
private _web3Wrapper: Web3Wrapper; private _web3Wrapper: Web3Wrapper;
/** /**
* Instantiates a new ContractWrappers instance. * Instantiates a new ContractWrappers instance.
@ -55,7 +55,7 @@ export class ContractWrappers {
contractWrappersPublicNetworkConfigSchema, contractWrappersPublicNetworkConfigSchema,
]); ]);
const artifactJSONs = _.values(artifacts); const artifactJSONs = _.values(artifacts);
const abiArrays = _.map(artifactJSONs, artifact => artifact.abi); const abiArrays = _.map(artifactJSONs, artifact => artifact.compilerOutput.abi);
const txDefaults = { const txDefaults = {
gasPrice: config.gasPrice, gasPrice: config.gasPrice,
}; };
@ -63,25 +63,19 @@ export class ContractWrappers {
_.forEach(abiArrays, abi => { _.forEach(abiArrays, abi => {
this._web3Wrapper.abiDecoder.addABI(abi); this._web3Wrapper.abiDecoder.addABI(abi);
}); });
this.proxy = new TokenTransferProxyWrapper( this.erc20Proxy = new ERC20ProxyWrapper(
this._web3Wrapper, this._web3Wrapper,
config.networkId, config.networkId,
config.tokenTransferProxyContractAddress, config.tokenTransferProxyContractAddress,
); );
this.token = new TokenWrapper(this._web3Wrapper, config.networkId, this.proxy); this.erc721Proxy = new ERC721ProxyWrapper(
this.exchange = new ExchangeWrapper(
this._web3Wrapper, this._web3Wrapper,
config.networkId, config.networkId,
this.token, config.tokenTransferProxyContractAddress,
config.exchangeContractAddress,
config.zrxContractAddress,
); );
this.tokenRegistry = new TokenRegistryWrapper( this.erc20Token = new ERC20TokenWrapper(this._web3Wrapper, config.networkId, this.erc20Proxy);
this._web3Wrapper, this.erc721Token = new ERC721TokenWrapper(this._web3Wrapper, config.networkId, this.erc721Proxy);
config.networkId, this.etherToken = new EtherTokenWrapper(this._web3Wrapper, config.networkId, this.erc20Token);
config.tokenRegistryContractAddress,
);
this.etherToken = new EtherTokenWrapper(this._web3Wrapper, config.networkId, this.token);
} }
/** /**
* Sets a new web3 provider for 0x.js. Updating the provider will stop all * Sets a new web3 provider for 0x.js. Updating the provider will stop all
@ -91,14 +85,10 @@ export class ContractWrappers {
*/ */
public setProvider(provider: Provider, networkId: number): void { public setProvider(provider: Provider, networkId: number): void {
this._web3Wrapper.setProvider(provider); this._web3Wrapper.setProvider(provider);
(this.exchange as any)._invalidateContractInstances(); (this.erc20Token as any)._invalidateContractInstances();
(this.exchange as any)._setNetworkId(networkId); (this.erc20Token as any)._setNetworkId(networkId);
(this.tokenRegistry as any)._invalidateContractInstance(); (this.erc20Proxy as any)._invalidateContractInstance();
(this.tokenRegistry as any)._setNetworkId(networkId); (this.erc20Proxy as any)._setNetworkId(networkId);
(this.token as any)._invalidateContractInstances();
(this.token as any)._setNetworkId(networkId);
(this.proxy as any)._invalidateContractInstance();
(this.proxy as any)._setNetworkId(networkId);
(this.etherToken as any)._invalidateContractInstance(); (this.etherToken as any)._invalidateContractInstance();
(this.etherToken as any)._setNetworkId(networkId); (this.etherToken as any)._setNetworkId(networkId);
} }

View File

@ -1,9 +1,7 @@
export { ContractWrappers } from './contract_wrappers'; export { ContractWrappers } from './contract_wrappers';
export { ExchangeWrapper } from './contract_wrappers/exchange_wrapper'; export { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper';
export { TokenWrapper } from './contract_wrappers/token_wrapper';
export { TokenRegistryWrapper } from './contract_wrappers/token_registry_wrapper';
export { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper'; export { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper';
export { TokenTransferProxyWrapper } from './contract_wrappers/token_transfer_proxy_wrapper'; export { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper';
export { export {
ContractWrappersError, ContractWrappersError,
@ -12,7 +10,6 @@ export {
Token, Token,
IndexedFilterValues, IndexedFilterValues,
BlockRange, BlockRange,
OrderCancellationRequest,
OrderFillRequest, OrderFillRequest,
ContractEventArgs, ContractEventArgs,
ContractWrappersConfig, ContractWrappersConfig,
@ -24,45 +21,38 @@ export {
OnOrderStateChangeCallback, OnOrderStateChangeCallback,
} from './types'; } from './types';
export { Order, SignedOrder, ECSignature, OrderStateValid, OrderStateInvalid, OrderState } from '@0xproject/types';
export { export {
BlockParamLiteral, BlockParamLiteral,
FilterObject, FilterObject,
BlockParam, BlockParam,
ContractEventArg, ContractEventArg,
ExchangeContractErrs,
LogWithDecodedArgs, LogWithDecodedArgs,
Order,
Provider, Provider,
SignedOrder,
ECSignature,
OrderStateValid,
OrderStateInvalid,
OrderState,
TransactionReceipt, TransactionReceipt,
TransactionReceiptWithDecodedLogs, TransactionReceiptWithDecodedLogs,
} from '@0xproject/types'; } from 'ethereum-types';
export { export {
EtherTokenContractEventArgs, WETH9Events,
WithdrawalContractEventArgs, WETH9WithdrawalEventArgs,
DepositContractEventArgs, WETH9ApprovalEventArgs,
EtherTokenEvents, WETH9EventArgs,
} from './contract_wrappers/generated/ether_token'; WETH9DepositEventArgs,
WETH9TransferEventArgs,
} from './contract_wrappers/generated/weth9';
export { export {
TransferContractEventArgs, ERC20TokenTransferEventArgs,
ApprovalContractEventArgs, ERC20TokenApprovalEventArgs,
TokenContractEventArgs, ERC20TokenEvents,
TokenEvents, ERC20TokenEventArgs,
} from './contract_wrappers/generated/token'; } from './contract_wrappers/generated/erc20_token';
export { export {
LogErrorContractEventArgs, ERC721TokenApprovalEventArgs,
LogCancelContractEventArgs, ERC721TokenApprovalForAllEventArgs,
LogFillContractEventArgs, ERC721TokenTransferEventArgs,
ExchangeContractEventArgs, ERC721TokenEvents,
ExchangeEvents, } from './contract_wrappers/generated/erc721_token';
} from './contract_wrappers/generated/exchange';
export { BalanceAndProxyAllowanceLazyStore } from './stores/balance_proxy_allowance_lazy_store';
export { OrderFilledCancelledLazyStore } from './stores/order_filled_cancelled_lazy_store';