From 7bbdb109d05a6fa50c0dd567cdd288da5f5d96ea Mon Sep 17 00:00:00 2001 From: Aleksandr Kuperman Date: Mon, 15 Jul 2024 13:27:39 +0100 Subject: [PATCH] chore: adding Vote Weighting deployment scripts --- .../deployment/deploy_23_vote_weighting.js | 62 +++++++++++++++++++ .../deployment/verify_23_vote_weighting.js | 8 +++ 2 files changed, 70 insertions(+) create mode 100644 scripts/deployment/deploy_23_vote_weighting.js create mode 100644 scripts/deployment/verify_23_vote_weighting.js diff --git a/scripts/deployment/deploy_23_vote_weighting.js b/scripts/deployment/deploy_23_vote_weighting.js new file mode 100644 index 0000000..18261ab --- /dev/null +++ b/scripts/deployment/deploy_23_vote_weighting.js @@ -0,0 +1,62 @@ +/*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 derivationPath = parsedData.derivationPath; + const useLedger = parsedData.useLedger; + const providerName = parsedData.providerName; + let EOA; + + const provider = await ethers.providers.getDefaultProvider(providerName); + 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); + + // Transaction signing and execution + console.log("23. EOA to deploy VoteWeighting contract pointed to veOLAS"); + const VoteWeighting = await ethers.getContractFactory("VoteWeighting"); + console.log("You are signing the following transaction: VoteWeighting.connect(EOA).deploy(veOLAS)"); + const voteWeighting = await VoteWeighting.connect(EOA).deploy(parsedData.veOLASAddress); + const result = await voteWeighting.deployed(); + + // Transaction details + console.log("Contract deployment: voteWeighting"); + console.log("Contract address:", voteWeighting.address); + console.log("Transaction:", result.deployTransaction.hash); + + // If on sepolia, wait half a minute for the transaction completion + if (providerName === "sepolia") { + await new Promise(r => setTimeout(r, 30000)); + } + + // Contract verification + if (parsedData.contractVerification) { + const execSync = require("child_process").execSync; + execSync("npx hardhat verify --constructor-args scripts/deployment/verify_23_vote_weighting.js --network " + providerName + " " + voteWeighting.address, { encoding: "utf-8" }); + } + + // Writing updated parameters back to the JSON file + parsedData.voteWeightingAddress = voteWeighting.address; + fs.writeFileSync(globalsFile, JSON.stringify(parsedData)); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); \ No newline at end of file diff --git a/scripts/deployment/verify_23_vote_weighting.js b/scripts/deployment/verify_23_vote_weighting.js new file mode 100644 index 0000000..7de09ce --- /dev/null +++ b/scripts/deployment/verify_23_vote_weighting.js @@ -0,0 +1,8 @@ +const fs = require("fs"); +const globalsFile = "globals.json"; +const dataFromJSON = fs.readFileSync(globalsFile, "utf8"); +const parsedData = JSON.parse(dataFromJSON); + +module.exports = [ + parsedData.veOLASAddress +]; \ No newline at end of file