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 gnosis chain #7454

Closed
wants to merge 2 commits into from
Closed
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: 10 additions & 0 deletions src/assets/svg/xdai_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const DEFAULT_CHAINS = [
ChainId.BNB,
ChainId.AVALANCHE,
ChainId.BASE,
ChainId.GNOSIS,
]

type UseMultiChainPositionsData = { positions?: PositionInfo[]; loading: boolean }
Expand Down
1 change: 1 addition & 0 deletions src/components/FeeSelector/shared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const FEE_AMOUNT_DETAIL: Record<
ChainId.POLYGON_MUMBAI,
ChainId.AVALANCHE,
ChainId.BASE,
ChainId.GNOSIS,
],
},
[FeeAmount.LOW]: {
Expand Down
7 changes: 7 additions & 0 deletions src/components/Logo/ChainLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ReactComponent as bnb } from './ChainSymbols/bnb.svg'
import { ReactComponent as celo } from './ChainSymbols/celo.svg'
import { ReactComponent as celoLight } from './ChainSymbols/celo_light.svg'
import { ReactComponent as ethereum } from './ChainSymbols/ethereum.svg'
import { ReactComponent as gnosis } from './ChainSymbols/gnosis.svg'
import { ReactComponent as optimism } from './ChainSymbols/optimism.svg'
import { ReactComponent as polygon } from './ChainSymbols/polygon.svg'

Expand Down Expand Up @@ -81,6 +82,12 @@ export function getChainUI(chainId: ChainId, darkMode: boolean): ChainUI | undef
bgColor: '#0052FF33',
textColor: '#0052FF',
}
case ChainId.GNOSIS:
return {
Symbol: gnosis,
bgColor: '#04795B33',
textColor: '#04795B',
}
default:
return undefined
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/Logo/ChainSymbols/gnosis.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/Tokens/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const SMALL_MEDIA_BREAKPOINT = '540px'
export const MOBILE_MEDIA_BREAKPOINT = '420px'

// includes chains that the backend does not current source off-chain metadata for
export const UNSUPPORTED_METADATA_CHAINS = [ChainId.BNB, ChainId.AVALANCHE]
export const UNSUPPORTED_METADATA_CHAINS = [ChainId.BNB, ChainId.AVALANCHE, ChainId.GNOSIS]
13 changes: 13 additions & 0 deletions src/constants/chainInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const START_BLOCKS: { [key: number]: number } = {
[ChainId.BNB]: 26324014,
[ChainId.AVALANCHE]: 31422450,
[ChainId.BASE]: 1371680,
[ChainId.GNOSIS]: 27416614,
}

export enum NetworkType {
Expand Down Expand Up @@ -224,6 +225,18 @@ const CHAIN_INFO: ChainInfoMap = {
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
color: darkTheme.chain_84531,
},
[ChainId.GNOSIS]: {
networkType: NetworkType.L1,
blockWaitMsBeforeWarning: ms(`10m`),
bridge: 'https://omnibridge.gnosischain.com/bridge',
docs: 'https://docs.gnosischain.com/',
explorer: 'https://gnosisscan.io/',
infoLink: 'https://info.uniswap.org/#/gnosis/',
label: 'Gnosis',
nativeCurrency: { name: 'Gnosis', symbol: 'xDAI', decimals: 18 },
color: darkTheme.chain_100,
backgroundColor: darkTheme.chain_100_background,
},
} as const

