Skip to content

Commit

Permalink
hot fix: remove Socket bridge till exploit is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogomartf authored and berteotti committed Jan 16, 2024
1 parent c0e71ea commit 6aed2f9
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 69 deletions.
5 changes: 0 additions & 5 deletions src/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ export const BRIDGES: Record<string, EcoBridgeConfig> = {
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',
Expand Down
6 changes: 1 addition & 5 deletions src/pages/Account/TransactionRows/BridgeTransactionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand Down
6 changes: 1 addition & 5 deletions src/pages/Bridge/BridgeTransactionsSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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(() => {
Expand Down
4 changes: 1 addition & 3 deletions src/services/AdvancedTradingView/useAllTrades.hook.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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(() => {
Expand Down
19 changes: 1 addition & 18 deletions src/services/EcoBridge/EcoBridge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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}`
Expand Down
2 changes: 0 additions & 2 deletions src/services/EcoBridge/EcoBridge.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -170,7 +169,6 @@ export const useBridgeFetchDynamicLists = () => {
useEffect(() => {
if (from.chainId && to.chainId) {
if (isBridgeSwapActive) {
ecoBridge.bridges[BRIDGES.SOCKET.id].fetchDynamicLists()
} else {
ecoBridge.fetchDynamicLists()
}
Expand Down
9 changes: 3 additions & 6 deletions src/services/EcoBridge/EcoBridge.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)}`
}

Expand Down Expand Up @@ -142,7 +139,7 @@ export abstract class EcoBridgeChildBase {
this.store.dispatch(
this.ecoBridgeUIActions.setBridgeModalStatus({
status,
error: error && getErrorMsg(error, bridgeId),
error: error && getErrorMsg(error),
})
)
},
Expand Down
25 changes: 3 additions & 22 deletions src/services/EcoBridge/store/EcoBridge.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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
}
)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -219,7 +205,6 @@ export const selectBridgeIdLists = createSelector(
...swprListWithIds,
...tokenListTestnet,
...tokenListMainnet,
...tokenListSocket,
...tokenListXdai,
...tokenListConnext,
...tokenListLifi,
Expand Down Expand Up @@ -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 {}

Expand Down Expand Up @@ -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(
Expand All @@ -360,7 +344,6 @@ export const selectSupportedBridgesForUI = createSelector(
arbitrumTestnetBridgeDetails,
arbitrumMainnetBridgeDetails,
omnibridgeBridgeDetails,
socketBridgeDetails,
connextBridgeDetails,
xdaiBridgeDetails,
lifiBridgeDetails,
Expand All @@ -370,7 +353,6 @@ export const selectSupportedBridgesForUI = createSelector(
arbitrumTestnetDetails,
arbitrumMainnetDetails,
omnibridgeEthGnosisDetails,
socketDetails,
connextDetails,
xdaiDetails,
lifiDetails
Expand All @@ -388,7 +370,6 @@ export const selectSupportedBridgesForUI = createSelector(
arbitrumMainnetDetails,
arbitrumTestnetDetails,
omnibridgeEthGnosisDetails,
socketDetails,
connextDetails,
xdaiDetails,
lifiDetails,
Expand Down
4 changes: 1 addition & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6aed2f9

Please sign in to comment.