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', () => { ...@@ -186,6 +186,14 @@ describe('Pair', () => {
BLASTBuyFeeBps, BLASTBuyFeeBps,
BLASTSellFeeBps BLASTSellFeeBps
) )
const BLAST_WIHTOUT_TAX = new Token(
ChainId.MAINNET,
'0x3ed643e9032230f01c6c36060e305ab53ad3b482',
18,
'BLAST',
'BLAST',
false
)
const BLASTERSBuyFeeBps = BigNumber.from(300) const BLASTERSBuyFeeBps = BigNumber.from(300)
const BLASTERSSellFeeBps = BigNumber.from(350) const BLASTERSSellFeeBps = BigNumber.from(350)
const BLASTERS = new Token( const BLASTERS = new Token(
...@@ -198,6 +206,14 @@ describe('Pair', () => { ...@@ -198,6 +206,14 @@ describe('Pair', () => {
BLASTERSBuyFeeBps, BLASTERSBuyFeeBps,
BLASTERSSellFeeBps BLASTERSSellFeeBps
) )
const BLASTERS_WITHOUT_TAX = new Token(
ChainId.MAINNET,
'0xab98093C7232E98A47D7270CE0c1c2106f61C73b',
9,
'BLAST',
'BLASTERS',
false
)
let calculateFotFees: boolean = false let calculateFotFees: boolean = false
...@@ -213,7 +229,7 @@ describe('Pair', () => { ...@@ -213,7 +229,7 @@ describe('Pair', () => {
const pair = new Pair(reserveBlasterAmount, reserveBlastAmount) 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 [outputBlastAmount] = pair.getOutputAmount(inputBlastersAmount, calculateFotFees)
// Theoretical amount out: // Theoretical amount out:
...@@ -246,7 +262,7 @@ describe('Pair', () => { ...@@ -246,7 +262,7 @@ describe('Pair', () => {
const pair = new Pair(reserveBlasterAmount, reserveBlastAmount) 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 [inputBlasterAmount] = pair.getInputAmount(outputBlastAmount, calculateFotFees)
// Theoretical amount in: // Theoretical amount in:
...@@ -294,7 +310,7 @@ describe('Pair', () => { ...@@ -294,7 +310,7 @@ describe('Pair', () => {
const pair = new Pair(reserveBlasterAmount, reserveBlastAmount) 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 [outputBlastAmount] = pair.getOutputAmount(inputBlastersAmount, calculateFotFees)
const expectedOutputBlastAmount = '0.000000000000000098' const expectedOutputBlastAmount = '0.000000000000000098'
...@@ -307,7 +323,7 @@ describe('Pair', () => { ...@@ -307,7 +323,7 @@ describe('Pair', () => {
const pair = new Pair(reserveBlasterAmount, reserveBlastAmount) 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 [inputBlasterAmount] = pair.getInputAmount(outputBlastAmount, calculateFotFees)
const expectedInputBlasterAmount = '0.000000093' const expectedInputBlasterAmount = '0.000000093'
......
...@@ -177,6 +177,7 @@ export class Pair { ...@@ -177,6 +177,7 @@ export class Pair {
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000) * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
* *
* @param inputAmount * @param inputAmount
* @param calculateFotFees
*/ */
public getOutputAmount( public getOutputAmount(
inputAmount: CurrencyAmount<Token>, inputAmount: CurrencyAmount<Token>,
...@@ -379,7 +380,9 @@ export class Pair { ...@@ -379,7 +380,9 @@ export class Pair {
} }
private derivePercentAfterSellFees(inputAmount: CurrencyAmount<Token>): Percent { 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))) { if (sellFeeBips?.gt(BigNumber.from(0))) {
return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS)) return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS))
} else { } else {
...@@ -388,7 +391,9 @@ export class Pair { ...@@ -388,7 +391,9 @@ export class Pair {
} }
private derivePercentAfterBuyFees(outputAmount: CurrencyAmount<Token>): Percent { 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))) { if (buyFeeBps?.gt(BigNumber.from(0))) {
return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS)) return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS))
} else { } 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