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: show ARB token on all Orbit chains #1475

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a145526
feat: always show ARB on Orbit pair
fionnachan Jan 24, 2024
2600e99
fix weird case when switching destination chain
fionnachan Jan 24, 2024
399a118
remove usecallback
fionnachan Jan 24, 2024
cd414cc
lowercase lol
fionnachan Jan 24, 2024
4dda7fb
remove console.log
fionnachan Jan 24, 2024
33064f4
remove unneeded code
fionnachan Jan 24, 2024
c842199
remove comment
fionnachan Jan 24, 2024
c0fd50e
clean up
fionnachan Jan 25, 2024
c034918
unneeded imports
fionnachan Jan 25, 2024
a909ee2
cypress didn't like the @ paths it doesn't know about
fionnachan Jan 25, 2024
8d91da6
fix path
fionnachan Jan 25, 2024
1bb8ee0
move file
fionnachan Jan 25, 2024
7e57735
nits
fionnachan Jan 26, 2024
d2b114f
nit
fionnachan Jan 26, 2024
ed95f46
more renaming
fionnachan Jan 26, 2024
b7f7ab6
Merge branch 'master' into fix-arb-on-orbit
fionnachan Jan 26, 2024
7439928
Merge branch 'master' into fix-arb-on-orbit
fionnachan Jan 30, 2024
8d24a23
Merge branch 'master' into fix-arb-on-orbit
fionnachan Jan 31, 2024
a5dfdc1
Merge branch 'master' into fix-arb-on-orbit
chrstph-dvx Feb 1, 2024
1992fa8
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 1, 2024
b16d5a2
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 5, 2024
1749754
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 6, 2024
0ecce9e
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 9, 2024
66cff86
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 13, 2024
04d8380
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 13, 2024
2e872f5
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 15, 2024
b5c7a7d
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 15, 2024
e67e5fc
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 16, 2024
925bb23
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 27, 2024
a13787b
Merge branch 'master' into fix-arb-on-orbit
fionnachan Feb 29, 2024
0144380
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 5, 2024
4515d29
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 5, 2024
a42a878
Merge remote-tracking branch 'origin/master' into fix-arb-on-orbit
fionnachan Mar 6, 2024
385b6dc
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 6, 2024
2162617
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 7, 2024
4d43c17
Merge remote-tracking branch 'origin/master' into fix-arb-on-orbit
fionnachan Mar 19, 2024
7d7ea3a
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 19, 2024
fb7d1b2
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 21, 2024
4b4c27e
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 25, 2024
0ab3d47
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 26, 2024
bbdbe3b
Merge branch 'master' into fix-arb-on-orbit
fionnachan Mar 28, 2024
d1d8bc2
Merge branch 'master' into fix-arb-on-orbit
fionnachan Apr 2, 2024
aa22245
Merge branch 'master' into fix-arb-on-orbit
fionnachan Apr 2, 2024
327f59d
Merge branch 'master' into fix-arb-on-orbit
fionnachan Apr 4, 2024
6bed30a
Merge branch 'master' into fix-arb-on-orbit
fionnachan Apr 9, 2024
46cc99e
Merge branch 'master' into fix-arb-on-orbit
fionnachan Apr 9, 2024
85d3f09
Merge remote-tracking branch 'origin/master' into fix-arb-on-orbit
fionnachan Apr 17, 2024
763ed06
Merge branch 'master' into fix-arb-on-orbit
fionnachan Apr 17, 2024
fbe590d
Merge branch 'master' into fix-arb-on-orbit
fionnachan Apr 22, 2024
e281aab
Merge remote-tracking branch 'origin/master' into fix-arb-on-orbit
fionnachan Jun 14, 2024
f82407f
clean up
fionnachan Jun 14, 2024
834f875
clean up
fionnachan Jun 14, 2024
0a5d807
Merge branch 'master' into fix-arb-on-orbit
fionnachan Jun 20, 2024
1b8bb4e
Merge branch 'master' into fix-arb-on-orbit
fionnachan Jul 3, 2024
3642076
Merge remote-tracking branch 'origin/master' into fix-arb-on-orbit
fionnachan Jul 22, 2024
6c5b341
Merge remote-tracking branch 'origin/master' into fix-arb-on-orbit
fionnachan Jul 26, 2024
ba84a9c
Merge branch 'master' into fix-arb-on-orbit
fionnachan Jul 31, 2024
2fcee98
Merge branch 'master' into fix-arb-on-orbit
fionnachan Aug 8, 2024
81d8159
Merge branch 'master' into fix-arb-on-orbit
fionnachan Aug 12, 2024
f3d3516
Merge branch 'master' into fix-arb-on-orbit
fionnachan Aug 19, 2024
d442ca2
Merge branch 'master' into fix-arb-on-orbit
fionnachan Aug 20, 2024
6749488
Merge branch 'master' into fix-arb-on-orbit
fionnachan Aug 21, 2024
c77b94a
Merge branch 'master' into fix-arb-on-orbit
fionnachan Aug 27, 2024
a08a994
Merge branch 'master' into fix-arb-on-orbit
fionnachan Aug 28, 2024
6b421fb
Merge branch 'master' into fix-arb-on-orbit
fionnachan Aug 30, 2024
2bd9c55
Merge branch 'master' into fix-arb-on-orbit
fionnachan Sep 2, 2024
27389c9
Merge branch 'master' into fix-arb-on-orbit
fionnachan Sep 3, 2024
53ca4c3
Merge branch 'master' into fix-arb-on-orbit
fionnachan Sep 3, 2024
bf52145
Merge remote-tracking branch 'origin/master' into fix-arb-on-orbit
fionnachan Sep 16, 2024
90da13d
Merge remote-tracking branch 'origin/master' into fix-arb-on-orbit
fionnachan Sep 20, 2024
e7379fa
Merge branch 'master' into fix-arb-on-orbit
fionnachan Oct 22, 2024
fca8881
Merge branch 'master' into fix-arb-on-orbit
fionnachan Nov 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function TokenImportDialog({

const selectToken = useCallback(
async (_token: ERC20BridgeToken) => {
await token.updateTokenData(_token.address)
await token.updateTokenData(_token.address.toLowerCase())
actions.app.setSelectedToken(_token)
},
[token, actions]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { Chain } from 'wagmi'

import { Loader } from '../common/atoms/Loader'
import { useAppState } from '../../state'
import {
listIdsToNames,
SPECIAL_ARBITRUM_TOKEN_TOKEN_LIST_ID
} from '../../util/TokenListUtils'
import { listIdsToNames } from '../../util/TokenListUtils'
import { formatAmount } from '../../util/NumberUtils'
import { shortenAddress } from '../../util/CommonUtils'
import {
Expand All @@ -20,6 +17,7 @@ import {
sanitizeTokenName,
sanitizeTokenSymbol
} from '../../util/TokenUtils'
import { isArbitrumToken as isArbitrumTokenCheck } from '../../util/ArbTokenUtils'
import { SafeImage } from '../common/SafeImage'
import { getExplorerUrl, getNetworkName } from '../../util/networks'
import { Tooltip } from '../common/Tooltip'
Expand Down Expand Up @@ -178,22 +176,16 @@ function useTokenInfo(token: ERC20BridgeToken | null) {

const balance = useBalanceOnSourceChain(token)

const isArbitrumToken = useMemo(() => {
if (!token) {
return false
}

return token.listIds.has(SPECIAL_ARBITRUM_TOKEN_TOKEN_LIST_ID)
}, [token])
const isArbitrumToken = isArbitrumTokenCheck(token)

const isPotentialFakeArbitrumToken = useMemo(() => {
if (!token || isArbitrumToken) {
return false
}

return (
token.name.toLowerCase().startsWith('arb') ||
token.symbol.toLowerCase().startsWith('arb')
token.name.toLowerCase().startsWith('arbitrum') ||
token.symbol.toLowerCase() === 'arb'
Comment on lines +187 to +188
Copy link
Member Author

Choose a reason for hiding this comment

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

)
}, [token, isArbitrumToken])

Expand Down Expand Up @@ -249,6 +241,8 @@ function TokenBalance({ token }: { token: ERC20BridgeToken | null }) {
isTokenArbitrumOneNativeUSDC(token?.address) ||
isTokenArbitrumSepoliaNativeUSDC(token?.address)

const isArbitrumToken = isArbitrumTokenCheck(token)

const tokenIsAddedToTheBridge = useMemo(() => {
// Can happen when switching networks.
if (typeof bridgeTokens === 'undefined') {
Expand All @@ -263,8 +257,12 @@ function TokenBalance({ token }: { token: ERC20BridgeToken | null }) {
return true
}

return typeof bridgeTokens[token.address] !== 'undefined'
}, [bridgeTokens, isArbitrumNativeUSDC, token])
if (isArbitrumToken) {
return true
}
Comment on lines +260 to +262
Copy link
Member Author

Choose a reason for hiding this comment

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

never show the "Import" text for Arb token


return typeof bridgeTokens[token.address.toLowerCase()] !== 'undefined'
}, [bridgeTokens, isArbitrumNativeUSDC, isArbitrumToken, token])

if (!tokenIsAddedToTheBridge) {
return <span className="arb-hover text-sm">Import</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ function TokenListRow({ tokenList }: { tokenList: BridgeTokenList }) {
app: { arbTokenBridge }
} = useAppState()
const { bridgeTokens, token } = arbTokenBridge
const [networks] = useNetworks()
const { childChain, parentChain } = useNetworksRelationship(networks)

const toggleTokenList = useCallback(
(bridgeTokenList: BridgeTokenList, isActive: boolean) => {
if (isActive) {
token.removeTokensFromList(bridgeTokenList.id)
} else {
addBridgeTokenListToBridge(bridgeTokenList, arbTokenBridge)
addBridgeTokenListToBridge({
bridgeTokenList,
arbTokenBridge,
parentChainId: parentChain.id,
childChainId: childChain.id
})
}
},
[arbTokenBridge, token]
[arbTokenBridge, childChain.id, parentChain.id, token]
)

const isActive = Object.keys(bridgeTokens ?? []).some(address => {
Expand Down Expand Up @@ -311,9 +318,9 @@ function TokensPanel({
return true
}

// Always show official ARB token except from or to Orbit chain
// Always show official ARB token
if (token?.listIds.has(SPECIAL_ARBITRUM_TOKEN_TOKEN_LIST_ID)) {
return !isOrbitChain
return true
}

const balance = getBalance(address)
Expand Down Expand Up @@ -554,7 +561,9 @@ export function TokenSearch({
return
}

if (!_token.address) {
const lowercasedTokenAddress = _token.address.toLowerCase()

if (!lowercasedTokenAddress) {
return
}

Expand All @@ -566,8 +575,8 @@ export function TokenSearch({
try {
// Native USDC on L2 won't have a corresponding L1 address
const isL2NativeUSDC =
isTokenArbitrumOneNativeUSDC(_token.address) ||
isTokenArbitrumSepoliaNativeUSDC(_token.address)
isTokenArbitrumOneNativeUSDC(lowercasedTokenAddress) ||
isTokenArbitrumSepoliaNativeUSDC(lowercasedTokenAddress)

if (isL2NativeUSDC) {
if (isLoadingAccountType) {
Expand Down Expand Up @@ -596,7 +605,7 @@ export function TokenSearch({
name: 'USD Coin',
type: TokenType.ERC20,
symbol: 'USDC',
address: _token.address,
address: lowercasedTokenAddress,
l2Address: childChainUsdcAddress,
decimals: 6,
listIds: new Set()
Expand All @@ -609,8 +618,8 @@ export function TokenSearch({
}

// Token not added to the bridge, so we'll handle importing it
if (typeof bridgeTokens[_token.address] === 'undefined') {
setTokenQueryParam(_token.address)
if (typeof bridgeTokens[lowercasedTokenAddress] === 'undefined') {
setTokenQueryParam(lowercasedTokenAddress)
return
}

Expand All @@ -619,19 +628,19 @@ export function TokenSearch({
}

const data = await fetchErc20Data({
address: _token.address,
address: lowercasedTokenAddress,
provider: parentChainProvider
})

if (data) {
token.updateTokenData(_token.address)
token.updateTokenData(lowercasedTokenAddress)
setSelectedToken({
...erc20DataToErc20BridgeToken(data),
l2Address: _token.l2Address
})
}

if (isTransferDisabledToken(_token.address, childChain.id)) {
if (isTransferDisabledToken(lowercasedTokenAddress, childChain.id)) {
openTransferDisabledDialog()
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect } from 'react'
import { useAccount } from 'wagmi'
import { useNetworks } from '../../hooks/useNetworks'
import { useNetworksRelationship } from '../../hooks/useNetworksRelationship'

Expand All @@ -15,19 +14,14 @@ const TokenListSyncer = (): JSX.Element => {
const {
app: { arbTokenBridge, arbTokenBridgeLoaded }
} = useAppState()
const { address: walletAddress } = useAccount()
const [networks] = useNetworks()
const { childChain } = useNetworksRelationship(networks)
const { childChain, parentChain } = useNetworksRelationship(networks)

useEffect(() => {
if (!arbTokenBridgeLoaded) {
return
}

if (!walletAddress) {
return
}
Comment on lines -27 to -29
Copy link
Member Author

Choose a reason for hiding this comment

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

didn't use it at all


const tokenListsToSet = BRIDGE_TOKEN_LISTS.filter(bridgeTokenList => {
// Always load the Arbitrum Token token list
if (bridgeTokenList.isArbitrumTokenTokenList) {
Expand All @@ -41,9 +35,14 @@ const TokenListSyncer = (): JSX.Element => {
})

tokenListsToSet.forEach(bridgeTokenList => {
addBridgeTokenListToBridge(bridgeTokenList, arbTokenBridge)
addBridgeTokenListToBridge({
bridgeTokenList,
arbTokenBridge,
parentChainId: parentChain.id,
childChainId: childChain.id
})
})
}, [walletAddress, childChain.id, arbTokenBridgeLoaded])
}, [childChain.id, arbTokenBridgeLoaded, parentChain.id])

return <></>
}
Expand Down
15 changes: 14 additions & 1 deletion packages/arb-token-bridge-ui/src/hooks/arbTokenBridge.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ import {
Transaction,
ParentToChildMessageData
} from './useTransactions'
import { ChainId } from '../util/networks'

export { OutgoingMessageState }

export type AddTokensFromListArgs = {
arbTokenList: TokenList
listId: number
parentChainId: ChainId
childChainId: ChainId
}

export enum TokenType {
ERC20 = 'ERC20'
}
Expand Down Expand Up @@ -147,7 +155,12 @@ export interface ArbTokenBridgeEth {
export interface ArbTokenBridgeToken {
add: (erc20L1orL2Address: string) => Promise<void>
addL2NativeToken: (erc20L2Address: string) => void
addTokensFromList: (tokenList: TokenList, listID: number) => void
addTokensFromList: ({
arbTokenList,
listId,
parentChainId,
childChainId
}: AddTokensFromListArgs) => void
removeTokensFromList: (listID: number) => void
updateTokenData: (l1Address: string) => Promise<void>
triggerOutbox: (params: {
Expand Down
46 changes: 29 additions & 17 deletions packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useCallback, useState, useMemo } from 'react'
import { useCallback, useState } from 'react'
import { Chain, useAccount } from 'wagmi'
import { BigNumber } from 'ethers'
import { Signer } from '@ethersproject/abstract-signer'
import { JsonRpcProvider } from '@ethersproject/providers'
import { useLocalStorage } from '@rehooks/local-storage'
import { TokenList } from '@uniswap/token-lists'
import {
EventArgs,
ChildToParentMessage,
Expand All @@ -19,7 +18,8 @@ import {
ERC20BridgeToken,
L2ToL1EventResultPlus,
TokenType,
L2ToL1EventResult
L2ToL1EventResult,
AddTokensFromListArgs
} from './arbTokenBridge.types'
import { useBalance } from './useBalance'
import {
Expand All @@ -33,6 +33,7 @@ import {
import { getL2NativeToken } from '../util/L2NativeUtils'
import { CommonAddress } from '../util/CommonAddressUtils'
import { isNetwork } from '../util/networks'
import { isArbitrumTokenList } from '../util/TokenListUtils'
import { useDestinationAddressStore } from '../components/TransferPanel/AdvancedSettings'
import { isValidTeleportChainPair } from '@/token-bridge-sdk/teleport'
import { getProviderForChainId } from '@/token-bridge-sdk/utils'
Expand Down Expand Up @@ -135,8 +136,6 @@ export const useArbTokenBridge = (
React.Dispatch<void>
]

const l1NetworkID = useMemo(() => String(l1.network.id), [l1.network.id])

const [transactions, { addTransaction, updateTransaction }] =
useTransactions()

Expand All @@ -157,9 +156,13 @@ export const useArbTokenBridge = (
})
}

const addTokensFromList = async (arbTokenList: TokenList, listId: number) => {
const l1ChainID = l1.network.id
const l2ChainID = l2.network.id
const addTokensFromList = async ({
arbTokenList,
listId,
parentChainId,
childChainId
}: AddTokensFromListArgs) => {
const isChildChainOrbit = isNetwork(childChainId).isOrbitChain

const bridgeTokensToAdd: ContractStorage<ERC20BridgeToken> = {}

Expand All @@ -169,7 +172,7 @@ export const useArbTokenBridge = (
const { address, name, symbol, extensions, decimals, logoURI, chainId } =
tokenData

if (![l1ChainID, l2ChainID].includes(chainId)) {
if (![parentChainId, childChainId].includes(chainId)) {
continue
}

Expand Down Expand Up @@ -205,18 +208,25 @@ export const useArbTokenBridge = (
})()

if (bridgeInfo) {
const l1Address = bridgeInfo[l1NetworkID]?.tokenAddress.toLowerCase()

if (!l1Address) {
const isArbitrumTokenAndIsChildChainOrbit =
isArbitrumTokenList(listId) && isChildChainOrbit
const parentChainAddress = isArbitrumTokenAndIsChildChainOrbit
? address.toLowerCase()
: bridgeInfo[parentChainId]?.tokenAddress.toLowerCase()
const childChainAddress = isArbitrumTokenAndIsChildChainOrbit
? undefined
: address.toLowerCase()

if (!parentChainAddress) {
return
}

bridgeTokensToAdd[l1Address] = {
bridgeTokensToAdd[parentChainAddress] = {
name,
type: TokenType.ERC20,
symbol,
address: l1Address,
l2Address: address.toLowerCase(),
address: parentChainAddress,
l2Address: childChainAddress,
decimals,
logoURI,
listIds: new Set([listId])
Expand Down Expand Up @@ -257,10 +267,10 @@ export const useArbTokenBridge = (

// USDC is not on any token list as it's unbridgeable
// but we still want to detect its balance on user's wallet
if (isNetwork(l2ChainID).isArbitrumOne) {
if (isNetwork(childChainId).isArbitrumOne) {
l2Addresses.push(CommonAddress.ArbitrumOne.USDC)
}
if (isNetwork(l2ChainID).isArbitrumSepolia) {
if (isNetwork(childChainId).isArbitrumSepolia) {
l2Addresses.push(CommonAddress.ArbitrumSepolia.USDC)
}

Expand All @@ -270,6 +280,7 @@ export const useArbTokenBridge = (
return
}
const { address, l2Address } = tokenToAdd

if (address) {
l1Addresses.push(address)
}
Expand Down Expand Up @@ -409,6 +420,7 @@ export const useArbTokenBridge = (
}
},
[
destinationAddress,
bridgeTokens,
setBridgeTokens,
updateErc20L1Balance,
Expand Down
Loading
Loading