Commit d8c05dd8 authored by jsy1218's avatar jsy1218 Committed by GitHub

Fix: FOT token tax retrieval source (#148)

* v3.2.2

* fix fot token tax retrieval source

* Fix code style issues with Prettier

* revert version change here

---------
Co-authored-by: default avatarLint Action <lint-action@samuelmeuli.com>
parent 53e3b8e9
......@@ -186,6 +186,14 @@ describe('Pair', () => {
BLASTBuyFeeBps,
BLASTSellFeeBps
)
const BLAST_WIHTOUT_TAX = new Token(
ChainId.MAINNET,
'0x3ed643e9032230f01c6c36060e305ab53ad3b482',
18,
'BLAST',
'BLAST',
false
)
const BLASTERSBuyFeeBps = BigNumber.from(300)
const BLASTERSSellFeeBps = BigNumber.from(350)
const BLASTERS = new Token(
......@@ -198,6 +206,14 @@ describe('Pair', () => {
BLASTERSBuyFeeBps,
BLASTERSSellFeeBps
)
const BLASTERS_WITHOUT_TAX = new Token(
ChainId.MAINNET,
'0xab98093C7232E98A47D7270CE0c1c2106f61C73b',
9,
'BLAST',
'BLASTERS',
false
)
let calculateFotFees: boolean = false
......@@ -213,7 +229,7 @@ describe('Pair', () => {
const pair = new Pair(reserveBlasterAmount, reserveBlastAmount)
const inputBlastersAmount = CurrencyAmount.fromRawAmount(BLASTERS, '100')
const inputBlastersAmount = CurrencyAmount.fromRawAmount(BLASTERS_WITHOUT_TAX, '100')
const [outputBlastAmount] = pair.getOutputAmount(inputBlastersAmount, calculateFotFees)
// Theoretical amount out:
......@@ -246,7 +262,7 @@ describe('Pair', () => {
const pair = new Pair(reserveBlasterAmount, reserveBlastAmount)
const outputBlastAmount = CurrencyAmount.fromRawAmount(BLAST, '91')
const outputBlastAmount = CurrencyAmount.fromRawAmount(BLAST_WIHTOUT_TAX, '91')
const [inputBlasterAmount] = pair.getInputAmount(outputBlastAmount, calculateFotFees)
// Theoretical amount in:
......@@ -294,7 +310,7 @@ describe('Pair', () => {
const pair = new Pair(reserveBlasterAmount, reserveBlastAmount)
const inputBlastersAmount = CurrencyAmount.fromRawAmount(BLASTERS, '100')
const inputBlastersAmount = CurrencyAmount.fromRawAmount(BLASTERS_WITHOUT_TAX, '100')
const [outputBlastAmount] = pair.getOutputAmount(inputBlastersAmount, calculateFotFees)
const expectedOutputBlastAmount = '0.000000000000000098'
......@@ -307,7 +323,7 @@ describe('Pair', () => {
const pair = new Pair(reserveBlasterAmount, reserveBlastAmount)
const outputBlastAmount = CurrencyAmount.fromRawAmount(BLAST, '91')
const outputBlastAmount = CurrencyAmount.fromRawAmount(BLAST_WIHTOUT_TAX, '91')
const [inputBlasterAmount] = pair.getInputAmount(outputBlastAmount, calculateFotFees)
const expectedInputBlasterAmount = '0.000000093'
......
......@@ -177,6 +177,7 @@ export class Pair {
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
*
* @param inputAmount
* @param calculateFotFees
*/
public getOutputAmount(
inputAmount: CurrencyAmount<Token>,
......@@ -379,7 +380,9 @@ export class Pair {
}
private derivePercentAfterSellFees(inputAmount: CurrencyAmount<Token>): Percent {
const sellFeeBips = inputAmount.currency.sellFeeBps
const sellFeeBips = this.token0.wrapped.equals(inputAmount.wrapped.currency)
? this.token0.wrapped.sellFeeBps
: this.token1.wrapped.sellFeeBps
if (sellFeeBips?.gt(BigNumber.from(0))) {
return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS))
} else {
......@@ -388,7 +391,9 @@ export class Pair {
}
private derivePercentAfterBuyFees(outputAmount: CurrencyAmount<Token>): Percent {
const buyFeeBps = outputAmount.currency.buyFeeBps
const buyFeeBps = this.token0.wrapped.equals(outputAmount.wrapped.currency)
? this.token0.wrapped.buyFeeBps
: this.token1.wrapped.buyFeeBps
if (buyFeeBps?.gt(BigNumber.from(0))) {
return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS))
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment