diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-14 22:50:32 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2019-01-15 23:25:24 +0800 |
commit | c3afc13dd660348e99b727c2dd01930eec8d99c3 (patch) | |
tree | 9a05e88e55200fdf72d08af10b5a753535e23256 /packages/contract-wrappers | |
parent | f570f80674c22f69712c45e8e3c48e948b51f357 (diff) | |
download | dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.gz dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.bz2 dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.lz dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.xz dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.tar.zst dexon-sol-tools-c3afc13dd660348e99b727c2dd01930eec8d99c3.zip |
Upgrade bignumber.js version
Diffstat (limited to 'packages/contract-wrappers')
5 files changed, 14 insertions, 12 deletions
diff --git a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts index ad42cfd4f..cd79a0e5d 100644 --- a/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/erc20_token_wrapper.ts @@ -271,7 +271,7 @@ export class ERC20TokenWrapper extends ContractWrapper { const tokenContract = await this._getTokenContractAsync(normalizedTokenAddress); const fromAddressBalance = await this.getBalanceAsync(normalizedTokenAddress, normalizedFromAddress); - if (fromAddressBalance.lessThan(amountInBaseUnits)) { + if (fromAddressBalance.isLessThan(amountInBaseUnits)) { throw new Error(ContractWrappersError.InsufficientBalanceForTransfer); } @@ -327,12 +327,12 @@ export class ERC20TokenWrapper extends ContractWrapper { normalizedFromAddress, normalizedSenderAddress, ); - if (fromAddressAllowance.lessThan(amountInBaseUnits)) { + if (fromAddressAllowance.isLessThan(amountInBaseUnits)) { throw new Error(ContractWrappersError.InsufficientAllowanceForTransfer); } const fromAddressBalance = await this.getBalanceAsync(normalizedTokenAddress, normalizedFromAddress); - if (fromAddressBalance.lessThan(amountInBaseUnits)) { + if (fromAddressBalance.isLessThan(amountInBaseUnits)) { throw new Error(ContractWrappersError.InsufficientBalanceForTransfer); } diff --git a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts index 1ff130a48..c35b24664 100644 --- a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts +++ b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts @@ -39,7 +39,7 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP nestedAssetDataElement, userAddress, )).dividedToIntegerBy(nestedAmountElement); - if (_.isUndefined(balance) || nestedAssetBalance.lessThan(balance)) { + if (_.isUndefined(balance) || nestedAssetBalance.isLessThan(balance)) { balance = nestedAssetBalance; } } @@ -81,7 +81,7 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP nestedAssetDataElement, userAddress, )).dividedToIntegerBy(nestedAmountElement); - if (_.isUndefined(proxyAllowance) || nestedAssetAllowance.lessThan(proxyAllowance)) { + if (_.isUndefined(proxyAllowance) || nestedAssetAllowance.isLessThan(proxyAllowance)) { proxyAllowance = nestedAssetAllowance; } } diff --git a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts index f374d509b..4b75ea386 100644 --- a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts +++ b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts @@ -72,10 +72,10 @@ export class ExchangeTransferSimulator { } const balance = await this._store.getBalanceAsync(tokenAddress, from); const proxyAllowance = await this._store.getProxyAllowanceAsync(tokenAddress, 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(tokenAddress, from, amountInBaseUnits); diff --git a/packages/contract-wrappers/src/utils/utils.ts b/packages/contract-wrappers/src/utils/utils.ts index 0b3270e78..ab69385e7 100644 --- a/packages/contract-wrappers/src/utils/utils.ts +++ b/packages/contract-wrappers/src/utils/utils.ts @@ -7,13 +7,15 @@ import { constants } from './constants'; export const utils = { getCurrentUnixTimestampSec(): BigNumber { const milisecondsInSecond = 1000; - return new BigNumber(Date.now() / milisecondsInSecond).round(); + return new BigNumber(Date.now() / milisecondsInSecond).integerValue(); }, getCurrentUnixTimestampMs(): BigNumber { return new BigNumber(Date.now()); }, numberPercentageToEtherTokenAmountPercentage(percentage: number): BigNumber { - return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).mul(percentage); + return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).multipliedBy( + percentage, + ); }, removeUndefinedProperties<T extends object>(obj: T): Partial<T> { return _.pickBy(obj); diff --git a/packages/contract-wrappers/test/ether_token_wrapper_test.ts b/packages/contract-wrappers/test/ether_token_wrapper_test.ts index e3efef19d..cc2419aa2 100644 --- a/packages/contract-wrappers/test/ether_token_wrapper_test.ts +++ b/packages/contract-wrappers/test/ether_token_wrapper_test.ts @@ -116,7 +116,7 @@ describe('EtherTokenWrapper', () => { const preETHBalance = await web3Wrapper.getBalanceInWeiAsync(addressWithETH); const extraETHBalance = Web3Wrapper.toWei(new BigNumber(5)); - const overETHBalanceinWei = preETHBalance.add(extraETHBalance); + const overETHBalanceinWei = preETHBalance.plus(extraETHBalance); return expect( contractWrappers.etherToken.depositAsync(wethContractAddress, overETHBalanceinWei, addressWithETH), @@ -153,7 +153,7 @@ describe('EtherTokenWrapper', () => { ); expect(postWETHBalanceInBaseUnits).to.be.bignumber.equal(0); - const expectedETHBalance = preETHBalance.add(depositWeiAmount).round(decimalPlaces); + const expectedETHBalance = preETHBalance.plus(depositWeiAmount).integerValue(decimalPlaces); gasCost = expectedETHBalance.minus(postETHBalance); expect(gasCost).to.be.bignumber.lte(MAX_REASONABLE_GAS_COST_IN_WEI); }); @@ -165,7 +165,7 @@ describe('EtherTokenWrapper', () => { expect(preWETHBalance).to.be.bignumber.equal(0); // tslint:disable-next-line:custom-no-magic-numbers - const overWETHBalance = preWETHBalance.add(999999999); + const overWETHBalance = preWETHBalance.plus(999999999); return expect( contractWrappers.etherToken.withdrawAsync(wethContractAddress, overWETHBalance, addressWithETH), |