hardhat-deploy 0.11.0-next.2 → 0.11.0-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,mBAAmB,EAEpB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAAC,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAKnD,OAAO,EAGL,oBAAoB,EAKpB,OAAO,EAKP,oBAAoB,EAMrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAelD,OAAO,EAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAClE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAiKxD,wBAAgB,UAAU,CACxB,iBAAiB,EAAE,kBAAkB,EACrC,gBAAgB,EAAE,gBAAgB,EAClC,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,EAChD,cAAc,EAAE,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,oBAAoB,EAChC,YAAY,CAAC,EAAE,MAAM,KAClB,OAAO,CAAC,IAAI,CAAC,EAClB,cAAc,EAAE,MAAM,OAAO,EAC7B,WAAW,EAAE,CACX,UAAU,EAAE,mBAAmB,EAC/B,IAAI,CAAC,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,GAAG,KACP,OAAO,CAAC,mBAAmB,CAAC,EACjC,WAAW,EAAE,MAAM,OAAO,CAAC;IACzB,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,YAAY,EAAE,SAAS,GAAG,SAAS,CAAC;IACpC,oBAAoB,EAAE,SAAS,GAAG,SAAS,CAAC;CAC7C,CAAC,EACF,GAA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,GAAG,CAAC;gBACjB,KAAK,EAAE,MAAM,CAAC;gBACd,OAAO,EAAE;oBACP,IAAI,EAAE,MAAM,CAAC;oBACb,QAAQ,CAAC,EAAE,MAAM,CAAC;oBAClB,YAAY,CAAC,EAAE,MAAM,CAAC;oBACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;oBAC9B,QAAQ,EAAE,MAAM,CAAC;oBACjB,EAAE,EAAE,MAAM,CAAC;oBACX,KAAK,EAAE,MAAM,CAAC;oBACd,KAAK,EAAE,MAAM,CAAC;oBACd,IAAI,EAAE,MAAM,CAAC;oBACb,CAAC,EAAE,MAAM,CAAC;oBACV,CAAC,EAAE,MAAM,CAAC;oBACV,CAAC,EAAE,MAAM,CAAC;oBAEV,OAAO,EAAE,MAAM,CAAC;iBACjB,CAAC;aACH,CAAC;SACH,EACD,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GAAG,SAAS,KAC/B,OAAO,CAAC,IAAI,CAAC,CAAC;KACpB,CAAC;CACH,CA0gGA;AAMD,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC,OAAO,CAAC,CAoBlB"}
@@ -23,6 +23,7 @@ const ProxyAdmin_json_1 = __importDefault(require("../extendedArtifacts/ProxyAdm
23
23
  const EIP173Proxy_json_1 = __importDefault(require("../extendedArtifacts/EIP173Proxy.json"));
24
24
  const EIP173ProxyWithReceive_json_1 = __importDefault(require("../extendedArtifacts/EIP173ProxyWithReceive.json"));
25
25
  const Diamond_json_1 = __importDefault(require("../extendedArtifacts/Diamond.json"));
26
+ const old_diamondbase_json_1 = __importDefault(require("./old_diamondbase.json"));
26
27
  const DiamondERC165Init_json_1 = __importDefault(require("../extendedArtifacts/DiamondERC165Init.json"));
27
28
  const DiamondCutFacet_json_1 = __importDefault(require("../extendedArtifacts/DiamondCutFacet.json"));
28
29
  const DiamondLoupeFacet_json_1 = __importDefault(require("../extendedArtifacts/DiamondLoupeFacet.json"));
@@ -1087,6 +1088,10 @@ Note that in this case, the contract deployment will not behave the same if depl
1087
1088
  }
1088
1089
  async function _deployViaDiamondProxy(name, options) {
1089
1090
  const oldDeployment = await getDeploymentOrNUll(name);
1091
+ if (oldDeployment &&
1092
+ oldDeployment.deployedBytecode === old_diamondbase_json_1.default.deployedByecode) {
1093
+ return _old_deployViaDiamondProxy(name, options);
1094
+ }
1090
1095
  let proxy;
1091
1096
  const deployResult = _checkUpgradeIndex(oldDeployment, options.upgradeIndex);
1092
1097
  if (deployResult) {
@@ -1131,7 +1136,7 @@ Note that in this case, the contract deployment will not behave the same if depl
1131
1136
  });
1132
1137
  }
