From 24487a31ada30e8148d73402e0191ccd3799f1ed Mon Sep 17 00:00:00 2001 From: Emily Williams Date: Fri, 7 Jan 2022 13:51:23 -0500 Subject: [PATCH 01/14] Update router02 address in provider (#50) --- src/providers/swap-router-provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/swap-router-provider.ts b/src/providers/swap-router-provider.ts index 16831add2..cd371cd32 100644 --- a/src/providers/swap-router-provider.ts +++ b/src/providers/swap-router-provider.ts @@ -9,7 +9,7 @@ type TokenApprovalTypes = { approvalTokenOut: ApprovalTypes; }; -const SWAP_ROUTER_ADDRESS = '0x075B36dE1Bd11cb361c5B3B1E80A9ab0e7aa8a60'; +const SWAP_ROUTER_ADDRESS = '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'; /** * Provider for accessing the SwapRouter02 Contract . From 288f3a0784f441459b7ac1c2c0fa59e8114b8297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Y=C3=A1bir=20Benchakhtir?= Date: Mon, 10 Jan 2022 18:10:41 +0100 Subject: [PATCH 02/14] Fix cli order for polygon not formatted properly (#51) --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73a3dcc83..7b71b299f 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,8 @@ Calldata: 0x414bf389000000000000000000000000dac17f958d2ee523a2206206994597c13d83 ./bin/cli quote --tokenIn 0x001b3b4d0f3714ca98ba10f6042daebf0b1b7b6f --tokenOut 0x9c3c9283d3e44854697cd22d3faa240cfb032889 --amount 1 --exactIn --protocols v3 --recipient 0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B --minSplits 1 --router alpha --chainId 80001 ``` -# Polygon Mainnet +## Polygon Mainnet +``` ./bin/cli quote --tokenIn 0x2791bca1f2de4661ed88a30c99a7a9449aa84174 --tokenOut 0x7ceb23fd6bc0add59e62ac25578270cff1b9f619 --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 137 +``` From 84b44806d1994447bda5c50f947e39eeb9dc1b54 Mon Sep 17 00:00:00 2001 From: Will Pote Date: Mon, 10 Jan 2022 18:03:18 -0500 Subject: [PATCH 03/14] Handle tokens with 0 decimals --- cli/base-command.ts | 20 +++++++++--- src/providers/v3/quote-provider.ts | 2 +- .../alpha-router/functions/best-swap-route.ts | 8 ++--- src/routers/legacy-router/legacy-router.ts | 2 +- .../routers/alpha-router/alpha-router.test.ts | 31 ++++++++++++++++++- test/unit/test-util/mock-data.ts | 19 ++++++++++++ 6 files changed, 71 insertions(+), 11 deletions(-) diff --git a/cli/base-command.ts b/cli/base-command.ts index 6641ff3fe..78d3c164d 100644 --- a/cli/base-command.ts +++ b/cli/base-command.ts @@ -303,14 +303,26 @@ export abstract class BaseCommand extends Command { this.logger.info(`${routeAmountsToString(routeAmounts)}`); this.logger.info(`\tRaw Quote Exact In:`); - this.logger.info(`\t\t${quote.toFixed(2)}`); + this.logger.info( + `\t\t${quote.toFixed(Math.min(quote.currency.decimals, 2))}` + ); this.logger.info(`\tGas Adjusted Quote In:`); - this.logger.info(`\t\t${quoteGasAdjusted.toFixed(2)}`); + this.logger.info( + `\t\t${quoteGasAdjusted.toFixed( + Math.min(quoteGasAdjusted.currency.decimals, 2) + )}` + ); this.logger.info(``); this.logger.info( - `Gas Used Quote Token: ${estimatedGasUsedQuoteToken.toFixed(6)}` + `Gas Used Quote Token: ${estimatedGasUsedQuoteToken.toFixed( + Math.min(estimatedGasUsedQuoteToken.currency.decimals, 6) + )}` + ); + this.logger.info( + `Gas Used USD: ${estimatedGasUsedUSD.toFixed( + Math.min(estimatedGasUsedUSD.currency.decimals, 6) + )}` ); - this.logger.info(`Gas Used USD: ${estimatedGasUsedUSD.toFixed(6)}`); this.logger.info(`Calldata: ${methodParameters?.calldata}`); this.logger.info(`Value: ${methodParameters?.value}`); this.logger.info({ diff --git a/src/providers/v3/quote-provider.ts b/src/providers/v3/quote-provider.ts index dc0fab01e..c3005567a 100644 --- a/src/providers/v3/quote-provider.ts +++ b/src/providers/v3/quote-provider.ts @@ -821,7 +821,7 @@ export class V3QuoteProvider implements IV3QuoteProvider { if (!quoteResult.success) { const percent = (100 / amounts.length) * (index + 1); - const amountStr = amount.toFixed(2); + const amountStr = amount.toFixed(Math.min(amount.currency.decimals, 2)); const routeStr = routeToString(route); debugFailedQuotes.push({ route: routeStr, diff --git a/src/routers/alpha-router/functions/best-swap-route.ts b/src/routers/alpha-router/functions/best-swap-route.ts index dd981e6ff..19873f0c8 100644 --- a/src/routers/alpha-router/functions/best-swap-route.ts +++ b/src/routers/alpha-router/functions/best-swap-route.ts @@ -91,9 +91,9 @@ export function getBestSwapRoute( numSplits: routeAmounts.length, amount: amount.toExact(), quote: swapRoute.quote.toExact(), - quoteGasAdjusted: swapRoute.quoteGasAdjusted.toFixed(2), - estimatedGasUSD: swapRoute.estimatedGasUsedUSD.toFixed(2), - estimatedGasToken: swapRoute.estimatedGasUsedQuoteToken.toFixed(2), + quoteGasAdjusted: swapRoute.quoteGasAdjusted.toFixed(Math.min(swapRoute.quoteGasAdjusted.currency.decimals, 2)), + estimatedGasUSD: swapRoute.estimatedGasUsedUSD.toFixed(Math.min(swapRoute.estimatedGasUsedUSD.currency.decimals, 2)), + estimatedGasToken: swapRoute.estimatedGasUsedQuoteToken.toFixed(Math.min(swapRoute.estimatedGasUsedQuoteToken.currency.decimals, 2)), }, `Found best swap route. ${routeAmounts.length} split.` ); @@ -139,7 +139,7 @@ export function getBestSwapRouteBy( protocol: p.protocol, route: routeToString(p.route), percent: p.percent, - quote: p.quoteAdjustedForGas.toFixed(2), + quote: p.quoteAdjustedForGas.toFixed(Math.min(p.quoteToken.decimals, 2)), })) ), }, diff --git a/src/routers/legacy-router/legacy-router.ts b/src/routers/legacy-router/legacy-router.ts index 3e6bb10d5..d358103f4 100644 --- a/src/routers/legacy-router/legacy-router.ts +++ b/src/routers/legacy-router/legacy-router.ts @@ -310,7 +310,7 @@ export class LegacyRouter implements IRouter { for (let rq of routeQuotes) { log.debug( - `Quote: ${rq.amount.toFixed(2)} Route: ${routeToString(rq.route)}` + `Quote: ${rq.amount.toFixed(Math.min(rq.amount.currency.decimals, 2))} Route: ${routeToString(rq.route)}` ); } diff --git a/test/unit/routers/alpha-router/alpha-router.test.ts b/test/unit/routers/alpha-router/alpha-router.test.ts index b980ac89c..2c5e711b4 100644 --- a/test/unit/routers/alpha-router/alpha-router.test.ts +++ b/test/unit/routers/alpha-router/alpha-router.test.ts @@ -53,11 +53,13 @@ import { mockBlock, mockBlockBN, mockGasPriceWeiBN, + MOCK_ZERO_DEC_TOKEN, pairToV2SubgraphPool, poolToV3SubgraphPool, USDC_DAI, USDC_DAI_LOW, USDC_DAI_MEDIUM, + USDC_MOCK_LOW, USDC_USDT_MEDIUM, USDC_WETH, USDC_WETH_LOW, @@ -144,7 +146,13 @@ describe('alpha router', () => { mockMulticallProvider = sinon.createStubInstance(UniswapMulticallProvider); mockTokenProvider = sinon.createStubInstance(TokenProvider); - const mockTokens = [USDC, DAI, WRAPPED_NATIVE_CURRENCY[1], USDT]; + const mockTokens = [ + USDC, + DAI, + WRAPPED_NATIVE_CURRENCY[1], + USDT, + MOCK_ZERO_DEC_TOKEN, + ]; mockTokenProvider.getTokens.resolves(buildMockTokenAccessor(mockTokens)); mockV3PoolProvider = sinon.createStubInstance(V3PoolProvider); @@ -155,6 +163,7 @@ describe('alpha router', () => { WETH9_USDT_LOW, DAI_USDT_LOW, USDC_USDT_MEDIUM, + USDC_MOCK_LOW, ]; mockV3PoolProvider.getPools.resolves(buildMockV3PoolAccessor(v3MockPools)); mockV3PoolProvider.getPoolAddress.callsFake((tA, tB, fee) => ({ @@ -651,6 +660,26 @@ describe('alpha router', () => { expect(swap!.blockNumber.toString()).toEqual(mockBlockBN.toString()); }); + test('succeeds to route to and from token with 0 decimals', async () => { + const swapFrom = await alphaRouter.route( + CurrencyAmount.fromRawAmount(USDC, 10000), + MOCK_ZERO_DEC_TOKEN, + TradeType.EXACT_INPUT, + undefined, + { ...ROUTING_CONFIG } + ); + expect(swapFrom).toBeDefined(); + + const swapTo = await alphaRouter.route( + CurrencyAmount.fromRawAmount(MOCK_ZERO_DEC_TOKEN, 10000), + USDC, + TradeType.EXACT_INPUT, + undefined, + { ...ROUTING_CONFIG } + ); + expect(swapTo).toBeDefined(); + }); + test('succeeds to route on v3 only', async () => { const swap = await alphaRouter.route( CurrencyAmount.fromRawAmount(USDC, 10000), diff --git a/test/unit/test-util/mock-data.ts b/test/unit/test-util/mock-data.ts index 9480d2bfc..ac5ac011b 100644 --- a/test/unit/test-util/mock-data.ts +++ b/test/unit/test-util/mock-data.ts @@ -6,6 +6,7 @@ import { BigNumber } from 'ethers'; import _ from 'lodash'; import { AlphaRouterConfig, + ChainId, CurrencyAmount, DAI_MAINNET as DAI, TokenAccessor, @@ -47,7 +48,25 @@ export const mockRoutingConfig: AlphaRouterConfig = { forceCrossProtocol: false, }; +// Mock 0 decimal token +export const MOCK_ZERO_DEC_TOKEN = new Token( + ChainId.MAINNET, + '0x11fe4b6ae13d2a6055c8d9cf65c55bac32b5d844', + 0, + 'MOCK', + 'Mock Zero Dec' +); + // Mock V3 Pools +export const USDC_MOCK_LOW = new Pool( + USDC, + MOCK_ZERO_DEC_TOKEN, + FeeAmount.LOW, + encodeSqrtRatioX96(1, 1), + 500, + 0 +); + export const USDC_WETH_LOW = new Pool( USDC, WRAPPED_NATIVE_CURRENCY[1]!, From ae2d48104ba852353327c11bd9f9d50dd7dbb6a8 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Tue, 11 Jan 2022 15:05:54 +0000 Subject: [PATCH 04/14] Fix code style issues with Prettier --- src/providers/v3/quote-provider.ts | 4 +++- .../alpha-router/functions/best-swap-route.ts | 16 ++++++++++++---- src/routers/legacy-router/legacy-router.ts | 4 +++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/providers/v3/quote-provider.ts b/src/providers/v3/quote-provider.ts index c3005567a..ea84f4e3f 100644 --- a/src/providers/v3/quote-provider.ts +++ b/src/providers/v3/quote-provider.ts @@ -821,7 +821,9 @@ export class V3QuoteProvider implements IV3QuoteProvider { if (!quoteResult.success) { const percent = (100 / amounts.length) * (index + 1); - const amountStr = amount.toFixed(Math.min(amount.currency.decimals, 2)); + const amountStr = amount.toFixed( + Math.min(amount.currency.decimals, 2) + ); const routeStr = routeToString(route); debugFailedQuotes.push({ route: routeStr, diff --git a/src/routers/alpha-router/functions/best-swap-route.ts b/src/routers/alpha-router/functions/best-swap-route.ts index 19873f0c8..e0e29cc48 100644 --- a/src/routers/alpha-router/functions/best-swap-route.ts +++ b/src/routers/alpha-router/functions/best-swap-route.ts @@ -91,9 +91,15 @@ export function getBestSwapRoute( numSplits: routeAmounts.length, amount: amount.toExact(), quote: swapRoute.quote.toExact(), - quoteGasAdjusted: swapRoute.quoteGasAdjusted.toFixed(Math.min(swapRoute.quoteGasAdjusted.currency.decimals, 2)), - estimatedGasUSD: swapRoute.estimatedGasUsedUSD.toFixed(Math.min(swapRoute.estimatedGasUsedUSD.currency.decimals, 2)), - estimatedGasToken: swapRoute.estimatedGasUsedQuoteToken.toFixed(Math.min(swapRoute.estimatedGasUsedQuoteToken.currency.decimals, 2)), + quoteGasAdjusted: swapRoute.quoteGasAdjusted.toFixed( + Math.min(swapRoute.quoteGasAdjusted.currency.decimals, 2) + ), + estimatedGasUSD: swapRoute.estimatedGasUsedUSD.toFixed( + Math.min(swapRoute.estimatedGasUsedUSD.currency.decimals, 2) + ), + estimatedGasToken: swapRoute.estimatedGasUsedQuoteToken.toFixed( + Math.min(swapRoute.estimatedGasUsedQuoteToken.currency.decimals, 2) + ), }, `Found best swap route. ${routeAmounts.length} split.` ); @@ -139,7 +145,9 @@ export function getBestSwapRouteBy( protocol: p.protocol, route: routeToString(p.route), percent: p.percent, - quote: p.quoteAdjustedForGas.toFixed(Math.min(p.quoteToken.decimals, 2)), + quote: p.quoteAdjustedForGas.toFixed( + Math.min(p.quoteToken.decimals, 2) + ), })) ), }, diff --git a/src/routers/legacy-router/legacy-router.ts b/src/routers/legacy-router/legacy-router.ts index d358103f4..fb688c683 100644 --- a/src/routers/legacy-router/legacy-router.ts +++ b/src/routers/legacy-router/legacy-router.ts @@ -310,7 +310,9 @@ export class LegacyRouter implements IRouter { for (let rq of routeQuotes) { log.debug( - `Quote: ${rq.amount.toFixed(Math.min(rq.amount.currency.decimals, 2))} Route: ${routeToString(rq.route)}` + `Quote: ${rq.amount.toFixed( + Math.min(rq.amount.currency.decimals, 2) + )} Route: ${routeToString(rq.route)}` ); } From c4ea0c50e526973058a7b849d8d16c5285d50784 Mon Sep 17 00:00:00 2001 From: Will Pote Date: Tue, 11 Jan 2022 10:07:07 -0500 Subject: [PATCH 05/14] chore(release): 2.5.10 --- CHANGELOG.md | 2 ++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5666bb506..6f77e2a3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.5.10](https://github.com/Uniswap/smart-order-router/compare/v2.5.9...v2.5.10) (2022-01-11) + ### [2.5.9](https://github.com/Uniswap/smart-order-router/compare/v2.5.4...v2.5.9) (2022-01-05) ### [2.5.8](https://github.com/Uniswap/smart-order-router/compare/v2.5.4...v2.5.8) (2022-01-04) diff --git a/package-lock.json b/package-lock.json index 55d0b3314..7811d92ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@uniswap/smart-order-router", - "version": "2.5.9", + "version": "2.5.10", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index ae53fe36d..6e6a35585 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uniswap/smart-order-router", - "version": "2.5.9", + "version": "2.5.10", "description": "Uniswap Smart Order Router", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From 7ecc88601bd2b9358914f82c43b56ece60645c87 Mon Sep 17 00:00:00 2001 From: Will Pote Date: Tue, 11 Jan 2022 11:29:56 -0500 Subject: [PATCH 06/14] Added debug logs for v2 quotes --- src/providers/v2/quote-provider.ts | 30 ++++++++++++++++++++++++++---- src/providers/v3/quote-provider.ts | 2 +- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/providers/v2/quote-provider.ts b/src/providers/v2/quote-provider.ts index be5d924c3..585981b66 100644 --- a/src/providers/v2/quote-provider.ts +++ b/src/providers/v2/quote-provider.ts @@ -6,6 +6,8 @@ import { import { BigNumber } from 'ethers'; import { V2Route } from '../../routers/router'; import { CurrencyAmount } from '../../util/amounts'; +import { log } from '../../util/log'; +import { routeToString } from '../../util/routes'; // Quotes can be null (e.g. pool did not have enough liquidity). export type V2AmountQuote = { @@ -58,9 +60,12 @@ export class V2QuoteProvider implements IV2QuoteProvider { ): Promise<{ routesWithQuotes: V2RouteWithQuotes[] }> { const routesWithQuotes: V2RouteWithQuotes[] = []; + let debugStrs: string[] = []; for (const route of routes) { const amountQuotes: V2AmountQuote[] = []; + let insufficientInputAmountErrorCount = 0; + let insufficientReservesErrorCount = 0; for (const amount of amounts) { try { if (tradeType == TradeType.EXACT_INPUT) { @@ -90,10 +95,12 @@ export class V2QuoteProvider implements IV2QuoteProvider { } } catch (err) { // Can fail to get quotes, e.g. throws InsufficientReservesError or InsufficientInputAmountError. - if ( - err instanceof InsufficientInputAmountError || - err instanceof InsufficientReservesError - ) { + if (err instanceof InsufficientInputAmountError) { + insufficientInputAmountErrorCount = + insufficientInputAmountErrorCount + 1; + amountQuotes.push({ amount, quote: null }); + } else if (err instanceof InsufficientReservesError) { + insufficientReservesErrorCount = insufficientReservesErrorCount + 1; amountQuotes.push({ amount, quote: null }); } else { throw err; @@ -101,8 +108,23 @@ export class V2QuoteProvider implements IV2QuoteProvider { } } + if ( + insufficientInputAmountErrorCount > 0 || + insufficientReservesErrorCount > 0 + ) { + debugStrs.push( + `${[ + routeToString(route), + ]} Input: ${insufficientInputAmountErrorCount} Reserves: ${insufficientReservesErrorCount} }` + ); + } + routesWithQuotes.push([route, amountQuotes]); } + + if (debugStrs.length > 0) { + log.info({ debugStrs }, `Failed quotes for V2 routes`); + } return { routesWithQuotes, diff --git a/src/providers/v3/quote-provider.ts b/src/providers/v3/quote-provider.ts index ea84f4e3f..ceadd47b6 100644 --- a/src/providers/v3/quote-provider.ts +++ b/src/providers/v3/quote-provider.ts @@ -871,7 +871,7 @@ export class V3QuoteProvider implements IV3QuoteProvider { (amounts, routeStr) => `${routeStr} : ${amounts}` ), }, - `Failed quotes for routes Part ${idx}/${Math.ceil( + `Failed quotes for V3 routes Part ${idx}/${Math.ceil( debugFailedQuotes.length / debugChunk )}` ); From fb2950eb8fcaffdea313368855c913836f8a5065 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Tue, 11 Jan 2022 16:31:04 +0000 Subject: [PATCH 07/14] Fix code style issues with Prettier --- src/providers/v2/quote-provider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/v2/quote-provider.ts b/src/providers/v2/quote-provider.ts index 585981b66..2489592be 100644 --- a/src/providers/v2/quote-provider.ts +++ b/src/providers/v2/quote-provider.ts @@ -121,7 +121,7 @@ export class V2QuoteProvider implements IV2QuoteProvider { routesWithQuotes.push([route, amountQuotes]); } - + if (debugStrs.length > 0) { log.info({ debugStrs }, `Failed quotes for V2 routes`); } From 4d69c109c0bdd956d059810de1bb1508d4c17efb Mon Sep 17 00:00:00 2001 From: Emily Williams Date: Tue, 11 Jan 2022 16:02:39 -0500 Subject: [PATCH 08/14] RouteToRatio edgecase fixes + better logging (#52) * better logs + more specific error for inadequate exchangeRate * Fix code style issues with Prettier Co-authored-by: Lint Action --- src/routers/alpha-router/alpha-router.ts | 28 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/routers/alpha-router/alpha-router.ts b/src/routers/alpha-router/alpha-router.ts index 47a2be5a4..3fd906750 100644 --- a/src/routers/alpha-router/alpha-router.ts +++ b/src/routers/alpha-router/alpha-router.ts @@ -559,7 +559,7 @@ export class AlphaRouter outputBalance ); if (amountToSwap.equalTo(0)) { - log.info(`no swap needed`); + log.info(`no swap needed: amountToSwap = 0`); return { status: SwapToRatioStatus.NO_SWAP_NEEDED, }; @@ -630,12 +630,26 @@ export class AlphaRouter } exchangeRate = swap.trade!.outputAmount.divide(swap.trade!.inputAmount); - log.info({ - optimalRatio: optimalRatio.asFraction.toFixed(18), - newRatio: newRatio.asFraction.toFixed(18), - ratioErrorTolerance: swapAndAddConfig.ratioErrorTolerance.toFixed(18), - iterationN: n.toString(), - }); + log.info( + { + exchangeRate: exchangeRate.asFraction.toFixed(18), + optimalRatio: optimalRatio.asFraction.toFixed(18), + newRatio: newRatio.asFraction.toFixed(18), + inputBalanceUpdated: inputBalanceUpdated.asFraction.toFixed(18), + outputBalanceUpdated: outputBalanceUpdated.asFraction.toFixed(18), + ratioErrorTolerance: swapAndAddConfig.ratioErrorTolerance.toFixed(18), + iterationN: n.toString(), + }, + 'QuoteToRatio Iteration Parameters' + ); + + if (exchangeRate.equalTo(0)) { + log.info('exchangeRate to 0'); + return { + status: SwapToRatioStatus.NO_ROUTE_FOUND, + error: 'insufficient liquidity to swap to optimal ratio', + }; + } } if (!swap) { From 6f66dfa0e225ede9369bd6d47fc92e04c1ef5f4b Mon Sep 17 00:00:00 2001 From: Emily Williams Date: Tue, 11 Jan 2022 16:06:50 -0500 Subject: [PATCH 09/14] add log to routeToRatio() --- src/routers/alpha-router/alpha-router.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routers/alpha-router/alpha-router.ts b/src/routers/alpha-router/alpha-router.ts index 3fd906750..80310a3a0 100644 --- a/src/routers/alpha-router/alpha-router.ts +++ b/src/routers/alpha-router/alpha-router.ts @@ -576,6 +576,7 @@ export class AlphaRouter } ); if (!swap) { + log.info('no route found from this.route()') return { status: SwapToRatioStatus.NO_ROUTE_FOUND, error: 'no route found', From 0491ae4745d89dcce79128eeaa6d8d59d08cee2b Mon Sep 17 00:00:00 2001 From: Lint Action Date: Tue, 11 Jan 2022 21:08:27 +0000 Subject: [PATCH 10/14] Fix code style issues with Prettier --- src/routers/alpha-router/alpha-router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routers/alpha-router/alpha-router.ts b/src/routers/alpha-router/alpha-router.ts index 80310a3a0..ec625ebc8 100644 --- a/src/routers/alpha-router/alpha-router.ts +++ b/src/routers/alpha-router/alpha-router.ts @@ -576,7 +576,7 @@ export class AlphaRouter } ); if (!swap) { - log.info('no route found from this.route()') + log.info('no route found from this.route()'); return { status: SwapToRatioStatus.NO_ROUTE_FOUND, error: 'no route found', From 0c8a628bc9ddef4a35659d99e5e5d680de5fe2dd Mon Sep 17 00:00:00 2001 From: Emily Williams Date: Tue, 11 Jan 2022 16:11:28 -0500 Subject: [PATCH 11/14] chore(release): 2.5.11 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f77e2a3f..fe9868af7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.5.11](https://github.com/Uniswap/smart-order-router/compare/v2.5.9...v2.5.11) (2022-01-11) + ### [2.5.10](https://github.com/Uniswap/smart-order-router/compare/v2.5.9...v2.5.10) (2022-01-11) ### [2.5.9](https://github.com/Uniswap/smart-order-router/compare/v2.5.4...v2.5.9) (2022-01-05) diff --git a/package-lock.json b/package-lock.json index 7811d92ad..1c5d209c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@uniswap/smart-order-router", - "version": "2.5.10", + "version": "2.5.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@uniswap/smart-order-router", - "version": "2.5.8", + "version": "2.5.11", "license": "GPL", "dependencies": { "@bitauth/libauth": "^1.17.1", diff --git a/package.json b/package.json index 6e6a35585..547c02368 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uniswap/smart-order-router", - "version": "2.5.10", + "version": "2.5.11", "description": "Uniswap Smart Order Router", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From f082067ffb0e4b4ef498f6de6d81318587b3d427 Mon Sep 17 00:00:00 2001 From: Will Pote Date: Wed, 12 Jan 2022 13:10:48 -0500 Subject: [PATCH 12/14] Update readme for running unit tests --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7b71b299f..0a1c9e8fb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ It searches for the most efficient way to swap token A for token B, considering ### Unit Tests +First make sure you have run `npm install` and `npm run build`. + ``` npm run test ``` From 5e60d46c7996eb1a6ee632c65e177cd874dad8db Mon Sep 17 00:00:00 2001 From: Will Pote Date: Wed, 12 Jan 2022 13:33:40 -0500 Subject: [PATCH 13/14] Workaround to support ring token --- src/providers/caching-token-provider.ts | 95 ++++++++++++++++++++++++- src/providers/token-provider.ts | 51 +------------ 2 files changed, 93 insertions(+), 53 deletions(-) diff --git a/src/providers/caching-token-provider.ts b/src/providers/caching-token-provider.ts index 7b836df6e..06ce28eb5 100644 --- a/src/providers/caching-token-provider.ts +++ b/src/providers/caching-token-provider.ts @@ -1,8 +1,97 @@ import { Token } from '@uniswap/sdk-core'; import _ from 'lodash'; -import { ChainId, log } from '../util'; +import { ChainId, log, WRAPPED_NATIVE_CURRENCY } from '../util'; import { ICache } from './cache'; -import { ITokenProvider, SEED_TOKENS, TokenAccessor } from './token-provider'; +import { + DAI_ARBITRUM, + DAI_ARBITRUM_RINKEBY, + DAI_MAINNET, + DAI_OPTIMISM, + DAI_OPTIMISTIC_KOVAN, + DAI_POLYGON_MUMBAI, + DAI_RINKEBY_1, + DAI_RINKEBY_2, + ITokenProvider, + TokenAccessor, + UNI_ARBITRUM_RINKEBY, + USDC_ARBITRUM, + USDC_ARBITRUM_RINKEBY, + USDC_MAINNET, + USDC_OPTIMISM, + USDC_OPTIMISTIC_KOVAN, + USDC_POLYGON, + USDT_ARBITRUM, + USDT_ARBITRUM_RINKEBY, + USDT_MAINNET, + USDT_OPTIMISM, + USDT_OPTIMISTIC_KOVAN, + WBTC_ARBITRUM, + WBTC_MAINNET, + WBTC_OPTIMISM, + WBTC_OPTIMISTIC_KOVAN, + WMATIC_POLYGON, + WMATIC_POLYGON_MUMBAI, +} from './token-provider'; + +// These tokens will added to the Token cache on initialization. +export const CACHE_SEED_TOKENS: { + [chainId in ChainId]?: { [symbol: string]: Token }; +} = { + [ChainId.MAINNET]: { + WETH: WRAPPED_NATIVE_CURRENCY[ChainId.MAINNET]!, + USDC: USDC_MAINNET, + USDT: USDT_MAINNET, + WBTC: WBTC_MAINNET, + DAI: DAI_MAINNET, + // This token stores its symbol as bytes32, therefore can not be fetched on-chain using + // our token providers. + // This workaround adds it to the cache, so we won't try to fetch it on-chain. + RING: new Token( + ChainId.MAINNET, + '0x9469D013805bFfB7D3DEBe5E7839237e535ec483', + 18, + 'RING', + 'RING' + ), + }, + [ChainId.RINKEBY]: { + WETH: WRAPPED_NATIVE_CURRENCY[ChainId.RINKEBY]!, + DAI_1: DAI_RINKEBY_1, + DAI_2: DAI_RINKEBY_2, + }, + [ChainId.OPTIMISM]: { + USDC: USDC_OPTIMISM, + USDT: USDT_OPTIMISM, + WBTC: WBTC_OPTIMISM, + DAI: DAI_OPTIMISM, + }, + [ChainId.OPTIMISTIC_KOVAN]: { + USDC: USDC_OPTIMISTIC_KOVAN, + USDT: USDT_OPTIMISTIC_KOVAN, + WBTC: WBTC_OPTIMISTIC_KOVAN, + DAI: DAI_OPTIMISTIC_KOVAN, + }, + [ChainId.ARBITRUM_ONE]: { + USDC: USDC_ARBITRUM, + USDT: USDT_ARBITRUM, + WBTC: WBTC_ARBITRUM, + DAI: DAI_ARBITRUM, + }, + [ChainId.ARBITRUM_RINKEBY]: { + USDT: USDT_ARBITRUM_RINKEBY, + UNI: UNI_ARBITRUM_RINKEBY, + DAI: DAI_ARBITRUM_RINKEBY, + USDC: USDC_ARBITRUM_RINKEBY, + }, + [ChainId.POLYGON]: { + WMATIC: WMATIC_POLYGON, + USDC: USDC_POLYGON, + }, + [ChainId.POLYGON_MUMBAI]: { + WMATIC: WMATIC_POLYGON_MUMBAI, + DAI: DAI_POLYGON_MUMBAI, + }, +}; /** * Provider for getting token metadata that falls back to a different provider @@ -25,7 +114,7 @@ export class CachingTokenProviderWithFallback implements ITokenProvider { ) {} public async getTokens(_addresses: string[]): Promise { - const seedTokens = SEED_TOKENS[this.chainId]; + const seedTokens = CACHE_SEED_TOKENS[this.chainId]; if (seedTokens) { for (const token of Object.values(seedTokens)) { diff --git a/src/providers/token-provider.ts b/src/providers/token-provider.ts index 7cdee80bc..6b0324295 100644 --- a/src/providers/token-provider.ts +++ b/src/providers/token-provider.ts @@ -1,7 +1,7 @@ import { Token } from '@uniswap/sdk-core'; import _ from 'lodash'; import { IERC20Metadata__factory } from '../types/v3'; -import { ChainId, log, WRAPPED_NATIVE_CURRENCY } from '../util'; +import { ChainId, log } from '../util'; import { IMulticallProvider } from './multicall-provider'; import { ProviderConfig } from './provider'; @@ -371,55 +371,6 @@ export const WETH_POLYGON_MUMBAI = new Token( 'Wrapped Ether' ); -export const SEED_TOKENS: { - [chainId in ChainId]?: { [symbol: string]: Token }; -} = { - [ChainId.MAINNET]: { - WETH: WRAPPED_NATIVE_CURRENCY[ChainId.MAINNET]!, - USDC: USDC_MAINNET, - USDT: USDT_MAINNET, - WBTC: WBTC_MAINNET, - DAI: DAI_MAINNET, - }, - [ChainId.RINKEBY]: { - WETH: WRAPPED_NATIVE_CURRENCY[ChainId.RINKEBY]!, - DAI_1: DAI_RINKEBY_1, - DAI_2: DAI_RINKEBY_2, - }, - [ChainId.OPTIMISM]: { - USDC: USDC_OPTIMISM, - USDT: USDT_OPTIMISM, - WBTC: WBTC_OPTIMISM, - DAI: DAI_OPTIMISM, - }, - [ChainId.OPTIMISTIC_KOVAN]: { - USDC: USDC_OPTIMISTIC_KOVAN, - USDT: USDT_OPTIMISTIC_KOVAN, - WBTC: WBTC_OPTIMISTIC_KOVAN, - DAI: DAI_OPTIMISTIC_KOVAN, - }, - [ChainId.ARBITRUM_ONE]: { - USDC: USDC_ARBITRUM, - USDT: USDT_ARBITRUM, - WBTC: WBTC_ARBITRUM, - DAI: DAI_ARBITRUM, - }, - [ChainId.ARBITRUM_RINKEBY]: { - USDT: USDT_ARBITRUM_RINKEBY, - UNI: UNI_ARBITRUM_RINKEBY, - DAI: DAI_ARBITRUM_RINKEBY, - USDC: USDC_ARBITRUM_RINKEBY, - }, - [ChainId.POLYGON]: { - WMATIC: WMATIC_POLYGON, - USDC: USDC_POLYGON, - }, - [ChainId.POLYGON_MUMBAI]: { - WMATIC: WMATIC_POLYGON_MUMBAI, - DAI: DAI_POLYGON_MUMBAI, - }, -}; - export class TokenProvider implements ITokenProvider { constructor( private chainId: ChainId, From 1ff372f4c6f789f19b18c2baeb3efeb2063cc599 Mon Sep 17 00:00:00 2001 From: Will Pote Date: Thu, 13 Jan 2022 13:05:21 -0500 Subject: [PATCH 14/14] chore(release): 2.5.12 --- CHANGELOG.md | 2 ++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe9868af7..a585b8ef8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [2.5.12](https://github.com/Uniswap/smart-order-router/compare/v2.5.9...v2.5.12) (2022-01-13) + ### [2.5.11](https://github.com/Uniswap/smart-order-router/compare/v2.5.9...v2.5.11) (2022-01-11) ### [2.5.10](https://github.com/Uniswap/smart-order-router/compare/v2.5.9...v2.5.10) (2022-01-11) diff --git a/package-lock.json b/package-lock.json index 1c5d209c6..bed141f6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@uniswap/smart-order-router", - "version": "2.5.11", + "version": "2.5.12", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 547c02368..3a27f6b24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uniswap/smart-order-router", - "version": "2.5.11", + "version": "2.5.12", "description": "Uniswap Smart Order Router", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts",