aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/contract_wrappers
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/src/contract_wrappers')
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts121
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts152
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts378
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/.gitignore6
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/base_contract.ts3
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/ether_token.ts363
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/exchange.ts730
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/token.ts232
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/token_registry.ts550
-rw-r--r--packages/0x.js/src/contract_wrappers/generated/token_transfer_proxy.ts285
-rw-r--r--packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts42
-rw-r--r--packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts18
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts169
13 files changed, 585 insertions, 2464 deletions
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
index d56b8632d..27551c01d 100644
--- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
@@ -1,11 +1,13 @@
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
-import {Block, BlockAndLogStreamer} from 'ethereumjs-blockstream';
+import { intervalUtils } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
+import { Block, BlockAndLogStreamer } from 'ethereumjs-blockstream';
import * as _ from 'lodash';
import * as Web3 from 'web3';
import {
Artifact,
BlockParamLiteral,
+ BlockRange,
ContractEventArgs,
ContractEvents,
EventCallback,
@@ -13,15 +15,15 @@ import {
InternalZeroExError,
LogWithDecodedArgs,
RawLog,
- SubscriptionOpts,
ZeroExError,
} from '../types';
-import {AbiDecoder} from '../utils/abi_decoder';
-import {constants} from '../utils/constants';
-import {filterUtils} from '../utils/filter_utils';
-import {intervalUtils} from '../utils/interval_utils';
+import { AbiDecoder } from '../utils/abi_decoder';
+import { constants } from '../utils/constants';
+import { filterUtils } from '../utils/filter_utils';
-const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {[contractName: string]: ZeroExError} = {
+const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {
+ [contractName: string]: ZeroExError;
+} = {
ZRX: ZeroExError.ZRXContractDoesNotExist,
EtherToken: ZeroExError.EtherTokenContractDoesNotExist,
Token: ZeroExError.TokenContractDoesNotExist,
@@ -34,26 +36,25 @@ export class ContractWrapper {
protected _web3Wrapper: Web3Wrapper;
private _networkId: number;
private _abiDecoder?: AbiDecoder;
- private _blockAndLogStreamer: BlockAndLogStreamer|undefined;
+ private _blockAndLogStreamerIfExists: BlockAndLogStreamer | undefined;
private _blockAndLogStreamInterval: NodeJS.Timer;
- private _filters: {[filterToken: string]: Web3.FilterObject};
- private _filterCallbacks: {[filterToken: string]: EventCallback<ContractEventArgs>};
- private _onLogAddedSubscriptionToken: string|undefined;
- private _onLogRemovedSubscriptionToken: string|undefined;
+ private _filters: { [filterToken: string]: Web3.FilterObject };
+ private _filterCallbacks: {
+ [filterToken: string]: EventCallback<ContractEventArgs>;
+ };
+ private _onLogAddedSubscriptionToken: string | undefined;
+ private _onLogRemovedSubscriptionToken: string | undefined;
constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder?: AbiDecoder) {
this._web3Wrapper = web3Wrapper;
this._networkId = networkId;
this._abiDecoder = abiDecoder;
this._filters = {};
this._filterCallbacks = {};
- this._blockAndLogStreamer = undefined;
+ this._blockAndLogStreamerIfExists = undefined;
this._onLogAddedSubscriptionToken = undefined;
this._onLogRemovedSubscriptionToken = undefined;
}
- /**
- * Cancels all existing subscriptions
- */
- public unsubscribeAll(): void {
+ protected unsubscribeAll(): void {
const filterTokens = _.keys(this._filterCallbacks);
_.each(filterTokens, filterToken => {
this._unsubscribe(filterToken);
@@ -74,27 +75,36 @@ export class ContractWrapper {
}
}
protected _subscribe<ArgsType extends ContractEventArgs>(
- address: string, eventName: ContractEvents, indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi,
- callback: EventCallback<ArgsType>): string {
+ address: string,
+ eventName: ContractEvents,
+ indexFilterValues: IndexedFilterValues,
+ abi: Web3.ContractAbi,
+ callback: EventCallback<ArgsType>,
+ ): string {
const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi);
- if (_.isUndefined(this._blockAndLogStreamer)) {
+ if (_.isUndefined(this._blockAndLogStreamerIfExists)) {
this._startBlockAndLogStream();
}
const filterToken = filterUtils.generateUUID();
this._filters[filterToken] = filter;
- this._filterCallbacks[filterToken] = callback;
+ this._filterCallbacks[filterToken] = callback as EventCallback<ContractEventArgs>;
return filterToken;
}
protected async _getLogsAsync<ArgsType extends ContractEventArgs>(
- address: string, eventName: ContractEvents, subscriptionOpts: SubscriptionOpts,
- indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
- const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi, subscriptionOpts);
+ address: string,
+ eventName: ContractEvents,
+ blockRange: BlockRange,
+ indexFilterValues: IndexedFilterValues,
+ abi: Web3.ContractAbi,
+ ): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
+ const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi, blockRange);
const logs = await this._web3Wrapper.getLogsAsync(filter);
const logsWithDecodedArguments = _.map(logs, this._tryToDecodeLogOrNoop.bind(this));
return logsWithDecodedArguments;
}
protected _tryToDecodeLogOrNoop<ArgsType extends ContractEventArgs>(
- log: Web3.LogEntry): LogWithDecodedArgs<ArgsType>|RawLog {
+ log: Web3.LogEntry,
+ ): LogWithDecodedArgs<ArgsType> | RawLog {
if (_.isUndefined(this._abiDecoder)) {
throw new Error(InternalZeroExError.NoAbiDecoder);
}
@@ -102,7 +112,8 @@ export class ContractWrapper {
return logWithDecodedArgs;
}
protected async _instantiateContractIfExistsAsync(
- artifact: Artifact, addressIfExists?: string,
+ artifact: Artifact,
+ addressIfExists?: string,
): Promise<Web3.ContractInstance> {
let contractAddress: string;
if (_.isUndefined(addressIfExists)) {
@@ -117,9 +128,7 @@ export class ContractWrapper {
if (!doesContractExist) {
throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contract_name]);
}
- const contractInstance = this._web3Wrapper.getContractInstance(
- artifact.abi, contractAddress,
- );
+ const contractInstance = this._web3Wrapper.getContractInstance(artifact.abi, contractAddress);
return contractInstance;
}
protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string {
@@ -146,45 +155,53 @@ export class ContractWrapper {
});
}
private _startBlockAndLogStream(): void {
- this._blockAndLogStreamer = new BlockAndLogStreamer(
+ if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
+ throw new Error(ZeroExError.SubscriptionAlreadyPresent);
+ }
+ this._blockAndLogStreamerIfExists = new BlockAndLogStreamer(
this._web3Wrapper.getBlockAsync.bind(this._web3Wrapper),
this._web3Wrapper.getLogsAsync.bind(this._web3Wrapper),
);
const catchAllLogFilter = {};
- this._blockAndLogStreamer.addLogFilter(catchAllLogFilter);
+ this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter);
this._blockAndLogStreamInterval = intervalUtils.setAsyncExcludingInterval(
- this._reconcileBlockAsync.bind(this), constants.DEFAULT_BLOCK_POLLING_INTERVAL,
+ this._reconcileBlockAsync.bind(this),
+ constants.DEFAULT_BLOCK_POLLING_INTERVAL,
+ this._onReconcileBlockError.bind(this),
);
let isRemoved = false;
- this._onLogAddedSubscriptionToken = this._blockAndLogStreamer.subscribeToOnLogAdded(
+ this._onLogAddedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogAdded(
this._onLogStateChanged.bind(this, isRemoved),
);
isRemoved = true;
- this._onLogRemovedSubscriptionToken = this._blockAndLogStreamer.subscribeToOnLogRemoved(
+ this._onLogRemovedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogRemoved(
this._onLogStateChanged.bind(this, isRemoved),
);
}
+ private _onReconcileBlockError(err: Error): void {
+ const filterTokens = _.keys(this._filterCallbacks);
+ _.each(filterTokens, filterToken => {
+ this._unsubscribe(filterToken, err);
+ });
+ }
+ private _setNetworkId(networkId: number): void {
+ this._networkId = networkId;
+ }
private _stopBlockAndLogStream(): void {
- (this._blockAndLogStreamer as BlockAndLogStreamer).unsubscribeFromOnLogAdded(
- this._onLogAddedSubscriptionToken as string);
- (this._blockAndLogStreamer as BlockAndLogStreamer).unsubscribeFromOnLogRemoved(
- this._onLogRemovedSubscriptionToken as string);
+ if (_.isUndefined(this._blockAndLogStreamerIfExists)) {
+ throw new Error(ZeroExError.SubscriptionNotFound);
+ }
+ this._blockAndLogStreamerIfExists.unsubscribeFromOnLogAdded(this._onLogAddedSubscriptionToken as string);
+ this._blockAndLogStreamerIfExists.unsubscribeFromOnLogRemoved(this._onLogRemovedSubscriptionToken as string);
intervalUtils.clearAsyncExcludingInterval(this._blockAndLogStreamInterval);
- delete this._blockAndLogStreamer;
+ delete this._blockAndLogStreamerIfExists;
}
private async _reconcileBlockAsync(): Promise<void> {
- try {
- const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest);
- // We need to coerce to Block type cause Web3.Block includes types for mempool blocks
- if (!_.isUndefined(this._blockAndLogStreamer)) {
- // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined
- await this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block);
- }
- } catch (err) {
- const filterTokens = _.keys(this._filterCallbacks);
- _.each(filterTokens, filterToken => {
- this._unsubscribe(filterToken, err);
- });
+ const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest);
+ // We need to coerce to Block type cause Web3.Block includes types for mempool blocks
+ if (!_.isUndefined(this._blockAndLogStreamerIfExists)) {
+ // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined
+ await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlock as any) as Block);
}
}
}
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 896cfde3d..b03571636 100644
--- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
@@ -1,40 +1,54 @@
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
-import BigNumber from 'bignumber.js';
+import { schemas } from '@0xproject/json-schemas';
+import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
-import {artifacts} from '../artifacts';
-import {TransactionOpts, ZeroExError} from '../types';
-import {assert} from '../utils/assert';
+import { artifacts } from '../artifacts';
+import {
+ BlockRange,
+ EtherTokenContractEventArgs,
+ EtherTokenEvents,
+ EventCallback,
+ IndexedFilterValues,
+ LogWithDecodedArgs,
+ TransactionOpts,
+ ZeroExError,
+} from '../types';
+import { AbiDecoder } from '../utils/abi_decoder';
+import { assert } from '../utils/assert';
-import {ContractWrapper} from './contract_wrapper';
-import {EtherTokenContract} from './generated/ether_token';
-import {TokenWrapper} from './token_wrapper';
+import { ContractWrapper } from './contract_wrapper';
+import { EtherTokenContract } from './generated/ether_token';
+import { TokenWrapper } from './token_wrapper';
/**
* This class includes all the functionality related to interacting with a wrapped Ether ERC20 token contract.
* The caller can convert ETH into the equivalent number of wrapped ETH ERC20 tokens and back.
*/
export class EtherTokenWrapper extends ContractWrapper {
- private _etherTokenContractIfExists?: EtherTokenContract;
+ private _etherTokenContractsByAddress: {
+ [address: string]: EtherTokenContract;
+ } = {};
private _tokenWrapper: TokenWrapper;
- private _contractAddressIfExists?: string;
- constructor(web3Wrapper: Web3Wrapper, networkId: number, tokenWrapper: TokenWrapper,
- contractAddressIfExists?: string) {
- super(web3Wrapper, networkId);
+ constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder, tokenWrapper: TokenWrapper) {
+ super(web3Wrapper, networkId, abiDecoder);
this._tokenWrapper = tokenWrapper;
- this._contractAddressIfExists = contractAddressIfExists;
}
/**
* Deposit ETH into the Wrapped ETH smart contract and issues the equivalent number of wrapped ETH tokens
* to the depositor address. These wrapped ETH tokens can be used in 0x trades and are redeemable for 1-to-1
* for ETH.
- * @param amountInWei Amount of ETH in Wei the caller wishes to deposit.
- * @param depositor The hex encoded user Ethereum address that would like to make the deposit.
- * @param txOpts Transaction parameters.
+ * @param etherTokenAddress EtherToken address you wish to deposit into.
+ * @param amountInWei Amount of ETH in Wei the caller wishes to deposit.
+ * @param depositor The hex encoded user Ethereum address that would like to make the deposit.
+ * @param txOpts Transaction parameters.
* @return Transaction hash.
*/
public async depositAsync(
- amountInWei: BigNumber, depositor: string, txOpts: TransactionOpts = {},
+ etherTokenAddress: string,
+ amountInWei: BigNumber,
+ depositor: string,
+ txOpts: TransactionOpts = {},
): Promise<string> {
assert.isValidBaseUnitAmount('amountInWei', amountInWei);
await assert.isSenderAddressAsync('depositor', depositor, this._web3Wrapper);
@@ -42,7 +56,7 @@ export class EtherTokenWrapper extends ContractWrapper {
const ethBalanceInWei = await this._web3Wrapper.getBalanceInWeiAsync(depositor);
assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.InsufficientEthBalanceForDeposit);
- const wethContract = await this._getEtherTokenContractAsync();
+ const wethContract = await this._getEtherTokenContractAsync(etherTokenAddress);
const txHash = await wethContract.deposit.sendTransactionAsync({
from: depositor,
value: amountInWei,
@@ -54,22 +68,25 @@ export class EtherTokenWrapper extends ContractWrapper {
/**
* Withdraw ETH to the withdrawer's address from the wrapped ETH smart contract in exchange for the
* equivalent number of wrapped ETH tokens.
+ * @param etherTokenAddress EtherToken address you wish to withdraw from.
* @param amountInWei Amount of ETH in Wei the caller wishes to withdraw.
* @param withdrawer The hex encoded user Ethereum address that would like to make the withdrawl.
* @param txOpts Transaction parameters.
* @return Transaction hash.
*/
public async withdrawAsync(
- amountInWei: BigNumber, withdrawer: string, txOpts: TransactionOpts = {},
+ etherTokenAddress: string,
+ amountInWei: BigNumber,
+ withdrawer: string,
+ txOpts: TransactionOpts = {},
): Promise<string> {
assert.isValidBaseUnitAmount('amountInWei', amountInWei);
await assert.isSenderAddressAsync('withdrawer', withdrawer, this._web3Wrapper);
- const wethContractAddress = this.getContractAddress();
- const WETHBalanceInBaseUnits = await this._tokenWrapper.getBalanceAsync(wethContractAddress, withdrawer);
+ const WETHBalanceInBaseUnits = await this._tokenWrapper.getBalanceAsync(etherTokenAddress, withdrawer);
assert.assert(WETHBalanceInBaseUnits.gte(amountInWei), ZeroExError.InsufficientWEthBalanceForWithdrawal);
- const wethContract = await this._getEtherTokenContractAsync();
+ const wethContract = await this._getEtherTokenContractAsync(etherTokenAddress);
const txHash = await wethContract.withdraw.sendTransactionAsync(amountInWei, {
from: withdrawer,
gas: txOpts.gasLimit,
@@ -78,27 +95,90 @@ export class EtherTokenWrapper extends ContractWrapper {
return txHash;
}
/**
- * Retrieves the Wrapped Ether token contract address
- * @return The Wrapped Ether token contract address
+ * Gets historical logs without creating a subscription
+ * @param etherTokenAddress An address of the ether token that emmited the logs.
+ * @param eventName The ether token contract event you would like to subscribe to.
+ * @param blockRange Block range to get logs from.
+ * @param indexFilterValues An object where the keys are indexed args returned by the event and
+ * the value is the value you are interested in. E.g `{_owner: aUserAddressHex}`
+ * @return Array of logs that match the parameters
*/
- public getContractAddress(): string {
- const contractAddress = this._getContractAddress(
- artifacts.EtherTokenArtifact, this._contractAddressIfExists,
+ public async getLogsAsync<ArgsType extends EtherTokenContractEventArgs>(
+ etherTokenAddress: string,
+ eventName: EtherTokenEvents,
+ blockRange: BlockRange,
+ indexFilterValues: IndexedFilterValues,
+ ): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
+ assert.isETHAddressHex('etherTokenAddress', etherTokenAddress);
+ assert.doesBelongToStringEnum('eventName', eventName, EtherTokenEvents);
+ assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
+ assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
+ const logs = await this._getLogsAsync<ArgsType>(
+ etherTokenAddress,
+ eventName,
+ blockRange,
+ indexFilterValues,
+ artifacts.EtherTokenArtifact.abi,
);
- return contractAddress;
+ return logs;
+ }
+ /**
+ * Subscribe to an event type emitted by the Token contract.
+ * @param etherTokenAddress The hex encoded address where the ether token is deployed.
+ * @param eventName The ether token contract event you would like to subscribe to.
+ * @param indexFilterValues An object where the keys are indexed args returned by the event and
+ * the value is the value you are interested in. E.g `{_owner: aUserAddressHex}`
+ * @param callback Callback that gets called when a log is added/removed
+ * @return Subscription token used later to unsubscribe
+ */
+ public subscribe<ArgsType extends EtherTokenContractEventArgs>(
+ etherTokenAddress: string,
+ eventName: EtherTokenEvents,
+ indexFilterValues: IndexedFilterValues,
+ callback: EventCallback<ArgsType>,
+ ): string {
+ assert.isETHAddressHex('etherTokenAddress', etherTokenAddress);
+ assert.doesBelongToStringEnum('eventName', eventName, EtherTokenEvents);
+ assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
+ assert.isFunction('callback', callback);
+ const subscriptionToken = this._subscribe<ArgsType>(
+ etherTokenAddress,
+ eventName,
+ indexFilterValues,
+ artifacts.EtherTokenArtifact.abi,
+ callback,
+ );
+ return subscriptionToken;
+ }
+ /**
+ * Cancel a subscription
+ * @param subscriptionToken Subscription token returned by `subscribe()`
+ */
+ public unsubscribe(subscriptionToken: string): void {
+ this._unsubscribe(subscriptionToken);
+ }
+ /**
+ * Cancels all existing subscriptions
+ */
+ public unsubscribeAll(): void {
+ super.unsubscribeAll();
}
private _invalidateContractInstance(): void {
- delete this._etherTokenContractIfExists;
+ this.unsubscribeAll();
+ this._etherTokenContractsByAddress = {};
}
- private async _getEtherTokenContractAsync(): Promise<EtherTokenContract> {
- if (!_.isUndefined(this._etherTokenContractIfExists)) {
- return this._etherTokenContractIfExists;
+ private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise<EtherTokenContract> {
+ let etherTokenContract = this._etherTokenContractsByAddress[etherTokenAddress];
+ if (!_.isUndefined(etherTokenContract)) {
+ return etherTokenContract;
}
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
- artifacts.EtherTokenArtifact, this._contractAddressIfExists,
+ artifacts.EtherTokenArtifact,
+ etherTokenAddress,
);
const contractInstance = new EtherTokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
- this._etherTokenContractIfExists = contractInstance;
- return this._etherTokenContractIfExists;
+ etherTokenContract = contractInstance;
+ this._etherTokenContractsByAddress[etherTokenAddress] = etherTokenContract;
+ return etherTokenContract;
}
}
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 1e9865395..2b6117729 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -1,12 +1,13 @@
-import {schemas} from '@0xproject/json-schemas';
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
-import BigNumber from 'bignumber.js';
+import { schemas } from '@0xproject/json-schemas';
+import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import * as Web3 from 'web3';
-import {artifacts} from '../artifacts';
+import { artifacts } from '../artifacts';
import {
BlockParamLiteral,
+ BlockRange,
DecodedLogArgs,
ECSignature,
EventCallback,
@@ -15,9 +16,7 @@ import {
ExchangeContractEventArgs,
ExchangeEvents,
IndexedFilterValues,
- LogCancelContractEventArgs,
LogErrorContractEventArgs,
- LogFillContractEventArgs,
LogWithDecodedArgs,
MethodOpts,
Order,
@@ -26,21 +25,19 @@ import {
OrderFillRequest,
OrderTransactionOpts,
OrderValues,
- RawLog,
SignedOrder,
- SubscriptionOpts,
ValidateOrderFillableOpts,
} from '../types';
-import {AbiDecoder} from '../utils/abi_decoder';
-import {assert} from '../utils/assert';
-import {decorators} from '../utils/decorators';
-import {ExchangeTransferSimulator} from '../utils/exchange_transfer_simulator';
-import {OrderValidationUtils} from '../utils/order_validation_utils';
-import {utils} from '../utils/utils';
+import { AbiDecoder } from '../utils/abi_decoder';
+import { assert } from '../utils/assert';
+import { decorators } from '../utils/decorators';
+import { ExchangeTransferSimulator } from '../utils/exchange_transfer_simulator';
+import { OrderValidationUtils } from '../utils/order_validation_utils';
+import { utils } from '../utils/utils';
-import {ContractWrapper} from './contract_wrapper';
-import {ExchangeContract} from './generated/exchange';
-import {TokenWrapper} from './token_wrapper';
+import { ContractWrapper } from './contract_wrapper';
+import { ExchangeContract } from './generated/exchange';
+import { TokenWrapper } from './token_wrapper';
const SHOULD_VALIDATE_BY_DEFAULT = true;
@@ -84,12 +81,19 @@ export class ExchangeWrapper extends ContractWrapper {
];
return [orderAddresses, orderValues];
}
- constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder,
- tokenWrapper: TokenWrapper, contractAddressIfExists?: string) {
+ constructor(
+ web3Wrapper: Web3Wrapper,
+ networkId: number,
+ abiDecoder: AbiDecoder,
+ tokenWrapper: TokenWrapper,
+ contractAddressIfExists?: string,
+ zrxContractAddressIfExists?: string,
+ ) {
super(web3Wrapper, networkId, abiDecoder);
this._tokenWrapper = tokenWrapper;
- this._orderValidationUtils = new OrderValidationUtils(tokenWrapper, this);
+ this._orderValidationUtils = new OrderValidationUtils(this);
this._contractAddressIfExists = contractAddressIfExists;
+ this._zrxContractAddressIfExists = zrxContractAddressIfExists;
}
/**
* Returns the unavailable takerAmount of an order. Unavailable amount is defined as the total
@@ -100,14 +104,14 @@ export class ExchangeWrapper extends ContractWrapper {
* @param methodOpts Optional arguments this method accepts.
* @return The amount of the order (in taker tokens) that has either been filled or cancelled.
*/
- public async getUnavailableTakerAmountAsync(orderHash: string,
- methodOpts?: MethodOpts): Promise<BigNumber> {
+ public async getUnavailableTakerAmountAsync(orderHash: string, methodOpts?: MethodOpts): Promise<BigNumber> {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
const exchangeContract = await this._getExchangeContractAsync();
const defaultBlock = _.isUndefined(methodOpts) ? undefined : methodOpts.defaultBlock;
let unavailableTakerTokenAmount = await exchangeContract.getUnavailableTakerTokenAmount.callAsync(
- orderHash, defaultBlock,
+ orderHash,
+ defaultBlock,
);
// Wrap BigNumbers returned from web3 with our own (later) version of BigNumber
unavailableTakerTokenAmount = new BigNumber(unavailableTakerTokenAmount);
@@ -165,25 +169,33 @@ export class ExchangeWrapper extends ContractWrapper {
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
- @decorators.contractCallErrorHandler
- public async fillOrderAsync(signedOrder: SignedOrder, fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ @decorators.asyncZeroExErrorHandler
+ public async fillOrderAsync(
+ signedOrder: SignedOrder,
+ fillTakerTokenAmount: BigNumber,
+ shouldThrowOnInsufficientBalanceOrAllowance: boolean,
+ takerAddress: string,
+ orderTransactionOpts: OrderTransactionOpts = {},
+ ): Promise<string> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const exchangeInstance = await this._getExchangeContractAsync();
- const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate) ?
- SHOULD_VALIDATE_BY_DEFAULT :
- orderTransactionOpts.shouldValidate;
+ const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate)
+ ? SHOULD_VALIDATE_BY_DEFAULT
+ : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
- exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
+ exchangeTradeEmulator,
+ signedOrder,
+ fillTakerTokenAmount,
+ takerAddress,
+ zrxTokenAddress,
+ );
}
const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder);
@@ -221,31 +233,45 @@ export class ExchangeWrapper extends ContractWrapper {
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
- @decorators.contractCallErrorHandler
- public async fillOrdersUpToAsync(signedOrders: SignedOrder[], fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ @decorators.asyncZeroExErrorHandler
+ public async fillOrdersUpToAsync(
+ signedOrders: SignedOrder[],
+ fillTakerTokenAmount: BigNumber,
+ shouldThrowOnInsufficientBalanceOrAllowance: boolean,
+ takerAddress: string,
+ orderTransactionOpts: OrderTransactionOpts = {},
+ ): Promise<string> {
assert.doesConformToSchema('signedOrders', signedOrders, schemas.signedOrdersSchema);
const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress);
- assert.hasAtMostOneUniqueValue(takerTokenAddresses,
- ExchangeContractErrs.MultipleTakerTokensInFillUpToDisallowed);
+ assert.hasAtMostOneUniqueValue(
+ takerTokenAddresses,
+ ExchangeContractErrs.MultipleTakerTokensInFillUpToDisallowed,
+ );
const exchangeContractAddresses = _.map(signedOrders, signedOrder => signedOrder.exchangeContractAddress);
- assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
- ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
+ assert.hasAtMostOneUniqueValue(
+ exchangeContractAddresses,
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress,
+ );
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
- const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate) ?
- SHOULD_VALIDATE_BY_DEFAULT :
- orderTransactionOpts.shouldValidate;
+ const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate)
+ ? SHOULD_VALIDATE_BY_DEFAULT
+ : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
+ let filledTakerTokenAmount = new BigNumber(0);
const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
for (const signedOrder of signedOrders) {
- await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
- exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
+ const singleFilledTakerTokenAmount = await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
+ exchangeTradeEmulator,
+ signedOrder,
+ fillTakerTokenAmount.minus(filledTakerTokenAmount),
+ takerAddress,
+ zrxTokenAddress,
+ );
+ filledTakerTokenAmount = filledTakerTokenAmount.plus(singleFilledTakerTokenAmount);
}
}
@@ -302,30 +328,37 @@ export class ExchangeWrapper extends ContractWrapper {
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
- @decorators.contractCallErrorHandler
- public async batchFillOrdersAsync(orderFillRequests: OrderFillRequest[],
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ @decorators.asyncZeroExErrorHandler
+ public async batchFillOrdersAsync(
+ orderFillRequests: OrderFillRequest[],
+ shouldThrowOnInsufficientBalanceOrAllowance: boolean,
+ takerAddress: string,
+ orderTransactionOpts: OrderTransactionOpts = {},
+ ): Promise<string> {
assert.doesConformToSchema('orderFillRequests', orderFillRequests, schemas.orderFillRequestsSchema);
const exchangeContractAddresses = _.map(
orderFillRequests,
orderFillRequest => orderFillRequest.signedOrder.exchangeContractAddress,
);
- assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
- ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
+ assert.hasAtMostOneUniqueValue(
+ exchangeContractAddresses,
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress,
+ );
assert.isBoolean('shouldThrowOnInsufficientBalanceOrAllowance', shouldThrowOnInsufficientBalanceOrAllowance);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
- const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate) ?
- SHOULD_VALIDATE_BY_DEFAULT :
- orderTransactionOpts.shouldValidate;
+ const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate)
+ ? SHOULD_VALIDATE_BY_DEFAULT
+ : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
for (const orderFillRequest of orderFillRequests) {
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
- exchangeTradeEmulator, orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount,
- takerAddress, zrxTokenAddress,
+ exchangeTradeEmulator,
+ orderFillRequest.signedOrder,
+ orderFillRequest.takerTokenFillAmount,
+ takerAddress,
+ zrxTokenAddress,
);
}
}
@@ -375,24 +408,32 @@ export class ExchangeWrapper extends ContractWrapper {
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
- @decorators.contractCallErrorHandler
- public async fillOrKillOrderAsync(signedOrder: SignedOrder, fillTakerTokenAmount: BigNumber,
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ @decorators.asyncZeroExErrorHandler
+ public async fillOrKillOrderAsync(
+ signedOrder: SignedOrder,
+ fillTakerTokenAmount: BigNumber,
+ takerAddress: string,
+ orderTransactionOpts: OrderTransactionOpts = {},
+ ): Promise<string> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const exchangeInstance = await this._getExchangeContractAsync();
- const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate) ?
- SHOULD_VALIDATE_BY_DEFAULT :
- orderTransactionOpts.shouldValidate;
+ const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate)
+ ? SHOULD_VALIDATE_BY_DEFAULT
+ : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
- exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
+ exchangeTradeEmulator,
+ signedOrder,
+ fillTakerTokenAmount,
+ takerAddress,
+ zrxTokenAddress,
+ );
}
const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(signedOrder);
@@ -420,34 +461,40 @@ export class ExchangeWrapper extends ContractWrapper {
* @param orderTransactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
- @decorators.contractCallErrorHandler
- public async batchFillOrKillAsync(orderFillRequests: OrderFillRequest[],
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
- assert.doesConformToSchema('orderFillRequests', orderFillRequests,
- schemas.orderFillRequestsSchema);
+ @decorators.asyncZeroExErrorHandler
+ public async batchFillOrKillAsync(
+ orderFillRequests: OrderFillRequest[],
+ takerAddress: string,
+ orderTransactionOpts: OrderTransactionOpts = {},
+ ): Promise<string> {
+ assert.doesConformToSchema('orderFillRequests', orderFillRequests, schemas.orderFillRequestsSchema);
const exchangeContractAddresses = _.map(
orderFillRequests,
orderFillRequest => orderFillRequest.signedOrder.exchangeContractAddress,
);
- assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
- ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
+ assert.hasAtMostOneUniqueValue(
+ exchangeContractAddresses,
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress,
+ );
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
if (_.isEmpty(orderFillRequests)) {
throw new Error(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem);
}
const exchangeInstance = await this._getExchangeContractAsync();
- const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate) ?
- SHOULD_VALIDATE_BY_DEFAULT :
- orderTransactionOpts.shouldValidate;
+ const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate)
+ ? SHOULD_VALIDATE_BY_DEFAULT
+ : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
for (const orderFillRequest of orderFillRequests) {
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
- exchangeTradeEmulator, orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount,
- takerAddress, zrxTokenAddress,
+ exchangeTradeEmulator,
+ orderFillRequest.signedOrder,
+ orderFillRequest.takerTokenFillAmount,
+ takerAddress,
+ zrxTokenAddress,
);
}
}
@@ -463,8 +510,9 @@ export class ExchangeWrapper extends ContractWrapper {
});
// We use _.unzip<any> because _.unzip doesn't type check if values have different types :'(
- const [orderAddresses, orderValues, fillTakerTokenAmounts, vParams, rParams, sParams] =
- _.unzip<any>(orderAddressesValuesAndTakerTokenFillAmounts);
+ const [orderAddresses, orderValues, fillTakerTokenAmounts, vParams, rParams, sParams] = _.unzip<any>(
+ orderAddressesValuesAndTakerTokenFillAmounts,
+ );
const txHash = await exchangeInstance.batchFillOrKillOrders.sendTransactionAsync(
orderAddresses,
orderValues,
@@ -488,24 +536,29 @@ export class ExchangeWrapper extends ContractWrapper {
* @param transactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
- @decorators.contractCallErrorHandler
- public async cancelOrderAsync(order: Order|SignedOrder,
- cancelTakerTokenAmount: BigNumber,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ @decorators.asyncZeroExErrorHandler
+ public async cancelOrderAsync(
+ order: Order | SignedOrder,
+ cancelTakerTokenAmount: BigNumber,
+ orderTransactionOpts: OrderTransactionOpts = {},
+ ): Promise<string> {
assert.doesConformToSchema('order', order, schemas.orderSchema);
assert.isValidBaseUnitAmount('takerTokenCancelAmount', cancelTakerTokenAmount);
await assert.isSenderAddressAsync('order.maker', order.maker, this._web3Wrapper);
const exchangeInstance = await this._getExchangeContractAsync();
- const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate) ?
- SHOULD_VALIDATE_BY_DEFAULT :
- orderTransactionOpts.shouldValidate;
+ const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate)
+ ? SHOULD_VALIDATE_BY_DEFAULT
+ : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
const orderHash = utils.getOrderHashHex(order);
const unavailableTakerTokenAmount = await this.getUnavailableTakerAmountAsync(orderHash);
OrderValidationUtils.validateCancelOrderThrowIfInvalid(
- order, cancelTakerTokenAmount, unavailableTakerTokenAmount);
+ order,
+ cancelTakerTokenAmount,
+ unavailableTakerTokenAmount,
+ );
}
const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order);
@@ -529,34 +582,41 @@ export class ExchangeWrapper extends ContractWrapper {
* @param transactionOpts Optional arguments this method accepts.
* @return Transaction hash.
*/
- @decorators.contractCallErrorHandler
- public async batchCancelOrdersAsync(orderCancellationRequests: OrderCancellationRequest[],
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
- assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests,
- schemas.orderCancellationRequestsSchema);
+ @decorators.asyncZeroExErrorHandler
+ public async batchCancelOrdersAsync(
+ orderCancellationRequests: OrderCancellationRequest[],
+ orderTransactionOpts: OrderTransactionOpts = {},
+ ): Promise<string> {
+ assert.doesConformToSchema(
+ 'orderCancellationRequests',
+ orderCancellationRequests,
+ schemas.orderCancellationRequestsSchema,
+ );
const exchangeContractAddresses = _.map(
orderCancellationRequests,
orderCancellationRequest => orderCancellationRequest.order.exchangeContractAddress,
);
- assert.hasAtMostOneUniqueValue(exchangeContractAddresses,
- ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress);
+ assert.hasAtMostOneUniqueValue(
+ exchangeContractAddresses,
+ ExchangeContractErrs.BatchOrdersMustHaveSameExchangeAddress,
+ );
const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker);
assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MultipleMakersInSingleCancelBatchDisallowed);
const maker = makers[0];
await assert.isSenderAddressAsync('maker', maker, this._web3Wrapper);
- const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate) ?
- SHOULD_VALIDATE_BY_DEFAULT :
- orderTransactionOpts.shouldValidate;
+ const shouldValidate = _.isUndefined(orderTransactionOpts.shouldValidate)
+ ? SHOULD_VALIDATE_BY_DEFAULT
+ : orderTransactionOpts.shouldValidate;
if (shouldValidate) {
for (const orderCancellationRequest of orderCancellationRequests) {
const orderHash = utils.getOrderHashHex(orderCancellationRequest.order);
const unavailableTakerTokenAmount = await this.getUnavailableTakerAmountAsync(orderHash);
OrderValidationUtils.validateCancelOrderThrowIfInvalid(
- orderCancellationRequest.order, orderCancellationRequest.takerTokenCancelAmount,
+ orderCancellationRequest.order,
+ orderCancellationRequest.takerTokenCancelAmount,
unavailableTakerTokenAmount,
);
}
-
}
if (_.isEmpty(orderCancellationRequests)) {
throw new Error(ExchangeContractErrs.BatchOrdersMustHaveAtLeastOneItem);
@@ -569,8 +629,9 @@ export class ExchangeWrapper extends ContractWrapper {
];
});
// We use _.unzip<any> because _.unzip doesn't type check if values have different types :'(
- const [orderAddresses, orderValues, cancelTakerTokenAmounts] =
- _.unzip<any>(orderAddressesValuesAndTakerTokenCancelAmounts);
+ const [orderAddresses, orderValues, cancelTakerTokenAmounts] = _.unzip<any>(
+ orderAddressesValuesAndTakerTokenCancelAmounts,
+ );
const txHash = await exchangeInstance.batchCancelOrders.sendTransactionAsync(
orderAddresses,
orderValues,
@@ -592,14 +653,20 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Subscription token used later to unsubscribe
*/
public subscribe<ArgsType extends ExchangeContractEventArgs>(
- eventName: ExchangeEvents, indexFilterValues: IndexedFilterValues,
- callback: EventCallback<ArgsType>): string {
+ eventName: ExchangeEvents,
+ indexFilterValues: IndexedFilterValues,
+ callback: EventCallback<ArgsType>,
+ ): string {
assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
const exchangeContractAddress = this.getContractAddress();
const subscriptionToken = this._subscribe<ArgsType>(
- exchangeContractAddress, eventName, indexFilterValues, artifacts.ExchangeArtifact.abi, callback,
+ exchangeContractAddress,
+ eventName,
+ indexFilterValues,
+ artifacts.ExchangeArtifact.abi,
+ callback,
);
return subscriptionToken;
}
@@ -611,22 +678,34 @@ export class ExchangeWrapper extends ContractWrapper {
this._unsubscribe(subscriptionToken);
}
/**
+ * Cancels all existing subscriptions
+ */
+ public unsubscribeAll(): void {
+ super.unsubscribeAll();
+ }
+ /**
* Gets historical logs without creating a subscription
* @param eventName The exchange contract event you would like to subscribe to.
- * @param subscriptionOpts Subscriptions options that let you configure the subscription.
+ * @param blockRange Block range to get logs from.
* @param indexFilterValues An object where the keys are indexed args returned by the event and
* 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 ExchangeContractEventArgs>(
- eventName: ExchangeEvents, subscriptionOpts: SubscriptionOpts, indexFilterValues: IndexedFilterValues,
+ eventName: ExchangeEvents,
+ blockRange: BlockRange,
+ indexFilterValues: IndexedFilterValues,
): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
- assert.doesConformToSchema('subscriptionOpts', subscriptionOpts, schemas.subscriptionOptsSchema);
+ assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const exchangeContractAddress = this.getContractAddress();
const logs = await this._getLogsAsync<ArgsType>(
- exchangeContractAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.ExchangeArtifact.abi,
+ exchangeContractAddress,
+ eventName,
+ blockRange,
+ indexFilterValues,
+ artifacts.ExchangeArtifact.abi,
);
return logs;
}
@@ -649,14 +728,18 @@ export class ExchangeWrapper extends ContractWrapper {
* to validate for.
*/
public async validateOrderFillableOrThrowAsync(
- signedOrder: SignedOrder, opts?: ValidateOrderFillableOpts,
+ signedOrder: SignedOrder,
+ opts?: ValidateOrderFillableOpts,
): Promise<void> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const zrxTokenAddress = this.getZRXTokenAddress();
const expectedFillTakerTokenAmount = !_.isUndefined(opts) ? opts.expectedFillTakerTokenAmount : undefined;
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateOrderFillableOrThrowAsync(
- exchangeTradeEmulator, signedOrder, zrxTokenAddress, expectedFillTakerTokenAmount,
+ exchangeTradeEmulator,
+ signedOrder,
+ zrxTokenAddress,
+ expectedFillTakerTokenAmount,
);
}
/**
@@ -667,16 +750,23 @@ export class ExchangeWrapper extends ContractWrapper {
* @param takerAddress The user Ethereum address who would like to fill this order.
* Must be available via the supplied Web3.Provider passed to 0x.js.
*/
- public async validateFillOrderThrowIfInvalidAsync(signedOrder: SignedOrder,
- fillTakerTokenAmount: BigNumber,
- takerAddress: string): Promise<void> {
+ public async validateFillOrderThrowIfInvalidAsync(
+ signedOrder: SignedOrder,
+ fillTakerTokenAmount: BigNumber,
+ takerAddress: string,
+ ): Promise<void> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateFillOrderThrowIfInvalidAsync(
- exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
+ exchangeTradeEmulator,
+ signedOrder,
+ fillTakerTokenAmount,
+ takerAddress,
+ zrxTokenAddress,
+ );
}
/**
* Checks if cancelling a given order will succeed and throws an informative error if it won't.
@@ -685,13 +775,18 @@ export class ExchangeWrapper extends ContractWrapper {
* @param cancelTakerTokenAmount The amount (specified in taker tokens) that you would like to cancel.
*/
public async validateCancelOrderThrowIfInvalidAsync(
- order: Order, cancelTakerTokenAmount: BigNumber): Promise<void> {
+ order: Order,
+ cancelTakerTokenAmount: BigNumber,
+ ): Promise<void> {
assert.doesConformToSchema('order', order, schemas.orderSchema);
assert.isValidBaseUnitAmount('cancelTakerTokenAmount', cancelTakerTokenAmount);
const orderHash = utils.getOrderHashHex(order);
const unavailableTakerTokenAmount = await this.getUnavailableTakerAmountAsync(orderHash);
OrderValidationUtils.validateCancelOrderThrowIfInvalid(
- order, cancelTakerTokenAmount, unavailableTakerTokenAmount);
+ order,
+ cancelTakerTokenAmount,
+ unavailableTakerTokenAmount,
+ );
}
/**
* Checks if calling fillOrKill on a given order will succeed and throws an informative error if it won't.
@@ -701,16 +796,23 @@ export class ExchangeWrapper extends ContractWrapper {
* @param takerAddress The user Ethereum address who would like to fill this order.
* Must be available via the supplied Web3.Provider passed to 0x.js.
*/
- public async validateFillOrKillOrderThrowIfInvalidAsync(signedOrder: SignedOrder,
- fillTakerTokenAmount: BigNumber,
- takerAddress: string): Promise<void> {
+ public async validateFillOrKillOrderThrowIfInvalidAsync(
+ signedOrder: SignedOrder,
+ fillTakerTokenAmount: BigNumber,
+ takerAddress: string,
+ ): Promise<void> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper);
const zrxTokenAddress = this.getZRXTokenAddress();
const exchangeTradeEmulator = new ExchangeTransferSimulator(this._tokenWrapper, BlockParamLiteral.Latest);
await this._orderValidationUtils.validateFillOrKillOrderThrowIfInvalidAsync(
- exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress);
+ exchangeTradeEmulator,
+ signedOrder,
+ fillTakerTokenAmount,
+ takerAddress,
+ zrxTokenAddress,
+ );
}
/**
* Checks if rounding error will be > 0.1% when computing makerTokenAmount by doing:
@@ -721,15 +823,19 @@ export class ExchangeWrapper extends ContractWrapper {
* @param takerTokenAmount The order size on the taker side
* @param makerTokenAmount The order size on the maker side
*/
- public async isRoundingErrorAsync(fillTakerTokenAmount: BigNumber,
- takerTokenAmount: BigNumber,
- makerTokenAmount: BigNumber): Promise<boolean> {
+ public async isRoundingErrorAsync(
+ fillTakerTokenAmount: BigNumber,
+ takerTokenAmount: BigNumber,
+ makerTokenAmount: BigNumber,
+ ): Promise<boolean> {
assert.isValidBaseUnitAmount('fillTakerTokenAmount', fillTakerTokenAmount);
assert.isValidBaseUnitAmount('takerTokenAmount', takerTokenAmount);
assert.isValidBaseUnitAmount('makerTokenAmount', makerTokenAmount);
const exchangeInstance = await this._getExchangeContractAsync();
const isRoundingError = await exchangeInstance.isRoundingError.callAsync(
- fillTakerTokenAmount, takerTokenAmount, makerTokenAmount,
+ fillTakerTokenAmount,
+ takerTokenAmount,
+ makerTokenAmount,
);
return isRoundingError;
}
@@ -737,10 +843,10 @@ export class ExchangeWrapper extends ContractWrapper {
* Checks if logs contain LogError, which is emmited by Exchange contract on transaction failure.
* @param logs Transaction logs as returned by `zeroEx.awaitTransactionMinedAsync`
*/
- public throwLogErrorsAsErrors(logs: Array<LogWithDecodedArgs<DecodedLogArgs>|Web3.LogEntry>): void {
+ public throwLogErrorsAsErrors(logs: Array<LogWithDecodedArgs<DecodedLogArgs> | Web3.LogEntry>): void {
const errLog = _.find(logs, {
event: ExchangeEvents.LogError,
- }) as LogWithDecodedArgs<LogErrorContractEventArgs>|undefined;
+ }) as LogWithDecodedArgs<LogErrorContractEventArgs> | undefined;
if (!_.isUndefined(errLog)) {
const logArgs = errLog.args;
const errCode = logArgs.errorId.toNumber();
@@ -753,17 +859,18 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Address of ZRX token
*/
public getZRXTokenAddress(): string {
- const contractAddress = this._getContractAddress(
- artifacts.ZRXArtifact, this._zrxContractAddressIfExists,
- );
+ const contractAddress = this._getContractAddress(artifacts.ZRXArtifact, this._zrxContractAddressIfExists);
return contractAddress;
}
private _invalidateContractInstances(): void {
this.unsubscribeAll();
delete this._exchangeContractIfExists;
}
- private async _isValidSignatureUsingContractCallAsync(dataHex: string, ecSignature: ECSignature,
- signerAddressHex: string): Promise<boolean> {
+ private async _isValidSignatureUsingContractCallAsync(
+ dataHex: string,
+ ecSignature: ECSignature,
+ signerAddressHex: string,
+ ): Promise<boolean> {
assert.isHexString('dataHex', dataHex);
assert.doesConformToSchema('ecSignature', ecSignature, schemas.ecSignatureSchema);
assert.isETHAddressHex('signerAddressHex', signerAddressHex);
@@ -779,7 +886,7 @@ export class ExchangeWrapper extends ContractWrapper {
);
return isValidSignature;
}
- private async _getOrderHashHexUsingContractCallAsync(order: Order|SignedOrder): Promise<string> {
+ private async _getOrderHashHexUsingContractCallAsync(order: Order | SignedOrder): Promise<string> {
const exchangeInstance = await this._getExchangeContractAsync();
const [orderAddresses, orderValues] = ExchangeWrapper._getOrderAddressesAndValues(order);
const orderHashHex = await exchangeInstance.getOrderHash.callAsync(orderAddresses, orderValues);
@@ -790,7 +897,8 @@ export class ExchangeWrapper extends ContractWrapper {
return this._exchangeContractIfExists;
}
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
- artifacts.ExchangeArtifact, this._contractAddressIfExists,
+ artifacts.ExchangeArtifact,
+ this._contractAddressIfExists,
);
const contractInstance = new ExchangeContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
this._exchangeContractIfExists = contractInstance;
diff --git a/packages/0x.js/src/contract_wrappers/generated/.gitignore b/packages/0x.js/src/contract_wrappers/generated/.gitignore
new file mode 100644
index 000000000..834808b48
--- /dev/null
+++ b/packages/0x.js/src/contract_wrappers/generated/.gitignore
@@ -0,0 +1,6 @@
+dummy_token.ts
+ether_token.ts
+exchange.ts
+token_registry.ts
+token_transfer_proxy.ts
+token.ts
diff --git a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
index 396a4d593..28a7e2f52 100644
--- a/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
+++ b/packages/0x.js/src/contract_wrappers/generated/base_contract.ts
@@ -1,8 +1,7 @@
+import {TxData, TxDataPayable} from '@0xproject/types';
import * as _ from 'lodash';
import * as Web3 from 'web3';
-import {TxData, TxDataPayable} from '../../types';
-
export class BaseContract {
protected web3ContractInstance: Web3.ContractInstance;
protected defaults: Partial<TxData>;
diff --git a/packages/0x.js/src/contract_wrappers/generated/ether_token.ts b/packages/0x.js/src/contract_wrappers/generated/ether_token.ts
deleted file mode 100644
index ce3f9f527..000000000
--- a/packages/0x.js/src/contract_wrappers/generated/ether_token.ts
+++ /dev/null
@@ -1,363 +0,0 @@
-/**
- * This file is auto-generated using abi-gen. Don't edit directly.
- * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
- */
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
-import * as Web3 from 'web3';
-
-import {TxData, TxDataPayable} from '../../types';
-import {classUtils} from '../../utils/class_utils';
-
-import {BaseContract} from './base_contract';
-
-export class EtherTokenContract extends BaseContract {
- public name = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as EtherTokenContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.name.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public approve = {
- async sendTransactionAsync(
- _spender: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.approve.estimateGasAsync.bind(
- self,
- _spender,
- _value,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.approve, self.web3ContractInstance,
- )(
- _spender,
- _value,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _spender: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.approve.estimateGas, self.web3ContractInstance,
- )(
- _spender,
- _value,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _spender: string,
- _value: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as EtherTokenContract;
- const abiEncodedTransactionData = self.web3ContractInstance.approve.getData();
- return abiEncodedTransactionData;
- },
- };
- public totalSupply = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as EtherTokenContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.totalSupply.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public transferFrom = {
- async sendTransactionAsync(
- _from: string,
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.transferFrom.estimateGasAsync.bind(
- self,
- _from,
- _to,
- _value,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.transferFrom, self.web3ContractInstance,
- )(
- _from,
- _to,
- _value,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _from: string,
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance,
- )(
- _from,
- _to,
- _value,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _from: string,
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as EtherTokenContract;
- const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData();
- return abiEncodedTransactionData;
- },
- };
- public withdraw = {
- async sendTransactionAsync(
- amount: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.withdraw.estimateGasAsync.bind(
- self,
- amount,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.withdraw, self.web3ContractInstance,
- )(
- amount,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- amount: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.withdraw.estimateGas, self.web3ContractInstance,
- )(
- amount,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- amount: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as EtherTokenContract;
- const abiEncodedTransactionData = self.web3ContractInstance.withdraw.getData();
- return abiEncodedTransactionData;
- },
- };
- public decimals = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as EtherTokenContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.decimals.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public balanceOf = {
- async callAsync(
- _owner: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as EtherTokenContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.balanceOf.call,
- self.web3ContractInstance,
- )(
- _owner,
- );
- return result;
- },
- };
- public symbol = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as EtherTokenContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.symbol.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public transfer = {
- async sendTransactionAsync(
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.transfer.estimateGasAsync.bind(
- self,
- _to,
- _value,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.transfer, self.web3ContractInstance,
- )(
- _to,
- _value,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.transfer.estimateGas, self.web3ContractInstance,
- )(
- _to,
- _value,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as EtherTokenContract;
- const abiEncodedTransactionData = self.web3ContractInstance.transfer.getData();
- return abiEncodedTransactionData;
- },
- };
- public deposit = {
- async sendTransactionAsync(
- txData: TxDataPayable = {},
- ): Promise<string> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.deposit.estimateGasAsync.bind(
- self,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.deposit, self.web3ContractInstance,
- )(
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- txData: TxData = {},
- ): Promise<number> {
- const self = this as EtherTokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.deposit.estimateGas, self.web3ContractInstance,
- )(
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- txData: TxData = {},
- ): string {
- const self = this as EtherTokenContract;
- const abiEncodedTransactionData = self.web3ContractInstance.deposit.getData();
- return abiEncodedTransactionData;
- },
- };
- public allowance = {
- async callAsync(
- _owner: string,
- _spender: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as EtherTokenContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.allowance.call,
- self.web3ContractInstance,
- )(
- _owner,
- _spender,
- );
- return result;
- },
- };
- constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- super(web3ContractInstance, defaults);
- classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
- }
-} // tslint:disable:max-file-line-count
diff --git a/packages/0x.js/src/contract_wrappers/generated/exchange.ts b/packages/0x.js/src/contract_wrappers/generated/exchange.ts
deleted file mode 100644
index e06ed960c..000000000
--- a/packages/0x.js/src/contract_wrappers/generated/exchange.ts
+++ /dev/null
@@ -1,730 +0,0 @@
-/**
- * This file is auto-generated using abi-gen. Don't edit directly.
- * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
- */
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
-import * as Web3 from 'web3';
-
-import {TxData, TxDataPayable} from '../../types';
-import {classUtils} from '../../utils/class_utils';
-
-import {BaseContract} from './base_contract';
-
-export class ExchangeContract extends BaseContract {
- public isRoundingError = {
- async callAsync(
- numerator: BigNumber,
- denominator: BigNumber,
- target: BigNumber,
- defaultBlock?: Web3.BlockParam,
- ): Promise<boolean
- > {
- const self = this as ExchangeContract;
- const result = await promisify<boolean
- >(
- self.web3ContractInstance.isRoundingError.call,
- self.web3ContractInstance,
- )(
- numerator,
- denominator,
- target,
- );
- return result;
- },
- };
- public filled = {
- async callAsync(
- index: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as ExchangeContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.filled.call,
- self.web3ContractInstance,
- )(
- index,
- );
- return result;
- },
- };
- public cancelled = {
- async callAsync(
- index: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as ExchangeContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.cancelled.call,
- self.web3ContractInstance,
- )(
- index,
- );
- return result;
- },
- };
- public fillOrdersUpTo = {
- async sendTransactionAsync(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): Promise<string> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.fillOrdersUpTo.estimateGasAsync.bind(
- self,
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.fillOrdersUpTo, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): Promise<number> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.fillOrdersUpTo.estimateGas, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): string {
- const self = this as ExchangeContract;
- const abiEncodedTransactionData = self.web3ContractInstance.fillOrdersUpTo.getData();
- return abiEncodedTransactionData;
- },
- };
- public cancelOrder = {
- async sendTransactionAsync(
- orderAddresses: string[],
- orderValues: BigNumber[],
- cancelTakerTokenAmount: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.cancelOrder.estimateGasAsync.bind(
- self,
- orderAddresses,
- orderValues,
- cancelTakerTokenAmount,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.cancelOrder, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- cancelTakerTokenAmount,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- orderAddresses: string[],
- orderValues: BigNumber[],
- cancelTakerTokenAmount: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.cancelOrder.estimateGas, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- cancelTakerTokenAmount,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- orderAddresses: string[],
- orderValues: BigNumber[],
- cancelTakerTokenAmount: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as ExchangeContract;
- const abiEncodedTransactionData = self.web3ContractInstance.cancelOrder.getData();
- return abiEncodedTransactionData;
- },
- };
- public ZRX_TOKEN_CONTRACT = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as ExchangeContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.ZRX_TOKEN_CONTRACT.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public batchFillOrKillOrders = {
- async sendTransactionAsync(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmounts: BigNumber[],
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): Promise<string> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.batchFillOrKillOrders.estimateGasAsync.bind(
- self,
- orderAddresses,
- orderValues,
- fillTakerTokenAmounts,
- v,
- r,
- s,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.batchFillOrKillOrders, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmounts,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmounts: BigNumber[],
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): Promise<number> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.batchFillOrKillOrders.estimateGas, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmounts,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmounts: BigNumber[],
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): string {
- const self = this as ExchangeContract;
- const abiEncodedTransactionData = self.web3ContractInstance.batchFillOrKillOrders.getData();
- return abiEncodedTransactionData;
- },
- };
- public fillOrKillOrder = {
- async sendTransactionAsync(
- orderAddresses: string[],
- orderValues: BigNumber[],
- fillTakerTokenAmount: BigNumber,
- v: number|BigNumber,
- r: string,
- s: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.fillOrKillOrder.estimateGasAsync.bind(
- self,
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- v,
- r,
- s,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.fillOrKillOrder, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- orderAddresses: string[],
- orderValues: BigNumber[],
- fillTakerTokenAmount: BigNumber,
- v: number|BigNumber,
- r: string,
- s: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.fillOrKillOrder.estimateGas, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- orderAddresses: string[],
- orderValues: BigNumber[],
- fillTakerTokenAmount: BigNumber,
- v: number|BigNumber,
- r: string,
- s: string,
- txData: TxData = {},
- ): string {
- const self = this as ExchangeContract;
- const abiEncodedTransactionData = self.web3ContractInstance.fillOrKillOrder.getData();
- return abiEncodedTransactionData;
- },
- };
- public getUnavailableTakerTokenAmount = {
- async callAsync(
- orderHash: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as ExchangeContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.getUnavailableTakerTokenAmount.call,
- self.web3ContractInstance,
- )(
- orderHash,
- );
- return result;
- },
- };
- public isValidSignature = {
- async callAsync(
- signer: string,
- hash: string,
- v: number|BigNumber,
- r: string,
- s: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<boolean
- > {
- const self = this as ExchangeContract;
- const result = await promisify<boolean
- >(
- self.web3ContractInstance.isValidSignature.call,
- self.web3ContractInstance,
- )(
- signer,
- hash,
- v,
- r,
- s,
- );
- return result;
- },
- };
- public getPartialAmount = {
- async callAsync(
- numerator: BigNumber,
- denominator: BigNumber,
- target: BigNumber,
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as ExchangeContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.getPartialAmount.call,
- self.web3ContractInstance,
- )(
- numerator,
- denominator,
- target,
- );
- return result;
- },
- };
- public TOKEN_TRANSFER_PROXY_CONTRACT = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as ExchangeContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.TOKEN_TRANSFER_PROXY_CONTRACT.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public batchFillOrders = {
- async sendTransactionAsync(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmounts: BigNumber[],
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): Promise<string> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.batchFillOrders.estimateGasAsync.bind(
- self,
- orderAddresses,
- orderValues,
- fillTakerTokenAmounts,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.batchFillOrders, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmounts,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmounts: BigNumber[],
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): Promise<number> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.batchFillOrders.estimateGas, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmounts,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- fillTakerTokenAmounts: BigNumber[],
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber[],
- r: string[],
- s: string[],
- txData: TxData = {},
- ): string {
- const self = this as ExchangeContract;
- const abiEncodedTransactionData = self.web3ContractInstance.batchFillOrders.getData();
- return abiEncodedTransactionData;
- },
- };
- public batchCancelOrders = {
- async sendTransactionAsync(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- cancelTakerTokenAmounts: BigNumber[],
- txData: TxData = {},
- ): Promise<string> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.batchCancelOrders.estimateGasAsync.bind(
- self,
- orderAddresses,
- orderValues,
- cancelTakerTokenAmounts,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.batchCancelOrders, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- cancelTakerTokenAmounts,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- cancelTakerTokenAmounts: BigNumber[],
- txData: TxData = {},
- ): Promise<number> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.batchCancelOrders.estimateGas, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- cancelTakerTokenAmounts,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- orderAddresses: string[][],
- orderValues: BigNumber[][],
- cancelTakerTokenAmounts: BigNumber[],
- txData: TxData = {},
- ): string {
- const self = this as ExchangeContract;
- const abiEncodedTransactionData = self.web3ContractInstance.batchCancelOrders.getData();
- return abiEncodedTransactionData;
- },
- };
- public fillOrder = {
- async sendTransactionAsync(
- orderAddresses: string[],
- orderValues: BigNumber[],
- fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber,
- r: string,
- s: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.fillOrder.estimateGasAsync.bind(
- self,
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.fillOrder, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- orderAddresses: string[],
- orderValues: BigNumber[],
- fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber,
- r: string,
- s: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as ExchangeContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.fillOrder.estimateGas, self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- fillTakerTokenAmount,
- shouldThrowOnInsufficientBalanceOrAllowance,
- v,
- r,
- s,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- orderAddresses: string[],
- orderValues: BigNumber[],
- fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- v: number|BigNumber,
- r: string,
- s: string,
- txData: TxData = {},
- ): string {
- const self = this as ExchangeContract;
- const abiEncodedTransactionData = self.web3ContractInstance.fillOrder.getData();
- return abiEncodedTransactionData;
- },
- };
- public getOrderHash = {
- async callAsync(
- orderAddresses: string[],
- orderValues: BigNumber[],
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as ExchangeContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.getOrderHash.call,
- self.web3ContractInstance,
- )(
- orderAddresses,
- orderValues,
- );
- return result;
- },
- };
- public EXTERNAL_QUERY_GAS_LIMIT = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as ExchangeContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.EXTERNAL_QUERY_GAS_LIMIT.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public VERSION = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as ExchangeContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.VERSION.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- super(web3ContractInstance, defaults);
- classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
- }
-} // tslint:disable:max-file-line-count
diff --git a/packages/0x.js/src/contract_wrappers/generated/token.ts b/packages/0x.js/src/contract_wrappers/generated/token.ts
deleted file mode 100644
index 83a4ead34..000000000
--- a/packages/0x.js/src/contract_wrappers/generated/token.ts
+++ /dev/null
@@ -1,232 +0,0 @@
-/**
- * This file is auto-generated using abi-gen. Don't edit directly.
- * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
- */
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
-import * as Web3 from 'web3';
-
-import {TxData, TxDataPayable} from '../../types';
-import {classUtils} from '../../utils/class_utils';
-
-import {BaseContract} from './base_contract';
-
-export class TokenContract extends BaseContract {
- public approve = {
- async sendTransactionAsync(
- _spender: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.approve.estimateGasAsync.bind(
- self,
- _spender,
- _value,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.approve, self.web3ContractInstance,
- )(
- _spender,
- _value,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _spender: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.approve.estimateGas, self.web3ContractInstance,
- )(
- _spender,
- _value,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _spender: string,
- _value: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as TokenContract;
- const abiEncodedTransactionData = self.web3ContractInstance.approve.getData();
- return abiEncodedTransactionData;
- },
- };
- public totalSupply = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as TokenContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.totalSupply.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public transferFrom = {
- async sendTransactionAsync(
- _from: string,
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.transferFrom.estimateGasAsync.bind(
- self,
- _from,
- _to,
- _value,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.transferFrom, self.web3ContractInstance,
- )(
- _from,
- _to,
- _value,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _from: string,
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance,
- )(
- _from,
- _to,
- _value,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _from: string,
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as TokenContract;
- const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData();
- return abiEncodedTransactionData;
- },
- };
- public balanceOf = {
- async callAsync(
- _owner: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as TokenContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.balanceOf.call,
- self.web3ContractInstance,
- )(
- _owner,
- );
- return result;
- },
- };
- public transfer = {
- async sendTransactionAsync(
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.transfer.estimateGasAsync.bind(
- self,
- _to,
- _value,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.transfer, self.web3ContractInstance,
- )(
- _to,
- _value,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.transfer.estimateGas, self.web3ContractInstance,
- )(
- _to,
- _value,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _to: string,
- _value: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as TokenContract;
- const abiEncodedTransactionData = self.web3ContractInstance.transfer.getData();
- return abiEncodedTransactionData;
- },
- };
- public allowance = {
- async callAsync(
- _owner: string,
- _spender: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<BigNumber
- > {
- const self = this as TokenContract;
- const result = await promisify<BigNumber
- >(
- self.web3ContractInstance.allowance.call,
- self.web3ContractInstance,
- )(
- _owner,
- _spender,
- );
- return result;
- },
- };
- constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- super(web3ContractInstance, defaults);
- classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
- }
-} // tslint:disable:max-file-line-count
diff --git a/packages/0x.js/src/contract_wrappers/generated/token_registry.ts b/packages/0x.js/src/contract_wrappers/generated/token_registry.ts
deleted file mode 100644
index 5d9ad9016..000000000
--- a/packages/0x.js/src/contract_wrappers/generated/token_registry.ts
+++ /dev/null
@@ -1,550 +0,0 @@
-/**
- * This file is auto-generated using abi-gen. Don't edit directly.
- * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
- */
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
-import * as Web3 from 'web3';
-
-import {TxData, TxDataPayable} from '../../types';
-import {classUtils} from '../../utils/class_utils';
-
-import {BaseContract} from './base_contract';
-
-export class TokenRegistryContract extends BaseContract {
- public removeToken = {
- async sendTransactionAsync(
- _token: string,
- _index: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.removeToken.estimateGasAsync.bind(
- self,
- _token,
- _index,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.removeToken, self.web3ContractInstance,
- )(
- _token,
- _index,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _token: string,
- _index: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.removeToken.estimateGas, self.web3ContractInstance,
- )(
- _token,
- _index,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _token: string,
- _index: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as TokenRegistryContract;
- const abiEncodedTransactionData = self.web3ContractInstance.removeToken.getData();
- return abiEncodedTransactionData;
- },
- };
- public getTokenAddressByName = {
- async callAsync(
- _name: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.getTokenAddressByName.call,
- self.web3ContractInstance,
- )(
- _name,
- );
- return result;
- },
- };
- public getTokenAddressBySymbol = {
- async callAsync(
- _symbol: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.getTokenAddressBySymbol.call,
- self.web3ContractInstance,
- )(
- _symbol,
- );
- return result;
- },
- };
- public setTokenSwarmHash = {
- async sendTransactionAsync(
- _token: string,
- _swarmHash: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.setTokenSwarmHash.estimateGasAsync.bind(
- self,
- _token,
- _swarmHash,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.setTokenSwarmHash, self.web3ContractInstance,
- )(
- _token,
- _swarmHash,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _token: string,
- _swarmHash: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.setTokenSwarmHash.estimateGas, self.web3ContractInstance,
- )(
- _token,
- _swarmHash,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _token: string,
- _swarmHash: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenRegistryContract;
- const abiEncodedTransactionData = self.web3ContractInstance.setTokenSwarmHash.getData();
- return abiEncodedTransactionData;
- },
- };
- public getTokenMetaData = {
- async callAsync(
- _token: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<[string, string, string, BigNumber, string, string]
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<[string, string, string, BigNumber, string, string]
- >(
- self.web3ContractInstance.getTokenMetaData.call,
- self.web3ContractInstance,
- )(
- _token,
- );
- return result;
- },
- };
- public owner = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.owner.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public addToken = {
- async sendTransactionAsync(
- _token: string,
- _name: string,
- _symbol: string,
- _decimals: number|BigNumber,
- _ipfsHash: string,
- _swarmHash: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.addToken.estimateGasAsync.bind(
- self,
- _token,
- _name,
- _symbol,
- _decimals,
- _ipfsHash,
- _swarmHash,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.addToken, self.web3ContractInstance,
- )(
- _token,
- _name,
- _symbol,
- _decimals,
- _ipfsHash,
- _swarmHash,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _token: string,
- _name: string,
- _symbol: string,
- _decimals: number|BigNumber,
- _ipfsHash: string,
- _swarmHash: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.addToken.estimateGas, self.web3ContractInstance,
- )(
- _token,
- _name,
- _symbol,
- _decimals,
- _ipfsHash,
- _swarmHash,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _token: string,
- _name: string,
- _symbol: string,
- _decimals: number|BigNumber,
- _ipfsHash: string,
- _swarmHash: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenRegistryContract;
- const abiEncodedTransactionData = self.web3ContractInstance.addToken.getData();
- return abiEncodedTransactionData;
- },
- };
- public setTokenName = {
- async sendTransactionAsync(
- _token: string,
- _name: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.setTokenName.estimateGasAsync.bind(
- self,
- _token,
- _name,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.setTokenName, self.web3ContractInstance,
- )(
- _token,
- _name,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _token: string,
- _name: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.setTokenName.estimateGas, self.web3ContractInstance,
- )(
- _token,
- _name,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _token: string,
- _name: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenRegistryContract;
- const abiEncodedTransactionData = self.web3ContractInstance.setTokenName.getData();
- return abiEncodedTransactionData;
- },
- };
- public tokens = {
- async callAsync(
- index: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<[string, string, string, BigNumber, string, string]
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<[string, string, string, BigNumber, string, string]
- >(
- self.web3ContractInstance.tokens.call,
- self.web3ContractInstance,
- )(
- index,
- );
- return result;
- },
- };
- public tokenAddresses = {
- async callAsync(
- index: BigNumber,
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.tokenAddresses.call,
- self.web3ContractInstance,
- )(
- index,
- );
- return result;
- },
- };
- public getTokenByName = {
- async callAsync(
- _name: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<[string, string, string, BigNumber, string, string]
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<[string, string, string, BigNumber, string, string]
- >(
- self.web3ContractInstance.getTokenByName.call,
- self.web3ContractInstance,
- )(
- _name,
- );
- return result;
- },
- };
- public getTokenAddresses = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string[]
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<string[]
- >(
- self.web3ContractInstance.getTokenAddresses.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public setTokenIpfsHash = {
- async sendTransactionAsync(
- _token: string,
- _ipfsHash: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.setTokenIpfsHash.estimateGasAsync.bind(
- self,
- _token,
- _ipfsHash,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.setTokenIpfsHash, self.web3ContractInstance,
- )(
- _token,
- _ipfsHash,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _token: string,
- _ipfsHash: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.setTokenIpfsHash.estimateGas, self.web3ContractInstance,
- )(
- _token,
- _ipfsHash,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _token: string,
- _ipfsHash: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenRegistryContract;
- const abiEncodedTransactionData = self.web3ContractInstance.setTokenIpfsHash.getData();
- return abiEncodedTransactionData;
- },
- };
- public getTokenBySymbol = {
- async callAsync(
- _symbol: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<[string, string, string, BigNumber, string, string]
- > {
- const self = this as TokenRegistryContract;
- const result = await promisify<[string, string, string, BigNumber, string, string]
- >(
- self.web3ContractInstance.getTokenBySymbol.call,
- self.web3ContractInstance,
- )(
- _symbol,
- );
- return result;
- },
- };
- public setTokenSymbol = {
- async sendTransactionAsync(
- _token: string,
- _symbol: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.setTokenSymbol.estimateGasAsync.bind(
- self,
- _token,
- _symbol,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.setTokenSymbol, self.web3ContractInstance,
- )(
- _token,
- _symbol,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- _token: string,
- _symbol: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.setTokenSymbol.estimateGas, self.web3ContractInstance,
- )(
- _token,
- _symbol,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- _token: string,
- _symbol: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenRegistryContract;
- const abiEncodedTransactionData = self.web3ContractInstance.setTokenSymbol.getData();
- return abiEncodedTransactionData;
- },
- };
- public transferOwnership = {
- async sendTransactionAsync(
- newOwner: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.transferOwnership.estimateGasAsync.bind(
- self,
- newOwner,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.transferOwnership, self.web3ContractInstance,
- )(
- newOwner,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- newOwner: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenRegistryContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.transferOwnership.estimateGas, self.web3ContractInstance,
- )(
- newOwner,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- newOwner: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenRegistryContract;
- const abiEncodedTransactionData = self.web3ContractInstance.transferOwnership.getData();
- return abiEncodedTransactionData;
- },
- };
- constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- super(web3ContractInstance, defaults);
- classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
- }
-} // tslint:disable:max-file-line-count
diff --git a/packages/0x.js/src/contract_wrappers/generated/token_transfer_proxy.ts b/packages/0x.js/src/contract_wrappers/generated/token_transfer_proxy.ts
deleted file mode 100644
index fd50a5894..000000000
--- a/packages/0x.js/src/contract_wrappers/generated/token_transfer_proxy.ts
+++ /dev/null
@@ -1,285 +0,0 @@
-/**
- * This file is auto-generated using abi-gen. Don't edit directly.
- * Templates can be found at https://github.com/0xProject/0x.js/tree/development/packages/abi-gen-templates.
- */
-import {promisify} from '@0xproject/utils';
-import {BigNumber} from 'bignumber.js';
-import * as Web3 from 'web3';
-
-import {TxData, TxDataPayable} from '../../types';
-import {classUtils} from '../../utils/class_utils';
-
-import {BaseContract} from './base_contract';
-
-export class TokenTransferProxyContract extends BaseContract {
- public transferFrom = {
- async sendTransactionAsync(
- token: string,
- from: string,
- to: string,
- value: BigNumber,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenTransferProxyContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.transferFrom.estimateGasAsync.bind(
- self,
- token,
- from,
- to,
- value,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.transferFrom, self.web3ContractInstance,
- )(
- token,
- from,
- to,
- value,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- token: string,
- from: string,
- to: string,
- value: BigNumber,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenTransferProxyContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.transferFrom.estimateGas, self.web3ContractInstance,
- )(
- token,
- from,
- to,
- value,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- token: string,
- from: string,
- to: string,
- value: BigNumber,
- txData: TxData = {},
- ): string {
- const self = this as TokenTransferProxyContract;
- const abiEncodedTransactionData = self.web3ContractInstance.transferFrom.getData();
- return abiEncodedTransactionData;
- },
- };
- public addAuthorizedAddress = {
- async sendTransactionAsync(
- target: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenTransferProxyContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.addAuthorizedAddress.estimateGasAsync.bind(
- self,
- target,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.addAuthorizedAddress, self.web3ContractInstance,
- )(
- target,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- target: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenTransferProxyContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.addAuthorizedAddress.estimateGas, self.web3ContractInstance,
- )(
- target,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- target: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenTransferProxyContract;
- const abiEncodedTransactionData = self.web3ContractInstance.addAuthorizedAddress.getData();
- return abiEncodedTransactionData;
- },
- };
- public authorities = {
- async callAsync(
- index: BigNumber,
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as TokenTransferProxyContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.authorities.call,
- self.web3ContractInstance,
- )(
- index,
- );
- return result;
- },
- };
- public removeAuthorizedAddress = {
- async sendTransactionAsync(
- target: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenTransferProxyContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.removeAuthorizedAddress.estimateGasAsync.bind(
- self,
- target,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.removeAuthorizedAddress, self.web3ContractInstance,
- )(
- target,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- target: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenTransferProxyContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.removeAuthorizedAddress.estimateGas, self.web3ContractInstance,
- )(
- target,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- target: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenTransferProxyContract;
- const abiEncodedTransactionData = self.web3ContractInstance.removeAuthorizedAddress.getData();
- return abiEncodedTransactionData;
- },
- };
- public owner = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string
- > {
- const self = this as TokenTransferProxyContract;
- const result = await promisify<string
- >(
- self.web3ContractInstance.owner.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public authorized = {
- async callAsync(
- index: string,
- defaultBlock?: Web3.BlockParam,
- ): Promise<boolean
- > {
- const self = this as TokenTransferProxyContract;
- const result = await promisify<boolean
- >(
- self.web3ContractInstance.authorized.call,
- self.web3ContractInstance,
- )(
- index,
- );
- return result;
- },
- };
- public getAuthorizedAddresses = {
- async callAsync(
- defaultBlock?: Web3.BlockParam,
- ): Promise<string[]
- > {
- const self = this as TokenTransferProxyContract;
- const result = await promisify<string[]
- >(
- self.web3ContractInstance.getAuthorizedAddresses.call,
- self.web3ContractInstance,
- )(
- );
- return result;
- },
- };
- public transferOwnership = {
- async sendTransactionAsync(
- newOwner: string,
- txData: TxData = {},
- ): Promise<string> {
- const self = this as TokenTransferProxyContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- self.transferOwnership.estimateGasAsync.bind(
- self,
- newOwner,
- ),
- );
- const txHash = await promisify<string>(
- self.web3ContractInstance.transferOwnership, self.web3ContractInstance,
- )(
- newOwner,
- txDataWithDefaults,
- );
- return txHash;
- },
- async estimateGasAsync(
- newOwner: string,
- txData: TxData = {},
- ): Promise<number> {
- const self = this as TokenTransferProxyContract;
- const txDataWithDefaults = await self.applyDefaultsToTxDataAsync(
- txData,
- );
- const gas = await promisify<number>(
- self.web3ContractInstance.transferOwnership.estimateGas, self.web3ContractInstance,
- )(
- newOwner,
- txDataWithDefaults,
- );
- return gas;
- },
- getABIEncodedTransactionData(
- newOwner: string,
- txData: TxData = {},
- ): string {
- const self = this as TokenTransferProxyContract;
- const abiEncodedTransactionData = self.web3ContractInstance.transferOwnership.getData();
- return abiEncodedTransactionData;
- },
- };
- constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- super(web3ContractInstance, defaults);
- classUtils.bindAll(this, ['web3ContractInstance', 'defaults']);
- }
-} // tslint:disable:max-file-line-count
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 064b826d8..f54aaf0f8 100644
--- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
@@ -1,13 +1,13 @@
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
-import {artifacts} from '../artifacts';
-import {Token, TokenMetadata, ZeroExError} from '../types';
-import {assert} from '../utils/assert';
-import {constants} from '../utils/constants';
+import { artifacts } from '../artifacts';
+import { Token, TokenMetadata } from '../types';
+import { assert } from '../utils/assert';
+import { constants } from '../utils/constants';
-import {ContractWrapper} from './contract_wrapper';
-import {TokenRegistryContract} from './generated/token_registry';
+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.
@@ -15,7 +15,7 @@ import {TokenRegistryContract} from './generated/token_registry';
export class TokenRegistryWrapper extends ContractWrapper {
private _tokenRegistryContractIfExists?: TokenRegistryContract;
private _contractAddressIfExists?: string;
- private static _createTokenFromMetadata(metadata: TokenMetadata): Token|undefined {
+ private static _createTokenFromMetadata(metadata: TokenMetadata): Token | undefined {
if (metadata[0] === constants.NULL_ADDRESS) {
return undefined;
}
@@ -36,12 +36,9 @@ export class TokenRegistryWrapper extends ContractWrapper {
* @return An array of objects that conform to the Token interface.
*/
public async getTokensAsync(): Promise<Token[]> {
- const tokenRegistryContract = await this._getTokenRegistryContractAsync();
-
const addresses = await this.getTokenAddressesAsync();
- const tokenPromises: Array<Promise<Token|undefined>> = _.map(
- addresses,
- async (address: string) => this.getTokenIfExistsAsync(address),
+ const tokenPromises: Array<Promise<Token | undefined>> = _.map(addresses, async (address: string) =>
+ this.getTokenIfExistsAsync(address),
);
const tokens = await Promise.all(tokenPromises);
return tokens as Token[];
@@ -59,7 +56,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
* Retrieves a token by address currently listed in the Token Registry smart contract
* @return An object that conforms to the Token interface or undefined if token not found.
*/
- public async getTokenIfExistsAsync(address: string): Promise<Token|undefined> {
+ public async getTokenIfExistsAsync(address: string): Promise<Token | undefined> {
assert.isETHAddressHex('address', address);
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
@@ -67,7 +64,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
const token = TokenRegistryWrapper._createTokenFromMetadata(metadata);
return token;
}
- public async getTokenAddressBySymbolIfExistsAsync(symbol: string): Promise<string|undefined> {
+ public async getTokenAddressBySymbolIfExistsAsync(symbol: string): Promise<string | undefined> {
assert.isString('symbol', symbol);
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const addressIfExists = await tokenRegistryContract.getTokenAddressBySymbol.callAsync(symbol);
@@ -76,7 +73,7 @@ export class TokenRegistryWrapper extends ContractWrapper {
}
return addressIfExists;
}
- public async getTokenAddressByNameIfExistsAsync(name: string): Promise<string|undefined> {
+ public async getTokenAddressByNameIfExistsAsync(name: string): Promise<string | undefined> {
assert.isString('name', name);
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const addressIfExists = await tokenRegistryContract.getTokenAddressByName.callAsync(name);
@@ -85,14 +82,14 @@ export class TokenRegistryWrapper extends ContractWrapper {
}
return addressIfExists;
}
- public async getTokenBySymbolIfExistsAsync(symbol: string): Promise<Token|undefined> {
+ public async getTokenBySymbolIfExistsAsync(symbol: string): Promise<Token | undefined> {
assert.isString('symbol', symbol);
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const metadata = await tokenRegistryContract.getTokenBySymbol.callAsync(symbol);
const token = TokenRegistryWrapper._createTokenFromMetadata(metadata);
return token;
}
- public async getTokenByNameIfExistsAsync(name: string): Promise<Token|undefined> {
+ public async getTokenByNameIfExistsAsync(name: string): Promise<Token | undefined> {
assert.isString('name', name);
const tokenRegistryContract = await this._getTokenRegistryContractAsync();
const metadata = await tokenRegistryContract.getTokenByName.callAsync(name);
@@ -106,7 +103,8 @@ export class TokenRegistryWrapper extends ContractWrapper {
*/
public getContractAddress(): string {
const contractAddress = this._getContractAddress(
- artifacts.TokenRegistryArtifact, this._contractAddressIfExists,
+ artifacts.TokenRegistryArtifact,
+ this._contractAddressIfExists,
);
return contractAddress;
}
@@ -118,10 +116,12 @@ export class TokenRegistryWrapper extends ContractWrapper {
return this._tokenRegistryContractIfExists;
}
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
- artifacts.TokenRegistryArtifact, this._contractAddressIfExists,
+ artifacts.TokenRegistryArtifact,
+ this._contractAddressIfExists,
);
const contractInstance = new TokenRegistryContract(
- web3ContractInstance, this._web3Wrapper.getContractDefaults(),
+ 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 1a16e3540..f5d9d108a 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,11 +1,10 @@
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
-import {artifacts} from '../artifacts';
-import {ZeroExError} from '../types';
+import { artifacts } from '../artifacts';
-import {ContractWrapper} from './contract_wrapper';
-import {TokenTransferProxyContract} from './generated/token_transfer_proxy';
+import { ContractWrapper } from './contract_wrapper';
+import { TokenTransferProxyContract } from './generated/token_transfer_proxy';
/**
* This class includes the functionality related to interacting with the TokenTransferProxy contract.
@@ -43,7 +42,8 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
*/
public getContractAddress(): string {
const contractAddress = this._getContractAddress(
- artifacts.TokenTransferProxyArtifact, this._contractAddressIfExists,
+ artifacts.TokenTransferProxyArtifact,
+ this._contractAddressIfExists,
);
return contractAddress;
}
@@ -55,10 +55,12 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
return this._tokenTransferProxyContractIfExists;
}
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
- artifacts.TokenTransferProxyArtifact, this._contractAddressIfExists,
+ artifacts.TokenTransferProxyArtifact,
+ this._contractAddressIfExists,
);
const contractInstance = new TokenTransferProxyContract(
- web3ContractInstance, this._web3Wrapper.getContractDefaults(),
+ 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 684f291a5..7943f4a60 100644
--- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
@@ -1,29 +1,27 @@
-import {schemas} from '@0xproject/json-schemas';
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
-import BigNumber from 'bignumber.js';
+import { schemas } from '@0xproject/json-schemas';
+import { BigNumber } from '@0xproject/utils';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
-import {artifacts} from '../artifacts';
+import { artifacts } from '../artifacts';
import {
+ BlockRange,
EventCallback,
IndexedFilterValues,
LogWithDecodedArgs,
MethodOpts,
- SubscriptionOpts,
TokenContractEventArgs,
TokenEvents,
TransactionOpts,
ZeroExError,
} from '../types';
-import {AbiDecoder} from '../utils/abi_decoder';
-import {assert} from '../utils/assert';
-import {constants} from '../utils/constants';
+import { AbiDecoder } from '../utils/abi_decoder';
+import { assert } from '../utils/assert';
+import { constants } from '../utils/constants';
-import {ContractWrapper} from './contract_wrapper';
-import {TokenContract} from './generated/token';
-import {TokenTransferProxyWrapper} from './token_transfer_proxy_wrapper';
-
-const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 47275;
+import { ContractWrapper } from './contract_wrapper';
+import { TokenContract } from './generated/token';
+import { TokenTransferProxyWrapper } from './token_transfer_proxy_wrapper';
/**
* This class includes all the functionality related to interacting with ERC20 token contracts.
@@ -32,10 +30,14 @@ const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 47275;
*/
export class TokenWrapper extends ContractWrapper {
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
- private _tokenContractsByAddress: {[address: string]: TokenContract};
+ private _tokenContractsByAddress: { [address: string]: TokenContract };
private _tokenTransferProxyWrapper: TokenTransferProxyWrapper;
- constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder,
- tokenTransferProxyWrapper: TokenTransferProxyWrapper) {
+ constructor(
+ web3Wrapper: Web3Wrapper,
+ networkId: number,
+ abiDecoder: AbiDecoder,
+ tokenTransferProxyWrapper: TokenTransferProxyWrapper,
+ ) {
super(web3Wrapper, networkId, abiDecoder);
this._tokenContractsByAddress = {};
this._tokenTransferProxyWrapper = tokenTransferProxyWrapper;
@@ -47,8 +49,11 @@ export class TokenWrapper extends ContractWrapper {
* @param methodOpts Optional arguments this method accepts.
* @return The owner's ERC20 token balance in base units.
*/
- public async getBalanceAsync(tokenAddress: string, ownerAddress: string,
- methodOpts?: MethodOpts): Promise<BigNumber> {
+ public async getBalanceAsync(
+ tokenAddress: string,
+ ownerAddress: string,
+ methodOpts?: MethodOpts,
+ ): Promise<BigNumber> {
assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
@@ -70,8 +75,13 @@ export class TokenWrapper extends ContractWrapper {
* @param txOpts Transaction parameters.
* @return Transaction hash.
*/
- public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string,
- amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}): Promise<string> {
+ public async setAllowanceAsync(
+ tokenAddress: string,
+ ownerAddress: string,
+ spenderAddress: string,
+ amountInBaseUnits: BigNumber,
+ txOpts: TransactionOpts = {},
+ ): Promise<string> {
await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper);
assert.isETHAddressHex('spenderAddress', spenderAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
@@ -97,10 +107,18 @@ export class TokenWrapper extends ContractWrapper {
* @param txOpts Transaction parameters.
* @return Transaction hash.
*/
- public async setUnlimitedAllowanceAsync(tokenAddress: string, ownerAddress: string,
- spenderAddress: string, txOpts: TransactionOpts = {}): Promise<string> {
+ public async setUnlimitedAllowanceAsync(
+ tokenAddress: string,
+ ownerAddress: string,
+ spenderAddress: string,
+ txOpts: TransactionOpts = {},
+ ): Promise<string> {
const txHash = await this.setAllowanceAsync(
- tokenAddress, ownerAddress, spenderAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS, txOpts,
+ tokenAddress,
+ ownerAddress,
+ spenderAddress,
+ this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
+ txOpts,
);
return txHash;
}
@@ -112,8 +130,12 @@ export class TokenWrapper extends ContractWrapper {
* @param spenderAddress The hex encoded user Ethereum address who can spend the allowance you are fetching.
* @param methodOpts Optional arguments this method accepts.
*/
- public async getAllowanceAsync(tokenAddress: string, ownerAddress: string,
- spenderAddress: string, methodOpts?: MethodOpts): Promise<BigNumber> {
+ public async getAllowanceAsync(
+ tokenAddress: string,
+ ownerAddress: string,
+ spenderAddress: string,
+ methodOpts?: MethodOpts,
+ ): Promise<BigNumber> {
assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
@@ -130,8 +152,11 @@ export class TokenWrapper extends ContractWrapper {
* @param ownerAddress The hex encoded user Ethereum address whose proxy contract allowance we are retrieving.
* @param methodOpts Optional arguments this method accepts.
*/
- public async getProxyAllowanceAsync(tokenAddress: string, ownerAddress: string,
- methodOpts?: MethodOpts): Promise<BigNumber> {
+ public async getProxyAllowanceAsync(
+ tokenAddress: string,
+ ownerAddress: string,
+ methodOpts?: MethodOpts,
+ ): Promise<BigNumber> {
assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
@@ -149,15 +174,23 @@ export class TokenWrapper extends ContractWrapper {
* @param txOpts Transaction parameters.
* @return Transaction hash.
*/
- public async setProxyAllowanceAsync(tokenAddress: string, ownerAddress: string,
- amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}): Promise<string> {
+ public async setProxyAllowanceAsync(
+ tokenAddress: string,
+ ownerAddress: string,
+ amountInBaseUnits: BigNumber,
+ txOpts: TransactionOpts = {},
+ ): Promise<string> {
assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isValidBaseUnitAmount('amountInBaseUnits', amountInBaseUnits);
const proxyAddress = this._tokenTransferProxyWrapper.getContractAddress();
const txHash = await this.setAllowanceAsync(
- tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits, txOpts,
+ tokenAddress,
+ ownerAddress,
+ proxyAddress,
+ amountInBaseUnits,
+ txOpts,
);
return txHash;
}
@@ -173,10 +206,15 @@ export class TokenWrapper extends ContractWrapper {
* @return Transaction hash.
*/
public async setUnlimitedProxyAllowanceAsync(
- tokenAddress: string, ownerAddress: string, txOpts: TransactionOpts = {},
+ tokenAddress: string,
+ ownerAddress: string,
+ txOpts: TransactionOpts = {},
): Promise<string> {
const txHash = await this.setProxyAllowanceAsync(
- tokenAddress, ownerAddress, this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS, txOpts,
+ tokenAddress,
+ ownerAddress,
+ this.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
+ txOpts,
);
return txHash;
}
@@ -189,8 +227,13 @@ export class TokenWrapper extends ContractWrapper {
* @param txOpts Transaction parameters.
* @return Transaction hash.
*/
- public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string,
- amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}): Promise<string> {
+ public async transferAsync(
+ tokenAddress: string,
+ fromAddress: string,
+ toAddress: string,
+ amountInBaseUnits: BigNumber,
+ txOpts: TransactionOpts = {},
+ ): Promise<string> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper);
assert.isETHAddressHex('toAddress', toAddress);
@@ -224,9 +267,14 @@ export class TokenWrapper extends ContractWrapper {
* @param txOpts Transaction parameters.
* @return Transaction hash.
*/
- public async transferFromAsync(tokenAddress: string, fromAddress: string, toAddress: string,
- senderAddress: string, amountInBaseUnits: BigNumber, txOpts: TransactionOpts = {}):
- Promise<string> {
+ public async transferFromAsync(
+ tokenAddress: string,
+ fromAddress: string,
+ toAddress: string,
+ senderAddress: string,
+ amountInBaseUnits: BigNumber,
+ txOpts: TransactionOpts = {},
+ ): Promise<string> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isETHAddressHex('fromAddress', fromAddress);
assert.isETHAddressHex('toAddress', toAddress);
@@ -246,7 +294,9 @@ export class TokenWrapper extends ContractWrapper {
}
const txHash = await tokenContract.transferFrom.sendTransactionAsync(
- fromAddress, toAddress, amountInBaseUnits,
+ fromAddress,
+ toAddress,
+ amountInBaseUnits,
{
from: senderAddress,
gas: txOpts.gasLimit,
@@ -265,14 +315,21 @@ export class TokenWrapper extends ContractWrapper {
* @return Subscription token used later to unsubscribe
*/
public subscribe<ArgsType extends TokenContractEventArgs>(
- tokenAddress: string, eventName: TokenEvents, indexFilterValues: IndexedFilterValues,
- callback: EventCallback<ArgsType>): string {
+ tokenAddress: string,
+ eventName: TokenEvents,
+ indexFilterValues: IndexedFilterValues,
+ callback: EventCallback<ArgsType>,
+ ): string {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.doesBelongToStringEnum('eventName', eventName, TokenEvents);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
assert.isFunction('callback', callback);
const subscriptionToken = this._subscribe<ArgsType>(
- tokenAddress, eventName, indexFilterValues, artifacts.TokenArtifact.abi, callback,
+ tokenAddress,
+ eventName,
+ indexFilterValues,
+ artifacts.TokenArtifact.abi,
+ callback,
);
return subscriptionToken;
}
@@ -284,23 +341,36 @@ export class TokenWrapper extends ContractWrapper {
this._unsubscribe(subscriptionToken);
}
/**
+ * Cancels all existing subscriptions
+ */
+ public unsubscribeAll(): void {
+ super.unsubscribeAll();
+ }
+ /**
* Gets historical logs without creating a subscription
* @param tokenAddress An address of the token that emmited the logs.
* @param eventName The token contract event you would like to subscribe to.
- * @param subscriptionOpts Subscriptions options that let you configure the subscription.
+ * @param blockRange Block range to get logs from.
* @param indexFilterValues An object where the keys are indexed args returned by the event and
* 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 TokenContractEventArgs>(
- tokenAddress: string, eventName: TokenEvents, subscriptionOpts: SubscriptionOpts,
- indexFilterValues: IndexedFilterValues): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
+ tokenAddress: string,
+ eventName: TokenEvents,
+ blockRange: BlockRange,
+ indexFilterValues: IndexedFilterValues,
+ ): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.doesBelongToStringEnum('eventName', eventName, TokenEvents);
- assert.doesConformToSchema('subscriptionOpts', subscriptionOpts, schemas.subscriptionOptsSchema);
+ assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const logs = await this._getLogsAsync<ArgsType>(
- tokenAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.TokenArtifact.abi,
+ tokenAddress,
+ eventName,
+ blockRange,
+ indexFilterValues,
+ artifacts.TokenArtifact.abi,
);
return logs;
}
@@ -314,11 +384,10 @@ export class TokenWrapper extends ContractWrapper {
return tokenContract;
}
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
- artifacts.TokenArtifact, tokenAddress,
- );
- const contractInstance = new TokenContract(
- web3ContractInstance, this._web3Wrapper.getContractDefaults(),
+ artifacts.TokenArtifact,
+ tokenAddress,
);
+ const contractInstance = new TokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
tokenContract = contractInstance;
this._tokenContractsByAddress[tokenAddress] = tokenContract;
return tokenContract;