aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-10-26 03:22:23 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-10-26 03:22:23 +0800
commit744a9b89312c825ee94195106b9aa8aa11f43b77 (patch)
tree29009ec3e75e9d0396e744993065c05ef04c650b /src/utils
parent45c4042e2bb6d4c13510a5922602ba49bb5108ef (diff)
downloaddexon-0x-contracts-744a9b89312c825ee94195106b9aa8aa11f43b77.tar.gz
dexon-0x-contracts-744a9b89312c825ee94195106b9aa8aa11f43b77.tar.zst
dexon-0x-contracts-744a9b89312c825ee94195106b9aa8aa11f43b77.zip
Upgrade bignumber to the version with native typings and remove typings
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/abi_decoder.ts2
-rw-r--r--src/utils/assert.ts6
-rw-r--r--src/utils/constants.ts2
-rw-r--r--src/utils/exchange_transfer_simulator.ts21
-rw-r--r--src/utils/order_validation_utils.ts23
-rw-r--r--src/utils/utils.ts6
6 files changed, 31 insertions, 29 deletions
diff --git a/src/utils/abi_decoder.ts b/src/utils/abi_decoder.ts
index a6c45bee7..247ba0e5b 100644
--- a/src/utils/abi_decoder.ts
+++ b/src/utils/abi_decoder.ts
@@ -1,6 +1,6 @@
import * as Web3 from 'web3';
import * as _ from 'lodash';
-import * as BigNumber from 'bignumber.js';
+import BigNumber from 'bignumber.js';
import {AbiType, DecodedLogArgs, LogWithDecodedArgs, RawLog, SolidityTypes, ContractEventArgs} from '../types';
import * as SolidityCoder from 'web3/lib/solidity/coder';
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index 099f4490f..286105345 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -1,5 +1,5 @@
import * as _ from 'lodash';
-import * as BigNumber from 'bignumber.js';
+import BigNumber from 'bignumber.js';
import * as Web3 from 'web3';
import {Web3Wrapper} from '../web3_wrapper';
import {SchemaValidator, Schema} from '0x-json-schemas';
@@ -7,8 +7,8 @@ import {SchemaValidator, Schema} from '0x-json-schemas';
const HEX_REGEX = /^0x[0-9A-F]*$/i;
export const assert = {
- isBigNumber(variableName: string, value: BigNumber.BigNumber): void {
- const isBigNumber = _.isObject(value) && value.isBigNumber;
+ isBigNumber(variableName: string, value: BigNumber): void {
+ const isBigNumber = _.isObject(value) && (value as any).isBigNumber;
this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value));
},
isUndefined(value: any, variableName?: string): void {
diff --git a/src/utils/constants.ts b/src/utils/constants.ts
index a066fe869..3de3f5bc1 100644
--- a/src/utils/constants.ts
+++ b/src/utils/constants.ts
@@ -1,4 +1,4 @@
-import * as BigNumber from 'bignumber.js';
+import BigNumber from 'bignumber.js';
export const constants = {
NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
diff --git a/src/utils/exchange_transfer_simulator.ts b/src/utils/exchange_transfer_simulator.ts
index db12abd29..89b23c8ab 100644
--- a/src/utils/exchange_transfer_simulator.ts
+++ b/src/utils/exchange_transfer_simulator.ts
@@ -1,4 +1,5 @@
import * as _ from 'lodash';
+import BigNumber from 'bignumber.js';
import {ExchangeContractErrs, TradeSide, TransferType} from '../types';
import {TokenWrapper} from '../contract_wrappers/token_wrapper';
@@ -37,12 +38,12 @@ export class BalanceAndProxyAllowanceLazyStore {
protected _token: TokenWrapper;
private _balance: {
[tokenAddress: string]: {
- [userAddress: string]: BigNumber.BigNumber,
+ [userAddress: string]: BigNumber,
},
};
private _proxyAllowance: {
[tokenAddress: string]: {
- [userAddress: string]: BigNumber.BigNumber,
+ [userAddress: string]: BigNumber,
},
};
constructor(token: TokenWrapper) {
@@ -50,7 +51,7 @@ export class BalanceAndProxyAllowanceLazyStore {
this._balance = {};
this._proxyAllowance = {};
}
- protected async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber.BigNumber> {
+ protected async getBalanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
if (_.isUndefined(this._balance[tokenAddress]) || _.isUndefined(this._balance[tokenAddress][userAddress])) {
const balance = await this._token.getBalanceAsync(tokenAddress, userAddress);
this.setBalance(tokenAddress, userAddress, balance);
@@ -58,13 +59,13 @@ export class BalanceAndProxyAllowanceLazyStore {
const cachedBalance = this._balance[tokenAddress][userAddress];
return cachedBalance;
}
- protected setBalance(tokenAddress: string, userAddress: string, balance: BigNumber.BigNumber): void {
+ protected setBalance(tokenAddress: string, userAddress: string, balance: BigNumber): void {
if (_.isUndefined(this._balance[tokenAddress])) {
this._balance[tokenAddress] = {};
}
this._balance[tokenAddress][userAddress] = balance;
}
- protected async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber.BigNumber> {
+ protected async getProxyAllowanceAsync(tokenAddress: string, userAddress: string): Promise<BigNumber> {
if (_.isUndefined(this._proxyAllowance[tokenAddress]) ||
_.isUndefined(this._proxyAllowance[tokenAddress][userAddress])) {
const proxyAllowance = await this._token.getProxyAllowanceAsync(tokenAddress, userAddress);
@@ -73,7 +74,7 @@ export class BalanceAndProxyAllowanceLazyStore {
const cachedProxyAllowance = this._proxyAllowance[tokenAddress][userAddress];
return cachedProxyAllowance;
}
- protected setProxyAllowance(tokenAddress: string, userAddress: string, proxyAllowance: BigNumber.BigNumber): void {
+ protected setProxyAllowance(tokenAddress: string, userAddress: string, proxyAllowance: BigNumber): void {
if (_.isUndefined(this._proxyAllowance[tokenAddress])) {
this._proxyAllowance[tokenAddress] = {};
}
@@ -92,7 +93,7 @@ export class ExchangeTransferSimulator extends BalanceAndProxyAllowanceLazyStore
* @param transferType Is it a fee payment or a value transfer
*/
public async transferFromAsync(tokenAddress: string, from: string, to: string,
- amountInBaseUnits: BigNumber.BigNumber, tradeSide: TradeSide,
+ amountInBaseUnits: BigNumber, tradeSide: TradeSide,
transferType: TransferType): Promise<void> {
const balance = await this.getBalanceAsync(tokenAddress, from);
const proxyAllowance = await this.getProxyAllowanceAsync(tokenAddress, from);
@@ -107,19 +108,19 @@ export class ExchangeTransferSimulator extends BalanceAndProxyAllowanceLazyStore
await this.increaseBalanceAsync(tokenAddress, to, amountInBaseUnits);
}
private async decreaseProxyAllowanceAsync(tokenAddress: string, userAddress: string,
- amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
+ amountInBaseUnits: BigNumber): Promise<void> {
const proxyAllowance = await this.getProxyAllowanceAsync(tokenAddress, userAddress);
if (!proxyAllowance.eq(this._token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)) {
this.setProxyAllowance(tokenAddress, userAddress, proxyAllowance.minus(amountInBaseUnits));
}
}
private async increaseBalanceAsync(tokenAddress: string, userAddress: string,
- amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
+ amountInBaseUnits: BigNumber): Promise<void> {
const balance = await this.getBalanceAsync(tokenAddress, userAddress);
this.setBalance(tokenAddress, userAddress, balance.plus(amountInBaseUnits));
}
private async decreaseBalanceAsync(tokenAddress: string, userAddress: string,
- amountInBaseUnits: BigNumber.BigNumber): Promise<void> {
+ amountInBaseUnits: BigNumber): Promise<void> {
const balance = await this.getBalanceAsync(tokenAddress, userAddress);
this.setBalance(tokenAddress, userAddress, balance.minus(amountInBaseUnits));
}
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts
index b7eae7e2f..f03703c4e 100644
--- a/src/utils/order_validation_utils.ts
+++ b/src/utils/order_validation_utils.ts
@@ -1,4 +1,5 @@
import * as _ from 'lodash';
+import BigNumber from 'bignumber.js';
import {ExchangeContractErrs, SignedOrder, Order, ZeroExError, TradeSide, TransferType} from '../types';
import {ZeroEx} from '../0x';
import {TokenWrapper} from '../contract_wrappers/token_wrapper';
@@ -16,7 +17,7 @@ export class OrderValidationUtils {
}
public async validateOrderFillableOrThrowAsync(
exchangeTradeEmulator: ExchangeTransferSimulator, signedOrder: SignedOrder, zrxTokenAddress: string,
- expectedFillTakerTokenAmount?: BigNumber.BigNumber): Promise<void> {
+ expectedFillTakerTokenAmount?: BigNumber): Promise<void> {
const orderHash = utils.getOrderHashHex(signedOrder);
const unavailableTakerTokenAmount = await this.exchangeWrapper.getUnavailableTakerAmountAsync(orderHash);
this.validateRemainingFillAmountNotZeroOrThrow(
@@ -48,8 +49,8 @@ export class OrderValidationUtils {
}
public async validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator: ExchangeTransferSimulator, signedOrder: SignedOrder,
- fillTakerTokenAmount: BigNumber.BigNumber, takerAddress: string,
- zrxTokenAddress: string): Promise<BigNumber.BigNumber> {
+ fillTakerTokenAmount: BigNumber, takerAddress: string,
+ zrxTokenAddress: string): Promise<BigNumber> {
if (fillTakerTokenAmount.eq(0)) {
throw new Error(ExchangeContractErrs.OrderFillAmountZero);
}
@@ -83,7 +84,7 @@ export class OrderValidationUtils {
}
public async validateFillOrKillOrderThrowIfInvalidAsync(
exchangeTradeEmulator: ExchangeTransferSimulator, signedOrder: SignedOrder,
- fillTakerTokenAmount: BigNumber.BigNumber, takerAddress: string, zrxTokenAddress: string): Promise<void> {
+ fillTakerTokenAmount: BigNumber, takerAddress: string, zrxTokenAddress: string): Promise<void> {
const filledTakerTokenAmount = await this.validateFillOrderThrowIfInvalidAsync(
exchangeTradeEmulator, signedOrder, fillTakerTokenAmount, takerAddress, zrxTokenAddress,
);
@@ -92,8 +93,8 @@ export class OrderValidationUtils {
}
}
public async validateCancelOrderThrowIfInvalidAsync(order: Order,
- cancelTakerTokenAmount: BigNumber.BigNumber,
- unavailableTakerTokenAmount: BigNumber.BigNumber,
+ cancelTakerTokenAmount: BigNumber,
+ unavailableTakerTokenAmount: BigNumber,
): Promise<void> {
if (cancelTakerTokenAmount.eq(0)) {
throw new Error(ExchangeContractErrs.OrderCancelAmountZero);
@@ -108,7 +109,7 @@ export class OrderValidationUtils {
}
public async validateFillOrderBalancesAllowancesThrowIfInvalidAsync(
exchangeTradeEmulator: ExchangeTransferSimulator, signedOrder: SignedOrder,
- fillTakerTokenAmount: BigNumber.BigNumber, senderAddress: string, zrxTokenAddress: string): Promise<void> {
+ fillTakerTokenAmount: BigNumber, senderAddress: string, zrxTokenAddress: string): Promise<void> {
const fillMakerTokenAmount = this.getPartialAmount(
fillTakerTokenAmount,
signedOrder.takerTokenAmount,
@@ -142,20 +143,20 @@ export class OrderValidationUtils {
);
}
private validateRemainingFillAmountNotZeroOrThrow(
- takerTokenAmount: BigNumber.BigNumber, unavailableTakerTokenAmount: BigNumber.BigNumber,
+ takerTokenAmount: BigNumber, unavailableTakerTokenAmount: BigNumber,
) {
if (takerTokenAmount.eq(unavailableTakerTokenAmount)) {
throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
}
}
- private validateOrderNotExpiredOrThrow(expirationUnixTimestampSec: BigNumber.BigNumber) {
+ private validateOrderNotExpiredOrThrow(expirationUnixTimestampSec: BigNumber) {
const currentUnixTimestampSec = utils.getCurrentUnixTimestamp();
if (expirationUnixTimestampSec.lessThan(currentUnixTimestampSec)) {
throw new Error(ExchangeContractErrs.OrderFillExpired);
}
}
- private getPartialAmount(numerator: BigNumber.BigNumber, denominator: BigNumber.BigNumber,
- target: BigNumber.BigNumber): BigNumber.BigNumber {
+ private getPartialAmount(numerator: BigNumber, denominator: BigNumber,
+ target: BigNumber): BigNumber {
const fillMakerTokenAmount = numerator
.mul(target)
.div(denominator)
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index f2bf74860..280f3e979 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -2,7 +2,7 @@ import * as _ from 'lodash';
import * as ethABI from 'ethereumjs-abi';
import * as ethUtil from 'ethereumjs-util';
import {Order, SignedOrder, SolidityTypes} from '../types';
-import * as BigNumber from 'bignumber.js';
+import BigNumber from 'bignumber.js';
import BN = require('bn.js');
export const utils = {
@@ -12,7 +12,7 @@ export const utils = {
* expects values of Solidity type `uint` to be passed as type `BN`.
* We do not use BN anywhere else in the codebase.
*/
- bigNumberToBN(value: BigNumber.BigNumber) {
+ bigNumberToBN(value: BigNumber) {
return new BN(value.toString(), 10);
},
consoleLog(message: string): void {
@@ -49,7 +49,7 @@ export const utils = {
const hashHex = ethUtil.bufferToHex(hashBuff);
return hashHex;
},
- getCurrentUnixTimestamp(): BigNumber.BigNumber {
+ getCurrentUnixTimestamp(): BigNumber {
return new BigNumber(Date.now() / 1000);
},
};