Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

feat: Add support for buy token affiliate fees #310

Merged
merged 2 commits into from
Aug 7, 2020

Conversation

moodlezoup
Copy link
Contributor

@moodlezoup moodlezoup commented Aug 6, 2020

Description

Testing Instructions

Checklist

  • Update documentation as needed. Website Documentation PR:
  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.

@moodlezoup moodlezoup force-pushed the feature/affiliate-fees branch from fbdfcd9 to 343123f Compare August 6, 2020 05:36
Copy link
Member

@dekz dekz left a 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.

@moodlezoup moodlezoup changed the title Add support for buy token affiliate fees feat: Add support for buy token affiliate fees Aug 6, 2020
@moodlezoup
Copy link
Contributor Author

deploy staging

@moodlezoup moodlezoup force-pushed the feature/affiliate-fees branch from 7e87547 to 796c89c Compare August 6, 2020 18:36
@moodlezoup
Copy link
Contributor Author

deploy staging

@moodlezoup moodlezoup force-pushed the feature/affiliate-fees branch from 796c89c to 5acb974 Compare August 6, 2020 23:28
Copy link
Contributor

@dorothy-zbornak dorothy-zbornak left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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)

Comment on lines +212 to +215
const buyTokenFeeAmount = quote.worstCaseQuoteInfo.makerAssetAmount
.times(fee.buyTokenPercentageFee)
.dividedBy(fee.buyTokenPercentageFee + 1)
.integerValue(BigNumber.ROUND_DOWN);
Copy link
Contributor

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.

@moodlezoup
Copy link
Contributor Author

deploy staging

@moodlezoup moodlezoup force-pushed the feature/affiliate-fees branch from 5acb974 to 675965a Compare August 7, 2020 03:49
@moodlezoup
Copy link
Contributor Author

deploy production

@moodlezoup moodlezoup merged commit 2866253 into master Aug 7, 2020
@moodlezoup moodlezoup deleted the feature/affiliate-fees branch August 7, 2020 04:04
github-actions bot pushed a commit that referenced this pull request Aug 10, 2020
# [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))
@github-actions
Copy link

🎉 This PR is included in version 1.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants