Commit a09ca5c6 authored by Moody Salem's avatar Moody Salem

bump sdk-core

parent a0e880df
import JSBI from 'jsbi'
import invariant from 'tiny-invariant'
import { ChainId, WETH9 as _WETH9, TradeType, Token, CurrencyAmount } from '@uniswap/sdk-core'
import { WETH9 as _WETH9, TradeType, Token, CurrencyAmount } from '@uniswap/sdk-core'
import { Pair, Route, Trade } from '../index'
const ADDRESSES = [
......@@ -8,8 +8,8 @@ const ADDRESSES = [
'0x0000000000000000000000000000000000000002',
'0x0000000000000000000000000000000000000003'
]
const CHAIN_ID = ChainId.RINKEBY
const WETH9 = _WETH9[ChainId.RINKEBY]
const CHAIN_ID = 3
const WETH9 = _WETH9[3]
const DECIMAL_PERMUTATIONS: [number, number, number][] = [
[0, 0, 0],
[0, 9, 18],
......
import { ChainId, Token, WETH9, Price, CurrencyAmount, currencyEquals } from '@uniswap/sdk-core'
import { Token, WETH9, Price, CurrencyAmount } from '@uniswap/sdk-core'
import { InsufficientInputAmountError } from '../errors'
import { computePairAddress, Pair } from './pair'
describe('computePairAddress', () => {
it('should correctly compute the pool address', () => {
const tokenA = new Token(ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin')
const tokenB = new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
const tokenA = new Token(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin')
const tokenB = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
const result = computePairAddress({
factoryAddress: '0x1111111111111111111111111111111111111111',
tokenA,
......@@ -15,8 +15,8 @@ describe('computePairAddress', () => {
expect(result).toEqual('0xb50b5182D6a47EC53a469395AF44e371d7C76ed4')
})
it('should give same result regardless of token order', () => {
const USDC = new Token(ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin')
const DAI = new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
const USDC = new Token(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin')
const DAI = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
let tokenA = USDC
let tokenB = DAI
const resultA = computePairAddress({
......@@ -38,17 +38,13 @@ describe('computePairAddress', () => {
})
describe('Pair', () => {
const USDC = new Token(ChainId.MAINNET, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin')
const DAI = new Token(ChainId.MAINNET, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
const USDC = new Token(1, '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 18, 'USDC', 'USD Coin')
const DAI = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'DAI Stablecoin')
describe('constructor', () => {
it('cannot be used for tokens on different chains', () => {
expect(
() =>
new Pair(
CurrencyAmount.fromRawAmount(USDC, '100'),
CurrencyAmount.fromRawAmount(WETH9[ChainId.RINKEBY], '100')
)
() => new Pair(CurrencyAmount.fromRawAmount(USDC, '100'), CurrencyAmount.fromRawAmount(WETH9[3], '100'))
).toThrow('CHAIN_IDS')
})
})
......@@ -130,7 +126,7 @@ describe('Pair', () => {
})
it('throws if invalid token', () => {
expect(() => pair.priceOf(WETH9[ChainId.MAINNET])).toThrow('TOKEN')
expect(() => pair.priceOf(WETH9[1])).toThrow('TOKEN')
})
})
......@@ -147,7 +143,7 @@ describe('Pair', () => {
it('throws if not in the pair', () => {
expect(() =>
new Pair(CurrencyAmount.fromRawAmount(DAI, '101'), CurrencyAmount.fromRawAmount(USDC, '100')).reserveOf(
WETH9[ChainId.MAINNET]
WETH9[1]
)
).toThrow('TOKEN')
})
......@@ -157,10 +153,10 @@ describe('Pair', () => {
it('returns the token0 chainId', () => {
expect(
new Pair(CurrencyAmount.fromRawAmount(USDC, '100'), CurrencyAmount.fromRawAmount(DAI, '100')).chainId
).toEqual(ChainId.MAINNET)
).toEqual(1)
expect(
new Pair(CurrencyAmount.fromRawAmount(DAI, '100'), CurrencyAmount.fromRawAmount(USDC, '100')).chainId
).toEqual(ChainId.MAINNET)
).toEqual(1)
})
})
describe('#involvesToken', () => {
......@@ -172,14 +168,14 @@ describe('Pair', () => {
).toEqual(true)
expect(
new Pair(CurrencyAmount.fromRawAmount(USDC, '100'), CurrencyAmount.fromRawAmount(DAI, '100')).involvesToken(
WETH9[ChainId.MAINNET]
WETH9[1]
)
).toEqual(false)
})
describe('miscellaneous', () => {
it('getLiquidityMinted:0', async () => {
const tokenA = new Token(ChainId.RINKEBY, '0x0000000000000000000000000000000000000001', 18)
const tokenB = new Token(ChainId.RINKEBY, '0x0000000000000000000000000000000000000002', 18)
const tokenA = new Token(3, '0x0000000000000000000000000000000000000001', 18)
const tokenB = new Token(3, '0x0000000000000000000000000000000000000002', 18)
const pair = new Pair(CurrencyAmount.fromRawAmount(tokenA, '0'), CurrencyAmount.fromRawAmount(tokenB, '0'))
expect(() => {
......@@ -208,8 +204,8 @@ describe('Pair', () => {
})
it('getLiquidityMinted:!0', async () => {
const tokenA = new Token(ChainId.RINKEBY, '0x0000000000000000000000000000000000000001', 18)
const tokenB = new Token(ChainId.RINKEBY, '0x0000000000000000000000000000000000000002', 18)
const tokenA = new Token(3, '0x0000000000000000000000000000000000000001', 18)
const tokenB = new Token(3, '0x0000000000000000000000000000000000000002', 18)
const pair = new Pair(
CurrencyAmount.fromRawAmount(tokenA, '10000'),
CurrencyAmount.fromRawAmount(tokenB, '10000')
......@@ -227,8 +223,8 @@ describe('Pair', () => {
})
it('getLiquidityValue:!feeOn', async () => {
const tokenA = new Token(ChainId.RINKEBY, '0x0000000000000000000000000000000000000001', 18)
const tokenB = new Token(ChainId.RINKEBY, '0x0000000000000000000000000000000000000002', 18)
const tokenA = new Token(3, '0x0000000000000000000000000000000000000001', 18)
const tokenB = new Token(3, '0x0000000000000000000000000000000000000002', 18)
const pair = new Pair(CurrencyAmount.fromRawAmount(tokenA, '1000'), CurrencyAmount.fromRawAmount(tokenB, '1000'))
{
......@@ -238,7 +234,7 @@ describe('Pair', () => {
CurrencyAmount.fromRawAmount(pair.liquidityToken, '1000'),
false
)
expect(currencyEquals(liquidityValue.currency, tokenA)).toBe(true)
expect(liquidityValue.currency.equals(tokenA)).toBe(true)
expect(liquidityValue.quotient.toString()).toBe('1000')
}
......@@ -250,7 +246,7 @@ describe('Pair', () => {
CurrencyAmount.fromRawAmount(pair.liquidityToken, '500'),
false
)
expect(currencyEquals(liquidityValue.currency, tokenA)).toBe(true)
expect(liquidityValue.currency.equals(tokenA)).toBe(true)
expect(liquidityValue.quotient.toString()).toBe('500')
}
......@@ -262,14 +258,14 @@ describe('Pair', () => {
CurrencyAmount.fromRawAmount(pair.liquidityToken, '1000'),
false
)
expect(currencyEquals(liquidityValue.currency, tokenB)).toBe(true)
expect(liquidityValue.currency.equals(tokenB)).toBe(true)
expect(liquidityValue.quotient.toString()).toBe('1000')
}
})
it('getLiquidityValue:feeOn', async () => {
const tokenA = new Token(ChainId.RINKEBY, '0x0000000000000000000000000000000000000001', 18)
const tokenB = new Token(ChainId.RINKEBY, '0x0000000000000000000000000000000000000002', 18)
const tokenA = new Token(3, '0x0000000000000000000000000000000000000001', 18)
const tokenB = new Token(3, '0x0000000000000000000000000000000000000002', 18)
const pair = new Pair(CurrencyAmount.fromRawAmount(tokenA, '1000'), CurrencyAmount.fromRawAmount(tokenB, '1000'))
const liquidityValue = pair.getLiquidityValue(
......@@ -279,7 +275,7 @@ describe('Pair', () => {
true,
'250000' // 500 ** 2
)
expect(currencyEquals(liquidityValue.currency, tokenA)).toBe(true)
expect(liquidityValue.currency.equals(tokenA)).toBe(true)
expect(liquidityValue.quotient.toString()).toBe('917') // ceiling(1000 - (500 * (1 / 6)))
})
})
......
import { BigintIsh, ChainId, Price, sqrt, Token, CurrencyAmount } from '@uniswap/sdk-core'
import { BigintIsh, Price, sqrt, Token, CurrencyAmount } from '@uniswap/sdk-core'
import invariant from 'tiny-invariant'
import JSBI from 'jsbi'
import { pack, keccak256 } from '@ethersproject/solidity'
......@@ -81,7 +81,7 @@ export class Pair {
/**
* Returns the chain ID of the tokens in the pair.
*/
public get chainId(): ChainId | number {
public get chainId(): number {
return this.token0.chainId
}
......
import { Token, WETH9, ChainId, CurrencyAmount, ETHER } from '@uniswap/sdk-core'
import { Token, WETH9, CurrencyAmount } from '@uniswap/sdk-core'
import { Ether } from '../../../../sdk-core'
import { Pair, Route } from './index'
describe('Route', () => {
const token0 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000001', 18, 't0')
const token1 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000002', 18, 't1')
const weth = WETH9[ChainId.MAINNET]
const ETHER = Ether.onChain(1)
const token0 = new Token(1, '0x0000000000000000000000000000000000000001', 18, 't0')
const token1 = new Token(1, '0x0000000000000000000000000000000000000002', 18, 't1')
const weth = WETH9[1]
const pair_0_1 = new Pair(CurrencyAmount.fromRawAmount(token0, '100'), CurrencyAmount.fromRawAmount(token1, '200'))
const pair_0_weth = new Pair(CurrencyAmount.fromRawAmount(token0, '100'), CurrencyAmount.fromRawAmount(weth, '100'))
const pair_1_weth = new Pair(CurrencyAmount.fromRawAmount(token1, '175'), CurrencyAmount.fromRawAmount(weth, '100'))
......@@ -15,7 +17,7 @@ describe('Route', () => {
expect(route.path).toEqual([token0, token1])
expect(route.input).toEqual(token0)
expect(route.output).toEqual(token1)
expect(route.chainId).toEqual(ChainId.MAINNET)
expect(route.chainId).toEqual(1)
})
it('can have a token as both input and output', () => {
......
import invariant from 'tiny-invariant'
import { ChainId, Currency, Price, Token, wrappedCurrency } from '@uniswap/sdk-core'
import { Currency, Price, Token } from '@uniswap/sdk-core'
import { Pair } from './pair'
......@@ -11,18 +11,15 @@ export class Route<TInput extends Currency, TOutput extends Currency> {
public constructor(pairs: Pair[], input: TInput, output: TOutput) {
invariant(pairs.length > 0, 'PAIRS')
const chainId: ChainId | number = pairs[0].chainId
const chainId: number = pairs[0].chainId
invariant(
pairs.every(pair => pair.chainId === chainId),
'CHAIN_IDS'
)
const wrappedInput = wrappedCurrency(input, chainId)
const wrappedInput = input.wrapped
invariant(pairs[0].involvesToken(wrappedInput), 'INPUT')
invariant(
typeof output === 'undefined' || pairs[pairs.length - 1].involvesToken(wrappedCurrency(output, chainId)),
'OUTPUT'
)
invariant(typeof output === 'undefined' || pairs[pairs.length - 1].involvesToken(output.wrapped), 'OUTPUT')
const path: Token[] = [wrappedInput]
for (const [i, pair] of pairs.entries()) {
......@@ -54,7 +51,7 @@ export class Route<TInput extends Currency, TOutput extends Currency> {
return (this._midPrice = new Price(this.input, this.output, reduced.denominator, reduced.numerator))
}
public get chainId(): ChainId | number {
public get chainId(): number {
return this.pairs[0].chainId
}
}
import { Ether } from '../../../../sdk-core'
import { Pair } from './pair'
import { Route } from './route'
import { Trade } from './trade'
import JSBI from 'jsbi'
import { ChainId, ETHER, CurrencyAmount, Percent, Token, TradeType, WETH9, Price } from '@uniswap/sdk-core'
import { CurrencyAmount, Percent, Token, TradeType, WETH9, Price } from '@uniswap/sdk-core'
describe('Trade', () => {
const token0 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000001', 18, 't0')
const token1 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000002', 18, 't1')
const token2 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000003', 18, 't2')
const token3 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000004', 18, 't3')
const ETHER = Ether.onChain(1)
const token0 = new Token(1, '0x0000000000000000000000000000000000000001', 18, 't0')
const token1 = new Token(1, '0x0000000000000000000000000000000000000002', 18, 't1')
const token2 = new Token(1, '0x0000000000000000000000000000000000000003', 18, 't2')
const token3 = new Token(1, '0x0000000000000000000000000000000000000004', 18, 't3')
const pair_0_1 = new Pair(
CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000)),
......@@ -32,7 +34,7 @@ describe('Trade', () => {
)
const pair_weth_0 = new Pair(
CurrencyAmount.fromRawAmount(WETH9[ChainId.MAINNET], JSBI.BigInt(1000)),
CurrencyAmount.fromRawAmount(WETH9[1], JSBI.BigInt(1000)),
CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000))
)
......@@ -44,7 +46,7 @@ describe('Trade', () => {
it('can be constructed with ETHER as input', () => {
const trade = new Trade(
new Route([pair_weth_0], ETHER, token0),
CurrencyAmount.ether(JSBI.BigInt(100)),
CurrencyAmount.ether(1, JSBI.BigInt(100)),
TradeType.EXACT_INPUT
)
expect(trade.inputAmount.currency).toEqual(ETHER)
......@@ -63,7 +65,7 @@ describe('Trade', () => {
it('can be constructed with ETHER as output', () => {
const trade = new Trade(
new Route([pair_weth_0], token0, ETHER),
CurrencyAmount.ether(JSBI.BigInt(100)),
CurrencyAmount.ether(1, JSBI.BigInt(100)),
TradeType.EXACT_OUTPUT
)
expect(trade.inputAmount.currency).toEqual(token0)
......@@ -163,15 +165,15 @@ describe('Trade', () => {
it('works for ETHER currency input', () => {
const result = Trade.bestTradeExactIn(
[pair_weth_0, pair_0_1, pair_0_3, pair_1_3],
CurrencyAmount.ether(JSBI.BigInt(100)),
CurrencyAmount.ether(1, JSBI.BigInt(100)),
token3
)
expect(result).toHaveLength(2)
expect(result[0].inputAmount.currency).toEqual(ETHER)
expect(result[0].route.path).toEqual([WETH9[ChainId.MAINNET], token0, token1, token3])
expect(result[0].route.path).toEqual([WETH9[1], token0, token1, token3])
expect(result[0].outputAmount.currency).toEqual(token3)
expect(result[1].inputAmount.currency).toEqual(ETHER)
expect(result[1].route.path).toEqual([WETH9[ChainId.MAINNET], token0, token3])
expect(result[1].route.path).toEqual([WETH9[1], token0, token3])
expect(result[1].outputAmount.currency).toEqual(token3)
})
it('works for ETHER currency output', () => {
......@@ -182,10 +184,10 @@ describe('Trade', () => {
)
expect(result).toHaveLength(2)
expect(result[0].inputAmount.currency).toEqual(token3)
expect(result[0].route.path).toEqual([token3, token0, WETH9[ChainId.MAINNET]])
expect(result[0].route.path).toEqual([token3, token0, WETH9[1]])
expect(result[0].outputAmount.currency).toEqual(ETHER)
expect(result[1].inputAmount.currency).toEqual(token3)
expect(result[1].route.path).toEqual([token3, token1, token0, WETH9[ChainId.MAINNET]])
expect(result[1].route.path).toEqual([token3, token1, token0, WETH9[1]])
expect(result[1].outputAmount.currency).toEqual(ETHER)
})
})
......@@ -437,24 +439,24 @@ describe('Trade', () => {
)
expect(result).toHaveLength(2)
expect(result[0].inputAmount.currency).toEqual(ETHER)
expect(result[0].route.path).toEqual([WETH9[ChainId.MAINNET], token0, token1, token3])
expect(result[0].route.path).toEqual([WETH9[1], token0, token1, token3])
expect(result[0].outputAmount.currency).toEqual(token3)
expect(result[1].inputAmount.currency).toEqual(ETHER)
expect(result[1].route.path).toEqual([WETH9[ChainId.MAINNET], token0, token3])
expect(result[1].route.path).toEqual([WETH9[1], token0, token3])
expect(result[1].outputAmount.currency).toEqual(token3)
})
it('works for ETHER currency output', () => {
const result = Trade.bestTradeExactOut(
[pair_weth_0, pair_0_1, pair_0_3, pair_1_3],
token3,
CurrencyAmount.ether(JSBI.BigInt(100))
CurrencyAmount.ether(1, JSBI.BigInt(100))
)
expect(result).toHaveLength(2)
expect(result[0].inputAmount.currency).toEqual(token3)
expect(result[0].route.path).toEqual([token3, token0, WETH9[ChainId.MAINNET]])
expect(result[0].route.path).toEqual([token3, token0, WETH9[1]])
expect(result[0].outputAmount.currency).toEqual(ETHER)
expect(result[1].inputAmount.currency).toEqual(token3)
expect(result[1].route.path).toEqual([token3, token1, token0, WETH9[ChainId.MAINNET]])
expect(result[1].route.path).toEqual([token3, token1, token0, WETH9[1]])
expect(result[1].outputAmount.currency).toEqual(ETHER)
})
})
......
import {
ChainId,
Currency,
CurrencyAmount,
currencyEquals,
Fraction,
Percent,
Price,
sortedInsert,
wrappedCurrency,
TradeType,
wrappedCurrencyAmount
} from '@uniswap/sdk-core'
import { Currency, CurrencyAmount, Fraction, Percent, Price, sortedInsert, TradeType } from '@uniswap/sdk-core'
import { computePriceImpact, Token } from '../../../../sdk-core'
import { ONE, ZERO } from '../constants'
import invariant from 'tiny-invariant'
......@@ -31,8 +19,8 @@ export function inputOutputComparator<TInput extends Currency, TOutput extends C
b: InputOutput<TInput, TOutput>
): number {
// must have same input and output token for comparison
invariant(currencyEquals(a.inputAmount.currency, b.inputAmount.currency), 'INPUT_CURRENCY')
invariant(currencyEquals(a.outputAmount.currency, b.outputAmount.currency), 'OUTPUT_CURRENCY')
invariant(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY')
invariant(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY')
if (a.outputAmount.equalTo(b.outputAmount)) {
if (a.inputAmount.equalTo(b.inputAmount)) {
return 0
......@@ -145,8 +133,8 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
const tokenAmounts: CurrencyAmount<Token>[] = new Array(route.path.length)
if (tradeType === TradeType.EXACT_INPUT) {
invariant(currencyEquals(amount.currency, route.input), 'INPUT')
tokenAmounts[0] = wrappedCurrencyAmount(amount, route.chainId)
invariant(amount.currency.equals(route.input), 'INPUT')
tokenAmounts[0] = amount.wrapped
for (let i = 0; i < route.path.length - 1; i++) {
const pair = route.pairs[i]
const [outputAmount] = pair.getOutputAmount(tokenAmounts[i])
......@@ -159,8 +147,8 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
tokenAmounts[tokenAmounts.length - 1].denominator
)
} else {
invariant(currencyEquals(amount.currency, route.output), 'OUTPUT')
tokenAmounts[tokenAmounts.length - 1] = wrappedCurrencyAmount(amount, route.chainId)
invariant(amount.currency.equals(route.output), 'OUTPUT')
tokenAmounts[tokenAmounts.length - 1] = amount.wrapped
for (let i = route.path.length - 1; i > 0; i--) {
const pair = route.pairs[i - 1]
const [inputAmount] = pair.getInputAmount(tokenAmounts[i])
......@@ -241,20 +229,13 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
invariant(pairs.length > 0, 'PAIRS')
invariant(maxHops > 0, 'MAX_HOPS')
invariant(currencyAmountIn === nextAmountIn || currentPairs.length > 0, 'INVALID_RECURSION')
const chainId: ChainId | undefined = nextAmountIn.currency.isToken
? nextAmountIn.currency.chainId
: currencyOut.isToken
? (currencyOut as Token).chainId
: undefined
invariant(chainId !== undefined, 'CHAIN_ID')
const amountIn = wrappedCurrencyAmount(nextAmountIn, chainId)
const tokenOut = wrappedCurrency(currencyOut, chainId)
const amountIn = nextAmountIn.wrapped
const tokenOut = currencyOut.wrapped
for (let i = 0; i < pairs.length; i++) {
const pair = pairs[i]
// pair irrelevant
if (!currencyEquals(pair.token0, amountIn.currency) && !currencyEquals(pair.token1, amountIn.currency)) continue
if (!pair.token0.equals(amountIn.currency) && !pair.token1.equals(amountIn.currency)) continue
if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue
let amountOut: CurrencyAmount<Token>
......@@ -268,7 +249,7 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
throw error
}
// we have arrived at the output token, so this is the final trade of one of the paths
if (currencyEquals(amountOut.currency, tokenOut)) {
if (amountOut.currency.equals(tokenOut)) {
sortedInsert(
bestTrades,
new Trade(
......@@ -342,19 +323,13 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
invariant(pairs.length > 0, 'PAIRS')
invariant(maxHops > 0, 'MAX_HOPS')
invariant(currencyAmountOut === nextAmountOut || currentPairs.length > 0, 'INVALID_RECURSION')
const chainId: ChainId | undefined = nextAmountOut.currency.isToken
? nextAmountOut.currency.chainId
: currencyIn.isToken
? (currencyIn as Token).chainId
: undefined
invariant(chainId !== undefined, 'CHAIN_ID')
const amountOut = wrappedCurrencyAmount(nextAmountOut, chainId)
const tokenIn = wrappedCurrency(currencyIn, chainId)
const amountOut = nextAmountOut.wrapped
const tokenIn = currencyIn.wrapped
for (let i = 0; i < pairs.length; i++) {
const pair = pairs[i]
// pair irrelevant
if (!currencyEquals(pair.token0, amountOut.currency) && !currencyEquals(pair.token1, amountOut.currency)) continue
if (!pair.token0.equals(amountOut.currency) && !pair.token1.equals(amountOut.currency)) continue
if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue
let amountIn: CurrencyAmount<Token>
......@@ -368,7 +343,7 @@ export class Trade<TInput extends Currency, TOutput extends Currency, TTradeType
throw error
}
// we have arrived at the input token, so this is the first trade of one of the paths
if (currencyEquals(amountIn.currency, tokenIn)) {
if (amountIn.currency.equals(tokenIn)) {
sortedInsert(
bestTrades,
new Trade(
......
import JSBI from 'jsbi'
import { Ether } from '../../../sdk-core'
import { Pair, Route, Trade } from './entities'
import { Router } from './router'
import invariant from 'tiny-invariant'
import { ChainId, CurrencyAmount, ETHER, Percent, Token, WETH9 } from '@uniswap/sdk-core'
import { CurrencyAmount, Percent, Token, WETH9 } from '@uniswap/sdk-core'
function checkDeadline(deadline: string[] | string): void {
expect(typeof deadline).toBe('string')
......@@ -12,8 +13,9 @@ function checkDeadline(deadline: string[] | string): void {
}
describe('Router', () => {
const token0 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000001', 18, 't0')
const token1 = new Token(ChainId.MAINNET, '0x0000000000000000000000000000000000000002', 18, 't1')
const ETHER = Ether.onChain(1)
const token0 = new Token(1, '0x0000000000000000000000000000000000000001', 18, 't0')
const token1 = new Token(1, '0x0000000000000000000000000000000000000002', 18, 't1')
const pair_0_1 = new Pair(
CurrencyAmount.fromRawAmount(token0, JSBI.BigInt(1000)),
......@@ -21,7 +23,7 @@ describe('Router', () => {
)
const pair_weth_0 = new Pair(
CurrencyAmount.fromRawAmount(WETH9[ChainId.MAINNET], '1000'),
CurrencyAmount.fromRawAmount(WETH9[1], '1000'),
CurrencyAmount.fromRawAmount(token0, '1000')
)
......@@ -29,13 +31,13 @@ describe('Router', () => {
describe('exact in', () => {
it.only('ether to token1', () => {
const result = Router.swapCallParameters(
Trade.exactIn(new Route([pair_weth_0, pair_0_1], ETHER, token1), CurrencyAmount.ether(JSBI.BigInt(100))),
Trade.exactIn(new Route([pair_weth_0, pair_0_1], ETHER, token1), CurrencyAmount.ether(1, JSBI.BigInt(100))),
{ ttl: 50, recipient: '0x0000000000000000000000000000000000000004', allowedSlippage: new Percent('1', '100') }
)
expect(result.methodName).toEqual('swapExactETHForTokens')
expect(result.args.slice(0, -1)).toEqual([
'0x51',
[WETH9[ChainId.MAINNET].address, token0.address, token1.address],
[WETH9[1].address, token0.address, token1.address],
'0x0000000000000000000000000000000000000004'
])
expect(result.value).toEqual('0x64')
......@@ -44,7 +46,7 @@ describe('Router', () => {
it('deadline specified', () => {
const result = Router.swapCallParameters(
Trade.exactIn(new Route([pair_weth_0, pair_0_1], ETHER, token1), CurrencyAmount.ether(JSBI.BigInt(100))),
Trade.exactIn(new Route([pair_weth_0, pair_0_1], ETHER, token1), CurrencyAmount.ether(1, JSBI.BigInt(100))),
{
deadline: 50,
recipient: '0x0000000000000000000000000000000000000004',
......@@ -54,7 +56,7 @@ describe('Router', () => {
expect(result.methodName).toEqual('swapExactETHForTokens')
expect(result.args).toEqual([
'0x51',
[WETH9[ChainId.MAINNET].address, token0.address, token1.address],
[WETH9[1].address, token0.address, token1.address],
'0x0000000000000000000000000000000000000004',
'0x32'
])
......@@ -73,7 +75,7 @@ describe('Router', () => {
expect(result.args.slice(0, -1)).toEqual([
'0x64',
'0x51',
[token1.address, token0.address, WETH9[ChainId.MAINNET].address],
[token1.address, token0.address, WETH9[1].address],
'0x0000000000000000000000000000000000000004'
])
expect(result.value).toEqual('0x0')
......@@ -107,7 +109,7 @@ describe('Router', () => {
expect(result.methodName).toEqual('swapETHForExactTokens')
expect(result.args.slice(0, -1)).toEqual([
'0x64',
[WETH9[ChainId.MAINNET].address, token0.address, token1.address],
[WETH9[1].address, token0.address, token1.address],
'0x0000000000000000000000000000000000000004'
])
expect(result.value).toEqual('0x80')
......@@ -115,14 +117,14 @@ describe('Router', () => {
})
it('token1 to ether', () => {
const result = Router.swapCallParameters(
Trade.exactOut(new Route([pair_0_1, pair_weth_0], token1, ETHER), CurrencyAmount.ether(JSBI.BigInt(100))),
Trade.exactOut(new Route([pair_0_1, pair_weth_0], token1, ETHER), CurrencyAmount.ether(1, JSBI.BigInt(100))),
{ ttl: 50, recipient: '0x0000000000000000000000000000000000000004', allowedSlippage: new Percent('1', '100') }
)
expect(result.methodName).toEqual('swapTokensForExactETH')
expect(result.args.slice(0, -1)).toEqual([
'0x64',
'0x80',
[token1.address, token0.address, WETH9[ChainId.MAINNET].address],
[token1.address, token0.address, WETH9[1].address],
'0x0000000000000000000000000000000000000004'
])
expect(result.value).toEqual('0x0')
......@@ -148,7 +150,7 @@ describe('Router', () => {
describe('exact in', () => {
it('ether to token1', () => {
const result = Router.swapCallParameters(
Trade.exactIn(new Route([pair_weth_0, pair_0_1], ETHER, token1), CurrencyAmount.ether(JSBI.BigInt(100))),
Trade.exactIn(new Route([pair_weth_0, pair_0_1], ETHER, token1), CurrencyAmount.ether(1, JSBI.BigInt(100))),
{
ttl: 50,
recipient: '0x0000000000000000000000000000000000000004',
......@@ -159,7 +161,7 @@ describe('Router', () => {
expect(result.methodName).toEqual('swapExactETHForTokensSupportingFeeOnTransferTokens')
expect(result.args.slice(0, -1)).toEqual([
'0x51',
[WETH9[ChainId.MAINNET].address, token0.address, token1.address],
[WETH9[1].address, token0.address, token1.address],
'0x0000000000000000000000000000000000000004'
])
expect(result.value).toEqual('0x64')
......@@ -182,7 +184,7 @@ describe('Router', () => {
expect(result.args.slice(0, -1)).toEqual([
'0x64',
'0x51',
[token1.address, token0.address, WETH9[ChainId.MAINNET].address],
[token1.address, token0.address, WETH9[1].address],
'0x0000000000000000000000000000000000000004'
])
expect(result.value).toEqual('0x0')
......@@ -232,7 +234,10 @@ describe('Router', () => {
it('token1 to ether', () => {
expect(() =>
Router.swapCallParameters(
Trade.exactOut(new Route([pair_0_1, pair_weth_0], token1, ETHER), CurrencyAmount.ether(JSBI.BigInt(100))),
Trade.exactOut(
new Route([pair_0_1, pair_weth_0], token1, ETHER),
CurrencyAmount.ether(1, JSBI.BigInt(100))
),
{
ttl: 50,
recipient: '0x0000000000000000000000000000000000000004',
......
......@@ -77,8 +77,8 @@ export abstract class Router {
trade: Trade<Currency, Currency, TradeType>,
options: TradeOptions | TradeOptionsDeadline
): SwapParameters {
const etherIn = trade.inputAmount.currency.isEther
const etherOut = trade.outputAmount.currency.isEther
const etherIn = trade.inputAmount.currency.isNative
const etherOut = trade.outputAmount.currency.isNative
// the router does not support both ether in and out
invariant(!(etherIn && etherOut), 'ETHER_IN_OUT')
invariant(!('ttl' in options) || options.ttl > 0, 'TTL')
......
......@@ -1706,10 +1706,10 @@
semver "^7.3.2"
tsutils "^3.17.1"
"@uniswap/sdk-core@^3.0.0-alpha.1":
version "3.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/@uniswap/sdk-core/-/sdk-core-3.0.0-alpha.1.tgz#8d735755818658fd4a6113cb6d30ed637f9e8347"
integrity sha512-dCRBMKtmVmQCoG6sju3j/ki81e82zyqcWm0g+eU3JU0hzbSo6i31wzkOQPHMRO6FcYIJ6+9qx3Sy0B7VoZ6t9g==
"@uniswap/sdk-core@^3.0.0-alpha.2":
version "3.0.0-alpha.2"
resolved "https://registry.yarnpkg.com/@uniswap/sdk-core/-/sdk-core-3.0.0-alpha.2.tgz#58f850a3a4e31c366a7471a92bcf704c35491cdd"
integrity sha512-X4tqngp/HLNIbfzHLXtf25OeLtgDVHafp6bCGYR29qsWwlOJR+GlQ+cYDuR+3tOZHt6kuJcXG4rAP6vnjkcqkg==
dependencies:
"@ethersproject/address" "^5.0.2"
big.js "^5.2.2"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment