aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/asset-buyer/src/asset_buyer.ts8
-rw-r--r--packages/asset-buyer/src/types.ts2
-rw-r--r--packages/asset-buyer/test/asset_buyer_test.ts51
3 files changed, 29 insertions, 32 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts
index 511c99fb1..92a99c28c 100644
--- a/packages/asset-buyer/src/asset_buyer.ts
+++ b/packages/asset-buyer/src/asset_buyer.ts
@@ -45,19 +45,19 @@ const calculateLiquidity = (ordersAndFillableAmounts: OrdersAndFillableAmounts):
const tokensAvailableForCurrentOrder = availableMakerAssetAmount;
const ethValueAvailableForCurrentOrder = orderUtils.getTakerFillAmount(order, availableMakerAssetAmount);
return {
- tokensAvailableInUnitAmount: acc.tokensAvailableInUnitAmount.plus(tokensAvailableForCurrentOrder),
+ tokensAvailableInBaseUnits: acc.tokensAvailableInBaseUnits.plus(tokensAvailableForCurrentOrder),
ethValueAvailableInWei: acc.ethValueAvailableInWei.plus(ethValueAvailableForCurrentOrder),
};
},
{
- tokensAvailableInUnitAmount: new BigNumber(0),
+ tokensAvailableInBaseUnits: new BigNumber(0),
ethValueAvailableInWei: new BigNumber(0),
},
);
// Turn into regular numbers
return {
- tokensAvailableInUnitAmount: liquidityInBigNumbers.tokensAvailableInUnitAmount.toNumber(),
+ tokensAvailableInBaseUnits: liquidityInBigNumbers.tokensAvailableInBaseUnits.toNumber(),
ethValueAvailableInWei: liquidityInBigNumbers.ethValueAvailableInWei.toNumber(),
};
};
@@ -225,7 +225,7 @@ export class AssetBuyer {
const assetPairs = await this.orderProvider.getAvailableMakerAssetDatasAsync(assetData);
if (!assetPairs.includes(assetData)) {
return {
- tokensAvailableInUnitAmount: 0,
+ tokensAvailableInBaseUnits: 0,
ethValueAvailableInWei: 0,
};
}
diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts
index 84434aa7f..71822c4d7 100644
--- a/packages/asset-buyer/src/types.ts
+++ b/packages/asset-buyer/src/types.ts
@@ -126,6 +126,6 @@ export interface OrdersAndFillableAmounts {
* Represents available liquidity for a given assetData
*/
export interface LiquidityForAssetData {
- tokensAvailableInUnitAmount: number;
+ tokensAvailableInBaseUnits: number;
ethValueAvailableInWei: number;
}
diff --git a/packages/asset-buyer/test/asset_buyer_test.ts b/packages/asset-buyer/test/asset_buyer_test.ts
index fd31b9843..5e05d5564 100644
--- a/packages/asset-buyer/test/asset_buyer_test.ts
+++ b/packages/asset-buyer/test/asset_buyer_test.ts
@@ -81,7 +81,7 @@ describe('AssetBuyer', () => {
const assetBuyer = new AssetBuyer(mockWeb3Provider.object, mockOrderProvider.object);
const liquidityResult = await assetBuyer.getLiquidityForAssetDataAsync(FAKE_ASSET_DATA);
expect(liquidityResult).to.deep.equal({
- tokensAvailableInUnitAmount: 0,
+ tokensAvailableInBaseUnits: 0,
ethValueAvailableInWei: 0,
});
});
@@ -106,41 +106,38 @@ describe('AssetBuyer', () => {
orders: [],
remainingFillableMakerAssetAmounts: [],
};
- const mockedAssetBuyer = mockedAssetBuyerWithOrdersAndFillableAmounts(
+ const expectedResult = {
+ tokensAvailableInBaseUnits: 0,
+ ethValueAvailableInWei: 0,
+ };
+ await expectLiquidityResult(
mockWeb3Provider.object,
mockOrderProvider.object,
- FAKE_ASSET_DATA,
ordersAndFillableAmounts,
+ expectedResult,
);
-
- const liquidityResult = await mockedAssetBuyer.object.getLiquidityForAssetDataAsync(FAKE_ASSET_DATA);
- expect(liquidityResult).to.deep.equal({
- tokensAvailableInUnitAmount: 0,
- ethValueAvailableInWei: 0,
- });
});
it('should return correct computed value when orders provided with full fillableAmounts', async () => {
const orders: SignedOrder[] = [sellTwoTokensFor1Weth, sellTenTokensFor10Weth];
- const remainingFillableMakerAssetAmounts: BigNumber[] = orders.map(o => o.makerAssetAmount);
- const mockedAssetBuyer = mockedAssetBuyerWithOrdersAndFillableAmounts(
- mockWeb3Provider.object,
- mockOrderProvider.object,
- FAKE_ASSET_DATA,
- {
- orders,
- remainingFillableMakerAssetAmounts,
- },
- );
+ const ordersAndFillableAmounts = {
+ orders: [sellTwoTokensFor1Weth, sellTenTokensFor10Weth],
+ remainingFillableMakerAssetAmounts: orders.map(o => o.makerAssetAmount),
+ };
const expectedTokensAvailable = orders[0].makerAssetAmount.plus(orders[1].makerAssetAmount);
const expectedEthValueAvailable = orders[0].takerAssetAmount.plus(orders[1].takerAssetAmount);
-
- const liquidityResult = await mockedAssetBuyer.object.getLiquidityForAssetDataAsync(FAKE_ASSET_DATA);
- expect(liquidityResult).to.deep.equal({
- tokensAvailableInUnitAmount: expectedTokensAvailable.toNumber(),
+ const expectedResult = {
+ tokensAvailableInBaseUnits: expectedTokensAvailable.toNumber(),
ethValueAvailableInWei: expectedEthValueAvailable.toNumber(),
- });
+ };
+
+ await expectLiquidityResult(
+ mockWeb3Provider.object,
+ mockOrderProvider.object,
+ ordersAndFillableAmounts,
+ expectedResult,
+ );
});
it('should return correct computed value with one partial fillableAmounts', async () => {
@@ -149,7 +146,7 @@ describe('AssetBuyer', () => {
remainingFillableMakerAssetAmounts: [baseUnitAmount(1)],
};
const expectedResult = {
- tokensAvailableInUnitAmount: baseUnitAmount(1).toNumber(),
+ tokensAvailableInBaseUnits: baseUnitAmount(1).toNumber(),
ethValueAvailableInWei: baseUnitAmount(0.5, WETH_DECIMALS).toNumber(),
};
@@ -167,7 +164,7 @@ describe('AssetBuyer', () => {
remainingFillableMakerAssetAmounts: [baseUnitAmount(1), baseUnitAmount(3)],
};
const expectedResult = {
- tokensAvailableInUnitAmount: baseUnitAmount(4).toNumber(),
+ tokensAvailableInBaseUnits: baseUnitAmount(4).toNumber(),
ethValueAvailableInWei: baseUnitAmount(3.5, WETH_DECIMALS).toNumber(),
};
@@ -185,7 +182,7 @@ describe('AssetBuyer', () => {
remainingFillableMakerAssetAmounts: [baseUnitAmount(0), baseUnitAmount(0)],
};
const expectedResult = {
- tokensAvailableInUnitAmount: baseUnitAmount(0).toNumber(),
+ tokensAvailableInBaseUnits: baseUnitAmount(0).toNumber(),
ethValueAvailableInWei: baseUnitAmount(0, WETH_DECIMALS).toNumber(),
};