From fb94af9a1fe3972c2c640acc44d98aea3786faa1 Mon Sep 17 00:00:00 2001 From: Sara Reynolds Date: Fri, 15 Jul 2022 12:14:27 -0700 Subject: [PATCH 1/3] should be able to quote in native currency string --- README.md | 27 +++++++++++++++++---------- cli/commands/quote.ts | 28 +++++++++++++++------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index b707d5ee5..8ec4a3e0e 100644 --- a/README.md +++ b/README.md @@ -146,16 +146,23 @@ Calldata: 0x414bf389000000000000000000000000dac17f958d2ee523a2206206994597c13d83 ./bin/cli quote --tokenIn 0x2791bca1f2de4661ed88a30c99a7a9449aa84174 --tokenOut 0x7ceb23fd6bc0add59e62ac25578270cff1b9f619 --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 137 ``` +## Celo Mainnet + +``` +./bin/cli quote --tokenIn CELO --tokenOut 0x765DE816845861e75A25fCA122bb6898B8B1282a --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 42220 +``` + ## Adding a new Chain + The main components to complete are: -* Deploy contracts on chain, add the pools to subgraph -* Populate v3 providers in `src/providers/v3/subgraph-provider` and `src/providers/v3/static-subgraph-provider` -* Populate chainId and addresses in `src/util/chains.ts` and `src/util/addresses.ts` -* Populate token providers in `src/providers/caching-token-provider` and `src/providers/token-provider.ts` -* Populate gas constants in `src/routers/alpha-router/gas-models/*` -* Populate bases in `src/routers/legacy-router/bases.ts` -* Populate `test/integ/routers/alpha-router/alpha-router.integration.test.ts` and `src/providers/v2/static-subgraph-provider.ts` -* Populate `src/routers/alpha-router/*` -* Add a log to `/CHANGELOG.md` -* Run `npm run integ-test` successfully +- Deploy contracts on chain, add the pools to subgraph +- Populate v3 providers in `src/providers/v3/subgraph-provider` and `src/providers/v3/static-subgraph-provider` +- Populate chainId and addresses in `src/util/chains.ts` and `src/util/addresses.ts` +- Populate token providers in `src/providers/caching-token-provider` and `src/providers/token-provider.ts` +- Populate gas constants in `src/routers/alpha-router/gas-models/*` +- Populate bases in `src/routers/legacy-router/bases.ts` +- Populate `test/integ/routers/alpha-router/alpha-router.integration.test.ts` and `src/providers/v2/static-subgraph-provider.ts` +- Populate `src/routers/alpha-router/*` +- Add a log to `/CHANGELOG.md` +- Run `npm run integ-test` successfully diff --git a/cli/commands/quote.ts b/cli/commands/quote.ts index ed838e4d4..2ff448816 100644 --- a/cli/commands/quote.ts +++ b/cli/commands/quote.ts @@ -85,20 +85,22 @@ export class Quote extends BaseCommand { const tokenProvider = this.tokenProvider; const router = this.router; - const tokenAccessor = await tokenProvider.getTokens([ - tokenInStr, - tokenOutStr, - ]); + // if the tokenIn str is 'ETH' or 'MATIC' or NATIVE_CURRENCY_STRING, quote with the wrapped native currency + const tokenIn: Currency = (Object) + .values(NativeCurrencyName) + .includes(tokenInStr) + ? nativeOnChain(chainId) + : (await tokenProvider.getTokens([tokenInStr])).getTokenByAddress( + tokenInStr + )!; - // if the tokenIn str is 'ETH' or 'MATIC' or NATIVE_CURRENCY_STRING - const tokenIn: Currency = - tokenInStr in NativeCurrencyName - ? nativeOnChain(chainId) - : tokenAccessor.getTokenByAddress(tokenInStr)!; - const tokenOut: Currency = - tokenOutStr in NativeCurrencyName - ? nativeOnChain(chainId) - : tokenAccessor.getTokenByAddress(tokenOutStr)!; + const tokenOut: Currency = (Object) + .values(NativeCurrencyName) + .includes(tokenOutStr) + ? nativeOnChain(chainId) + : (await tokenProvider.getTokens([tokenOutStr])).getTokenByAddress( + tokenOutStr + )!; let swapRoutes: SwapRoute | null; if (exactIn) { From 2fd7facd1b132a6de4b463a2854fffe26ffc6f16 Mon Sep 17 00:00:00 2001 From: Sara Reynolds Date: Wed, 20 Jul 2022 16:25:18 -0400 Subject: [PATCH 2/3] allow for other strings to map to native currency objects --- cli/commands/quote.ts | 13 ++++------ src/util/chains.ts | 58 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/cli/commands/quote.ts b/cli/commands/quote.ts index 2ff448816..7e7867c44 100644 --- a/cli/commands/quote.ts +++ b/cli/commands/quote.ts @@ -6,12 +6,11 @@ import dotenv from 'dotenv'; import _ from 'lodash'; import { ID_TO_CHAIN_ID, - NativeCurrencyName, nativeOnChain, parseAmount, SwapRoute, } from '../../src'; -import { TO_PROTOCOL } from '../../src/util'; +import { NATIVE_NAMES_BY_ID, TO_PROTOCOL } from '../../src/util'; import { BaseCommand } from '../base-command'; dotenv.config(); @@ -86,17 +85,15 @@ export class Quote extends BaseCommand { const router = this.router; // if the tokenIn str is 'ETH' or 'MATIC' or NATIVE_CURRENCY_STRING, quote with the wrapped native currency - const tokenIn: Currency = (Object) - .values(NativeCurrencyName) - .includes(tokenInStr) + const tokenIn: Currency = NATIVE_NAMES_BY_ID[chainId]!.includes(tokenInStr) ? nativeOnChain(chainId) : (await tokenProvider.getTokens([tokenInStr])).getTokenByAddress( tokenInStr )!; - const tokenOut: Currency = (Object) - .values(NativeCurrencyName) - .includes(tokenOutStr) + const tokenOut: Currency = NATIVE_NAMES_BY_ID[chainId]!.includes( + tokenOutStr + ) ? nativeOnChain(chainId) : (await tokenProvider.getTokens([tokenOutStr])).getTokenByAddress( tokenOutStr diff --git a/src/util/chains.ts b/src/util/chains.ts index 814b0e125..56ab96836 100644 --- a/src/util/chains.ts +++ b/src/util/chains.ts @@ -1,6 +1,6 @@ import { Currency, Ether, NativeCurrency, Token } from '@uniswap/sdk-core'; - import { WGLMR_MOONBEAM, WXDAI_GNOSIS } from '../providers'; + export enum ChainId { MAINNET = 1, ROPSTEN = 3, @@ -129,6 +129,62 @@ export enum NativeCurrencyName { GNOSIS = 'XDAI', MOONBEAM = 'GLMR', } +export const NATIVE_NAMES_BY_ID: { [chainId: number]: string[] } = { + [ChainId.MAINNET]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.RINKEBY]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.GĂ–RLI]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.KOVAN]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.ROPSTEN]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.OPTIMISM]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.OPTIMISTIC_KOVAN]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.ARBITRUM_ONE]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.ARBITRUM_RINKEBY]: [ + 'ETH', + 'ETHER', + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', + ], + [ChainId.POLYGON]: ['MATIC', '0x0000000000000000000000000000000000001010'], + [ChainId.POLYGON_MUMBAI]: [ + 'MATIC', + '0x0000000000000000000000000000000000001010', + ], + [ChainId.CELO]: ['CELO'], + [ChainId.CELO_ALFAJORES]: ['CELO'], + [ChainId.GNOSIS]: ['XDAI'], + [ChainId.MOONBEAM]: ['GLMR'], +}; export const NATIVE_CURRENCY: { [chainId: number]: NativeCurrencyName } = { [ChainId.MAINNET]: NativeCurrencyName.ETHER, From 4c08ff6e1d7569f40f5576c6831276ecbec22408 Mon Sep 17 00:00:00 2001 From: Sara Reynolds Date: Wed, 20 Jul 2022 16:26:39 -0400 Subject: [PATCH 3/3] fix comment --- cli/commands/quote.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/commands/quote.ts b/cli/commands/quote.ts index 7e7867c44..035dea15d 100644 --- a/cli/commands/quote.ts +++ b/cli/commands/quote.ts @@ -84,7 +84,7 @@ export class Quote extends BaseCommand { const tokenProvider = this.tokenProvider; const router = this.router; - // if the tokenIn str is 'ETH' or 'MATIC' or NATIVE_CURRENCY_STRING, quote with the wrapped native currency + // if the tokenIn str is 'ETH' or 'MATIC' or in NATIVE_NAMES_BY_ID const tokenIn: Currency = NATIVE_NAMES_BY_ID[chainId]!.includes(tokenInStr) ? nativeOnChain(chainId) : (await tokenProvider.getTokens([tokenInStr])).getTokenByAddress(