UNPKG

@dydxfoundation/governance

Version:
33 lines (32 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.upgradeContract = exports.deployUpgradeable = void 0; const utils_1 = require("ethers/lib/utils"); const types_1 = require("../../../types"); const util_1 = require("../../lib/util"); async function deployUpgradeable(factory, deployer, constructorArgs, initializeArgs) { const proxyAdmin = await new types_1.ProxyAdmin__factory(deployer).deploy(); const proxy = await new types_1.InitializableAdminUpgradeabilityProxy__factory(deployer).deploy(); const implementation = await new factory(deployer).deploy(...constructorArgs); await Promise.all([ (0, util_1.waitForTx)(proxyAdmin.deployTransaction), (0, util_1.waitForTx)(proxy.deployTransaction), (0, util_1.waitForTx)(implementation.deployTransaction), ]); const initializeCalldata = new utils_1.Interface(factory.abi).encodeFunctionData('initialize', initializeArgs); await (0, util_1.waitForTx)(await proxy['initialize(address,address,bytes)'](implementation.address, proxyAdmin.address, initializeCalldata)); const proxyInstance = new factory(deployer).attach(proxy.address); return [ proxyInstance, implementation, proxyAdmin, ]; } exports.deployUpgradeable = deployUpgradeable; async function upgradeContract(factory, deployer, proxyAddress, proxyAdmin, constructorArgs) { const newImplementation = await new factory(deployer).deploy(...constructorArgs); await (0, util_1.waitForTx)(newImplementation.deployTransaction); await (0, util_1.waitForTx)(await proxyAdmin.upgrade(proxyAddress, newImplementation.address)); return newImplementation; } exports.upgradeContract = upgradeContract;