From 91284b933e4ae971bcfc173eb1ee9779a72a29f5 Mon Sep 17 00:00:00 2001 From: Alfetopito Date: Fri, 24 May 2024 16:41:30 +0100 Subject: [PATCH] fix: overwrite bridge addresses when there are known addresses which differ --- src/public/ArbitrumOneUniswapTokensList.json | 24 ++++----- src/scripts/generateBridgeList.ts | 54 ++++++++++++++++++++ 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/public/ArbitrumOneUniswapTokensList.json b/src/public/ArbitrumOneUniswapTokensList.json index 15d60872..c587a6c2 100644 --- a/src/public/ArbitrumOneUniswapTokensList.json +++ b/src/public/ArbitrumOneUniswapTokensList.json @@ -63,7 +63,7 @@ }, { "chainId": 42161, - "address": "0xcee84bf3106ded890b9730e2b89f4a4da84ad387", + "address": "0xFA5Ed56A203466CbBC2430a43c66b9D8723528E7", "name": "agEur", "symbol": "agEUR", "decimals": 18, @@ -168,7 +168,7 @@ { "chainId": 42161, "name": "Arbitrum", - "address": "0xad17a0a8b4d923d20991eef1a8e4a6b1a61bb51a", + "address": "0x912CE59144191C1204E64559FE8253a0e49E6548", "symbol": "ARB", "decimals": 18, "logoURI": "https://arbitrum.foundation/logo.png" @@ -247,7 +247,7 @@ }, { "chainId": 42161, - "address": "0xf701d1d701ad494d7e3ec69bd1dd5d5443651487", + "address": "0x23ee2343B892b1BB63503a4FAbc840E0e2C6810f", "name": "Axelar", "symbol": "AXL", "decimals": 6, @@ -399,7 +399,7 @@ }, { "chainId": 42161, - "address": "0x1ed190c87ca0a1b322b62dc1c0914915bd563249", + "address": "0x4E51aC49bC5e2d87e0EF713E9e5AB2D71EF4F336", "name": "Celo native asset (Wormhole)", "symbol": "CELO", "decimals": 18, @@ -535,7 +535,7 @@ }, { "name": "Dai Stablecoin", - "address": "0x7cec86400dfbe0d75b1ec468767d044b21a39c25", + "address": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", "symbol": "DAI", "decimals": 18, "chainId": 42161, @@ -815,7 +815,7 @@ }, { "chainId": 42161, - "address": "0x23a941036ae778ac51ab04cea08ed6e2fe103614", + "address": "0x9623063377AD1B27544C965cCd7342f7EA7e88C7", "name": "The Graph", "symbol": "GRT", "decimals": 18, @@ -839,7 +839,7 @@ }, { "chainId": 42161, - "address": "0x3fecb65993e4835884baf6452d1ebfdbc3a78480", + "address": "0x589d35656641d6aB57A545F08cf473eCD9B6D5F7", "name": "GYEN", "symbol": "GYEN", "decimals": 6, @@ -1031,7 +1031,7 @@ }, { "chainId": 42161, - "address": "0xca65f362bde046c646f3d6cf12d6708af5029275", + "address": "0x289ba1701C2F088cf0faf8B3705246331cB8A839", "name": "Livepeer", "symbol": "LPT", "decimals": 18, @@ -1394,7 +1394,7 @@ "name": "Marlin", "symbol": "POND", "logoURI": "https://assets.coingecko.com/coins/images/8903/thumb/POND_200x200.png?1622515451", - "address": "0x5f5dbb71841ac60e6c58a772954e8c00678fd6a4", + "address": "0xdA0a57B710768ae17941a9Fa33f8B720c8bD9ddD", "decimals": 18 }, { @@ -1911,7 +1911,7 @@ }, { "name": "USDCoin", - "address": "0xbfbd7a22dd2cae93400a39f9273de3899e349c37", + "address": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", "symbol": "USDC", "decimals": 6, "chainId": 42161, @@ -1919,7 +1919,7 @@ }, { "name": "Tether USD", - "address": "0xc9f0cacf9a9d451c7133597fb379eb39b80efa77", + "address": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", "symbol": "USDT", "decimals": 6, "chainId": 42161, @@ -1959,7 +1959,7 @@ }, { "name": "Wrapped Ether", - "address": "0x82ea8a97bfb03dc83d214feb1df6330f5c3d65da", + "address": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", "symbol": "WETH", "decimals": 18, "chainId": 42161, diff --git a/src/scripts/generateBridgeList.ts b/src/scripts/generateBridgeList.ts index 723f12d1..21dc3525 100644 --- a/src/scripts/generateBridgeList.ts +++ b/src/scripts/generateBridgeList.ts @@ -13,6 +13,15 @@ type Call = { callData: string } +type Extensions = { + bridgeInfo?: Record< + SupportedChainId, + { + tokenAddress?: string + } + > +} + async function generateBridgedList( chainId: SupportedChainId, tokenListSource: string | TokenList, @@ -20,6 +29,7 @@ async function generateBridgedList( bridgeContractAbi: ContractInterface, methodName: string, outputFilePath: string, + tokensToReplace: Record = {}, ): Promise { const provider = getProvider(chainId, undefined) const bridgeContract = new Contract(bridgeContractAddress, bridgeContractAbi, provider) @@ -33,6 +43,8 @@ async function generateBridgedList( const calls = tokensList.tokens.reduce<{ token: TokenInfo; call: Call }[]>((acc, token) => { // Take only Mainnet tokens if (token.chainId !== SupportedChainId.MAINNET) return acc + // Do not check for tokens we want to skip/replace + if (tokensToReplace[token.address.toLowerCase()] === null) return acc // A call to resolve token address in target chain const call = { @@ -60,9 +72,45 @@ async function generateBridgedList( // Get rid of tokens that are not known by the bridge contract if (!token || address === ZERO_ADDRESS) return acc + const toReplace = tokensToReplace[token.address.toLowerCase()] + if (toReplace !== undefined) { + if (toReplace === null) { + // Do not add to the list + return acc + } + + // Replace the fetched address with the one provided + acc.push({ + ...token, + chainId, + address: toReplace, + extensions: undefined, + }) + + return acc + } // Copy everything from the Mainnet token and override address and chainId // Let's hope no one deploys the same token in a different networks with different data + const extensions = token.extensions as Extensions + const tokenAddress = extensions?.bridgeInfo?.[chainId]?.tokenAddress + + if (tokenAddress && tokenAddress.toLowerCase() !== address.toLowerCase()) { + console.log( + `TokenList extension contains address different than returned by bridge. Extension: ${tokenAddress} Bridge: ${address}`, + ) + + acc.push({ + ...token, + chainId, + address: tokenAddress, + extensions: undefined, + }) + + return acc + } + + // Use bridge address acc.push({ ...token, chainId, @@ -102,5 +150,11 @@ export async function generateArbitrumOneChainList(source: string | TokenList, r ARBITRUM_BRIDGE_ABI, 'calculateL2TokenAddress', resultFile, + // { + // // USDC + // '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': '0xaf88d065e77c8cc2239327c5edb3a432268e5831', + // // WETH + // '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', + // }, ) }