aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src
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/utils/src
parentf570f80674c22f69712c45e8e3c48e948b51f357 (diff)
downloaddexon-0x-contracts-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.gz
dexon-0x-contracts-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.zst
dexon-0x-contracts-c3afc13dd660348e99b727c2dd01930eec8d99c3.zip
Upgrade bignumber.js version
Diffstat (limited to 'packages/utils/src')
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/bool.ts4
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/int.ts4
-rw-r--r--packages/utils/src/abi_encoder/evm_data_types/uint.ts2
-rw-r--r--packages/utils/src/abi_encoder/utils/math.ts8
4 files changed, 9 insertions, 9 deletions
diff --git a/packages/utils/src/abi_encoder/evm_data_types/bool.ts b/packages/utils/src/abi_encoder/evm_data_types/bool.ts
index 7f91f34e6..23298bc88 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/bool.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/bool.ts
@@ -37,11 +37,11 @@ export class BoolDataType extends AbstractBlobDataType {
const valueBuf = calldata.popWord();
const valueHex = ethUtil.bufferToHex(valueBuf);
const valueNumber = new BigNumber(valueHex, constants.HEX_BASE);
- if (!(valueNumber.equals(0) || valueNumber.equals(1))) {
+ if (!(valueNumber.isEqualTo(0) || valueNumber.isEqualTo(1))) {
throw new Error(`Failed to decode boolean. Expected 0x0 or 0x1, got ${valueHex}`);
}
/* tslint:disable boolean-naming */
- const value: boolean = !valueNumber.equals(0);
+ const value: boolean = !valueNumber.isEqualTo(0);
/* tslint:enable boolean-naming */
return value;
}
diff --git a/packages/utils/src/abi_encoder/evm_data_types/int.ts b/packages/utils/src/abi_encoder/evm_data_types/int.ts
index 8d98e195b..b7e0d9f4e 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/int.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/int.ts
@@ -38,8 +38,8 @@ export class IntDataType extends AbstractBlobDataType {
throw new Error(`Tried to instantiate Int with bad input: ${dataItem}`);
}
this._width = IntDataType._decodeWidthFromType(dataItem.type);
- this._minValue = new BigNumber(2).toPower(this._width - 1).times(-1);
- this._maxValue = new BigNumber(2).toPower(this._width - 1).sub(1);
+ this._minValue = new BigNumber(2).exponentiatedBy(this._width - 1).times(-1);
+ this._maxValue = new BigNumber(2).exponentiatedBy(this._width - 1).minus(1);
}
public encodeValue(value: BigNumber | string | number): Buffer {
diff --git a/packages/utils/src/abi_encoder/evm_data_types/uint.ts b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
index 8e382e8dc..a82aa789e 100644
--- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts
+++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts
@@ -38,7 +38,7 @@ export class UIntDataType extends AbstractBlobDataType {
throw new Error(`Tried to instantiate UInt with bad input: ${dataItem}`);
}
this._width = UIntDataType._decodeWidthFromType(dataItem.type);
- this._maxValue = new BigNumber(2).toPower(this._width).sub(1);
+ this._maxValue = new BigNumber(2).exponentiatedBy(this._width).minus(1);
}
public encodeValue(value: BigNumber | string | number): Buffer {
diff --git a/packages/utils/src/abi_encoder/utils/math.ts b/packages/utils/src/abi_encoder/utils/math.ts
index d84983c5b..b2fa5fe7d 100644
--- a/packages/utils/src/abi_encoder/utils/math.ts
+++ b/packages/utils/src/abi_encoder/utils/math.ts
@@ -10,9 +10,9 @@ function sanityCheckBigNumberRange(
maxValue: BigNumber,
): void {
const value = new BigNumber(value_, 10);
- if (value.greaterThan(maxValue)) {
+ if (value.isGreaterThan(maxValue)) {
throw new Error(`Tried to assign value of ${value}, which exceeds max value of ${maxValue}`);
- } else if (value.lessThan(minValue)) {
+ } else if (value.isLessThan(minValue)) {
throw new Error(`Tried to assign value of ${value}, which exceeds min value of ${minValue}`);
}
}
@@ -30,7 +30,7 @@ function bigNumberToPaddedBuffer(value: BigNumber): Buffer {
export function encodeNumericValue(value_: BigNumber | string | number): Buffer {
const value = new BigNumber(value_, 10);
// Case 1/2: value is non-negative
- if (value.greaterThanOrEqualTo(0)) {
+ if (value.isGreaterThanOrEqualTo(0)) {
const encodedPositiveValue = bigNumberToPaddedBuffer(value);
return encodedPositiveValue;
}
@@ -74,7 +74,7 @@ export function decodeNumericValue(encodedValue: Buffer, minValue: BigNumber): B
const valueHex = ethUtil.bufferToHex(encodedValue);
// Case 1/3: value is definitely non-negative because of numeric boundaries
const value = new BigNumber(valueHex, constants.HEX_BASE);
- if (!minValue.lessThan(0)) {
+ if (!minValue.isLessThan(0)) {
return value;
}
// Case 2/3: value is non-negative because there is no leading 1 (encoded as two's-complement)