-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathdeploy.ts
More file actions
85 lines (71 loc) · 2.47 KB
/
deploy.ts
File metadata and controls
85 lines (71 loc) · 2.47 KB
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
// SPDX-FileCopyrightText: © 2025 Phala Network <dstack@phala.network>
//
// SPDX-License-Identifier: Apache-2.0
import { HardhatRuntimeEnvironment } from "hardhat/types";
import * as helpers from "../lib/deployment-helpers";
// This function should be called directly by Hardhat tasks
export async function deployContract(hre: HardhatRuntimeEnvironment, contractName: string, initializerArgs: any[] = [], quiet: boolean = false, initializer?: string) {
try {
function log(...msgs: any[]) {
if (!quiet) {
console.log(...msgs);
}
}
log(`Starting ${contractName} deployment process...`);
if (!quiet) {
// Get network info
await helpers.logNetworkInfo(hre);
}
log("Getting contract factory...");
const contractFactory = await hre.ethers.getContractFactory(contractName);
if (!quiet) {
// Estimate gas for deployment
await helpers.estimateDeploymentCost(
hre,
contractName,
initializerArgs,
initializer
);
// Prompt for confirmation
if (!(await helpers.confirmAction('Do you want to proceed with deployment?'))) {
log('Deployment cancelled');
return;
}
}
// Deploy using proxy pattern
log("Deploying proxy...");
const contract = await hre.upgrades.deployProxy(contractFactory,
initializerArgs,
{ kind: 'uups', ...(initializer ? { initializer } : {}) }
);
log("Waiting for deployment...");
await contract.waitForDeployment();
const address = await contract.getAddress();
log(`${contractName} Proxy deployed to:`, address);
// Verify deployment
await helpers.verifyDeployment(hre, address, quiet);
const tx = await contract.deploymentTransaction();
log("Deployment completed successfully");
log("Transaction hash:", tx?.hash);
return contract;
} catch (error) {
console.error("Error during deployment:", error);
throw error;
}
}
// For backward compatibility when running the script directly
async function main() {
const hre = require("hardhat");
const deployer = await helpers.getSigner(hre);
const address = await deployer.getAddress();
console.log("Deploying with account:", address);
console.log("Account balance:", await helpers.accountBalance(hre.ethers, address));
await deployContract(hre, "DstackKms", [address]);
}
// Only execute if directly run
if (require.main === module) {
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
}