forked from bosonprotocol/boson-protocol-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate_2.2.1.js
103 lines (82 loc) · 3.26 KB
/
migrate_2.2.1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const shell = require("shelljs");
const { readContracts } = require("../util/utils.js");
const hre = require("hardhat");
const { provider, getContractAt } = hre.ethers;
const network = hre.network.name;
const { getStateModifyingFunctionsHashes } = require("../../scripts/util/diamond-utils.js");
const tag = "v2.2.1";
const config = {
addOrUpgrade: [
"AccountHandlerFacet",
"SellerHandlerFacet",
"DisputeResolverHandlerFacet",
"OrchestrationHandlerFacet1",
"ProtocolInitializationHandlerFacet",
],
remove: [],
skipSelectors: {},
facetsToInit: {
AccountHandlerFacet: { init: [] },
OrchestrationHandlerFacet1: { init: [] },
},
initializationData: "0x",
};
async function migrate(env) {
console.log(`Migration ${tag} started`);
try {
console.log("Removing any local changes before upgrading");
shell.exec(`git reset @{u}`);
const statusOutput = shell.exec("git status -s -uno scripts");
if (statusOutput.stdout) {
throw new Error("Local changes found. Please stash them before upgrading");
}
// Checking old version contracts to get selectors to remove
console.log("Checking out contracts on version 2.2.0");
shell.exec(`rm -rf contracts/*`);
shell.exec(`git checkout v2.2.0 contracts`);
console.log("Compiling old contracts");
await hre.run("clean");
await hre.run("compile");
const { chainId } = await provider.getNetwork();
const contractsFile = readContracts(chainId, network, env);
if (contractsFile?.protocolVersion != "2.2.0") {
throw new Error("Current contract version must be 2.2.0");
}
let contracts = contractsFile?.contracts;
// Get addresses of currently deployed contracts
const protocolAddress = contracts.find((c) => c.name === "ProtocolDiamond")?.address;
const getFunctionHashesClosure = getStateModifyingFunctionsHashes(
["SellerHandlerFacet", "OrchestrationHandlerFacet1"],
undefined,
["createSeller", "updateSeller"]
);
const selectorsToRemove = await getFunctionHashesClosure();
console.log(`Checking out contracts on version ${tag}`);
shell.exec(`rm -rf contracts/*`);
shell.exec(`git checkout ${tag} contracts package.json package-lock.json`);
console.log("Installing dependencies");
shell.exec(`npm install`);
console.log("Compiling contracts");
await hre.run("clean");
await hre.run("compile");
console.log("Executing upgrade facets script");
await hre.run("upgrade-facets", {
env,
facetConfig: JSON.stringify(config),
newVersion: tag.replace("v", ""),
});
const selectorsToAdd = await getFunctionHashesClosure();
const metaTransactionHandlerFacet = await getContractAt("MetaTransactionsHandlerFacet", protocolAddress);
console.log("Removing selectors", selectorsToRemove.join(","));
await metaTransactionHandlerFacet.setAllowlistedFunctions(selectorsToRemove, false);
console.log("Adding selectors", selectorsToAdd.join(","));
await metaTransactionHandlerFacet.setAllowlistedFunctions(selectorsToAdd, true);
shell.exec(`git checkout HEAD`);
console.log(`Migration ${tag} completed`);
} catch (e) {
console.error(e);
shell.exec(`git checkout HEAD`);
throw `Migration failed with: ${e}`;
}
}
exports.migrate = migrate;