Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Base support to Uniswap widget #619

Merged
merged 10 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
"@uniswap/permit2-sdk": "^1.2.0",
"@uniswap/redux-multicall": "^1.1.8",
"@uniswap/router-sdk": "^1.6.0",
"@uniswap/sdk-core": "^4.0.6",
"@uniswap/smart-order-router": "^3.13.7",
"@uniswap/sdk-core": "^4.0.7",
"@uniswap/smart-order-router": "^3.16.25",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, i was about to comment but you found it 👍

"@uniswap/token-lists": "^1.0.0-beta.30",
"@uniswap/universal-router-sdk": "^1.5.6",
"@uniswap/v2-sdk": "^3.2.0",
"@uniswap/universal-router-sdk": "^1.5.7",
"@uniswap/v2-sdk": "^3.2.1",
"@uniswap/v3-sdk": "^3.10.0",
"@web3-react/core": "^8.2.0",
"@web3-react/eip1193": "^8.2.0",
Expand Down Expand Up @@ -166,7 +166,7 @@
"@types/wcag-contrast": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"@uniswap/default-token-list": "^9.0.0",
"@uniswap/default-token-list": "^11.6.0",
"@uniswap/v2-core": "1.0.0",
"@uniswap/v3-core": "1.0.0",
"@uniswap/v3-periphery": "^1.1.1",
Expand Down
11 changes: 11 additions & 0 deletions src/assets/svg/base_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/components/Logo/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { SupportedChainId } from 'constants/chains'
import { isAddress } from 'utils'

import EthereumLogo from '../../assets/images/ethereum-logo.png'
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 MaticLogo from '../../assets/svg/matic-token-icon.svg'
import { LogoTableInput } from './LogoTable'

type Network = 'ethereum' | 'arbitrum' | 'optimism' | 'polygon' | 'celo' | 'smartchain'
type Network = 'ethereum' | 'arbitrum' | 'optimism' | 'polygon' | 'celo' | 'smartchain' | 'base'

function chainIdToNetworkName(networkId: SupportedChainId): Network | undefined {
switch (networkId) {
Expand All @@ -23,6 +24,8 @@ function chainIdToNetworkName(networkId: SupportedChainId): Network | undefined
return 'celo'
case SupportedChainId.BNB:
return 'smartchain'
case SupportedChainId.BASE:
return 'base'
default:
return 'ethereum'
}
Expand Down Expand Up @@ -51,6 +54,8 @@ export function getNativeLogoURI(chainId: SupportedChainId = SupportedChainId.MA
return CeloLogo
case SupportedChainId.BNB:
return BnbLogo
case SupportedChainId.BASE:
return BaseLogo
default:
return EthereumLogo
}
Expand Down
2 changes: 2 additions & 0 deletions src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const MULTICALL_ADDRESS: AddressMap = {
[SupportedChainId.ARBITRUM_RINKEBY]: '0xa501c031958F579dB7676fF1CE78AD305794d579',
[SupportedChainId.CELO]: '0x633987602DE5C4F337e3DbF265303A1080324204',
[SupportedChainId.CELO_ALFAJORES]: '0x633987602DE5C4F337e3DbF265303A1080324204',
[SupportedChainId.BASE]: '0x091e99cb1C49331a94dD62755D168E941AbD0693',
}

export const SWAP_ROUTER_ADDRESSES: AddressMap = {
Expand All @@ -29,6 +30,7 @@ export const SWAP_ROUTER_ADDRESSES: AddressMap = {
]),
[SupportedChainId.CELO]: '0x5615CDAb10dc425a742d643d949a7F474C01abc4',
[SupportedChainId.CELO_ALFAJORES]: '0x5615CDAb10dc425a742d643d949a7F474C01abc4',
[SupportedChainId.BASE]: '0x2626664c2603336E57B271c5C0b26F421741e481',
}

export const ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap = {
Expand Down
14 changes: 14 additions & 0 deletions src/constants/chainInfo.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -237,6 +238,19 @@ const CHAIN_INFO: ChainInfoMap = {
color: '#F0B90B',
backgroundColor: '#F0B90B',
},
[SupportedChainId.BASE]: {
networkType: NetworkType.L2,
blockWaitMsBeforeWarning: ms`25m`,
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',
},
}

export function getChainInfo(chainId: SupportedL1ChainId): L1ChainInfo
Expand Down
6 changes: 6 additions & 0 deletions src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export enum SupportedChainId {
CELO_ALFAJORES = 44787,

BNB = 56,

BASE = 8453,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some point our team might remove this enum entirely, like i started to do in #615 but for now this works

}

