diff --git a/sdks/router-sdk/package.json b/sdks/router-sdk/package.json index 529d44948..4672c99c7 100644 --- a/sdks/router-sdk/package.json +++ b/sdks/router-sdk/package.json @@ -1,5 +1,5 @@ { - "name": "@uniswap/router-sdk", + "name": "@uniswap/router-sdk-guidestar-routes-1", "description": "An sdk for routing swaps using Uniswap v2 and Uniswap v3.", "repository": "https://github.com/Uniswap/sdks.git", "keywords": [ diff --git a/sdks/router-sdk/src/entities/trade.ts b/sdks/router-sdk/src/entities/trade.ts index 9b4e5c0ed..cc9932f5e 100644 --- a/sdks/router-sdk/src/entities/trade.ts +++ b/sdks/router-sdk/src/entities/trade.ts @@ -133,7 +133,7 @@ export class Trade { diff --git a/sdks/universal-router-sdk/package.json b/sdks/universal-router-sdk/package.json index 124168c25..e1396b17b 100644 --- a/sdks/universal-router-sdk/package.json +++ b/sdks/universal-router-sdk/package.json @@ -31,7 +31,7 @@ "dependencies": { "@openzeppelin/contracts": "4.7.0", "@uniswap/permit2-sdk": "^1.3.0", - "@uniswap/router-sdk": "^2.4.0", + "@uniswap/router-sdk": "file:tmp/router-sdk-guidestar-routes-1.tgz", "@uniswap/sdk-core": "^7.10.0", "@uniswap/universal-router": "2.1.0", "@uniswap/v2-core": "^1.0.1", diff --git a/sdks/universal-router-sdk/test/uniswapTrades.test.ts b/sdks/universal-router-sdk/test/uniswapTrades.test.ts index a2dbddfe0..9682b89ac 100644 --- a/sdks/universal-router-sdk/test/uniswapTrades.test.ts +++ b/sdks/universal-router-sdk/test/uniswapTrades.test.ts @@ -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, @@ -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 @@ -68,9 +68,10 @@ describe('Uniswap', () => { let WETH_USDC_V3: V3Pool let WETH_USDC_V3_LOW_FEE: V3Pool let USDC_DAI_V3: V3Pool - let ETH_DAI_V4: V4Pool let ETH_USDC_V4: V4Pool + let ETH_USDT_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 @@ -145,6 +146,30 @@ describe('Uniswap', () => { tickProviderMock ) + ETH_USDT_V4 = new V4Pool( + ETHER, + USDT, + 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, @@ -1064,6 +1089,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 USDC -> USDT, v4 USDC -> ETH -> USDT', async () => { + const inputEther = expandTo18Decimals(1) + const v4Trade1 = await V4Trade.fromRoute( + new V4Route([USDC_USDT_V4], USDC, USDT), + CurrencyAmount.fromRawAmount(USDC, inputEther), + TradeType.EXACT_INPUT + ) + const v4Trade2 = await V4Trade.fromRoute( + new V4Route([ETH_USDC_V4, ETH_USDT_V4], USDC, USDT), + CurrencyAmount.fromRawAmount(USDC, 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 diff --git a/sdks/universal-router-sdk/test/utils/uniswapData.ts b/sdks/universal-router-sdk/test/utils/uniswapData.ts index df701905b..6232c9e85 100644 --- a/sdks/universal-router-sdk/test/utils/uniswapData.ts +++ b/sdks/universal-router-sdk/test/utils/uniswapData.ts @@ -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 = { diff --git a/sdks/universal-router-sdk/tmp/router-sdk-guidestar-routes-1.tgz b/sdks/universal-router-sdk/tmp/router-sdk-guidestar-routes-1.tgz new file mode 100644 index 000000000..51ed16f71 Binary files /dev/null and b/sdks/universal-router-sdk/tmp/router-sdk-guidestar-routes-1.tgz differ diff --git a/yarn.lock b/yarn.lock index 82db4581c..237f34eb5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4866,23 +4866,9 @@ __metadata: languageName: unknown linkType: soft -"@uniswap/router-sdk@npm:^2.4.0": - version: 2.4.0 - resolution: "@uniswap/router-sdk@npm:2.4.0" - dependencies: - "@ethersproject/abi": ^5.5.0 - "@uniswap/sdk-core": ^7.10.1 - "@uniswap/swap-router-contracts": ^1.3.0 - "@uniswap/v2-sdk": ^4.17.0 - "@uniswap/v3-sdk": ^3.27.0 - "@uniswap/v4-sdk": ^1.27.0 - checksum: 0e3771ab799c716d2dc8dd10882babe8ad090a665094b886c67eed669af2f6016ac77d389f83b6811f5f4ebd567474f4c60a0b89fce2a410857e794072779b6b - languageName: node - linkType: hard - -"@uniswap/router-sdk@workspace:sdks/router-sdk": +"@uniswap/router-sdk-guidestar-routes-1@workspace:sdks/router-sdk": version: 0.0.0-use.local - resolution: "@uniswap/router-sdk@workspace:sdks/router-sdk" + resolution: "@uniswap/router-sdk-guidestar-routes-1@workspace:sdks/router-sdk" dependencies: "@ethersproject/abi": ^5.5.0 "@types/jest": ^24.0.25 @@ -4898,6 +4884,20 @@ __metadata: languageName: unknown linkType: soft +"@uniswap/router-sdk@file:tmp/router-sdk-guidestar-routes-1.tgz::locator=%40uniswap%2Funiversal-router-sdk%40workspace%3Asdks%2Funiversal-router-sdk": + version: 0.0.0 + resolution: "@uniswap/router-sdk@file:tmp/router-sdk-guidestar-routes-1.tgz::locator=%40uniswap%2Funiversal-router-sdk%40workspace%3Asdks%2Funiversal-router-sdk" + dependencies: + "@ethersproject/abi": ^5.5.0 + "@uniswap/sdk-core": ^7.10.1 + "@uniswap/swap-router-contracts": ^1.3.0 + "@uniswap/v2-sdk": ^4.17.0 + "@uniswap/v3-sdk": ^3.27.0 + "@uniswap/v4-sdk": ^1.27.0 + checksum: 8e32c7e253bce508a5713dece1c635052bb8a5e23e816f3b3eb2b30fa35cb055ac914df4c1f8dee3118c2db3995bc05169092d96eefc356fc9c07bbdd1bef35c + languageName: node + linkType: hard + "@uniswap/sdk-core@npm:^7.10.0, @uniswap/sdk-core@npm:^7.10.1, @uniswap/sdk-core@npm:^7.5.0, @uniswap/sdk-core@npm:^7.6.0": version: 7.10.1 resolution: "@uniswap/sdk-core@npm:7.10.1" @@ -5042,7 +5042,7 @@ __metadata: "@types/node": ^18.7.16 "@types/node-fetch": ^2.6.2 "@uniswap/permit2-sdk": ^1.3.0 - "@uniswap/router-sdk": ^2.4.0 + "@uniswap/router-sdk": "file:tmp/router-sdk-guidestar-routes-1.tgz" "@uniswap/sdk-core": ^7.10.0 "@uniswap/universal-router": 2.1.0 "@uniswap/v2-core": ^1.0.1