aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2019-01-14 22:50:32 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2019-01-15 23:25:24 +0800
commitc3afc13dd660348e99b727c2dd01930eec8d99c3 (patch)
tree9a05e88e55200fdf72d08af10b5a753535e23256 /packages/order-utils
parentf570f80674c22f69712c45e8e3c48e948b51f357 (diff)
downloaddexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.gz
dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.zst
dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.zip
Upgrade bignumber.js version
Diffstat (limited to 'packages/order-utils')
-rw-r--r--packages/order-utils/src/exchange_transfer_simulator.ts4
-rw-r--r--packages/order-utils/src/market_utils.ts4
-rw-r--r--packages/order-utils/src/order_state_utils.ts12
-rw-r--r--packages/order-utils/src/order_validation_utils.ts8
-rw-r--r--packages/order-utils/src/rate_utils.ts6
-rw-r--r--packages/order-utils/src/remaining_fillable_calculator.ts6
-rw-r--r--packages/order-utils/src/salt.ts2
-rw-r--r--packages/order-utils/src/utils.ts6
-rw-r--r--packages/order-utils/test/remaining_fillable_calculator_test.ts2
-rw-r--r--packages/order-utils/test/signature_utils_test.ts4
10 files changed, 27 insertions, 27 deletions
diff --git a/packages/order-utils/src/exchange_transfer_simulator.ts b/packages/order-utils/src/exchange_transfer_simulator.ts
index 06621fd9e..922ae8e17 100644
--- a/packages/order-utils/src/exchange_transfer_simulator.ts
+++ b/packages/order-utils/src/exchange_transfer_simulator.ts
@@ -88,14 +88,14 @@ export class ExchangeTransferSimulator {
}
const balance = await this._store.getBalanceAsync(assetData, from);
const proxyAllowance = await this._store.getProxyAllowanceAsync(assetData, from);
- if (proxyAllowance.lessThan(amountInBaseUnits)) {
+ if (proxyAllowance.isLessThan(amountInBaseUnits)) {
ExchangeTransferSimulator._throwValidationError(
FailureReason.ProxyAllowance,
tradeSide,
transferType,
);
}
- if (balance.lessThan(amountInBaseUnits)) {
+ if (balance.isLessThan(amountInBaseUnits)) {
ExchangeTransferSimulator._throwValidationError(FailureReason.Balance, tradeSide, transferType);
}
await this._decreaseProxyAllowanceAsync(assetData, from, amountInBaseUnits);
diff --git a/packages/order-utils/src/market_utils.ts b/packages/order-utils/src/market_utils.ts
index fa32f1413..9042551fa 100644
--- a/packages/order-utils/src/market_utils.ts
+++ b/packages/order-utils/src/market_utils.ts
@@ -52,7 +52,7 @@ export const marketUtils = {
const result = _.reduce(
orders,
({ resultOrders, remainingFillAmount, ordersRemainingFillableMakerAssetAmounts }, order, index) => {
- if (remainingFillAmount.lessThanOrEqualTo(constants.ZERO_AMOUNT)) {
+ if (remainingFillAmount.isLessThanOrEqualTo(constants.ZERO_AMOUNT)) {
return {
resultOrders,
remainingFillAmount: constants.ZERO_AMOUNT,
@@ -137,7 +137,7 @@ export const marketUtils = {
(accFees, order, index) => {
const makerAssetAmountAvailable = remainingFillableMakerAssetAmounts[index];
const feeToFillMakerAssetAmountAvailable = makerAssetAmountAvailable
- .mul(order.takerFee)
+ .multipliedBy(order.takerFee)
.dividedToIntegerBy(order.makerAssetAmount);
return accFees.plus(feeToFillMakerAssetAmountAvailable);
},
diff --git a/packages/order-utils/src/order_state_utils.ts b/packages/order-utils/src/order_state_utils.ts
index 389419587..430178b5d 100644
--- a/packages/order-utils/src/order_state_utils.ts
+++ b/packages/order-utils/src/order_state_utils.ts
@@ -214,10 +214,10 @@ export class OrderStateUtils {
const remainingFillableTakerAssetAmountGivenTakersStatus = orderRelevantTakerState.remainingFillableAssetAmount;
// The min of these two in the actualy max fillable by either party
- const fillableTakerAssetAmount = BigNumber.min([
+ const fillableTakerAssetAmount = BigNumber.min(
remainingFillableTakerAssetAmountGivenMakersStatus,
remainingFillableTakerAssetAmountGivenTakersStatus,
- ]);
+ );
return fillableTakerAssetAmount;
}
@@ -260,8 +260,8 @@ export class OrderStateUtils {
traderAddress,
);
- const transferrableTraderAssetAmount = BigNumber.min([traderProxyAllowance, traderBalance]);
- const transferrableFeeAssetAmount = BigNumber.min([traderFeeProxyAllowance, traderFeeBalance]);
+ const transferrableTraderAssetAmount = BigNumber.min(traderProxyAllowance, traderBalance);
+ const transferrableFeeAssetAmount = BigNumber.min(traderFeeProxyAllowance, traderFeeBalance);
const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
const filledTakerAssetAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash);
@@ -312,7 +312,7 @@ export class OrderStateUtils {
const tokenAddress = decodedAssetData.tokenAddress;
balances[tokenAddress] = _.isUndefined(initialBalances[tokenAddress])
? balance
- : balances[tokenAddress].add(balance);
+ : balances[tokenAddress].plus(balance);
} else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
for (const assetDataElement of decodedAssetData.nestedAssetData) {
balances = await this._getAssetBalancesAsync(assetDataElement, traderAddress, balances);
@@ -335,7 +335,7 @@ export class OrderStateUtils {
const tokenAddress = decodedAssetData.tokenAddress;
allowances[tokenAddress] = _.isUndefined(initialAllowances[tokenAddress])
? allowance
- : allowances[tokenAddress].add(allowance);
+ : allowances[tokenAddress].plus(allowance);
} else if (assetDataUtils.isMultiAssetData(decodedAssetData)) {
for (const assetDataElement of decodedAssetData.nestedAssetData) {
allowances = await this._getAssetBalancesAsync(assetDataElement, traderAddress, allowances);
diff --git a/packages/order-utils/src/order_validation_utils.ts b/packages/order-utils/src/order_validation_utils.ts
index ae4291ea8..95215d918 100644
--- a/packages/order-utils/src/order_validation_utils.ts
+++ b/packages/order-utils/src/order_validation_utils.ts
@@ -31,13 +31,13 @@ export class OrderValidationUtils {
if (denominator.eq(0)) {
throw new Error('denominator cannot be 0');
}
- const remainder = target.mul(numerator).mod(denominator);
+ const remainder = target.multipliedBy(numerator).mod(denominator);
if (remainder.eq(0)) {
return false; // no rounding error
}
// tslint:disable-next-line:custom-no-magic-numbers
- const errPercentageTimes1000000 = remainder.mul(1000000).div(numerator.mul(target));
+ const errPercentageTimes1000000 = remainder.multipliedBy(1000000).div(numerator.multipliedBy(target));
// tslint:disable-next-line:custom-no-magic-numbers
const isError = errPercentageTimes1000000.gt(1000);
return isError;
@@ -108,7 +108,7 @@ export class OrderValidationUtils {
}
private static _validateOrderNotExpiredOrThrow(expirationTimeSeconds: BigNumber): void {
const currentUnixTimestampSec = utils.getCurrentUnixTimestampSec();
- if (expirationTimeSeconds.lessThan(currentUnixTimestampSec)) {
+ if (expirationTimeSeconds.isLessThan(currentUnixTimestampSec)) {
throw new Error(RevertReason.OrderUnfillable);
}
}
@@ -216,7 +216,7 @@ export class OrderValidationUtils {
}
OrderValidationUtils._validateOrderNotExpiredOrThrow(signedOrder.expirationTimeSeconds);
const remainingTakerTokenAmount = signedOrder.takerAssetAmount.minus(filledTakerTokenAmount);
- const desiredFillTakerTokenAmount = remainingTakerTokenAmount.lessThan(fillTakerAssetAmount)
+ const desiredFillTakerTokenAmount = remainingTakerTokenAmount.isLessThan(fillTakerAssetAmount)
? remainingTakerTokenAmount
: fillTakerAssetAmount;
try {
diff --git a/packages/order-utils/src/rate_utils.ts b/packages/order-utils/src/rate_utils.ts
index 416e00c67..dacdbd5a2 100644
--- a/packages/order-utils/src/rate_utils.ts
+++ b/packages/order-utils/src/rate_utils.ts
@@ -22,7 +22,7 @@ export const rateUtils = {
feeRate.gte(constants.ZERO_AMOUNT),
`Expected feeRate: ${feeRate} to be greater than or equal to 0`,
);
- const takerAssetAmountNeededToPayForFees = order.takerFee.mul(feeRate);
+ const takerAssetAmountNeededToPayForFees = order.takerFee.multipliedBy(feeRate);
const totalTakerAssetAmount = takerAssetAmountNeededToPayForFees.plus(order.takerAssetAmount);
const rate = totalTakerAssetAmount.div(order.makerAssetAmount);
return rate;
@@ -35,9 +35,9 @@ export const rateUtils = {
*/
getFeeAdjustedRateOfFeeOrder(feeOrder: Order): BigNumber {
assert.doesConformToSchema('feeOrder', feeOrder, schemas.orderSchema);
- const zrxAmountAfterFees = feeOrder.makerAssetAmount.sub(feeOrder.takerFee);
+ const zrxAmountAfterFees = feeOrder.makerAssetAmount.minus(feeOrder.takerFee);
assert.assert(
- zrxAmountAfterFees.greaterThan(constants.ZERO_AMOUNT),
+ zrxAmountAfterFees.isGreaterThan(constants.ZERO_AMOUNT),
`Expected takerFee: ${JSON.stringify(feeOrder.takerFee)} to be less than makerAssetAmount: ${JSON.stringify(
feeOrder.makerAssetAmount,
)}`,
diff --git a/packages/order-utils/src/remaining_fillable_calculator.ts b/packages/order-utils/src/remaining_fillable_calculator.ts
index 052eafa1d..92ffc8e80 100644
--- a/packages/order-utils/src/remaining_fillable_calculator.ts
+++ b/packages/order-utils/src/remaining_fillable_calculator.ts
@@ -39,15 +39,15 @@ export class RemainingFillableCalculator {
private _hasSufficientFundsForFeeAndTransferAmount(): boolean {
if (this._isTraderAssetZRX) {
const totalZRXTransferAmountRequired = this._remainingOrderAssetAmount.plus(this._remainingOrderFeeAmount);
- const hasSufficientFunds = this._transferrableAssetAmount.greaterThanOrEqualTo(
+ const hasSufficientFunds = this._transferrableAssetAmount.isGreaterThanOrEqualTo(
totalZRXTransferAmountRequired,
);
return hasSufficientFunds;
} else {
- const hasSufficientFundsForTransferAmount = this._transferrableAssetAmount.greaterThanOrEqualTo(
+ const hasSufficientFundsForTransferAmount = this._transferrableAssetAmount.isGreaterThanOrEqualTo(
this._remainingOrderAssetAmount,
);
- const hasSufficientFundsForFeeAmount = this._transferrableFeeAmount.greaterThanOrEqualTo(
+ const hasSufficientFundsForFeeAmount = this._transferrableFeeAmount.isGreaterThanOrEqualTo(
this._remainingOrderFeeAmount,
);
const hasSufficientFunds = hasSufficientFundsForTransferAmount && hasSufficientFundsForFeeAmount;
diff --git a/packages/order-utils/src/salt.ts b/packages/order-utils/src/salt.ts
index ff47ab5d2..95df66c99 100644
--- a/packages/order-utils/src/salt.ts
+++ b/packages/order-utils/src/salt.ts
@@ -13,6 +13,6 @@ export function generatePseudoRandomSalt(): BigNumber {
// Source: https://mikemcl.github.io/bignumber.js/#random
const randomNumber = BigNumber.random(MAX_DIGITS_IN_UNSIGNED_256_INT);
const factor = new BigNumber(10).pow(MAX_DIGITS_IN_UNSIGNED_256_INT - 1);
- const salt = randomNumber.times(factor).round();
+ const salt = randomNumber.times(factor).integerValue();
return salt;
}
diff --git a/packages/order-utils/src/utils.ts b/packages/order-utils/src/utils.ts
index 6b2261001..64195dbed 100644
--- a/packages/order-utils/src/utils.ts
+++ b/packages/order-utils/src/utils.ts
@@ -10,13 +10,13 @@ export const utils = {
},
getCurrentUnixTimestampSec(): BigNumber {
const milisecondsInSecond = 1000;
- return new BigNumber(Date.now() / milisecondsInSecond).round();
+ return new BigNumber(Date.now() / milisecondsInSecond).integerValue();
},
getPartialAmountFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): BigNumber {
const fillMakerTokenAmount = numerator
- .mul(target)
+ .multipliedBy(target)
.div(denominator)
- .round(0);
+ .integerValue(0);
return fillMakerTokenAmount;
},
};
diff --git a/packages/order-utils/test/remaining_fillable_calculator_test.ts b/packages/order-utils/test/remaining_fillable_calculator_test.ts
index c55a76def..affad8f1c 100644
--- a/packages/order-utils/test/remaining_fillable_calculator_test.ts
+++ b/packages/order-utils/test/remaining_fillable_calculator_test.ts
@@ -162,7 +162,7 @@ describe('RemainingFillableCalculator', () => {
remainingMakeAssetAmount,
);
const calculatedFillableAmount = calculator.computeRemainingFillable();
- expect(calculatedFillableAmount.lessThanOrEqualTo(transferrableMakeAssetAmount)).to.be.true();
+ expect(calculatedFillableAmount.isLessThanOrEqualTo(transferrableMakeAssetAmount)).to.be.true();
expect(calculatedFillableAmount).to.be.bignumber.greaterThan(new BigNumber(0));
const orderToFeeRatio = signedOrder.makerAssetAmount.dividedBy(signedOrder.makerFee);
const calculatedFeeAmount = calculatedFillableAmount.dividedBy(orderToFeeRatio);
diff --git a/packages/order-utils/test/signature_utils_test.ts b/packages/order-utils/test/signature_utils_test.ts
index 84e5559a9..937382056 100644
--- a/packages/order-utils/test/signature_utils_test.ts
+++ b/packages/order-utils/test/signature_utils_test.ts
@@ -132,10 +132,10 @@ describe('Signature utils', () => {
});
it('generates salt in range [0..2^256)', () => {
const salt = generatePseudoRandomSalt();
- expect(salt.greaterThanOrEqualTo(0)).to.be.true();
+ expect(salt.isGreaterThanOrEqualTo(0)).to.be.true();
// tslint:disable-next-line:custom-no-magic-numbers
const twoPow256 = new BigNumber(2).pow(256);
- expect(salt.lessThan(twoPow256)).to.be.true();
+ expect(salt.isLessThan(twoPow256)).to.be.true();
});
});
describe('#ecSignOrderAsync', () => {