From 6aed2f92c72949277ff8fa296fb5d647d0da437a Mon Sep 17 00:00:00 2001 From: Diogo Ferreira Date: Tue, 16 Jan 2024 20:40:10 +0000 Subject: [PATCH] hot fix: remove Socket bridge till exploit is fixed --- src/constants/index.tsx | 5 ---- .../TransactionRows/BridgeTransactionRow.tsx | 6 +---- .../Bridge/BridgeTransactionsSummary.tsx | 6 +---- .../AdvancedTradingView/useAllTrades.hook.ts | 4 +-- src/services/EcoBridge/EcoBridge.config.ts | 19 +------------- src/services/EcoBridge/EcoBridge.hooks.ts | 2 -- src/services/EcoBridge/EcoBridge.utils.tsx | 9 +++---- .../EcoBridge/store/EcoBridge.selectors.ts | 25 +++---------------- src/utils/index.ts | 4 +-- 9 files changed, 11 insertions(+), 69 deletions(-) diff --git a/src/constants/index.tsx b/src/constants/index.tsx index 65f2e64332..2b836f1271 100644 --- a/src/constants/index.tsx +++ b/src/constants/index.tsx @@ -144,11 +144,6 @@ export const BRIDGES: Record = { name: 'OmniBridge', url: 'https://omnibridge.gnosischain.com/', }, - SOCKET: { - id: BridgeIds.SOCKET, - name: 'Socket Network', - url: 'https://socket.tech/', - }, XDAI: { id: BridgeIds.XDAI, name: 'xDai Bridge', diff --git a/src/pages/Account/TransactionRows/BridgeTransactionRow.tsx b/src/pages/Account/TransactionRows/BridgeTransactionRow.tsx index a2f950582d..493b4e6ac6 100644 --- a/src/pages/Account/TransactionRows/BridgeTransactionRow.tsx +++ b/src/pages/Account/TransactionRows/BridgeTransactionRow.tsx @@ -4,7 +4,6 @@ import { Repeat } from 'react-feather' import { Box, Flex } from 'rebass' import styled from 'styled-components' -import { BRIDGES } from '../../../constants' import { getExplorerLink } from '../../../utils' import { formatNumber } from '../../../utils/formatNumber' import { getNetworkInfo } from '../../../utils/networksList' @@ -34,10 +33,7 @@ export function BridgeTransactionRow({ transaction, showBackgroundStatus }: Brid const toNetwork = buyToken?.chainId ? getNetworkInfo(Number(buyToken?.chainId)) : undefined const fromLink = getExplorerLink(logs[0]?.chainId, logs[0]?.txHash, 'transaction', bridgeId) - const toLink = - bridgeId === BRIDGES.SOCKET.id - ? logs[0] && logs[1] && getExplorerLink(logs[0].chainId, logs[0].txHash, 'transaction', bridgeId) - : logs[1] && getExplorerLink(logs[1].chainId, logs[1].txHash, 'transaction', bridgeId) + const toLink = logs[1] && getExplorerLink(logs[1].chainId, logs[1].txHash, 'transaction', bridgeId) const price = flipPrice ? buyToken.value / sellToken.value : sellToken.value / buyToken.value diff --git a/src/pages/Bridge/BridgeTransactionsSummary.tsx b/src/pages/Bridge/BridgeTransactionsSummary.tsx index 757d74b28f..c12ca4c338 100644 --- a/src/pages/Bridge/BridgeTransactionsSummary.tsx +++ b/src/pages/Bridge/BridgeTransactionsSummary.tsx @@ -3,7 +3,6 @@ import styled from 'styled-components' import { useAnalytics } from '../../analytics' import { AdvancedDetailsFooter } from '../../components/AdvancedDetailsFooter' -import { BRIDGES } from '../../constants' import { BridgeTransactionStatus, BridgeTransactionSummary } from '../../state/bridgeTransactions/types' import { getExplorerLink } from '../../utils' import { getNetworkInfo } from '../../utils/networksList' @@ -172,10 +171,7 @@ const BridgeTransactionsSummaryRow = ({ tx, handleTriggerCollect }: BridgeTransa const fromChainName = fromChainId ? getNetworkInfo(fromChainId).name : '' const toChainName = toChainId ? getNetworkInfo(toChainId).name : '' - const toLink = - bridgeId === BRIDGES.SOCKET.id - ? log[0] && log[1] && getExplorerLink(log[0].chainId, log[0].txHash, 'transaction', bridgeId) - : log[1] && getExplorerLink(log[1].chainId, log[1].txHash, 'transaction', bridgeId) + const toLink = log[1] && getExplorerLink(log[1].chainId, log[1].txHash, 'transaction', bridgeId) // track trade volume on first confirmation useEffect(() => { diff --git a/src/services/AdvancedTradingView/useAllTrades.hook.ts b/src/services/AdvancedTradingView/useAllTrades.hook.ts index f531ac0ae4..c506b1de9c 100644 --- a/src/services/AdvancedTradingView/useAllTrades.hook.ts +++ b/src/services/AdvancedTradingView/useAllTrades.hook.ts @@ -1,7 +1,6 @@ import { useMemo } from 'react' import { useSelector } from 'react-redux' -import { BRIDGES } from '../../constants' import { useActiveWeb3React } from '../../hooks' import { Transaction, TransactionStatus } from '../../pages/Account/Account.types' import { formatTransactions } from '../../pages/Account/utils/accountUtils' @@ -31,8 +30,7 @@ export const useAllTrades = (): { const allLimitOrderTransactions = useLimitOrderTransactions(chainId, account) const allSwapBridgeTransactions = useAllBridgeTransactions(true).filter( - transaction => - transaction.bridgeId === BRIDGES.SOCKET.id && transaction.sellToken.symbol !== transaction.buyToken.symbol + transaction => transaction.sellToken.symbol !== transaction.buyToken.symbol ) const transactions = useMemo(() => { diff --git a/src/services/EcoBridge/EcoBridge.config.ts b/src/services/EcoBridge/EcoBridge.config.ts index a0ebb72236..720173efd4 100644 --- a/src/services/EcoBridge/EcoBridge.config.ts +++ b/src/services/EcoBridge/EcoBridge.config.ts @@ -8,7 +8,6 @@ import { EcoBridgeChildBase } from './EcoBridge.utils' import { LifiBridge } from './Lifi/LifiBridge' import { OmniBridge } from './OmniBridge/OmniBridge' import { bridgeSupportedChains } from './Socket/Socket.utils' -import { SocketBridge } from './Socket/SocketBridge' import { XdaiBridge } from './Xdai/XdaiBridge' //supported chains are bidirectional @@ -57,20 +56,6 @@ export const ecoBridgeConfig: EcoBridgeChildBase[] = [ displayUrl: BRIDGES.OMNIBRIDGE.url, supportedChains: [{ from: ChainId.XDAI, to: ChainId.MAINNET }], }), - new SocketBridge({ - bridgeId: BRIDGES.SOCKET.id, - displayName: BRIDGES.SOCKET.name, - displayUrl: BRIDGES.SOCKET.url, - supportedChains: bridgeSupportedChains([ - ChainId.ARBITRUM_ONE, - ChainId.MAINNET, - ChainId.POLYGON, - ChainId.GNOSIS, - ChainId.OPTIMISM_MAINNET, - ChainId.BSC_MAINNET, - ChainId.ZK_SYNC_ERA_MAINNET, - ]), - }), new XdaiBridge({ bridgeId: BRIDGES.XDAI.id, displayName: BRIDGES.XDAI.name, @@ -84,9 +69,7 @@ export const ecoBridgePersistedKeys = ecoBridgeConfig.map( ) export const fixCorruptedEcoBridgeLocalStorageEntries = (persistenceNamespace: string) => { - const keysWithoutSocketOrLifi = ecoBridgePersistedKeys.filter( - key => !(key.includes(BRIDGES.SOCKET.id) || key.includes(BRIDGES.LIFI.id)) - ) + const keysWithoutSocketOrLifi = ecoBridgePersistedKeys.filter(key => !key.includes(BRIDGES.LIFI.id)) keysWithoutSocketOrLifi.forEach(key => { const fullKey = `${persistenceNamespace}_${key}` diff --git a/src/services/EcoBridge/EcoBridge.hooks.ts b/src/services/EcoBridge/EcoBridge.hooks.ts index 5409995bca..ff2ddea14a 100644 --- a/src/services/EcoBridge/EcoBridge.hooks.ts +++ b/src/services/EcoBridge/EcoBridge.hooks.ts @@ -3,7 +3,6 @@ import { ChainId, Currency, Token } from '@swapr/sdk' import { useCallback, useEffect, useMemo, useState } from 'react' import { useDispatch, useSelector } from 'react-redux' -import { BRIDGES } from '../../constants' import { useActiveWeb3React } from '../../hooks' import { parseStringOrBytes32 } from '../../hooks/Tokens' import { useBytes32TokenContract, useTokenContract, useWrappingToken } from '../../hooks/useContract' @@ -170,7 +169,6 @@ export const useBridgeFetchDynamicLists = () => { useEffect(() => { if (from.chainId && to.chainId) { if (isBridgeSwapActive) { - ecoBridge.bridges[BRIDGES.SOCKET.id].fetchDynamicLists() } else { ecoBridge.fetchDynamicLists() } diff --git a/src/services/EcoBridge/EcoBridge.utils.tsx b/src/services/EcoBridge/EcoBridge.utils.tsx index 998a2149dd..5ae76052ec 100644 --- a/src/services/EcoBridge/EcoBridge.utils.tsx +++ b/src/services/EcoBridge/EcoBridge.utils.tsx @@ -2,7 +2,6 @@ import { createSlice, PayloadAction, SliceCaseReducers, ValidateSliceCaseReducer import { TokenList } from '@uniswap/token-lists' import { subgraphClients } from '../../apollo/client' -import { BRIDGES } from '../../constants' import { GetBundleQuery, GetBundleDocument } from '../../graphql/generated/schema' import { BridgeTransactionSummary } from '../../state/bridgeTransactions/types' import { SWPRSupportedChains } from '../../utils/chainSupportsSWPR' @@ -44,13 +43,11 @@ const reduceMessage = (message?: string) => { return message.slice(0, getIndexOfSpecialCharacter(message)) } -export const getErrorMsg = (error: any, bridgeId?: BridgeIdList) => { +export const getErrorMsg = (error: any) => { if (error?.code === 4001) { return 'Transaction rejected' } - if (bridgeId === BRIDGES.SOCKET.id && error.status === 500 && !error.ok) { - return 'Socket API is temporarily unavailable' - } + return `Bridge failed: ${reduceMessage(error.message)}` } @@ -142,7 +139,7 @@ export abstract class EcoBridgeChildBase { this.store.dispatch( this.ecoBridgeUIActions.setBridgeModalStatus({ status, - error: error && getErrorMsg(error, bridgeId), + error: error && getErrorMsg(error), }) ) }, diff --git a/src/services/EcoBridge/store/EcoBridge.selectors.ts b/src/services/EcoBridge/store/EcoBridge.selectors.ts index 8a5f05586c..4bb96021cf 100644 --- a/src/services/EcoBridge/store/EcoBridge.selectors.ts +++ b/src/services/EcoBridge/store/EcoBridge.selectors.ts @@ -25,7 +25,6 @@ import { } from '../EcoBridge.types' import { lifiSelectors } from '../Lifi/Lifi.selectors' import { omniBridgeSelectors } from '../OmniBridge/OmniBridge.selectors' -import { socketSelectors } from '../Socket/Socket.selectors' import { xdaiSelectors } from '../Xdai/XdaiBridge.selectors' /** @@ -96,7 +95,7 @@ export const selectSupportedBridges = createSelector( }, []) return isBridgeSwapActive - ? supportedBridges.filter(bridge => [BRIDGES.LIFI.id, BRIDGES.SOCKET.id].includes(bridge.bridgeId)) + ? supportedBridges.filter(bridge => [BRIDGES.LIFI.id].includes(bridge.bridgeId)) : supportedBridges } ) @@ -109,22 +108,12 @@ export const selectBridgeTransactions = createSelector( connextSelectors[BridgeIds.CONNEXT].selectBridgeTransactionsSummary, lifiSelectors[BridgeIds.LIFI].selectBridgeTransactionsSummary, omniBridgeSelectors[BridgeIds.OMNIBRIDGE].selectBridgeTransactionsSummary, - socketSelectors[BridgeIds.SOCKET].selectBridgeTransactionsSummary, xdaiSelectors[BridgeIds.XDAI].selectBridgeTransactionsSummary, ], - ( - txsSummaryTestnet, - txsSummaryMainnet, - txsSummarySocket, - txsOmnibridgeEthGnosis, - txsSummaryConnext, - txsSummaryXdai, - txsSummaryLifi - ) => { + (txsSummaryTestnet, txsSummaryMainnet, txsOmnibridgeEthGnosis, txsSummaryConnext, txsSummaryXdai, txsSummaryLifi) => { const txs = [ ...txsSummaryTestnet, ...txsSummaryMainnet, - ...txsSummarySocket, ...txsOmnibridgeEthGnosis, ...txsSummaryConnext, ...txsSummaryXdai, @@ -182,7 +171,6 @@ export const selectBridgeListsLoadingStatus = createSelector( (state: AppState) => state.ecoBridge[BridgeIds.ARBITRUM_TESTNET].listsStatus, (state: AppState) => state.ecoBridge[BridgeIds.CONNEXT].listsStatus, (state: AppState) => state.ecoBridge[BridgeIds.OMNIBRIDGE].listsStatus, - (state: AppState) => state.ecoBridge[BridgeIds.SOCKET].listsStatus, (state: AppState) => state.ecoBridge[BridgeIds.XDAI].listsStatus, ], // Because of redux-persist initial state is undefined @@ -196,14 +184,12 @@ export const selectBridgeIdLists = createSelector( (state: AppState) => state.ecoBridge[BridgeIds.CONNEXT].lists, (state: AppState) => state.ecoBridge[BridgeIds.LIFI].lists, (state: AppState) => state.ecoBridge[BridgeIds.OMNIBRIDGE].lists, - (state: AppState) => state.ecoBridge[BridgeIds.SOCKET].lists, (state: AppState) => state.ecoBridge[BridgeIds.XDAI].lists, (state: AppState) => state.lists.byUrl[DEFAULT_TOKEN_LIST].current, ], ( tokenListTestnet, tokenListMainnet, - tokenListSocket, tokenListConnext, omnibridgeEthGnosisList, tokenListXdai, @@ -219,7 +205,6 @@ export const selectBridgeIdLists = createSelector( ...swprListWithIds, ...tokenListTestnet, ...tokenListMainnet, - ...tokenListSocket, ...tokenListXdai, ...tokenListConnext, ...tokenListLifi, @@ -293,7 +278,7 @@ export const selectBridgeActiveTokens = createSelector( (state: AppState) => state.ecoBridge.ui.isBridgeSwapActive, ], (supportedLists, activeLists, isBridgeSwapActive) => { - const lists = isBridgeSwapActive ? [BRIDGES.SOCKET.id] : activeLists + const lists = isBridgeSwapActive ? [] : activeLists if (!lists.length) return {} @@ -351,7 +336,6 @@ const arbitrumTestnetBridgeDetails = createSelectBridgingDetails( const connextBridgeDetails = createSelectBridgingDetails(BRIDGES.CONNEXT.id, BRIDGES.CONNEXT.url) const lifiBridgeDetails = createSelectBridgingDetails(BRIDGES.LIFI.id, BRIDGES.LIFI.url) const omnibridgeBridgeDetails = createSelectBridgingDetails(BRIDGES.OMNIBRIDGE.id, BRIDGES.OMNIBRIDGE.url) -const socketBridgeDetails = createSelectBridgingDetails(BRIDGES.SOCKET.id, BRIDGES.SOCKET.url) const xdaiBridgeDetails = createSelectBridgingDetails(BRIDGES.XDAI.id, BRIDGES.XDAI.url) export const selectSupportedBridgesForUI = createSelector( @@ -360,7 +344,6 @@ export const selectSupportedBridgesForUI = createSelector( arbitrumTestnetBridgeDetails, arbitrumMainnetBridgeDetails, omnibridgeBridgeDetails, - socketBridgeDetails, connextBridgeDetails, xdaiBridgeDetails, lifiBridgeDetails, @@ -370,7 +353,6 @@ export const selectSupportedBridgesForUI = createSelector( arbitrumTestnetDetails, arbitrumMainnetDetails, omnibridgeEthGnosisDetails, - socketDetails, connextDetails, xdaiDetails, lifiDetails @@ -388,7 +370,6 @@ export const selectSupportedBridgesForUI = createSelector( arbitrumMainnetDetails, arbitrumTestnetDetails, omnibridgeEthGnosisDetails, - socketDetails, connextDetails, xdaiDetails, lifiDetails, diff --git a/src/utils/index.ts b/src/utils/index.ts index fe986a4d8e..65d7f037f4 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -9,7 +9,7 @@ import { ChainId, Currency, CurrencyAmount, JSBI, Pair, Percent, Token, UniswapV import Decimal from 'decimal.js-light' import { commify } from 'ethers/lib/utils' -import { BRIDGES, NetworkDetails } from '../constants' +import { NetworkDetails } from '../constants' import { TokenAddressMap } from '../state/lists/hooks' import { SwapProtocol } from '../state/transactions/reducer' @@ -77,8 +77,6 @@ export function getExplorerLink( return getGnosisProtocolExplorerOrderLink(chainId, hash) } - if (protocol === BRIDGES.SOCKET.id) return getSocketExplorerLink(hash) - const prefix = getExplorerPrefix(chainId) // exception. blockscout doesn't have a token-specific address if (chainId === ChainId.XDAI && type === EXPLORER_LINK_TYPE.token) {