-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mani Brar
authored and
Mani Brar
committed
Nov 25, 2024
1 parent
14a5228
commit 5c7c017
Showing
13 changed files
with
222 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,61 @@ | ||
// File for handling contants and configurations | ||
require("dotenv").config(); | ||
import veaOutboxArbToEthContract from "@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthTestnet.json"; | ||
import veaOutboxArbToGnosisContract from "@kleros/vea-contracts/deployments/chiado/VeaOutboxArbToGnosisTestnet.json"; | ||
|
||
interface IBridge { | ||
chainId: number; | ||
veaInbox: string; | ||
veaOutbox: string; | ||
chain: string; | ||
epochPeriod: number; | ||
veaInboxAddress: string; | ||
veaOutboxAddress: string; | ||
batcher: string; | ||
rpcOutbox: string; | ||
veaOutboxContract: any; | ||
} | ||
|
||
// Using destination chainId to get the route configuration. | ||
const bridges: { [chainId: number]: IBridge } = { | ||
11155111: { | ||
chainId: 11155111, | ||
veaInbox: process.env.VEAINBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS, | ||
veaOutbox: process.env.VEAOUTBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS, | ||
chain: "sepolia", | ||
epochPeriod: 7200, | ||
veaInboxAddress: process.env.VEAINBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS, | ||
veaOutboxAddress: process.env.VEAOUTBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS, | ||
batcher: process.env.TRANSACTION_BATCHER_CONTRACT_ADDRESS_SEPOLIA, | ||
rpcOutbox: process.env.RPC_SEPOLIA, | ||
veaOutboxContract: veaOutboxArbToEthContract, | ||
}, | ||
10200: { | ||
chainId: 10200, | ||
veaInbox: process.env.VEAINBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS, | ||
veaOutbox: process.env.VEAOUTBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS, | ||
chain: "chiado", | ||
epochPeriod: 3600, | ||
veaInboxAddress: process.env.VEAINBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS, | ||
veaOutboxAddress: process.env.VEAOUTBOX_ARBSEPOLIA_TO_CHIADO_ADDRESS, | ||
batcher: process.env.TRANSACTION_BATCHER_CONTRACT_ADDRESS_CHIADO, | ||
rpcOutbox: process.env.RPC_CHIADO, | ||
veaOutboxContract: veaOutboxArbToGnosisContract, | ||
}, | ||
}; | ||
|
||
// Getters | ||
const getBridgeConfig = (chainId: number): IBridge | undefined => { | ||
return bridges[chainId]; | ||
}; | ||
|
||
const getEpochPeriod = (chainId: number): number => { | ||
return bridges[chainId].epochPeriod; | ||
}; | ||
|
||
const getInboxSubgraph = (chainId: number): string => { | ||
switch (chainId) { | ||
case 11155111: | ||
return process.env.VEAINBOX_ARBSEPOLIA_TO_SEPOLIA_SUBGRAPH; | ||
case 10200: | ||
return process.env.VEAINBOX_ARBSEPOLIA_TO_CHIADO_SUBGRAPH; | ||
default: | ||
throw new Error("Invalid chainid"); | ||
throw new Error("Invalid chainId"); | ||
} | ||
}; | ||
|
||
export { getBridgeConfig, getInboxSubgraph }; | ||
export { getBridgeConfig, getInboxSubgraph, getEpochPeriod }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,26 @@ | ||
import { relayAllFrom } from "./utils/relay"; | ||
import * as fs from "fs"; | ||
import { initialize, updateStateFile } from "./utils/relayerHelpers"; | ||
import { initialize, ShutdownManager, updateStateFile, setupExitHandlers, delay } from "./utils/relayerHelpers"; | ||
|
||
// let chain_ids = [5, 10200]; | ||
let chain_ids = [11155111]; | ||
const epochPeriod = 1800; // 30 min | ||
const _contract = require("@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthDevnet.json"); | ||
const network = "devnet"; | ||
export async function start(shutdownManager: ShutdownManager = new ShutdownManager()) { | ||
const chainId = parseInt(process.env.VEAOUTBOX_CHAIN_ID); | ||
const epochPeriod = 1800; // 30 min | ||
const network = "devnet"; | ||
await setupExitHandlers(chainId, shutdownManager); | ||
while (!shutdownManager.getIsShuttingDown()) { | ||
let nonce = await initialize(chainId, network); | ||
// This is libghtbulb switch address in arbitrum sepolia | ||
const sender = process.env.DEVNET_SENDER; | ||
nonce = await relayAllFrom(chainId, nonce, sender); | ||
if (nonce != null) await updateStateFile(chainId, Math.floor(Date.now() / 1000), nonce, network); | ||
|
||
["SIGINT", "SIGTERM", "SIGQUIT", "EXIT", "MODULE_NOT_FOUND"].forEach((signal) => | ||
process.on(signal, async () => { | ||
console.log("exit"); | ||
for (const chain_id of chain_ids) { | ||
const lock_file_name = "./src/state/" + chain_id + ".pid"; | ||
if (fs.existsSync(lock_file_name)) { | ||
fs.unlinkSync(lock_file_name); | ||
} | ||
} | ||
process.exit(0); | ||
}) | ||
); | ||
|
||
(async () => { | ||
while (1) { | ||
for (const chain_id of chain_ids) { | ||
let nonce = await initialize(chain_id, network); | ||
// This is libghtbulb switch address in arbitrum sepolia | ||
const sender = "0x28d6D503F4c5734cD926E96b63C61527d975B382"; | ||
nonce = await relayAllFrom(chain_id, nonce, sender, _contract); | ||
if (nonce != null) await updateStateFile(chain_id, Math.floor(Date.now() / 1000), nonce, network); | ||
} | ||
const currentTS = Math.floor(Date.now() / 1000); | ||
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000; | ||
console.log("waiting for the next epoch. . .", Math.floor(delayAmount / 1000), "seconds"); | ||
await delay(delayAmount); | ||
} | ||
})(); | ||
} | ||
|
||
function delay(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
if (require.main === module) { | ||
const shutdownManager = new ShutdownManager(false); | ||
start(shutdownManager); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require("dotenv").config(); | ||
import { relayBatch } from "utils/relay"; | ||
import { initialize, updateStateFile, delay, setupExitHandlers, ShutdownManager } from "utils/relayerHelpers"; | ||
import { getEpochPeriod } from "consts/bridgeRoutes"; | ||
|
||
export async function start(shutdownManager: ShutdownManager = new ShutdownManager()) { | ||
const network = "testnet"; | ||
const chainId = parseInt(process.env.VEAOUTBOX_CHAIN_ID); | ||
const epochPeriod = getEpochPeriod(chainId); | ||
const batchSize = 10; // 10 messages per batch | ||
|
||
await setupExitHandlers(chainId, shutdownManager); | ||
|
||
while (!shutdownManager.getIsShuttingDown()) { | ||
let nonce = await initialize(chainId, network); | ||
nonce = await relayBatch(chainId, nonce, batchSize); | ||
if (nonce != null) await updateStateFile(chainId, Math.floor(Date.now() / 1000), nonce, network); | ||
const currentTS = Math.floor(Date.now() / 1000); | ||
const delayAmount = (epochPeriod - (currentTS % epochPeriod)) * 1000 + 100 * 1000; | ||
console.log("waiting for the next epoch. . .", Math.floor(delayAmount / 1000), "seconds"); | ||
await delay(delayAmount); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
const shutdownManager = new ShutdownManager(false); | ||
start(shutdownManager); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.