aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/contract_wrappers
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-12-22 22:05:32 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-01-03 18:37:38 +0800
commite744e4cd989bd3ae1070c59f7baa8097f18b8b06 (patch)
treea7fde03873f3c1b8689d3991edbb362f8022e5f0 /packages/0x.js/src/contract_wrappers
parent9a96e8c704b6f84e00bbe848159a4819844cf09d (diff)
downloaddexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.gz
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.bz2
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.lz
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.xz
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.tar.zst
dexon-sol-tools-e744e4cd989bd3ae1070c59f7baa8097f18b8b06.zip
Apply prettier config
Diffstat (limited to 'packages/0x.js/src/contract_wrappers')
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts59
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts59
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts339
-rw-r--r--packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts40
-rw-r--r--packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts17
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts153
6 files changed, 437 insertions, 230 deletions
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
index 3f07e4e47..eb7e042e7 100644
--- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
@@ -1,6 +1,6 @@
-import {intervalUtils} from '@0xproject/utils';
-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';
@@ -17,11 +17,13 @@ import {
RawLog,
ZeroExError,
} from '../types';
-import {AbiDecoder} from '../utils/abi_decoder';
-import {constants} from '../utils/constants';
-import {filterUtils} from '../utils/filter_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,12 +36,14 @@ export class ContractWrapper {
protected _web3Wrapper: Web3Wrapper;
private _networkId: number;
private _abiDecoder?: AbiDecoder;
- private _blockAndLogStreamerIfExists: 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;
@@ -71,8 +75,12 @@ 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._blockAndLogStreamerIfExists)) {
this._startBlockAndLogStream();
@@ -83,15 +91,20 @@ export class ContractWrapper {
return filterToken;
}
protected async _getLogsAsync<ArgsType extends ContractEventArgs>(
- address: string, eventName: ContractEvents, blockRange: BlockRange,
- indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
+ 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);
}
@@ -99,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)) {
@@ -114,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 {
@@ -153,7 +165,8 @@ export class ContractWrapper {
const 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,
);
let isRemoved = false;
this._onLogAddedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogAdded(
@@ -179,7 +192,7 @@ export class ContractWrapper {
// 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);
+ await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlock as any) as Block);
}
} catch (err) {
const filterTokens = _.keys(this._filterCallbacks);
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 969f30463..09719b2d8 100644
--- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
@@ -1,9 +1,9 @@
-import {schemas} from '@0xproject/json-schemas';
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
+import { schemas } from '@0xproject/json-schemas';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import BigNumber from 'bignumber.js';
import * as _ from 'lodash';
-import {artifacts} from '../artifacts';
+import { artifacts } from '../artifacts';
import {
BlockRange,
EtherTokenContractEventArgs,
@@ -14,19 +14,21 @@ import {
TransactionOpts,
ZeroExError,
} from '../types';
-import {AbiDecoder} from '../utils/abi_decoder';
-import {assert} from '../utils/assert';
+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 _etherTokenContractsByAddress: {[address: string]: EtherTokenContract} = {};
+ private _etherTokenContractsByAddress: {
+ [address: string]: EtherTokenContract;
+ } = {};
private _tokenWrapper: TokenWrapper;
constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder, tokenWrapper: TokenWrapper) {
super(web3Wrapper, networkId, abiDecoder);
@@ -43,7 +45,10 @@ export class EtherTokenWrapper extends ContractWrapper {
* @return Transaction hash.
*/
public async depositAsync(
- etherTokenAddress: string, 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);
@@ -70,7 +75,10 @@ export class EtherTokenWrapper extends ContractWrapper {
* @return Transaction hash.
*/
public async withdrawAsync(
- etherTokenAddress: string, 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);
@@ -96,14 +104,21 @@ export class EtherTokenWrapper extends ContractWrapper {
* @return Array of logs that match the parameters
*/
public async getLogsAsync<ArgsType extends EtherTokenContractEventArgs>(
- etherTokenAddress: string, eventName: EtherTokenEvents, blockRange: BlockRange,
- indexFilterValues: IndexedFilterValues): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
+ 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,
+ etherTokenAddress,
+ eventName,
+ blockRange,
+ indexFilterValues,
+ artifacts.EtherTokenArtifact.abi,
);
return logs;
}
@@ -117,14 +132,21 @@ export class EtherTokenWrapper extends ContractWrapper {
* @return Subscription token used later to unsubscribe
*/
public subscribe<ArgsType extends EtherTokenContractEventArgs>(
- etherTokenAddress: string, eventName: EtherTokenEvents, indexFilterValues: IndexedFilterValues,
- callback: EventCallback<ArgsType>): string {
+ 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,
+ etherTokenAddress,
+ eventName,
+ indexFilterValues,
+ artifacts.EtherTokenArtifact.abi,
+ callback,
);
return subscriptionToken;
}
@@ -151,7 +173,8 @@ export class EtherTokenWrapper extends ContractWrapper {
return etherTokenContract;
}
const web3ContractInstance = await this._instantiateContractIfExistsAsync(
- artifacts.EtherTokenArtifact, etherTokenAddress,
+ artifacts.EtherTokenArtifact,
+ etherTokenAddress,
);
const contractInstance = new EtherTokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
etherTokenContract = contractInstance;
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 70d2be7e9..a111128ba 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -1,10 +1,10 @@
-import {schemas} from '@0xproject/json-schemas';
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
+import { schemas } from '@0xproject/json-schemas';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import BigNumber from 'bignumber.js';
import * as _ from 'lodash';
import * as Web3 from 'web3';
-import {artifacts} from '../artifacts';
+import { artifacts } from '../artifacts';
import {
BlockParamLiteral,
BlockRange,
@@ -28,16 +28,16 @@ import {
SignedOrder,
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;
@@ -81,8 +81,13 @@ 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,
+ ) {
super(web3Wrapper, networkId, abiDecoder);
this._tokenWrapper = tokenWrapper;
this._orderValidationUtils = new OrderValidationUtils(this);
@@ -97,14 +102,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);
@@ -163,24 +168,32 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Transaction hash.
*/
@decorators.asyncZeroExErrorHandler
- public async fillOrderAsync(signedOrder: SignedOrder, fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ 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);
@@ -219,30 +232,42 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Transaction hash.
*/
@decorators.asyncZeroExErrorHandler
- public async fillOrdersUpToAsync(signedOrders: SignedOrder[], fillTakerTokenAmount: BigNumber,
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ 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) {
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);
+ exchangeTradeEmulator,
+ signedOrder,
+ fillTakerTokenAmount,
+ takerAddress,
+ zrxTokenAddress,
+ );
}
}
@@ -300,29 +325,36 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Transaction hash.
*/
@decorators.asyncZeroExErrorHandler
- public async batchFillOrdersAsync(orderFillRequests: OrderFillRequest[],
- shouldThrowOnInsufficientBalanceOrAllowance: boolean,
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ 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,
);
}
}
@@ -373,23 +405,31 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Transaction hash.
*/
@decorators.asyncZeroExErrorHandler
- public async fillOrKillOrderAsync(signedOrder: SignedOrder, fillTakerTokenAmount: BigNumber,
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ 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);
@@ -418,33 +458,39 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Transaction hash.
*/
@decorators.asyncZeroExErrorHandler
- public async batchFillOrKillAsync(orderFillRequests: OrderFillRequest[],
- takerAddress: string,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
- assert.doesConformToSchema('orderFillRequests', orderFillRequests,
- schemas.orderFillRequestsSchema);
+ 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,
);
}
}
@@ -460,8 +506,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,
@@ -486,23 +533,28 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Transaction hash.
*/
@decorators.asyncZeroExErrorHandler
- public async cancelOrderAsync(order: Order|SignedOrder,
- cancelTakerTokenAmount: BigNumber,
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
+ 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);
@@ -527,33 +579,40 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Transaction hash.
*/
@decorators.asyncZeroExErrorHandler
- public async batchCancelOrdersAsync(orderCancellationRequests: OrderCancellationRequest[],
- orderTransactionOpts: OrderTransactionOpts = {}): Promise<string> {
- assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests,
- schemas.orderCancellationRequestsSchema);
+ 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);
@@ -566,8 +625,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,
@@ -589,14 +649,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;
}
@@ -622,14 +688,20 @@ export class ExchangeWrapper extends ContractWrapper {
* @return Array of logs that match the parameters
*/
public async getLogsAsync<ArgsType extends ExchangeContractEventArgs>(
- eventName: ExchangeEvents, blockRange: BlockRange, indexFilterValues: IndexedFilterValues,
+ eventName: ExchangeEvents,
+ blockRange: BlockRange,
+ indexFilterValues: IndexedFilterValues,
): Promise<Array<LogWithDecodedArgs<ArgsType>>> {
assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents);
assert.doesConformToSchema('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const exchangeContractAddress = this.getContractAddress();
const logs = await this._getLogsAsync<ArgsType>(
- exchangeContractAddress, eventName, blockRange, indexFilterValues, artifacts.ExchangeArtifact.abi,
+ exchangeContractAddress,
+ eventName,
+ blockRange,
+ indexFilterValues,
+ artifacts.ExchangeArtifact.abi,
);
return logs;
}
@@ -652,14 +724,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,
);
}
/**
@@ -670,16 +746,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.
@@ -688,13 +771,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.
@@ -704,16 +792,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:
@@ -724,15 +819,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;
}
@@ -740,10 +839,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();
@@ -756,17 +855,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);
@@ -782,7 +882,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);
@@ -793,7 +893,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/token_registry_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
index 69e9d7e21..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} 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;
}
@@ -37,9 +37,8 @@ export class TokenRegistryWrapper extends ContractWrapper {
*/
public async getTokensAsync(): Promise<Token[]> {
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[];
@@ -57,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();
@@ -65,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);
@@ -74,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);
@@ -83,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);
@@ -104,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;
}
@@ -116,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 c67ef87df..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,10 +1,10 @@
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
-import {artifacts} from '../artifacts';
+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.
@@ -42,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;
}
@@ -54,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 a9eac10e0..bfa7da5b4 100644
--- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
@@ -1,9 +1,9 @@
-import {schemas} from '@0xproject/json-schemas';
-import {Web3Wrapper} from '@0xproject/web3-wrapper';
+import { schemas } from '@0xproject/json-schemas';
+import { Web3Wrapper } from '@0xproject/web3-wrapper';
import BigNumber from 'bignumber.js';
import * as _ from 'lodash';
-import {artifacts} from '../artifacts';
+import { artifacts } from '../artifacts';
import {
BlockRange,
EventCallback,
@@ -15,13 +15,13 @@ import {
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';
+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.
@@ -30,10 +30,14 @@ import {TokenTransferProxyWrapper} from './token_transfer_proxy_wrapper';
*/
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;
@@ -45,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);
@@ -68,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);
@@ -95,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;
}
@@ -110,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);
@@ -128,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);
@@ -147,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;
}
@@ -171,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;
}
@@ -187,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);
@@ -222,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);
@@ -244,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,
@@ -263,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;
}
@@ -297,14 +356,21 @@ export class TokenWrapper extends ContractWrapper {
* @return Array of logs that match the parameters
*/
public async getLogsAsync<ArgsType extends TokenContractEventArgs>(
- tokenAddress: string, eventName: TokenEvents, blockRange: BlockRange,
- 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('blockRange', blockRange, schemas.blockRangeSchema);
assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema);
const logs = await this._getLogsAsync<ArgsType>(
- tokenAddress, eventName, blockRange, indexFilterValues, artifacts.TokenArtifact.abi,
+ tokenAddress,
+ eventName,
+ blockRange,
+ indexFilterValues,
+ artifacts.TokenArtifact.abi,
);
return logs;
}
@@ -318,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;