aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-06-23 04:50:16 +0800
committerGitHub <noreply@github.com>2017-06-23 04:50:16 +0800
commite5785532ed1f4cada70db7815a44ffdd005077f5 (patch)
treeda804f637b18b8589be98d81b34b26cbfc2b9032 /src/contract_wrappers
parentbd9fa3d335afdd0cd8b573f60b3ce3c0db6ad4dd (diff)
parent49e43c98767666fcf457edfe2f3cbe098d12b6a5 (diff)
downloaddexon-sol-tools-e5785532ed1f4cada70db7815a44ffdd005077f5.tar
dexon-sol-tools-e5785532ed1f4cada70db7815a44ffdd005077f5.tar.gz
dexon-sol-tools-e5785532ed1f4cada70db7815a44ffdd005077f5.tar.bz2
dexon-sol-tools-e5785532ed1f4cada70db7815a44ffdd005077f5.tar.lz
dexon-sol-tools-e5785532ed1f4cada70db7815a44ffdd005077f5.tar.xz
dexon-sol-tools-e5785532ed1f4cada70db7815a44ffdd005077f5.tar.zst
dexon-sol-tools-e5785532ed1f4cada70db7815a44ffdd005077f5.zip
Merge branch 'master' into fill-order-amuont
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/contract_wrapper.ts15
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts49
-rw-r--r--src/contract_wrappers/token_registry_wrapper.ts9
-rw-r--r--src/contract_wrappers/token_wrapper.ts8
4 files changed, 37 insertions, 44 deletions
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 30cdbd101..d6de801a3 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -1,9 +1,4 @@
-import map = require('lodash/map');
-import isEmpty = require('lodash/isEmpty');
-import find = require('lodash/find');
-import each = require('lodash/each');
-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';
@@ -210,7 +205,7 @@ export class ExchangeWrapper extends ContractWrapper {
@decorators.contractCallErrorHandler
public async fillOrdersUpToAsync(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber.BigNumber,
shouldCheckTransfer: boolean, takerAddress: string): Promise<BigNumber.BigNumber> {
- 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);
@@ -221,11 +216,11 @@ export class ExchangeWrapper extends ContractWrapper {
await this._validateFillOrderAndThrowIfInvalidAsync(
signedOrder, takerTokenFillAmount, takerAddress);
}
- if (isEmpty(signedOrders)) {
+ if (_isEmpty(signedOrders)) {
return new BigNumber(0); // no-op
}
- const orderAddressesValuesAndSignatureArray = map(signedOrders, signedOrder => {
+ const orderAddressesValuesAndSignatureArray = _.map(signedOrders, signedOrder => {
return [
...ExchangeWrapper._getOrderAddressesAndValues(signedOrder),
signedOrder.ecSignature.v,
@@ -233,8 +228,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,
);
@@ -294,11 +289,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,
@@ -307,8 +302,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,
);
@@ -407,7 +402,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,
@@ -417,9 +412,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,
@@ -494,7 +489,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);
@@ -505,19 +500,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,
@@ -582,7 +577,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 = [];
@@ -736,8 +731,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);
@@ -754,7 +749,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;