1133
1138
  facetsSet.push({
1134
- name: '_DefaultDiamondLoopeFacet',
1139
+ name: '_DefaultDiamondLoupeFacet',
1135
1140
  contract: DiamondLoupeFacet_json_1.default,
1136
1141
  args: [],
1137
1142
  deterministic: true,
@@ -1334,6 +1339,7 @@ Note that in this case, the contract deployment will not behave the same if depl
1334
1339
  const executionDeployment = await _deployOne(options.execute.contract.name, {
1335
1340
  from: options.from,
1336
1341
  contract: options.execute.contract.artifact,
1342
+ args: options.execute.contract.args,
1337
1343
  autoMine: options.autoMine,
1338
1344
  estimateGasExtra: options.estimateGasExtra,
1339
1345
  estimatedGasLimit: options.estimatedGasLimit,
@@ -1571,16 +1577,7 @@ Note that in this case, the contract deployment will not behave the same if depl
1571
1577
  if (!executeReceipt) {
1572
1578
  throw new Error('failed to execute');
1573
1579
  }
1574
- const diamondDeployment = {
1575
- receipt: executeReceipt,
1576
- transactionHash: executeReceipt.transactionHash,
1577
- linkedData: options.linkedData,
1578
- address: proxy.address,
1579
- abi,
1580
- facets: facetSnapshot,
1581
- diamondCut: facetCuts,
1582
- execute: options.execute,
1583
- };
1580
+ const diamondDeployment = Object.assign(Object.assign({}, oldDeployment), { linkedData: options.linkedData, address: proxy.address, abi, facets: facetSnapshot, diamondCut: facetCuts, execute: options.execute });
1584
1581
  // TODO reenable history with options
1585
1582
  if (oldDeployment.history) {
1586
1583
  diamondDeployment.history = diamondDeployment.history
@@ -2087,6 +2084,257 @@ data: ${data}
2087
2084
  return deploy(name, options);
2088
2085
  };
2089
2086
  // ////////////////////////////////////////////////////////////////////
2087
+ async function _old_deployViaDiamondProxy(name, options) {
2088
+ if (options.log) {
2089
+ log(`old diamond...`);
2090
+ }
2091
+ const oldDeployment = await getDeploymentOrNUll(name);
2092
+ let proxy;
2093
+ const deployResult = _checkUpgradeIndex(oldDeployment, options.upgradeIndex);
2094
+ if (deployResult) {
2095
+ return deployResult;
2096
+ }
2097
+ if (options.deterministicSalt) {
2098
+ throw new Error(`old diamonds do not support determinsitc deployment`);
2099
+ // need to compute the resulting address accurately
2100
+ }
2101
+ const proxyName = name + '_DiamondProxy';
2102
+ const { address: owner, hardwareWallet } = getDiamondOwner(options);
2103
+ const newSelectors = [];
2104
+ const facetSnapshot = [];
2105
+ const oldFacets = [];
2106
+ const selectorToNotTouch = {};
2107
+ for (const selector of [
2108
+ '0xcdffacc6',
2109
+ '0x52ef6b2c',
2110
+ '0xadfca15e',
2111
+ '0x7a0ed627',
2112
+ '0x01ffc9a7',
2113
+ '0x1f931c1c',
2114
+ '0xf2fde38b',
2115
+ '0x8da5cb5b',
2116
+ ]) {
2117
+ selectorToNotTouch[selector] = true;
2118
+ }
2119
+ if (oldDeployment) {
2120
+ proxy = await getDeployment(proxyName);
2121
+ const diamondProxy = new contracts_1.Contract(proxy.address, proxy.abi, provider);
2122
+ const currentFacets = await diamondProxy.facets();
2123
+ for (const currentFacet of currentFacets) {
2124
+ oldFacets.push(currentFacet);
2125
+ // ensure DiamondLoupeFacet, OwnershipFacet and DiamondCutFacet are kept // TODO options to delete cut them out?
2126
+ if (findAll([
2127
+ '0xcdffacc6',
2128
+ '0x52ef6b2c',
2129
+ '0xadfca15e',
2130
+ '0x7a0ed627',
2131
+ '0x01ffc9a7',
2132
+ ], currentFacet.functionSelectors) || // Loupe
2133
+ currentFacet.functionSelectors[0] === '0x1f931c1c' || // DiamoncCut
2134
+ findAll(['0xf2fde38b', '0x8da5cb5b'], currentFacet.functionSelectors) // ERC173
2135
+ ) {
2136
+ facetSnapshot.push(currentFacet);
2137
+ newSelectors.push(...currentFacet.functionSelectors);
2138
+ }
2139
+ }
2140
+ }
2141
+ else {
2142
+ throw new Error(`old diamond deployments are now disabled`);
2143
+ }
2144
+ // console.log({ oldFacets: JSON.stringify(oldFacets, null, " ") });
2145
+ let changesDetected = !oldDeployment;
2146
+ let abi = old_diamondbase_json_1.default.abi.concat([]);
2147
+ const facetCuts = [];
2148
+ for (const facet of options.facets) {
2149
+ let facetName;
2150
+ let artifact;
2151
+ let linkedData = options.linkedData;
2152
+ let libraries = options.libraries;
2153
+ let facetArgs = options.facetsArgs;
2154
+ let argsSpecific = false;
2155
+ if (typeof facet === 'string') {
2156
+ artifact = await partialExtension.getExtendedArtifact(facet);
2157
+ facetName = facet;
2158
+ }
2159
+ else {
2160
+ if (facet.linkedData) {
2161
+ linkedData = facet.linkedData;
2162
+ }
2163
+ if (facet.libraries) {
2164
+ libraries = facet.libraries;
2165
+ }
2166
+ if (facet.args) {
2167
+ facetArgs = facet.args;
2168
+ argsSpecific = true;
2169
+ }
2170
+ if (facet.contract) {
2171
+ if (typeof facet.contract === 'string') {
2172
+ artifact = await partialExtension.getExtendedArtifact(facet.contract);
2173
+ }
2174
+ else {
2175
+ artifact = facet.contract;
2176
+ }
2177
+ }
2178
+ else {
2179
+ if (!facet.name) {
2180
+ throw new Error(`no name , not contract is specified for facet, cannot proceed`);
2181
+ }
2182
+ artifact = await partialExtension.getExtendedArtifact(facet.name);
2183
+ }
2184
+ facetName = facet.name;
2185
+ if (!facetName) {
2186
+ if (typeof facet.contract === 'string') {
2187
+ facetName = name + '_facet_' + facet.contract;
2188
+ }
2189
+ else {
2190
+ throw new Error(`facet has no name, please specify one`);
2191
+ }
2192
+ }
2193
+ }
2194
+ const constructor = artifact.abi.find((fragment) => fragment.type === 'constructor');
2195
+ if ((!argsSpecific && !constructor) || constructor.inputs.length === 0) {
2196
+ // reset args for case where facet do not expect any and there was no specific args set on it
2197
+ facetArgs = [];
2198
+ }
2199
+ abi = utils_1.mergeABIs([abi, artifact.abi], {
2200
+ check: true,
2201
+ skipSupportsInterface: false,
2202
+ });
2203
+ // TODO allow facet to be named so multiple version could coexist
2204
+ const implementation = await _deployOne(facetName, {
2205
+ contract: artifact,
2206
+ from: options.from,
2207
+ autoMine: options.autoMine,
2208
+ estimateGasExtra: options.estimateGasExtra,
2209
+ estimatedGasLimit: options.estimatedGasLimit,
2210
+ gasPrice: options.gasPrice,
2211
+ maxFeePerGas: options.maxFeePerGas,
2212
+ maxPriorityFeePerGas: options.maxPriorityFeePerGas,
2213
+ log: options.log,
2214
+ // deterministicDeployment: options.deterministicDeployment, // todo ?
2215
+ libraries,
2216
+ linkedData,
2217
+ args: facetArgs,
2218
+ });
2219
+ if (implementation.newlyDeployed) {
2220
+ // console.log(`facet ${facet} deployed at ${implementation.address}`);
2221
+ const newFacet = {
2222
+ facetAddress: implementation.address,
2223
+ functionSelectors: sigsFromABI(implementation.abi),
2224
+ };
2225
+ facetSnapshot.push(newFacet);
2226
+ newSelectors.push(...newFacet.functionSelectors);
2227
+ }
2228
+ else {
2229
+ const oldImpl = await getDeployment(facetName);
2230
+ const newFacet = {
2231
+ facetAddress: oldImpl.address,
2232
+ functionSelectors: sigsFromABI(oldImpl.abi),
2233
+ };
2234
+ facetSnapshot.push(newFacet);
2235
+ newSelectors.push(...newFacet.functionSelectors);
2236
+ }
2237
+ }
2238
+ const oldSelectors = [];
2239
+ const oldSelectorsFacetAddress = {};
2240
+ for (const oldFacet of oldFacets) {
2241
+ for (const selector of oldFacet.functionSelectors) {
2242
+ oldSelectors.push(selector);
2243
+ oldSelectorsFacetAddress[selector] = oldFacet.facetAddress;
2244
+ }
2245
+ }
2246
+ for (const newFacet of facetSnapshot) {
2247
+ const selectorsToAdd = [];
2248
+ const selectorsToReplace = [];
2249
+ for (const selector of newFacet.functionSelectors) {
2250
+ if (oldSelectors.indexOf(selector) > 0) {
2251
+ if (oldSelectorsFacetAddress[selector].toLowerCase() !==
2252
+ newFacet.facetAddress.toLowerCase() &&
2253
+ !selectorToNotTouch[selector]) {
2254
+ selectorsToReplace.push(selector);
2255
+ }
2256
+ }
2257
+ else {
2258
+ if (!selectorToNotTouch[selector]) {
2259
+ selectorsToAdd.push(selector);
2260
+ }
2261
+ }
2262
+ }
2263
+ if (selectorsToReplace.length > 0) {
2264
+ changesDetected = true;
2265
+ facetCuts.push({
2266
+ facetAddress: newFacet.facetAddress,
2267
+ functionSelectors: selectorsToReplace,
2268
+ action: types_1.FacetCutAction.Replace,
2269
+ });
2270
+ }
2271
+ if (selectorsToAdd.length > 0) {
2272
+ changesDetected = true;
2273
+ facetCuts.push({
2274
+ facetAddress: newFacet.facetAddress,
2275
+ functionSelectors: selectorsToAdd,
2276
+ action: types_1.FacetCutAction.Add,
2277
+ });
2278
+ }
2279
+ }
2280
+ const selectorsToDelete = [];
2281
+ for (const selector of oldSelectors) {
2282
+ if (newSelectors.indexOf(selector) === -1) {
2283
+ selectorsToDelete.push(selector);
2284
+ }
2285
+ }
2286
+ if (selectorsToDelete.length > 0) {
2287
+ changesDetected = true;
2288
+ facetCuts.unshift({
2289
+ facetAddress: '0x0000000000000000000000000000000000000000',
2290
+ functionSelectors: selectorsToDelete,
2291
+ action: types_1.FacetCutAction.Remove,
2292
+ });
2293
+ }
2294
+ let data = '0x';
2295
+ if (options.execute) {
2296
+ const diamondContract = new contracts_1.Contract('0x0000000000000000000000000000000000000001', abi);
2297
+ const txData = await diamondContract.populateTransaction[options.execute.methodName](...options.execute.args);
2298
+ data = txData.data || '0x';
2299
+ }
2300
+ if (changesDetected) {
2301
+ if (!proxy) {
2302
+ throw new Error(`no proxy found: old diamond deployments are now disabled`);
2303
+ }
2304
+ else {
2305
+ const currentOwner = await read(proxyName, 'owner');
2306
+ if (currentOwner.toLowerCase() !== owner.toLowerCase()) {
2307
+ throw new Error('To change owner, you need to call `transferOwnership`');
2308
+ }
2309
+ if (currentOwner === constants_1.AddressZero) {
2310
+ throw new Error('The Diamond belongs to no-one. It cannot be upgraded anymore');
2311
+ }
2312
+ const executeReceipt = await execute(name, Object.assign(Object.assign({}, options), { from: currentOwner }), 'diamondCut', facetCuts, data === '0x'
2313
+ ? '0x0000000000000000000000000000000000000000'
2314
+ : proxy.address, data);
2315
+ if (!executeReceipt) {
2316
+ throw new Error('failed to execute');
2317
+ }
2318
+ const diamondDeployment = Object.assign(Object.assign({}, oldDeployment), { linkedData: options.linkedData, address: proxy.address, abi, facets: facetSnapshot, diamondCut: facetCuts, execute: options.execute });
2319
+ // TODO reenable history with options
2320
+ if (oldDeployment.history) {
2321
+ diamondDeployment.history = diamondDeployment.history
2322
+ ? diamondDeployment.history.concat([oldDeployment])
2323
+ : [oldDeployment];
2324
+ }
2325
+ await saveDeployment(name, diamondDeployment);
2326
+ }
2327
+ const deployment = await partialExtension.get(name);
2328
+ return Object.assign(Object.assign({}, deployment), { newlyDeployed: true });
2329
+ }
2330
+ else {
2331
+ const oldDeployment = await partialExtension.get(name);
2332
+ const proxiedDeployment = Object.assign(Object.assign({}, oldDeployment), { facets: facetSnapshot, diamondCut: facetCuts, abi, execute: options.execute });
2333
+ await saveDeployment(name, proxiedDeployment);
2334
+ const deployment = await partialExtension.get(name);
2335
+ return Object.assign(Object.assign({}, deployment), { newlyDeployed: false });
2336
+ }
2337
+ }
2090
2338
  return { extension, utils };
2091
2339
  }
2092
2340
  exports.addHelpers = addHelpers;