(hre: HardhatRuntimeEnvironment, contractName: string, initializerArgs: any[] = [], quiet: boolean = false, initializer?: string)
| 7 | |
| 8 | // This function should be called directly by Hardhat tasks |
| 9 | export async function deployContract(hre: HardhatRuntimeEnvironment, contractName: string, initializerArgs: any[] = [], quiet: boolean = false, initializer?: string) { |
| 10 | try { |
| 11 | function log(...msgs: any[]) { |
| 12 | if (!quiet) { |
| 13 | console.log(...msgs); |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | log(`Starting ${contractName} deployment process...`); |
| 18 | |
| 19 | if (!quiet) { |
| 20 | // Get network info |
| 21 | await helpers.logNetworkInfo(hre); |
| 22 | } |
| 23 | |
| 24 | log("Getting contract factory..."); |
| 25 | const contractFactory = await hre.ethers.getContractFactory(contractName); |
| 26 | |
| 27 | if (!quiet) { |
| 28 | // Estimate gas for deployment |
| 29 | await helpers.estimateDeploymentCost( |
| 30 | hre, |
| 31 | contractName, |
| 32 | initializerArgs, |
| 33 | initializer |
| 34 | ); |
| 35 | |
| 36 | // Prompt for confirmation |
| 37 | if (!(await helpers.confirmAction('Do you want to proceed with deployment?'))) { |
| 38 | log('Deployment cancelled'); |
| 39 | return; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // Deploy using proxy pattern |
| 44 | log("Deploying proxy..."); |
| 45 | const contract = await hre.upgrades.deployProxy(contractFactory, |
| 46 | initializerArgs, |
| 47 | { kind: 'uups', ...(initializer ? { initializer } : {}) } |
| 48 | ); |
| 49 | log("Waiting for deployment..."); |
| 50 | await contract.waitForDeployment(); |
| 51 | |
| 52 | const address = await contract.getAddress(); |
| 53 | log(`${contractName} Proxy deployed to:`, address); |
| 54 | |
| 55 | // Verify deployment |
| 56 | await helpers.verifyDeployment(hre, address, quiet); |
| 57 | |
| 58 | const tx = await contract.deploymentTransaction(); |
| 59 | log("Deployment completed successfully"); |
| 60 | log("Transaction hash:", tx?.hash); |
| 61 | |
| 62 | return contract; |
| 63 | } catch (error) { |
| 64 | console.error("Error during deployment:", error); |
| 65 | throw error; |
| 66 | } |
no test coverage detected