Skip to content

Commit

Permalink
fix: overwrite bridge addresses when there are known addresses which …
Browse files Browse the repository at this point in the history
…differ
  • Loading branch information
alfetopito committed May 24, 2024
1 parent 8f62814 commit 91284b9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/public/ArbitrumOneUniswapTokensList.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
{
"chainId": 42161,
"address": "0xcee84bf3106ded890b9730e2b89f4a4da84ad387",
"address": "0xFA5Ed56A203466CbBC2430a43c66b9D8723528E7",
"name": "agEur",
"symbol": "agEUR",
"decimals": 18,
Expand Down Expand Up @@ -168,7 +168,7 @@
{
"chainId": 42161,
"name": "Arbitrum",
"address": "0xad17a0a8b4d923d20991eef1a8e4a6b1a61bb51a",
"address": "0x912CE59144191C1204E64559FE8253a0e49E6548",
"symbol": "ARB",
"decimals": 18,
"logoURI": "https://arbitrum.foundation/logo.png"
Expand Down Expand Up @@ -247,7 +247,7 @@
},
{
"chainId": 42161,
"address": "0xf701d1d701ad494d7e3ec69bd1dd5d5443651487",
"address": "0x23ee2343B892b1BB63503a4FAbc840E0e2C6810f",
"name": "Axelar",
"symbol": "AXL",
"decimals": 6,
Expand Down Expand Up @@ -399,7 +399,7 @@
},
{
"chainId": 42161,
"address": "0x1ed190c87ca0a1b322b62dc1c0914915bd563249",
"address": "0x4E51aC49bC5e2d87e0EF713E9e5AB2D71EF4F336",
"name": "Celo native asset (Wormhole)",
"symbol": "CELO",
"decimals": 18,
Expand Down Expand Up @@ -535,7 +535,7 @@
},
{
"name": "Dai Stablecoin",
"address": "0x7cec86400dfbe0d75b1ec468767d044b21a39c25",
"address": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
"symbol": "DAI",
"decimals": 18,
"chainId": 42161,
Expand Down Expand Up @@ -815,7 +815,7 @@
},
{
"chainId": 42161,
"address": "0x23a941036ae778ac51ab04cea08ed6e2fe103614",
"address": "0x9623063377AD1B27544C965cCd7342f7EA7e88C7",
"name": "The Graph",
"symbol": "GRT",
"decimals": 18,
Expand All @@ -839,7 +839,7 @@
},
{
"chainId": 42161,
"address": "0x3fecb65993e4835884baf6452d1ebfdbc3a78480",
"address": "0x589d35656641d6aB57A545F08cf473eCD9B6D5F7",
"name": "GYEN",
"symbol": "GYEN",
"decimals": 6,
Expand Down Expand Up @@ -1031,7 +1031,7 @@
},
{
"chainId": 42161,
"address": "0xca65f362bde046c646f3d6cf12d6708af5029275",
"address": "0x289ba1701C2F088cf0faf8B3705246331cB8A839",
"name": "Livepeer",
"symbol": "LPT",
"decimals": 18,
Expand Down Expand Up @@ -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
},
{
Expand Down Expand Up @@ -1911,15 +1911,15 @@
},
{
"name": "USDCoin",
"address": "0xbfbd7a22dd2cae93400a39f9273de3899e349c37",
"address": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
"symbol": "USDC",
"decimals": 6,
"chainId": 42161,
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png"
},
{
"name": "Tether USD",
"address": "0xc9f0cacf9a9d451c7133597fb379eb39b80efa77",
"address": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
"symbol": "USDT",
"decimals": 6,
"chainId": 42161,
Expand Down Expand Up @@ -1959,7 +1959,7 @@
},
{
"name": "Wrapped Ether",
"address": "0x82ea8a97bfb03dc83d214feb1df6330f5c3d65da",
"address": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
"symbol": "WETH",
"decimals": 18,
"chainId": 42161,
Expand Down
54 changes: 54 additions & 0 deletions src/scripts/generateBridgeList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ type Call = {
callData: string
}

type Extensions = {
bridgeInfo?: Record<
SupportedChainId,
{
tokenAddress?: string
}
>
}

async function generateBridgedList(
chainId: SupportedChainId,
tokenListSource: string | TokenList,
bridgeContractAddress: string,
bridgeContractAbi: ContractInterface,
methodName: string,
outputFilePath: string,
tokensToReplace: Record<string, string | null> = {},
): Promise<void> {
const provider = getProvider(chainId, undefined)
const bridgeContract = new Contract(bridgeContractAddress, bridgeContractAbi, provider)
Expand All @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -102,5 +150,11 @@ export async function generateArbitrumOneChainList(source: string | TokenList, r
ARBITRUM_BRIDGE_ABI,
'calculateL2TokenAddress',
resultFile,
// {
// // USDC
// '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
// // WETH
// '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
// },
)
}

0 comments on commit 91284b9

Please sign in to comment.