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: Dynamically load tokenlists for Orbit chains #2135

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 @@ -34,9 +34,9 @@ import { TokenLogoFallback } from './TokenInfo'
import { useBalanceOnSourceChain } from '../../hooks/useBalanceOnSourceChain'
import { useSourceChainNativeCurrencyDecimals } from '../../hooks/useSourceChainNativeCurrencyDecimals'

function tokenListIdsToNames(ids: number[]): string {
function tokenListIdsToNames(ids: string[]): string {
return ids
.map((tokenListId: number) => listIdsToNames[tokenListId])
.map((tokenListId: string) => listIdsToNames[tokenListId])
.join(', ')
}

Expand Down Expand Up @@ -90,7 +90,7 @@ function TokenListInfo({ token }: { token: ERC20BridgeToken | null }) {
return 'Native USDC on Arbitrum Sepolia'
}

const listIds: Set<number> = token.listIds
const listIds: Set<string> = token.listIds
const listIdsSize = listIds.size
if (listIdsSize === 0) {
return 'Added by User'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { useSetInputAmount } from '../../hooks/TransferPanel/useSetInputAmount'

export const ARB_ONE_NATIVE_USDC_TOKEN = {
...ArbOneNativeUSDC,
listIds: new Set<number>(),
listIds: new Set<string>(),
type: TokenType.ERC20,
// the address field is for L1 address but native USDC does not have an L1 address
// the L2 address is used instead to avoid errors
Expand All @@ -57,7 +57,7 @@ export const ARB_ONE_NATIVE_USDC_TOKEN = {

export const ARB_SEPOLIA_NATIVE_USDC_TOKEN = {
...ArbOneNativeUSDC,
listIds: new Set<number>(),
listIds: new Set<string>(),
type: TokenType.ERC20,
address: CommonAddress.ArbitrumSepolia.USDC,
l2Address: CommonAddress.ArbitrumSepolia.USDC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const commonUSDC = {
type: TokenType.ERC20,
symbol: 'USDC',
decimals: 6,
listIds: new Set<number>()
listIds: new Set<string>()
}

export function useUpdateUSDCTokenData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface BridgeToken {
address: string
l2Address?: string
logoURI?: string
listIds: Set<number> // no listID indicates added by user
listIds: Set<string> // no listID indicates added by user
isL2Native?: boolean
}

Expand Down Expand Up @@ -140,8 +140,8 @@ export interface ArbTokenBridgeEth {
export interface ArbTokenBridgeToken {
add: (erc20L1orL2Address: string) => Promise<void>
addL2NativeToken: (erc20L2Address: string) => void
addTokensFromList: (tokenList: TokenList, listID: number) => void
removeTokensFromList: (listID: number) => void
addTokensFromList: (tokenList: TokenList, listID: string) => void
removeTokensFromList: (listID: string) => void
updateTokenData: (l1Address: string) => Promise<void>
triggerOutbox: (params: {
event: L2ToL1EventResultPlus
Expand Down
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useArbTokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const useArbTokenBridge = (

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

const removeTokensFromList = (listID: number) => {
const removeTokensFromList = (listID: string) => {
setBridgeTokens(prevBridgeTokens => {
const newBridgeTokens = { ...prevBridgeTokens }
for (const address in bridgeTokens) {
Expand All @@ -153,7 +153,7 @@ export const useArbTokenBridge = (
})
}

const addTokensFromList = async (arbTokenList: TokenList, listId: number) => {
const addTokensFromList = async (arbTokenList: TokenList, listId: string) => {
const l1ChainID = l1.network.id
const l2ChainID = l2.network.id

Expand Down
101 changes: 42 additions & 59 deletions packages/arb-token-bridge-ui/src/util/TokenListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import CoinGeckoLogo from '@/images/lists/coinGecko.svg'
import ArbitrumLogo from '@/images/lists/ArbitrumLogo.png'
import { ArbTokenBridge } from '../hooks/arbTokenBridge.types'
import { ChainId } from './networks'
import orbitChainsData from './orbitChainsData.json'

export const SPECIAL_ARBITRUM_TOKEN_TOKEN_LIST_ID = 0
export const SPECIAL_ARBITRUM_TOKEN_TOKEN_LIST_ID =
'SPECIAL_ARBITRUM_TOKEN_TOKEN_LIST_ID'

export interface BridgeTokenList {
id: number
id: string
originChainID: number
url: string
name: string
Expand All @@ -34,39 +36,39 @@ export const BRIDGE_TOKEN_LISTS: BridgeTokenList[] = [
isArbitrumTokenTokenList: true
},
{
id: 1,
id: '1',
originChainID: ChainId.ArbitrumOne,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/arbed_arb_whitelist_era.json',
name: 'Arbitrum Whitelist Era',
isDefault: true,
logoURI: ArbitrumLogo
},
{
id: 2,
id: '2',
Copy link
Member

Choose a reason for hiding this comment

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

we should unify the id syntax and use ${chain.chainId}_native or ${chain.chainId}_uniswap or _cmc etc, then tighten the type

originChainID: ChainId.ArbitrumOne,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/arbed_uniswap_labs_default.json',
name: 'Arbed Uniswap List',
isDefault: true,
logoURI: UniswapLogo
},
{
id: 4,
id: '4',
originChainID: ChainId.ArbitrumOne,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/arbed_coingecko.json',
name: 'Arbed CoinGecko List',
isDefault: true,
logoURI: CoinGeckoLogo
},
{
id: 5,
id: '5',
originChainID: ChainId.ArbitrumOne,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/arbed_coinmarketcap.json',
name: 'Arbed CMC List',
isDefault: false,
logoURI: CMCLogo
},
{
id: 6,
id: '6',
originChainID: ChainId.ArbitrumNova,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/42170_arbed_uniswap_labs_default.json',
name: 'Arbed Uniswap List',
Expand All @@ -78,7 +80,7 @@ export const BRIDGE_TOKEN_LISTS: BridgeTokenList[] = [
// TODO: remove list for chain ID 412346 after fix:
// https://github.com/OffchainLabs/arb-token-bridge/issues/564
{
id: 9,
id: '9',
// Local node
originChainID: ChainId.ArbitrumLocal,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/421613_arbed_coinmarketcap.json',
Expand All @@ -87,7 +89,7 @@ export const BRIDGE_TOKEN_LISTS: BridgeTokenList[] = [
logoURI: CMCLogo
},
{
id: 10,
id: '10',
originChainID: ChainId.ArbitrumSepolia,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/421614_arbed_uniswap_labs.json',
name: 'Arbed Uniswap List',
Expand All @@ -96,76 +98,57 @@ export const BRIDGE_TOKEN_LISTS: BridgeTokenList[] = [
},
// CoinGecko
{
id: 11,
id: '11',
originChainID: ChainId.ArbitrumNova,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/42170_arbed_coingecko.json',
name: 'Arbed CoinGecko List',
isDefault: true,
logoURI: CoinGeckoLogo
},
{
id: 13,
id: '13',
originChainID: ChainId.ArbitrumSepolia,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/421614_arbed_coingecko.json',
name: 'Arbed CoinGecko List',
isDefault: true,
logoURI: CoinGeckoLogo
},
// Orbit
{
id: 14,
// Xai
originChainID: 660279,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/660279_arbed_uniswap_labs.json',
name: 'Arbed Uniswap List',
isDefault: true,
logoURI: UniswapLogo
},
{
id: 660279,
id: '660279',
// Xai
originChainID: 660279,
url: 'tokenLists/660279_default.json',
name: 'XAI Default List',
isDefault: true,
logoURI: '/images/XaiLogo.svg'
},
{
id: 15,
// Rari
originChainID: 1380012617,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/1380012617_arbed_uniswap_labs.json',
name: 'Arbed Uniswap List',
isDefault: true,
logoURI: UniswapLogo
},
{
id: 16,
// Muster
originChainID: 4078,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/4078_arbed_uniswap_labs.json',
name: 'Arbed Uniswap List',
isDefault: true,
logoURI: UniswapLogo
},
{
id: 17,
// Proof of Play Apex
originChainID: 70700,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/70700_arbed_uniswap_labs.json',
name: 'Arbed Uniswap List',
isDefault: true,
logoURI: UniswapLogo
},
{
id: 19,
// SX Network
originChainID: 4162,
url: 'https://tokenlist.arbitrum.io/ArbTokenLists/4162_arbed_uniswap_labs.json',
name: 'Arbed Uniswap List',
isDefault: true,
logoURI: UniswapLogo
}
// For all orbit chains,
...orbitChainsData.mainnet
.concat(orbitChainsData.testnet)
.reduce((acc, chain) => {
// Only include arbified native token list for L3 settling to ArbOne
if (chain.parentChainId === ChainId.ArbitrumOne) {
acc.push({
id: `${chain.chainId}_native`,
originChainID: chain.chainId,
url: `https://tokenlist.arbitrum.io/ArbTokenLists/${chain.chainId}_arbed_native_list.json`,
name: `${chain.name} Arbed L2 native list`,
Copy link
Member

Choose a reason for hiding this comment

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

this is actually a bit confusing on the UI

maybe sth like Proof of Play Apex default list?

image

Copy link
Member

@fionnachan fionnachan Dec 17, 2024

Choose a reason for hiding this comment

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

a note: if the user has some local storage (visited the bridge before), these new lists seem to be off by default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Updated to ${chainName} default list
  2. Already happening in production, fixed in refactor: Remove useArbTokenBridge from store 1/3 #2088 to 2090

isDefault: true,
logoURI: ArbitrumLogo
})
}

acc.push({
id: `${chain.chainId}_uniswap`,
originChainID: chain.chainId,
url: `https://tokenlist.arbitrum.io/ArbTokenLists/${chain.chainId}_arbed_uniswap_labs.json`,
name: `${chain.name} Arbed Uniswap List`,
fionnachan marked this conversation as resolved.
Show resolved Hide resolved
isDefault: true,
logoURI: UniswapLogo
})

return acc
}, [] as BridgeTokenList[])
]

export const listIdsToNames: { [key: string]: string } = {}
Expand All @@ -176,7 +159,7 @@ BRIDGE_TOKEN_LISTS.forEach(bridgeTokenList => {

export interface TokenListWithId extends TokenList {
l2ChainId: string
bridgeTokenListId: number
bridgeTokenListId: string
isValid?: boolean
}

Expand Down
Loading