Skip to content

Commit

Permalink
chain mapping object
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Dec 18, 2024
1 parent 5e67221 commit eba9ca2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/handlers/runAdapterFromTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
Expand Down
20 changes: 17 additions & 3 deletions src/helpers/tokenMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -143,3 +143,17 @@ export const transformTokenDecimals = {
[token: string]: number;
};
};

export const chainMappings: Record<string, string> = {
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",
};
5 changes: 3 additions & 2 deletions src/server/jobs/runAdaptersFromTo.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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();
}
Expand Down
17 changes: 5 additions & 12 deletions src/utils/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit eba9ca2

Please sign in to comment.