diff --git a/scripts/deployment/deploy_03_change_manager.js b/scripts/deployment/deploy_03_change_manager.js new file mode 100644 index 0000000..44b8eaa --- /dev/null +++ b/scripts/deployment/deploy_03_change_manager.js @@ -0,0 +1,63 @@ +/*global process*/ + +const { expect } = require("chai"); +const { ethers } = require("hardhat"); +const { LedgerSigner } = require("@anders-t/ethers-ledger"); + +async function main() { + const fs = require("fs"); + const globalsFile = "globals.json"; + const dataFromJSON = fs.readFileSync(globalsFile, "utf8"); + let parsedData = JSON.parse(dataFromJSON); + const useLedger = parsedData.useLedger; + const derivationPath = parsedData.derivationPath; + const providerName = parsedData.providerName; + const agentRegistryAddress = parsedData.agentRegistryAddress; + const agentFactoryAddress = parsedData.agentFactoryAddress; + let EOA; + + let networkURL; + if (providerName === "gnosis") { + if (!process.env.GNOSIS_CHAIN_API_KEY) { + console.log("set GNOSIS_CHAIN_API_KEY env variable"); + return; + } + networkURL = "https://rpc.gnosischain.com"; + } else if (providerName === "chiado") { + networkURL = "https://rpc.chiadochain.net"; + } else { + console.log("Unknown network provider", providerName); + return; + } + + const provider = new ethers.providers.JsonRpcProvider(networkURL); + const signers = await ethers.getSigners(); + + if (useLedger) { + EOA = new LedgerSigner(provider, derivationPath); + } else { + EOA = signers[0]; + } + // EOA address + const deployer = await EOA.getAddress(); + console.log("EOA is:", deployer); + + // Get all the contracts + const agentRegistry = await ethers.getContractAt("AgentRegistry", agentRegistryAddress); + + // Transaction signing and execution + // 3. EOA to change the manager of AgentRegistry via `changeManager(AgentRegistry)`; + console.log("You are signing the following transaction: agentRegistry.connect(EOA).changeManager()"); + let result = await agentRegistry.connect(EOA).changeManager(agentFactoryAddress); + // Transaction details + console.log("Contract deployment: AgentRegistry"); + console.log("Contract address:", agentRegistryAddress); + console.log("Transaction:", result.hash); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + });