-
Notifications
You must be signed in to change notification settings - Fork 238
feat: Add support for buy token affiliate fees #310
Conversation
fbdfcd9
to
343123f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lookin good to me, one question about the way the new buyAmount
is scaled.
deploy staging |
7e87547
to
796c89c
Compare
deploy staging |
796c89c
to
5acb974
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌 Thanks again for taking this on.
@@ -479,10 +492,13 @@ export class SwapService { | |||
assetSwapperOpts, | |||
); | |||
} else if (buyAmount !== undefined) { | |||
const buyAmountScaled = buyAmount | |||
.times(affiliateFee.buyTokenPercentageFee + 1) | |||
.integerValue(BigNumber.ROUND_DOWN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should be ROUND_UP
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the rounding mode needs to be the same between this and getAffiliateFeeAmounts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it possible we'll be under by 1 wei after the affiliate fee is taken out by the transformer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to work out the math but gave up
for (let i = 0; i < 100000; i++) {
it(`Test ${i}`, () => {
const buyAmount = getRandomInteger(0, constants.ONE_ETHER);
const buyTokenPercentageFee = getRandomFloat(0, 1);
const buyAmountScaled = buyAmount.times(buyTokenPercentageFee.plus(1)).integerValue(BigNumber.ROUND_DOWN);
const buyTokenFeeAmount = buyAmountScaled
.times(buyTokenPercentageFee)
.dividedBy(buyTokenPercentageFee.plus(1))
.integerValue(BigNumber.ROUND_DOWN);
expect(buyAmountScaled.minus(buyTokenFeeAmount)).to.bignumber.equal(buyAmount);
});
}
100000 passing (26s)
const buyTokenFeeAmount = quote.worstCaseQuoteInfo.makerAssetAmount | ||
.times(fee.buyTokenPercentageFee) | ||
.dividedBy(fee.buyTokenPercentageFee + 1) | ||
.integerValue(BigNumber.ROUND_DOWN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that the the fee is only off the guaranteed price.
deploy staging |
5acb974
to
675965a
Compare
deploy production |
# [1.14.0](v1.13.0...v1.14.0) (2020-08-10) ### Bug Fixes * handle addresses in depth ([#313](#313)) ([ce6978b](ce6978b)) * return input in depth-chart ([#307](#307)) ([a3fa961](a3fa961)) * source regression ([#306](#306)) ([cdcfc78](cdcfc78)) * update asset-swapper optimizer for splits ([#311](#311)) ([5b212c9](5b212c9)) ### Features * Add support for buy token affiliate fees ([#310](#310)) ([2866253](2866253)) * ethToInputRate cost routing ([#315](#315)) ([e542c98](e542c98))
🎉 This PR is included in version 1.14.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Description
Testing Instructions
Checklist
[WIP]
if necessary.