Fix incorrect affiliate fee calculations and associated tests
This commit is contained in:
parent
cb1311ecc5
commit
f9f8e06c1c
@ -72,7 +72,6 @@ export const buyQuoteCalculator = {
|
|||||||
assetBuyAmount,
|
assetBuyAmount,
|
||||||
feePercentage,
|
feePercentage,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
assetData,
|
assetData,
|
||||||
orders: resultOrders,
|
orders: resultOrders,
|
||||||
@ -98,13 +97,14 @@ function calculateQuoteInfo(
|
|||||||
);
|
);
|
||||||
// find the total eth needed to buy fees
|
// find the total eth needed to buy fees
|
||||||
const ethAmountToBuyFees = findEthAmountNeededToBuyFees(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset);
|
const ethAmountToBuyFees = findEthAmountNeededToBuyFees(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset);
|
||||||
const ethAmountBeforeAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyFees);
|
const affiliateFeeEthAmount = ethAmountToBuyAsset.mul(feePercentage);
|
||||||
const totalEthAmount = ethAmountBeforeAffiliateFee.mul(feePercentage + 1);
|
const totalEthAmountWithoutAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyFees);
|
||||||
|
const totalEthAmount = totalEthAmountWithoutAffiliateFee.plus(affiliateFeeEthAmount);
|
||||||
// divide into the assetBuyAmount in order to find rate of makerAsset / WETH
|
// divide into the assetBuyAmount in order to find rate of makerAsset / WETH
|
||||||
const ethPerAssetPrice = ethAmountBeforeAffiliateFee.div(assetBuyAmount);
|
const ethPerAssetPrice = totalEthAmountWithoutAffiliateFee.div(assetBuyAmount);
|
||||||
return {
|
return {
|
||||||
totalEthAmount,
|
totalEthAmount,
|
||||||
feeEthAmount: totalEthAmount.minus(ethAmountBeforeAffiliateFee),
|
feeEthAmount: affiliateFeeEthAmount,
|
||||||
ethPerAssetPrice,
|
ethPerAssetPrice,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -103,9 +103,11 @@ describe('buyQuoteCalculator', () => {
|
|||||||
expect(buyQuote.feeOrders).to.deep.equal([smallFeeOrderAndFillableAmount.orders[0]]);
|
expect(buyQuote.feeOrders).to.deep.equal([smallFeeOrderAndFillableAmount.orders[0]]);
|
||||||
// test if rates are correct
|
// test if rates are correct
|
||||||
// 50 eth to fill the first order + 100 eth for fees
|
// 50 eth to fill the first order + 100 eth for fees
|
||||||
const expectedFillEthAmount = new BigNumber(150);
|
const expectedEthAmountForAsset = new BigNumber(50);
|
||||||
const expectedTotalEthAmount = expectedFillEthAmount.mul(feePercentage + 1);
|
const expectedEthAmountForZrxFees = new BigNumber(100);
|
||||||
const expectedFeeEthAmount = expectedTotalEthAmount.minus(expectedFillEthAmount);
|
const expectedFillEthAmount = expectedEthAmountForAsset.plus(expectedEthAmountForZrxFees);
|
||||||
|
const expectedFeeEthAmount = expectedEthAmountForAsset.mul(feePercentage);
|
||||||
|
const expectedTotalEthAmount = expectedFillEthAmount.plus(expectedFeeEthAmount);
|
||||||
const expectedEthPerAssetPrice = expectedFillEthAmount.div(assetBuyAmount);
|
const expectedEthPerAssetPrice = expectedFillEthAmount.div(assetBuyAmount);
|
||||||
expect(buyQuote.bestCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
|
expect(buyQuote.bestCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
|
||||||
expect(buyQuote.bestCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
|
expect(buyQuote.bestCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
|
||||||
@ -138,17 +140,21 @@ describe('buyQuoteCalculator', () => {
|
|||||||
expect(buyQuote.feeOrders).to.deep.equal(allFeeOrdersAndFillableAmounts.orders);
|
expect(buyQuote.feeOrders).to.deep.equal(allFeeOrdersAndFillableAmounts.orders);
|
||||||
// test if rates are correct
|
// test if rates are correct
|
||||||
// 50 eth to fill the first order + 100 eth for fees
|
// 50 eth to fill the first order + 100 eth for fees
|
||||||
const expectedFillEthAmount = new BigNumber(150);
|
const expectedEthAmountForAsset = new BigNumber(50);
|
||||||
const expectedTotalEthAmount = expectedFillEthAmount.mul(feePercentage + 1);
|
const expectedEthAmountForZrxFees = new BigNumber(100);
|
||||||
const expectedFeeEthAmount = expectedTotalEthAmount.minus(expectedFillEthAmount);
|
const expectedFillEthAmount = expectedEthAmountForAsset.plus(expectedEthAmountForZrxFees);
|
||||||
|
const expectedFeeEthAmount = expectedEthAmountForAsset.mul(feePercentage);
|
||||||
|
const expectedTotalEthAmount = expectedFillEthAmount.plus(expectedFeeEthAmount);
|
||||||
const expectedEthPerAssetPrice = expectedFillEthAmount.div(assetBuyAmount);
|
const expectedEthPerAssetPrice = expectedFillEthAmount.div(assetBuyAmount);
|
||||||
expect(buyQuote.bestCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
|
expect(buyQuote.bestCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedFeeEthAmount);
|
||||||
expect(buyQuote.bestCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
|
expect(buyQuote.bestCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedTotalEthAmount);
|
||||||
expect(buyQuote.bestCaseQuoteInfo.ethPerAssetPrice).to.bignumber.equal(expectedEthPerAssetPrice);
|
expect(buyQuote.bestCaseQuoteInfo.ethPerAssetPrice).to.bignumber.equal(expectedEthPerAssetPrice);
|
||||||
// 100 eth to fill the first order + 200 eth for fees
|
// 100 eth to fill the first order + 200 eth for fees
|
||||||
const expectedWorstFillEthAmount = new BigNumber(300);
|
const expectedWorstEthAmountForAsset = new BigNumber(100);
|
||||||
const expectedWorstTotalEthAmount = expectedWorstFillEthAmount.mul(feePercentage + 1);
|
const expectedWorstEthAmountForZrxFees = new BigNumber(200);
|
||||||
const expectedWorstFeeEthAmount = expectedWorstTotalEthAmount.minus(expectedWorstFillEthAmount);
|
const expectedWorstFillEthAmount = expectedWorstEthAmountForAsset.plus(expectedWorstEthAmountForZrxFees);
|
||||||
|
const expectedWorstFeeEthAmount = expectedWorstEthAmountForAsset.mul(feePercentage);
|
||||||
|
const expectedWorstTotalEthAmount = expectedWorstFillEthAmount.plus(expectedWorstFeeEthAmount);
|
||||||
const expectedWorstEthPerAssetPrice = expectedWorstFillEthAmount.div(assetBuyAmount);
|
const expectedWorstEthPerAssetPrice = expectedWorstFillEthAmount.div(assetBuyAmount);
|
||||||
expect(buyQuote.worstCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedWorstFeeEthAmount);
|
expect(buyQuote.worstCaseQuoteInfo.feeEthAmount).to.bignumber.equal(expectedWorstFeeEthAmount);
|
||||||
expect(buyQuote.worstCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedWorstTotalEthAmount);
|
expect(buyQuote.worstCaseQuoteInfo.totalEthAmount).to.bignumber.equal(expectedWorstTotalEthAmount);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user