Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check chainId for predeployed contracts #185

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dictionaries/domain-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ reentrancy
secp256k1
typehash
untrusted
predeployed

17 changes: 16 additions & 1 deletion src/upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ProxyAdmin } from "../typechain-types";
import { artifacts, ethers, network, upgrades } from "hardhat";
import { getManifestAdmin } from "@openzeppelin/hardhat-upgrades/dist/admin";
import { getVersion } from "./version";
import { promises as fs } from "fs";
import { promises as fs, existsSync } from "fs";
import { deployLibraries, getLinkedContractFactory, getManifestFile } from "./deploy";
import { UnsignedTransaction } from "ethers";
import { SkaleABIFile } from "./types/SkaleABIFile";
Expand Down Expand Up @@ -49,6 +49,21 @@ export abstract class Upgrader {
// public

async upgrade() {
const MAINNET_CHAIN_ID = 1;
const GOERLI_CHAIN_ID = 5;
const mainChainIds = [MAINNET_CHAIN_ID, GOERLI_CHAIN_ID];
const { chainId } = await hre.ethers.provider.getNetwork();

if (!mainChainIds.includes(chainId)) {
const originManifestFileName = __dirname + "/../.openzeppelin/predeployed.json";
const targetManifestFileName = __dirname + `/../.openzeppelin/unknown-${chainId}.json`;

if (!existsSync(targetManifestFileName)) {
console.log("Create a manifest file based on predeployed template");
await fs.copyFile(originManifestFileName, targetManifestFileName);
}
}

const proxyAdmin = await getManifestAdmin(hre) as ProxyAdmin;

const deployedVersion = await this.getDeployedVersion();
Expand Down