MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / upgradeContract

Function upgradeContract

kms/auth-eth/scripts/upgrade.ts:10–66  ·  view source on GitHub ↗
(
  hre: HardhatRuntimeEnvironment,
  contractName: string,
  proxyAddress?: string,
  dryRun: boolean = false
)

Source from the content-addressed store, hash-verified

8
9// This function can be called directly by Hardhat tasks
10export async function upgradeContract(
11 hre: HardhatRuntimeEnvironment,
12 contractName: string,
13 proxyAddress?: string,
14 dryRun: boolean = false
15) {
16 try {
17 if (!proxyAddress) {
18 throw new Error("Proxy address is required but was not provided");
19 }
20
21 console.log(`Preparing to upgrade ${contractName} at ${proxyAddress}...`);
22 console.log(`Mode: ${dryRun ? "Dry Run (simulation only)" : "Live Upgrade"}`);
23
24 // Get network info to confirm we're on the right network
25 await helpers.logNetworkInfo(hre);
26
27 // Prepare the upgrade
28 const {
29 newImplementationAddress,
30 upgradeTx
31 } = await helpers.prepareContractUpgrade(hre, proxyAddress, contractName, "uups");
32
33 if (dryRun) {
34 console.log("Upgrade transaction data:", upgradeTx);
35 return {
36 proxyAddress,
37 newImplementationAddress,
38 upgradeTx
39 };
40 } else {
41 // Estimate the gas cost
42 await helpers.estimateUpgradeCost(hre, proxyAddress, upgradeTx);
43
44 // Confirm the upgrade
45 const confirmed = await helpers.confirmAction(`Are you sure you want to upgrade ${contractName}?`);
46 if (!confirmed) {
47 console.log("Upgrade cancelled");
48 return;
49 }
50
51 console.log("Executing upgrade...");
52 // Execute the upgrade
53 const upgraded = await helpers.executeContractUpgrade(
54 hre,
55 proxyAddress,
56 contractName,
57 "uups"
58 );
59
60 return upgraded;
61 }
62 } catch (error) {
63 console.error("Error during upgrade:", error);
64 throw error;
65 }
66}
67

Callers 2

hardhat.config.tsFile · 0.90
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected