@uniswap/v2-sdk
Advanced tools
Comparing version 2.0.2 to 3.0.0-alpha.0
@@ -11,3 +11,3 @@ import { BigintIsh, ChainId, Price, Token, CurrencyAmount } from '@uniswap/sdk-core'; | ||
static getAddress(tokenA: Token, tokenB: Token): string; | ||
constructor(currencyAmountA: CurrencyAmount, tokenAmountB: CurrencyAmount); | ||
constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>); | ||
/** | ||
@@ -21,7 +21,7 @@ * Returns true if the token is either token0 or token1 | ||
*/ | ||
get token0Price(): Price; | ||
get token0Price(): Price<Token, Token>; | ||
/** | ||
* Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1 | ||
*/ | ||
get token1Price(): Price; | ||
get token1Price(): Price<Token, Token>; | ||
/** | ||
@@ -31,3 +31,3 @@ * Return the price of the given token in terms of the other token in the pair. | ||
*/ | ||
priceOf(token: Token): Price; | ||
priceOf(token: Token): Price<Token, Token>; | ||
/** | ||
@@ -39,9 +39,9 @@ * Returns the chain ID of the tokens in the pair. | ||
get token1(): Token; | ||
get reserve0(): CurrencyAmount; | ||
get reserve1(): CurrencyAmount; | ||
reserveOf(token: Token): CurrencyAmount; | ||
getOutputAmount(inputAmount: CurrencyAmount): [CurrencyAmount, Pair]; | ||
getInputAmount(outputAmount: CurrencyAmount): [CurrencyAmount, Pair]; | ||
getLiquidityMinted(totalSupply: CurrencyAmount, tokenAmountA: CurrencyAmount, tokenAmountB: CurrencyAmount): CurrencyAmount; | ||
getLiquidityValue(token: Token, totalSupply: CurrencyAmount, liquidity: CurrencyAmount, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount; | ||
get reserve0(): CurrencyAmount<Token>; | ||
get reserve1(): CurrencyAmount<Token>; | ||
reserveOf(token: Token): CurrencyAmount<Token>; | ||
getOutputAmount(inputAmount: CurrencyAmount<Token>): [CurrencyAmount<Token>, Pair]; | ||
getInputAmount(outputAmount: CurrencyAmount<Token>): [CurrencyAmount<Token>, Pair]; | ||
getLiquidityMinted(totalSupply: CurrencyAmount<Token>, tokenAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>): CurrencyAmount<Token>; | ||
getLiquidityValue(token: Token, totalSupply: CurrencyAmount<Token>, liquidity: CurrencyAmount<Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<Token>; | ||
} |
import { ChainId, Currency, Price, Token } from '@uniswap/sdk-core'; | ||
import { Pair } from './pair'; | ||
export declare class Route { | ||
export declare class Route<TInput extends Currency, TOutput extends Currency> { | ||
readonly pairs: Pair[]; | ||
readonly path: Token[]; | ||
readonly input: Currency; | ||
readonly output: Currency; | ||
get midPrice(): Price; | ||
constructor(pairs: Pair[], input: Currency, output?: Currency); | ||
readonly input: TInput; | ||
readonly output: TOutput; | ||
constructor(pairs: Pair[], input: TInput, output: TOutput); | ||
private _midPrice; | ||
get midPrice(): Price<TInput, TOutput>; | ||
get chainId(): ChainId | number; | ||
} |
import { Currency, CurrencyAmount, Percent, Price, TradeType } from '@uniswap/sdk-core'; | ||
import { Pair } from './pair'; | ||
import { Route } from './route'; | ||
interface InputOutput { | ||
readonly inputAmount: CurrencyAmount; | ||
readonly outputAmount: CurrencyAmount; | ||
interface InputOutput<TInput extends Currency, TOutput extends Currency> { | ||
readonly inputAmount: CurrencyAmount<TInput>; | ||
readonly outputAmount: CurrencyAmount<TOutput>; | ||
} | ||
export declare function inputOutputComparator(a: InputOutput, b: InputOutput): number; | ||
export declare function tradeComparator(a: Trade, b: Trade): number; | ||
export declare function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(a: InputOutput<TInput, TOutput>, b: InputOutput<TInput, TOutput>): number; | ||
export declare function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(a: Trade<TInput, TOutput, TTradeType>, b: Trade<TInput, TOutput, TTradeType>): number; | ||
export interface BestTradeOptions { | ||
@@ -18,28 +18,24 @@ maxNumResults?: number; | ||
*/ | ||
export declare class Trade { | ||
export declare class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> { | ||
/** | ||
* The route of the trade, i.e. which pairs the trade goes through. | ||
* The route of the trade, i.e. which pairs the trade goes through and the input/output currencies. | ||
*/ | ||
readonly route: Route; | ||
readonly route: Route<TInput, TOutput>; | ||
/** | ||
* The type of the trade, either exact in or exact out. | ||
*/ | ||
readonly tradeType: TradeType; | ||
readonly tradeType: TTradeType; | ||
/** | ||
* The input amount for the trade assuming no slippage. | ||
*/ | ||
readonly inputAmount: CurrencyAmount; | ||
readonly inputAmount: CurrencyAmount<TInput>; | ||
/** | ||
* The output amount for the trade assuming no slippage. | ||
*/ | ||
readonly outputAmount: CurrencyAmount; | ||
readonly outputAmount: CurrencyAmount<TOutput>; | ||
/** | ||
* The price expressed in terms of output amount/input amount. | ||
*/ | ||
readonly executionPrice: Price; | ||
readonly executionPrice: Price<TInput, TOutput>; | ||
/** | ||
* The mid price after the trade executes assuming no slippage. | ||
*/ | ||
readonly nextMidPrice: Price; | ||
/** | ||
* The percent difference between the mid price before the trade and the trade execution price. | ||
@@ -53,3 +49,3 @@ */ | ||
*/ | ||
static exactIn(route: Route, amountIn: CurrencyAmount): Trade; | ||
static exactIn<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountIn: CurrencyAmount<TInput>): Trade<TInput, TOutput, TradeType.EXACT_INPUT>; | ||
/** | ||
@@ -60,4 +56,4 @@ * Constructs an exact out trade with the given amount out and route | ||
*/ | ||
static exactOut(route: Route, amountOut: CurrencyAmount): Trade; | ||
constructor(route: Route, amount: CurrencyAmount, tradeType: TradeType); | ||
static exactOut<TInput extends Currency, TOutput extends Currency>(route: Route<TInput, TOutput>, amountOut: CurrencyAmount<TOutput>): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>; | ||
constructor(route: Route<TInput, TOutput>, amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>, tradeType: TTradeType); | ||
/** | ||
@@ -67,3 +63,3 @@ * Get the minimum amount that must be received from this trade for the given slippage tolerance | ||
*/ | ||
minimumAmountOut(slippageTolerance: Percent): CurrencyAmount; | ||
minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput>; | ||
/** | ||
@@ -73,3 +69,3 @@ * Get the maximum amount in that can be spent via this trade for the given slippage tolerance | ||
*/ | ||
maximumAmountIn(slippageTolerance: Percent): CurrencyAmount; | ||
maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput>; | ||
/** | ||
@@ -81,3 +77,3 @@ * Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token | ||
* @param pairs the pairs to consider in finding the best trade | ||
* @param currencyAmountIn exact amount of input currency to spend | ||
* @param nextAmountIn exact amount of input currency to spend | ||
* @param currencyOut the desired currency out | ||
@@ -87,6 +83,6 @@ * @param maxNumResults maximum number of results to return | ||
* @param currentPairs used in recursion; the current list of pairs | ||
* @param originalAmountIn used in recursion; the original value of the currencyAmountIn parameter | ||
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter | ||
* @param bestTrades used in recursion; the current list of best trades | ||
*/ | ||
static bestTradeExactIn(pairs: Pair[], currencyAmountIn: CurrencyAmount, currencyOut: Currency, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], originalAmountIn?: CurrencyAmount, bestTrades?: Trade[]): Trade[]; | ||
static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyAmountIn: CurrencyAmount<TInput>, currencyOut: TOutput, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountIn?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[]; | ||
/** | ||
@@ -96,3 +92,3 @@ * Return the execution price after accounting for slippage tolerance | ||
*/ | ||
worstExecutionPrice(slippageTolerance: Percent): Price; | ||
worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput>; | ||
/** | ||
@@ -106,11 +102,11 @@ * similar to the above method but instead targets a fixed output amount | ||
* @param currencyIn the currency to spend | ||
* @param currencyAmountOut the exact amount of currency out | ||
* @param nextAmountOut the exact amount of currency out | ||
* @param maxNumResults maximum number of results to return | ||
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair | ||
* @param currentPairs used in recursion; the current list of pairs | ||
* @param originalAmountOut used in recursion; the original value of the currencyAmountOut parameter | ||
* @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter | ||
* @param bestTrades used in recursion; the current list of best trades | ||
*/ | ||
static bestTradeExactOut(pairs: Pair[], currencyIn: Currency, currencyAmountOut: CurrencyAmount, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], originalAmountOut?: CurrencyAmount, bestTrades?: Trade[]): Trade[]; | ||
static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(pairs: Pair[], currencyIn: TInput, currencyAmountOut: CurrencyAmount<TOutput>, { maxNumResults, maxHops }?: BestTradeOptions, currentPairs?: Pair[], nextAmountOut?: CurrencyAmount<Currency>, bestTrades?: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[]; | ||
} | ||
export {}; |
@@ -1,3 +0,1 @@ | ||
import JSBI from 'jsbi'; | ||
export { JSBI }; | ||
export { FACTORY_ADDRESS, INIT_CODE_HASH, MINIMUM_LIQUIDITY } from './constants'; | ||
@@ -4,0 +2,0 @@ export * from './errors'; |
@@ -1,2 +0,2 @@ | ||
import { Percent } from '@uniswap/sdk-core'; | ||
import { Currency, Percent, TradeType } from '@uniswap/sdk-core'; | ||
import { Trade } from 'entities'; | ||
@@ -63,3 +63,3 @@ /** | ||
*/ | ||
static swapCallParameters(trade: Trade, options: TradeOptions | TradeOptionsDeadline): SwapParameters; | ||
static swapCallParameters(trade: Trade<Currency, Currency, TradeType>, options: TradeOptions | TradeOptionsDeadline): SwapParameters; | ||
} |
@@ -12,2 +12,5 @@ 'use strict'; | ||
var address = require('@ethersproject/address'); | ||
var _Decimal = _interopDefault(require('decimal.js-light')); | ||
var _Big = _interopDefault(require('big.js')); | ||
var toFormat = _interopDefault(require('toformat')); | ||
@@ -237,6 +240,4 @@ var FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'; | ||
function Pair(currencyAmountA, tokenAmountB) { | ||
!(currencyAmountA.currency.isToken && tokenAmountB.currency.isToken) ? invariant(false, 'TOKEN') : void 0; | ||
var tokenAmounts = currencyAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks | ||
? [currencyAmountA, tokenAmountB] : [tokenAmountB, currencyAmountA]; | ||
!(tokenAmounts[0].currency.isToken && tokenAmounts[1].currency.isToken) ? invariant(false, 'TOKEN') : void 0; | ||
this.liquidityToken = new sdkCore.Token(tokenAmounts[0].currency.chainId, Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency), 18, 'UNI-V2', 'Uniswap V2'); | ||
@@ -288,5 +289,5 @@ this.tokenAmounts = tokenAmounts; | ||
_proto.getOutputAmount = function getOutputAmount(inputAmount) { | ||
!(inputAmount.currency.isToken && this.involvesToken(inputAmount.currency)) ? invariant(false, 'TOKEN') : void 0; | ||
!this.involvesToken(inputAmount.currency) ? invariant(false, 'TOKEN') : void 0; | ||
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO)) { | ||
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) { | ||
throw new InsufficientReservesError(); | ||
@@ -297,8 +298,8 @@ } | ||
var outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0); | ||
var inputAmountWithFee = JSBI.multiply(inputAmount.raw, _997); | ||
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.raw); | ||
var denominator = JSBI.add(JSBI.multiply(inputReserve.raw, _1000), inputAmountWithFee); | ||
var outputAmount = new sdkCore.CurrencyAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator)); | ||
var inputAmountWithFee = JSBI.multiply(inputAmount.quotient, _997); | ||
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.quotient); | ||
var denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFee); | ||
var outputAmount = sdkCore.CurrencyAmount.fromRawAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator)); | ||
if (JSBI.equal(outputAmount.raw, ZERO)) { | ||
if (JSBI.equal(outputAmount.quotient, ZERO)) { | ||
throw new InsufficientInputAmountError(); | ||
@@ -311,5 +312,5 @@ } | ||
_proto.getInputAmount = function getInputAmount(outputAmount) { | ||
!(outputAmount.currency.isToken && this.involvesToken(outputAmount.currency)) ? invariant(false, 'TOKEN') : void 0; | ||
!this.involvesToken(outputAmount.currency) ? invariant(false, 'TOKEN') : void 0; | ||
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO) || JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.currency).raw)) { | ||
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO) || JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient)) { | ||
throw new InsufficientReservesError(); | ||
@@ -320,5 +321,5 @@ } | ||
var inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0); | ||
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.raw, outputAmount.raw), _1000); | ||
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.raw, outputAmount.raw), _997); | ||
var inputAmount = new sdkCore.CurrencyAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE)); | ||
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmount.quotient), _1000); | ||
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmount.quotient), _997); | ||
var inputAmount = sdkCore.CurrencyAmount.fromRawAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE)); | ||
return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]; | ||
@@ -328,14 +329,13 @@ }; | ||
_proto.getLiquidityMinted = function getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) { | ||
!(totalSupply.currency.isToken && totalSupply.currency.equals(this.liquidityToken)) ? invariant(false, 'LIQUIDITY') : void 0; | ||
var tokenAmounts = tokenAmountA.currency.isToken && tokenAmountB.currency.isToken && tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks | ||
!totalSupply.currency.equals(this.liquidityToken) ? invariant(false, 'LIQUIDITY') : void 0; | ||
var tokenAmounts = tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks | ||
? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA]; | ||
!(tokenAmounts[0].currency.isToken && tokenAmounts[1].currency.isToken) ? invariant(false) : void 0; | ||
!(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1)) ? invariant(false, 'TOKEN') : void 0; | ||
var liquidity; | ||
if (JSBI.equal(totalSupply.raw, ZERO)) { | ||
liquidity = JSBI.subtract(sdkCore.sqrt(JSBI.multiply(tokenAmounts[0].raw, tokenAmounts[1].raw)), MINIMUM_LIQUIDITY); | ||
if (JSBI.equal(totalSupply.quotient, ZERO)) { | ||
liquidity = JSBI.subtract(sdkCore.sqrt(JSBI.multiply(tokenAmounts[0].quotient, tokenAmounts[1].quotient)), MINIMUM_LIQUIDITY); | ||
} else { | ||
var amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].raw, totalSupply.raw), this.reserve0.raw); | ||
var amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].raw, totalSupply.raw), this.reserve1.raw); | ||
var amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].quotient, totalSupply.quotient), this.reserve0.quotient); | ||
var amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].quotient, totalSupply.quotient), this.reserve1.quotient); | ||
liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1; | ||
@@ -348,3 +348,3 @@ } | ||
return new sdkCore.CurrencyAmount(this.liquidityToken, liquidity); | ||
return sdkCore.CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity); | ||
}; | ||
@@ -358,5 +358,5 @@ | ||
!this.involvesToken(token) ? invariant(false, 'TOKEN') : void 0; | ||
!(totalSupply.currency.isToken && totalSupply.currency.equals(this.liquidityToken)) ? invariant(false, 'TOTAL_SUPPLY') : void 0; | ||
!(liquidity.currency.isToken && liquidity.currency.equals(this.liquidityToken)) ? invariant(false, 'LIQUIDITY') : void 0; | ||
!JSBI.lessThanOrEqual(liquidity.raw, totalSupply.raw) ? invariant(false, 'LIQUIDITY') : void 0; | ||
!totalSupply.currency.equals(this.liquidityToken) ? invariant(false, 'TOTAL_SUPPLY') : void 0; | ||
!liquidity.currency.equals(this.liquidityToken) ? invariant(false, 'LIQUIDITY') : void 0; | ||
!JSBI.lessThanOrEqual(liquidity.quotient, totalSupply.quotient) ? invariant(false, 'LIQUIDITY') : void 0; | ||
var totalSupplyAdjusted; | ||
@@ -371,10 +371,10 @@ | ||
if (!JSBI.equal(kLastParsed, ZERO)) { | ||
var rootK = sdkCore.sqrt(JSBI.multiply(this.reserve0.raw, this.reserve1.raw)); | ||
var rootK = sdkCore.sqrt(JSBI.multiply(this.reserve0.quotient, this.reserve1.quotient)); | ||
var rootKLast = sdkCore.sqrt(kLastParsed); | ||
if (JSBI.greaterThan(rootK, rootKLast)) { | ||
var numerator = JSBI.multiply(totalSupply.raw, JSBI.subtract(rootK, rootKLast)); | ||
var numerator = JSBI.multiply(totalSupply.quotient, JSBI.subtract(rootK, rootKLast)); | ||
var denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast); | ||
var feeLiquidity = JSBI.divide(numerator, denominator); | ||
totalSupplyAdjusted = totalSupply.add(new sdkCore.CurrencyAmount(this.liquidityToken, feeLiquidity)); | ||
totalSupplyAdjusted = totalSupply.add(sdkCore.CurrencyAmount.fromRawAmount(this.liquidityToken, feeLiquidity)); | ||
} else { | ||
@@ -388,3 +388,3 @@ totalSupplyAdjusted = totalSupply; | ||
return new sdkCore.CurrencyAmount(token, JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw)); | ||
return sdkCore.CurrencyAmount.fromRawAmount(token, JSBI.divide(JSBI.multiply(liquidity.quotient, this.reserveOf(token).quotient), totalSupplyAdjusted.quotient)); | ||
}; | ||
@@ -395,3 +395,4 @@ | ||
get: function get() { | ||
return new sdkCore.Price(this.token0, this.token1, this.tokenAmounts[0].raw, this.tokenAmounts[1].raw); | ||
var result = this.tokenAmounts[1].divide(this.tokenAmounts[0]); | ||
return new sdkCore.Price(this.token0, this.token1, result.denominator, result.numerator); | ||
} | ||
@@ -405,3 +406,4 @@ /** | ||
get: function get() { | ||
return new sdkCore.Price(this.token1, this.token0, this.tokenAmounts[1].raw, this.tokenAmounts[0].raw); | ||
var result = this.tokenAmounts[0].divide(this.tokenAmounts[1]); | ||
return new sdkCore.Price(this.token1, this.token0, result.denominator, result.numerator); | ||
} | ||
@@ -416,3 +418,2 @@ }, { | ||
get: function get() { | ||
!this.tokenAmounts[0].currency.isToken ? invariant(false) : void 0; | ||
return this.tokenAmounts[0].currency; | ||
@@ -423,3 +424,2 @@ } | ||
get: function get() { | ||
!this.tokenAmounts[1].currency.isToken ? invariant(false) : void 0; | ||
return this.tokenAmounts[1].currency; | ||
@@ -444,2 +444,3 @@ } | ||
function Route(pairs, input, output) { | ||
this._midPrice = null; | ||
!(pairs.length > 0) ? invariant(false, 'PAIRS') : void 0; | ||
@@ -450,6 +451,6 @@ var chainId = pairs[0].chainId; | ||
}) ? invariant(false, 'CHAIN_IDS') : void 0; | ||
var weth = sdkCore.WETH9[chainId]; | ||
!(input.isToken && pairs[0].involvesToken(input) || input === sdkCore.ETHER && weth && pairs[0].involvesToken(weth)) ? invariant(false, 'INPUT') : void 0; | ||
!(typeof output === 'undefined' || output.isToken && pairs[pairs.length - 1].involvesToken(output) || output === sdkCore.ETHER && weth && pairs[pairs.length - 1].involvesToken(weth)) ? invariant(false, 'OUTPUT') : void 0; | ||
var path = [input.isToken ? input : weth]; | ||
var wrappedInput = sdkCore.wrappedCurrency(input, chainId); | ||
!pairs[0].involvesToken(wrappedInput) ? invariant(false, 'INPUT') : void 0; | ||
!(typeof output === 'undefined' || pairs[pairs.length - 1].involvesToken(sdkCore.wrappedCurrency(output, chainId))) ? invariant(false, 'OUTPUT') : void 0; | ||
var path = [wrappedInput]; | ||
@@ -471,3 +472,3 @@ for (var _iterator = _createForOfIteratorHelperLoose(pairs.entries()), _step; !(_step = _iterator()).done;) { | ||
this.input = input; | ||
this.output = output != null ? output : path[path.length - 1]; | ||
this.output = output; | ||
} | ||
@@ -478,2 +479,3 @@ | ||
get: function get() { | ||
if (this._midPrice !== null) return this._midPrice; | ||
var prices = []; | ||
@@ -485,8 +487,9 @@ | ||
pair = _step2$value[1]; | ||
prices.push(this.path[i].equals(pair.token0) ? new sdkCore.Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.raw, pair.reserve1.raw) : new sdkCore.Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.raw, pair.reserve0.raw)); | ||
prices.push(this.path[i].equals(pair.token0) ? new sdkCore.Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient) : new sdkCore.Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient)); | ||
} | ||
return prices.slice(1).reduce(function (accumulator, currentValue) { | ||
var reduced = prices.slice(1).reduce(function (accumulator, currentValue) { | ||
return accumulator.multiply(currentValue); | ||
}, prices[0]); | ||
return this._midPrice = new sdkCore.Price(this.input, this.output, reduced.denominator, reduced.numerator); | ||
} | ||
@@ -503,3 +506,337 @@ }, { | ||
var ChainId; | ||
(function (ChainId) { | ||
ChainId[ChainId["MAINNET"] = 1] = "MAINNET"; | ||
ChainId[ChainId["ROPSTEN"] = 3] = "ROPSTEN"; | ||
ChainId[ChainId["RINKEBY"] = 4] = "RINKEBY"; | ||
ChainId[ChainId["G\xD6RLI"] = 5] = "G\xD6RLI"; | ||
ChainId[ChainId["KOVAN"] = 42] = "KOVAN"; | ||
})(ChainId || (ChainId = {})); | ||
var TradeType; | ||
(function (TradeType) { | ||
TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT"; | ||
TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT"; | ||
})(TradeType || (TradeType = {})); | ||
var Rounding; | ||
(function (Rounding) { | ||
Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN"; | ||
Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP"; | ||
Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP"; | ||
})(Rounding || (Rounding = {})); | ||
function _defineProperties$1(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass$1(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties$1(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _inheritsLoose$1(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
/** | ||
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens. | ||
* | ||
* The only instance of the base class `Currency` is Ether. | ||
*/ | ||
var BaseCurrency = | ||
/** | ||
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`. | ||
* @param decimals decimals of the currency | ||
* @param symbol symbol of the currency | ||
* @param name of the currency | ||
*/ | ||
function BaseCurrency(decimals, symbol, name) { | ||
!(decimals >= 0 && decimals < 255 && Number.isInteger(decimals)) ? invariant(false, 'DECIMALS') : void 0; | ||
this.decimals = decimals; | ||
this.symbol = symbol; | ||
this.name = name; | ||
}; | ||
var _toSignificantRoundin, _toFixedRounding; | ||
var Decimal = /*#__PURE__*/toFormat(_Decimal); | ||
var Big = /*#__PURE__*/toFormat(_Big); | ||
var toSignificantRounding = (_toSignificantRoundin = {}, _toSignificantRoundin[Rounding.ROUND_DOWN] = Decimal.ROUND_DOWN, _toSignificantRoundin[Rounding.ROUND_HALF_UP] = Decimal.ROUND_HALF_UP, _toSignificantRoundin[Rounding.ROUND_UP] = Decimal.ROUND_UP, _toSignificantRoundin); | ||
var toFixedRounding = (_toFixedRounding = {}, _toFixedRounding[Rounding.ROUND_DOWN] = 0, _toFixedRounding[Rounding.ROUND_HALF_UP] = 1, _toFixedRounding[Rounding.ROUND_UP] = 3, _toFixedRounding); | ||
var Fraction = /*#__PURE__*/function () { | ||
function Fraction(numerator, denominator) { | ||
if (denominator === void 0) { | ||
denominator = JSBI.BigInt(1); | ||
} | ||
this.numerator = JSBI.BigInt(numerator); | ||
this.denominator = JSBI.BigInt(denominator); | ||
} | ||
Fraction.tryParseFraction = function tryParseFraction(fractionish) { | ||
if (fractionish instanceof JSBI || typeof fractionish === 'number' || typeof fractionish === 'string') return new Fraction(fractionish); | ||
if ('numerator' in fractionish && 'denominator' in fractionish) return fractionish; | ||
throw new Error('Could not parse fraction'); | ||
} // performs floor division | ||
; | ||
var _proto = Fraction.prototype; | ||
_proto.invert = function invert() { | ||
return new Fraction(this.denominator, this.numerator); | ||
}; | ||
_proto.add = function add(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
if (JSBI.equal(this.denominator, otherParsed.denominator)) { | ||
return new Fraction(JSBI.add(this.numerator, otherParsed.numerator), this.denominator); | ||
} | ||
return new Fraction(JSBI.add(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator)); | ||
}; | ||
_proto.subtract = function subtract(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
if (JSBI.equal(this.denominator, otherParsed.denominator)) { | ||
return new Fraction(JSBI.subtract(this.numerator, otherParsed.numerator), this.denominator); | ||
} | ||
return new Fraction(JSBI.subtract(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator)); | ||
}; | ||
_proto.lessThan = function lessThan(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return JSBI.lessThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); | ||
}; | ||
_proto.equalTo = function equalTo(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return JSBI.equal(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); | ||
}; | ||
_proto.greaterThan = function greaterThan(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return JSBI.greaterThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); | ||
}; | ||
_proto.multiply = function multiply(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return new Fraction(JSBI.multiply(this.numerator, otherParsed.numerator), JSBI.multiply(this.denominator, otherParsed.denominator)); | ||
}; | ||
_proto.divide = function divide(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return new Fraction(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(this.denominator, otherParsed.numerator)); | ||
}; | ||
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) { | ||
if (format === void 0) { | ||
format = { | ||
groupSeparator: '' | ||
}; | ||
} | ||
if (rounding === void 0) { | ||
rounding = Rounding.ROUND_HALF_UP; | ||
} | ||
!Number.isInteger(significantDigits) ? invariant(false, significantDigits + " is not an integer.") : void 0; | ||
!(significantDigits > 0) ? invariant(false, significantDigits + " is not positive.") : void 0; | ||
Decimal.set({ | ||
precision: significantDigits + 1, | ||
rounding: toSignificantRounding[rounding] | ||
}); | ||
var quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits); | ||
return quotient.toFormat(quotient.decimalPlaces(), format); | ||
}; | ||
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) { | ||
if (format === void 0) { | ||
format = { | ||
groupSeparator: '' | ||
}; | ||
} | ||
if (rounding === void 0) { | ||
rounding = Rounding.ROUND_HALF_UP; | ||
} | ||
!Number.isInteger(decimalPlaces) ? invariant(false, decimalPlaces + " is not an integer.") : void 0; | ||
!(decimalPlaces >= 0) ? invariant(false, decimalPlaces + " is negative.") : void 0; | ||
Big.DP = decimalPlaces; | ||
Big.RM = toFixedRounding[rounding]; | ||
return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format); | ||
} | ||
/** | ||
* Helper method for converting any super class back to a fraction | ||
*/ | ||
; | ||
_createClass$1(Fraction, [{ | ||
key: "quotient", | ||
get: function get() { | ||
return JSBI.divide(this.numerator, this.denominator); | ||
} // remainder after floor division | ||
}, { | ||
key: "remainder", | ||
get: function get() { | ||
return new Fraction(JSBI.remainder(this.numerator, this.denominator), this.denominator); | ||
} | ||
}, { | ||
key: "asFraction", | ||
get: function get() { | ||
return new Fraction(this.numerator, this.denominator); | ||
} | ||
}]); | ||
return Fraction; | ||
}(); | ||
var ONE_HUNDRED = /*#__PURE__*/new Fraction( /*#__PURE__*/JSBI.BigInt(100)); | ||
/** | ||
* Converts a fraction to a percent | ||
* @param fraction the fraction to convert | ||
*/ | ||
function toPercent(fraction) { | ||
return new Percent(fraction.numerator, fraction.denominator); | ||
} | ||
var Percent = /*#__PURE__*/function (_Fraction) { | ||
_inheritsLoose$1(Percent, _Fraction); | ||
function Percent() { | ||
var _this; | ||
_this = _Fraction.apply(this, arguments) || this; | ||
/** | ||
* This boolean prevents a fraction from being interpreted as a Percent | ||
*/ | ||
_this.isPercent = true; | ||
return _this; | ||
} | ||
var _proto = Percent.prototype; | ||
_proto.add = function add(other) { | ||
return toPercent(_Fraction.prototype.add.call(this, other)); | ||
}; | ||
_proto.subtract = function subtract(other) { | ||
return toPercent(_Fraction.prototype.subtract.call(this, other)); | ||
}; | ||
_proto.multiply = function multiply(other) { | ||
return toPercent(_Fraction.prototype.multiply.call(this, other)); | ||
}; | ||
_proto.divide = function divide(other) { | ||
return toPercent(_Fraction.prototype.divide.call(this, other)); | ||
}; | ||
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) { | ||
if (significantDigits === void 0) { | ||
significantDigits = 5; | ||
} | ||
return _Fraction.prototype.multiply.call(this, ONE_HUNDRED).toSignificant(significantDigits, format, rounding); | ||
}; | ||
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) { | ||
if (decimalPlaces === void 0) { | ||
decimalPlaces = 2; | ||
} | ||
return _Fraction.prototype.multiply.call(this, ONE_HUNDRED).toFixed(decimalPlaces, format, rounding); | ||
}; | ||
return Percent; | ||
}(Fraction); | ||
/** | ||
* Validates an address and returns the parsed (checksummed) version of that address | ||
* @param address the unchecksummed hex address | ||
*/ | ||
function validateAndParseAddress(address$1) { | ||
try { | ||
return address.getAddress(address$1); | ||
} catch (error) { | ||
throw new Error(address$1 + " is not a valid address."); | ||
} | ||
} | ||
var _WETH; | ||
/** | ||
* Represents an ERC20 token with a unique address and some metadata. | ||
*/ | ||
var Token = /*#__PURE__*/function (_BaseCurrency) { | ||
_inheritsLoose$1(Token, _BaseCurrency); | ||
function Token(chainId, address, decimals, symbol, name) { | ||
var _this; | ||
_this = _BaseCurrency.call(this, decimals, symbol, name) || this; | ||
_this.isEther = false; | ||
_this.isToken = true; | ||
_this.chainId = chainId; | ||
_this.address = validateAndParseAddress(address); | ||
return _this; | ||
} | ||
/** | ||
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address. | ||
* @param other other token to compare | ||
*/ | ||
var _proto = Token.prototype; | ||
_proto.equals = function equals(other) { | ||
// short circuit on reference equality | ||
if (this === other) { | ||
return true; | ||
} | ||
return this.chainId === other.chainId && this.address === other.address; | ||
} | ||
/** | ||
* Returns true if the address of this token sorts before the address of the other token | ||
* @param other other token to compare | ||
* @throws if the tokens have the same address | ||
* @throws if the tokens are on different chains | ||
*/ | ||
; | ||
_proto.sortsBefore = function sortsBefore(other) { | ||
!(this.chainId === other.chainId) ? invariant(false, 'CHAIN_IDS') : void 0; | ||
!(this.address !== other.address) ? invariant(false, 'ADDRESSES') : void 0; | ||
return this.address.toLowerCase() < other.address.toLowerCase(); | ||
}; | ||
return Token; | ||
}(BaseCurrency); | ||
var WETH9 = (_WETH = {}, _WETH[ChainId.MAINNET] = /*#__PURE__*/new Token(ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.ROPSTEN] = /*#__PURE__*/new Token(ChainId.ROPSTEN, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.RINKEBY] = /*#__PURE__*/new Token(ChainId.RINKEBY, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.GÖRLI] = /*#__PURE__*/new Token(ChainId.GÖRLI, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.KOVAN] = /*#__PURE__*/new Token(ChainId.KOVAN, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH9', 'Wrapped Ether'), _WETH); | ||
/** | ||
* Returns the percent difference between the mid price and the execution price, i.e. price impact. | ||
@@ -512,10 +849,10 @@ * @param midPrice mid price before the trade | ||
function computePriceImpact(midPrice, inputAmount, outputAmount) { | ||
var exactQuote = midPrice.raw.multiply(inputAmount.raw); // calculate slippage := (exactQuote - outputAmount) / exactQuote | ||
var quotedOutputAmount = midPrice.quote(inputAmount); // calculate price impact := (exactQuote - outputAmount) / exactQuote | ||
var slippage = exactQuote.subtract(outputAmount.raw).divide(exactQuote); | ||
return new sdkCore.Percent(slippage.numerator, slippage.denominator); | ||
} // comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts | ||
var priceImpact = quotedOutputAmount.subtract(outputAmount).divide(quotedOutputAmount); | ||
return new Percent(priceImpact.numerator, priceImpact.denominator); | ||
} // `maxSize` by removing the last item | ||
// in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first | ||
function inputOutputComparator(a, b) { | ||
@@ -565,19 +902,2 @@ // must have same input and output token for comparison | ||
/** | ||
* Given a currency amount and a chain ID, returns the equivalent representation as the token amount. | ||
* In other words, if the currency is ETHER, returns the WETH9 token amount for the given chain. Otherwise, returns | ||
* the input currency amount. | ||
*/ | ||
function wrappedAmount(currencyAmount, chainId) { | ||
if (currencyAmount.currency.isToken) return currencyAmount; | ||
if (currencyAmount.currency.isEther) return new sdkCore.CurrencyAmount(sdkCore.WETH9[chainId], currencyAmount.raw); | ||
throw new Error('CURRENCY'); | ||
} | ||
function wrappedCurrency(currency, chainId) { | ||
if (currency.isToken) return currency; | ||
if (currency === sdkCore.ETHER) return sdkCore.WETH9[chainId]; | ||
throw new Error('CURRENCY'); | ||
} | ||
/** | ||
* Represents a trade executed against a list of pairs. | ||
@@ -587,11 +907,11 @@ * Does not account for slippage, i.e. trades that front run this trade and move the price. | ||
var Trade = /*#__PURE__*/function () { | ||
function Trade(route, amount, tradeType) { | ||
var amounts = new Array(route.path.length); | ||
var nextPairs = new Array(route.pairs.length); | ||
this.route = route; | ||
this.tradeType = tradeType; | ||
var tokenAmounts = new Array(route.path.length); | ||
if (tradeType === sdkCore.TradeType.EXACT_INPUT) { | ||
!sdkCore.currencyEquals(amount.currency, route.input) ? invariant(false, 'INPUT') : void 0; | ||
amounts[0] = wrappedAmount(amount, route.chainId); | ||
tokenAmounts[0] = sdkCore.wrappedCurrencyAmount(amount, route.chainId); | ||
@@ -601,12 +921,13 @@ for (var i = 0; i < route.path.length - 1; i++) { | ||
var _pair$getOutputAmount = pair.getOutputAmount(amounts[i]), | ||
outputAmount = _pair$getOutputAmount[0], | ||
nextPair = _pair$getOutputAmount[1]; | ||
var _pair$getOutputAmount = pair.getOutputAmount(tokenAmounts[i]), | ||
outputAmount = _pair$getOutputAmount[0]; | ||
amounts[i + 1] = outputAmount; | ||
nextPairs[i] = nextPair; | ||
tokenAmounts[i + 1] = outputAmount; | ||
} | ||
this.inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator); | ||
this.outputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.output, tokenAmounts[tokenAmounts.length - 1].numerator, tokenAmounts[tokenAmounts.length - 1].denominator); | ||
} else { | ||
!sdkCore.currencyEquals(amount.currency, route.output) ? invariant(false, 'OUTPUT') : void 0; | ||
amounts[amounts.length - 1] = wrappedAmount(amount, route.chainId); | ||
tokenAmounts[tokenAmounts.length - 1] = sdkCore.wrappedCurrencyAmount(amount, route.chainId); | ||
@@ -616,17 +937,13 @@ for (var _i = route.path.length - 1; _i > 0; _i--) { | ||
var _pair$getInputAmount = _pair.getInputAmount(amounts[_i]), | ||
inputAmount = _pair$getInputAmount[0], | ||
_nextPair = _pair$getInputAmount[1]; | ||
var _pair$getInputAmount = _pair.getInputAmount(tokenAmounts[_i]), | ||
inputAmount = _pair$getInputAmount[0]; | ||
amounts[_i - 1] = inputAmount; | ||
nextPairs[_i - 1] = _nextPair; | ||
tokenAmounts[_i - 1] = inputAmount; | ||
} | ||
this.inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, tokenAmounts[0].numerator, tokenAmounts[0].denominator); | ||
this.outputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator); | ||
} | ||
this.route = route; | ||
this.tradeType = tradeType; | ||
this.inputAmount = tradeType === sdkCore.TradeType.EXACT_INPUT ? amount : route.input === sdkCore.ETHER ? sdkCore.CurrencyAmount.ether(amounts[0].raw) : amounts[0]; | ||
this.outputAmount = tradeType === sdkCore.TradeType.EXACT_OUTPUT ? amount : route.output === sdkCore.ETHER ? sdkCore.CurrencyAmount.ether(amounts[amounts.length - 1].raw) : amounts[amounts.length - 1]; | ||
this.executionPrice = new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.raw, this.outputAmount.raw); | ||
this.nextMidPrice = new Route(nextPairs, route.input).midPrice; | ||
this.executionPrice = new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient); | ||
this.priceImpact = computePriceImpact(route.midPrice, this.inputAmount, this.outputAmount); | ||
@@ -668,4 +985,4 @@ } | ||
} else { | ||
var slippageAdjustedAmountOut = new sdkCore.Fraction(ONE).add(slippageTolerance).invert().multiply(this.outputAmount.raw).quotient; | ||
return new sdkCore.CurrencyAmount(this.outputAmount.currency, slippageAdjustedAmountOut); | ||
var slippageAdjustedAmountOut = new sdkCore.Fraction(ONE).add(slippageTolerance).invert().multiply(this.outputAmount.quotient).quotient; | ||
return sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, slippageAdjustedAmountOut); | ||
} | ||
@@ -685,4 +1002,4 @@ } | ||
} else { | ||
var slippageAdjustedAmountIn = new sdkCore.Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.raw).quotient; | ||
return new sdkCore.CurrencyAmount(this.inputAmount.currency, slippageAdjustedAmountIn); | ||
var slippageAdjustedAmountIn = new sdkCore.Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.quotient).quotient; | ||
return sdkCore.CurrencyAmount.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn); | ||
} | ||
@@ -696,3 +1013,3 @@ } | ||
* @param pairs the pairs to consider in finding the best trade | ||
* @param currencyAmountIn exact amount of input currency to spend | ||
* @param nextAmountIn exact amount of input currency to spend | ||
* @param currencyOut the desired currency out | ||
@@ -702,3 +1019,3 @@ * @param maxNumResults maximum number of results to return | ||
* @param currentPairs used in recursion; the current list of pairs | ||
* @param originalAmountIn used in recursion; the original value of the currencyAmountIn parameter | ||
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter | ||
* @param bestTrades used in recursion; the current list of best trades | ||
@@ -709,3 +1026,3 @@ */ | ||
Trade.bestTradeExactIn = function bestTradeExactIn(pairs, currencyAmountIn, currencyOut, _temp, // used in recursion. | ||
currentPairs, originalAmountIn, bestTrades) { | ||
currentPairs, nextAmountIn, bestTrades) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
@@ -721,4 +1038,4 @@ _ref$maxNumResults = _ref.maxNumResults, | ||
if (originalAmountIn === void 0) { | ||
originalAmountIn = currencyAmountIn; | ||
if (nextAmountIn === void 0) { | ||
nextAmountIn = currencyAmountIn; | ||
} | ||
@@ -732,7 +1049,7 @@ | ||
!(maxHops > 0) ? invariant(false, 'MAX_HOPS') : void 0; | ||
!(originalAmountIn === currencyAmountIn || currentPairs.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0; | ||
var chainId = currencyAmountIn.currency.isToken ? currencyAmountIn.currency.chainId : currencyOut.isToken ? currencyOut.chainId : undefined; | ||
!(currencyAmountIn === nextAmountIn || currentPairs.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0; | ||
var chainId = nextAmountIn.currency.isToken ? nextAmountIn.currency.chainId : currencyOut.isToken ? currencyOut.chainId : undefined; | ||
!(chainId !== undefined) ? invariant(false, 'CHAIN_ID') : void 0; | ||
var amountIn = wrappedAmount(currencyAmountIn, chainId); | ||
var tokenOut = wrappedCurrency(currencyOut, chainId); | ||
var amountIn = sdkCore.wrappedCurrencyAmount(nextAmountIn, chainId); | ||
var tokenOut = sdkCore.wrappedCurrency(currencyOut, chainId); | ||
@@ -763,10 +1080,10 @@ for (var i = 0; i < pairs.length; i++) { | ||
if (sdkCore.currencyEquals(amountOut.currency, tokenOut)) { | ||
sdkCore.sortedInsert(bestTrades, new Trade(new Route([].concat(currentPairs, [pair]), originalAmountIn.currency, currencyOut), originalAmountIn, sdkCore.TradeType.EXACT_INPUT), maxNumResults, tradeComparator); | ||
sdkCore.sortedInsert(bestTrades, new Trade(new Route([].concat(currentPairs, [pair]), currencyAmountIn.currency, currencyOut), currencyAmountIn, sdkCore.TradeType.EXACT_INPUT), maxNumResults, tradeComparator); | ||
} else if (maxHops > 1 && pairs.length > 1) { | ||
var pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length)); // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops | ||
Trade.bestTradeExactIn(pairsExcludingThisPair, amountOut, currencyOut, { | ||
Trade.bestTradeExactIn(pairsExcludingThisPair, currencyAmountIn, currencyOut, { | ||
maxNumResults: maxNumResults, | ||
maxHops: maxHops - 1 | ||
}, [].concat(currentPairs, [pair]), originalAmountIn, bestTrades); | ||
}, [].concat(currentPairs, [pair]), amountOut, bestTrades); | ||
} | ||
@@ -784,3 +1101,3 @@ } | ||
_proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) { | ||
return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).raw, this.minimumAmountOut(slippageTolerance).raw); | ||
return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient); | ||
} | ||
@@ -795,7 +1112,7 @@ /** | ||
* @param currencyIn the currency to spend | ||
* @param currencyAmountOut the exact amount of currency out | ||
* @param nextAmountOut the exact amount of currency out | ||
* @param maxNumResults maximum number of results to return | ||
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair | ||
* @param currentPairs used in recursion; the current list of pairs | ||
* @param originalAmountOut used in recursion; the original value of the currencyAmountOut parameter | ||
* @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter | ||
* @param bestTrades used in recursion; the current list of best trades | ||
@@ -806,3 +1123,3 @@ */ | ||
Trade.bestTradeExactOut = function bestTradeExactOut(pairs, currencyIn, currencyAmountOut, _temp2, // used in recursion. | ||
currentPairs, originalAmountOut, bestTrades) { | ||
currentPairs, nextAmountOut, bestTrades) { | ||
var _ref2 = _temp2 === void 0 ? {} : _temp2, | ||
@@ -818,4 +1135,4 @@ _ref2$maxNumResults = _ref2.maxNumResults, | ||
if (originalAmountOut === void 0) { | ||
originalAmountOut = currencyAmountOut; | ||
if (nextAmountOut === void 0) { | ||
nextAmountOut = currencyAmountOut; | ||
} | ||
@@ -829,7 +1146,7 @@ | ||
!(maxHops > 0) ? invariant(false, 'MAX_HOPS') : void 0; | ||
!(originalAmountOut === currencyAmountOut || currentPairs.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0; | ||
var chainId = currencyAmountOut.currency.isToken ? currencyAmountOut.currency.chainId : currencyIn.isToken ? currencyIn.chainId : undefined; | ||
!(currencyAmountOut === nextAmountOut || currentPairs.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0; | ||
var chainId = nextAmountOut.currency.isToken ? nextAmountOut.currency.chainId : currencyIn.isToken ? currencyIn.chainId : undefined; | ||
!(chainId !== undefined) ? invariant(false, 'CHAIN_ID') : void 0; | ||
var amountOut = wrappedAmount(currencyAmountOut, chainId); | ||
var tokenIn = wrappedCurrency(currencyIn, chainId); | ||
var amountOut = sdkCore.wrappedCurrencyAmount(nextAmountOut, chainId); | ||
var tokenIn = sdkCore.wrappedCurrency(currencyIn, chainId); | ||
@@ -860,10 +1177,10 @@ for (var i = 0; i < pairs.length; i++) { | ||
if (sdkCore.currencyEquals(amountIn.currency, tokenIn)) { | ||
sdkCore.sortedInsert(bestTrades, new Trade(new Route([pair].concat(currentPairs), currencyIn, originalAmountOut.currency), originalAmountOut, sdkCore.TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator); | ||
sdkCore.sortedInsert(bestTrades, new Trade(new Route([pair].concat(currentPairs), currencyIn, currencyAmountOut.currency), currencyAmountOut, sdkCore.TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator); | ||
} else if (maxHops > 1 && pairs.length > 1) { | ||
var pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length)); // otherwise, consider all the other paths that arrive at this token as long as we have not exceeded maxHops | ||
Trade.bestTradeExactOut(pairsExcludingThisPair, currencyIn, amountIn, { | ||
Trade.bestTradeExactOut(pairsExcludingThisPair, currencyIn, currencyAmountOut, { | ||
maxNumResults: maxNumResults, | ||
maxHops: maxHops - 1 | ||
}, [pair].concat(currentPairs), originalAmountOut, bestTrades); | ||
}, [pair].concat(currentPairs), amountIn, bestTrades); | ||
} | ||
@@ -879,3 +1196,3 @@ } | ||
function toHex(currencyAmount) { | ||
return "0x" + currencyAmount.raw.toString(16); | ||
return "0x" + currencyAmount.quotient.toString(16); | ||
} | ||
@@ -901,4 +1218,4 @@ | ||
Router.swapCallParameters = function swapCallParameters(trade, options) { | ||
var etherIn = trade.inputAmount.currency === sdkCore.ETHER; | ||
var etherOut = trade.outputAmount.currency === sdkCore.ETHER; // the router does not support both ether in and out | ||
var etherIn = trade.inputAmount.currency.isEther; | ||
var etherOut = trade.outputAmount.currency.isEther; // the router does not support both ether in and out | ||
@@ -973,3 +1290,2 @@ !!(etherIn && etherOut) ? invariant(false, 'ETHER_IN_OUT') : void 0; | ||
exports.JSBI = JSBI; | ||
exports.FACTORY_ADDRESS = FACTORY_ADDRESS; | ||
@@ -976,0 +1292,0 @@ exports.INIT_CODE_HASH = INIT_CODE_HASH; |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("jsbi")),r=require("@uniswap/sdk-core"),n=e(require("tiny-invariant")),u=require("@ethersproject/solidity"),o=require("@ethersproject/address"),i="0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",c=t.BigInt(1e3),s=t.BigInt(0),a=t.BigInt(1),l=t.BigInt(5),p=t.BigInt(997),h=t.BigInt(1e3);function y(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function f(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),e}function d(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function v(e){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function T(e,t){return(T=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function m(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function k(e,t,r){return(k=m()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var u=new(Function.bind.apply(e,n));return r&&T(u,r.prototype),u}).apply(null,arguments)}function w(e){var t="function"==typeof Map?new Map:void 0;return(w=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return k(e,arguments,v(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),T(r,e)})(e)}function A(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function g(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return E(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?E(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}var I="setPrototypeOf"in Object,q=function(e){function t(){var r;return(r=e.call(this)||this).isInsufficientReservesError=!0,r.name=r.constructor.name,I&&Object.setPrototypeOf(A(r),(this instanceof t?this.constructor:void 0).prototype),r}return d(t,e),t}(w(Error)),x=function(e){function t(){var r;return(r=e.call(this)||this).isInsufficientInputAmountError=!0,r.name=r.constructor.name,I&&Object.setPrototypeOf(A(r),(this instanceof t?this.constructor:void 0).prototype),r}return d(t,e),t}(w(Error)),b=function(e){var t=e.factoryAddress,r=e.tokenA,n=e.tokenB,c=r.sortsBefore(n)?[r,n]:[n,r];return o.getCreate2Address(t,u.keccak256(["bytes"],[u.pack(["address","address"],[c[0].address,c[1].address])]),i)},O=function(){function e(t,u){t.currency.isToken&&u.currency.isToken||n(!1);var o=t.currency.sortsBefore(u.currency)?[t,u]:[u,t];o[0].currency.isToken&&o[1].currency.isToken||n(!1),this.liquidityToken=new r.Token(o[0].currency.chainId,e.getAddress(o[0].currency,o[1].currency),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=o}e.getAddress=function(e,t){return b({factoryAddress:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",tokenA:e,tokenB:t})};var u=e.prototype;return u.involvesToken=function(e){return e.equals(this.token0)||e.equals(this.token1)},u.priceOf=function(e){return this.involvesToken(e)||n(!1),e.equals(this.token0)?this.token0Price:this.token1Price},u.reserveOf=function(e){return this.involvesToken(e)||n(!1),e.equals(this.token0)?this.reserve0:this.reserve1},u.getOutputAmount=function(u){if(u.currency.isToken&&this.involvesToken(u.currency)||n(!1),t.equal(this.reserve0.raw,s)||t.equal(this.reserve1.raw,s))throw new q;var o=this.reserveOf(u.currency),i=this.reserveOf(u.currency.equals(this.token0)?this.token1:this.token0),c=t.multiply(u.raw,p),a=t.multiply(c,i.raw),l=t.add(t.multiply(o.raw,h),c),y=new r.CurrencyAmount(u.currency.equals(this.token0)?this.token1:this.token0,t.divide(a,l));if(t.equal(y.raw,s))throw new x;return[y,new e(o.add(u),i.subtract(y))]},u.getInputAmount=function(u){if(u.currency.isToken&&this.involvesToken(u.currency)||n(!1),t.equal(this.reserve0.raw,s)||t.equal(this.reserve1.raw,s)||t.greaterThanOrEqual(u.raw,this.reserveOf(u.currency).raw))throw new q;var o=this.reserveOf(u.currency),i=this.reserveOf(u.currency.equals(this.token0)?this.token1:this.token0),c=t.multiply(t.multiply(i.raw,u.raw),h),l=t.multiply(t.subtract(o.raw,u.raw),p),y=new r.CurrencyAmount(u.currency.equals(this.token0)?this.token1:this.token0,t.add(t.divide(c,l),a));return[y,new e(i.add(y),o.subtract(u))]},u.getLiquidityMinted=function(e,u,o){e.currency.isToken&&e.currency.equals(this.liquidityToken)||n(!1);var i,a=u.currency.isToken&&o.currency.isToken&&u.currency.sortsBefore(o.currency)?[u,o]:[o,u];if(a[0].currency.isToken&&a[1].currency.isToken||n(!1),a[0].currency.equals(this.token0)&&a[1].currency.equals(this.token1)||n(!1),t.equal(e.raw,s))i=t.subtract(r.sqrt(t.multiply(a[0].raw,a[1].raw)),c);else{var l=t.divide(t.multiply(a[0].raw,e.raw),this.reserve0.raw),p=t.divide(t.multiply(a[1].raw,e.raw),this.reserve1.raw);i=t.lessThanOrEqual(l,p)?l:p}if(!t.greaterThan(i,s))throw new x;return new r.CurrencyAmount(this.liquidityToken,i)},u.getLiquidityValue=function(e,u,o,i,c){var a;if(void 0===i&&(i=!1),this.involvesToken(e)||n(!1),u.currency.isToken&&u.currency.equals(this.liquidityToken)||n(!1),o.currency.isToken&&o.currency.equals(this.liquidityToken)||n(!1),t.lessThanOrEqual(o.raw,u.raw)||n(!1),i){c||n(!1);var p=t.BigInt(c);if(t.equal(p,s))a=u;else{var h=r.sqrt(t.multiply(this.reserve0.raw,this.reserve1.raw)),y=r.sqrt(p);if(t.greaterThan(h,y)){var f=t.multiply(u.raw,t.subtract(h,y)),d=t.add(t.multiply(h,l),y),v=t.divide(f,d);a=u.add(new r.CurrencyAmount(this.liquidityToken,v))}else a=u}}else a=u;return new r.CurrencyAmount(e,t.divide(t.multiply(o.raw,this.reserveOf(e).raw),a.raw))},f(e,[{key:"token0Price",get:function(){return new r.Price(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new r.Price(this.token1,this.token0,this.tokenAmounts[1].raw,this.tokenAmounts[0].raw)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"token0",get:function(){return this.tokenAmounts[0].currency.isToken||n(!1),this.tokenAmounts[0].currency}},{key:"token1",get:function(){return this.tokenAmounts[1].currency.isToken||n(!1),this.tokenAmounts[1].currency}},{key:"reserve0",get:function(){return this.tokenAmounts[0]}},{key:"reserve1",get:function(){return this.tokenAmounts[1]}}]),e}(),P=function(){function e(e,t,u){e.length>0||n(!1);var o=e[0].chainId;e.every((function(e){return e.chainId===o}))||n(!1);var i=r.WETH9[o];t.isToken&&e[0].involvesToken(t)||t===r.ETHER&&i&&e[0].involvesToken(i)||n(!1),void 0===u||u.isToken&&e[e.length-1].involvesToken(u)||u===r.ETHER&&i&&e[e.length-1].involvesToken(i)||n(!1);for(var c,s=[t.isToken?t:i],a=g(e.entries());!(c=a()).done;){var l=c.value,p=l[1],h=s[l[0]];h.equals(p.token0)||h.equals(p.token1)||n(!1);var y=h.equals(p.token0)?p.token1:p.token0;s.push(y)}this.pairs=e,this.path=s,this.input=t,this.output=null!=u?u:s[s.length-1]}return f(e,[{key:"midPrice",get:function(){for(var e,t=[],n=g(this.pairs.entries());!(e=n()).done;){var u=e.value,o=u[1];t.push(this.path[u[0]].equals(o.token0)?new r.Price(o.reserve0.currency,o.reserve1.currency,o.reserve0.raw,o.reserve1.raw):new r.Price(o.reserve1.currency,o.reserve0.currency,o.reserve1.raw,o.reserve0.raw))}return t.slice(1).reduce((function(e,t){return e.multiply(t)}),t[0])}},{key:"chainId",get:function(){return this.pairs[0].chainId}}]),e}();function C(e,t){return r.currencyEquals(e.inputAmount.currency,t.inputAmount.currency)||n(!1),r.currencyEquals(e.outputAmount.currency,t.outputAmount.currency)||n(!1),e.outputAmount.equalTo(t.outputAmount)?e.inputAmount.equalTo(t.inputAmount)?0:e.inputAmount.lessThan(t.inputAmount)?-1:1:e.outputAmount.lessThan(t.outputAmount)?1:-1}function _(e,t){var r=C(e,t);return 0!==r?r:e.priceImpact.lessThan(t.priceImpact)?-1:e.priceImpact.greaterThan(t.priceImpact)?1:e.route.path.length-t.route.path.length}function R(e,t){if(e.currency.isToken)return e;if(e.currency.isEther)return new r.CurrencyAmount(r.WETH9[t],e.raw);throw new Error("CURRENCY")}function U(e,t){if(e.isToken)return e;if(e===r.ETHER)return r.WETH9[t];throw new Error("CURRENCY")}var H=function(){function e(e,t,u){var o,i,c,s=new Array(e.path.length),a=new Array(e.pairs.length);if(u===r.TradeType.EXACT_INPUT){r.currencyEquals(t.currency,e.input)||n(!1),s[0]=R(t,e.chainId);for(var l=0;l<e.path.length-1;l++){var p=e.pairs[l].getOutputAmount(s[l]),h=p[1];s[l+1]=p[0],a[l]=h}}else{r.currencyEquals(t.currency,e.output)||n(!1),s[s.length-1]=R(t,e.chainId);for(var y=e.path.length-1;y>0;y--){var f=e.pairs[y-1].getInputAmount(s[y]),d=f[1];s[y-1]=f[0],a[y-1]=d}}this.route=e,this.tradeType=u,this.inputAmount=u===r.TradeType.EXACT_INPUT?t:e.input===r.ETHER?r.CurrencyAmount.ether(s[0].raw):s[0],this.outputAmount=u===r.TradeType.EXACT_OUTPUT?t:e.output===r.ETHER?r.CurrencyAmount.ether(s[s.length-1].raw):s[s.length-1],this.executionPrice=new r.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=new P(a,e.input).midPrice,this.priceImpact=(o=this.outputAmount,c=(i=e.midPrice.raw.multiply(this.inputAmount.raw)).subtract(o.raw).divide(i),new r.Percent(c.numerator,c.denominator))}e.exactIn=function(t,n){return new e(t,n,r.TradeType.EXACT_INPUT)},e.exactOut=function(t,n){return new e(t,n,r.TradeType.EXACT_OUTPUT)};var t=e.prototype;return t.minimumAmountOut=function(e){if(e.lessThan(s)&&n(!1),this.tradeType===r.TradeType.EXACT_OUTPUT)return this.outputAmount;var t=new r.Fraction(a).add(e).invert().multiply(this.outputAmount.raw).quotient;return new r.CurrencyAmount(this.outputAmount.currency,t)},t.maximumAmountIn=function(e){if(e.lessThan(s)&&n(!1),this.tradeType===r.TradeType.EXACT_INPUT)return this.inputAmount;var t=new r.Fraction(a).add(e).multiply(this.inputAmount.raw).quotient;return new r.CurrencyAmount(this.inputAmount.currency,t)},e.bestTradeExactIn=function(t,u,o,i,c,a,l){var p=void 0===i?{}:i,h=p.maxNumResults,y=void 0===h?3:h,f=p.maxHops,d=void 0===f?3:f;void 0===c&&(c=[]),void 0===a&&(a=u),void 0===l&&(l=[]),t.length>0||n(!1),d>0||n(!1),a===u||c.length>0||n(!1);var v=u.currency.isToken?u.currency.chainId:o.isToken?o.chainId:void 0;void 0===v&&n(!1);for(var T=R(u,v),m=U(o,v),k=0;k<t.length;k++){var w=t[k];if((r.currencyEquals(w.token0,T.currency)||r.currencyEquals(w.token1,T.currency))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getOutputAmount(T)[0]}catch(e){if(e.isInsufficientInputAmountError)continue;throw e}if(r.currencyEquals(A.currency,m))r.sortedInsert(l,new e(new P([].concat(c,[w]),a.currency,o),a,r.TradeType.EXACT_INPUT),y,_);else if(d>1&&t.length>1){var E=t.slice(0,k).concat(t.slice(k+1,t.length));e.bestTradeExactIn(E,A,o,{maxNumResults:y,maxHops:d-1},[].concat(c,[w]),a,l)}}}return l},t.worstExecutionPrice=function(e){return new r.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(e).raw,this.minimumAmountOut(e).raw)},e.bestTradeExactOut=function(t,u,o,i,c,a,l){var p=void 0===i?{}:i,h=p.maxNumResults,y=void 0===h?3:h,f=p.maxHops,d=void 0===f?3:f;void 0===c&&(c=[]),void 0===a&&(a=o),void 0===l&&(l=[]),t.length>0||n(!1),d>0||n(!1),a===o||c.length>0||n(!1);var v=o.currency.isToken?o.currency.chainId:u.isToken?u.chainId:void 0;void 0===v&&n(!1);for(var T=R(o,v),m=U(u,v),k=0;k<t.length;k++){var w=t[k];if((r.currencyEquals(w.token0,T.currency)||r.currencyEquals(w.token1,T.currency))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getInputAmount(T)[0]}catch(e){if(e.isInsufficientReservesError)continue;throw e}if(r.currencyEquals(A.currency,m))r.sortedInsert(l,new e(new P([w].concat(c),u,a.currency),a,r.TradeType.EXACT_OUTPUT),y,_);else if(d>1&&t.length>1){var E=t.slice(0,k).concat(t.slice(k+1,t.length));e.bestTradeExactOut(E,u,A,{maxNumResults:y,maxHops:d-1},[w].concat(c),a,l)}}}return l},e}();function S(e){return"0x"+e.raw.toString(16)}var B=function(){function e(){}return e.swapCallParameters=function(e,t){var u=e.inputAmount.currency===r.ETHER,o=e.outputAmount.currency===r.ETHER;u&&o&&n(!1),!("ttl"in t)||t.ttl>0||n(!1);var i,c,s,a=r.validateAndParseAddress(t.recipient),l=S(e.maximumAmountIn(t.allowedSlippage)),p=S(e.minimumAmountOut(t.allowedSlippage)),h=e.route.path.map((function(e){return e.address})),y="ttl"in t?"0x"+(Math.floor((new Date).getTime()/1e3)+t.ttl).toString(16):"0x"+t.deadline.toString(16),f=Boolean(t.feeOnTransfer);switch(e.tradeType){case r.TradeType.EXACT_INPUT:u?(i=f?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",c=[p,h,a,y],s=l):o?(i=f?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",c=[l,p,h,a,y],s="0x0"):(i=f?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",c=[l,p,h,a,y],s="0x0");break;case r.TradeType.EXACT_OUTPUT:f&&n(!1),u?(i="swapETHForExactTokens",c=[p,h,a,y],s=l):o?(i="swapTokensForExactETH",c=[p,l,h,a,y],s="0x0"):(i="swapTokensForExactTokens",c=[p,l,h,a,y],s="0x0")}return{methodName:i,args:c,value:s}},e}();exports.JSBI=t,exports.FACTORY_ADDRESS="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.INIT_CODE_HASH=i,exports.InsufficientInputAmountError=x,exports.InsufficientReservesError=q,exports.MINIMUM_LIQUIDITY=c,exports.Pair=O,exports.Route=P,exports.Router=B,exports.Trade=H,exports.computePairAddress=b,exports.inputOutputComparator=C,exports.tradeComparator=_; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("jsbi")),r=require("@uniswap/sdk-core"),n=t(require("tiny-invariant")),o=require("@ethersproject/solidity"),i=require("@ethersproject/address"),u=t(require("decimal.js-light")),a=t(require("big.js")),s=t(require("toformat")),c="0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",p=e.BigInt(1e3),l=e.BigInt(0),d=e.BigInt(1),m=e.BigInt(5),h=e.BigInt(997),f=e.BigInt(1e3);function y(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function v(t,e,r){return e&&y(t.prototype,e),r&&y(t,r),t}function T(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function A(t){return(A=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function q(t,e){return(q=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function g(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function k(t,e,r){return(k=g()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&q(o,r.prototype),o}).apply(null,arguments)}function w(t){var e="function"==typeof Map?new Map:void 0;return(w=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return k(t,arguments,A(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),q(r,t)})(t)}function E(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function I(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function O(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return I(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?I(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=t[Symbol.iterator]()).next.bind(r)}var b,P,x,_="setPrototypeOf"in Object,N=function(t){function e(){var r;return(r=t.call(this)||this).isInsufficientReservesError=!0,r.name=r.constructor.name,_&&Object.setPrototypeOf(E(r),(this instanceof e?this.constructor:void 0).prototype),r}return T(e,t),e}(w(Error)),R=function(t){function e(){var r;return(r=t.call(this)||this).isInsufficientInputAmountError=!0,r.name=r.constructor.name,_&&Object.setPrototypeOf(E(r),(this instanceof e?this.constructor:void 0).prototype),r}return T(e,t),e}(w(Error)),C=function(t){var e=t.factoryAddress,r=t.tokenA,n=t.tokenB,u=r.sortsBefore(n)?[r,n]:[n,r];return i.getCreate2Address(e,o.keccak256(["bytes"],[o.pack(["address","address"],[u[0].address,u[1].address])]),c)},U=function(){function t(e,n){var o=e.currency.sortsBefore(n.currency)?[e,n]:[n,e];this.liquidityToken=new r.Token(o[0].currency.chainId,t.getAddress(o[0].currency,o[1].currency),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=o}t.getAddress=function(t,e){return C({factoryAddress:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",tokenA:t,tokenB:e})};var o=t.prototype;return o.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},o.priceOf=function(t){return this.involvesToken(t)||n(!1),t.equals(this.token0)?this.token0Price:this.token1Price},o.reserveOf=function(t){return this.involvesToken(t)||n(!1),t.equals(this.token0)?this.reserve0:this.reserve1},o.getOutputAmount=function(o){if(this.involvesToken(o.currency)||n(!1),e.equal(this.reserve0.quotient,l)||e.equal(this.reserve1.quotient,l))throw new N;var i=this.reserveOf(o.currency),u=this.reserveOf(o.currency.equals(this.token0)?this.token1:this.token0),a=e.multiply(o.quotient,h),s=e.multiply(a,u.quotient),c=e.add(e.multiply(i.quotient,f),a),p=r.CurrencyAmount.fromRawAmount(o.currency.equals(this.token0)?this.token1:this.token0,e.divide(s,c));if(e.equal(p.quotient,l))throw new R;return[p,new t(i.add(o),u.subtract(p))]},o.getInputAmount=function(o){if(this.involvesToken(o.currency)||n(!1),e.equal(this.reserve0.quotient,l)||e.equal(this.reserve1.quotient,l)||e.greaterThanOrEqual(o.quotient,this.reserveOf(o.currency).quotient))throw new N;var i=this.reserveOf(o.currency),u=this.reserveOf(o.currency.equals(this.token0)?this.token1:this.token0),a=e.multiply(e.multiply(u.quotient,o.quotient),f),s=e.multiply(e.subtract(i.quotient,o.quotient),h),c=r.CurrencyAmount.fromRawAmount(o.currency.equals(this.token0)?this.token1:this.token0,e.add(e.divide(a,s),d));return[c,new t(u.add(c),i.subtract(o))]},o.getLiquidityMinted=function(t,o,i){t.currency.equals(this.liquidityToken)||n(!1);var u,a=o.currency.sortsBefore(i.currency)?[o,i]:[i,o];if(a[0].currency.equals(this.token0)&&a[1].currency.equals(this.token1)||n(!1),e.equal(t.quotient,l))u=e.subtract(r.sqrt(e.multiply(a[0].quotient,a[1].quotient)),p);else{var s=e.divide(e.multiply(a[0].quotient,t.quotient),this.reserve0.quotient),c=e.divide(e.multiply(a[1].quotient,t.quotient),this.reserve1.quotient);u=e.lessThanOrEqual(s,c)?s:c}if(!e.greaterThan(u,l))throw new R;return r.CurrencyAmount.fromRawAmount(this.liquidityToken,u)},o.getLiquidityValue=function(t,o,i,u,a){var s;if(void 0===u&&(u=!1),this.involvesToken(t)||n(!1),o.currency.equals(this.liquidityToken)||n(!1),i.currency.equals(this.liquidityToken)||n(!1),e.lessThanOrEqual(i.quotient,o.quotient)||n(!1),u){a||n(!1);var c=e.BigInt(a);if(e.equal(c,l))s=o;else{var p=r.sqrt(e.multiply(this.reserve0.quotient,this.reserve1.quotient)),d=r.sqrt(c);if(e.greaterThan(p,d)){var h=e.multiply(o.quotient,e.subtract(p,d)),f=e.add(e.multiply(p,m),d),y=e.divide(h,f);s=o.add(r.CurrencyAmount.fromRawAmount(this.liquidityToken,y))}else s=o}}else s=o;return r.CurrencyAmount.fromRawAmount(t,e.divide(e.multiply(i.quotient,this.reserveOf(t).quotient),s.quotient))},v(t,[{key:"token0Price",get:function(){var t=this.tokenAmounts[1].divide(this.tokenAmounts[0]);return new r.Price(this.token0,this.token1,t.denominator,t.numerator)}},{key:"token1Price",get:function(){var t=this.tokenAmounts[0].divide(this.tokenAmounts[1]);return new r.Price(this.token1,this.token0,t.denominator,t.numerator)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"token0",get:function(){return this.tokenAmounts[0].currency}},{key:"token1",get:function(){return this.tokenAmounts[1].currency}},{key:"reserve0",get:function(){return this.tokenAmounts[0]}},{key:"reserve1",get:function(){return this.tokenAmounts[1]}}]),t}(),F=function(){function t(t,e,o){this._midPrice=null,t.length>0||n(!1);var i=t[0].chainId;t.every((function(t){return t.chainId===i}))||n(!1);var u=r.wrappedCurrency(e,i);t[0].involvesToken(u)||n(!1),void 0===o||t[t.length-1].involvesToken(r.wrappedCurrency(o,i))||n(!1);for(var a,s=[u],c=O(t.entries());!(a=c()).done;){var p=a.value,l=p[1],d=s[p[0]];d.equals(l.token0)||d.equals(l.token1)||n(!1);var m=d.equals(l.token0)?l.token1:l.token0;s.push(m)}this.pairs=t,this.path=s,this.input=e,this.output=o}return v(t,[{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;for(var t,e=[],n=O(this.pairs.entries());!(t=n()).done;){var o=t.value,i=o[1];e.push(this.path[o[0]].equals(i.token0)?new r.Price(i.reserve0.currency,i.reserve1.currency,i.reserve0.quotient,i.reserve1.quotient):new r.Price(i.reserve1.currency,i.reserve0.currency,i.reserve1.quotient,i.reserve0.quotient))}var u=e.slice(1).reduce((function(t,e){return t.multiply(e)}),e[0]);return this._midPrice=new r.Price(this.input,this.output,u.denominator,u.numerator)}},{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}();function D(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}!function(t){t[t.MAINNET=1]="MAINNET",t[t.ROPSTEN=3]="ROPSTEN",t[t.RINKEBY=4]="RINKEBY",t[t["GÖRLI"]=5]="GÖRLI",t[t.KOVAN=42]="KOVAN"}(b||(b={})),function(t){t[t.EXACT_INPUT=0]="EXACT_INPUT",t[t.EXACT_OUTPUT=1]="EXACT_OUTPUT"}(P||(P={})),function(t){t[t.ROUND_DOWN=0]="ROUND_DOWN",t[t.ROUND_HALF_UP=1]="ROUND_HALF_UP",t[t.ROUND_UP=2]="ROUND_UP"}(x||(x={}));var S,B,H=function(t,e,r){t>=0&&t<255&&Number.isInteger(t)||n(!1),this.decimals=t,this.symbol=e,this.name=r},j=s(u),L=s(a),W=((S={})[x.ROUND_DOWN]=j.ROUND_DOWN,S[x.ROUND_HALF_UP]=j.ROUND_HALF_UP,S[x.ROUND_UP]=j.ROUND_UP,S),M=((B={})[x.ROUND_DOWN]=0,B[x.ROUND_HALF_UP]=1,B[x.ROUND_UP]=3,B),X=function(){function t(t,r){void 0===r&&(r=e.BigInt(1)),this.numerator=e.BigInt(t),this.denominator=e.BigInt(r)}t.tryParseFraction=function(r){if(r instanceof e||"number"==typeof r||"string"==typeof r)return new t(r);if("numerator"in r&&"denominator"in r)return r;throw new Error("Could not parse fraction")};var r,o=t.prototype;return o.invert=function(){return new t(this.denominator,this.numerator)},o.add=function(r){var n=t.tryParseFraction(r);return e.equal(this.denominator,n.denominator)?new t(e.add(this.numerator,n.numerator),this.denominator):new t(e.add(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator)),e.multiply(this.denominator,n.denominator))},o.subtract=function(r){var n=t.tryParseFraction(r);return e.equal(this.denominator,n.denominator)?new t(e.subtract(this.numerator,n.numerator),this.denominator):new t(e.subtract(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator)),e.multiply(this.denominator,n.denominator))},o.lessThan=function(r){var n=t.tryParseFraction(r);return e.lessThan(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator))},o.equalTo=function(r){var n=t.tryParseFraction(r);return e.equal(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator))},o.greaterThan=function(r){var n=t.tryParseFraction(r);return e.greaterThan(e.multiply(this.numerator,n.denominator),e.multiply(n.numerator,this.denominator))},o.multiply=function(r){var n=t.tryParseFraction(r);return new t(e.multiply(this.numerator,n.numerator),e.multiply(this.denominator,n.denominator))},o.divide=function(r){var n=t.tryParseFraction(r);return new t(e.multiply(this.numerator,n.denominator),e.multiply(this.denominator,n.numerator))},o.toSignificant=function(t,e,r){void 0===e&&(e={groupSeparator:""}),void 0===r&&(r=x.ROUND_HALF_UP),Number.isInteger(t)||n(!1),t>0||n(!1),j.set({precision:t+1,rounding:W[r]});var o=new j(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),e)},o.toFixed=function(t,e,r){return void 0===e&&(e={groupSeparator:""}),void 0===r&&(r=x.ROUND_HALF_UP),Number.isInteger(t)||n(!1),t>=0||n(!1),L.DP=t,L.RM=M[r],new L(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},(r=[{key:"quotient",get:function(){return e.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(e.remainder(this.numerator,this.denominator),this.denominator)}},{key:"asFraction",get:function(){return new t(this.numerator,this.denominator)}}])&&function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}(t.prototype,r),t}(),K=new X(e.BigInt(100));function V(t){return new G(t.numerator,t.denominator)}var Y,G=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).isPercent=!0,e}D(e,t);var r=e.prototype;return r.add=function(e){return V(t.prototype.add.call(this,e))},r.subtract=function(e){return V(t.prototype.subtract.call(this,e))},r.multiply=function(e){return V(t.prototype.multiply.call(this,e))},r.divide=function(e){return V(t.prototype.divide.call(this,e))},r.toSignificant=function(e,r,n){return void 0===e&&(e=5),t.prototype.multiply.call(this,K).toSignificant(e,r,n)},r.toFixed=function(e,r,n){return void 0===e&&(e=2),t.prototype.multiply.call(this,K).toFixed(e,r,n)},e}(X);function Q(t){try{return i.getAddress(t)}catch(e){throw new Error(t+" is not a valid address.")}}var $=function(t){function e(e,r,n,o,i){var u;return(u=t.call(this,n,o,i)||this).isEther=!1,u.isToken=!0,u.chainId=e,u.address=Q(r),u}D(e,t);var r=e.prototype;return r.equals=function(t){return this===t||this.chainId===t.chainId&&this.address===t.address},r.sortsBefore=function(t){return this.chainId!==t.chainId&&n(!1),this.address===t.address&&n(!1),this.address.toLowerCase()<t.address.toLowerCase()},e}(H);function z(t,e){return r.currencyEquals(t.inputAmount.currency,e.inputAmount.currency)||n(!1),r.currencyEquals(t.outputAmount.currency,e.outputAmount.currency)||n(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?0:t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}function J(t,e){var r=z(t,e);return 0!==r?r:t.priceImpact.lessThan(e.priceImpact)?-1:t.priceImpact.greaterThan(e.priceImpact)?1:t.route.path.length-e.route.path.length}(Y={})[b.MAINNET]=new $(b.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH9","Wrapped Ether"),Y[b.ROPSTEN]=new $(b.ROPSTEN,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH9","Wrapped Ether"),Y[b.RINKEBY]=new $(b.RINKEBY,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH9","Wrapped Ether"),Y[b.GÖRLI]=new $(b.GÖRLI,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH9","Wrapped Ether"),Y[b.KOVAN]=new $(b.KOVAN,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH9","Wrapped Ether");var Z=function(){function t(t,e,o){this.route=t,this.tradeType=o;var i,u,a,s=new Array(t.path.length);if(o===r.TradeType.EXACT_INPUT){r.currencyEquals(e.currency,t.input)||n(!1),s[0]=r.wrappedCurrencyAmount(e,t.chainId);for(var c=0;c<t.path.length-1;c++){var p=t.pairs[c].getOutputAmount(s[c]);s[c+1]=p[0]}this.inputAmount=r.CurrencyAmount.fromFractionalAmount(t.input,e.numerator,e.denominator),this.outputAmount=r.CurrencyAmount.fromFractionalAmount(t.output,s[s.length-1].numerator,s[s.length-1].denominator)}else{r.currencyEquals(e.currency,t.output)||n(!1),s[s.length-1]=r.wrappedCurrencyAmount(e,t.chainId);for(var l=t.path.length-1;l>0;l--){var d=t.pairs[l-1].getInputAmount(s[l]);s[l-1]=d[0]}this.inputAmount=r.CurrencyAmount.fromFractionalAmount(t.input,s[0].numerator,s[0].denominator),this.outputAmount=r.CurrencyAmount.fromFractionalAmount(t.output,e.numerator,e.denominator)}this.executionPrice=new r.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient),this.priceImpact=(i=this.outputAmount,a=(u=t.midPrice.quote(this.inputAmount)).subtract(i).divide(u),new G(a.numerator,a.denominator))}t.exactIn=function(e,n){return new t(e,n,r.TradeType.EXACT_INPUT)},t.exactOut=function(e,n){return new t(e,n,r.TradeType.EXACT_OUTPUT)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(l)&&n(!1),this.tradeType===r.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new r.Fraction(d).add(t).invert().multiply(this.outputAmount.quotient).quotient;return r.CurrencyAmount.fromRawAmount(this.outputAmount.currency,e)},e.maximumAmountIn=function(t){if(t.lessThan(l)&&n(!1),this.tradeType===r.TradeType.EXACT_INPUT)return this.inputAmount;var e=new r.Fraction(d).add(t).multiply(this.inputAmount.quotient).quotient;return r.CurrencyAmount.fromRawAmount(this.inputAmount.currency,e)},t.bestTradeExactIn=function(e,o,i,u,a,s,c){var p=void 0===u?{}:u,d=p.maxNumResults,m=void 0===d?3:d,h=p.maxHops,f=void 0===h?3:h;void 0===a&&(a=[]),void 0===s&&(s=o),void 0===c&&(c=[]),e.length>0||n(!1),f>0||n(!1),o===s||a.length>0||n(!1);var y=s.currency.isToken?s.currency.chainId:i.isToken?i.chainId:void 0;void 0===y&&n(!1);for(var v=r.wrappedCurrencyAmount(s,y),T=r.wrappedCurrency(i,y),A=0;A<e.length;A++){var q=e[A];if((r.currencyEquals(q.token0,v.currency)||r.currencyEquals(q.token1,v.currency))&&!q.reserve0.equalTo(l)&&!q.reserve1.equalTo(l)){var g=void 0;try{g=q.getOutputAmount(v)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(r.currencyEquals(g.currency,T))r.sortedInsert(c,new t(new F([].concat(a,[q]),o.currency,i),o,r.TradeType.EXACT_INPUT),m,J);else if(f>1&&e.length>1){var k=e.slice(0,A).concat(e.slice(A+1,e.length));t.bestTradeExactIn(k,o,i,{maxNumResults:m,maxHops:f-1},[].concat(a,[q]),g,c)}}}return c},e.worstExecutionPrice=function(t){return new r.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactOut=function(e,o,i,u,a,s,c){var p=void 0===u?{}:u,d=p.maxNumResults,m=void 0===d?3:d,h=p.maxHops,f=void 0===h?3:h;void 0===a&&(a=[]),void 0===s&&(s=i),void 0===c&&(c=[]),e.length>0||n(!1),f>0||n(!1),i===s||a.length>0||n(!1);var y=s.currency.isToken?s.currency.chainId:o.isToken?o.chainId:void 0;void 0===y&&n(!1);for(var v=r.wrappedCurrencyAmount(s,y),T=r.wrappedCurrency(o,y),A=0;A<e.length;A++){var q=e[A];if((r.currencyEquals(q.token0,v.currency)||r.currencyEquals(q.token1,v.currency))&&!q.reserve0.equalTo(l)&&!q.reserve1.equalTo(l)){var g=void 0;try{g=q.getInputAmount(v)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(r.currencyEquals(g.currency,T))r.sortedInsert(c,new t(new F([q].concat(a),o,i.currency),i,r.TradeType.EXACT_OUTPUT),m,J);else if(f>1&&e.length>1){var k=e.slice(0,A).concat(e.slice(A+1,e.length));t.bestTradeExactOut(k,o,i,{maxNumResults:m,maxHops:f-1},[q].concat(a),g,c)}}}return c},t}();function tt(t){return"0x"+t.quotient.toString(16)}var et=function(){function t(){}return t.swapCallParameters=function(t,e){var o=t.inputAmount.currency.isEther,i=t.outputAmount.currency.isEther;o&&i&&n(!1),!("ttl"in e)||e.ttl>0||n(!1);var u,a,s,c=r.validateAndParseAddress(e.recipient),p=tt(t.maximumAmountIn(e.allowedSlippage)),l=tt(t.minimumAmountOut(e.allowedSlippage)),d=t.route.path.map((function(t){return t.address})),m="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),h=Boolean(e.feeOnTransfer);switch(t.tradeType){case r.TradeType.EXACT_INPUT:o?(u=h?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",a=[l,d,c,m],s=p):i?(u=h?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",a=[p,l,d,c,m],s="0x0"):(u=h?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",a=[p,l,d,c,m],s="0x0");break;case r.TradeType.EXACT_OUTPUT:h&&n(!1),o?(u="swapETHForExactTokens",a=[l,d,c,m],s=p):i?(u="swapTokensForExactETH",a=[l,p,d,c,m],s="0x0"):(u="swapTokensForExactTokens",a=[l,p,d,c,m],s="0x0")}return{methodName:u,args:a,value:s}},t}();exports.FACTORY_ADDRESS="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.INIT_CODE_HASH=c,exports.InsufficientInputAmountError=R,exports.InsufficientReservesError=N,exports.MINIMUM_LIQUIDITY=p,exports.Pair=U,exports.Route=F,exports.Router=et,exports.Trade=Z,exports.computePairAddress=C,exports.inputOutputComparator=z,exports.tradeComparator=J; | ||
//# sourceMappingURL=v2-sdk.cjs.production.min.js.map |
import JSBI from 'jsbi'; | ||
export { default as JSBI } from 'jsbi'; | ||
import { CurrencyAmount, sqrt, Token, Price, ETHER, WETH9, currencyEquals, TradeType, Fraction, Percent, sortedInsert, validateAndParseAddress } from '@uniswap/sdk-core'; | ||
import { CurrencyAmount, sqrt, Token as Token$1, Price, wrappedCurrency, currencyEquals, TradeType as TradeType$1, Fraction as Fraction$1, wrappedCurrencyAmount, sortedInsert, validateAndParseAddress as validateAndParseAddress$1 } from '@uniswap/sdk-core'; | ||
import invariant from 'tiny-invariant'; | ||
import { keccak256, pack } from '@ethersproject/solidity'; | ||
import { getCreate2Address } from '@ethersproject/address'; | ||
import { getCreate2Address, getAddress } from '@ethersproject/address'; | ||
import _Decimal from 'decimal.js-light'; | ||
import _Big from 'big.js'; | ||
import toFormat from 'toformat'; | ||
@@ -231,7 +233,5 @@ var FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'; | ||
function Pair(currencyAmountA, tokenAmountB) { | ||
!(currencyAmountA.currency.isToken && tokenAmountB.currency.isToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; | ||
var tokenAmounts = currencyAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks | ||
? [currencyAmountA, tokenAmountB] : [tokenAmountB, currencyAmountA]; | ||
!(tokenAmounts[0].currency.isToken && tokenAmounts[1].currency.isToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; | ||
this.liquidityToken = new Token(tokenAmounts[0].currency.chainId, Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency), 18, 'UNI-V2', 'Uniswap V2'); | ||
this.liquidityToken = new Token$1(tokenAmounts[0].currency.chainId, Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency), 18, 'UNI-V2', 'Uniswap V2'); | ||
this.tokenAmounts = tokenAmounts; | ||
@@ -282,5 +282,5 @@ } | ||
_proto.getOutputAmount = function getOutputAmount(inputAmount) { | ||
!(inputAmount.currency.isToken && this.involvesToken(inputAmount.currency)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; | ||
!this.involvesToken(inputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; | ||
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO)) { | ||
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) { | ||
throw new InsufficientReservesError(); | ||
@@ -291,8 +291,8 @@ } | ||
var outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0); | ||
var inputAmountWithFee = JSBI.multiply(inputAmount.raw, _997); | ||
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.raw); | ||
var denominator = JSBI.add(JSBI.multiply(inputReserve.raw, _1000), inputAmountWithFee); | ||
var outputAmount = new CurrencyAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator)); | ||
var inputAmountWithFee = JSBI.multiply(inputAmount.quotient, _997); | ||
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.quotient); | ||
var denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFee); | ||
var outputAmount = CurrencyAmount.fromRawAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator)); | ||
if (JSBI.equal(outputAmount.raw, ZERO)) { | ||
if (JSBI.equal(outputAmount.quotient, ZERO)) { | ||
throw new InsufficientInputAmountError(); | ||
@@ -305,5 +305,5 @@ } | ||
_proto.getInputAmount = function getInputAmount(outputAmount) { | ||
!(outputAmount.currency.isToken && this.involvesToken(outputAmount.currency)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; | ||
!this.involvesToken(outputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; | ||
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO) || JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.currency).raw)) { | ||
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO) || JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient)) { | ||
throw new InsufficientReservesError(); | ||
@@ -314,5 +314,5 @@ } | ||
var inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0); | ||
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.raw, outputAmount.raw), _1000); | ||
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.raw, outputAmount.raw), _997); | ||
var inputAmount = new CurrencyAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE)); | ||
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmount.quotient), _1000); | ||
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmount.quotient), _997); | ||
var inputAmount = CurrencyAmount.fromRawAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE)); | ||
return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]; | ||
@@ -322,14 +322,13 @@ }; | ||
_proto.getLiquidityMinted = function getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) { | ||
!(totalSupply.currency.isToken && totalSupply.currency.equals(this.liquidityToken)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; | ||
var tokenAmounts = tokenAmountA.currency.isToken && tokenAmountB.currency.isToken && tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks | ||
!totalSupply.currency.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; | ||
var tokenAmounts = tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks | ||
? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA]; | ||
!(tokenAmounts[0].currency.isToken && tokenAmounts[1].currency.isToken) ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
!(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; | ||
var liquidity; | ||
if (JSBI.equal(totalSupply.raw, ZERO)) { | ||
liquidity = JSBI.subtract(sqrt(JSBI.multiply(tokenAmounts[0].raw, tokenAmounts[1].raw)), MINIMUM_LIQUIDITY); | ||
if (JSBI.equal(totalSupply.quotient, ZERO)) { | ||
liquidity = JSBI.subtract(sqrt(JSBI.multiply(tokenAmounts[0].quotient, tokenAmounts[1].quotient)), MINIMUM_LIQUIDITY); | ||
} else { | ||
var amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].raw, totalSupply.raw), this.reserve0.raw); | ||
var amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].raw, totalSupply.raw), this.reserve1.raw); | ||
var amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].quotient, totalSupply.quotient), this.reserve0.quotient); | ||
var amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].quotient, totalSupply.quotient), this.reserve1.quotient); | ||
liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1; | ||
@@ -342,3 +341,3 @@ } | ||
return new CurrencyAmount(this.liquidityToken, liquidity); | ||
return CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity); | ||
}; | ||
@@ -352,5 +351,5 @@ | ||
!this.involvesToken(token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0; | ||
!(totalSupply.currency.isToken && totalSupply.currency.equals(this.liquidityToken)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOTAL_SUPPLY') : invariant(false) : void 0; | ||
!(liquidity.currency.isToken && liquidity.currency.equals(this.liquidityToken)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; | ||
!JSBI.lessThanOrEqual(liquidity.raw, totalSupply.raw) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; | ||
!totalSupply.currency.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOTAL_SUPPLY') : invariant(false) : void 0; | ||
!liquidity.currency.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; | ||
!JSBI.lessThanOrEqual(liquidity.quotient, totalSupply.quotient) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0; | ||
var totalSupplyAdjusted; | ||
@@ -365,10 +364,10 @@ | ||
if (!JSBI.equal(kLastParsed, ZERO)) { | ||
var rootK = sqrt(JSBI.multiply(this.reserve0.raw, this.reserve1.raw)); | ||
var rootK = sqrt(JSBI.multiply(this.reserve0.quotient, this.reserve1.quotient)); | ||
var rootKLast = sqrt(kLastParsed); | ||
if (JSBI.greaterThan(rootK, rootKLast)) { | ||
var numerator = JSBI.multiply(totalSupply.raw, JSBI.subtract(rootK, rootKLast)); | ||
var numerator = JSBI.multiply(totalSupply.quotient, JSBI.subtract(rootK, rootKLast)); | ||
var denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast); | ||
var feeLiquidity = JSBI.divide(numerator, denominator); | ||
totalSupplyAdjusted = totalSupply.add(new CurrencyAmount(this.liquidityToken, feeLiquidity)); | ||
totalSupplyAdjusted = totalSupply.add(CurrencyAmount.fromRawAmount(this.liquidityToken, feeLiquidity)); | ||
} else { | ||
@@ -382,3 +381,3 @@ totalSupplyAdjusted = totalSupply; | ||
return new CurrencyAmount(token, JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw)); | ||
return CurrencyAmount.fromRawAmount(token, JSBI.divide(JSBI.multiply(liquidity.quotient, this.reserveOf(token).quotient), totalSupplyAdjusted.quotient)); | ||
}; | ||
@@ -389,3 +388,4 @@ | ||
get: function get() { | ||
return new Price(this.token0, this.token1, this.tokenAmounts[0].raw, this.tokenAmounts[1].raw); | ||
var result = this.tokenAmounts[1].divide(this.tokenAmounts[0]); | ||
return new Price(this.token0, this.token1, result.denominator, result.numerator); | ||
} | ||
@@ -399,3 +399,4 @@ /** | ||
get: function get() { | ||
return new Price(this.token1, this.token0, this.tokenAmounts[1].raw, this.tokenAmounts[0].raw); | ||
var result = this.tokenAmounts[0].divide(this.tokenAmounts[1]); | ||
return new Price(this.token1, this.token0, result.denominator, result.numerator); | ||
} | ||
@@ -410,3 +411,2 @@ }, { | ||
get: function get() { | ||
!this.tokenAmounts[0].currency.isToken ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
return this.tokenAmounts[0].currency; | ||
@@ -417,3 +417,2 @@ } | ||
get: function get() { | ||
!this.tokenAmounts[1].currency.isToken ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
return this.tokenAmounts[1].currency; | ||
@@ -438,2 +437,3 @@ } | ||
function Route(pairs, input, output) { | ||
this._midPrice = null; | ||
!(pairs.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'PAIRS') : invariant(false) : void 0; | ||
@@ -444,6 +444,6 @@ var chainId = pairs[0].chainId; | ||
}) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_IDS') : invariant(false) : void 0; | ||
var weth = WETH9[chainId]; | ||
!(input.isToken && pairs[0].involvesToken(input) || input === ETHER && weth && pairs[0].involvesToken(weth)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0; | ||
!(typeof output === 'undefined' || output.isToken && pairs[pairs.length - 1].involvesToken(output) || output === ETHER && weth && pairs[pairs.length - 1].involvesToken(weth)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0; | ||
var path = [input.isToken ? input : weth]; | ||
var wrappedInput = wrappedCurrency(input, chainId); | ||
!pairs[0].involvesToken(wrappedInput) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0; | ||
!(typeof output === 'undefined' || pairs[pairs.length - 1].involvesToken(wrappedCurrency(output, chainId))) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0; | ||
var path = [wrappedInput]; | ||
@@ -465,3 +465,3 @@ for (var _iterator = _createForOfIteratorHelperLoose(pairs.entries()), _step; !(_step = _iterator()).done;) { | ||
this.input = input; | ||
this.output = output != null ? output : path[path.length - 1]; | ||
this.output = output; | ||
} | ||
@@ -472,2 +472,3 @@ | ||
get: function get() { | ||
if (this._midPrice !== null) return this._midPrice; | ||
var prices = []; | ||
@@ -479,8 +480,9 @@ | ||
pair = _step2$value[1]; | ||
prices.push(this.path[i].equals(pair.token0) ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.raw, pair.reserve1.raw) : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.raw, pair.reserve0.raw)); | ||
prices.push(this.path[i].equals(pair.token0) ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient) : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient)); | ||
} | ||
return prices.slice(1).reduce(function (accumulator, currentValue) { | ||
var reduced = prices.slice(1).reduce(function (accumulator, currentValue) { | ||
return accumulator.multiply(currentValue); | ||
}, prices[0]); | ||
return this._midPrice = new Price(this.input, this.output, reduced.denominator, reduced.numerator); | ||
} | ||
@@ -497,3 +499,337 @@ }, { | ||
var ChainId; | ||
(function (ChainId) { | ||
ChainId[ChainId["MAINNET"] = 1] = "MAINNET"; | ||
ChainId[ChainId["ROPSTEN"] = 3] = "ROPSTEN"; | ||
ChainId[ChainId["RINKEBY"] = 4] = "RINKEBY"; | ||
ChainId[ChainId["G\xD6RLI"] = 5] = "G\xD6RLI"; | ||
ChainId[ChainId["KOVAN"] = 42] = "KOVAN"; | ||
})(ChainId || (ChainId = {})); | ||
var TradeType; | ||
(function (TradeType) { | ||
TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT"; | ||
TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT"; | ||
})(TradeType || (TradeType = {})); | ||
var Rounding; | ||
(function (Rounding) { | ||
Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN"; | ||
Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP"; | ||
Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP"; | ||
})(Rounding || (Rounding = {})); | ||
function _defineProperties$1(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass$1(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties$1(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _inheritsLoose$1(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
/** | ||
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens. | ||
* | ||
* The only instance of the base class `Currency` is Ether. | ||
*/ | ||
var BaseCurrency = | ||
/** | ||
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`. | ||
* @param decimals decimals of the currency | ||
* @param symbol symbol of the currency | ||
* @param name of the currency | ||
*/ | ||
function BaseCurrency(decimals, symbol, name) { | ||
!(decimals >= 0 && decimals < 255 && Number.isInteger(decimals)) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, 'DECIMALS') : invariant(false) : process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
this.decimals = decimals; | ||
this.symbol = symbol; | ||
this.name = name; | ||
}; | ||
var _toSignificantRoundin, _toFixedRounding; | ||
var Decimal = /*#__PURE__*/toFormat(_Decimal); | ||
var Big = /*#__PURE__*/toFormat(_Big); | ||
var toSignificantRounding = (_toSignificantRoundin = {}, _toSignificantRoundin[Rounding.ROUND_DOWN] = Decimal.ROUND_DOWN, _toSignificantRoundin[Rounding.ROUND_HALF_UP] = Decimal.ROUND_HALF_UP, _toSignificantRoundin[Rounding.ROUND_UP] = Decimal.ROUND_UP, _toSignificantRoundin); | ||
var toFixedRounding = (_toFixedRounding = {}, _toFixedRounding[Rounding.ROUND_DOWN] = 0, _toFixedRounding[Rounding.ROUND_HALF_UP] = 1, _toFixedRounding[Rounding.ROUND_UP] = 3, _toFixedRounding); | ||
var Fraction = /*#__PURE__*/function () { | ||
function Fraction(numerator, denominator) { | ||
if (denominator === void 0) { | ||
denominator = JSBI.BigInt(1); | ||
} | ||
this.numerator = JSBI.BigInt(numerator); | ||
this.denominator = JSBI.BigInt(denominator); | ||
} | ||
Fraction.tryParseFraction = function tryParseFraction(fractionish) { | ||
if (fractionish instanceof JSBI || typeof fractionish === 'number' || typeof fractionish === 'string') return new Fraction(fractionish); | ||
if ('numerator' in fractionish && 'denominator' in fractionish) return fractionish; | ||
throw new Error('Could not parse fraction'); | ||
} // performs floor division | ||
; | ||
var _proto = Fraction.prototype; | ||
_proto.invert = function invert() { | ||
return new Fraction(this.denominator, this.numerator); | ||
}; | ||
_proto.add = function add(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
if (JSBI.equal(this.denominator, otherParsed.denominator)) { | ||
return new Fraction(JSBI.add(this.numerator, otherParsed.numerator), this.denominator); | ||
} | ||
return new Fraction(JSBI.add(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator)); | ||
}; | ||
_proto.subtract = function subtract(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
if (JSBI.equal(this.denominator, otherParsed.denominator)) { | ||
return new Fraction(JSBI.subtract(this.numerator, otherParsed.numerator), this.denominator); | ||
} | ||
return new Fraction(JSBI.subtract(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator)); | ||
}; | ||
_proto.lessThan = function lessThan(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return JSBI.lessThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); | ||
}; | ||
_proto.equalTo = function equalTo(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return JSBI.equal(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); | ||
}; | ||
_proto.greaterThan = function greaterThan(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return JSBI.greaterThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); | ||
}; | ||
_proto.multiply = function multiply(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return new Fraction(JSBI.multiply(this.numerator, otherParsed.numerator), JSBI.multiply(this.denominator, otherParsed.denominator)); | ||
}; | ||
_proto.divide = function divide(other) { | ||
var otherParsed = Fraction.tryParseFraction(other); | ||
return new Fraction(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(this.denominator, otherParsed.numerator)); | ||
}; | ||
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) { | ||
if (format === void 0) { | ||
format = { | ||
groupSeparator: '' | ||
}; | ||
} | ||
if (rounding === void 0) { | ||
rounding = Rounding.ROUND_HALF_UP; | ||
} | ||
!Number.isInteger(significantDigits) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, significantDigits + " is not an integer.") : invariant(false) : process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
!(significantDigits > 0) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, significantDigits + " is not positive.") : invariant(false) : process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
Decimal.set({ | ||
precision: significantDigits + 1, | ||
rounding: toSignificantRounding[rounding] | ||
}); | ||
var quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits); | ||
return quotient.toFormat(quotient.decimalPlaces(), format); | ||
}; | ||
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) { | ||
if (format === void 0) { | ||
format = { | ||
groupSeparator: '' | ||
}; | ||
} | ||
if (rounding === void 0) { | ||
rounding = Rounding.ROUND_HALF_UP; | ||
} | ||
!Number.isInteger(decimalPlaces) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, decimalPlaces + " is not an integer.") : invariant(false) : process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
!(decimalPlaces >= 0) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, decimalPlaces + " is negative.") : invariant(false) : process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
Big.DP = decimalPlaces; | ||
Big.RM = toFixedRounding[rounding]; | ||
return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format); | ||
} | ||
/** | ||
* Helper method for converting any super class back to a fraction | ||
*/ | ||
; | ||
_createClass$1(Fraction, [{ | ||
key: "quotient", | ||
get: function get() { | ||
return JSBI.divide(this.numerator, this.denominator); | ||
} // remainder after floor division | ||
}, { | ||
key: "remainder", | ||
get: function get() { | ||
return new Fraction(JSBI.remainder(this.numerator, this.denominator), this.denominator); | ||
} | ||
}, { | ||
key: "asFraction", | ||
get: function get() { | ||
return new Fraction(this.numerator, this.denominator); | ||
} | ||
}]); | ||
return Fraction; | ||
}(); | ||
var ONE_HUNDRED = /*#__PURE__*/new Fraction( /*#__PURE__*/JSBI.BigInt(100)); | ||
/** | ||
* Converts a fraction to a percent | ||
* @param fraction the fraction to convert | ||
*/ | ||
function toPercent(fraction) { | ||
return new Percent(fraction.numerator, fraction.denominator); | ||
} | ||
var Percent = /*#__PURE__*/function (_Fraction) { | ||
_inheritsLoose$1(Percent, _Fraction); | ||
function Percent() { | ||
var _this; | ||
_this = _Fraction.apply(this, arguments) || this; | ||
/** | ||
* This boolean prevents a fraction from being interpreted as a Percent | ||
*/ | ||
_this.isPercent = true; | ||
return _this; | ||
} | ||
var _proto = Percent.prototype; | ||
_proto.add = function add(other) { | ||
return toPercent(_Fraction.prototype.add.call(this, other)); | ||
}; | ||
_proto.subtract = function subtract(other) { | ||
return toPercent(_Fraction.prototype.subtract.call(this, other)); | ||
}; | ||
_proto.multiply = function multiply(other) { | ||
return toPercent(_Fraction.prototype.multiply.call(this, other)); | ||
}; | ||
_proto.divide = function divide(other) { | ||
return toPercent(_Fraction.prototype.divide.call(this, other)); | ||
}; | ||
_proto.toSignificant = function toSignificant(significantDigits, format, rounding) { | ||
if (significantDigits === void 0) { | ||
significantDigits = 5; | ||
} | ||
return _Fraction.prototype.multiply.call(this, ONE_HUNDRED).toSignificant(significantDigits, format, rounding); | ||
}; | ||
_proto.toFixed = function toFixed(decimalPlaces, format, rounding) { | ||
if (decimalPlaces === void 0) { | ||
decimalPlaces = 2; | ||
} | ||
return _Fraction.prototype.multiply.call(this, ONE_HUNDRED).toFixed(decimalPlaces, format, rounding); | ||
}; | ||
return Percent; | ||
}(Fraction); | ||
/** | ||
* Validates an address and returns the parsed (checksummed) version of that address | ||
* @param address the unchecksummed hex address | ||
*/ | ||
function validateAndParseAddress(address) { | ||
try { | ||
return getAddress(address); | ||
} catch (error) { | ||
throw new Error(address + " is not a valid address."); | ||
} | ||
} | ||
var _WETH; | ||
/** | ||
* Represents an ERC20 token with a unique address and some metadata. | ||
*/ | ||
var Token = /*#__PURE__*/function (_BaseCurrency) { | ||
_inheritsLoose$1(Token, _BaseCurrency); | ||
function Token(chainId, address, decimals, symbol, name) { | ||
var _this; | ||
_this = _BaseCurrency.call(this, decimals, symbol, name) || this; | ||
_this.isEther = false; | ||
_this.isToken = true; | ||
_this.chainId = chainId; | ||
_this.address = validateAndParseAddress(address); | ||
return _this; | ||
} | ||
/** | ||
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address. | ||
* @param other other token to compare | ||
*/ | ||
var _proto = Token.prototype; | ||
_proto.equals = function equals(other) { | ||
// short circuit on reference equality | ||
if (this === other) { | ||
return true; | ||
} | ||
return this.chainId === other.chainId && this.address === other.address; | ||
} | ||
/** | ||
* Returns true if the address of this token sorts before the address of the other token | ||
* @param other other token to compare | ||
* @throws if the tokens have the same address | ||
* @throws if the tokens are on different chains | ||
*/ | ||
; | ||
_proto.sortsBefore = function sortsBefore(other) { | ||
!(this.chainId === other.chainId) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_IDS') : invariant(false) : process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
!(this.address !== other.address) ? process.env.NODE_ENV !== "production" ? process.env.NODE_ENV !== "production" ? invariant(false, 'ADDRESSES') : invariant(false) : process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0; | ||
return this.address.toLowerCase() < other.address.toLowerCase(); | ||
}; | ||
return Token; | ||
}(BaseCurrency); | ||
var WETH9 = (_WETH = {}, _WETH[ChainId.MAINNET] = /*#__PURE__*/new Token(ChainId.MAINNET, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.ROPSTEN] = /*#__PURE__*/new Token(ChainId.ROPSTEN, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.RINKEBY] = /*#__PURE__*/new Token(ChainId.RINKEBY, '0xc778417E063141139Fce010982780140Aa0cD5Ab', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.GÖRLI] = /*#__PURE__*/new Token(ChainId.GÖRLI, '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', 18, 'WETH9', 'Wrapped Ether'), _WETH[ChainId.KOVAN] = /*#__PURE__*/new Token(ChainId.KOVAN, '0xd0A1E359811322d97991E03f863a0C30C2cF029C', 18, 'WETH9', 'Wrapped Ether'), _WETH); | ||
/** | ||
* Returns the percent difference between the mid price and the execution price, i.e. price impact. | ||
@@ -506,10 +842,10 @@ * @param midPrice mid price before the trade | ||
function computePriceImpact(midPrice, inputAmount, outputAmount) { | ||
var exactQuote = midPrice.raw.multiply(inputAmount.raw); // calculate slippage := (exactQuote - outputAmount) / exactQuote | ||
var quotedOutputAmount = midPrice.quote(inputAmount); // calculate price impact := (exactQuote - outputAmount) / exactQuote | ||
var slippage = exactQuote.subtract(outputAmount.raw).divide(exactQuote); | ||
return new Percent(slippage.numerator, slippage.denominator); | ||
} // comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts | ||
var priceImpact = quotedOutputAmount.subtract(outputAmount).divide(quotedOutputAmount); | ||
return new Percent(priceImpact.numerator, priceImpact.denominator); | ||
} // `maxSize` by removing the last item | ||
// in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first | ||
function inputOutputComparator(a, b) { | ||
@@ -559,19 +895,2 @@ // must have same input and output token for comparison | ||
/** | ||
* Given a currency amount and a chain ID, returns the equivalent representation as the token amount. | ||
* In other words, if the currency is ETHER, returns the WETH9 token amount for the given chain. Otherwise, returns | ||
* the input currency amount. | ||
*/ | ||
function wrappedAmount(currencyAmount, chainId) { | ||
if (currencyAmount.currency.isToken) return currencyAmount; | ||
if (currencyAmount.currency.isEther) return new CurrencyAmount(WETH9[chainId], currencyAmount.raw); | ||
throw new Error('CURRENCY'); | ||
} | ||
function wrappedCurrency(currency, chainId) { | ||
if (currency.isToken) return currency; | ||
if (currency === ETHER) return WETH9[chainId]; | ||
throw new Error('CURRENCY'); | ||
} | ||
/** | ||
* Represents a trade executed against a list of pairs. | ||
@@ -581,11 +900,11 @@ * Does not account for slippage, i.e. trades that front run this trade and move the price. | ||
var Trade = /*#__PURE__*/function () { | ||
function Trade(route, amount, tradeType) { | ||
var amounts = new Array(route.path.length); | ||
var nextPairs = new Array(route.pairs.length); | ||
this.route = route; | ||
this.tradeType = tradeType; | ||
var tokenAmounts = new Array(route.path.length); | ||
if (tradeType === TradeType.EXACT_INPUT) { | ||
if (tradeType === TradeType$1.EXACT_INPUT) { | ||
!currencyEquals(amount.currency, route.input) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0; | ||
amounts[0] = wrappedAmount(amount, route.chainId); | ||
tokenAmounts[0] = wrappedCurrencyAmount(amount, route.chainId); | ||
@@ -595,12 +914,13 @@ for (var i = 0; i < route.path.length - 1; i++) { | ||
var _pair$getOutputAmount = pair.getOutputAmount(amounts[i]), | ||
outputAmount = _pair$getOutputAmount[0], | ||
nextPair = _pair$getOutputAmount[1]; | ||
var _pair$getOutputAmount = pair.getOutputAmount(tokenAmounts[i]), | ||
outputAmount = _pair$getOutputAmount[0]; | ||
amounts[i + 1] = outputAmount; | ||
nextPairs[i] = nextPair; | ||
tokenAmounts[i + 1] = outputAmount; | ||
} | ||
this.inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator); | ||
this.outputAmount = CurrencyAmount.fromFractionalAmount(route.output, tokenAmounts[tokenAmounts.length - 1].numerator, tokenAmounts[tokenAmounts.length - 1].denominator); | ||
} else { | ||
!currencyEquals(amount.currency, route.output) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0; | ||
amounts[amounts.length - 1] = wrappedAmount(amount, route.chainId); | ||
tokenAmounts[tokenAmounts.length - 1] = wrappedCurrencyAmount(amount, route.chainId); | ||
@@ -610,17 +930,13 @@ for (var _i = route.path.length - 1; _i > 0; _i--) { | ||
var _pair$getInputAmount = _pair.getInputAmount(amounts[_i]), | ||
inputAmount = _pair$getInputAmount[0], | ||
_nextPair = _pair$getInputAmount[1]; | ||
var _pair$getInputAmount = _pair.getInputAmount(tokenAmounts[_i]), | ||
inputAmount = _pair$getInputAmount[0]; | ||
amounts[_i - 1] = inputAmount; | ||
nextPairs[_i - 1] = _nextPair; | ||
tokenAmounts[_i - 1] = inputAmount; | ||
} | ||
this.inputAmount = CurrencyAmount.fromFractionalAmount(route.input, tokenAmounts[0].numerator, tokenAmounts[0].denominator); | ||
this.outputAmount = CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator); | ||
} | ||
this.route = route; | ||
this.tradeType = tradeType; | ||
this.inputAmount = tradeType === TradeType.EXACT_INPUT ? amount : route.input === ETHER ? CurrencyAmount.ether(amounts[0].raw) : amounts[0]; | ||
this.outputAmount = tradeType === TradeType.EXACT_OUTPUT ? amount : route.output === ETHER ? CurrencyAmount.ether(amounts[amounts.length - 1].raw) : amounts[amounts.length - 1]; | ||
this.executionPrice = new Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.raw, this.outputAmount.raw); | ||
this.nextMidPrice = new Route(nextPairs, route.input).midPrice; | ||
this.executionPrice = new Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient); | ||
this.priceImpact = computePriceImpact(route.midPrice, this.inputAmount, this.outputAmount); | ||
@@ -636,3 +952,3 @@ } | ||
Trade.exactIn = function exactIn(route, amountIn) { | ||
return new Trade(route, amountIn, TradeType.EXACT_INPUT); | ||
return new Trade(route, amountIn, TradeType$1.EXACT_INPUT); | ||
} | ||
@@ -647,3 +963,3 @@ /** | ||
Trade.exactOut = function exactOut(route, amountOut) { | ||
return new Trade(route, amountOut, TradeType.EXACT_OUTPUT); | ||
return new Trade(route, amountOut, TradeType$1.EXACT_OUTPUT); | ||
} | ||
@@ -661,7 +977,7 @@ /** | ||
if (this.tradeType === TradeType.EXACT_OUTPUT) { | ||
if (this.tradeType === TradeType$1.EXACT_OUTPUT) { | ||
return this.outputAmount; | ||
} else { | ||
var slippageAdjustedAmountOut = new Fraction(ONE).add(slippageTolerance).invert().multiply(this.outputAmount.raw).quotient; | ||
return new CurrencyAmount(this.outputAmount.currency, slippageAdjustedAmountOut); | ||
var slippageAdjustedAmountOut = new Fraction$1(ONE).add(slippageTolerance).invert().multiply(this.outputAmount.quotient).quotient; | ||
return CurrencyAmount.fromRawAmount(this.outputAmount.currency, slippageAdjustedAmountOut); | ||
} | ||
@@ -678,7 +994,7 @@ } | ||
if (this.tradeType === TradeType.EXACT_INPUT) { | ||
if (this.tradeType === TradeType$1.EXACT_INPUT) { | ||
return this.inputAmount; | ||
} else { | ||
var slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.raw).quotient; | ||
return new CurrencyAmount(this.inputAmount.currency, slippageAdjustedAmountIn); | ||
var slippageAdjustedAmountIn = new Fraction$1(ONE).add(slippageTolerance).multiply(this.inputAmount.quotient).quotient; | ||
return CurrencyAmount.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn); | ||
} | ||
@@ -692,3 +1008,3 @@ } | ||
* @param pairs the pairs to consider in finding the best trade | ||
* @param currencyAmountIn exact amount of input currency to spend | ||
* @param nextAmountIn exact amount of input currency to spend | ||
* @param currencyOut the desired currency out | ||
@@ -698,3 +1014,3 @@ * @param maxNumResults maximum number of results to return | ||
* @param currentPairs used in recursion; the current list of pairs | ||
* @param originalAmountIn used in recursion; the original value of the currencyAmountIn parameter | ||
* @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter | ||
* @param bestTrades used in recursion; the current list of best trades | ||
@@ -705,3 +1021,3 @@ */ | ||
Trade.bestTradeExactIn = function bestTradeExactIn(pairs, currencyAmountIn, currencyOut, _temp, // used in recursion. | ||
currentPairs, originalAmountIn, bestTrades) { | ||
currentPairs, nextAmountIn, bestTrades) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
@@ -717,4 +1033,4 @@ _ref$maxNumResults = _ref.maxNumResults, | ||
if (originalAmountIn === void 0) { | ||
originalAmountIn = currencyAmountIn; | ||
if (nextAmountIn === void 0) { | ||
nextAmountIn = currencyAmountIn; | ||
} | ||
@@ -728,6 +1044,6 @@ | ||
!(maxHops > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_HOPS') : invariant(false) : void 0; | ||
!(originalAmountIn === currencyAmountIn || currentPairs.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0; | ||
var chainId = currencyAmountIn.currency.isToken ? currencyAmountIn.currency.chainId : currencyOut.isToken ? currencyOut.chainId : undefined; | ||
!(currencyAmountIn === nextAmountIn || currentPairs.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0; | ||
var chainId = nextAmountIn.currency.isToken ? nextAmountIn.currency.chainId : currencyOut.isToken ? currencyOut.chainId : undefined; | ||
!(chainId !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_ID') : invariant(false) : void 0; | ||
var amountIn = wrappedAmount(currencyAmountIn, chainId); | ||
var amountIn = wrappedCurrencyAmount(nextAmountIn, chainId); | ||
var tokenOut = wrappedCurrency(currencyOut, chainId); | ||
@@ -759,10 +1075,10 @@ | ||
if (currencyEquals(amountOut.currency, tokenOut)) { | ||
sortedInsert(bestTrades, new Trade(new Route([].concat(currentPairs, [pair]), originalAmountIn.currency, currencyOut), originalAmountIn, TradeType.EXACT_INPUT), maxNumResults, tradeComparator); | ||
sortedInsert(bestTrades, new Trade(new Route([].concat(currentPairs, [pair]), currencyAmountIn.currency, currencyOut), currencyAmountIn, TradeType$1.EXACT_INPUT), maxNumResults, tradeComparator); | ||
} else if (maxHops > 1 && pairs.length > 1) { | ||
var pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length)); // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops | ||
Trade.bestTradeExactIn(pairsExcludingThisPair, amountOut, currencyOut, { | ||
Trade.bestTradeExactIn(pairsExcludingThisPair, currencyAmountIn, currencyOut, { | ||
maxNumResults: maxNumResults, | ||
maxHops: maxHops - 1 | ||
}, [].concat(currentPairs, [pair]), originalAmountIn, bestTrades); | ||
}, [].concat(currentPairs, [pair]), amountOut, bestTrades); | ||
} | ||
@@ -780,3 +1096,3 @@ } | ||
_proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) { | ||
return new Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).raw, this.minimumAmountOut(slippageTolerance).raw); | ||
return new Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient); | ||
} | ||
@@ -791,7 +1107,7 @@ /** | ||
* @param currencyIn the currency to spend | ||
* @param currencyAmountOut the exact amount of currency out | ||
* @param nextAmountOut the exact amount of currency out | ||
* @param maxNumResults maximum number of results to return | ||
* @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair | ||
* @param currentPairs used in recursion; the current list of pairs | ||
* @param originalAmountOut used in recursion; the original value of the currencyAmountOut parameter | ||
* @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter | ||
* @param bestTrades used in recursion; the current list of best trades | ||
@@ -802,3 +1118,3 @@ */ | ||
Trade.bestTradeExactOut = function bestTradeExactOut(pairs, currencyIn, currencyAmountOut, _temp2, // used in recursion. | ||
currentPairs, originalAmountOut, bestTrades) { | ||
currentPairs, nextAmountOut, bestTrades) { | ||
var _ref2 = _temp2 === void 0 ? {} : _temp2, | ||
@@ -814,4 +1130,4 @@ _ref2$maxNumResults = _ref2.maxNumResults, | ||
if (originalAmountOut === void 0) { | ||
originalAmountOut = currencyAmountOut; | ||
if (nextAmountOut === void 0) { | ||
nextAmountOut = currencyAmountOut; | ||
} | ||
@@ -825,6 +1141,6 @@ | ||
!(maxHops > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'MAX_HOPS') : invariant(false) : void 0; | ||
!(originalAmountOut === currencyAmountOut || currentPairs.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0; | ||
var chainId = currencyAmountOut.currency.isToken ? currencyAmountOut.currency.chainId : currencyIn.isToken ? currencyIn.chainId : undefined; | ||
!(currencyAmountOut === nextAmountOut || currentPairs.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0; | ||
var chainId = nextAmountOut.currency.isToken ? nextAmountOut.currency.chainId : currencyIn.isToken ? currencyIn.chainId : undefined; | ||
!(chainId !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_ID') : invariant(false) : void 0; | ||
var amountOut = wrappedAmount(currencyAmountOut, chainId); | ||
var amountOut = wrappedCurrencyAmount(nextAmountOut, chainId); | ||
var tokenIn = wrappedCurrency(currencyIn, chainId); | ||
@@ -856,10 +1172,10 @@ | ||
if (currencyEquals(amountIn.currency, tokenIn)) { | ||
sortedInsert(bestTrades, new Trade(new Route([pair].concat(currentPairs), currencyIn, originalAmountOut.currency), originalAmountOut, TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator); | ||
sortedInsert(bestTrades, new Trade(new Route([pair].concat(currentPairs), currencyIn, currencyAmountOut.currency), currencyAmountOut, TradeType$1.EXACT_OUTPUT), maxNumResults, tradeComparator); | ||
} else if (maxHops > 1 && pairs.length > 1) { | ||
var pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length)); // otherwise, consider all the other paths that arrive at this token as long as we have not exceeded maxHops | ||
Trade.bestTradeExactOut(pairsExcludingThisPair, currencyIn, amountIn, { | ||
Trade.bestTradeExactOut(pairsExcludingThisPair, currencyIn, currencyAmountOut, { | ||
maxNumResults: maxNumResults, | ||
maxHops: maxHops - 1 | ||
}, [pair].concat(currentPairs), originalAmountOut, bestTrades); | ||
}, [pair].concat(currentPairs), amountIn, bestTrades); | ||
} | ||
@@ -875,3 +1191,3 @@ } | ||
function toHex(currencyAmount) { | ||
return "0x" + currencyAmount.raw.toString(16); | ||
return "0x" + currencyAmount.quotient.toString(16); | ||
} | ||
@@ -897,8 +1213,8 @@ | ||
Router.swapCallParameters = function swapCallParameters(trade, options) { | ||
var etherIn = trade.inputAmount.currency === ETHER; | ||
var etherOut = trade.outputAmount.currency === ETHER; // the router does not support both ether in and out | ||
var etherIn = trade.inputAmount.currency.isEther; | ||
var etherOut = trade.outputAmount.currency.isEther; // the router does not support both ether in and out | ||
!!(etherIn && etherOut) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ETHER_IN_OUT') : invariant(false) : void 0; | ||
!(!('ttl' in options) || options.ttl > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TTL') : invariant(false) : void 0; | ||
var to = validateAndParseAddress(options.recipient); | ||
var to = validateAndParseAddress$1(options.recipient); | ||
var amountIn = toHex(trade.maximumAmountIn(options.allowedSlippage)); | ||
@@ -916,3 +1232,3 @@ var amountOut = toHex(trade.minimumAmountOut(options.allowedSlippage)); | ||
switch (trade.tradeType) { | ||
case TradeType.EXACT_INPUT: | ||
case TradeType$1.EXACT_INPUT: | ||
if (etherIn) { | ||
@@ -937,3 +1253,3 @@ methodName = useFeeOnTransfer ? 'swapExactETHForTokensSupportingFeeOnTransferTokens' : 'swapExactETHForTokens'; // (uint amountOutMin, address[] calldata path, address to, uint deadline) | ||
case TradeType.EXACT_OUTPUT: | ||
case TradeType$1.EXACT_OUTPUT: | ||
!!useFeeOnTransfer ? process.env.NODE_ENV !== "production" ? invariant(false, 'EXACT_OUT_FOT') : invariant(false) : void 0; | ||
@@ -940,0 +1256,0 @@ |
{ | ||
"name": "@uniswap/v2-sdk", | ||
"license": "MIT", | ||
"version": "2.0.2", | ||
"version": "3.0.0-alpha.0", | ||
"description": "🛠 An SDK for building applications on top of Uniswap V2", | ||
@@ -27,3 +27,3 @@ "main": "dist/index.js", | ||
"@ethersproject/solidity": "^5.0.0", | ||
"@uniswap/sdk-core": "^2.0.2", | ||
"@uniswap/sdk-core": "^3.0.0-alpha.1", | ||
"tiny-invariant": "^1.1.0", | ||
@@ -30,0 +30,0 @@ "tiny-warning": "^1.0.3" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
306720
2384
3
56
+ Added@uniswap/sdk-core@3.2.6(transitive)
- Removed@uniswap/sdk-core@2.0.5(transitive)