feat: Deploy executors and set them in router
--- don't change below this line --- ENG-4101 Took 59 minutes Took 10 seconds
This commit is contained in:
62
foundry/scripts/set-executors.js
Normal file
62
foundry/scripts/set-executors.js
Normal file
@@ -0,0 +1,62 @@
|
||||
require('dotenv').config();
|
||||
const {ethers} = require("hardhat");
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const hre = require("hardhat");
|
||||
const prompt = require('prompt-sync')();
|
||||
|
||||
async function main() {
|
||||
const network = hre.network.name;
|
||||
const routerAddress = process.env.ROUTER_ADDRESS;
|
||||
console.log(`Setting executors on TychoRouter at ${routerAddress} on ${network}`);
|
||||
|
||||
const [deployer] = await ethers.getSigners();
|
||||
console.log(`Setting executors with account: ${deployer.address}`);
|
||||
console.log(`Account balance: ${ethers.utils.formatEther(await deployer.getBalance())} ETH`);
|
||||
|
||||
const TychoRouter = await ethers.getContractFactory("TychoRouter");
|
||||
const router = TychoRouter.attach(routerAddress);
|
||||
|
||||
const executorsFilePath = path.join(__dirname, "executors.json");
|
||||
const executors = JSON.parse(fs.readFileSync(executorsFilePath, "utf8"));
|
||||
|
||||
// Filter out executors that are already set
|
||||
const executorsToSet = [];
|
||||
for (const executor of executors) {
|
||||
const isExecutorSet = await router.executors(executor.executor);
|
||||
if (!isExecutorSet) {
|
||||
executorsToSet.push(executor);
|
||||
}
|
||||
}
|
||||
|
||||
if (executorsToSet.length === 0) {
|
||||
console.log("All executors are already set. No changes needed.");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`The following ${executorsToSet.length} executor(s) will be set:`);
|
||||
executorsToSet.forEach(executor => {
|
||||
console.log(`Name: ${executor.name}`);
|
||||
console.log(`Address: ${executor.executor}`);
|
||||
console.log("———");
|
||||
});
|
||||
|
||||
const userConfirmation = prompt("Do you want to proceed with setting these executors? (yes/no): ");
|
||||
if (userConfirmation.toLowerCase() !== 'yes') {
|
||||
console.log("Operation cancelled by user.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set executors
|
||||
const executorAddresses = executorsToSet.map(executor => executor.executor);
|
||||
const tx = await router.setExecutors(executorAddresses);
|
||||
await tx.wait(); // Wait for the transaction to be mined
|
||||
console.log(`Executors set at transaction: ${tx.hash}`);
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error("Error setting executors:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user