From 817a330f36df8f51148513cfe6d95427402c13e5 Mon Sep 17 00:00:00 2001 From: belbix <7453635@gmail.com> Date: Thu, 21 Dec 2023 07:11:15 +0300 Subject: [PATCH] deploy zkevm --- hardhat.config.ts | 38 +++++++++++++-- scripts/addresses/addresses.ts | 3 ++ scripts/addresses/zkevm.ts | 24 +++++----- scripts/deploy/DeployAllProdSimplified.ts | 23 ++++++---- scripts/gov/execute-upgrades.ts | 4 +- scripts/utils/DeployerUtils.ts | 56 +++++++++++------------ scripts/utils/RunHelper.ts | 49 ++++++++++++++++++-- 7 files changed, 136 insertions(+), 61 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 18cfe8f..04fb815 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -51,6 +51,9 @@ const argv = require('yargs/yargs')() networkScanKeyBsc: { type: "string", }, + networkScanKeyZkevm: { + type: "string", + }, privateKey: { type: "string", default: "85bb5fa78d5c4ed1fde856e9d0d1fe19973d7a79ce9ed6c0358ee06a4550504e" // random account @@ -67,6 +70,13 @@ const argv = require('yargs/yargs')() type: "number", default: 0 }, + zkevmRpcUrl: { + type: "string", + }, + zkevmForkBlock: { + type: "number", + default: 0 + }, loggingEnabled: { type: "boolean", default: false @@ -97,12 +107,14 @@ export default { argv.hardhatChainId === 1 ? argv.ethRpcUrl : argv.hardhatChainId === 137 ? argv.maticRpcUrl : argv.hardhatChainId === 8453 ? argv.baseRpcUrl : - undefined, + argv.hardhatChainId === 1101 ? argv.zkevmRpcUrl : + undefined, blockNumber: argv.hardhatChainId === 1 ? argv.ethForkBlock !== 0 ? argv.ethForkBlock : undefined : argv.hardhatChainId === 137 ? argv.maticForkBlock !== 0 ? argv.maticForkBlock : undefined : argv.hardhatChainId === 8453 ? argv.baseForkBlock !== 0 ? argv.baseForkBlock : undefined : - undefined + argv.hardhatChainId === 1101 ? argv.zkevmForkBlock !== 0 ? argv.zkevmForkBlock : undefined : + undefined } : undefined, accounts: { mnemonic: "test test test test test test test test test test test junk", @@ -139,6 +151,17 @@ export default { // gas: 50_000_000_000, accounts: [argv.privateKey], }, + zkevm: { + url: argv.zkevmRpcUrl || '', + chainId: 1101, + accounts: [argv.privateKey], + gasPrice: 1000000000, + verify: { + etherscan: { + apiKey: argv.networkScanKeyZkevm + } + } + }, }, etherscan: { // https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html#multiple-api-keys-and-alternative-block-explorers @@ -149,6 +172,7 @@ export default { polygon: argv.networkScanKeyMatic || argv.networkScanKey, bsc: argv.networkScanKeyBsc, base: argv.networkScanKeyBase, + zkevm: argv.networkScanKeyZkevm || argv.networkScanKey, }, customChains: [ { @@ -158,7 +182,15 @@ export default { apiURL: "https://api.basescan.org/api", browserURL: "https://basescan.org" } - } + }, + { + network: "zkevm", + chainId: 1101, + urls: { + apiURL: "https://api-zkevm.polygonscan.com/api", + browserURL: "https://zkevm.polygonscan.com/" + } + }, ] }, solidity: { diff --git a/scripts/addresses/addresses.ts b/scripts/addresses/addresses.ts index 0a8ab52..381963c 100644 --- a/scripts/addresses/addresses.ts +++ b/scripts/addresses/addresses.ts @@ -4,6 +4,7 @@ import {PolygonAddresses} from "./polygon"; import {SepoliaAddresses} from "./sepolia"; import {ToolsAddresses} from "../models/ToolsAddresses"; import {BaseAddresses} from "./base"; +import {ZkEvmAddresses} from "./zkevm"; // tslint:disable-next-line:no-var-requires const hre = require("hardhat"); @@ -15,11 +16,13 @@ export class Addresses { [11155111, SepoliaAddresses.CORE_ADDRESSES], [137, PolygonAddresses.CORE_ADDRESSES], [8453, BaseAddresses.CORE_ADDRESSES], + [1101, ZkEvmAddresses.CORE_ADDRESSES], ]); public static TOOLS = new Map([ [137, PolygonAddresses.TOOLS_ADDRESSES], [8453, BaseAddresses.TOOLS_ADDRESSES], + [1101, ZkEvmAddresses.TOOLS_ADDRESSES], ]); public static getCore(): CoreAddresses { diff --git a/scripts/addresses/zkevm.ts b/scripts/addresses/zkevm.ts index 938bc90..31b6cdf 100644 --- a/scripts/addresses/zkevm.ts +++ b/scripts/addresses/zkevm.ts @@ -5,24 +5,24 @@ import {CoreAddresses} from "../models/CoreAddresses"; import {ToolsAddresses} from "../models/ToolsAddresses"; // noinspection SpellCheckingInspection -export class BaseAddresses { +export class ZkEvmAddresses { public static CORE_ADDRESSES = new CoreAddresses( "0x7C1B24c139a3EdA18Ab77C8Fa04A0F816C23e6D4", // tetu - "", // controller - "", // ve - "", // veDist - "", // gauge - "", // bribe - "", // tetuVoter - "", // platformVoter - "", // forwarder - "", // vaultFactory - "", // investFundV2 + "0x35B0329118790B8c8FC36262812D92a4923C6795", // controller + "0x0000000000000000000000000000000000000000", // ve + "0x0000000000000000000000000000000000000000", // veDist + "0xd353254872E8797B159594c1E528b8Be9a6cb1F8", // gauge + "0x0000000000000000000000000000000000000000", // bribe + "0x099C314F792e1F91f53765Fc64AaDCcf4dCf1538", // tetuVoter + "0x0000000000000000000000000000000000000000", // platformVoter + "0x255707B70BF90aa112006E1b07B9AeA6De021424", // forwarder + "0xeFBc16b8c973DecA383aAAbAB07153D2EB676556", // vaultFactory + "0x5373C3d09C39D8F256f88E08aa61402FE14A3792", // investFundV2 ); public static TOOLS_ADDRESSES = new ToolsAddresses( - "",// todo + "0xBcda73B7184D5974F77721db79ff8BA190b342ce", "",// todo "",// todo ); diff --git a/scripts/deploy/DeployAllProdSimplified.ts b/scripts/deploy/DeployAllProdSimplified.ts index a524d25..e50e979 100644 --- a/scripts/deploy/DeployAllProdSimplified.ts +++ b/scripts/deploy/DeployAllProdSimplified.ts @@ -17,7 +17,7 @@ async function main() { const forwarder = await DeployerUtils.deployForwarderSimplified(signer, controller.address, tetu); const fundAdr = await DeployerUtils.deployProxy(signer, 'InvestFundV2'); const investFund = InvestFundV2__factory.connect(fundAdr, signer); - await RunHelper.runAndWait(() => investFund.init(controller.address)); + await RunHelper.runAndWait2(investFund.populateTransaction.init(controller.address)); const vaultImpl = await DeployerUtils.deployContract(signer, 'TetuVaultV2'); const vaultInsuranceImpl = await DeployerUtils.deployContract(signer, 'VaultInsurance'); @@ -31,16 +31,16 @@ async function main() { splitterImpl.address, ); - await RunHelper.runAndWait(() => controller.announceAddressChange(2, tetuVoter.address)); - await RunHelper.runAndWait(() => controller.announceAddressChange(4, tools.liquidator)); - await RunHelper.runAndWait(() => controller.announceAddressChange(5, forwarder.address)); - await RunHelper.runAndWait(() => controller.announceAddressChange(6, fundAdr)); + await RunHelper.runAndWait2(controller.populateTransaction.announceAddressChange(2, tetuVoter.address)); + await RunHelper.runAndWait2(controller.populateTransaction.announceAddressChange(4, tools.liquidator)); + await RunHelper.runAndWait2(controller.populateTransaction.announceAddressChange(5, forwarder.address)); + await RunHelper.runAndWait2(controller.populateTransaction.announceAddressChange(6, fundAdr)); - await RunHelper.runAndWait(() => controller.changeAddress(2)); // TETU_VOTER - await RunHelper.runAndWait(() => controller.changeAddress(4)); // LIQUIDATOR - await RunHelper.runAndWait(() => controller.changeAddress(5)); // FORWARDER - await RunHelper.runAndWait(() => controller.changeAddress(6)); // INVEST_FUND + await RunHelper.runAndWait2(controller.populateTransaction.changeAddress(2)); // TETU_VOTER + await RunHelper.runAndWait2(controller.populateTransaction.changeAddress(4)); // LIQUIDATOR + await RunHelper.runAndWait2(controller.populateTransaction.changeAddress(5)); // FORWARDER + await RunHelper.runAndWait2(controller.populateTransaction.changeAddress(6)); // INVEST_FUND const result = ` public static CORE_ADDRESSES = new CoreAddresses( "${tetu}", // tetu @@ -60,7 +60,10 @@ async function main() { } main() - .then(() => process.exit(0)) + .then(() => { + console.log('Script finished successfully'); + process.exit(0); + }) .catch(error => { console.error(error); process.exit(1); diff --git a/scripts/gov/execute-upgrades.ts b/scripts/gov/execute-upgrades.ts index 4a416b5..e5386b3 100644 --- a/scripts/gov/execute-upgrades.ts +++ b/scripts/gov/execute-upgrades.ts @@ -2,7 +2,6 @@ import {ethers} from "hardhat"; import {Addresses} from "../addresses/addresses"; import {ControllerV2__factory} from "../../typechain"; import {RunHelper} from "../utils/RunHelper"; -import {txParams} from "../deploy/DeployContract"; // tslint:disable-next-line:no-var-requires const hre = require("hardhat"); @@ -31,8 +30,7 @@ async function main() { console.log('Ready to Update ', proxiesReadyToUpgrade); if (proxiesReadyToUpgrade.length !== 0) { - const props = await txParams(hre, ethers.provider); - await RunHelper.runAndWait(() => ControllerV2__factory.connect(core.controller, signer).upgradeProxy(proxiesReadyToUpgrade, {...props})); + await RunHelper.runAndWait2(ControllerV2__factory.connect(core.controller, signer).populateTransaction.upgradeProxy(proxiesReadyToUpgrade)); } diff --git a/scripts/utils/DeployerUtils.ts b/scripts/utils/DeployerUtils.ts index 41d5410..e198e7a 100644 --- a/scripts/utils/DeployerUtils.ts +++ b/scripts/utils/DeployerUtils.ts @@ -63,7 +63,7 @@ export class DeployerUtils { public static async deployMockToken(signer: SignerWithAddress, name = 'MOCK', decimals = 18, premint = true) { const token = await DeployerUtils.deployContract(signer, 'MockToken', name + '_MOCK_TOKEN', name, decimals) as MockToken; if (premint) { - await RunHelper.runAndWait(() => token.mint(signer.address, parseUnits('1000000', decimals))); + await RunHelper.runAndWait2(token.populateTransaction.mint(signer.address, parseUnits('1000000', decimals))); } return token; } @@ -79,7 +79,7 @@ export class DeployerUtils { public static async deployProxy(signer: SignerWithAddress, contract: string) { const logic = await DeployerUtils.deployContract(signer, contract); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); return proxy.address; } @@ -112,8 +112,8 @@ export class DeployerUtils { public static async deployVeTetu(signer: SignerWithAddress, token: string, controller: string, weight = parseUnits('100')) { const logic = await DeployerUtils.deployContract(signer, 'VeTetu'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); - await RunHelper.runAndWait(() => VeTetu__factory.connect(proxy.address, signer).init( + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); + await RunHelper.runAndWait2(VeTetu__factory.connect(proxy.address, signer).populateTransaction.init( token, weight, controller @@ -131,8 +131,8 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'TetuVoter'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); - await RunHelper.runAndWait(() => TetuVoter__factory.connect(proxy.address, signer).init( + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); + await RunHelper.runAndWait2(TetuVoter__factory.connect(proxy.address, signer).populateTransaction.init( controller, ve, rewardToken, @@ -150,8 +150,8 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'TetuVoterSimplified'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); - await RunHelper.runAndWait(() => TetuVoterSimplified__factory.connect(proxy.address, signer).init( + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); + await RunHelper.runAndWait2(TetuVoterSimplified__factory.connect(proxy.address, signer).populateTransaction.init( controller, rewardToken, gauge, @@ -167,8 +167,8 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'MultiGauge'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); - await RunHelper.runAndWait(() => MultiGauge__factory.connect(proxy.address, signer).init( + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); + await RunHelper.runAndWait2(MultiGauge__factory.connect(proxy.address, signer).populateTransaction.init( controller, ve, defaultRewardToken, @@ -183,8 +183,8 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'MultiGaugeNoBoost'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); - await RunHelper.runAndWait(() => MultiGaugeNoBoost__factory.connect(proxy.address, signer).init( + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); + await RunHelper.runAndWait2(MultiGaugeNoBoost__factory.connect(proxy.address, signer).populateTransaction.init( controller, defaultRewardToken, )); @@ -199,8 +199,8 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'MultiBribe'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); - await RunHelper.runAndWait(() => MultiBribe__factory.connect(proxy.address, signer).init( + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); + await RunHelper.runAndWait2(MultiBribe__factory.connect(proxy.address, signer).populateTransaction.init( controller, ve, defaultReward @@ -220,8 +220,8 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'VeDistributor'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); - await RunHelper.runAndWait(() => VeDistributor__factory.connect(proxy.address, signer).init( + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); + await RunHelper.runAndWait2(VeDistributor__factory.connect(proxy.address, signer).populateTransaction.init( controller, ve, rewardToken @@ -237,8 +237,8 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'VeDistributorV2'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); - await RunHelper.runAndWait(() => VeDistributorV2__factory.connect(proxy.address, signer).init( + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); + await RunHelper.runAndWait2(VeDistributorV2__factory.connect(proxy.address, signer).populateTransaction.init( controller, ve, rewardToken @@ -299,9 +299,9 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'ForwarderV3') as ForwarderV3; const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); const forwarder = ForwarderV3__factory.connect(proxy.address, signer); - await RunHelper.runAndWait(() => forwarder.init( + await RunHelper.runAndWait2(forwarder.populateTransaction.init( controller, tetu, bribe @@ -316,9 +316,9 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'ForwarderV4'); const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); const forwarder = ForwarderV4__factory.connect(proxy.address, signer); - await RunHelper.runAndWait(() => forwarder.init( + await RunHelper.runAndWait2(forwarder.populateTransaction.init( controller, tetu, )); @@ -332,9 +332,9 @@ export class DeployerUtils { ) { const logic = await DeployerUtils.deployContract(signer, 'PlatformVoter') as PlatformVoter; const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); const forwarder = PlatformVoter__factory.connect(proxy.address, signer); - await RunHelper.runAndWait(() => forwarder.init( + await RunHelper.runAndWait2(forwarder.populateTransaction.init( controller, ve )); @@ -344,18 +344,18 @@ export class DeployerUtils { public static async deployController(signer: SignerWithAddress) { const logic = await DeployerUtils.deployContract(signer, 'ControllerV2') as ControllerV2; const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); const controller = ControllerV2__factory.connect(proxy.address, signer); - await RunHelper.runAndWait(() => controller.init(signer.address)); + await RunHelper.runAndWait2(controller.populateTransaction.init(signer.address)); return controller; } public static async deployTetuEmitter(signer: SignerWithAddress, controller: string, token: string, bribe: string) { const logic = await DeployerUtils.deployContract(signer, 'TetuEmitter') as ControllerV2; const proxy = await DeployerUtils.deployContract(signer, 'ProxyControlled') as ProxyControlled; - await RunHelper.runAndWait(() => proxy.initProxy(logic.address)); + await RunHelper.runAndWait2(proxy.populateTransaction.initProxy(logic.address)); const contract = TetuEmitter__factory.connect(proxy.address, signer); - await RunHelper.runAndWait(() => contract.init(controller, token, bribe)); + await RunHelper.runAndWait2(contract.populateTransaction.init(controller, token, bribe)); return contract; } diff --git a/scripts/utils/RunHelper.ts b/scripts/utils/RunHelper.ts index d7cbfb6..d718316 100644 --- a/scripts/utils/RunHelper.ts +++ b/scripts/utils/RunHelper.ts @@ -1,15 +1,13 @@ -import {ethers} from "hardhat"; -import {ContractTransaction} from "ethers"; +import hre, {ethers} from "hardhat"; +import {BigNumber, ContractTransaction, PopulatedTransaction} from "ethers"; import {Logger} from "tslog"; import logSettings from "../../log_settings"; import {Misc} from "./Misc"; import {WAIT_BLOCKS_BETWEEN_DEPLOY} from "../deploy/DeployContract"; +import {formatUnits} from "ethers/lib/utils"; const log: Logger = new Logger(logSettings); -// tslint:disable-next-line:no-var-requires -const hre = require("hardhat"); - export class RunHelper { public static async runAndWait(callback: () => Promise, stopOnError = true, wait = true) { @@ -46,4 +44,45 @@ export class RunHelper { Misc.printDuration('runAndWait completed', start); } + public static async runAndWait2(txPopulated: Promise, stopOnError = true, wait = true) { + console.log('prepare run and wait2') + const tx = await txPopulated; + const signer = (await ethers.getSigners())[0]; + const gas = (await signer.estimateGas(tx)).toNumber() + + const params = await RunHelper.txParams(); + console.log('params', params) + + tx.gasLimit = BigNumber.from(gas).mul(15).div(10); + + if (params?.maxFeePerGas) tx.maxFeePerGas = BigNumber.from(params.maxFeePerGas); + if (params?.maxPriorityFeePerGas) tx.maxPriorityFeePerGas = BigNumber.from(params.maxPriorityFeePerGas); + if (params?.gasPrice) tx.gasPrice = BigNumber.from(params.gasPrice); + + return RunHelper.runAndWait(() => signer.sendTransaction(tx), stopOnError, wait); + } + + public static async txParams() { + const provider = ethers.provider; + const feeData = await provider.getFeeData(); + + + console.log('maxPriorityFeePerGas', formatUnits(feeData.maxPriorityFeePerGas?.toString() ?? '0', 9)); + console.log('maxFeePerGas', formatUnits(feeData.maxFeePerGas?.toString() ?? '0', 9)); + console.log('gas price:', formatUnits(feeData.gasPrice?.toString() ?? '0', 9)); + + if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) { + const maxPriorityFeePerGas = Math.max(feeData.maxPriorityFeePerGas?.toNumber() ?? 1, feeData.lastBaseFeePerGas?.toNumber() ?? 1); + const maxFeePerGas = (feeData.maxFeePerGas?.toNumber() ?? 1) * 2; + return { + maxPriorityFeePerGas: maxPriorityFeePerGas.toFixed(0), + maxFeePerGas: maxFeePerGas.toFixed(0), + }; + } else { + return { + gasPrice: ((feeData.gasPrice?.toNumber() ?? 1) * 1.2).toFixed(0), + }; + } + } + }