aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2019-01-17 06:16:49 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2019-01-17 06:16:49 +0800
commit466ec6b22a51f0a9d618f6091ce6f9f533118280 (patch)
tree433bf040b0e11666bb1429b569c941d5e677395b
parenta58771844366d5fd331e6b46a8de596d17fa6632 (diff)
downloaddexon-sol-tools-466ec6b22a51f0a9d618f6091ce6f9f533118280.tar
dexon-sol-tools-466ec6b22a51f0a9d618f6091ce6f9f533118280.tar.gz
dexon-sol-tools-466ec6b22a51f0a9d618f6091ce6f9f533118280.tar.bz2
dexon-sol-tools-466ec6b22a51f0a9d618f6091ce6f9f533118280.tar.lz
dexon-sol-tools-466ec6b22a51f0a9d618f6091ce6f9f533118280.tar.xz
dexon-sol-tools-466ec6b22a51f0a9d618f6091ce6f9f533118280.tar.zst
dexon-sol-tools-466ec6b22a51f0a9d618f6091ce6f9f533118280.zip
Change LiquidityForAssetData to return a BigNumber instead of a number to avoid losing precision
-rw-r--r--packages/asset-buyer/src/asset_buyer.ts4
-rw-r--r--packages/asset-buyer/src/types.ts4
-rw-r--r--packages/asset-buyer/src/utils/calculate_liquidity.ts4
-rw-r--r--packages/asset-buyer/test/asset_buyer_test.ts28
4 files changed, 20 insertions, 20 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts
index b4b024d62..4344f070c 100644
--- a/packages/asset-buyer/src/asset_buyer.ts
+++ b/packages/asset-buyer/src/asset_buyer.ts
@@ -200,8 +200,8 @@ export class AssetBuyer {
const etherTokenAssetData = this._getEtherTokenAssetDataOrThrow();
if (!assetPairs.includes(etherTokenAssetData)) {
return {
- tokensAvailableInBaseUnits: 0,
- ethValueAvailableInWei: 0,
+ tokensAvailableInBaseUnits: new BigNumber(0),
+ ethValueAvailableInWei: new BigNumber(0),
};
}
diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts
index 9208a3217..46a2338ce 100644
--- a/packages/asset-buyer/src/types.ts
+++ b/packages/asset-buyer/src/types.ts
@@ -137,6 +137,6 @@ export interface OrdersAndFillableAmounts {
* Represents available liquidity for a given assetData
*/
export interface LiquidityForAssetData {
- tokensAvailableInBaseUnits: number;
- ethValueAvailableInWei: number;
+ tokensAvailableInBaseUnits: BigNumber;
+ ethValueAvailableInWei: BigNumber;
}
diff --git a/packages/asset-buyer/src/utils/calculate_liquidity.ts b/packages/asset-buyer/src/utils/calculate_liquidity.ts
index 910c756ac..a8d165b4b 100644
--- a/packages/asset-buyer/src/utils/calculate_liquidity.ts
+++ b/packages/asset-buyer/src/utils/calculate_liquidity.ts
@@ -28,7 +28,7 @@ export const calculateLiquidity = (ordersAndFillableAmounts: OrdersAndFillableAm
// Turn into regular numbers
return {
- tokensAvailableInBaseUnits: liquidityInBigNumbers.tokensAvailableInBaseUnits.toNumber(),
- ethValueAvailableInWei: liquidityInBigNumbers.ethValueAvailableInWei.toNumber(),
+ tokensAvailableInBaseUnits: liquidityInBigNumbers.tokensAvailableInBaseUnits,
+ ethValueAvailableInWei: liquidityInBigNumbers.ethValueAvailableInWei,
};
};
diff --git a/packages/asset-buyer/test/asset_buyer_test.ts b/packages/asset-buyer/test/asset_buyer_test.ts
index 9ed51f5e5..f117b4d7a 100644
--- a/packages/asset-buyer/test/asset_buyer_test.ts
+++ b/packages/asset-buyer/test/asset_buyer_test.ts
@@ -84,8 +84,8 @@ describe('AssetBuyer', () => {
const assetBuyer = new AssetBuyer(mockWeb3Provider.object, mockOrderProvider.object);
const liquidityResult = await assetBuyer.getLiquidityForAssetDataAsync(FAKE_ASSET_DATA);
expect(liquidityResult).to.deep.equal({
- tokensAvailableInBaseUnits: 0,
- ethValueAvailableInWei: 0,
+ tokensAvailableInBaseUnits: new BigNumber(0),
+ ethValueAvailableInWei: new BigNumber(0),
});
});
it('should return 0s when only other asset pair supported', async () => {
@@ -94,8 +94,8 @@ describe('AssetBuyer', () => {
const assetBuyer = new AssetBuyer(mockWeb3Provider.object, mockOrderProvider.object);
const liquidityResult = await assetBuyer.getLiquidityForAssetDataAsync(FAKE_ASSET_DATA);
expect(liquidityResult).to.deep.equal({
- tokensAvailableInBaseUnits: 0,
- ethValueAvailableInWei: 0,
+ tokensAvailableInBaseUnits: new BigNumber(0),
+ ethValueAvailableInWei: new BigNumber(0),
});
});
});
@@ -121,8 +121,8 @@ describe('AssetBuyer', () => {
remainingFillableMakerAssetAmounts: [],
};
const expectedResult = {
- tokensAvailableInBaseUnits: 0,
- ethValueAvailableInWei: 0,
+ tokensAvailableInBaseUnits: new BigNumber(0),
+ ethValueAvailableInWei: new BigNumber(0),
};
await expectLiquidityResult(
mockWeb3Provider.object,
@@ -142,8 +142,8 @@ describe('AssetBuyer', () => {
const expectedTokensAvailable = orders[0].makerAssetAmount.plus(orders[1].makerAssetAmount);
const expectedEthValueAvailable = orders[0].takerAssetAmount.plus(orders[1].takerAssetAmount);
const expectedResult = {
- tokensAvailableInBaseUnits: expectedTokensAvailable.toNumber(),
- ethValueAvailableInWei: expectedEthValueAvailable.toNumber(),
+ tokensAvailableInBaseUnits: expectedTokensAvailable,
+ ethValueAvailableInWei: expectedEthValueAvailable,
};
await expectLiquidityResult(
@@ -160,8 +160,8 @@ describe('AssetBuyer', () => {
remainingFillableMakerAssetAmounts: [baseUnitAmount(1)],
};
const expectedResult = {
- tokensAvailableInBaseUnits: baseUnitAmount(1).toNumber(),
- ethValueAvailableInWei: baseUnitAmount(0.5, WETH_DECIMALS).toNumber(),
+ tokensAvailableInBaseUnits: baseUnitAmount(1),
+ ethValueAvailableInWei: baseUnitAmount(0.5, WETH_DECIMALS),
};
await expectLiquidityResult(
@@ -178,8 +178,8 @@ describe('AssetBuyer', () => {
remainingFillableMakerAssetAmounts: [baseUnitAmount(1), baseUnitAmount(3)],
};
const expectedResult = {
- tokensAvailableInBaseUnits: baseUnitAmount(4).toNumber(),
- ethValueAvailableInWei: baseUnitAmount(3.5, WETH_DECIMALS).toNumber(),
+ tokensAvailableInBaseUnits: baseUnitAmount(4),
+ ethValueAvailableInWei: baseUnitAmount(3.5, WETH_DECIMALS),
};
await expectLiquidityResult(
@@ -196,8 +196,8 @@ describe('AssetBuyer', () => {
remainingFillableMakerAssetAmounts: [baseUnitAmount(0), baseUnitAmount(0)],
};
const expectedResult = {
- tokensAvailableInBaseUnits: baseUnitAmount(0).toNumber(),
- ethValueAvailableInWei: baseUnitAmount(0, WETH_DECIMALS).toNumber(),
+ tokensAvailableInBaseUnits: baseUnitAmount(0),
+ ethValueAvailableInWei: baseUnitAmount(0, WETH_DECIMALS),
};
await expectLiquidityResult(