Skip to content

Commit

Permalink
fix finality wait (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: mrlotfi <[email protected]>
  • Loading branch information
mrlotfi and mrlotfi authored Sep 10, 2024
1 parent bebec15 commit 2e08744
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 39 deletions.
10 changes: 9 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ SOLANA_SEND_RPCS="https://mainnet.block-engine.jito.wtf/api/v1/transactions,http
AVALANCHE_RPC="https://1rpc.io/avax/c"
ARBITRUM_RPC="https://arb1.arbitrum.io/rpc"
BASE_RPC="https://mainnet.base.org"
BSC_RPC="https://rpc.ankr.com/bsc "
BSC_RPC="https://rpc.ankr.com/bsc"
ETHEREUM_FLASHBOT_RPC="https://rpc.flashbots.net/fast"
ETHEREUM_RPC="https://rpc.ankr.com/eth"
OPTIMISM_RPC="https://mainnet.optimism.io"
POLYGON_RPC="https://polygon-rpc.com/"

AVALANCHE_2ND_RPC="https://1rpc.io/avax/c"
ARBITRUM_2ND_RPC="https://arb1.arbitrum.io/rpc"
BASE_2ND_RPC="https://mainnet.base.org"
BSC_2ND_RPC="https://rpc.ankr.com/bsc"
ETHEREUM_2ND_RPC="https://rpc.ankr.com/eth"
OPTIMISM_2ND_RPC="https://mainnet.optimism.io"
POLYGON_2ND_RPC="https://polygon-rpc.com/"

DISABLE_UNLOCKER="false"
BLACKLISTED_REFERRERS=""

Expand Down
14 changes: 14 additions & 0 deletions src/config/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ export type RpcConfig = {
evmEndpoints: {
ethereumFlashBot: string;
ethereum: string;
ethereum2nd: string;
bsc: string;
bsc2nd: string;
polygon: string;
polygon2nd: string;
avalanche: string;
avalanche2nd: string;
arbitrum: string;
arbitrum2nd: string;
optimism: string;
optimism2nd: string;
base: string;
base2nd: string;
};
jupV6Endpoint: string;
oneInchApiKey: string;
Expand All @@ -41,13 +48,20 @@ export const rpcConfig: RpcConfig = {
},
evmEndpoints: {
avalanche: process.env.AVALANCHE_RPC || 'https://1rpc.io/avax/c',
avalanche2nd: process.env.AVALANCHE_2ND_RPC || 'https://1rpc.io/avax/c',
arbitrum: process.env.ARBITRUM_RPC || 'https://arb1.arbitrum.io/rpc',
arbitrum2nd: process.env.ARBITRUM_2ND_RPC || 'https://arb1.arbitrum.io/rpc',
base: process.env.BASE_RPC || 'https://mainnet.base.org',
base2nd: process.env.BASE_2ND_RPC || 'https://mainnet.base.org',
bsc: process.env.BSC_RPC || 'https://rpc.ankr.com/bsc ',
bsc2nd: process.env.BSC_2ND_RPC || 'https://rpc.ankr.com/bsc',
ethereumFlashBot: process.env.ETHEREUM_FLASHBOT_RPC || 'https://rpc.flashbots.net/fast',
ethereum: process.env.ETHEREUM_RPC || 'https://rpc.ankr.com/eth',
ethereum2nd: process.env.ETHEREUM_2ND_RPC || 'https://rpc.ankr.com/eth',
optimism: process.env.OPTIMISM_RPC || 'https://mainnet.optimism.io',
optimism2nd: process.env.OPTIMISM_2ND_RPC || 'https://mainnet.optimism.io',
polygon: process.env.POLYGON_RPC || 'https://polygon-rpc.com/',
polygon2nd: process.env.POLYGON_2ND_RPC || 'https://polygon-rpc.com/',
},
jupV6Endpoint: process.env.JUP_V6_ENDPOINT || 'https://quote-api.jup.ag/v6',
oneInchApiKey: process.env.ONE_INCH_API_KEY || '',
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Unlocker } from './driver/unlocker';
import { WalletsHelper } from './driver/wallet-helper';
import { Relayer } from './relayer';
import { SimpleFulfillerConfig } from './simple';
import { makeEvmProviders } from './utils/evm-providers';
import { makeEvmProviders, makeSecondEvmProviders } from './utils/evm-providers';
import { FeeService } from './utils/fees';
import { ChainFinality } from './utils/finality';
import logger from './utils/logger';
Expand Down Expand Up @@ -71,6 +71,7 @@ export async function main() {
}, 60_000);