export enum ChainName {
Expand All @@ -38,6 +40,7 @@ export enum ChainName {
CELO = 'celo',
CELO_ALFAJORES = 'celo-alfajores',
BNB = 'bnb',
BASE = 'base',
}

export const CHAIN_NAMES_TO_IDS: { [chainName: string]: SupportedChainId } = {
Expand All @@ -55,6 +58,7 @@ 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,
}

/**
Expand All @@ -71,6 +75,7 @@ export const SUPPORTED_GAS_ESTIMATE_CHAIN_IDS = [
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.CELO,
SupportedChainId.BNB,
SupportedChainId.BASE,
]

/**
Expand Down Expand Up @@ -99,6 +104,7 @@ export const L2_CHAIN_IDS = [
SupportedChainId.ARBITRUM_RINKEBY,
SupportedChainId.OPTIMISM,
SupportedChainId.OPTIMISM_GOERLI,
SupportedChainId.BASE,
] as const

export type SupportedL2ChainId = typeof L2_CHAIN_IDS[number]
Expand Down
9 changes: 9 additions & 0 deletions src/constants/jsonRpcEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,13 @@ export const JSON_RPC_FALLBACK_ENDPOINTS: Record<SupportedChainId, string[]> = {
'https://bsc-dataseed4.defibit.io',
'https://rpc.ankr.com/bsc',
],
[SupportedChainId.BASE]: [
// "Safe" URLs
'https://mainnet.base.org',
'https://base.gateway.tenderly.co',
'https://base.publicnode.com',
// "Fallback" URLs
'https://1rpc.io/base',
'https://base.meowrpc.com',
],
}
3 changes: 3 additions & 0 deletions src/constants/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CUSD_CELO,
DAI,
DAI_ARBITRUM_ONE,
DAI_BASE,
DAI_OPTIMISM,
DAI_POLYGON,
ETH2X_FLI,
Expand All @@ -23,6 +24,7 @@ import {
sETH2,
SWISE,
TRIBE,
USDC_BASE,
USDC_BNB_CHAIN,
USDC_MAINNET,
USDC_POLYGON,
Expand Down Expand Up @@ -92,6 +94,7 @@ 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]: {
Expand Down
24 changes: 24 additions & 0 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ 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: { [chainId in SupportedChainId]: Token } = {
[SupportedChainId.MAINNET]: USDC_MAINNET,
[SupportedChainId.ARBITRUM_ONE]: USDC_ARBITRUM,
Expand All @@ -145,6 +152,7 @@ export const USDC: { [chainId in SupportedChainId]: Token } = {
[SupportedChainId.KOVAN]: USDC_KOVAN,
[SupportedChainId.ROPSTEN]: USDC_ROPSTEN,
[SupportedChainId.BNB]: USDC_BNB_CHAIN,
[SupportedChainId.BASE]: USDC_BASE,
}
export const DAI_POLYGON = new Token(
SupportedChainId.POLYGON,
Expand Down Expand Up @@ -407,6 +415,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
}
Expand Down Expand Up @@ -490,6 +506,13 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } =
'WBNB',
'Wrapped BNB'
),
[SupportedChainId.BASE]: new Token(
SupportedChainId.BASE,
'0x4200000000000000000000000000000000000006',
18,
'WETH',
'Wrapped Ether'
),
}

export function isCelo(chainId: number): chainId is SupportedChainId.CELO | SupportedChainId.CELO_ALFAJORES {
Expand Down Expand Up @@ -574,5 +597,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,
},
}
1 change: 1 addition & 0 deletions src/hooks/transactions/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const RETRY_OPTIONS_BY_CHAIN_ID: { [chainId: number]: RetryOptions } = {
[SupportedChainId.ARBITRUM_RINKEBY]: { n: 10, minWait: 250, maxWait: 1000 },
[SupportedChainId.OPTIMISM_GOERLI]: { n: 10, minWait: 250, maxWait: 1000 },
[SupportedChainId.OPTIMISM]: { n: 10, minWait: 250, maxWait: 1000 },
[SupportedChainId.BASE]: { n: 10, minWait: 250, maxWait: 1000 },
}
const DEFAULT_RETRY_OPTIONS: RetryOptions = { n: 1, minWait: 0, maxWait: 0 }

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useStablecoinAmountFromFiatValue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CurrencyAmount, Token } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { SupportedChainId } from 'constants/chains'
import { CUSD_CELO, DAI_OPTIMISM, USDC_ARBITRUM, USDC_MAINNET, USDC_POLYGON } from 'constants/tokens'
import { CUSD_CELO, DAI_OPTIMISM, USDC_ARBITRUM, USDC_BASE, USDC_MAINNET, USDC_POLYGON } from 'constants/tokens'
import { useMemo } from 'react'
import tryParseCurrencyAmount from 'utils/tryParseCurrencyAmount'

Expand All @@ -13,6 +13,7 @@ export const STABLECOIN_AMOUNT_OUT: { [chainId: number]: CurrencyAmount<Token> }
[SupportedChainId.OPTIMISM]: CurrencyAmount.fromRawAmount(DAI_OPTIMISM, 10_000e18),
[SupportedChainId.POLYGON]: CurrencyAmount.fromRawAmount(USDC_POLYGON, 10_000e6),
[SupportedChainId.CELO]: CurrencyAmount.fromRawAmount(CUSD_CELO, 10_000e18),
[SupportedChainId.BASE]: CurrencyAmount.fromRawAmount(USDC_BASE, 10_000e6),
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/hooks/web3/useJsonRpcUrlsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function toJsonRpcMap<T>(getChainConnections: (chainId: SupportedChainId) => T):
[SupportedChainId.CELO]: getChainConnections(SupportedChainId.CELO),
[SupportedChainId.CELO_ALFAJORES]: getChainConnections(SupportedChainId.CELO_ALFAJORES),
[SupportedChainId.BNB]: getChainConnections(SupportedChainId.BNB),
[SupportedChainId.BASE]: getChainConnections(SupportedChainId.BASE),
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/utils/getExplorerLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ describe('#getExplorerLink', () => {
it('bnb chain', () => {
expect(getExplorerLink(56, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://bscscan.com/address/abc')
})
it('base', () => {
expect(getExplorerLink(8453, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://basescan.org/address/abc')
})
})
1 change: 1 addition & 0 deletions src/utils/getExplorerLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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',
}

export enum ExplorerDataType {
Expand Down
Loading
Loading