export function getChainInfo(
Expand Down
7 changes: 6 additions & 1 deletion src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const CHAIN_IDS_TO_NAMES = {
[ChainId.BNB]: 'bnb',
[ChainId.AVALANCHE]: 'avalanche',
[ChainId.BASE]: 'base',
[ChainId.GNOSIS]: 'gnosis',
} as const

// Include ChainIds in this array if they are not supported by the UX yet, but are already in the SDK.
Expand Down Expand Up @@ -53,6 +54,7 @@ export const SUPPORTED_GAS_ESTIMATE_CHAIN_IDS = [
ChainId.BNB,
ChainId.AVALANCHE,
ChainId.BASE,
ChainId.GNOSIS,
] as const

/**
Expand Down Expand Up @@ -82,6 +84,7 @@ export const L1_CHAIN_IDS = [
ChainId.CELO_ALFAJORES,
ChainId.BNB,
ChainId.AVALANCHE,
ChainId.GNOSIS,
] as const

export type SupportedL1ChainId = (typeof L1_CHAIN_IDS)[number]
Expand Down Expand Up @@ -129,8 +132,10 @@ export function getChainPriority(chainId: ChainId): number {
case ChainId.CELO:
case ChainId.CELO_ALFAJORES:
return 7
default:
case ChainId.GNOSIS:
return 8
default:
return 9
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/constants/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const COINGECKO_OPTIMISM_LIST = 'https://tokens.coingecko.com/optimistic-ethereu
const COINGECKO_CELO_LIST = 'https://tokens.coingecko.com/celo/all.json'
const COINGECKO_POLYGON_LIST = 'https://tokens.coingecko.com/polygon-pos/all.json'
const COINGECKO_AVAX_LIST = 'https://tokens.coingecko.com/avalanche/all.json'
const COINGECKO_GNOSIS_LIST = 'https://tokens.coingecko.com/xdai/all.json'
const COMPOUND_LIST = 'https://raw.githubusercontent.com/compound-finance/token-list/master/compound.tokenlist.json'
const GEMINI_LIST = 'https://www.gemini.com/uniswap/manifest.json'
const KLEROS_LIST = 't2crtokens.eth'
Expand Down Expand Up @@ -43,6 +44,7 @@ export const DEFAULT_INACTIVE_LIST_URLS: string[] = [
COINGECKO_CELO_LIST,
COINGECKO_POLYGON_LIST,
COINGECKO_AVAX_LIST,
COINGECKO_GNOSIS_LIST,
KLEROS_LIST,
GEMINI_LIST,
WRAPPED_LIST,
Expand Down
7 changes: 7 additions & 0 deletions src/constants/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ export const FALLBACK_URLS = {
'https://1rpc.io/base',
'https://base.meowrpc.com',
],
[ChainId.GNOSIS]: [
// "Safe" URLs
'https://rpc.gnosischain.com',
'https://rpc.gnosis.gateway.fm',
'https://rpc.ankr.com/gnosis',
],
}

/**
Expand Down Expand Up @@ -156,4 +162,5 @@ export const RPC_URLS = {
[ChainId.BNB]: [QUICKNODE_BNB_RPC_URL, ...FALLBACK_URLS[ChainId.BNB]],
[ChainId.AVALANCHE]: [`https://avalanche-mainnet.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[ChainId.AVALANCHE]],
[ChainId.BASE]: [`https://base-mainnet.infura.io/v3/${INFURA_KEY}`, ...FALLBACK_URLS[ChainId.BASE]],
[ChainId.GNOSIS]: FALLBACK_URLS[ChainId.GNOSIS],
}
2 changes: 2 additions & 0 deletions src/constants/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const RPC_PROVIDERS: { [key in SupportedInterfaceChain]: StaticJsonRpcPro
[ChainId.BNB]: providerFactory(ChainId.BNB),
[ChainId.AVALANCHE]: providerFactory(ChainId.AVALANCHE),
[ChainId.BASE]: providerFactory(ChainId.BASE),
[ChainId.GNOSIS]: providerFactory(ChainId.GNOSIS),
}

export const DEPRECATED_RPC_PROVIDERS: { [key in SupportedInterfaceChain]: AppStaticJsonRpcProvider } = {
Expand All @@ -47,4 +48,5 @@ export const DEPRECATED_RPC_PROVIDERS: { [key in SupportedInterfaceChain]: AppSt
[ChainId.BNB]: providerFactory(ChainId.BNB),
[ChainId.AVALANCHE]: providerFactory(ChainId.AVALANCHE),
[ChainId.BASE]: providerFactory(ChainId.BASE),
[ChainId.GNOSIS]: providerFactory(ChainId.GNOSIS),
}
12 changes: 12 additions & 0 deletions src/constants/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ import {
USDC_AVALANCHE,
USDC_BASE,
USDC_BSC,
USDC_GNOSIS,
USDC_MAINNET,
USDC_OPTIMISM,
USDC_POLYGON,
USDT,
USDT_ARBITRUM_ONE,
USDT_AVALANCHE,
USDT_BSC,
USDT_GNOSIS,
USDT_OPTIMISM,
USDT_POLYGON,
WBTC,
WBTC_ARBITRUM_ONE,
WBTC_CELO,
WBTC_GNOSIS,
WBTC_OPTIMISM,
WBTC_POLYGON,
WETH_AVALANCHE,
WETH_GNOSIS,
WETH_POLYGON,
WETH_POLYGON_MUMBAI,
WRAPPED_NATIVE_CURRENCY,
Expand Down Expand Up @@ -115,6 +119,7 @@ export const COMMON_BASES: ChainCurrencyList = {
USDT_AVALANCHE,
WETH_AVALANCHE,
],
[ChainId.GNOSIS]: [nativeOnChain(ChainId.GNOSIS), USDC_GNOSIS, USDT_GNOSIS, WETH_GNOSIS, WBTC_GNOSIS],
}

// used to construct the list of all pairs we consider by default in the frontend
Expand All @@ -137,6 +142,13 @@ export const BASES_TO_TRACK_LIQUIDITY_FOR: ChainTokenList = {
USDT_AVALANCHE,
WETH_AVALANCHE,
],
[ChainId.GNOSIS]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[ChainId.GNOSIS],
USDC_GNOSIS,
USDT_GNOSIS,
WETH_GNOSIS,
WBTC_GNOSIS,
],
}
export const PINNED_PAIRS: { readonly [chainId: number]: [Token, Token][] } = {
[ChainId.MAINNET]: [
Expand Down
55 changes: 55 additions & 0 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,29 @@ export const DAI_AVALANCHE = new Token(
'Dai.e Token'
)

export const USDC_GNOSIS = new Token(ChainId.GNOSIS, '0xddafbb505ad214d7b80b1f830fccc89b60fb7a83', 6, 'USDC', 'USD//C')
export const USDT_GNOSIS = new Token(
ChainId.GNOSIS,
'0x4ecaba5870353805a9f068101a40e0f32ed605c6',
6,
'USDT',
'Tether USD'
)
export const WETH_GNOSIS = new Token(
ChainId.GNOSIS,
'0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1',
18,
'WETH',
'Wrapped Ether'
)
export const WBTC_GNOSIS = new Token(
ChainId.GNOSIS,
'0x8e5bbbb09ed1ebde8674cda39a0c169401db4252',
8,
'WBT',
'Wrapped BTC'
)

export const UNI: { [chainId: number]: Token } = {
[ChainId.MAINNET]: new Token(ChainId.MAINNET, UNI_ADDRESSES[ChainId.MAINNET], 18, 'UNI', 'Uniswap'),
[ChainId.GOERLI]: new Token(ChainId.GOERLI, UNI_ADDRESSES[ChainId.GOERLI], 18, 'UNI', 'Uniswap'),
Expand Down Expand Up @@ -336,6 +359,13 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } =
'WAVAX',
'Wrapped AVAX'
),
[ChainId.GNOSIS]: new Token(
ChainId.GNOSIS,
'0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
18,
'WXDAI',
'Wrapped XDAI'
),
}

export function isCelo(chainId: number): chainId is ChainId.CELO | ChainId.CELO_ALFAJORES {
Expand Down Expand Up @@ -419,6 +449,28 @@ class AvaxNativeCurrency extends NativeCurrency {
}
}

export function isGnosis(chainId: number): chainId is ChainId.GNOSIS {
return chainId === ChainId.GNOSIS
}

class GnosisNativeCurrency extends NativeCurrency {
equals(other: Currency): boolean {
return other.isNative && other.chainId === this.chainId
}

get wrapped(): Token {
if (!isGnosis(this.chainId)) throw new Error('Not gnosis')
const wrapped = WRAPPED_NATIVE_CURRENCY[this.chainId]
invariant(wrapped instanceof Token)
return wrapped
}

public constructor(chainId: number) {
if (!isGnosis(chainId)) throw new Error('Not gnosis')
super(chainId, 18, 'xDAI', 'xDAI')
}
}

class ExtendedEther extends Ether {
public get wrapped(): Token {
const wrapped = WRAPPED_NATIVE_CURRENCY[this.chainId]
Expand All @@ -445,6 +497,8 @@ export function nativeOnChain(chainId: number): NativeCurrency | Token {
nativeCurrency = new BscNativeCurrency(chainId)
} else if (isAvalanche(chainId)) {
nativeCurrency = new AvaxNativeCurrency(chainId)
} else if (isGnosis(chainId)) {
nativeCurrency = new GnosisNativeCurrency(chainId)
} else {
nativeCurrency = ExtendedEther.onChain(chainId)
}
Expand Down Expand Up @@ -473,5 +527,6 @@ export const TOKEN_SHORTHANDS: { [shorthand: string]: { [chainId in ChainId]?: s
[ChainId.GOERLI]: USDC_GOERLI.address,
[ChainId.SEPOLIA]: USDC_SEPOLIA.address,
[ChainId.AVALANCHE]: USDC_AVALANCHE.address,
[ChainId.GNOSIS]: USDC_GNOSIS.address,
},
}
3 changes: 3 additions & 0 deletions src/graphql/data/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const GQL_MAINNET_CHAINS = [
Chain.Bnb,
Chain.Avalanche,
Chain.Base,
Chain.Gnosis,
] as const

const GQL_TESTNET_CHAINS = [Chain.EthereumGoerli, Chain.EthereumSepolia] as const
Expand All @@ -88,6 +89,7 @@ export const CHAIN_ID_TO_BACKEND_NAME: { [key: number]: InterfaceGqlChain } = {
[ChainId.BNB]: Chain.Bnb,
[ChainId.AVALANCHE]: Chain.Avalanche,
[ChainId.BASE]: Chain.Base,
[ChainId.GNOSIS]: Chain.Gnosis,
}

export function chainIdToBackendName(chainId: number | undefined) {
Expand Down Expand Up @@ -164,6 +166,7 @@ const CHAIN_NAME_TO_CHAIN_ID: { [key in InterfaceGqlChain]: ChainId } = {
[Chain.Bnb]: ChainId.BNB,
[Chain.Avalanche]: ChainId.AVALANCHE,
[Chain.Base]: ChainId.BASE,
[Chain.Gnosis]: ChainId.GNOSIS,
}

export function isSupportedGQLChain(chain: Chain): chain is InterfaceGqlChain {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useStablecoinPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const STABLECOIN_AMOUNT_OUT: { [chainId: number]: CurrencyAmount<Token> } = {
[ChainId.CELO]: CurrencyAmount.fromRawAmount(CUSD_CELO, 10_000e18),
[ChainId.BNB]: CurrencyAmount.fromRawAmount(USDT_BSC, 100e18),
[ChainId.AVALANCHE]: CurrencyAmount.fromRawAmount(USDC_AVALANCHE, 10_000e6),
[ChainId.GNOSIS]: CurrencyAmount.fromRawAmount(USDC_AVALANCHE, 10_000e6),
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/lib/hooks/useCurrencyLogoURIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import AvaxLogo from '../../assets/svg/avax_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 GnosisLogo from '../../assets/svg/xdai_logo.svg'
import { isCelo, NATIVE_CHAIN_ID, nativeOnChain } from '../../constants/tokens'

type Network = 'ethereum' | 'arbitrum' | 'optimism' | 'polygon' | 'smartchain' | 'celo' | 'avalanchec'
type Network = 'ethereum' | 'arbitrum' | 'optimism' | 'polygon' | 'smartchain' | 'celo' | 'avalanchec' | 'gnosis'

export function chainIdToNetworkName(networkId: ChainId): Network {
switch (networkId) {
Expand All @@ -28,6 +29,8 @@ export function chainIdToNetworkName(networkId: ChainId): Network {
return 'celo'
case ChainId.AVALANCHE:
return 'avalanchec'
case ChainId.GNOSIS:
return 'gnosis'
default:
return 'ethereum'
}
Expand All @@ -45,6 +48,8 @@ export function getNativeLogoURI(chainId: ChainId = ChainId.MAINNET): string {
return CeloLogo
case ChainId.AVALANCHE:
return AvaxLogo
case ChainId.GNOSIS:
return GnosisLogo
default:
return EthereumLogo
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/state/multicall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function getBlocksPerFetchForChainId(chainId: number | undefined): number {
case ChainId.CELO:
case ChainId.CELO_ALFAJORES:
return 5
case ChainId.GNOSIS:
return 2
default:
return 1
}
Expand Down
1 change: 1 addition & 0 deletions src/state/routing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ export enum SwapRouterNativeAssets {
BNB = 'BNB',
AVAX = 'AVAX',
ETH = 'ETH',
XDAI = 'xDAI',
}

export enum URAQuoteType {
Expand Down
3 changes: 2 additions & 1 deletion src/state/routing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Currency, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core'
import { DutchOrderInfo, DutchOrderInfoJSON } from '@uniswap/uniswapx-sdk'
import { Pair, Route as V2Route } from '@uniswap/v2-sdk'
import { FeeAmount, Pool, Route as V3Route } from '@uniswap/v3-sdk'
import { isAvalanche, isBsc, isMatic, nativeOnChain } from 'constants/tokens'
import { isAvalanche, isBsc, isGnosis, isMatic, nativeOnChain } from 'constants/tokens'
import { toSlippagePercent } from 'utils/slippage'

import { getApproveInfo, getWrapInfo } from './gas'
Expand Down Expand Up @@ -318,6 +318,7 @@ export function currencyAddressForSwapQuote(currency: Currency): string {
if (isMatic(currency.chainId)) return SwapRouterNativeAssets.MATIC
if (isBsc(currency.chainId)) return SwapRouterNativeAssets.BNB
if (isAvalanche(currency.chainId)) return SwapRouterNativeAssets.AVAX
if (isGnosis(currency.chainId)) return SwapRouterNativeAssets.XDAI
return SwapRouterNativeAssets.ETH
}

Expand Down
Loading
Loading