diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/0x.ts | 6 | ||||
-rw-r--r-- | src/contract_wrappers/contract_wrapper.ts | 15 | ||||
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 48 | ||||
-rw-r--r-- | src/contract_wrappers/token_registry_wrapper.ts | 9 | ||||
-rw-r--r-- | src/contract_wrappers/token_wrapper.ts | 8 | ||||
-rw-r--r-- | src/types.ts | 4 | ||||
-rw-r--r-- | src/utils/assert.ts | 24 | ||||
-rw-r--r-- | src/utils/decorators.ts | 6 | ||||
-rw-r--r-- | src/utils/utils.ts | 9 | ||||
-rw-r--r-- | src/web3_wrapper.ts | 4 |
10 files changed, 60 insertions, 73 deletions
@@ -1,4 +1,4 @@ -import isUndefined = require('lodash/isUndefined'); +import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; import {bigNumberConfigs} from './bignumber_config'; import * as ethUtil from 'ethereumjs-util'; @@ -239,10 +239,10 @@ export class ZeroEx { } private async _getExchangeAddressAsync() { const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); - const exchangeNetworkConfigsIfExists = isUndefined(networkIdIfExists) ? + const exchangeNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : (ExchangeArtifacts as any).networks[networkIdIfExists]; - if (isUndefined(exchangeNetworkConfigsIfExists)) { + if (_.isUndefined(exchangeNetworkConfigsIfExists)) { throw new Error(ZeroExError.CONTRACT_NOT_DEPLOYED_ON_NETWORK); } const exchangeAddress = exchangeNetworkConfigsIfExists.address; diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts index f5d2cd4eb..f9c1bc1cf 100644 --- a/src/contract_wrappers/contract_wrapper.ts +++ b/src/contract_wrappers/contract_wrapper.ts @@ -1,5 +1,4 @@ -import includes = require('lodash/includes'); -import isUndefined = require('lodash/isUndefined'); +import * as _ from 'lodash'; import contract = require('truffle-contract'); import {Web3Wrapper} from '../web3_wrapper'; import {ZeroExError, Artifact, ContractInstance} from '../types'; @@ -16,17 +15,17 @@ export class ContractWrapper { c.setProvider(providerObj); const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); - const artifactNetworkConfigs = isUndefined(networkIdIfExists) ? + const artifactNetworkConfigs = _.isUndefined(networkIdIfExists) ? undefined : artifact.networks[networkIdIfExists]; let contractAddress; - if (!isUndefined(address)) { + if (!_.isUndefined(address)) { contractAddress = address; - } else if (!isUndefined(artifactNetworkConfigs)) { + } else if (!_.isUndefined(artifactNetworkConfigs)) { contractAddress = artifactNetworkConfigs.address; } - if (!isUndefined(contractAddress)) { + if (!_.isUndefined(contractAddress)) { const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress); if (!doesContractExist) { throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST); @@ -34,11 +33,11 @@ export class ContractWrapper { } try { - const contractInstance = isUndefined(address) ? await c.deployed() : await c.at(address); + const contractInstance = _.isUndefined(address) ? await c.deployed() : await c.at(address); return contractInstance; } catch (err) { const errMsg = `${err}`; - if (includes(errMsg, 'not been deployed to detected network')) { + if (_.includes(errMsg, 'not been deployed to detected network')) { throw new Error(ZeroExError.CONTRACT_DOES_NOT_EXIST); } else { utils.consoleLog(`Notice: Error encountered: ${err} ${err.stack}`); diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 6d42dc110..e33dd6f6e 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -1,8 +1,4 @@ -import map = require('lodash/map'); -import isEmpty = require('lodash/isEmpty'); -import find = require('lodash/find'); -import isUndefined = require('lodash/isUndefined'); -import unzip = require('lodash/unzip'); +import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); import {Web3Wrapper} from '../web3_wrapper'; @@ -202,7 +198,7 @@ export class ExchangeWrapper extends ContractWrapper { @decorators.contractCallErrorHandler public async fillOrdersUpToAsync(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber.BigNumber, shouldCheckTransfer: boolean, takerAddress: string): Promise<void> { - const takerTokenAddresses = map(signedOrders, signedOrder => signedOrder.takerTokenAddress); + const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress); assert.hasAtMostOneUniqueValue(takerTokenAddresses, ExchangeContractErrs.MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED); assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); @@ -213,11 +209,11 @@ export class ExchangeWrapper extends ContractWrapper { await this._validateFillOrderAndThrowIfInvalidAsync( signedOrder, takerTokenFillAmount, takerAddress); } - if (isEmpty(signedOrders)) { + if (_.isEmpty(signedOrders)) { return; // no-op } - const orderAddressesValuesAndSignatureArray = map(signedOrders, signedOrder => { + const orderAddressesValuesAndSignatureArray = _.map(signedOrders, signedOrder => { return [ ...ExchangeWrapper._getOrderAddressesAndValues(signedOrder), signedOrder.ecSignature.v, @@ -225,8 +221,8 @@ export class ExchangeWrapper extends ContractWrapper { signedOrder.ecSignature.s, ]; }); - // We use unzip<any> because unzip doesn't type check if values have different types :'( - const [orderAddressesArray, orderValuesArray, vArray, rArray, sArray] = unzip<any>( + // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( + const [orderAddressesArray, orderValuesArray, vArray, rArray, sArray] = _.unzip<any>( orderAddressesValuesAndSignatureArray, ); @@ -281,11 +277,11 @@ export class ExchangeWrapper extends ContractWrapper { await this._validateFillOrderAndThrowIfInvalidAsync( orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress); } - if (isEmpty(orderFillRequests)) { + if (_.isEmpty(orderFillRequests)) { return; // no-op } - const orderAddressesValuesAmountsAndSignatureArray = map(orderFillRequests, orderFillRequest => { + const orderAddressesValuesAmountsAndSignatureArray = _.map(orderFillRequests, orderFillRequest => { return [ ...ExchangeWrapper._getOrderAddressesAndValues(orderFillRequest.signedOrder), orderFillRequest.takerTokenFillAmount, @@ -294,8 +290,8 @@ export class ExchangeWrapper extends ContractWrapper { orderFillRequest.signedOrder.ecSignature.s, ]; }); - // We use unzip<any> because unzip doesn't type check if values have different types :'( - const [orderAddressesArray, orderValuesArray, takerTokenFillAmountArray, vArray, rArray, sArray] = unzip<any>( + // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( + const [orderAddressesArray, orderValuesArray, takerTokenFillAmountArray, vArray, rArray, sArray] = _.unzip<any>( orderAddressesValuesAmountsAndSignatureArray, ); @@ -394,7 +390,7 @@ export class ExchangeWrapper extends ContractWrapper { request.fillTakerAmount); } - const orderAddressesValuesAndTakerTokenFillAmounts = map(orderFillOrKillRequests, request => { + const orderAddressesValuesAndTakerTokenFillAmounts = _.map(orderFillOrKillRequests, request => { return [ ...ExchangeWrapper._getOrderAddressesAndValues(request.signedOrder), request.fillTakerAmount, @@ -404,9 +400,9 @@ export class ExchangeWrapper extends ContractWrapper { ]; }); - // We use unzip<any> because unzip doesn't type check if values have different types :'( + // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( const [orderAddresses, orderValues, fillTakerAmounts, vParams, rParams, sParams] = - unzip<any>(orderAddressesValuesAndTakerTokenFillAmounts); + _.unzip<any>(orderAddressesValuesAndTakerTokenFillAmounts); const gas = await exchangeInstance.batchFillOrKill.estimateGas( orderAddresses, @@ -477,7 +473,7 @@ export class ExchangeWrapper extends ContractWrapper { */ @decorators.contractCallErrorHandler public async batchCancelOrderAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise<void> { - const makers = map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker); + const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker); assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED); const maker = makers[0]; await assert.isSenderAddressAsync('maker', maker, this._web3Wrapper); @@ -488,19 +484,19 @@ export class ExchangeWrapper extends ContractWrapper { cancellationRequest.order, cancellationRequest.takerTokenCancelAmount, ); } - if (isEmpty(orderCancellationRequests)) { + if (_.isEmpty(orderCancellationRequests)) { return; // no-op } const exchangeInstance = await this._getExchangeContractAsync(); - const orderAddressesValuesAndTakerTokenCancelAmounts = map(orderCancellationRequests, cancellationRequest => { + const orderAddressesValuesAndTakerTokenCancelAmounts = _.map(orderCancellationRequests, cancellationRequest => { return [ ...ExchangeWrapper._getOrderAddressesAndValues(cancellationRequest.order), cancellationRequest.takerTokenCancelAmount, ]; }); - // We use unzip<any> because unzip doesn't type check if values have different types :'( + // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( const [orderAddresses, orderValues, takerTokenCancelAmounts] = - unzip<any>(orderAddressesValuesAndTakerTokenCancelAmounts); + _.unzip<any>(orderAddressesValuesAndTakerTokenCancelAmounts); const gas = await exchangeInstance.batchCancel.estimateGas( orderAddresses, orderValues, @@ -565,7 +561,7 @@ export class ExchangeWrapper extends ContractWrapper { * Stops watching for all exchange events */ public async stopWatchingAllEventsAsync(): Promise<void> { - const stopWatchingPromises = map(this._exchangeLogEventEmitters, + const stopWatchingPromises = _.map(this._exchangeLogEventEmitters, logEventObj => logEventObj.stopWatchingAsync()); await Promise.all(stopWatchingPromises); this._exchangeLogEventEmitters = []; @@ -719,8 +715,8 @@ export class ExchangeWrapper extends ContractWrapper { } } private _throwErrorLogsAsErrors(logs: ContractEvent[]): void { - const errEvent = find(logs, {event: 'LogError'}); - if (!isUndefined(errEvent)) { + const errEvent = _.find(logs, {event: 'LogError'}); + if (!_.isUndefined(errEvent)) { const errCode = (errEvent.args as LogErrorContractEventArgs).errorId.toNumber(); const errMessage = this._exchangeContractErrCodesToMsg[errCode]; throw new Error(errMessage); @@ -737,7 +733,7 @@ export class ExchangeWrapper extends ContractWrapper { return isRoundingError; } private async _getExchangeContractAsync(): Promise<ExchangeContract> { - if (!isUndefined(this._exchangeContractIfExists)) { + if (!_.isUndefined(this._exchangeContractIfExists)) { return this._exchangeContractIfExists; } const contractInstance = await this._instantiateContractIfExistsAsync((ExchangeArtifacts as any)); diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 971b2d43c..3e87e4852 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -1,5 +1,4 @@ -import map = require('lodash/map'); -import isUndefined = require('lodash/isUndefined'); +import * as _ from 'lodash'; import {Web3Wrapper} from '../web3_wrapper'; import {Token, TokenRegistryContract, TokenMetadata} from '../types'; import {assert} from '../utils/assert'; @@ -25,12 +24,12 @@ export class TokenRegistryWrapper extends ContractWrapper { const tokenRegistryContract = await this._getTokenRegistryContractAsync(); const addresses = await tokenRegistryContract.getTokenAddresses.call(); - const tokenMetadataPromises: Array<Promise<TokenMetadata>> = map( + const tokenMetadataPromises: Array<Promise<TokenMetadata>> = _.map( addresses, (address: string) => (tokenRegistryContract.getTokenMetaData.call(address)), ); const tokensMetadata = await Promise.all(tokenMetadataPromises); - const tokens = map(tokensMetadata, metadata => { + const tokens = _.map(tokensMetadata, metadata => { return { address: metadata[0], name: metadata[1], @@ -42,7 +41,7 @@ export class TokenRegistryWrapper extends ContractWrapper { return tokens; } private async _getTokenRegistryContractAsync(): Promise<TokenRegistryContract> { - if (!isUndefined(this._tokenRegistryContractIfExists)) { + if (!_.isUndefined(this._tokenRegistryContractIfExists)) { return this._tokenRegistryContractIfExists; } const contractInstance = await this._instantiateContractIfExistsAsync((TokenRegistryArtifacts as any)); diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index 5db7248e8..29f9b2d1c 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -1,4 +1,4 @@ -import isUndefined = require('lodash/isUndefined'); +import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; import {Web3Wrapper} from '../web3_wrapper'; import {assert} from '../utils/assert'; @@ -179,7 +179,7 @@ export class TokenWrapper extends ContractWrapper { } private async _getTokenContractAsync(tokenAddress: string): Promise<TokenContract> { let tokenContract = this._tokenContractsByAddress[tokenAddress]; - if (!isUndefined(tokenContract)) { + if (!_.isUndefined(tokenContract)) { return tokenContract; } const contractInstance = await this._instantiateContractIfExistsAsync((TokenArtifacts as any), tokenAddress); @@ -189,10 +189,10 @@ export class TokenWrapper extends ContractWrapper { } private async _getProxyAddressAsync() { const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); - const proxyNetworkConfigsIfExists = isUndefined(networkIdIfExists) ? + const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : (ProxyArtifacts as any).networks[networkIdIfExists]; - if (isUndefined(proxyNetworkConfigsIfExists)) { + if (_.isUndefined(proxyNetworkConfigsIfExists)) { throw new Error(ZeroExError.CONTRACT_NOT_DEPLOYED_ON_NETWORK); } const proxyAddress = proxyNetworkConfigsIfExists.address; diff --git a/src/types.ts b/src/types.ts index d9189c8a0..2b7fba226 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,10 +1,10 @@ -import reduce = require('lodash/reduce'); +import * as _ from 'lodash'; import * as Web3 from 'web3'; // Utility function to create a K:V from a list of strings // Adapted from: https://basarat.gitbooks.io/typescript/content/docs/types/literal-types.html function strEnum(values: string[]): {[key: string]: string} { - return reduce(values, (result, key) => { + return _.reduce(values, (result, key) => { result[key] = key; return result; }, Object.create(null)); diff --git a/src/utils/assert.ts b/src/utils/assert.ts index efc7ed366..94b119d5a 100644 --- a/src/utils/assert.ts +++ b/src/utils/assert.ts @@ -1,10 +1,4 @@ -import uniq = require('lodash/uniq'); -import isEmpty = require('lodash/isEmpty'); -import isObject = require('lodash/isObject'); -import isFinite = require('lodash/isFinite'); -import isString = require('lodash/isString'); -import isBoolean = require('lodash/isBoolean'); -import isUndefined = require('lodash/isUndefined'); +import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; import * as Web3 from 'web3'; import {Web3Wrapper} from '../web3_wrapper'; @@ -15,17 +9,17 @@ const HEX_REGEX = /^0x[0-9A-F]*$/i; export const assert = { isBigNumber(variableName: string, value: BigNumber.BigNumber): void { - const isBigNumber = isObject(value) && value.isBigNumber; + const isBigNumber = _.isObject(value) && value.isBigNumber; this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value)); }, isUndefined(value: any, variableName?: string): void { - this.assert(isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value)); + this.assert(_.isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value)); }, isString(variableName: string, value: string): void { - this.assert(isString(value), this.typeAssertionMessage(variableName, 'string', value)); + this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value)); }, isHexString(variableName: string, value: string): void { - this.assert(isString(value) && HEX_REGEX.test(value), + this.assert(_.isString(value) && HEX_REGEX.test(value), this.typeAssertionMessage(variableName, 'HexString', value)); }, isETHAddressHex(variableName: string, value: string): void { @@ -42,19 +36,19 @@ export const assert = { }, async isUserAddressAvailableAsync(web3Wrapper: Web3Wrapper): Promise<void> { const availableAddresses = await web3Wrapper.getAvailableAddressesAsync(); - this.assert(!isEmpty(availableAddresses), 'No addresses were available on the provided web3 instance'); + this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 instance'); }, hasAtMostOneUniqueValue(value: any[], errMsg: string): void { - this.assert(uniq(value).length <= 1, errMsg); + this.assert(_.uniq(value).length <= 1, errMsg); }, isNumber(variableName: string, value: number): void { - this.assert(isFinite(value), this.typeAssertionMessage(variableName, 'number', value)); + this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value)); }, isValidOrderHash(variableName: string, value: string): void { this.assert(utils.isValidOrderHash(value), this.typeAssertionMessage(variableName, 'orderHash', value)); }, isBoolean(variableName: string, value: boolean): void { - this.assert(isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value)); + this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value)); }, doesConformToSchema(variableName: string, value: object, schema: Schema): void { const schemaValidator = new SchemaValidator(); diff --git a/src/utils/decorators.ts b/src/utils/decorators.ts index b06e96747..a25f2cff5 100644 --- a/src/utils/decorators.ts +++ b/src/utils/decorators.ts @@ -1,4 +1,4 @@ -import includes = require('lodash/includes'); +import * as _ from 'lodash'; import {constants} from './constants'; import {AsyncMethod, ZeroExError} from '../types'; @@ -20,10 +20,10 @@ export const decorators = { const result = await originalMethod.apply(this, args); return result; } catch (error) { - if (includes(error.message, constants.INVALID_JUMP_PATTERN)) { + if (_.includes(error.message, constants.INVALID_JUMP_PATTERN)) { throw new Error(ZeroExError.INVALID_JUMP); } - if (includes(error.message, constants.OUT_OF_GAS_PATTERN)) { + if (_.includes(error.message, constants.OUT_OF_GAS_PATTERN)) { throw new Error(ZeroExError.OUT_OF_GAS); } throw error; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 2db611ccb..bad5b6498 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -1,5 +1,4 @@ -import map = require('lodash/map'); -import includes = require('lodash/includes'); +import * as _ from 'lodash'; import * as BN from 'bn.js'; import * as ethABI from 'ethereumjs-abi'; import * as ethUtil from 'ethereumjs-util'; @@ -21,7 +20,7 @@ export const utils = { console.log(message); }, isParityNode(nodeVersion: string): boolean { - return includes(nodeVersion, 'Parity'); + return _.includes(nodeVersion, 'Parity'); }, isValidOrderHash(orderHashHex: string): boolean { const isValid = /^0x[0-9A-F]{64}$/i.test(orderHashHex); @@ -45,8 +44,8 @@ export const utils = { {value: utils.bigNumberToBN(order.expirationUnixTimestampSec), type: SolidityTypes.uint256}, {value: utils.bigNumberToBN(order.salt), type: SolidityTypes.uint256}, ]; - const types = map(orderParts, o => o.type); - const values = map(orderParts, o => o.value); + const types = _.map(orderParts, o => o.type); + const values = _.map(orderParts, o => o.value); const hashBuff = ethABI.soliditySHA3(types, values); const hashHex = ethUtil.bufferToHex(hashBuff); return hashHex; diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index d7cf6df58..6bdca499f 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -1,4 +1,4 @@ -import includes = require('lodash/includes'); +import * as _ from 'lodash'; import * as Web3 from 'web3'; import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); @@ -17,7 +17,7 @@ export class Web3Wrapper { } public async isSenderAddressAvailableAsync(senderAddress: string): Promise<boolean> { const addresses = await this.getAvailableAddressesAsync(); - return includes(addresses, senderAddress); + return _.includes(addresses, senderAddress); } public async getNodeVersionAsync(): Promise<string> { const nodeVersion = await promisify(this.web3.version.getNode)(); |