aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-10-06 06:42:19 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-10-06 06:42:19 +0800
commitf9f8e06c1c8ac5b254dfae08e216ea199a77ff02 (patch)
treeb658e45627e1ef63fb9d86c46db93ee50b13c61a /packages
parentcb1311ecc5889a0fd81b61f3ab7b66605d75960f (diff)
downloaddexon-sol-tools-f9f8e06c1c8ac5b254dfae08e216ea199a77ff02.tar
dexon-sol-tools-f9f8e06c1c8ac5b254dfae08e216ea199a77ff02.tar.gz
dexon-sol-tools-f9f8e06c1c8ac5b254dfae08e216ea199a77ff02.tar.bz2
dexon-sol-tools-f9f8e06c1c8ac5b254dfae08e216ea199a77ff02.tar.lz
dexon-sol-tools-f9f8e06c1c8ac5b254dfae08e216ea199a77ff02.tar.xz
dexon-sol-tools-f9f8e06c1c8ac5b254dfae08e216ea199a77ff02.tar.zst
dexon-sol-tools-f9f8e06c1c8ac5b254dfae08e216ea199a77ff02.zip
Fix incorrect affiliate fee calculations and associated tests
Diffstat (limited to 'packages')
-rw-r--r--packages/asset-buyer/src/utils/buy_quote_calculator.ts10
-rw-r--r--packages/asset-buyer/test/buy_quote_calculator_test.ts24
2 files changed, 20 insertions, 14 deletions
diff --git a/packages/asset-buyer/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts
index cb0fd128c..a1d334eef 100644
--- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts
+++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts
@@ -72,7 +72,6 @@ export const buyQuoteCalculator = {
assetBuyAmount,
feePercentage,
);
-
return {
assetData,
orders: resultOrders,
@@ -98,13 +97,14 @@ function calculateQuoteInfo(
);
// find the total eth needed to buy fees
const ethAmountToBuyFees = findEthAmountNeededToBuyFees(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset);
- const ethAmountBeforeAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyFees);
- const totalEthAmount = ethAmountBeforeAffiliateFee.mul(feePercentage + 1);
+ const affiliateFeeEthAmount = ethAmountToBuyAsset.mul(feePercentage);
+ const totalEthAmountWithoutAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyFees);
+ const totalEthAmount = totalEthAmountWithoutAffiliateFee.plus(affiliateFeeEthAmount);
// divide into the assetBuyAmount in order to find rate of makerAsset / WETH
- const ethPerAssetPrice = ethAmountBeforeAffiliateFee.div(assetBuyAmount);
+ const ethPerAssetPrice = totalEthAmountWithoutAffiliateFee.div(assetBuyAmount);
return {
totalEthAmount,
- feeEthAmount: totalEthAmount.minus(ethAmountBeforeAffiliateFee),
+ feeEthAmount: affiliateFeeEthAmount,
ethPerAssetPrice,
};
}
diff --git a/packages/asset-buyer/test/buy_quote_calculator_test.ts b/packages/asset-buyer/test/buy_quote_calculator_test.ts
index b987b45a8..fda6958cd 100644
--- a/packages/asset-buyer/test/buy_quote_calculator_test.ts
+++ b/packages/asset-buyer/test/buy_quote_calculator_test.ts
@@ -103,9 +103,11 @@ describe('buyQuoteCalculator', () => {
expect(buyQuote.feeOrders).to.deep.equal([smallFeeOrderAndFillableAmount.orders[0]]);
// test if rates are correct
// 50 eth to fill the first order + 100 eth for fees
- const expectedFillEthAmount = new BigNumber(150);
- const expectedTotalEthAmount = expectedFillEthAmount.mul(feePercentage + 1);
- const expectedFeeEthAmount = expectedTotalEthAmount.minus(expectedFillEthAmount);
+ const expectedEthAmountForAsset = new BigNumber(50);
+ const expectedEthAmountForZrxFees = new BigNumber(100);
+ const expectedFillEthAmount = expectedEthAmountForAsset.plus(expectedEthAmountForZrxFees);
+ const expectedFeeEthAmount = expectedEthAmountForAsset.mul(feePercentage);
+ const expectedTotalEthAmount = expectedFillEthAmount.plus(expectedFeeEthAmount);
const expectedEthPerAssetPrice = expectedFillEthAmount.div(assetBuyAmount);
expect(buyQuote.bestCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
expect(buyQuote.bestCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
@@ -138,17 +140,21 @@ describe('buyQuoteCalculator', () => {
expect(buyQuote.feeOrders).to.deep.equal(allFeeOrdersAndFillableAmounts.orders);
// test if rates are correct
// 50 eth to fill the first order + 100 eth for fees
- const expectedFillEthAmount = new BigNumber(150);
- const expectedTotalEthAmount = expectedFillEthAmount.mul(feePercentage + 1);
- const expectedFeeEthAmount = expectedTotalEthAmount.minus(expectedFillEthAmount);
+ const expectedEthAmountForAsset = new BigNumber(50);
+ const expectedEthAmountForZrxFees = new BigNumber(100);
+ const expectedFillEthAmount = expectedEthAmountForAsset.plus(expectedEthAmountForZrxFees);
+ const expectedFeeEthAmount = expectedEthAmountForAsset.mul(feePercentage);
+ const expectedTotalEthAmount = expectedFillEthAmount.plus(expectedFeeEthAmount);
const expectedEthPerAssetPrice = expectedFillEthAmount.div(assetBuyAmount);
expect(buyQuote.bestCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
expect(buyQuote.bestCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
expect(buyQuote.bestCaseQuoteInfo.ethPerAssetPrice).to.bignumber.equal(expectedEthPerAssetPrice);
// 100 eth to fill the first order + 200 eth for fees
- const expectedWorstFillEthAmount = new BigNumber(300);
- const expectedWorstTotalEthAmount = expectedWorstFillEthAmount.mul(feePercentage + 1);
- const expectedWorstFeeEthAmount = expectedWorstTotalEthAmount.minus(expectedWorstFillEthAmount);
+ const expectedWorstEthAmountForAsset = new BigNumber(100);
+ const expectedWorstEthAmountForZrxFees = new BigNumber(200);
+ const expectedWorstFillEthAmount = expectedWorstEthAmountForAsset.plus(expectedWorstEthAmountForZrxFees);
+ const expectedWorstFeeEthAmount = expectedWorstEthAmountForAsset.mul(feePercentage);
+ const expectedWorstTotalEthAmount = expectedWorstFillEthAmount.plus(expectedWorstFeeEthAmount);
const expectedWorstEthPerAssetPrice = expectedWorstFillEthAmount.div(assetBuyAmount);
expect(buyQuote.worstCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedWorstFeeEthAmount);
expect(buyQuote.worstCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedWorstTotalEthAmount);