change to affiliate fees

This commit is contained in:
David Sun
2019-06-20 16:30:47 -07:00
parent e1ab9aa690
commit 92a1e5413b
2 changed files with 9 additions and 4 deletions

View File

@@ -158,7 +158,7 @@ export interface SwapQuote {
/**
* assetEthAmount: The amount of eth required to pay for the requested asset.
* feeEthAmount: The amount of eth required to pay the affiliate fee.
* feeEthAmount: The amount of eth required to pay any fee concerned with an extension contract.
* totalEthAmount: The total amount of eth required to complete the buy (filling orders, feeOrders, and paying affiliate fee).
*/
export interface SwapQuoteInfo {

View File

@@ -12,13 +12,18 @@ export const affiliateFeeUtils = {
},
};
/**
* Adds a fee based on feePercentage of the takerTokenAmount and adds it to the feeTakerTokenAmount and totalTakerTokenAmount
* @param quoteInfo quote information to add fee to
* @param feePercentage the percentage of takerTokenAmount charged additionally as a fee
*/
const getSwapQuoteInfoWithAffiliateFee = (quoteInfo: SwapQuoteInfo, feePercentage: number): SwapQuoteInfo => {
const newQuoteInfo = _.clone(quoteInfo);
const affiliateFeeAmount = newQuoteInfo.takerTokenAmount
const affiliateFeeAmount = quoteInfo.takerTokenAmount
.multipliedBy(feePercentage)
.integerValue(BigNumber.ROUND_CEIL);
const newFeeAmount = newQuoteInfo.feeTakerTokenAmount.plus(affiliateFeeAmount);
const newFeeAmount = quoteInfo.feeTakerTokenAmount.plus(affiliateFeeAmount);
newQuoteInfo.feeTakerTokenAmount = newFeeAmount;
newQuoteInfo.totalTakerTokenAmount = newFeeAmount.plus(newQuoteInfo.takerTokenAmount);
newQuoteInfo.totalTakerTokenAmount = newFeeAmount.plus(quoteInfo.takerTokenAmount);
return newQuoteInfo;
};