From 54f9bc1c2153c544f324c650389a3e851c8dccd2 Mon Sep 17 00:00:00 2001 From: Alexander <61561908+Shchepetov@users.noreply.github.com> Date: Tue, 6 Aug 2024 10:09:47 +0300 Subject: [PATCH] Deploy scripts --- .env.mock | 6 +++++- package.json | 2 +- scripts/{ => RewardPool}/deploy.js | 2 +- scripts/{ => RewardPool}/upgrade.js | 4 ++-- scripts/RewardPoolV2/deploy.js | 31 +++++++++++++++++++++++++++++ scripts/RewardPoolV2/upgrade.js | 31 +++++++++++++++++++++++++++++ test/RewardPool.js | 2 +- test/RewardPoolV2.js | 2 +- utils/utils.js | 4 ++-- 9 files changed, 75 insertions(+), 9 deletions(-) rename scripts/{ => RewardPool}/deploy.js (92%) rename scripts/{ => RewardPool}/upgrade.js (86%) create mode 100644 scripts/RewardPoolV2/deploy.js create mode 100644 scripts/RewardPoolV2/upgrade.js diff --git a/.env.mock b/.env.mock index f27648a..7d28d6b 100644 --- a/.env.mock +++ b/.env.mock @@ -2,9 +2,13 @@ AZUR=0x765...456 UNSTAKEPERIOD=2592000 REWARD_POOL_ADDRESS= +NAME="Staked $AZUR" +SYMBOL="stAZUR" +REWARD_POOL_V2_ADDRESS=0xa..d3 + POLYGONSCAN_API_KEY=1N..XX ETHERSCAN_API_KEY=1N..XX MUMBAI_PRIVATE_KEY=db0e..82c2 POLYGON_PRIVATE_KEY=db0e..82c2 MAINNET_PRIVATE_KEY=db0e..82c2 -INFURA_API_KEY= \ No newline at end of file +INFURA_API_KEY= diff --git a/package.json b/package.json index 2d39ff0..a485c9e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "compile": "npx hardhat compile", "test": "npx hardhat test", "prettier-sol": "npx prettier --write \"contracts/**/*.sol\"", - "prettier-js": "npx prettier --write {scripts,test,utils}/*.js --print-width 120 --tab-width 2", + "prettier-js": "npx prettier --write {scripts/*,test,utils}/*.js --print-width 120 --tab-width 2", "coverage": "npx hardhat coverage" } } diff --git a/scripts/deploy.js b/scripts/RewardPool/deploy.js similarity index 92% rename from scripts/deploy.js rename to scripts/RewardPool/deploy.js index 70a869c..2708e0b 100644 --- a/scripts/deploy.js +++ b/scripts/RewardPool/deploy.js @@ -1,6 +1,6 @@ const { ethers } = require("hardhat"); const hre = require("hardhat"); -const { getTimeout, deployRewardPool } = require("../utils/utils"); +const { getTimeout, deployRewardPool } = require("../../utils/utils"); async function main() { const [deployer] = await ethers.getSigners(); diff --git a/scripts/upgrade.js b/scripts/RewardPool/upgrade.js similarity index 86% rename from scripts/upgrade.js rename to scripts/RewardPool/upgrade.js index 9e04751..79347c5 100644 --- a/scripts/upgrade.js +++ b/scripts/RewardPool/upgrade.js @@ -1,6 +1,6 @@ const { ethers } = require("hardhat"); const hre = require("hardhat"); -const { getTimeout, deployRewardPool } = require("../utils/utils"); +const { getTimeout } = require("../../utils/utils"); async function main() { const [deployer] = await ethers.getSigners(); @@ -19,7 +19,7 @@ async function main() { const REWARDPOOL = await ethers.getContractFactory("RewardPool"); - const rewardPool = await upgrades.upgradeProxy(REWARD_POOL_ADDRESS, REWARDPOOL); + await upgrades.upgradeProxy(REWARD_POOL_ADDRESS, REWARDPOOL); await timeout(); let rewardPoolImplAddress = await upgrades.erc1967.getImplementationAddress(REWARD_POOL_ADDRESS); diff --git a/scripts/RewardPoolV2/deploy.js b/scripts/RewardPoolV2/deploy.js new file mode 100644 index 0000000..acf99d4 --- /dev/null +++ b/scripts/RewardPoolV2/deploy.js @@ -0,0 +1,31 @@ +const { ethers } = require("hardhat"); +const hre = require("hardhat"); +const { getTimeout, deployRewardPoolV2 } = require("../../utils/utils"); + +async function main() { + const [deployer] = await ethers.getSigners(); + + // ........................ ENV ENV ENV ................ + const AZUR = process.env.AZUR; + const NAME = process.env.NAME; + const SYMBOL = process.env.SYMBOL; + const UNSTAKEPERIOD = process.env.UNSTAKEPERIOD; + // ........................ ENV ENV ENV ................ + + console.log("Deployer wallet:", deployer.address); + + const chainId = await hre.network.provider.send("eth_chainId"); + const timeout = getTimeout(chainId); + + const rewardPoolV2 = await deployRewardPoolV2(AZUR, deployer, NAME, SYMBOL, UNSTAKEPERIOD); + + await timeout(); + console.log("RewardPoolV2:", await rewardPoolV2.getAddress()); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/scripts/RewardPoolV2/upgrade.js b/scripts/RewardPoolV2/upgrade.js new file mode 100644 index 0000000..06038e8 --- /dev/null +++ b/scripts/RewardPoolV2/upgrade.js @@ -0,0 +1,31 @@ +const { ethers } = require("hardhat"); +const hre = require("hardhat"); +const { getTimeout } = require("../../utils/utils"); + +async function main() { + const [deployer] = await ethers.getSigners(); + + // ........................ ENV ENV ENV ................ + const REWARD_POOL_V2_ADDRESS = process.env.REWARD_POOL_V2_ADDRESS; + // ........................ ENV ENV ENV ................ + + console.log("Deployer wallet:", deployer.address); + console.log("Upgrading RewardPoolV2:", REWARD_POOL_V2_ADDRESS); + + const chainId = await hre.network.provider.send("eth_chainId"); + const timeout = getTimeout(chainId); + + const RewardPoolV2 = await ethers.getContractFactory("RewardPoolV2"); + await upgrades.upgradeProxy(REWARD_POOL_V2_ADDRESS, RewardPoolV2); + await timeout(); + + const rewardPoolV2ImplAddress = await upgrades.erc1967.getImplementationAddress(REWARD_POOL_V2_ADDRESS); + console.log("RewardPoolV2 new implementation address:", rewardPoolV2ImplAddress); +} + +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + }); diff --git a/test/RewardPool.js b/test/RewardPool.js index ac5b65e..5545b99 100644 --- a/test/RewardPool.js +++ b/test/RewardPool.js @@ -38,7 +38,7 @@ describe("RewardPool", function () { const rewardPool = await deployRewardPool(azur.address, owner, UNSTAKEPERIOD); rewardPool.address = await rewardPool.getAddress(); - const stAzur = await deployRewardPoolV2(azur.address, owner, UNSTAKEPERIOD); + const stAzur = await deployRewardPoolV2(azur.address, owner, "Staked $AZUR", "stAZUR", UNSTAKEPERIOD); stAzur.address = await stAzur.getAddress(); await azur.connect(owner).approve(rewardPool.address, INIT_MINT); diff --git a/test/RewardPoolV2.js b/test/RewardPoolV2.js index 002b147..23ec4ed 100644 --- a/test/RewardPoolV2.js +++ b/test/RewardPoolV2.js @@ -27,7 +27,7 @@ describe("RewardPool", function () { await azur.waitForDeployment(); azur.address = await azur.getAddress(); - const stAzur = await deployRewardPoolV2(azur.address, owner, WITHDRAWAL_DELAY); + const stAzur = await deployRewardPoolV2(azur.address, owner, "Staked $AZUR", "stAZUR", WITHDRAWAL_DELAY); stAzur.address = await stAzur.getAddress(); await azur.connect(owner).transfer(user.address, INIT_BALANCE); diff --git a/utils/utils.js b/utils/utils.js index 681156c..904323f 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -45,9 +45,9 @@ const deployRewardPool = async (azurAddress, owner, unstakedPeriod) => { return rewardPool; }; -const deployRewardPoolV2 = async (azurAddress, owner, unstakePeriod) => { +const deployRewardPoolV2 = async (azurAddress, owner, name, symbol, unstakePeriod) => { const RewardPoolV2 = await ethers.getContractFactory("RewardPoolV2", { signer: owner }); - const rewardPoolV2 = await upgrades.deployProxy(RewardPoolV2, [azurAddress, "Staked AZUR", "stAZUR", unstakePeriod]); + const rewardPoolV2 = await upgrades.deployProxy(RewardPoolV2, [azurAddress, name, symbol, unstakePeriod]); await rewardPoolV2.waitForDeployment(); return rewardPoolV2; };