addressed reviews and light refactor

added comments to types and refactored some naming
This commit is contained in:
David Sun
2019-06-19 10:29:18 -07:00
parent 59001f827b
commit 222f7e6fd4
15 changed files with 337 additions and 311 deletions

View File

@@ -0,0 +1,24 @@
import { BigNumber } from '@0x/utils';
import * as _ from 'lodash';
import { SwapQuote, SwapQuoteInfo } from '../types';
export const affiliateFeeUtils = {
getSwapQuoteWithAffiliateFee(quote: SwapQuote, feePercentage: number): SwapQuote {
const newQuote = _.clone(quote);
newQuote.bestCaseQuoteInfo = getSwapQuoteInfoWithAffiliateFee(newQuote.bestCaseQuoteInfo, feePercentage);
newQuote.worstCaseQuoteInfo = getSwapQuoteInfoWithAffiliateFee(newQuote.worstCaseQuoteInfo, feePercentage);
return newQuote;
},
};
const getSwapQuoteInfoWithAffiliateFee = (quoteInfo: SwapQuoteInfo, feePercentage: number): SwapQuoteInfo => {
const newQuoteInfo = _.clone(quoteInfo);
const affiliateFeeAmount = newQuoteInfo.takerTokenAmount
.multipliedBy(feePercentage)
.integerValue(BigNumber.ROUND_CEIL);
const newFeeAmount = newQuoteInfo.feeTakerTokenAmount.plus(affiliateFeeAmount);
newQuoteInfo.feeTakerTokenAmount = newFeeAmount;
newQuoteInfo.totalTakerTokenAmount = newFeeAmount.plus(newQuoteInfo.takerTokenAmount);
return newQuoteInfo;
};