From ac01e8d4f761844621cdffb5f05ab38081b77c39 Mon Sep 17 00:00:00 2001 From: Philippe Schommers Date: Sat, 3 Feb 2024 14:53:13 +0100 Subject: [PATCH 1/2] feat: add Gnosis Chain --- src/assets/svg/gnosis_logo.svg | 6 ++ src/assets/svg/xdai_logo.svg | 10 ++++ src/components/FeeSelector/shared.tsx | 4 +- .../NavBar/ChainSelectorRow.test.tsx | 3 +- src/constants/chainInfo.ts | 26 ++++++++- src/constants/chains.test.ts | 1 + src/constants/chains.ts | 12 +++- src/constants/lists.ts | 2 + src/constants/networks.ts | 7 +++ src/constants/providers.ts | 1 + src/constants/routing.ts | 11 ++++ src/constants/tokens.ts | 55 +++++++++++++++++++ src/hooks/useStablecoinPrice.ts | 1 + src/lib/hooks/useCurrencyLogoURIs.ts | 7 ++- src/lib/state/multicall.tsx | 2 + src/state/routing/types.ts | 1 + src/state/routing/utils.ts | 3 +- src/state/transactions/hooks.tsx | 3 +- src/theme/colors.ts | 3 + .../RadialGradientByChainUpdater.ts | 9 +++ src/types/types-and-hooks.ts | 1 + src/utils/getExplorerLink.test.ts | 5 ++ src/utils/getExplorerLink.ts | 1 + 23 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 src/assets/svg/gnosis_logo.svg create mode 100644 src/assets/svg/xdai_logo.svg diff --git a/src/assets/svg/gnosis_logo.svg b/src/assets/svg/gnosis_logo.svg new file mode 100644 index 00000000000..b2f54c40d1e --- /dev/null +++ b/src/assets/svg/gnosis_logo.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/assets/svg/xdai_logo.svg b/src/assets/svg/xdai_logo.svg new file mode 100644 index 00000000000..4a958dca209 --- /dev/null +++ b/src/assets/svg/xdai_logo.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/components/FeeSelector/shared.tsx b/src/components/FeeSelector/shared.tsx index b2ca763bc30..8e4730c2ed0 100644 --- a/src/components/FeeSelector/shared.tsx +++ b/src/components/FeeSelector/shared.tsx @@ -1,6 +1,7 @@ import { Trans } from '@lingui/macro' -import { ChainId, SUPPORTED_CHAINS } from '@uniswap/sdk-core' +import { ChainId } from '@uniswap/sdk-core' import { FeeAmount } from '@uniswap/v3-sdk' +import { SUPPORTED_CHAINS } from 'constants/chains' import type { ReactNode } from 'react' export const FEE_AMOUNT_DETAIL: Record< @@ -21,6 +22,7 @@ export const FEE_AMOUNT_DETAIL: Record< ChainId.POLYGON_MUMBAI, ChainId.AVALANCHE, ChainId.BASE, + ChainId.GNOSIS, ], }, [FeeAmount.LOW]: { diff --git a/src/components/NavBar/ChainSelectorRow.test.tsx b/src/components/NavBar/ChainSelectorRow.test.tsx index 46c82d6dedc..7aecd4a2fb9 100644 --- a/src/components/NavBar/ChainSelectorRow.test.tsx +++ b/src/components/NavBar/ChainSelectorRow.test.tsx @@ -1,4 +1,5 @@ -import { ChainId, SUPPORTED_CHAINS } from '@uniswap/sdk-core' +import { ChainId } from '@uniswap/sdk-core' +import { SUPPORTED_CHAINS } from 'constants/chains' import { render } from 'test-utils/render' import ChainSelectorRow from './ChainSelectorRow' diff --git a/src/constants/chainInfo.ts b/src/constants/chainInfo.ts index 40bacacd642..8c974d08397 100644 --- a/src/constants/chainInfo.ts +++ b/src/constants/chainInfo.ts @@ -11,6 +11,7 @@ import bnbSquareLogoUrl from 'assets/svg/bnb_square_logo.svg' import bnbLogo from 'assets/svg/bnb-logo.svg' import celoLogo from 'assets/svg/celo_logo.svg' import celoSquareLogoUrl from 'assets/svg/celo_square_logo.svg' +import gnosisLogo from 'assets/svg/gnosis_logo.svg' import optimismSquareLogoUrl from 'assets/svg/optimism_square_logo.svg' import optimismLogoUrl from 'assets/svg/optimistic_ethereum.svg' import polygonSquareLogoUrl from 'assets/svg/polygon_square_logo.svg' @@ -19,7 +20,15 @@ import ms from 'ms' import { darkTheme } from 'theme/colors' import { SupportedL1ChainId, SupportedL2ChainId } from './chains' -import { ARBITRUM_LIST, AVALANCHE_LIST, BASE_LIST, CELO_LIST, OPTIMISM_LIST, PLASMA_BNB_LIST } from './lists' +import { + ARBITRUM_LIST, + AVALANCHE_LIST, + BASE_LIST, + CELO_LIST, + GNOSIS_LIST, + OPTIMISM_LIST, + PLASMA_BNB_LIST, +} from './lists' export const AVERAGE_L1_BLOCK_TIME = ms(`12s`) @@ -259,6 +268,21 @@ 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', + defaultListUrl: GNOSIS_LIST, + 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, + circleLogoUrl: gnosisLogo, + logoUrl: gnosisLogo, + }, } as const export function getChainInfo(chainId: SupportedL1ChainId): L1ChainInfo diff --git a/src/constants/chains.test.ts b/src/constants/chains.test.ts index 04d4201c070..07f050bc801 100644 --- a/src/constants/chains.test.ts +++ b/src/constants/chains.test.ts @@ -18,6 +18,7 @@ const chainPriorityTestCases: [ChainId, number][] = [ [ChainId.AVALANCHE, 6], [ChainId.CELO, 7], [ChainId.CELO_ALFAJORES, 7], + [ChainId.GNOSIS, 8], ] test.each(chainPriorityTestCases)( diff --git a/src/constants/chains.ts b/src/constants/chains.ts index 41992c0a67a..6e2d9176c05 100644 --- a/src/constants/chains.ts +++ b/src/constants/chains.ts @@ -1,4 +1,7 @@ -import { ChainId, SUPPORTED_CHAINS, SupportedChainsType } from '@uniswap/sdk-core' +import { ChainId, SUPPORTED_CHAINS as UNISWAP_SUPPORTED_CHAINS } from '@uniswap/sdk-core' + +export const SUPPORTED_CHAINS = [...UNISWAP_SUPPORTED_CHAINS, ChainId.GNOSIS] as const +declare type SupportedChainsType = (typeof SUPPORTED_CHAINS)[number] export const CHAIN_IDS_TO_NAMES = { [ChainId.MAINNET]: 'mainnet', @@ -15,6 +18,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. @@ -41,6 +45,7 @@ export const SUPPORTED_GAS_ESTIMATE_CHAIN_IDS = [ ChainId.BNB, ChainId.AVALANCHE, ChainId.BASE, + ChainId.GNOSIS, ] as const /** @@ -70,6 +75,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] @@ -117,7 +123,9 @@ export function getChainPriority(chainId: ChainId): number { case ChainId.CELO: case ChainId.CELO_ALFAJORES: return 7 - default: + case ChainId.GNOSIS: return 8 + default: + return 9 } } diff --git a/src/constants/lists.ts b/src/constants/lists.ts index 780a85626a8..cae15412521 100644 --- a/src/constants/lists.ts +++ b/src/constants/lists.ts @@ -24,6 +24,7 @@ export const AVALANCHE_LIST = 'https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/token_list.json' export const BASE_LIST = 'https://raw.githubusercontent.com/ethereum-optimism/ethereum-optimism.github.io/master/optimism.tokenlist.json' +export const GNOSIS_LIST = 'https://raw.githubusercontent.com/cowprotocol/token-lists/main/src/public/CowSwap.json' // default lists to be 'active' aka searched across export const DEFAULT_ACTIVE_LIST_URLS: string[] = [UNI_LIST] @@ -49,6 +50,7 @@ export const DEFAULT_INACTIVE_LIST_URLS: string[] = [ PLASMA_BNB_LIST, AVALANCHE_LIST, BASE_LIST, + GNOSIS_LIST, ] export const DEFAULT_LIST_OF_LISTS: string[] = [...DEFAULT_ACTIVE_LIST_URLS, ...DEFAULT_INACTIVE_LIST_URLS] diff --git a/src/constants/networks.ts b/src/constants/networks.ts index 1b74095dcf2..9940241d92c 100644 --- a/src/constants/networks.ts +++ b/src/constants/networks.ts @@ -105,6 +105,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', + ], } /** @@ -126,4 +132,5 @@ export const RPC_URLS = { [ChainId.BNB]: [...FALLBACK_URLS[ChainId.BNB]], [ChainId.AVALANCHE]: [...FALLBACK_URLS[ChainId.AVALANCHE]], [ChainId.BASE]: [...FALLBACK_URLS[ChainId.BASE]], + [ChainId.GNOSIS]: FALLBACK_URLS[ChainId.GNOSIS], } diff --git a/src/constants/providers.ts b/src/constants/providers.ts index b6ae97472fe..102ae55f3e7 100644 --- a/src/constants/providers.ts +++ b/src/constants/providers.ts @@ -30,4 +30,5 @@ 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), } diff --git a/src/constants/routing.ts b/src/constants/routing.ts index 283e8a238eb..8316b746628 100644 --- a/src/constants/routing.ts +++ b/src/constants/routing.ts @@ -25,6 +25,7 @@ import { USDC_AVALANCHE, USDC_BASE, USDC_BSC, + USDC_GNOSIS, USDC_MAINNET, USDC_OPTIMISM, USDC_POLYGON, @@ -32,14 +33,17 @@ import { 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, @@ -137,6 +141,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]: [ diff --git a/src/constants/tokens.ts b/src/constants/tokens.ts index 494493013fd..b370146faec 100644 --- a/src/constants/tokens.ts +++ b/src/constants/tokens.ts @@ -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'), @@ -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 { @@ -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] @@ -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) } @@ -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, }, } diff --git a/src/hooks/useStablecoinPrice.ts b/src/hooks/useStablecoinPrice.ts index 9619b37fb96..3a7eb026747 100644 --- a/src/hooks/useStablecoinPrice.ts +++ b/src/hooks/useStablecoinPrice.ts @@ -25,6 +25,7 @@ const STABLECOIN_AMOUNT_OUT: { [chainId: number]: CurrencyAmount } = { [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), } /** diff --git a/src/lib/hooks/useCurrencyLogoURIs.ts b/src/lib/hooks/useCurrencyLogoURIs.ts index f3e693b22ee..0cc8e2685b3 100644 --- a/src/lib/hooks/useCurrencyLogoURIs.ts +++ b/src/lib/hooks/useCurrencyLogoURIs.ts @@ -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) { @@ -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' } @@ -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 } diff --git a/src/lib/state/multicall.tsx b/src/lib/state/multicall.tsx index 354211b0676..cc206ef0743 100644 --- a/src/lib/state/multicall.tsx +++ b/src/lib/state/multicall.tsx @@ -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 } diff --git a/src/state/routing/types.ts b/src/state/routing/types.ts index afc79feb419..3a61ef1e52a 100644 --- a/src/state/routing/types.ts +++ b/src/state/routing/types.ts @@ -348,6 +348,7 @@ export enum SwapRouterNativeAssets { BNB = 'BNB', AVAX = 'AVAX', ETH = 'ETH', + XDAI = 'xDAI', } export enum URAQuoteType { diff --git a/src/state/routing/utils.ts b/src/state/routing/utils.ts index f4d914584b0..ebc6949f111 100644 --- a/src/state/routing/utils.ts +++ b/src/state/routing/utils.ts @@ -3,7 +3,7 @@ import { MixedRouteSDK } from '@uniswap/router-sdk' import { Currency, CurrencyAmount, Token } from '@uniswap/sdk-core' 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 { getApproveInfo } from './gas' import { @@ -226,6 +226,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 } diff --git a/src/state/transactions/hooks.tsx b/src/state/transactions/hooks.tsx index 6a1e84eec3f..7002ccf4b41 100644 --- a/src/state/transactions/hooks.tsx +++ b/src/state/transactions/hooks.tsx @@ -1,8 +1,9 @@ import { BigNumber } from '@ethersproject/bignumber' import type { TransactionResponse } from '@ethersproject/providers' -import { ChainId, SUPPORTED_CHAINS, Token } from '@uniswap/sdk-core' +import { ChainId, Token } from '@uniswap/sdk-core' import { useWeb3React } from '@web3-react/core' import { getTransactionStatus } from 'components/AccountDrawer/MiniPortfolio/Activity/parseLocal' +import { SUPPORTED_CHAINS } from 'constants/chains' import { SwapResult } from 'hooks/useSwapCallback' import { useCallback, useMemo } from 'react' import { useAppDispatch, useAppSelector } from 'state/hooks' diff --git a/src/theme/colors.ts b/src/theme/colors.ts index 8e45b09a8aa..243b32a0400 100644 --- a/src/theme/colors.ts +++ b/src/theme/colors.ts @@ -97,6 +97,7 @@ export const colors = { networkPolygonSoft: 'rgba(164, 87, 255, 0.16)', networkEthereumSoft: 'rgba(98, 126, 234, 0.16)', networkBase: '#0052FF', + networkGnosis: '#04795B', //NEW COLORS FOR SPORE - need to define light/dark here cause they are root colors now (different system) neutral1_dark: '#FFFFFF', neutral2_dark: '#9B9B9B', @@ -134,6 +135,7 @@ const commonTheme = { chain_4: colors.pink400, chain_5: colors.green400, chain_10: colors.networkOptimism, + chain_100: colors.networkGnosis, chain_137: colors.networkPolygon, chain_42: colors.networkArbitrum, chain_56: colors.networkBsc, @@ -144,6 +146,7 @@ const commonTheme = { chain_43114: colors.networkOptimism, chain_137_background: colors.purple900, chain_10_background: colors.red900, + chain_100_background: colors.green700, chain_43114_background: colors.red900, chain_42161_background: colors.blue900, chain_84531: colors.networkBase, diff --git a/src/theme/components/RadialGradientByChainUpdater.ts b/src/theme/components/RadialGradientByChainUpdater.ts index 200311e6540..b24a9f58023 100644 --- a/src/theme/components/RadialGradientByChainUpdater.ts +++ b/src/theme/components/RadialGradientByChainUpdater.ts @@ -110,6 +110,15 @@ export default function RadialGradientByChainUpdater(): null { backgroundRadialGradientElement.style.background = darkMode ? baseDarkGradient : baseLightGradient break } + case ChainId.GNOSIS: { + setBackground(backgroundResetStyles) + const gnosisightGradient = + 'radial-gradient(100% 100% at 50% 0%, rgba(0, 82, 255, 0) 0%, rgba(0, 82, 255, 0) 40.0%, rgba(252, 255, 82, 0.00) 100%), rgb(255, 255, 255)' + const gnosisDarkGradient = + 'radial-gradient(100% 100% at 50% 0%, rgba(10, 41, 75, 0) 0%, rgba(0, 82, 255, 0) 40%, rgba(0, 82, 255, 0) 100%), rgb(13, 14, 14)' + backgroundRadialGradientElement.style.background = darkMode ? gnosisDarkGradient : gnosisightGradient + break + } default: { setDefaultBackground(backgroundRadialGradientElement, darkMode) } diff --git a/src/types/types-and-hooks.ts b/src/types/types-and-hooks.ts index 6b57de988a0..85885254cea 100644 --- a/src/types/types-and-hooks.ts +++ b/src/types/types-and-hooks.ts @@ -188,6 +188,7 @@ export enum Chain { EthereumSepolia = 'ETHEREUM_SEPOLIA', Optimism = 'OPTIMISM', Polygon = 'POLYGON', + Gnosis = 'GNOSIS', UnknownChain = 'UNKNOWN_CHAIN', } diff --git a/src/utils/getExplorerLink.test.ts b/src/utils/getExplorerLink.test.ts index 0ffc6b585ef..a7afc862a57 100644 --- a/src/utils/getExplorerLink.test.ts +++ b/src/utils/getExplorerLink.test.ts @@ -38,4 +38,9 @@ describe('#getExplorerLink', () => { it('base', () => { expect(getExplorerLink(ChainId.BASE, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://basescan.org/address/abc') }) + it('gnosis', () => { + expect(getExplorerLink(ChainId.GNOSIS, 'abc', ExplorerDataType.ADDRESS)).toEqual( + 'https://gnosisscan.io/address/abc' + ) + }) }) diff --git a/src/utils/getExplorerLink.ts b/src/utils/getExplorerLink.ts index f53231afb40..605279498bb 100644 --- a/src/utils/getExplorerLink.ts +++ b/src/utils/getExplorerLink.ts @@ -13,6 +13,7 @@ const BLOCK_EXPLORER_PREFIXES: { [chainId: number]: string } = { [ChainId.BNB]: 'https://bscscan.com', [ChainId.AVALANCHE]: 'https://snowtrace.io', [ChainId.BASE]: 'https://basescan.org', + [ChainId.GNOSIS]: 'https://gnosisscan.io', } export enum ExplorerDataType { From b8b3b9aa4f3ee97995d3c301797bf7f1d6bb2f97 Mon Sep 17 00:00:00 2001 From: Philippe Schommers Date: Sat, 3 Feb 2024 15:35:40 +0100 Subject: [PATCH 2/2] feat: patch Gnosis Chain into @uniswap/universal-router-sdk --- .../@uniswap+universal-router-sdk+1.5.6.patch | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 patches/@uniswap+universal-router-sdk+1.5.6.patch diff --git a/patches/@uniswap+universal-router-sdk+1.5.6.patch b/patches/@uniswap+universal-router-sdk+1.5.6.patch new file mode 100644 index 00000000000..149b6f3c0d6 --- /dev/null +++ b/patches/@uniswap+universal-router-sdk+1.5.6.patch @@ -0,0 +1,23 @@ +diff --git a/node_modules/@uniswap/universal-router-sdk/dist/universal-router-sdk.cjs.development.js b/node_modules/@uniswap/universal-router-sdk/dist/universal-router-sdk.cjs.development.js +index d0e1f6e..95e47f6 100644 +--- a/node_modules/@uniswap/universal-router-sdk/dist/universal-router-sdk.cjs.development.js ++++ b/node_modules/@uniswap/universal-router-sdk/dist/universal-router-sdk.cjs.development.js +@@ -246,6 +246,10 @@ var CHAIN_CONFIGS = (_CHAIN_CONFIGS = {}, _CHAIN_CONFIGS[1] = { + router: '0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC', + weth: '0x4200000000000000000000000000000000000006', + creationBlock: 1452376 ++}, _CHAIN_CONFIGS[100] = { ++ router: '0xcb395D837BD9329fcCEB4f64eFE6c035b19B666b', ++ weth: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', ++ creationBlock: 32269510 + }, _CHAIN_CONFIGS); + var UNIVERSAL_ROUTER_ADDRESS = function UNIVERSAL_ROUTER_ADDRESS(chainId) { + if (!(chainId in CHAIN_CONFIGS)) throw new Error("Universal Router not deployed on chain " + chainId); +diff --git a/node_modules/@uniswap/universal-router-sdk/dist/universal-router-sdk.cjs.production.min.js b/node_modules/@uniswap/universal-router-sdk/dist/universal-router-sdk.cjs.production.min.js +index 00f5ced..b59cc45 100644 +--- a/node_modules/@uniswap/universal-router-sdk/dist/universal-router-sdk.cjs.production.min.js ++++ b/node_modules/@uniswap/universal-router-sdk/dist/universal-router-sdk.cjs.production.min.js +@@ -1,2 +1,2 @@ +-"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t,n=e(require("tiny-invariant")),a=require("@uniswap/universal-router/artifacts/contracts/UniversalRouter.sol/UniversalRouter.json"),i=require("@ethersproject/abi"),r=require("ethers"),p=e(require("jsbi")),s=require("ethers/lib/utils"),y=require("@uniswap/v2-sdk"),u=require("@uniswap/v3-sdk"),o=require("@uniswap/router-sdk"),d=require("@uniswap/sdk-core");function l(){return(l=Object.assign?Object.assign.bind():function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,a=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t=exports.RouterTradeType||(exports.RouterTradeType={})).UniswapTrade="UniswapTrade",t.NFTTrade="NFTTrade",t.UnwrapWETH="UnwrapWETH";var f,b,v,A,C=function(e,t){this.tradeType=exports.RouterTradeType.NFTTrade,t.length>0||n(!1),this.market=e,this.orders=t};(f=exports.Market||(exports.Market={})).Foundation="foundation",f.LooksRareV2="looksrareV2",f.NFT20="nft20",f.NFTX="nftx",f.Seaport="seaport",f.Sudoswap="Sudoswap",f.Cryptopunks="cryptopunks",f.X2Y2="x2y2",f.Element="element",(b=exports.TokenType||(exports.TokenType={})).ERC721="ERC721",b.ERC1155="ERC1155",b.Cryptopunk="Cryptopunk",function(e){e[e.V3_SWAP_EXACT_IN=0]="V3_SWAP_EXACT_IN",e[e.V3_SWAP_EXACT_OUT=1]="V3_SWAP_EXACT_OUT",e[e.PERMIT2_TRANSFER_FROM=2]="PERMIT2_TRANSFER_FROM",e[e.PERMIT2_PERMIT_BATCH=3]="PERMIT2_PERMIT_BATCH",e[e.SWEEP=4]="SWEEP",e[e.TRANSFER=5]="TRANSFER",e[e.PAY_PORTION=6]="PAY_PORTION",e[e.V2_SWAP_EXACT_IN=8]="V2_SWAP_EXACT_IN",e[e.V2_SWAP_EXACT_OUT=9]="V2_SWAP_EXACT_OUT",e[e.PERMIT2_PERMIT=10]="PERMIT2_PERMIT",e[e.WRAP_ETH=11]="WRAP_ETH",e[e.UNWRAP_WETH=12]="UNWRAP_WETH",e[e.PERMIT2_TRANSFER_FROM_BATCH=13]="PERMIT2_TRANSFER_FROM_BATCH",e[e.BALANCE_CHECK_ERC20=14]="BALANCE_CHECK_ERC20",e[e.SEAPORT_V1_5=16]="SEAPORT_V1_5",e[e.LOOKS_RARE_V2=17]="LOOKS_RARE_V2",e[e.NFTX=18]="NFTX",e[e.CRYPTOPUNKS=19]="CRYPTOPUNKS",e[e.OWNER_CHECK_721=21]="OWNER_CHECK_721",e[e.OWNER_CHECK_1155=22]="OWNER_CHECK_1155",e[e.SWEEP_ERC721=23]="SWEEP_ERC721",e[e.X2Y2_721=24]="X2Y2_721",e[e.SUDOSWAP=25]="SUDOSWAP",e[e.NFT20=26]="NFT20",e[e.X2Y2_1155=27]="X2Y2_1155",e[e.FOUNDATION=28]="FOUNDATION",e[e.SWEEP_ERC1155=29]="SWEEP_ERC1155",e[e.ELEMENT_MARKET=30]="ELEMENT_MARKET",e[e.SEAPORT_V1_4=32]="SEAPORT_V1_4",e[e.EXECUTE_SUB_PLAN=33]="EXECUTE_SUB_PLAN",e[e.APPROVE_ERC20=34]="APPROVE_ERC20"}(A||(A={}));var S,I=new Set([A.SEAPORT_V1_5,A.SEAPORT_V1_4,A.NFTX,A.LOOKS_RARE_V2,A.X2Y2_721,A.X2Y2_1155,A.FOUNDATION,A.SUDOSWAP,A.NFT20,A.EXECUTE_SUB_PLAN,A.CRYPTOPUNKS,A.ELEMENT_MARKET]),R=((v={})[A.EXECUTE_SUB_PLAN]=["bytes","bytes[]"],v[A.PERMIT2_PERMIT]=["((address token,uint160 amount,uint48 expiration,uint48 nonce) details,address spender,uint256 sigDeadline)","bytes"],v[A.PERMIT2_PERMIT_BATCH]=["((address token,uint160 amount,uint48 expiration,uint48 nonce)[] details,address spender,uint256 sigDeadline)","bytes"],v[A.PERMIT2_TRANSFER_FROM]=["address","address","uint160"],v[A.PERMIT2_TRANSFER_FROM_BATCH]=["(address from,address to,uint160 amount,address token)[]"],v[A.V3_SWAP_EXACT_IN]=["address","uint256","uint256","bytes","bool"],v[A.V3_SWAP_EXACT_OUT]=["address","uint256","uint256","bytes","bool"],v[A.V2_SWAP_EXACT_IN]=["address","uint256","uint256","address[]","bool"],v[A.V2_SWAP_EXACT_OUT]=["address","uint256","uint256","address[]","bool"],v[A.WRAP_ETH]=["address","uint256"],v[A.UNWRAP_WETH]=["address","uint256"],v[A.SWEEP]=["address","address","uint256"],v[A.SWEEP_ERC721]=["address","address","uint256"],v[A.SWEEP_ERC1155]=["address","address","uint256","uint256"],v[A.TRANSFER]=["address","address","uint256"],v[A.PAY_PORTION]=["address","address","uint256"],v[A.BALANCE_CHECK_ERC20]=["address","address","uint256"],v[A.OWNER_CHECK_721]=["address","address","uint256"],v[A.OWNER_CHECK_1155]=["address","address","uint256","uint256"],v[A.APPROVE_ERC20]=["address","uint256"],v[A.SEAPORT_V1_5]=["uint256","bytes"],v[A.SEAPORT_V1_4]=["uint256","bytes"],v[A.NFTX]=["uint256","bytes"],v[A.LOOKS_RARE_V2]=["uint256","bytes"],v[A.X2Y2_721]=["uint256","bytes","address","address","uint256"],v[A.X2Y2_1155]=["uint256","bytes","address","address","uint256","uint256"],v[A.FOUNDATION]=["uint256","bytes","address","address","uint256"],v[A.SUDOSWAP]=["uint256","bytes"],v[A.NFT20]=["uint256","bytes"],v[A.CRYPTOPUNKS]=["uint256","address","uint256"],v[A.ELEMENT_MARKET]=["uint256","bytes"],v),M=function(){function e(){this.commands="0x",this.inputs=[]}var t=e.prototype;return t.addSubPlan=function(e){this.addCommand(A.EXECUTE_SUB_PLAN,[e.commands,e.inputs],!0)},t.addCommand=function(e,t,n){void 0===n&&(n=!1);var a=function(e,t){return{type:e,encodedInput:s.defaultAbiCoder.encode(R[e],t)}}(e,t);if(this.inputs.push(a.encodedInput),n){if(!I.has(a.type))throw new Error("command type: "+a.type+" cannot be allowed to revert");a.type=128|a.type}this.commands=this.commands.concat(a.type.toString(16).padStart(2,"0"))},e}(),_=((S={})[1]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",creationBlock:17143817},S[5]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6",creationBlock:8940568},S[11155111]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",creationBlock:3543575},S[137]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",creationBlock:42294741},S[80001]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889",creationBlock:35176052},S[10]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x4200000000000000000000000000000000000006",creationBlock:96333990},S[420]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x4200000000000000000000000000000000000006",creationBlock:8887728},S[42161]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",creationBlock:87206402},S[421613]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3",creationBlock:18815277},S[42220]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x0000000000000000000000000000000000000000",creationBlock:19106929},S[44787]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x0000000000000000000000000000000000000000",creationBlock:17566658},S[56]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",creationBlock:27915533},S[43114]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",creationBlock:31583684},S[84531]={router:"0xd0872d928672ae2ff74bdb2f5130ac12229cafaf",weth:"0x4200000000000000000000000000000000000006",creationBlock:6915289},S[8453]={router:"0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC",weth:"0x4200000000000000000000000000000000000006",creationBlock:1452376},S),x=function(e){if(!(e in _))throw new Error("Universal Router not deployed on chain "+e);if("0x0000000000000000000000000000000000000000"==_[e].weth)throw new Error("Chain "+e+" does not have WETH");return _[e].weth},k=r.BigNumber.from(2).pow(255),E="0x0000000000000000000000000000000000000000",P="0x0000000000000000000000000000000000000000",O="0x0000000000000000000000000000000000000001",w="0x0000000000000000000000000000000000000002",F=new d.Percent(p.BigInt(50),p.BigInt(100)),h=function(){function e(e,t){this.trade=e,this.options=t,this.tradeType=exports.RouterTradeType.UniswapTrade}return e.prototype.encode=function(e,t){var n,a=!0;this.trade.inputAmount.currency.isNative&&(e.addCommand(A.WRAP_ETH,[w,this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]),a=!1),this.options.recipient=null!=(n=this.options.recipient)?n:O;for(var i,r=this.trade.outputAmount.currency.isNative,p=this.trade.inputAmount.currency.isNative,s=this.trade.tradeType===d.TradeType.EXACT_INPUT&&this.trade.routes.length>2||r,y=c(this.trade.swaps);!(i=y()).done;){var u=i.value;switch(u.route.protocol){case o.Protocol.V2:N(e,u,this.trade.tradeType,this.options,a,s);break;case o.Protocol.V3:g(e,u,this.trade.tradeType,this.options,a,s);break;case o.Protocol.MIXED:B(e,u,this.trade.tradeType,this.options,a,s);break;default:throw new Error("UNSUPPORTED_TRADE_PROTOCOL")}}s&&(r?e.addCommand(A.UNWRAP_WETH,[this.options.recipient,this.trade.minimumAmountOut(this.options.slippageTolerance).quotient.toString()]):e.addCommand(A.SWEEP,[this.trade.outputAmount.currency.wrapped.address,this.options.recipient,this.trade.minimumAmountOut(this.options.slippageTolerance).quotient.toString()])),p&&(this.trade.tradeType===d.TradeType.EXACT_OUTPUT||this.trade.priceImpact.greaterThan(F))&&e.addCommand(A.UNWRAP_WETH,[this.options.recipient,0])},e}();function N(e,t,n,a,i,r){var p=t.route,s=new y.Trade(p,n==d.TradeType.EXACT_INPUT?t.inputAmount:t.outputAmount,n);n==d.TradeType.EXACT_INPUT?e.addCommand(A.V2_SWAP_EXACT_IN,[r?w:a.recipient,s.maximumAmountIn(a.slippageTolerance).quotient.toString(),s.minimumAmountOut(a.slippageTolerance).quotient.toString(),p.path.map((function(e){return e.address})),i]):n==d.TradeType.EXACT_OUTPUT&&e.addCommand(A.V2_SWAP_EXACT_OUT,[r?w:a.recipient,s.minimumAmountOut(a.slippageTolerance).quotient.toString(),s.maximumAmountIn(a.slippageTolerance).quotient.toString(),p.path.map((function(e){return e.address})),i])}function g(e,t,n,a,i,r){var p=t.route,s=u.Trade.createUncheckedTrade({route:p,inputAmount:t.inputAmount,outputAmount:t.outputAmount,tradeType:n}),y=u.encodeRouteToPath(p,s.tradeType===d.TradeType.EXACT_OUTPUT);n==d.TradeType.EXACT_INPUT?e.addCommand(A.V3_SWAP_EXACT_IN,[r?w:a.recipient,s.maximumAmountIn(a.slippageTolerance).quotient.toString(),s.minimumAmountOut(a.slippageTolerance).quotient.toString(),y,i]):n==d.TradeType.EXACT_OUTPUT&&e.addCommand(A.V3_SWAP_EXACT_OUT,[r?w:a.recipient,s.minimumAmountOut(a.slippageTolerance).quotient.toString(),s.maximumAmountIn(a.slippageTolerance).quotient.toString(),y,i])}function B(e,t,n,a,i,r){var p=t.route,s=t.inputAmount,d=t.outputAmount,l=r?w:a.recipient;if(1===p.pools.length){if(p.pools[0]instanceof u.Pool)return g(e,t,n,a,i,r);if(p.pools[0]instanceof y.Pair)return N(e,t,n,a,i,r);throw new Error("Invalid route type")}for(var m,T=o.MixedRouteTrade.createUncheckedTrade({route:p,inputAmount:s,outputAmount:d,tradeType:n}),c=T.maximumAmountIn(a.slippageTolerance,s).quotient.toString(),f=T.minimumAmountOut(a.slippageTolerance,d).quotient.toString(),b=o.partitionMixedRouteByProtocol(p),v=function(e){return e===b.length-1},C=p.input.wrapped,S=0;S=e||n(!1),this.permit2Data=a)}return e.prototype.encode=function(e,t){L(e,{permit2Permit:this.permit2Data,permit2TransferFrom:{token:this.wethAddress,amount:this.amount.toString()}}),e.addCommand(A.UNWRAP_WETH,[w,this.amount])},e}();exports.CryptopunkTrade=H,exports.FoundationTrade=X,exports.LooksRareV2Trade=q,exports.NFT20Trade=Y,exports.NFTTrade=C,exports.NFTXTrade=G,exports.PERMIT2_ADDRESS="0x000000000022D473030F116dDEE9F6B43aC78BA3",exports.ROUTER_AS_RECIPIENT=w,exports.SeaportTrade=Z,exports.SudoswapTrade=J,exports.SwapRouter=U,exports.UNIVERSAL_ROUTER_ADDRESS=function(e){if(!(e in _))throw new Error("Universal Router not deployed on chain "+e);return _[e].router},exports.UNIVERSAL_ROUTER_CREATION_BLOCK=function(e){if(!(e in _))throw new Error("Universal Router not deployed on chain "+e);return _[e].creationBlock},exports.UniswapTrade=h,exports.UnwrapWETH=ne,exports.WETH_ADDRESS=x,exports.X2Y2Trade=te; ++"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t,n=e(require("tiny-invariant")),a=require("@uniswap/universal-router/artifacts/contracts/UniversalRouter.sol/UniversalRouter.json"),i=require("@ethersproject/abi"),r=require("ethers"),p=e(require("jsbi")),s=require("ethers/lib/utils"),y=require("@uniswap/v2-sdk"),u=require("@uniswap/v3-sdk"),o=require("@uniswap/router-sdk"),d=require("@uniswap/sdk-core");function l(){return(l=Object.assign?Object.assign.bind():function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,a=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(t=exports.RouterTradeType||(exports.RouterTradeType={})).UniswapTrade="UniswapTrade",t.NFTTrade="NFTTrade",t.UnwrapWETH="UnwrapWETH";var f,b,v,A,C=function(e,t){this.tradeType=exports.RouterTradeType.NFTTrade,t.length>0||n(!1),this.market=e,this.orders=t};(f=exports.Market||(exports.Market={})).Foundation="foundation",f.LooksRareV2="looksrareV2",f.NFT20="nft20",f.NFTX="nftx",f.Seaport="seaport",f.Sudoswap="Sudoswap",f.Cryptopunks="cryptopunks",f.X2Y2="x2y2",f.Element="element",(b=exports.TokenType||(exports.TokenType={})).ERC721="ERC721",b.ERC1155="ERC1155",b.Cryptopunk="Cryptopunk",function(e){e[e.V3_SWAP_EXACT_IN=0]="V3_SWAP_EXACT_IN",e[e.V3_SWAP_EXACT_OUT=1]="V3_SWAP_EXACT_OUT",e[e.PERMIT2_TRANSFER_FROM=2]="PERMIT2_TRANSFER_FROM",e[e.PERMIT2_PERMIT_BATCH=3]="PERMIT2_PERMIT_BATCH",e[e.SWEEP=4]="SWEEP",e[e.TRANSFER=5]="TRANSFER",e[e.PAY_PORTION=6]="PAY_PORTION",e[e.V2_SWAP_EXACT_IN=8]="V2_SWAP_EXACT_IN",e[e.V2_SWAP_EXACT_OUT=9]="V2_SWAP_EXACT_OUT",e[e.PERMIT2_PERMIT=10]="PERMIT2_PERMIT",e[e.WRAP_ETH=11]="WRAP_ETH",e[e.UNWRAP_WETH=12]="UNWRAP_WETH",e[e.PERMIT2_TRANSFER_FROM_BATCH=13]="PERMIT2_TRANSFER_FROM_BATCH",e[e.BALANCE_CHECK_ERC20=14]="BALANCE_CHECK_ERC20",e[e.SEAPORT_V1_5=16]="SEAPORT_V1_5",e[e.LOOKS_RARE_V2=17]="LOOKS_RARE_V2",e[e.NFTX=18]="NFTX",e[e.CRYPTOPUNKS=19]="CRYPTOPUNKS",e[e.OWNER_CHECK_721=21]="OWNER_CHECK_721",e[e.OWNER_CHECK_1155=22]="OWNER_CHECK_1155",e[e.SWEEP_ERC721=23]="SWEEP_ERC721",e[e.X2Y2_721=24]="X2Y2_721",e[e.SUDOSWAP=25]="SUDOSWAP",e[e.NFT20=26]="NFT20",e[e.X2Y2_1155=27]="X2Y2_1155",e[e.FOUNDATION=28]="FOUNDATION",e[e.SWEEP_ERC1155=29]="SWEEP_ERC1155",e[e.ELEMENT_MARKET=30]="ELEMENT_MARKET",e[e.SEAPORT_V1_4=32]="SEAPORT_V1_4",e[e.EXECUTE_SUB_PLAN=33]="EXECUTE_SUB_PLAN",e[e.APPROVE_ERC20=34]="APPROVE_ERC20"}(A||(A={}));var S,I=new Set([A.SEAPORT_V1_5,A.SEAPORT_V1_4,A.NFTX,A.LOOKS_RARE_V2,A.X2Y2_721,A.X2Y2_1155,A.FOUNDATION,A.SUDOSWAP,A.NFT20,A.EXECUTE_SUB_PLAN,A.CRYPTOPUNKS,A.ELEMENT_MARKET]),R=((v={})[A.EXECUTE_SUB_PLAN]=["bytes","bytes[]"],v[A.PERMIT2_PERMIT]=["((address token,uint160 amount,uint48 expiration,uint48 nonce) details,address spender,uint256 sigDeadline)","bytes"],v[A.PERMIT2_PERMIT_BATCH]=["((address token,uint160 amount,uint48 expiration,uint48 nonce)[] details,address spender,uint256 sigDeadline)","bytes"],v[A.PERMIT2_TRANSFER_FROM]=["address","address","uint160"],v[A.PERMIT2_TRANSFER_FROM_BATCH]=["(address from,address to,uint160 amount,address token)[]"],v[A.V3_SWAP_EXACT_IN]=["address","uint256","uint256","bytes","bool"],v[A.V3_SWAP_EXACT_OUT]=["address","uint256","uint256","bytes","bool"],v[A.V2_SWAP_EXACT_IN]=["address","uint256","uint256","address[]","bool"],v[A.V2_SWAP_EXACT_OUT]=["address","uint256","uint256","address[]","bool"],v[A.WRAP_ETH]=["address","uint256"],v[A.UNWRAP_WETH]=["address","uint256"],v[A.SWEEP]=["address","address","uint256"],v[A.SWEEP_ERC721]=["address","address","uint256"],v[A.SWEEP_ERC1155]=["address","address","uint256","uint256"],v[A.TRANSFER]=["address","address","uint256"],v[A.PAY_PORTION]=["address","address","uint256"],v[A.BALANCE_CHECK_ERC20]=["address","address","uint256"],v[A.OWNER_CHECK_721]=["address","address","uint256"],v[A.OWNER_CHECK_1155]=["address","address","uint256","uint256"],v[A.APPROVE_ERC20]=["address","uint256"],v[A.SEAPORT_V1_5]=["uint256","bytes"],v[A.SEAPORT_V1_4]=["uint256","bytes"],v[A.NFTX]=["uint256","bytes"],v[A.LOOKS_RARE_V2]=["uint256","bytes"],v[A.X2Y2_721]=["uint256","bytes","address","address","uint256"],v[A.X2Y2_1155]=["uint256","bytes","address","address","uint256","uint256"],v[A.FOUNDATION]=["uint256","bytes","address","address","uint256"],v[A.SUDOSWAP]=["uint256","bytes"],v[A.NFT20]=["uint256","bytes"],v[A.CRYPTOPUNKS]=["uint256","address","uint256"],v[A.ELEMENT_MARKET]=["uint256","bytes"],v),M=function(){function e(){this.commands="0x",this.inputs=[]}var t=e.prototype;return t.addSubPlan=function(e){this.addCommand(A.EXECUTE_SUB_PLAN,[e.commands,e.inputs],!0)},t.addCommand=function(e,t,n){void 0===n&&(n=!1);var a=function(e,t){return{type:e,encodedInput:s.defaultAbiCoder.encode(R[e],t)}}(e,t);if(this.inputs.push(a.encodedInput),n){if(!I.has(a.type))throw new Error("command type: "+a.type+" cannot be allowed to revert");a.type=128|a.type}this.commands=this.commands.concat(a.type.toString(16).padStart(2,"0"))},e}(),_=((S={})[1]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",creationBlock:17143817},S[5]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6",creationBlock:8940568},S[11155111]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14",creationBlock:3543575},S[137]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",creationBlock:42294741},S[80001]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889",creationBlock:35176052},S[10]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x4200000000000000000000000000000000000006",creationBlock:96333990},S[420]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x4200000000000000000000000000000000000006",creationBlock:8887728},S[42161]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",creationBlock:87206402},S[421613]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3",creationBlock:18815277},S[42220]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x0000000000000000000000000000000000000000",creationBlock:19106929},S[44787]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0x0000000000000000000000000000000000000000",creationBlock:17566658},S[56]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",creationBlock:27915533},S[43114]={router:"0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",weth:"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",creationBlock:31583684},S[84531]={router:"0xd0872d928672ae2ff74bdb2f5130ac12229cafaf",weth:"0x4200000000000000000000000000000000000006",creationBlock:6915289},S[8453]={router:"0x198EF79F1F515F02dFE9e3115eD9fC07183f02fC",weth:"0x4200000000000000000000000000000000000006",creationBlock:1452376},S[100]={router:"0xcb395D837BD9329fcCEB4f64eFE6c035b19B666b",weth:"0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d",creationBlock:32269510},S),x=function(e){if(!(e in _))throw new Error("Universal Router not deployed on chain "+e);if("0x0000000000000000000000000000000000000000"==_[e].weth)throw new Error("Chain "+e+" does not have WETH");return _[e].weth},k=r.BigNumber.from(2).pow(255),E="0x0000000000000000000000000000000000000000",P="0x0000000000000000000000000000000000000000",O="0x0000000000000000000000000000000000000001",w="0x0000000000000000000000000000000000000002",F=new d.Percent(p.BigInt(50),p.BigInt(100)),h=function(){function e(e,t){this.trade=e,this.options=t,this.tradeType=exports.RouterTradeType.UniswapTrade}return e.prototype.encode=function(e,t){var n,a=!0;this.trade.inputAmount.currency.isNative&&(e.addCommand(A.WRAP_ETH,[w,this.trade.maximumAmountIn(this.options.slippageTolerance).quotient.toString()]),a=!1),this.options.recipient=null!=(n=this.options.recipient)?n:O;for(var i,r=this.trade.outputAmount.currency.isNative,p=this.trade.inputAmount.currency.isNative,s=this.trade.tradeType===d.TradeType.EXACT_INPUT&&this.trade.routes.length>2||r,y=c(this.trade.swaps);!(i=y()).done;){var u=i.value;switch(u.route.protocol){case o.Protocol.V2:N(e,u,this.trade.tradeType,this.options,a,s);break;case o.Protocol.V3:g(e,u,this.trade.tradeType,this.options,a,s);break;case o.Protocol.MIXED:B(e,u,this.trade.tradeType,this.options,a,s);break;default:throw new Error("UNSUPPORTED_TRADE_PROTOCOL")}}s&&(r?e.addCommand(A.UNWRAP_WETH,[this.options.recipient,this.trade.minimumAmountOut(this.options.slippageTolerance).quotient.toString()]):e.addCommand(A.SWEEP,[this.trade.outputAmount.currency.wrapped.address,this.options.recipient,this.trade.minimumAmountOut(this.options.slippageTolerance).quotient.toString()])),p&&(this.trade.tradeType===d.TradeType.EXACT_OUTPUT||this.trade.priceImpact.greaterThan(F))&&e.addCommand(A.UNWRAP_WETH,[this.options.recipient,0])},e}();function N(e,t,n,a,i,r){var p=t.route,s=new y.Trade(p,n==d.TradeType.EXACT_INPUT?t.inputAmount:t.outputAmount,n);n==d.TradeType.EXACT_INPUT?e.addCommand(A.V2_SWAP_EXACT_IN,[r?w:a.recipient,s.maximumAmountIn(a.slippageTolerance).quotient.toString(),s.minimumAmountOut(a.slippageTolerance).quotient.toString(),p.path.map((function(e){return e.address})),i]):n==d.TradeType.EXACT_OUTPUT&&e.addCommand(A.V2_SWAP_EXACT_OUT,[r?w:a.recipient,s.minimumAmountOut(a.slippageTolerance).quotient.toString(),s.maximumAmountIn(a.slippageTolerance).quotient.toString(),p.path.map((function(e){return e.address})),i])}function g(e,t,n,a,i,r){var p=t.route,s=u.Trade.createUncheckedTrade({route:p,inputAmount:t.inputAmount,outputAmount:t.outputAmount,tradeType:n}),y=u.encodeRouteToPath(p,s.tradeType===d.TradeType.EXACT_OUTPUT);n==d.TradeType.EXACT_INPUT?e.addCommand(A.V3_SWAP_EXACT_IN,[r?w:a.recipient,s.maximumAmountIn(a.slippageTolerance).quotient.toString(),s.minimumAmountOut(a.slippageTolerance).quotient.toString(),y,i]):n==d.TradeType.EXACT_OUTPUT&&e.addCommand(A.V3_SWAP_EXACT_OUT,[r?w:a.recipient,s.minimumAmountOut(a.slippageTolerance).quotient.toString(),s.maximumAmountIn(a.slippageTolerance).quotient.toString(),y,i])}function B(e,t,n,a,i,r){var p=t.route,s=t.inputAmount,d=t.outputAmount,l=r?w:a.recipient;if(1===p.pools.length){if(p.pools[0]instanceof u.Pool)return g(e,t,n,a,i,r);if(p.pools[0]instanceof y.Pair)return N(e,t,n,a,i,r);throw new Error("Invalid route type")}for(var m,T=o.MixedRouteTrade.createUncheckedTrade({route:p,inputAmount:s,outputAmount:d,tradeType:n}),c=T.maximumAmountIn(a.slippageTolerance,s).quotient.toString(),f=T.minimumAmountOut(a.slippageTolerance,d).quotient.toString(),b=o.partitionMixedRouteByProtocol(p),v=function(e){return e===b.length-1},C=p.input.wrapped,S=0;S=e||n(!1),this.permit2Data=a)}return e.prototype.encode=function(e,t){L(e,{permit2Permit:this.permit2Data,permit2TransferFrom:{token:this.wethAddress,amount:this.amount.toString()}}),e.addCommand(A.UNWRAP_WETH,[w,this.amount])},e}();exports.CryptopunkTrade=H,exports.FoundationTrade=X,exports.LooksRareV2Trade=q,exports.NFT20Trade=Y,exports.NFTTrade=C,exports.NFTXTrade=G,exports.PERMIT2_ADDRESS="0x000000000022D473030F116dDEE9F6B43aC78BA3",exports.ROUTER_AS_RECIPIENT=w,exports.SeaportTrade=Z,exports.SudoswapTrade=J,exports.SwapRouter=U,exports.UNIVERSAL_ROUTER_ADDRESS=function(e){if(!(e in _))throw new Error("Universal Router not deployed on chain "+e);return _[e].router},exports.UNIVERSAL_ROUTER_CREATION_BLOCK=function(e){if(!(e in _))throw new Error("Universal Router not deployed on chain "+e);return _[e].creationBlock},exports.UniswapTrade=h,exports.UnwrapWETH=ne,exports.WETH_ADDRESS=x,exports.X2Y2Trade=te; + //# sourceMappingURL=universal-router-sdk.cjs.production.min.js.map