-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Receive an option to decide if we calculate FOT tax or not #146
Conversation
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 |
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.
hmm shouldnt this be 100% instead of 0? this refers to the % of inputAmount
that goes into the v2 calculation right?
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.
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?
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.
It needs to be 0%. Although I think we can make it simpler by passing the calculateFotFees
to derivePercentAfterBuyFees
calculateFotFees = true | ||
}) | ||
|
||
describe('getOutputAmount', () => { |
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 think we need two tests for getOutputAmount
and two tests for getInputAmount
, making it a total of 4.
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 think I have the 4 tests
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