Skip to content

Commit

Permalink
Set nonce prepareUpgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Sep 21, 2023
1 parent 3a9281c commit 9427935
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/contractFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
18 changes: 15 additions & 3 deletions src/upgrader.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -44,6 +45,8 @@ export abstract class Upgrader {

submitter: Submitter;

nonceProvider?: NonceProvider;

constructor (
project: Project,
submitter: Submitter = new AutoSubmitter()
Expand Down Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -193,6 +200,11 @@ export abstract class Upgrader {
proxyAddress,
contractFactory,
{
"constructorArgs": [
{
"nonce": this.nonceProvider?.reserveNonce()
}
],
"unsafeAllowLinkedLibraries": true,
"unsafeAllowRenames": true
}
Expand Down

0 comments on commit 9427935

Please sign in to comment.