From eba9ca2c96d4935fc2c7ecd37009652b06e27c02 Mon Sep 17 00:00:00 2001 From: vrtnd Date: Wed, 18 Dec 2024 21:02:15 +0300 Subject: [PATCH] chain mapping object --- src/handlers/runAdapterFromTo.ts | 5 +++-- src/helpers/tokenMappings.ts | 20 +++++++++++++++++--- src/server/jobs/runAdaptersFromTo.ts | 5 +++-- src/utils/adapter.ts | 17 +++++------------ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/handlers/runAdapterFromTo.ts b/src/handlers/runAdapterFromTo.ts index 5a7c0ebf..d411beb6 100644 --- a/src/handlers/runAdapterFromTo.ts +++ b/src/handlers/runAdapterFromTo.ts @@ -4,6 +4,7 @@ import { runAdapterHistorical } from "../utils/adapter"; import { sql } from "../utils/db"; import { getBridgeID } from "../utils/wrappa/postgres/query"; import { getLatestBlock } from "../utils/blocks"; +import { chainMappings } from "../helpers/tokenMappings"; const handler = async (event: any) => { try { @@ -16,8 +17,8 @@ const handler = async (event: any) => { const promises = adapter.chains.map(async (chain) => { let nChain; - if (adapter.chainMapping && adapter.chainMapping[chain.toLowerCase()]) { - nChain = adapter.chainMapping[chain.toLowerCase()]; + if (chainMappings[chain.toLowerCase()]) { + nChain = chainMappings[chain.toLowerCase()]; } else { nChain = chain.toLowerCase(); } diff --git a/src/helpers/tokenMappings.ts b/src/helpers/tokenMappings.ts index bd370513..1891cc84 100644 --- a/src/helpers/tokenMappings.ts +++ b/src/helpers/tokenMappings.ts @@ -64,15 +64,15 @@ export const transformTokens = { "0xf5e11df1ebcf78b6b6d26e04ff19cd786a1e81dc": "bsc:0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c", "0x77776b40c3d75cb07ce54dea4b2fd1d07f865222": "bsc:0xe9e7cea3dedca5984780bafc599bd69add087d56", }, - "combo-mainnet":{ + "combo-mainnet": { "0xd08a2917653d4e460893203471f0000826fb4034": "bsc:0xc03fbf20a586fa89c2a5f6f941458e1fbc40c661", "0x7c6b91d9be155a6db01f749217d76ff02a7227f2": "bsc:0x55d398326f99059ff775485246999027b3197955", "0x4200000000000000000000000000000000000006": "bsc:0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c", }, - "op_bnb":{ + op_bnb: { "0xe7798f023fc62146e8aa1b36da45fb70855a77ea": "ethereum:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x9d94a7ff461e83f161c8c040e78557e31d8cba72": "bsc:0xf4c8e32eadec4bfe97e0f595add0f4450a863a11", - } + }, } as { [chain: string]: { [token: string]: string; @@ -143,3 +143,17 @@ export const transformTokenDecimals = { [token: string]: number; }; }; + +export const chainMappings: Record = { + avalanche: "avax", + gnosis: "xdai", + "zksync era": "era", + "polygon zkevm": "polygon_zkevm", + "arbitrum nova": "arbitrum_nova", + rootstock: "rsk", + bsquared: "b2-mainnet", + "x layer": "xlayer", + bouncebit: "bouncebit-mainnet", + opbnb: "op_bnb", + bitlayer: "btr", +}; diff --git a/src/server/jobs/runAdaptersFromTo.ts b/src/server/jobs/runAdaptersFromTo.ts index 472548ff..7ecbfe3a 100644 --- a/src/server/jobs/runAdaptersFromTo.ts +++ b/src/server/jobs/runAdaptersFromTo.ts @@ -1,4 +1,5 @@ import bridgeNetworks from "../../data/bridgeNetworkData"; +import { chainMappings } from "../../helpers/tokenMappings"; import { runAdapterHistorical } from "../../utils/adapter"; import { sql } from "../../utils/db"; import { getBridgeID } from "../../utils/wrappa/postgres/query"; @@ -15,8 +16,8 @@ export const runAdaptersFromTo = async () => { await Promise.all( adapter.chains.map(async (chain) => { let nChain; - if (adapter.chainMapping && adapter.chainMapping[chain.toLowerCase()]) { - nChain = adapter.chainMapping[chain.toLowerCase()]; + if (chainMappings[chain.toLowerCase()]) { + nChain = chainMappings[chain.toLowerCase()]; } else { nChain = chain.toLowerCase(); } diff --git a/src/utils/adapter.ts b/src/utils/adapter.ts index 86e65c0f..20d96821 100644 --- a/src/utils/adapter.ts +++ b/src/utils/adapter.ts @@ -17,6 +17,7 @@ import { groupBy } from "lodash"; import { getProvider } from "./provider"; import { sendDiscordText } from "./discord"; import { getConnection } from "../helpers/solana"; +import { chainMappings } from "../helpers/tokenMappings"; const axios = require("axios"); const retry = require("async-retry"); @@ -146,9 +147,7 @@ export const runAdapterToCurrentBlock = async ( const adapterPromises = Promise.all( Object.keys(adapter).map(async (chain) => { - const chainContractsAreOn = bridgeNetwork.chainMapping?.[chain as Chain] - ? bridgeNetwork.chainMapping?.[chain as Chain] - : chain; + const chainContractsAreOn = chainMappings[chain as Chain] ? chainMappings[chain as Chain] : chain; let bridgeID: string; try { @@ -274,9 +273,7 @@ export const runAllAdaptersToCurrentBlock = async ( const adapterPromises = Promise.all( Object.keys(adapter).map(async (chain, i) => { await wait(100 * i); // attempt to space out API calls - const chainContractsAreOn = bridgeNetwork.chainMapping?.[chain as Chain] - ? bridgeNetwork.chainMapping?.[chain as Chain] - : chain; + const chainContractsAreOn = chainMappings[chain as Chain] ? chainMappings[chain as Chain] : chain; const { startBlock, endBlock, useRecordedBlocks } = await getBlocksForRunningAdapter( bridgeDbName, chain, @@ -329,9 +326,7 @@ export const runAllAdaptersTimestampRange = async ( const adapterPromises = Promise.all( Object.keys(adapter).map(async (chain, i) => { await wait(100 * i); // attempt to space out API calls - const chainContractsAreOn = bridgeNetwork.chainMapping?.[chain as Chain] - ? bridgeNetwork.chainMapping?.[chain as Chain] - : chain; + const chainContractsAreOn = chainMappings[chain as Chain] ? chainMappings[chain as Chain] : chain; if (chainContractsAreOn === "tron" || chainContractsAreOn === "sui" || chainContractsAreOn === "solana") { console.info(`Skipping running adapter ${bridgeDbName} on chain ${chainContractsAreOn}.`); return; @@ -423,9 +418,7 @@ export const runAdapterHistorical = async ( }); throw new Error(errString); } - const chainContractsAreOn = bridgeNetwork.chainMapping?.[chain as Chain] - ? bridgeNetwork.chainMapping?.[chain as Chain] - : chain; + const chainContractsAreOn = chainMappings[chain as Chain] ? chainMappings[chain as Chain] : chain; const bridgeID = (await getBridgeID(bridgeDbName, chain))?.id; if (!bridgeID) {