Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions sdks/universal-router-sdk/test/uniswapTrades.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
TradeType,
} from '@uniswap/sdk-core'
import { registerFixture } from './forge/writeInterop'
import { buildTrade, getUniswapPools, swapOptions, ETHER, DAI, USDC, WETH } from './utils/uniswapData'
import { buildTrade, getUniswapPools, swapOptions, ETHER, DAI, USDC, WETH, USDT, UNI } from './utils/uniswapData'
import { hexToDecimalString } from './utils/hexToDecimalString'
import {
FORGE_V4_POSITION_MANAGER,
Expand All @@ -55,7 +55,7 @@ import {
UniversalRouterVersion,
ZERO_ADDRESS,
} from '../src/utils/constants'
import { parseUnits, parseUnits, splitSignature } from 'ethers/lib/utils'
import { splitSignature } from 'ethers/lib/utils'

const FORK_BLOCK = 16075500

Expand All @@ -70,7 +70,10 @@ describe('Uniswap', () => {
let USDC_DAI_V3: V3Pool

let ETH_DAI_V4: V4Pool
let ETH_UNI_V4: V4Pool
let ETH_USDC_V4: V4Pool
let UNI_USDC_V4: V4Pool
let USDC_USDT_V4: V4Pool
let WETH_USDC_V4: V4Pool
let WETH_USDC_V4_LOW_FEE: V4Pool
let ETH_USDC_V4_LOW_FEE: V4Pool
Expand Down Expand Up @@ -145,6 +148,30 @@ describe('Uniswap', () => {
tickProviderMock
)

UNI_USDC_V4 = new V4Pool(
USDC,
USDT,
Comment thread
jsy1218 marked this conversation as resolved.
Outdated
FeeAmount.MEDIUM,
tickSpacing,
ZERO_ADDRESS,
encodeSqrtRatioX96(1, 1),
liquidity,
0,
tickProviderMock
)

USDC_USDT_V4 = new V4Pool(
USDC,
USDT,
FeeAmount.MEDIUM,
tickSpacing,
ZERO_ADDRESS,
encodeSqrtRatioX96(1, 1),
liquidity,
0,
tickProviderMock
)

USDC_DAI_V4 = new V4Pool(
DAI,
USDC,
Expand Down Expand Up @@ -180,6 +207,18 @@ describe('Uniswap', () => {
0,
tickProviderMock
)

ETH_UNI_V4 = new V4Pool(
UNI,
ETHER,
FeeAmount.MEDIUM,
tickSpacing,
ZERO_ADDRESS,
encodeSqrtRatioX96(1, 1),
liquidity,
0,
tickProviderMock
)
})

describe('v2', () => {
Expand Down Expand Up @@ -1064,6 +1103,25 @@ describe('Uniswap', () => {
expect(hexToDecimalString(methodParameters.value)).to.eq(JSBI.multiply(inputEther, JSBI.BigInt(2)).toString())
})

it('encodes a split exactInput with 2 routes v4 ETH -> USDC -> USDT, v4 ETH -> UNI -> USDC -> USDT', async () => {
const inputEther = expandTo18Decimals(1)
const v4Trade1 = await V4Trade.fromRoute(
new V4Route([ETH_USDC_V4, USDC_USDT_V4], ETHER, USDT),
CurrencyAmount.fromRawAmount(ETHER, inputEther),
TradeType.EXACT_INPUT
)
const v4Trade2 = await V4Trade.fromRoute(
new V4Route([ETH_USDC_V4, USDC_USDT_V4], ETHER, USDT),
CurrencyAmount.fromRawAmount(ETHER, inputEther),
TradeType.EXACT_INPUT
)
const opts = swapOptions({})
const methodParameters = SwapRouter.swapCallParameters(buildTrade([v4Trade1, v4Trade2]), opts)
registerFixture('_UNISWAP_SPLIT_TWO_ROUTES_V4_ETH_TO_USDT_AND_UNI', methodParameters)
expect(hexToDecimalString(methodParameters.value)).to.eq(inputEther)
console.log('my calldata is ' + methodParameters.calldata)
})

/**
* Test: Three-way split route (V2 + V3 + V3)
* - V2 route: ETH -> USDC
Expand Down
2 changes: 2 additions & 0 deletions sdks/universal-router-sdk/test/utils/uniswapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const ETHER = Ether.onChain(1)
export const WETH = new Token(1, '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 18, 'WETH', 'Wrapped Ether')
export const DAI = new Token(1, '0x6B175474E89094C44Da98b954EedeAC495271d0F', 18, 'DAI', 'dai')
export const USDC = new Token(1, '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', 6, 'USDC', 'USD Coin')
export const USDT = new Token(1, '0xdAC17F958D2ee523a2206206994597C13D831ec7', 6, 'USDT', 'Tether USD')
export const UNI = new Token(1, '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', 18, 'UNI', 'Uniswap')
export const FEE_AMOUNT = FeeAmount.MEDIUM

type UniswapPools = {
Expand Down
Loading