| 2 | import { ethers, upgrades } from 'hardhat' |
| 3 | |
| 4 | export async function deployUpgradeableContract<T extends Contract>( |
| 5 | contractName: string, |
| 6 | proxyAddress?: string, |
| 7 | initializeArgs: any[] = [], |
| 8 | ): Promise<T> { |
| 9 | const ContractFactory = await ethers.getContractFactory(contractName) |
| 10 | |
| 11 | let proxy: T |
| 12 | if (proxyAddress) { |
| 13 | proxy = (await upgrades.upgradeProxy(proxyAddress, ContractFactory, { timeout: 1000 * 60 * 60 })) as T |
| 14 | } else { |
| 15 | proxy = (await upgrades.deployProxy(ContractFactory, initializeArgs, { timeout: 1000 * 60 * 60 })) as T |
| 16 | } |
| 17 | |
| 18 | await proxy.deployed() |
| 19 | console.log(`${contractName} deployed to:`, proxy.address) |
| 20 | |
| 21 | return proxy |
| 22 | } |