aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src/utils/buy_quote_calculator.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-11-14 09:09:58 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-11-14 09:09:58 +0800
commitda9de70bbcecc16fa3a7f6991623f5027628f2b3 (patch)
tree5ec1cdef371604aa360eeae4ae7cde3190a8783d /packages/asset-buyer/src/utils/buy_quote_calculator.ts
parentf03afe6f1b6a6bfa339507ee47b42c62550444a0 (diff)
parente02dc13805349a770506350c69e9061f596b48b2 (diff)
downloaddexon-0x-contracts-da9de70bbcecc16fa3a7f6991623f5027628f2b3.tar
dexon-0x-contracts-da9de70bbcecc16fa3a7f6991623f5027628f2b3.tar.gz
dexon-0x-contracts-da9de70bbcecc16fa3a7f6991623f5027628f2b3.tar.bz2
dexon-0x-contracts-da9de70bbcecc16fa3a7f6991623f5027628f2b3.tar.lz
dexon-0x-contracts-da9de70bbcecc16fa3a7f6991623f5027628f2b3.tar.xz
dexon-0x-contracts-da9de70bbcecc16fa3a7f6991623f5027628f2b3.tar.zst
dexon-0x-contracts-da9de70bbcecc16fa3a7f6991623f5027628f2b3.zip
Merge https://github.com/0xProject/0x-monorepo into feature/instant/metamask-connect-flow
Diffstat (limited to 'packages/asset-buyer/src/utils/buy_quote_calculator.ts')
-rw-r--r--packages/asset-buyer/src/utils/buy_quote_calculator.ts28
1 files changed, 14 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 6a67ed1ed..b15b880c2 100644
--- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts
+++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts
@@ -106,28 +106,28 @@ function calculateQuoteInfo(
isMakerAssetZrxToken: boolean,
): BuyQuoteInfo {
// find the total eth and zrx needed to buy assetAmount from the resultOrders from left to right
- let ethAmountToBuyAsset = constants.ZERO_AMOUNT;
- let ethAmountToBuyZrx = constants.ZERO_AMOUNT;
+ let assetEthAmount = constants.ZERO_AMOUNT;
+ let zrxEthAmount = constants.ZERO_AMOUNT;
if (isMakerAssetZrxToken) {
- ethAmountToBuyAsset = findEthAmountNeededToBuyZrx(ordersAndFillableAmounts, assetBuyAmount);
+ assetEthAmount = findEthAmountNeededToBuyZrx(ordersAndFillableAmounts, assetBuyAmount);
} else {
// find eth and zrx amounts needed to buy
const ethAndZrxAmountToBuyAsset = findEthAndZrxAmountNeededToBuyAsset(ordersAndFillableAmounts, assetBuyAmount);
- ethAmountToBuyAsset = ethAndZrxAmountToBuyAsset[0];
+ assetEthAmount = ethAndZrxAmountToBuyAsset[0];
const zrxAmountToBuyAsset = ethAndZrxAmountToBuyAsset[1];
// find eth amount needed to buy zrx
- ethAmountToBuyZrx = findEthAmountNeededToBuyZrx(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset);
+ zrxEthAmount = findEthAmountNeededToBuyZrx(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset);
}
- /// find the eth amount needed to buy the affiliate fee
- const ethAmountToBuyAffiliateFee = ethAmountToBuyAsset.mul(feePercentage).ceil();
- const totalEthAmountWithoutAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyZrx);
- const ethAmountTotal = totalEthAmountWithoutAffiliateFee.plus(ethAmountToBuyAffiliateFee);
- // divide into the assetBuyAmount in order to find rate of makerAsset / WETH
- const ethPerAssetPrice = totalEthAmountWithoutAffiliateFee.div(assetBuyAmount);
+ // eth amount needed to buy the affiliate fee
+ const affiliateFeeEthAmount = assetEthAmount.mul(feePercentage).ceil();
+ // eth amount needed for fees is the sum of affiliate fee and zrx fee
+ const feeEthAmount = affiliateFeeEthAmount.plus(zrxEthAmount);
+ // eth amount needed in total is the sum of the amount needed for the asset and the amount needed for fees
+ const totalEthAmount = assetEthAmount.plus(feeEthAmount);
return {
- totalEthAmount: ethAmountTotal,
- feeEthAmount: ethAmountToBuyAffiliateFee,
- ethPerAssetPrice,
+ assetEthAmount,
+ feeEthAmount,
+ totalEthAmount,
};
}