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 4 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 @@ -101,10 +101,11 @@ export function TokenImportDialog({
const { openDialog: openTransferDisabledDialog } =
useTransferDisabledDialogStore()
const { isOpen } = useTokenImportDialogStore()
const { data: l1Address, isLoading: isL1AddressLoading } = useERC20L1Address({
eitherL1OrL2Address: tokenAddress,
l2Provider: childChainProvider
})
const { data: tokenAddressOnParentChain, isLoading: isL1AddressLoading } =
useERC20L1Address({
eitherL1OrL2Address: tokenAddress,
l2Provider: childChainProvider
})

const modalTitle = useMemo(() => {
switch (status) {
Expand All @@ -125,18 +126,23 @@ export function TokenImportDialog({
}, [status])

const getL1TokenDataFromL1Address = useCallback(async () => {
if (!l1Address || !walletAddress) {
if (!tokenAddressOnParentChain || !walletAddress) {
return
}

const erc20Params = { address: l1Address, provider: parentChainProvider }
const erc20Params = {
address: tokenAddressOnParentChain,
provider: parentChainProvider
}

if (!(await isValidErc20(erc20Params))) {
throw new Error(`${l1Address} is not a valid ERC-20 token`)
throw new Error(
`${tokenAddressOnParentChain} is not a valid ERC-20 token`
)
}

return fetchErc20Data(erc20Params)
}, [parentChainProvider, walletAddress, l1Address])
}, [parentChainProvider, walletAddress, tokenAddressOnParentChain])

const searchForTokenInLists = useCallback(
(erc20L1Address: string): TokenListSearchResult => {
Expand Down Expand Up @@ -192,17 +198,17 @@ export function TokenImportDialog({
return
}

if (!isL1AddressLoading && !l1Address) {
if (!isL1AddressLoading && !tokenAddressOnParentChain) {
setStatus(ImportStatus.ERROR)
return
}

if (l1Address) {
const searchResult1 = searchForTokenInLists(l1Address)
if (tokenAddressOnParentChain) {
const searchResult = searchForTokenInLists(tokenAddressOnParentChain)

if (searchResult1.found) {
setStatus(searchResult1.status)
setTokenToImport(searchResult1.token)
if (searchResult.found) {
setStatus(searchResult.status)
setTokenToImport(searchResult.token)

return
}
Expand All @@ -228,7 +234,7 @@ export function TokenImportDialog({
getL1TokenDataFromL1Address,
isL1AddressLoading,
isOpen,
l1Address,
tokenAddressOnParentChain,
searchForTokenInLists
])

Expand All @@ -237,11 +243,11 @@ export function TokenImportDialog({
return
}

if (isL1AddressLoading && !l1Address) {
if (isL1AddressLoading && !tokenAddressOnParentChain) {
return
}

const foundToken = tokensFromUser[l1Address || tokenAddress]
const foundToken = tokensFromUser[tokenAddressOnParentChain || tokenAddress]

if (typeof foundToken === 'undefined') {
return
Expand All @@ -256,7 +262,7 @@ export function TokenImportDialog({
isL1AddressLoading,
tokenAddress,
isOpen,
l1Address,
tokenAddressOnParentChain,
onClose,
selectToken,
selectedToken,
Expand Down Expand Up @@ -284,28 +290,31 @@ export function TokenImportDialog({

setIsImportingToken(true)

if (!l1Address) {
if (!tokenAddressOnParentChain) {
return
}

if (typeof bridgeTokens[l1Address] !== 'undefined') {
if (typeof bridgeTokens[tokenAddressOnParentChain] !== 'undefined') {
// Token is already added to the bridge
onClose(true)
selectToken(tokenToImport!)
} else {
// Token is not added to the bridge, so we add it
storeNewToken(l1Address).catch(() => {
storeNewToken(tokenAddressOnParentChain).catch(() => {
setStatus(ImportStatus.ERROR)
})
}

// do not allow import of withdraw-only tokens at deposit mode
if (isDepositMode && isWithdrawOnlyToken(l1Address, childChain.id)) {
if (
isDepositMode &&
isWithdrawOnlyToken(tokenAddressOnParentChain, childChain.id)
) {
openTransferDisabledDialog()
return
}

if (isTransferDisabledToken(l1Address, childChain.id)) {
if (isTransferDisabledToken(tokenAddressOnParentChain, childChain.id)) {
openTransferDisabledDialog()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import { Chain, useAccount } 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 {
isArbitrumToken as isArbitrumTokenCheck,
isTokenArbitrumOneNativeUSDC,
isTokenArbitrumSepoliaNativeUSDC,
sanitizeTokenName,
Expand Down Expand Up @@ -123,7 +121,10 @@ export function TokenRow({
return nativeCurrency.symbol
}, [token, nativeCurrency.symbol, chainId])

const isL2NativeToken = useMemo(() => token?.isL2Native ?? false, [token])
const isChildChainNativeToken = useMemo(
chrstph-dvx marked this conversation as resolved.
Show resolved Hide resolved
() => token?.isL2Native ?? false,
[token]
)
const tokenIsArbOneNativeUSDC = useMemo(
() => isTokenArbitrumOneNativeUSDC(token?.address),
[token]
Expand Down Expand Up @@ -186,13 +187,7 @@ export function TokenRow({
token
])

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

return token.listIds.has(SPECIAL_ARBITRUM_TOKEN_TOKEN_LIST_ID)
}, [token])
const isArbitrumToken = useMemo(() => isArbitrumTokenCheck(token), [token])
chrstph-dvx marked this conversation as resolved.
Show resolved Hide resolved

const isPotentialFakeArbitrumToken = useMemo(() => {
if (!token || isArbitrumToken) {
Expand Down Expand Up @@ -252,15 +247,20 @@ export function TokenRow({
return true
}

return typeof bridgeTokens[token.address] !== 'undefined'
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,
isArbitrumToken,
token,
tokenIsArbOneNativeUSDC,
tokenIsArbSepoliaNativeUSDC
])

const tokenHasL2Address = useMemo(() => {
const tokenHasChildChainAddress = useMemo(() => {
if (!token) {
return true
}
Expand All @@ -269,16 +269,16 @@ export function TokenRow({
}, [token])

const tokenIsBridgeable = useMemo(() => {
if (isL2NativeToken) {
if (isChildChainNativeToken) {
return false
}

if (isDepositMode) {
return true
}

return tokenHasL2Address
}, [isDepositMode, tokenHasL2Address, isL2NativeToken])
return tokenHasChildChainAddress
}, [isDepositMode, tokenHasChildChainAddress, isChildChainNativeToken])

const isCustomFeeTokenRow = token === null && nativeCurrency.isCustom

Expand Down Expand Up @@ -391,7 +391,7 @@ export function TokenRow({
<div className="flex w-full justify-between">
{isDepositMode ? (
<>
{isL2NativeToken ? (
{isChildChainNativeToken ? (
<BlockExplorerTokenLink
chain={childChain}
address={token.address}
Expand All @@ -405,7 +405,7 @@ export function TokenRow({
</>
) : (
<>
{tokenHasL2Address ? (
{tokenHasChildChainAddress ? (
<BlockExplorerTokenLink
chain={childChain}
address={token.l2Address}
Expand All @@ -420,7 +420,7 @@ export function TokenRow({
)}
{tokenIsBridgeable && tokenBalanceContent}
</div>
{isL2NativeToken ? (
{isChildChainNativeToken ? (
<span className="flex gap-1 text-xs font-normal">
{`This token is native to ${getNetworkName(
childChain.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function TokenListsPanel() {
app: { arbTokenBridge }
} = useAppState()
const [networks] = useNetworks()
const { childChain } = useNetworksRelationship(networks)
const { childChain, parentChain } = useNetworksRelationship(networks)
const { bridgeTokens, token } = arbTokenBridge

const listsToShow: BridgeTokenList[] = useMemo(() => {
Expand All @@ -98,7 +98,12 @@ function TokenListsPanel() {
if (isActive) {
token.removeTokensFromList(bridgeTokenList.id)
} else {
addBridgeTokenListToBridge(bridgeTokenList, arbTokenBridge)
addBridgeTokenListToBridge({
bridgeTokenList,
arbTokenBridge,
parentChainId: parentChain.id,
childChainId: childChain.id
})
}
}

Expand Down Expand Up @@ -273,9 +278,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 @@ -501,7 +506,9 @@ export function TokenSearch({ close }: { close: () => void }) {
return
}

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

if (!lowercasedTokenAddress) {
return
}

Expand All @@ -512,29 +519,31 @@ export function TokenSearch({ close }: { close: () => void }) {
try {
// Native USDC on L2 won't have a corresponding L1 address
const isNativeUSDC =
isTokenArbitrumOneNativeUSDC(_token.address) ||
isTokenArbitrumSepoliaNativeUSDC(_token.address)
isTokenArbitrumOneNativeUSDC(lowercasedTokenAddress) ||
isTokenArbitrumSepoliaNativeUSDC(lowercasedTokenAddress)

if (isNativeUSDC) {
if (isLoadingAccountType) {
return
}

updateUSDCBalances(_token.address)
updateUSDCBalances(lowercasedTokenAddress)
setSelectedToken({
name: 'USD Coin',
type: TokenType.ERC20,
symbol: 'USDC',
address: _token.address,
address: lowercasedTokenAddress,
decimals: 6,
listIds: new Set()
})
return
}

console.log('bridgeTokens!!! ', bridgeTokens)

// 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 @@ -543,25 +552,28 @@ export function TokenSearch({ close }: { close: () => void }) {
}

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
})
}

// do not allow import of withdraw-only tokens at deposit mode
if (isDepositMode && isWithdrawOnlyToken(_token.address, childChain.id)) {
if (
isDepositMode &&
isWithdrawOnlyToken(lowercasedTokenAddress, childChain.id)
) {
openTransferDisabledDialog()
return
}

if (isTransferDisabledToken(_token.address, childChain.id)) {
if (isTransferDisabledToken(lowercasedTokenAddress, childChain.id)) {
openTransferDisabledDialog()
return
}
Expand Down
Loading
Loading