From eb61652514597a238076445559ca8440a1f53ec5 Mon Sep 17 00:00:00 2001 From: Anthony Date: Thu, 14 Sep 2023 16:41:35 +0900 Subject: [PATCH] Add Base support to Uniswap widget --- src/assets/svg/base_logo.svg | 4 ++++ src/constants/chainInfo.ts | 27 +++++++++++++++++++++++++++ src/constants/chains.ts | 12 ++++++++++++ src/constants/jsonRpcEndpoints.ts | 8 ++++++++ src/constants/routing.ts | 7 +++++++ src/constants/tokens.ts | 25 +++++++++++++++++++++++++ src/utils/getExplorerLink.ts | 2 ++ 7 files changed, 85 insertions(+) create mode 100644 src/assets/svg/base_logo.svg diff --git a/src/assets/svg/base_logo.svg b/src/assets/svg/base_logo.svg new file mode 100644 index 000000000..a784d6a5c --- /dev/null +++ b/src/assets/svg/base_logo.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/constants/chainInfo.ts b/src/constants/chainInfo.ts index d98069641..fe3103be7 100644 --- a/src/constants/chainInfo.ts +++ b/src/constants/chainInfo.ts @@ -1,5 +1,6 @@ import ethereumLogoUrl from 'assets/images/ethereum-logo.png' import arbitrumLogoUrl from 'assets/svg/arbitrum_logo.svg' +import baseLogo from 'assets/svg/base_logo.svg' import bnbLogo from 'assets/svg/bnb-logo.svg' import celoLogo from 'assets/svg/celo_logo.svg' import optimismLogoUrl from 'assets/svg/optimism_logo.svg' @@ -237,6 +238,32 @@ const CHAIN_INFO: ChainInfoMap = { color: '#F0B90B', backgroundColor: '#F0B90B', }, + [SupportedChainId.BASE]: { + networkType: NetworkType.L2, + blockWaitMsBeforeWarning: ms`10m`, + bridge: 'https://bridge.base.org/', + docs: 'https://docs.base.org/', + explorer: 'https://basescan.org/', + infoLink: 'https://info.uniswap.org/#/base/', + label: 'Base', + logoUrl: baseLogo, + nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, + color: '#0152ff', + backgroundColor: '#0152ff', + }, + [SupportedChainId.BASE_GOERLI]: { + networkType: NetworkType.L2, + blockWaitMsBeforeWarning: ms`10m`, + bridge: 'https://goerli-bridge.base.org/', + docs: 'https://docs.base.org/', + explorer: 'https://goerli.basescan.org/', + infoLink: 'https://info.uniswap.org/#/base/', + label: 'Base Goerli', + logoUrl: baseLogo, + nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 }, + color: '#0152ff', + backgroundColor: '#0152ff', + }, } export function getChainInfo(chainId: SupportedL1ChainId): L1ChainInfo diff --git a/src/constants/chains.ts b/src/constants/chains.ts index cf530f941..1dfb8fa68 100644 --- a/src/constants/chains.ts +++ b/src/constants/chains.ts @@ -21,6 +21,9 @@ export enum SupportedChainId { CELO_ALFAJORES = 44787, BNB = 56, + + BASE = 8453, + BASE_GOERLI = 84531, } export enum ChainName { @@ -38,6 +41,8 @@ export enum ChainName { CELO = 'celo', CELO_ALFAJORES = 'celo-alfajores', BNB = 'bnb', + BASE = 'base', + BASE_GOERLI = 'base-goerli', } export const CHAIN_NAMES_TO_IDS: { [chainName: string]: SupportedChainId } = { @@ -55,6 +60,8 @@ export const CHAIN_NAMES_TO_IDS: { [chainName: string]: SupportedChainId } = { [ChainName.CELO]: SupportedChainId.CELO, [ChainName.CELO_ALFAJORES]: SupportedChainId.CELO_ALFAJORES, [ChainName.BNB]: SupportedChainId.BNB, + [ChainName.BASE]: SupportedChainId.BASE, + [ChainName.BASE_GOERLI]: SupportedChainId.BASE_GOERLI, } /** @@ -71,6 +78,7 @@ export const SUPPORTED_GAS_ESTIMATE_CHAIN_IDS = [ SupportedChainId.ARBITRUM_ONE, SupportedChainId.CELO, SupportedChainId.BNB, + SupportedChainId.BASE, ] /** @@ -86,6 +94,8 @@ export const L1_CHAIN_IDS = [ SupportedChainId.POLYGON_MUMBAI, SupportedChainId.CELO, SupportedChainId.CELO_ALFAJORES, + SupportedChainId.BASE, + SupportedChainId.BASE_GOERLI, ] as const export type SupportedL1ChainId = typeof L1_CHAIN_IDS[number] @@ -99,6 +109,8 @@ export const L2_CHAIN_IDS = [ SupportedChainId.ARBITRUM_RINKEBY, SupportedChainId.OPTIMISM, SupportedChainId.OPTIMISM_GOERLI, + SupportedChainId.BASE, + SupportedChainId.BASE_GOERLI, ] as const export type SupportedL2ChainId = typeof L2_CHAIN_IDS[number] diff --git a/src/constants/jsonRpcEndpoints.ts b/src/constants/jsonRpcEndpoints.ts index 7c7e97561..8069dea12 100644 --- a/src/constants/jsonRpcEndpoints.ts +++ b/src/constants/jsonRpcEndpoints.ts @@ -86,4 +86,12 @@ export const JSON_RPC_FALLBACK_ENDPOINTS: Record = { 'https://bsc-dataseed4.defibit.io', 'https://rpc.ankr.com/bsc', ], + [SupportedChainId.BASE]: [ + // "Safe" URLs + 'https://mainnet.base.org', + ], + [SupportedChainId.BASE_GOERLI]: [ + // "Safe" URLs + 'https://goerli.base.org', + ], } diff --git a/src/constants/routing.ts b/src/constants/routing.ts index 1336fe771..d748a0ddd 100644 --- a/src/constants/routing.ts +++ b/src/constants/routing.ts @@ -9,6 +9,7 @@ import { CUSD_CELO, DAI, DAI_ARBITRUM_ONE, + DAI_BASE, DAI_OPTIMISM, DAI_POLYGON, ETH2X_FLI, @@ -24,6 +25,7 @@ import { SWISE, TRIBE, USDC_BNB_CHAIN, + USDC_BASE, USDC_MAINNET, USDC_POLYGON, USDT, @@ -92,6 +94,11 @@ export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = { USDT_BNB_CHAIN, ...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.BNB], ], + [SupportedChainId.BASE]: [ + ...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.BASE], + DAI_BASE, + USDC_BASE, + ], } export const ADDITIONAL_BASES: { [chainId: number]: { [tokenAddress: string]: Token[] } } = { [SupportedChainId.MAINNET]: { diff --git a/src/constants/tokens.ts b/src/constants/tokens.ts index df853c490..efb677eeb 100644 --- a/src/constants/tokens.ts +++ b/src/constants/tokens.ts @@ -130,6 +130,20 @@ export const USDC_BNB_CHAIN = new Token( 'USDC', 'USDC' ) +export const USDC_BASE = new Token( + SupportedChainId.BASE, + '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', + 6, + 'USDC', + 'USD Coin' +) +export const USDC_BASE_GOERLI = new Token( + SupportedChainId.BASE, + '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', + 6, + 'USDC', + 'USD Coin' +) export const USDC: { [chainId in SupportedChainId]: Token } = { [SupportedChainId.MAINNET]: USDC_MAINNET, [SupportedChainId.ARBITRUM_ONE]: USDC_ARBITRUM, @@ -145,6 +159,8 @@ export const USDC: { [chainId in SupportedChainId]: Token } = { [SupportedChainId.KOVAN]: USDC_KOVAN, [SupportedChainId.ROPSTEN]: USDC_ROPSTEN, [SupportedChainId.BNB]: USDC_BNB_CHAIN, + [SupportedChainId.BASE]: USDC_BASE, + [SupportedChainId.BASE_GOERLI]: USDC_BASE_GOERLI, } export const DAI_POLYGON = new Token( SupportedChainId.POLYGON, @@ -407,6 +423,14 @@ export const DAI_BNB_CHAIN = new Token( 'DAI' ) +export const DAI_BASE = new Token( + SupportedChainId.BASE, + '0x50c5725949a6f0c72e6c4a641f24049a917db0cb', + 18, + 'DAI', + 'Dai Stablecoin' +) + function isBnbChain(chainId: number): chainId is SupportedChainId.BNB { return chainId === SupportedChainId.BNB } @@ -574,5 +598,6 @@ export const TOKEN_SHORTHANDS: { [shorthand: string]: { [chainId in SupportedCha [SupportedChainId.ROPSTEN]: USDC_ROPSTEN.address, [SupportedChainId.CELO]: PORTAL_USDC_CELO.address, [SupportedChainId.CELO_ALFAJORES]: USDC_CELO_ALFAJORES.address, + [SupportedChainId.BASE]: USDC_BASE.address, }, } diff --git a/src/utils/getExplorerLink.ts b/src/utils/getExplorerLink.ts index 4ad6ab6c4..148a928ff 100644 --- a/src/utils/getExplorerLink.ts +++ b/src/utils/getExplorerLink.ts @@ -13,6 +13,8 @@ const ETHERSCAN_PREFIXES: { [chainId: number]: string } = { [SupportedChainId.CELO]: 'https://celoscan.io', [SupportedChainId.CELO_ALFAJORES]: 'https://alfajores.celoscan.io', [SupportedChainId.BNB]: 'https://bscscan.com', + [SupportedChainId.BASE]: 'https://basescan.org/', + [SupportedChainId.BASE_GOERLI]: 'https://goerli.basescan.org/', } export enum ExplorerDataType {