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

Receive an option to decide if we calculate FOT tax or not #146

Merged
merged 2 commits into from
Sep 29, 2023

Conversation

mikeki
Copy link
Contributor

@mikeki mikeki commented Sep 29, 2023

Option to decide if we should calculate FOT tax

We are calculating FOT tax by default, but it's possible that we don't want to do that all the time.

This branch adds a flag (defaulting to false) to indicate if we should run this calculation

invariant(this.involvesToken(inputAmount.currency), 'TOKEN')
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) {
throw new InsufficientReservesError()
}
const inputReserve = this.reserveOf(inputAmount.currency)
const outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0)

const percentAfterSellFees = this.derivePercentAfterSellFees(inputAmount)
const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : ZERO_PERCENT

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm shouldnt this be 100% instead of 0? this refers to the % of inputAmount that goes into the v2 calculation right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function we use to derive returns ZERO_PERCENT when there's no fee:

  private derivePercentAfterSellFees(inputAmount: CurrencyAmount<Token>): Percent {
    const sellFeeBips = inputAmount.currency.sellFeeBps
    if (sellFeeBips?.gt(BigNumber.from(0))) {
      return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS))
    } else {
      return ZERO_PERCENT
    }
  }

  private derivePercentAfterBuyFees(outputAmount: CurrencyAmount<Token>): Percent {
    const buyFeeBps = outputAmount.currency.buyFeeBps
    if (buyFeeBps?.gt(BigNumber.from(0))) {
      return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS))
    } else {
      return ZERO_PERCENT
    }
  }

so I think that's okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be 0%. Although I think we can make it simpler by passing the calculateFotFees to derivePercentAfterBuyFees

calculateFotFees = true
})

describe('getOutputAmount', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need two tests for getOutputAmount and two tests for getInputAmount, making it a total of 4.

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 think I have the 4 tests

@mikeki mikeki merged commit 53e3b8e into main Sep 29, 2023
1 check passed
@mikeki mikeki deleted the mikeki/flag_to_calculate_or_not_fot branch September 29, 2023 21:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants