From 942793538eb08c83d70a9fdf7dcc245c28703901 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Thu, 21 Sep 2023 19:14:57 +0300 Subject: [PATCH] Set nonce prepareUpgrade --- src/contractFactory.ts | 11 +++++++++-- src/upgrader.ts | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/contractFactory.ts b/src/contractFactory.ts index 6d30267..452bafb 100644 --- a/src/contractFactory.ts +++ b/src/contractFactory.ts @@ -4,6 +4,7 @@ import { getManifestFile } from "./deploy"; import {LinkReferences} from "hardhat/types"; +import {NonceProvider} from "./nonceProvider"; import {SkaleManifestData} from "./types/SkaleManifestData"; import {promises as fs} from "fs"; import {hashBytecode} from "@openzeppelin/upgrades-core"; @@ -107,7 +108,10 @@ const getLibrariesToUpgrade = async ( }; }; -export const getContractFactoryAndUpdateManifest = async (contract: string) => { +export const getContractFactoryAndUpdateManifest = async ( + contract: string, + nonceProvider?: NonceProvider +) => { const {linkReferences} = await artifacts.readArtifact(contract); if (!Object.keys(linkReferences).length) { return await ethers.getContractFactory(contract); @@ -122,7 +126,10 @@ export const getContractFactoryAndUpdateManifest = async (contract: string) => { manifest, linkReferences ); - const libraries = await deployLibraries(librariesToUpgrade); + const libraries = await deployLibraries( + librariesToUpgrade, + nonceProvider + ); await updateManifest( manifest, libraries, diff --git a/src/upgrader.ts b/src/upgrader.ts index 6ad03c2..1c7d7be 100644 --- a/src/upgrader.ts +++ b/src/upgrader.ts @@ -1,7 +1,8 @@ -import hre, {network, upgrades} from "hardhat"; +import hre, {ethers, network, upgrades} from "hardhat"; import {AutoSubmitter} from "./submitters/auto-submitter"; import {EXIT_CODES} from "./exitCodes"; import {Instance} from "@skalenetwork/skale-contracts-ethers-v5"; +import {NonceProvider} from "./nonceProvider"; import {ProxyAdmin} from "../typechain-types"; import {Submitter} from "./submitters/submitter"; import {UnsignedTransaction} from "ethers"; @@ -44,6 +45,8 @@ export abstract class Upgrader { submitter: Submitter; + nonceProvider?: NonceProvider; + constructor ( project: Project, submitter: Submitter = new AutoSubmitter() @@ -170,6 +173,8 @@ export abstract class Upgrader { } private async deployNewImplementations () { + const [deployer] = await ethers.getSigners(); + this.nonceProvider ??= await NonceProvider.createForWallet(deployer); const contracts = await Promise.all(this.contractNamesToUpgrade. map( this.deployNewImplementation, @@ -179,8 +184,10 @@ export abstract class Upgrader { } private async deployNewImplementation (contract: string) { - const contractFactory = - await getContractFactoryAndUpdateManifest(contract); + const contractFactory = await getContractFactoryAndUpdateManifest( + contract, + this.nonceProvider + ); const proxyAddress = (await this.instance.getContract(contract)).address; @@ -193,6 +200,11 @@ export abstract class Upgrader { proxyAddress, contractFactory, { + "constructorArgs": [ + { + "nonce": this.nonceProvider?.reserveNonce() + } + ], "unsafeAllowLinkedLibraries": true, "unsafeAllowRenames": true }