const evmProviders = makeEvmProviders(supportedChainIds, rpcConfig);
const secondaryEvmProviders = makeSecondEvmProviders(supportedChainIds, rpcConfig);
const solanaConnection = new Connection(rpcConfig.solana.solanaMainRpc, {
commitment: 'confirmed',
});
Expand Down Expand Up @@ -155,7 +156,13 @@ export async function main() {
tokenList,
solanaTxSender,
);
const chainFinalitySvc = new ChainFinality(solanaConnection, contracts, rpcConfig, evmProviders);
const chainFinalitySvc = new ChainFinality(
solanaConnection,
contracts,
rpcConfig,
evmProviders,
secondaryEvmProviders,
);
const relayer = new Relayer(
rpcConfig,
mayanEndpoints,
Expand Down
44 changes: 41 additions & 3 deletions src/utils/evm-providers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from "ethers6";
import { ethers } from 'ethers6';
import {
CHAIN_ID_ARBITRUM,
CHAIN_ID_AVAX,
Expand All @@ -7,8 +7,8 @@ import {
CHAIN_ID_ETH,
CHAIN_ID_OPTIMISM,
CHAIN_ID_POLYGON,
} from "../config/chains";
import { RpcConfig } from "../config/rpc";
} from '../config/chains';
import { RpcConfig } from '../config/rpc';

export type EvmProviders = { [evmNetworkId: number | string]: ethers.JsonRpcProvider };

Expand Down Expand Up @@ -49,3 +49,41 @@ export function makeEvmProviders(chainIds: number[], rpcConfig: RpcConfig): EvmP

return result;
}

export function makeSecondEvmProviders(chainIds: number[], rpcConfig: RpcConfig): EvmProviders {
const result: { [key: number]: ethers.JsonRpcProvider } = {};

for (const chainId of chainIds) {
if (chainId === CHAIN_ID_BSC) {
result[chainId] = new ethers.JsonRpcProvider(rpcConfig.evmEndpoints.bsc2nd, 56, {
staticNetwork: ethers.Network.from(56),
});
} else if (chainId === CHAIN_ID_POLYGON) {
result[chainId] = new ethers.JsonRpcProvider(rpcConfig.evmEndpoints.polygon2nd, 137, {
staticNetwork: ethers.Network.from(137),
});
} else if (chainId === CHAIN_ID_ETH) {
result[chainId] = new ethers.JsonRpcProvider(rpcConfig.evmEndpoints.ethereum2nd, 1, {
staticNetwork: ethers.Network.from(1),
});
} else if (chainId === CHAIN_ID_AVAX) {
result[chainId] = new ethers.JsonRpcProvider(rpcConfig.evmEndpoints.avalanche2nd, 43114, {
staticNetwork: ethers.Network.from(43114),
});
} else if (chainId === CHAIN_ID_ARBITRUM) {
result[chainId] = new ethers.JsonRpcProvider(rpcConfig.evmEndpoints.arbitrum2nd, 42161, {
staticNetwork: ethers.Network.from(42161),
});
} else if (chainId === CHAIN_ID_OPTIMISM) {
result[chainId] = new ethers.JsonRpcProvider(rpcConfig.evmEndpoints.optimism2nd, 10, {
staticNetwork: ethers.Network.from(10),
});
} else if (chainId === CHAIN_ID_BASE) {
result[chainId] = new ethers.JsonRpcProvider(rpcConfig.evmEndpoints.base2nd, 8453, {
staticNetwork: ethers.Network.from(8453),
});
}
}

return result;
}
Loading

0 comments on commit 2e08744

Please sign in to comment.