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

Commit

Permalink
add error for 100% buy tax
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaszheng committed Oct 13, 2023
1 parent 11f9562 commit fa70cfd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export const ONE = JSBI.BigInt(1)
export const V2_FEE_PATH_PLACEHOLDER = 8388608

export const ZERO_PERCENT = new Percent(ZERO)
export const ONE_HUNDRED_PERCENT = new Percent(100, 100)
6 changes: 5 additions & 1 deletion src/entities/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Currency, CurrencyAmount, Fraction, Percent, Price, TradeType } from '@
import { Pair, Route as V2RouteSDK, Trade as V2TradeSDK } from '@uniswap/v2-sdk'
import { Pool, Route as V3RouteSDK, Trade as V3TradeSDK } from '@uniswap/v3-sdk'
import invariant from 'tiny-invariant'
import { ONE, ZERO, ZERO_PERCENT } from '../constants'
import { ONE, ONE_HUNDRED_PERCENT, ZERO, ZERO_PERCENT } from '../constants'
import { MixedRouteSDK } from './mixedRoute/route'
import { MixedRouteTrade as MixedRouteTradeSDK } from './mixedRoute/trade'
import { IRoute, MixedRoute, RouteV2, RouteV3 } from './route'
Expand Down Expand Up @@ -198,6 +198,10 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
return this._priceImpact
}

if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) {
throw new Error("Unable to calculate price impact for a 100% buy-tax token")
}

let spotOutputAmount = CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0)
for (const { route, inputAmount } of this.swaps) {
const midPrice = route.midPrice
Expand Down

0 comments on commit fa70cfd

Please sign in to comment.