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:
@@ -2,7 +2,7 @@
|
||||
|
||||
- Install dependencies `npm install`
|
||||
|
||||
## Deploy on Tenderly fork
|
||||
## Deploy on a Tenderly fork
|
||||
|
||||
1. Make a new [fork](https://dashboard.tenderly.co/) in tenderly dashboard.
|
||||
2. Set the following environment variables:
|
||||
@@ -14,7 +14,18 @@ export PRIVATE_KEY=<private-key>
|
||||
```
|
||||
|
||||
3. Fund wallet: `npx hardhat run scripts/fund-wallet-tenderly-fork.js --network tenderly`
|
||||
4. Deploy router: `npx hardhat run scripts/deploy-router.js --network tenderly`
|
||||
5. Define the accounts to grant roles to in `scripts/roles.json`
|
||||
6. Export the router address to the environment variable `export ROUTER=<router-address>`
|
||||
7. Grant roles: `npx hardhat run scripts/set-roles.js --network tenderly`
|
||||
|
||||
### Deploy Tycho Router
|
||||
|
||||
1. Deploy router: `npx hardhat run scripts/deploy-router.js --network tenderly`
|
||||
2. Define the accounts to grant roles to in `scripts/roles.json`
|
||||
3. Export the router address to the environment variable `export ROUTER=<router-address>`
|
||||
4. Grant roles: `npx hardhat run scripts/set-roles.js --network tenderly`
|
||||
5. Set executors: `npx hardhat run scripts/set-executors.js --network tenderly`. Make sure you change the DEPLOY_WALLET
|
||||
to the executor deployer wallet. If you need to deploy executors, follow the instructions below.
|
||||
|
||||
### Deploy executors
|
||||
|
||||
1. In `scripts/deploy-executors.js` define the executors to be deployed
|
||||
2. Deploy executors: `npx hardhat run scripts/deploy-executors.js --network tenderly`
|
||||
3. Fill in the executor addresses in `scripts/executors.json`
|
||||
|
||||
45
foundry/scripts/deploy-executors.js
Normal file
45
foundry/scripts/deploy-executors.js
Normal file
@@ -0,0 +1,45 @@
|
||||
require('dotenv').config();
|
||||
const {ethers} = require("hardhat");
|
||||
const hre = require("hardhat");
|
||||
|
||||
// Comment out the executors you don't want to deploy
|
||||
const executors_to_deploy = [
|
||||
{exchange: "UniswapV2Executor", args: []},
|
||||
{exchange: "UniswapV3Executor", args: ["0x1F98431c8aD98523631AE4a59f267346ea31F984"]},
|
||||
{exchange: "UniswapV4Executor", args: ["0x000000000004444c5dc75cB358380D2e3dE08A90"]},
|
||||
{exchange: "BalancerV2Executor", args: []},
|
||||
]
|
||||
|
||||
async function main() {
|
||||
const network = hre.network.name;
|
||||
console.log(`Deploying executors to ${network}`);
|
||||
|
||||
const [deployer] = await ethers.getSigners();
|
||||
console.log(`Deploying with account: ${deployer.address}`);
|
||||
console.log(`Account balance: ${ethers.utils.formatEther(await deployer.getBalance())} ETH`);
|
||||
|
||||
for (const executor of executors_to_deploy) {
|
||||
const {exchange, args} = executor;
|
||||
const Executor = await ethers.getContractFactory(exchange);
|
||||
const deployedExecutor = await Executor.deploy(...args);
|
||||
await deployedExecutor.deployed();
|
||||
console.log(`${exchange} deployed to: ${deployedExecutor.address}`);
|
||||
|
||||
try {
|
||||
await hre.tenderly.verify({
|
||||
name: exchange,
|
||||
address: deployedExecutor.address,
|
||||
});
|
||||
console.log("Contract verified successfully on Tenderly");
|
||||
} catch (error) {
|
||||
console.error("Error during contract verification:", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
console.error("Deployment failed:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -33,7 +33,6 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Execute deployment
|
||||
main()
|
||||
.then(() => process.exit(0))
|
||||
.catch((error) => {
|
||||
|
||||
18
foundry/scripts/executors.json
Normal file
18
foundry/scripts/executors.json
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"name": "UniswapV2Executor",
|
||||
"executor": "0xFF804342b632bd2C210643c005Ef139c0AaeBa0c"
|
||||
},
|
||||
{
|
||||
"name": "UniswapV3Executor",
|
||||
"executor": "0xb45f428357174C8d9DfB56E7ccf87EDdB8fDa5C6"
|
||||
},
|
||||
{
|
||||
"name": "UniswapV4Executor",
|
||||
"executor": "0x0E759000F3C1FFEe31ecc56D125EB796151F556E"
|
||||
},
|
||||
{
|
||||
"name": "BalancerV2Executor",
|
||||
"executor": "0x14702382b81e6d8677321ed904edd6ec3ea7e3dc"
|
||||
}
|
||||
]
|
||||
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);
|
||||
});
|
||||
@@ -31,13 +31,13 @@ async function main() {
|
||||
const addresses = rolesDict[roleName];
|
||||
if (addresses && addresses.length > 0) {
|
||||
console.log(`Granting ${roleName} to the following addresses:`, addresses);
|
||||
await router.batchGrantRole(roleHash, addresses);
|
||||
const tx = await router.batchGrantRole(roleHash, addresses);
|
||||
await tx.wait(); // Wait for the transaction to be mined
|
||||
console.log(`Role ${roleName} granted at transaction: ${tx.hash}`);
|
||||
} else {
|
||||
console.log(`No addresses found for role ${roleName}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("All roles have been set successfully.");
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user