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

Fix: FOT token tax retrieval source #148

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/entities/pair.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand Down
9 changes: 7 additions & 2 deletions src/entities/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export class Pair {
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
*
* @param inputAmount
* @param calculateFotFees
*/
public getOutputAmount(
inputAmount: CurrencyAmount<Token>,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Loading