diff --git a/utils/env.config.ts b/config/env.config.ts similarity index 100% rename from utils/env.config.ts rename to config/env.config.ts diff --git a/config/fees.ts b/config/fees.ts index 04fa3f844..1e05f5582 100644 --- a/config/fees.ts +++ b/config/fees.ts @@ -1,5 +1,5 @@ +import {FeeTypes} from "../types"; import {Fees} from "./types"; -import {FeeTypes} from "../utils"; export const FEES: Fees = { [FeeTypes.Default]: { diff --git a/config/index.ts b/config/index.ts index a54111547..409d78ad0 100644 --- a/config/index.ts +++ b/config/index.ts @@ -74,4 +74,5 @@ export const CONFIG: Config = { }, }; +export * from "./env.config"; export * from "./fees"; diff --git a/config/types.ts b/config/types.ts index 8c8df7179..8821fa354 100644 --- a/config/types.ts +++ b/config/types.ts @@ -1,6 +1,6 @@ import {BigNumber} from "ethers"; +import {FeeTypes} from "types"; import {AddressObj} from "../utils"; -import {FeeTypes} from "../utils"; export type Config = { AP_TEAM_MULTISIG_DATA: { @@ -61,3 +61,15 @@ export type Fees = { bps: number; }; }; + +export type EnvConfig = { + ETHERSCAN_API_KEY: string; + GANACHE_PRIVATE_KEY: string; + GANACHE_RPC_URL: string; + GOERLI_RPC_URL: string; + MAINNET_RPC_URL: string; + MUMBAI_RPC_URL: string; + POLYGON_RPC_URL: string; + POLYSCAN_API_KEY: string; + ACCOUNTS: string[]; +}; diff --git a/contracts/accessory/gift-cards/scripts/deploy.ts b/contracts/accessory/gift-cards/scripts/deploy.ts index e24bea018..ae26a1947 100644 --- a/contracts/accessory/gift-cards/scripts/deploy.ts +++ b/contracts/accessory/gift-cards/scripts/deploy.ts @@ -1,7 +1,7 @@ import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {getContractName, getSigners, logger, updateAddresses, verify} from "utils"; +import {GiftCards__factory} from "typechain-types"; import {GiftCardsMessage} from "typechain-types/contracts/accessory/gift-cards/GiftCards"; -import {GiftCards__factory, ProxyContract__factory} from "typechain-types"; +import {deployBehindProxy, getSigners, updateAddresses, verify} from "utils"; export async function deployGiftCard( GiftCardsDataInput: GiftCardsMessage.InstantiateMsgStruct, @@ -12,43 +12,29 @@ export async function deployGiftCard( try { const {deployer} = await getSigners(hre); + // data setup const GiftCards = new GiftCards__factory(deployer); - const GiftCardsInstance = await GiftCards.deploy(); - await GiftCardsInstance.deployed(); - logger.out(`GiftCards implementation address: ${GiftCardsInstance.address}"`); + const initData = GiftCards.interface.encodeFunctionData("initialize", [GiftCardsDataInput]); + // deploy + const {implementation, proxy} = await deployBehindProxy(GiftCards, admin, initData); - const ProxyContract = new ProxyContract__factory(deployer); - const GiftCardsData = GiftCardsInstance.interface.encodeFunctionData("initialize", [ - GiftCardsDataInput, - ]); - const GiftCardsProxy = await ProxyContract.deploy( - GiftCardsInstance.address, - admin, - GiftCardsData - ); - await GiftCardsProxy.deployed(); - logger.out(`GiftCards Address (Proxy): ${GiftCardsProxy.address}"`); - - // update address file & verify contracts + // update address file await updateAddresses( { giftcards: { - proxy: GiftCardsProxy.address, - implementation: GiftCardsInstance.address, + proxy: proxy.contract.address, + implementation: implementation.contract.address, }, }, hre ); if (verify_contracts) { - await verify(hre, { - address: GiftCardsProxy.address, - constructorArguments: [GiftCardsInstance.address, admin, GiftCardsData], - contractName: getContractName(GiftCards), - }); + await verify(hre, implementation); + await verify(hre, proxy); } - return Promise.resolve(GiftCardsProxy.address); + return Promise.resolve(proxy.contract.address); } catch (error) { return Promise.reject(error); } diff --git a/contracts/core/accounts/scripts/deploy/cutDiamond.ts b/contracts/core/accounts/scripts/deploy/cutDiamond.ts index da36cb854..3e8b55519 100644 --- a/contracts/core/accounts/scripts/deploy/cutDiamond.ts +++ b/contracts/core/accounts/scripts/deploy/cutDiamond.ts @@ -23,15 +23,13 @@ export default async function cutDiamond( networkName, ]); - const cuts = facetCuts.map((x) => x.cut); - const tx = await diamondCut.diamondCut(cuts, diamondInit, calldata); - logger.out(`Cutting Diamond tx: ${tx.hash}`); - - const receipt = await hre.ethers.provider.waitForTransaction(tx.hash); - - if (!receipt.status) { - throw new Error(`Diamond cut failed: ${tx.hash}`); - } + const tx = await diamondCut.diamondCut( + facetCuts.map((x) => x.cut), + diamondInit, + calldata + ); + logger.out(`Tx hash: ${tx.hash}`); + await tx.wait(); logger.out("Completed Diamond cut."); } diff --git a/contracts/core/accounts/scripts/deploy/deploy.ts b/contracts/core/accounts/scripts/deploy/deploy.ts index c097818b6..0540acf2e 100644 --- a/contracts/core/accounts/scripts/deploy/deploy.ts +++ b/contracts/core/accounts/scripts/deploy/deploy.ts @@ -1,4 +1,5 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; +import {ContractFactory} from "ethers"; import {HardhatRuntimeEnvironment} from "hardhat/types"; import { DiamondCutFacet__factory, @@ -6,7 +7,8 @@ import { Diamond__factory, IERC173__factory, } from "typechain-types"; -import {Deployment, getContractName, logger, updateAddresses} from "utils"; +import {Deployment} from "types"; +import {deploy, logger, updateAddresses} from "utils"; import cutDiamond from "./cutDiamond"; import deployFacets from "./deployFacets"; @@ -17,8 +19,8 @@ export async function deployAccountsDiamond( deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment ): Promise<{ - diamond: Deployment; - facets: Array; + diamond: Deployment; + facets: Array>; }> { logger.out("Deploying and setting up Accounts Diamond and all its facets..."); @@ -28,17 +30,22 @@ export async function deployAccountsDiamond( const cuts = await deployFacets(deployer, hre); - await cutDiamond(diamond.address, diamondInit.address, deployer, owner, registrar, cuts, hre); + await cutDiamond( + diamond.contract.address, + diamondInit.contract.address, + deployer, + owner, + registrar, + cuts, + hre + ); - await setDiamondContractOwner(diamond.address, diamondAdmin, deployer); + await setDiamondContractOwner(diamond.contract.address, diamondAdmin, deployer); return { diamond, facets: cuts - .map(({cut, facetName}) => ({ - address: cut.facetAddress.toString(), - contractName: facetName, - })) + .map>((facetCut) => facetCut.deployment) .concat(diamondCutFacet, diamondInit), }; } @@ -46,36 +53,30 @@ export async function deployAccountsDiamond( async function deployDiamond( deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise<{diamond: Deployment; diamondCutFacet: Deployment}> { - const DiamondCutFacet = new DiamondCutFacet__factory(deployer); - const diamondCutFacet = await DiamondCutFacet.deploy(); - await diamondCutFacet.deployed(); - logger.out(`DiamondCutFacet deployed at: ${diamondCutFacet.address}`); +): Promise<{ + diamond: Deployment; + diamondCutFacet: Deployment; +}> { + const diamondCutFacet = await deploy(new DiamondCutFacet__factory(deployer)); - const constructorArguments: Parameters = [ + const diamond = await deploy(new Diamond__factory(deployer), [ deployer.address, - diamondCutFacet.address, - ]; - const Diamond = new Diamond__factory(deployer); - const diamond = await Diamond.deploy(...constructorArguments); - await diamond.deployed(); - logger.out(`Diamond deployed at: ${diamond.address}`); + diamondCutFacet.contract.address, + ]); await updateAddresses( - {accounts: {diamond: diamond.address, facets: {diamondCutFacet: diamondCutFacet.address}}}, + { + accounts: { + diamond: diamond.contract.address, + facets: {diamondCutFacet: diamondCutFacet.contract.address}, + }, + }, hre ); return { - diamond: { - address: diamond.address, - contractName: getContractName(Diamond), - constructorArguments, - }, - diamondCutFacet: { - address: diamondCutFacet.address, - contractName: getContractName(DiamondCutFacet), - }, + diamond, + diamondCutFacet, }; } @@ -87,18 +88,15 @@ async function deployDiamond( async function deployDiamondInit( admin: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise { - const DiamondInit = new DiamondInit__factory(admin); - const diamondInit = await DiamondInit.deploy(); - await diamondInit.deployed(); - logger.out(`DiamondInit deployed at: ${diamondInit.address}`); +): Promise> { + const diamondInit = await deploy(new DiamondInit__factory(admin)); - await updateAddresses({accounts: {facets: {diamondInitFacet: diamondInit.address}}}, hre); + await updateAddresses( + {accounts: {facets: {diamondInitFacet: diamondInit.contract.address}}}, + hre + ); - return { - address: diamondInit.address, - contractName: getContractName(DiamondInit), - }; + return diamondInit; } async function setDiamondContractOwner( diff --git a/contracts/core/accounts/scripts/deploy/deployFacets.ts b/contracts/core/accounts/scripts/deploy/deployFacets.ts index 329918881..737d43140 100644 --- a/contracts/core/accounts/scripts/deploy/deployFacets.ts +++ b/contracts/core/accounts/scripts/deploy/deployFacets.ts @@ -1,6 +1,6 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {getContractName, logger, updateAddresses} from "utils"; +import {deploy, logger, updateAddresses} from "utils"; import {FacetCutAction, getSelectors} from "../libraries/diamond"; import getFacetFactoryEntries from "./getFacetFactoryEntries"; import {FacetCut} from "./types"; @@ -16,24 +16,24 @@ export default async function deployFacets( const factoryEntries = getFacetFactoryEntries(diamondOwner); for (const entry of factoryEntries) { - const contractName = getContractName(entry.factory); try { - const facet = await entry.factory.deploy(); - await facet.deployed(); - logger.out(`${contractName} deployed at: ${facet.address}`); + const deployment = await deploy(entry.factory); - await updateAddresses({accounts: {facets: {[entry.addressField]: facet.address}}}, hre); + await updateAddresses( + {accounts: {facets: {[entry.addressField]: deployment.contract.address}}}, + hre + ); cuts.push({ - facetName: contractName, + deployment: deployment, cut: { - facetAddress: facet.address, + facetAddress: deployment.contract.address, action: FacetCutAction.Add, - functionSelectors: getSelectors(facet), + functionSelectors: getSelectors(deployment.contract), }, }); } catch (error) { - logger.out(`Failed to deploy ${contractName}, reason: ${error}`, logger.Level.Error); + logger.out(`Deployment failed, reason: ${error}`, logger.Level.Error); } } diff --git a/contracts/core/accounts/scripts/deploy/types.ts b/contracts/core/accounts/scripts/deploy/types.ts index c7b9cd5fb..16ebc7693 100644 --- a/contracts/core/accounts/scripts/deploy/types.ts +++ b/contracts/core/accounts/scripts/deploy/types.ts @@ -1,3 +1,8 @@ +import {ContractFactory} from "ethers"; import {IDiamondCut} from "typechain-types"; +import {Deployment} from "types"; -export type FacetCut = {facetName: string; cut: IDiamondCut.FacetCutStruct}; +export type FacetCut = { + deployment: Deployment; + cut: IDiamondCut.FacetCutStruct; +}; diff --git a/contracts/core/gasFwd/scripts/deploy.ts b/contracts/core/gasFwd/scripts/deploy.ts index 2c62d674a..79d51ccad 100644 --- a/contracts/core/gasFwd/scripts/deploy.ts +++ b/contracts/core/gasFwd/scripts/deploy.ts @@ -1,58 +1,49 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {HardhatRuntimeEnvironment} from "hardhat/types"; import {GasFwdFactory__factory, GasFwd__factory} from "typechain-types"; -import {Deployment, getAddresses, getContractName, logger, updateAddresses} from "utils"; +import {Deployment} from "types"; +import {deploy, logger, updateAddresses} from "utils"; type Data = { deployer: SignerWithAddress; proxyAdmin: string; factoryOwner: string; - registrar?: string; + registrar: string; }; export async function deployGasFwd( {deployer, proxyAdmin, factoryOwner, registrar}: Data, hre: HardhatRuntimeEnvironment -): Promise<{factory: Deployment; implementation: Deployment}> { - logger.out("Deploying Gas Forwarder..."); - - logger.out("Deploying GasFwd implementation..."); - const GF = new GasFwd__factory(deployer); - const gf = await GF.deploy(); - await gf.deployed(); - logger.out(`Address: ${gf.address}`); - - const addresses = await getAddresses(hre); - let registrarAddress = registrar ? registrar : addresses.registrar.proxy; - - logger.out("Deploying factory..."); - const GFF = new GasFwdFactory__factory(deployer); - const constructorArguments: Parameters = [ - gf.address, +): Promise<{ + factory: Deployment; + implementation: Deployment; +}> { + const implementation = await deploy(new GasFwd__factory(deployer)); + + const factory = await deploy(new GasFwdFactory__factory(deployer), [ + implementation.contract.address, proxyAdmin, - registrarAddress, - ]; - const gff = await GFF.deploy(...constructorArguments); - await gff.deployed(); - logger.out(`Address: ${gff.address}`); + registrar, + ]); logger.out(`Transferring ownership to: ${factoryOwner}...`); - const tx = await gff.transferOwnership(factoryOwner); + const tx = await factory.contract.transferOwnership(factoryOwner); logger.out(`Tx hash: ${tx.hash}`); await tx.wait(); + const newOwner = await factory.contract.owner(); + if (newOwner !== factoryOwner) { + throw new Error(`Error updating owner: expected '${factoryOwner}', actual: '${newOwner}'`); + } await updateAddresses( { gasFwd: { - implementation: gf.address, - factory: gff.address, + implementation: implementation.contract.address, + factory: factory.contract.address, }, }, hre ); - return { - implementation: {address: gf.address, contractName: getContractName(GF)}, - factory: {address: gff.address, contractName: getContractName(GFF), constructorArguments}, - }; + return {implementation, factory}; } diff --git a/contracts/core/index-fund/scripts/deploy.ts b/contracts/core/index-fund/scripts/deploy.ts index 866f831c3..3c2a6d435 100644 --- a/contracts/core/index-fund/scripts/deploy.ts +++ b/contracts/core/index-fund/scripts/deploy.ts @@ -1,8 +1,9 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {CONFIG} from "config"; import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {IndexFund__factory, ProxyContract__factory} from "typechain-types"; -import {Deployment, getContractName, logger, updateAddresses} from "utils"; +import {IndexFund__factory} from "typechain-types"; +import {ProxyDeployment} from "types"; +import {deployBehindProxy, logger, updateAddresses} from "utils"; export async function deployIndexFund( registrar: string, @@ -10,51 +11,38 @@ export async function deployIndexFund( proxyAdmin: string, deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise<{ - implementation: Deployment; - proxy: Deployment; -}> { - logger.out("Deploying IndexFund..."); - - // deploy implementation - logger.out("Deploying implementation..."); - const indexFundFactory = new IndexFund__factory(deployer); - const indexFund = await indexFundFactory.deploy(); - await indexFund.deployed(); - logger.out(`Address: ${indexFund.address}`); - - // deploy proxy - logger.out("Deploying proxy..."); - const initData = indexFund.interface.encodeFunctionData("initialize", [ +): Promise> { + // data setup + const IndexFund = new IndexFund__factory(deployer); + const initData = IndexFund.interface.encodeFunctionData("initialize", [ registrar, CONFIG.INDEX_FUND_DATA.fundRotation, CONFIG.INDEX_FUND_DATA.fundingGoal, ]); - const proxyFactory = new ProxyContract__factory(deployer); - const indexFundProxy = await proxyFactory.deploy(indexFund.address, proxyAdmin, initData); - await indexFundProxy.deployed(); - logger.out(`Address: ${indexFundProxy.address}`); + // deploy + const {implementation, proxy} = await deployBehindProxy(IndexFund, proxyAdmin, initData); // update owner logger.out(`Transferring ownership to: ${owner}...`); - const proxiedIndexFund = IndexFund__factory.connect(indexFundProxy.address, deployer); + const proxiedIndexFund = IndexFund__factory.connect(proxy.contract.address, deployer); const tx = await proxiedIndexFund.transferOwnership(owner); logger.out(`Tx hash: ${tx.hash}`); await tx.wait(); + const newOwner = await proxiedIndexFund.owner(); + if (newOwner !== owner) { + throw new Error(`Error updating owner: expected '${owner}', actual: '${newOwner}'`); + } - // update address file & verify contracts + // update address file await updateAddresses( { indexFund: { - proxy: indexFundProxy.address, - implementation: indexFund.address, + proxy: proxy.contract.address, + implementation: implementation.contract.address, }, }, hre ); - return { - implementation: {address: indexFund.address, contractName: getContractName(indexFundFactory)}, - proxy: {address: indexFundProxy.address, contractName: getContractName(proxyFactory)}, - }; + return {implementation, proxy}; } diff --git a/contracts/core/registrar/scripts/deploy.ts b/contracts/core/registrar/scripts/deploy.ts index f636c3183..914814bd9 100644 --- a/contracts/core/registrar/scripts/deploy.ts +++ b/contracts/core/registrar/scripts/deploy.ts @@ -1,7 +1,8 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {LocalRegistrar__factory, ProxyContract__factory, Registrar__factory} from "typechain-types"; -import {Deployment, getAxlNetworkName, getContractName, logger, updateAddresses} from "utils"; +import {LocalRegistrar__factory, Registrar__factory} from "typechain-types"; +import {ProxyDeployment} from "types"; +import {deployBehindProxy, getAxlNetworkName, logger, updateAddresses} from "utils"; type RegistrarDeployData = { axelarGateway: string; @@ -26,24 +27,12 @@ export async function deployRegistrar( apTeamMultisig, }: RegistrarDeployData, hre: HardhatRuntimeEnvironment -): Promise<{ - implementation: Deployment; - proxy: Deployment; -}> { - logger.out("Deploying Registrar..."); - +): Promise> { const networkName = await getAxlNetworkName(hre); - // deploy implementation - logger.out("Deploying implementation..."); - const factory = new Registrar__factory(deployer); - const registrar = await factory.deploy(); - await registrar.deployed(); - logger.out(`Address: ${registrar.address}`); - - // deploy proxy - logger.out("Deploying proxy..."); - const initData = registrar.interface.encodeFunctionData( + // data setup + const Registrar = new Registrar__factory(deployer); + const initData = Registrar.interface.encodeFunctionData( "initialize((address,address,address,address,address,string,address))", [ { @@ -57,32 +46,31 @@ export async function deployRegistrar( }, ] ); - const proxyFactory = new ProxyContract__factory(deployer); - const proxy = await proxyFactory.deploy(registrar.address, proxyAdmin, initData); - await proxy.deployed(); - logger.out(`Address: ${proxy.address}`); + // deploy + const {implementation, proxy} = await deployBehindProxy(Registrar, proxyAdmin, initData); // update owner logger.out(`Updating Registrar owner to '${owner}'..."`); - const proxiedRegistrar = Registrar__factory.connect(proxy.address, deployer); + const proxiedRegistrar = Registrar__factory.connect(proxy.contract.address, deployer); const tx = await proxiedRegistrar.transferOwnership(owner); await tx.wait(); + const newOwner = await proxiedRegistrar.owner(); + if (newOwner !== owner) { + throw new Error(`Error updating owner: expected '${owner}', actual: '${newOwner}'`); + } - // update address file & verify contracts + // update address file await updateAddresses( { registrar: { - implementation: registrar.address, - proxy: proxy.address, + implementation: implementation.contract.address, + proxy: proxy.contract.address, }, }, hre ); - return { - implementation: {address: registrar.address, contractName: getContractName(factory)}, - proxy: {address: proxy.address, contractName: getContractName(proxyFactory)}, - }; + return {implementation, proxy}; } type LocalRegistrarDeployData = { @@ -94,32 +82,18 @@ type LocalRegistrarDeployData = { export async function deployLocalRegistrar( {owner, deployer, proxyAdmin}: LocalRegistrarDeployData, hre: HardhatRuntimeEnvironment -): Promise<{ - implementation: Deployment; - proxy: Deployment; -}> { - logger.out("Deploying Local Registrar..."); - - // deploy implementation - logger.out("Deploying implementation..."); - const factory = new LocalRegistrar__factory(deployer); - const localRegistrar = await factory.deploy(); - await localRegistrar.deployed(); - logger.out(`Address: ${localRegistrar.address}`); - - // deploy proxy - logger.out("Deploying proxy..."); - const proxyFactory = new ProxyContract__factory(deployer); - const initData = localRegistrar.interface.encodeFunctionData("initialize", [ +): Promise> { + // data setup + const LocalRegistrar = new LocalRegistrar__factory(deployer); + const initData = LocalRegistrar.interface.encodeFunctionData("initialize", [ await getAxlNetworkName(hre), ]); - const proxy = await proxyFactory.deploy(localRegistrar.address, proxyAdmin, initData); - await proxy.deployed(); - logger.out(`Address: ${proxy.address}`); + // deploy + const {implementation, proxy} = await deployBehindProxy(LocalRegistrar, proxyAdmin, initData); // update owner - logger.out(`Updating Registrar owner to '${owner}...`); - const proxiedRegistrar = LocalRegistrar__factory.connect(proxy.address, deployer); + logger.out(`Updating Registrar owner to '${owner}'...`); + const proxiedRegistrar = LocalRegistrar__factory.connect(proxy.contract.address, deployer); const tx = await proxiedRegistrar.transferOwnership(owner); await tx.wait(); const newOwner = await proxiedRegistrar.owner(); @@ -127,19 +101,16 @@ export async function deployLocalRegistrar( throw new Error(`Error updating owner: expected '${owner}', actual: '${newOwner}'`); } - // update address file & verify contracts + // update address file await updateAddresses( { registrar: { - implementation: localRegistrar.address, - proxy: proxy.address, + implementation: implementation.contract.address, + proxy: proxy.contract.address, }, }, hre ); - return { - implementation: {address: localRegistrar.address, contractName: getContractName(factory)}, - proxy: {address: proxy.address, contractName: getContractName(proxyFactory)}, - }; + return {implementation, proxy}; } diff --git a/contracts/core/router/scripts/deploy.ts b/contracts/core/router/scripts/deploy.ts index e9aa96b4f..7a15580d2 100644 --- a/contracts/core/router/scripts/deploy.ts +++ b/contracts/core/router/scripts/deploy.ts @@ -1,43 +1,26 @@ -import {HardhatRuntimeEnvironment} from "hardhat/types"; import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; -import {ProxyContract__factory, Router__factory} from "typechain-types"; -import {Deployment, getContractName, logger, updateAddresses} from "utils"; +import {HardhatRuntimeEnvironment} from "hardhat/types"; +import {Router__factory} from "typechain-types"; +import {ProxyDeployment} from "types"; +import {deployBehindProxy, updateAddresses} from "utils"; export async function deployRouter( registrar: string, proxyAdmin: string, deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise<{ - implementation: Deployment; - proxy: Deployment; -}> { - logger.divider(); - logger.out("Deploying Router..."); - - // deploy implementation - logger.out("Deploying implementation..."); - const routerFactory = new Router__factory(deployer); - const router = await routerFactory.deploy(); - await router.deployed(); - logger.out(`Address: ${router.address}.`); - - // deploy proxy - logger.out("Deploying proxy..."); - const initData = router.interface.encodeFunctionData("initialize", [registrar]); - const routerProxyFactory = new ProxyContract__factory(deployer); - const routerProxy = await routerProxyFactory.deploy(router.address, proxyAdmin, initData); - await routerProxy.deployed(); - logger.out(`Address: ${routerProxy.address}.`); +): Promise> { + // data setup + const Router = new Router__factory(deployer); + const initData = Router.interface.encodeFunctionData("initialize", [registrar]); + // deploy + const {implementation, proxy} = await deployBehindProxy(Router, proxyAdmin, initData); - // update address file & verify contracts + // update address file await updateAddresses( - {router: {implementation: router.address, proxy: routerProxy.address}}, + {router: {implementation: implementation.contract.address, proxy: proxy.contract.address}}, hre ); - return { - implementation: {address: router.address, contractName: getContractName(routerFactory)}, - proxy: {address: routerProxy.address, contractName: getContractName(routerProxyFactory)}, - }; + return {implementation, proxy}; } diff --git a/contracts/core/vault/scripts/deployVaultEmitter.ts b/contracts/core/vault/scripts/deployVaultEmitter.ts index 52d61fb02..1b80394c3 100644 --- a/contracts/core/vault/scripts/deployVaultEmitter.ts +++ b/contracts/core/vault/scripts/deployVaultEmitter.ts @@ -1,52 +1,30 @@ -import {HardhatRuntimeEnvironment} from "hardhat/types"; import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; -import {ProxyContract__factory, VaultEmitter__factory} from "typechain-types"; -import {Deployment, getContractName, logger, updateAddresses} from "utils"; +import {HardhatRuntimeEnvironment} from "hardhat/types"; +import {VaultEmitter__factory} from "typechain-types"; +import {ProxyDeployment} from "types"; +import {deployBehindProxy, updateAddresses} from "utils"; export async function deployVaultEmitter( proxyAdmin: string, deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise<{ - implementation: Deployment; - proxy: Deployment; -}> { - logger.out("Deploying VaultEmitter..."); - - logger.out("Deploying implementation..."); +): Promise> { + // data setup const Emitter = new VaultEmitter__factory(deployer); - const emitter = await Emitter.deploy(); - logger.out(`Tx hash: ${emitter.deployTransaction.hash}`); - await emitter.deployed(); - logger.out(`Address: ${emitter.address}`); + const initData = Emitter.interface.encodeFunctionData("initialize"); + // deploy + const {implementation, proxy} = await deployBehindProxy(Emitter, proxyAdmin, initData); - logger.out("Deploying proxy..."); - const initData = emitter.interface.encodeFunctionData("initialize"); - const Proxy = new ProxyContract__factory(deployer); - const proxy = await Proxy.deploy(emitter.address, proxyAdmin, initData); - logger.out(`Tx hash: ${proxy.deployTransaction.hash}`); - await proxy.deployed(); - logger.out(`Address: ${proxy.address}`); - - // update address file & verify contracts + // update address file await updateAddresses( { vaultEmitter: { - implementation: emitter.address, - proxy: proxy.address, + implementation: implementation.contract.address, + proxy: proxy.contract.address, }, }, hre ); - return { - implementation: { - address: emitter.address, - contractName: getContractName(Emitter), - }, - proxy: { - address: proxy.address, - contractName: getContractName(Proxy), - }, - }; + return {implementation, proxy}; } diff --git a/contracts/halo/airdrop/scripts/deploy.ts b/contracts/halo/airdrop/scripts/deploy.ts index 983eb9bd3..01c1fc437 100644 --- a/contracts/halo/airdrop/scripts/deploy.ts +++ b/contracts/halo/airdrop/scripts/deploy.ts @@ -1,47 +1,37 @@ import {HardhatRuntimeEnvironment} from "hardhat/types"; +import {Airdrop__factory} from "typechain-types"; +import {AirdropMessage} from "typechain-types/contracts/halo/airdrop/Airdrop"; import { - getContractName, + deployBehindProxy, getProxyAdminOwner, + getSigners, isLocalNetwork, - logger, updateAddresses, verify, } from "utils"; -import {AirdropMessage} from "typechain-types/contracts/halo/airdrop/Airdrop"; - export async function deployAirdrop( AirdropDataInput: AirdropMessage.InstantiateMsgStruct, verify_contracts: boolean, hre: HardhatRuntimeEnvironment ) { try { - const {ethers, run, network} = hre; + const {deployer} = await getSigners(hre); const proxyAdmin = await getProxyAdminOwner(hre); - const Airdrop = await ethers.getContractFactory("Airdrop"); - const AirdropInstance = await Airdrop.deploy(); - await AirdropInstance.deployed(); - logger.out(`Airdrop implementation address: ${AirdropInstance.address}"`); - const ProxyContract = await ethers.getContractFactory("ProxyContract"); - const AirdropData = AirdropInstance.interface.encodeFunctionData("initialize", [ - AirdropDataInput, - ]); - const AirdropProxy = await ProxyContract.deploy( - AirdropInstance.address, - proxyAdmin.address, - AirdropData - ); - await AirdropProxy.deployed(); - logger.out(`Airdrop Address (Proxy): ${AirdropProxy.address}"`); + // data setup + const Airdrop = new Airdrop__factory(deployer); + const initData = Airdrop.interface.encodeFunctionData("initialize", [AirdropDataInput]); + // deploy + const {implementation, proxy} = await deployBehindProxy(Airdrop, proxyAdmin.address, initData); - // update address file & verify contracts + // update address file await updateAddresses( { halo: { airdrop: { - proxy: AirdropProxy.address, - implementation: AirdropInstance.address, + proxy: proxy.contract.address, + implementation: implementation.contract.address, }, }, }, @@ -49,14 +39,11 @@ export async function deployAirdrop( ); if (!isLocalNetwork(hre) && verify_contracts) { - await verify(hre, {contractName: getContractName(Airdrop), address: AirdropInstance.address}); - await verify(hre, { - contractName: getContractName(ProxyContract), - address: AirdropProxy.address, - }); + await verify(hre, implementation); + await verify(hre, proxy); } - return Promise.resolve(AirdropProxy.address); + return Promise.resolve(proxy.contract.address); } catch (error) { return Promise.reject(error); } diff --git a/contracts/halo/collector/scripts/deploy.ts b/contracts/halo/collector/scripts/deploy.ts index 643f9318f..970a9eaad 100644 --- a/contracts/halo/collector/scripts/deploy.ts +++ b/contracts/halo/collector/scripts/deploy.ts @@ -1,47 +1,41 @@ import {HardhatRuntimeEnvironment} from "hardhat/types"; +import {Collector__factory} from "typechain-types"; +import {CollectorMessage} from "typechain-types/contracts/halo/collector/Collector"; import { - getContractName, + deployBehindProxy, getProxyAdminOwner, + getSigners, isLocalNetwork, - logger, updateAddresses, verify, } from "utils"; -import {CollectorMessage} from "typechain-types/contracts/halo/collector/Collector"; - export async function deployCollector( CollectorDataInput: CollectorMessage.InstantiateMsgStruct, verify_contracts: boolean, hre: HardhatRuntimeEnvironment ) { try { - const {ethers, run, network} = hre; + const {deployer} = await getSigners(hre); const proxyAdmin = await getProxyAdminOwner(hre); - const Collector = await ethers.getContractFactory("Collector"); - const CollectorInstance = await Collector.deploy(); - await CollectorInstance.deployed(); - logger.out(`Collector implementation address: ${CollectorInstance.address}"`); - const ProxyContract = await ethers.getContractFactory("ProxyContract"); - const CollectorData = CollectorInstance.interface.encodeFunctionData("initialize", [ - CollectorDataInput, - ]); - const CollectorProxy = await ProxyContract.deploy( - CollectorInstance.address, + // data setup + const Collector = new Collector__factory(deployer); + const initData = Collector.interface.encodeFunctionData("initialize", [CollectorDataInput]); + // deploy + const {implementation, proxy} = await deployBehindProxy( + Collector, proxyAdmin.address, - CollectorData + initData ); - await CollectorProxy.deployed(); - logger.out(`Collector Address (Proxy): ${CollectorProxy.address}"`); - // update address file & verify contracts + // update address file await updateAddresses( { halo: { collector: { - proxy: CollectorProxy.address, - implementation: CollectorInstance.address, + proxy: proxy.contract.address, + implementation: implementation.contract.address, }, }, }, @@ -49,17 +43,11 @@ export async function deployCollector( ); if (!isLocalNetwork(hre) && verify_contracts) { - await verify(hre, { - contractName: getContractName(Collector), - address: CollectorInstance.address, - }); - await verify(hre, { - contractName: getContractName(ProxyContract), - address: CollectorProxy.address, - }); + await verify(hre, implementation); + await verify(hre, proxy); } - return Promise.resolve(CollectorProxy.address); + return Promise.resolve(proxy.contract.address); } catch (error) { return Promise.reject(error); } diff --git a/contracts/halo/community/scripts/deploy.ts b/contracts/halo/community/scripts/deploy.ts index c52dbd6f9..f6c0c9d39 100644 --- a/contracts/halo/community/scripts/deploy.ts +++ b/contracts/halo/community/scripts/deploy.ts @@ -1,13 +1,14 @@ import {HardhatRuntimeEnvironment} from "hardhat/types"; import { - getContractName, + deployBehindProxy, getProxyAdminOwner, + getSigners, isLocalNetwork, - logger, updateAddresses, verify, } from "utils"; +import {Community__factory} from "typechain-types"; import {CommunityMessage} from "typechain-types/contracts/halo/community/Community"; export async function deployCommunity( @@ -16,32 +17,26 @@ export async function deployCommunity( hre: HardhatRuntimeEnvironment ) { try { - const {ethers, run, network} = hre; + const {deployer} = await getSigners(hre); const proxyAdmin = await getProxyAdminOwner(hre); - const Community = await ethers.getContractFactory("Community"); - const CommunityInstance = await Community.deploy(); - await CommunityInstance.deployed(); - logger.out(`Community implementation address: ${CommunityInstance.address}"`); - const ProxyContract = await ethers.getContractFactory("ProxyContract"); - const CommunityData = CommunityInstance.interface.encodeFunctionData("initialize", [ - CommunityDataInput, - ]); - const CommunityProxy = await ProxyContract.deploy( - CommunityInstance.address, + // data setup + const Community = new Community__factory(deployer); + const initData = Community.interface.encodeFunctionData("initialize", [CommunityDataInput]); + // deploy + const {implementation, proxy} = await deployBehindProxy( + Community, proxyAdmin.address, - CommunityData + initData ); - await CommunityProxy.deployed(); - logger.out(`Community Address (Proxy): ${CommunityProxy.address}"`); - // update address file & verify contracts + // update address file await updateAddresses( { halo: { community: { - proxy: CommunityProxy.address, - implementation: CommunityInstance.address, + proxy: proxy.contract.address, + implementation: implementation.contract.address, }, }, }, @@ -49,17 +44,11 @@ export async function deployCommunity( ); if (!isLocalNetwork(hre) && verify_contracts) { - await verify(hre, { - contractName: getContractName(Community), - address: CommunityInstance.address, - }); - await verify(hre, { - contractName: getContractName(ProxyContract), - address: CommunityProxy.address, - }); + await verify(hre, implementation); + await verify(hre, proxy); } - return Promise.resolve(CommunityProxy.address); + return Promise.resolve(proxy.contract.address); } catch (error) { return Promise.reject(error); } diff --git a/contracts/halo/gov/scripts/deploy.ts b/contracts/halo/gov/scripts/deploy.ts index 161c93011..f1c1ac2be 100644 --- a/contracts/halo/gov/scripts/deploy.ts +++ b/contracts/halo/gov/scripts/deploy.ts @@ -1,9 +1,10 @@ import {HardhatRuntimeEnvironment} from "hardhat/types"; +import {Gov__factory} from "typechain-types"; import { - getContractName, + deployBehindProxy, getProxyAdminOwner, + getSigners, isLocalNetwork, - logger, updateAddresses, verify, } from "utils"; @@ -15,26 +16,22 @@ export async function deployGov( hre: HardhatRuntimeEnvironment ) { try { - const {ethers, run, network} = hre; + const {deployer} = await getSigners(hre); const proxyAdmin = await getProxyAdminOwner(hre); - const Gov = await ethers.getContractFactory("Gov"); - const GovInstance = await Gov.deploy(); - await GovInstance.deployed(); - logger.out(`Gov implementation address: ${GovInstance.address}"`); - const ProxyContract = await ethers.getContractFactory("ProxyContract"); - const GovData = GovInstance.interface.encodeFunctionData("initialize", [haloToken, timelock]); - const GovProxy = await ProxyContract.deploy(GovInstance.address, proxyAdmin.address, GovData); - await GovProxy.deployed(); - logger.out(`Gov Address (Proxy): ${GovProxy.address}"`); + // data setup + const Gov = new Gov__factory(deployer); + const initData = Gov.interface.encodeFunctionData("initialize", [haloToken, timelock]); + // deploy + const {implementation, proxy} = await deployBehindProxy(Gov, proxyAdmin.address, initData); - // update address file & verify contracts + // update address file await updateAddresses( { halo: { gov: { - proxy: GovProxy.address, - implementation: GovInstance.address, + proxy: proxy.contract.address, + implementation: implementation.contract.address, }, }, }, @@ -42,11 +39,11 @@ export async function deployGov( ); if (!isLocalNetwork(hre) && verify_contracts) { - await verify(hre, {contractName: getContractName(Gov), address: GovInstance.address}); - await verify(hre, {contractName: getContractName(ProxyContract), address: GovProxy.address}); + await verify(hre, implementation); + await verify(hre, proxy); } - return Promise.resolve(GovProxy.address); + return Promise.resolve(proxy.contract.address); } catch (error) { return Promise.reject(error); } diff --git a/contracts/halo/staking/scripts/deploy.ts b/contracts/halo/staking/scripts/deploy.ts index 1be67179d..f59b0fe67 100644 --- a/contracts/halo/staking/scripts/deploy.ts +++ b/contracts/halo/staking/scripts/deploy.ts @@ -1,47 +1,37 @@ import {HardhatRuntimeEnvironment} from "hardhat/types"; +import {Staking__factory} from "typechain-types"; +import {StakingMessages} from "typechain-types/contracts/halo/staking/Staking"; import { - getContractName, + deployBehindProxy, getProxyAdminOwner, + getSigners, isLocalNetwork, - logger, updateAddresses, verify, } from "utils"; -import {StakingMessages} from "typechain-types/contracts/halo/staking/Staking"; - export async function deployStaking( StakingDataInput: StakingMessages.InstantiateMsgStruct, verify_contracts: boolean, hre: HardhatRuntimeEnvironment ) { try { - const {ethers, run, network} = hre; + const {deployer} = await getSigners(hre); const proxyAdmin = await getProxyAdminOwner(hre); - const Staking = await ethers.getContractFactory("Staking"); - const StakingInstance = await Staking.deploy(); - await StakingInstance.deployed(); - logger.out(`Staking implementation address: ${StakingInstance.address}"`); - const ProxyContract = await ethers.getContractFactory("ProxyContract"); - const StakingData = StakingInstance.interface.encodeFunctionData("initialize", [ - StakingDataInput, - ]); - const StakingProxy = await ProxyContract.deploy( - StakingInstance.address, - proxyAdmin.address, - StakingData - ); - await StakingProxy.deployed(); - logger.out(`Staking Address (Proxy): ${StakingProxy.address}"`); + // data setup + const Staking = new Staking__factory(deployer); + const initData = Staking.interface.encodeFunctionData("initialize", [StakingDataInput]); + // deploy + const {implementation, proxy} = await deployBehindProxy(Staking, proxyAdmin.address, initData); - // update address file & verify contracts + // update address file await updateAddresses( { halo: { staking: { - proxy: StakingProxy.address, - implementation: StakingInstance.address, + proxy: proxy.contract.address, + implementation: implementation.contract.address, }, }, }, @@ -49,14 +39,11 @@ export async function deployStaking( ); if (!isLocalNetwork(hre) && verify_contracts) { - await verify(hre, {contractName: getContractName(Staking), address: StakingInstance.address}); - await verify(hre, { - contractName: getContractName(ProxyContract), - address: StakingProxy.address, - }); + await verify(hre, implementation); + await verify(hre, proxy); } - return Promise.resolve(StakingProxy.address); + return Promise.resolve(proxy.contract.address); } catch (error) { return Promise.reject(error); } diff --git a/contracts/halo/vesting/scripts/deploy.ts b/contracts/halo/vesting/scripts/deploy.ts index da2cc7efb..f972758da 100644 --- a/contracts/halo/vesting/scripts/deploy.ts +++ b/contracts/halo/vesting/scripts/deploy.ts @@ -1,47 +1,37 @@ import {HardhatRuntimeEnvironment} from "hardhat/types"; +import {Vesting__factory} from "typechain-types"; +import {VestingMessages} from "typechain-types/contracts/halo/vesting/Vesting"; import { - getContractName, + deployBehindProxy, getProxyAdminOwner, + getSigners, isLocalNetwork, - logger, updateAddresses, verify, } from "utils"; -import {VestingMessages} from "typechain-types/contracts/halo/vesting/Vesting"; - export async function deployVesting( VestingDataInput: VestingMessages.InstantiateMsgStruct, verify_contracts: boolean, hre: HardhatRuntimeEnvironment ) { try { - const {ethers, run, network} = hre; + const {deployer} = await getSigners(hre); const proxyAdmin = await getProxyAdminOwner(hre); - const Vesting = await ethers.getContractFactory("Vesting"); - const VestingInstance = await Vesting.deploy(); - await VestingInstance.deployed(); - logger.out(`Vesting implementation address: ${VestingInstance.address}"`); - const ProxyContract = await ethers.getContractFactory("ProxyContract"); - const VestingData = VestingInstance.interface.encodeFunctionData("initialize", [ - VestingDataInput, - ]); - const VestingProxy = await ProxyContract.deploy( - VestingInstance.address, - proxyAdmin.address, - VestingData - ); - await VestingProxy.deployed(); - logger.out(`Vesting Address (Proxy): ${VestingProxy.address}"`); + // data setup + const Vesting = new Vesting__factory(deployer); + const initData = Vesting.interface.encodeFunctionData("initialize", [VestingDataInput]); + // deploy + const {implementation, proxy} = await deployBehindProxy(Vesting, proxyAdmin.address, initData); - // update address file & verify contracts + // update address file await updateAddresses( { halo: { vesting: { - proxy: VestingProxy.address, - implementation: VestingInstance.address, + proxy: proxy.contract.address, + implementation: implementation.contract.address, }, }, }, @@ -49,14 +39,11 @@ export async function deployVesting( ); if (!isLocalNetwork(hre) && verify_contracts) { - await verify(hre, {contractName: getContractName(Vesting), address: VestingInstance.address}); - await verify(hre, { - contractName: getContractName(ProxyContract), - address: VestingProxy.address, - }); + await verify(hre, implementation); + await verify(hre, proxy); } - return Promise.resolve(VestingProxy.address); + return Promise.resolve(proxy.contract.address); } catch (error) { return Promise.reject(error); } diff --git a/contracts/integrations/stratConfig.ts b/contracts/integrations/stratConfig.ts index 227dfcbec..17cb4a535 100644 --- a/contracts/integrations/stratConfig.ts +++ b/contracts/integrations/stratConfig.ts @@ -1,10 +1,5 @@ -import { - AllStratConfigs, - StratConfig, - StrategyApprovalState, - VaultType, - getVaultAddress, -} from "utils"; +import {StrategyApprovalState, VaultType} from "types"; +import {AllStratConfigs, StratConfig, getVaultAddress} from "utils"; export const dummy: StratConfig = { name: "dummy", diff --git a/contracts/multisigs/endowment-multisig/scripts/deploy.ts b/contracts/multisigs/endowment-multisig/scripts/deploy.ts index be8f156f1..1fe98515e 100644 --- a/contracts/multisigs/endowment-multisig/scripts/deploy.ts +++ b/contracts/multisigs/endowment-multisig/scripts/deploy.ts @@ -1,12 +1,12 @@ -import {HardhatRuntimeEnvironment} from "hardhat/types"; import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; +import {HardhatRuntimeEnvironment} from "hardhat/types"; import { EndowmentMultiSigEmitter__factory, EndowmentMultiSigFactory__factory, EndowmentMultiSig__factory, - ProxyContract__factory, } from "typechain-types"; -import {Deployment, getContractName, logger, updateAddresses} from "utils"; +import {Deployment, ProxyDeployment} from "types"; +import {deploy, deployBehindProxy, logger, updateAddresses} from "utils"; export async function deployEndowmentMultiSig( registrar: string, @@ -15,68 +15,50 @@ export async function deployEndowmentMultiSig( deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment ): Promise<{ - emitter: { - implementation: Deployment; - proxy: Deployment; - }; - factory: Deployment; - implementation: Deployment; + emitter: ProxyDeployment; + factory: Deployment; + implementation: Deployment; }> { logger.out("Deploying EndowmentMultiSig contracts..."); // deploy implementation contract - logger.out("Deploying EndowmentMultiSig implementation..."); - const endowmentMultiSigFactory = new EndowmentMultiSig__factory(deployer); - const endowmentMultiSig = await endowmentMultiSigFactory.deploy(); - await endowmentMultiSig.deployed(); - logger.out(`Address: ${endowmentMultiSig.address}`); + const implementation = await deploy(new EndowmentMultiSig__factory(deployer)); // deploy factory - logger.out("Deploying EndowmentMultiSigFactory..."); - const factoryCtorArgs: Parameters = [ - endowmentMultiSig.address, + const factory = await deploy(new EndowmentMultiSigFactory__factory(deployer), [ + implementation.contract.address, proxyAdmin, registrar, - ]; - const EndowmentMultiSigFactoryFactory = new EndowmentMultiSigFactory__factory(deployer); - const EndowmentMultiSigFactory = await EndowmentMultiSigFactoryFactory.deploy(...factoryCtorArgs); - await EndowmentMultiSigFactory.deployed(); - logger.out(`Address: ${EndowmentMultiSigFactory.address}`); + ]); logger.out(`Transferring ownership to: ${factoryOwner}...`); - const tx = await EndowmentMultiSigFactory.transferOwnership(factoryOwner); + const tx = await factory.contract.transferOwnership(factoryOwner); logger.out(`Tx hash: ${tx.hash}`); await tx.wait(); + const newOwner = await factory.contract.owner(); + if (newOwner !== factoryOwner) { + throw new Error(`Error updating owner: expected '${factoryOwner}', actual: '${newOwner}'`); + } - // deploy emitter - logger.out("Deploying EndowmentMultiSigEmitter..."); - - logger.out("Deploying implementation..."); - const emitterFactory = new EndowmentMultiSigEmitter__factory(deployer); - const emitter = await emitterFactory.deploy(); - await emitter.deployed(); - logger.out(`Address: ${emitter.address}`); - - logger.out("Deploying proxy..."); - const initData = emitter.interface.encodeFunctionData("initEndowmentMultiSigEmitter", [ - EndowmentMultiSigFactory.address, + // emitter data setup + const Emitter = new EndowmentMultiSigEmitter__factory(deployer); + const initData = Emitter.interface.encodeFunctionData("initEndowmentMultiSigEmitter", [ + factory.contract.address, ]); - const proxyFactory = new ProxyContract__factory(deployer); - const emitterProxy = await proxyFactory.deploy(emitter.address, proxyAdmin, initData); - await emitterProxy.deployed(); - logger.out(`Address: ${emitterProxy.address}`); + // deploy emitter + const emitter = await deployBehindProxy(Emitter, proxyAdmin, initData); - // update address file & verify contracts + // update address file await updateAddresses( { multiSig: { endowment: { emitter: { - implementation: emitter.address, - proxy: emitterProxy.address, + implementation: emitter.implementation.contract.address, + proxy: emitter.proxy.contract.address, }, - factory: EndowmentMultiSigFactory.address, - implementation: endowmentMultiSig.address, + factory: factory.contract.address, + implementation: implementation.contract.address, }, }, }, @@ -84,24 +66,8 @@ export async function deployEndowmentMultiSig( ); return { - emitter: { - implementation: { - address: emitter.address, - contractName: getContractName(emitterFactory), - }, - proxy: { - address: emitterProxy.address, - contractName: getContractName(proxyFactory), - }, - }, - factory: { - address: EndowmentMultiSigFactory.address, - constructorArguments: factoryCtorArgs, - contractName: getContractName(EndowmentMultiSigFactoryFactory), - }, - implementation: { - address: endowmentMultiSig.address, - contractName: getContractName(endowmentMultiSigFactory), - }, + emitter, + factory, + implementation, }; } diff --git a/contracts/multisigs/scripts/deployAPTeamMultiSig.ts b/contracts/multisigs/scripts/deployAPTeamMultiSig.ts index 1db4eabd9..219d1253e 100644 --- a/contracts/multisigs/scripts/deployAPTeamMultiSig.ts +++ b/contracts/multisigs/scripts/deployAPTeamMultiSig.ts @@ -1,69 +1,43 @@ +import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {CONFIG} from "config"; import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; -import {APTeamMultiSig__factory, ProxyContract__factory} from "typechain-types"; -import {Deployment, getContractName, getSigners, logger, updateAddresses} from "utils"; +import {APTeamMultiSig__factory} from "typechain-types"; +import {ProxyDeployment} from "types"; +import {deployBehindProxy, getSigners, updateAddresses} from "utils"; export async function deployAPTeamMultiSig( proxyAdmin: string, deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise<{ - implementation: Deployment; - proxy: Deployment; -}> { - logger.out("Deploying APTeamMultiSig..."); - +): Promise> { const {apTeamMultisigOwners} = await getSigners(hre); const owners = apTeamMultisigOwners ? apTeamMultisigOwners.map((x) => x.address) : CONFIG.PROD_CONFIG.APTeamMultiSigOwners; - // deploy implementation - logger.out("Deploying implementation..."); - const apTeamMultiSigFactory = new APTeamMultiSig__factory(deployer); - const apTeamMultiSig = await apTeamMultiSigFactory.deploy(); - await apTeamMultiSig.deployed(); - logger.out(`Address: ${apTeamMultiSig.address}.`); - - // deploy proxy - logger.out("Deploying proxy..."); - const apTeamMultiSigData = apTeamMultiSig.interface.encodeFunctionData("initializeAPTeam", [ + // data setup + const APTeamMultiSig = new APTeamMultiSig__factory(deployer); + const data = APTeamMultiSig.interface.encodeFunctionData("initializeAPTeam", [ owners, CONFIG.AP_TEAM_MULTISIG_DATA.threshold, CONFIG.AP_TEAM_MULTISIG_DATA.requireExecution, CONFIG.AP_TEAM_MULTISIG_DATA.transactionExpiry, ]); - const proxyFactory = new ProxyContract__factory(deployer); - const apTeamMultiSigProxy = await proxyFactory.deploy( - apTeamMultiSig.address, - proxyAdmin, - apTeamMultiSigData - ); - await apTeamMultiSigProxy.deployed(); - logger.out(`Address: ${apTeamMultiSigProxy.address}.`); + // deploy + const {implementation, proxy} = await deployBehindProxy(APTeamMultiSig, proxyAdmin, data); - // update address file & verify contracts + // update address file await updateAddresses( { multiSig: { apTeam: { - implementation: apTeamMultiSig.address, - proxy: apTeamMultiSigProxy.address, + implementation: implementation.contract.address, + proxy: proxy.contract.address, }, }, }, hre ); - return { - implementation: { - address: apTeamMultiSig.address, - contractName: getContractName(apTeamMultiSigFactory), - }, - proxy: { - address: apTeamMultiSigProxy.address, - contractName: getContractName(proxyFactory), - }, - }; + return {implementation, proxy}; } diff --git a/contracts/multisigs/scripts/deployCharityApplications.ts b/contracts/multisigs/scripts/deployCharityApplications.ts index e0add4d0b..36ca10bda 100644 --- a/contracts/multisigs/scripts/deployCharityApplications.ts +++ b/contracts/multisigs/scripts/deployCharityApplications.ts @@ -1,8 +1,9 @@ -import {CONFIG} from "config"; import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; +import {CONFIG} from "config"; import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {CharityApplications__factory, ProxyContract__factory} from "typechain-types"; -import {Deployment, getContractName, getSigners, logger, updateAddresses} from "utils"; +import {CharityApplications__factory} from "typechain-types"; +import {ProxyDeployment} from "types"; +import {deployBehindProxy, getSigners, updateAddresses} from "utils"; export async function deployCharityApplications( accountsDiamond: string, @@ -10,27 +11,15 @@ export async function deployCharityApplications( seedAsset: string, deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise<{ - implementation: Deployment; - proxy: Deployment; -}> { - logger.out("Deploying CharityApplications..."); - +): Promise> { const {charityApplicationsOwners} = await getSigners(hre); const owners = !charityApplicationsOwners ? CONFIG.PROD_CONFIG.CharityApplicationsOwners : charityApplicationsOwners.map((x) => x.address); - // deploy implementation - logger.out("Deploying implementation..."); - const charityApplicationsFactory = new CharityApplications__factory(deployer); - const charityApplications = await charityApplicationsFactory.deploy(); - await charityApplications.deployed(); - logger.out(`Address: ${charityApplications.address}`); - - // deploy proxy - logger.out("Deploying proxy..."); - const initData = charityApplications.interface.encodeFunctionData("initializeApplications", [ + // data setup + const CharityApplications = new CharityApplications__factory(deployer); + const initData = CharityApplications.interface.encodeFunctionData("initializeApplications", [ owners, CONFIG.CHARITY_APPLICATIONS_DATA.threshold, CONFIG.CHARITY_APPLICATIONS_DATA.requireExecution, @@ -41,36 +30,25 @@ export async function deployCharityApplications( seedAsset, CONFIG.CHARITY_APPLICATIONS_DATA.seedAmount, ]); - const proxyFactory = new ProxyContract__factory(deployer); - const charityApplicationsProxy = await proxyFactory.deploy( - charityApplications.address, + // deploy + const {implementation, proxy} = await deployBehindProxy( + CharityApplications, proxyAdmin, initData ); - await charityApplicationsProxy.deployed(); - logger.out(`Address: ${charityApplicationsProxy.address}`); - // update address file & verify contracts + // update address file await updateAddresses( { multiSig: { charityApplications: { - implementation: charityApplications.address, - proxy: charityApplicationsProxy.address, + implementation: implementation.contract.address, + proxy: proxy.contract.address, }, }, }, hre ); - return { - implementation: { - address: charityApplications.address, - contractName: getContractName(charityApplicationsFactory), - }, - proxy: { - address: charityApplicationsProxy.address, - contractName: getContractName(proxyFactory), - }, - }; + return {implementation, proxy}; } diff --git a/contracts/multisigs/scripts/deployProxyAdminMultiSig.ts b/contracts/multisigs/scripts/deployProxyAdminMultiSig.ts index c8a32df97..0b157d693 100644 --- a/contracts/multisigs/scripts/deployProxyAdminMultiSig.ts +++ b/contracts/multisigs/scripts/deployProxyAdminMultiSig.ts @@ -2,34 +2,23 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {CONFIG} from "config"; import {HardhatRuntimeEnvironment} from "hardhat/types"; import {ProxyAdminMultiSig__factory} from "typechain-types"; -import {Deployment, getContractName, logger, updateAddresses} from "utils"; +import {Deployment} from "types"; +import {deploy, updateAddresses} from "utils"; export async function deployProxyAdminMultisig( owners: string[], deployer: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise { - logger.out("Deploying ProxyAdmin multisig..."); - - const constructorArguments: Parameters = [ +): Promise> { + const proxyAdmin = await deploy(new ProxyAdminMultiSig__factory(deployer), [ owners, CONFIG.PROXY_ADMIN_MULTISIG_DATA.threshold, CONFIG.PROXY_ADMIN_MULTISIG_DATA.requireExecution, CONFIG.PROXY_ADMIN_MULTISIG_DATA.transactionExpiry, - ]; - - const proxyAdminFactory = new ProxyAdminMultiSig__factory(deployer); - const proxyAdmin = await proxyAdminFactory.deploy(...constructorArguments); - logger.out(`Tx hash: ${proxyAdmin.deployTransaction.hash}`); - await proxyAdmin.deployed(); - logger.out(`Address: ${proxyAdmin.address}.`); + ]); - // update address file & verify contracts - await updateAddresses({multiSig: {proxyAdmin: proxyAdmin.address}}, hre); + // update address file + await updateAddresses({multiSig: {proxyAdmin: proxyAdmin.contract.address}}, hre); - return { - address: proxyAdmin.address, - contractName: getContractName(proxyAdminFactory), - constructorArguments: constructorArguments, - }; + return proxyAdmin; } diff --git a/hardhat.config.ts b/hardhat.config.ts index 3ed1a6fb3..955f01ed8 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -1,6 +1,6 @@ import {HardhatUserConfig} from "hardhat/config"; import {HardhatNetworkAccountsUserConfig} from "hardhat/types"; -import {envConfigDev, envConfigProd, getHardhatAccounts} from "./utils"; +import {envConfigDev, envConfigProd, getHardhatAccounts} from "./config"; import "@nomiclabs/hardhat-etherscan"; import "@nomicfoundation/hardhat-chai-matchers"; import "@openzeppelin/hardhat-upgrades"; diff --git a/tasks/deploy/deployAPTeamMultiSig.ts b/tasks/deploy/deployAPTeamMultiSig.ts index 931cd03d0..b3086d85f 100644 --- a/tasks/deploy/deployAPTeamMultiSig.ts +++ b/tasks/deploy/deployAPTeamMultiSig.ts @@ -34,17 +34,17 @@ task("deploy:APTeamMultiSig", "Will deploy APTeamMultiSig contract") } await hre.run("manage:registrar:transferOwnership", { - to: deployments.proxy.address, + to: deployments.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); await hre.run("manage:AccountsDiamond:updateOwner", { - to: deployments.proxy.address, + to: deployments.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); await hre.run("manage:IndexFund:transferOwnership", { - to: deployments.proxy.address, + to: deployments.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); diff --git a/tasks/deploy/deployAccountsDiamond.ts b/tasks/deploy/deployAccountsDiamond.ts index b1e863edd..e804b5e14 100644 --- a/tasks/deploy/deployAccountsDiamond.ts +++ b/tasks/deploy/deployAccountsDiamond.ts @@ -51,12 +51,12 @@ task("deploy:accounts", "It will deploy accounts diamond contracts") ); await hre.run("manage:registrar:updateConfig", { - accountsContract: diamond.address, + accountsContract: diamond.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); await hre.run("manage:CharityApplications:updateConfig", { - accountsDiamond: diamond.address, + accountsDiamond: diamond.contract.address, appsSignerPkey: taskArgs.appsSignerPkey, yes: true, }); diff --git a/tasks/deploy/deployAngelProtocol.ts b/tasks/deploy/deployAngelProtocol.ts index 4a08d804e..eb5809cb5 100644 --- a/tasks/deploy/deployAngelProtocol.ts +++ b/tasks/deploy/deployAngelProtocol.ts @@ -11,10 +11,11 @@ import { deployCharityApplications, deployProxyAdminMultisig, } from "contracts/multisigs/scripts/deploy"; +import {ContractFactory} from "ethers"; import {task} from "hardhat/config"; +import {Deployment} from "types"; import { ADDRESS_ZERO, - Deployment, confirmAction, getSigners, isLocalNetwork, @@ -68,33 +69,37 @@ task("deploy:AngelProtocol", "Will deploy complete Angel Protocol") const thirdPartyAddresses = await getOrDeployThirdPartyContracts(deployer, hre); - const apTeamMultisig = await deployAPTeamMultiSig(proxyAdminMultisig.address, deployer, hre); + const apTeamMultisig = await deployAPTeamMultiSig( + proxyAdminMultisig.contract.address, + deployer, + hre + ); const registrar = await deployRegistrar( { axelarGateway: thirdPartyAddresses.axelarGateway.address, axelarGasService: thirdPartyAddresses.axelarGasService.address, router: ADDRESS_ZERO, // will be updated once Router is deployed - owner: apTeamMultisig.proxy.address, + owner: apTeamMultisig.proxy.contract.address, deployer, - proxyAdmin: proxyAdminMultisig.address, + proxyAdmin: proxyAdminMultisig.contract.address, treasury: treasuryAddress, - apTeamMultisig: apTeamMultisig.proxy.address, + apTeamMultisig: apTeamMultisig.proxy.contract.address, }, hre ); const router = await deployRouter( - registrar.proxy.address, - proxyAdminMultisig.address, + registrar.proxy.contract.address, + proxyAdminMultisig.contract.address, deployer, hre ); const accounts = await deployAccountsDiamond( - apTeamMultisig.proxy.address, - registrar.proxy.address, - proxyAdminMultisig.address, + apTeamMultisig.proxy.contract.address, + registrar.proxy.contract.address, + proxyAdminMultisig.contract.address, deployer, hre ); @@ -102,9 +107,9 @@ task("deploy:AngelProtocol", "Will deploy complete Angel Protocol") const gasFwd = await deployGasFwd( { deployer: deployer, - proxyAdmin: proxyAdminMultisig.address, - factoryOwner: apTeamMultisig.proxy.address, - registrar: registrar.proxy.address, + proxyAdmin: proxyAdminMultisig.contract.address, + factoryOwner: apTeamMultisig.proxy.contract.address, + registrar: registrar.proxy.contract.address, }, hre ); @@ -112,49 +117,53 @@ task("deploy:AngelProtocol", "Will deploy complete Angel Protocol") // const emitters = await deployEmitters(accountsDiamond.address, hre); const charityApplications = await deployCharityApplications( - accounts.diamond.address, - proxyAdminMultisig.address, + accounts.diamond.contract.address, + proxyAdminMultisig.contract.address, thirdPartyAddresses.seedAsset.address, deployer, hre ); const indexFund = await deployIndexFund( - registrar.proxy.address, - apTeamMultisig.proxy.address, - proxyAdminMultisig.address, + registrar.proxy.contract.address, + apTeamMultisig.proxy.contract.address, + proxyAdminMultisig.contract.address, deployer, hre ); const endowmentMultiSig = await deployEndowmentMultiSig( - registrar.proxy.address, - proxyAdminMultisig.address, - apTeamMultisig.proxy.address, + registrar.proxy.contract.address, + proxyAdminMultisig.contract.address, + apTeamMultisig.proxy.contract.address, deployer, hre ); - const vaultEmitter = await deployVaultEmitter(proxyAdminMultisig.address, deployer, hre); + const vaultEmitter = await deployVaultEmitter( + proxyAdminMultisig.contract.address, + deployer, + hre + ); await hre.run("manage:registrar:updateConfig", { - accountsContract: accounts.diamond.address, //Address - indexFundContract: indexFund.proxy.address, //address + accountsContract: accounts.diamond.contract.address, //Address + indexFundContract: indexFund.proxy.contract.address, //address treasury: treasuryAddress, uniswapRouter: thirdPartyAddresses.uniswap.swapRouter.address, //address uniswapFactory: thirdPartyAddresses.uniswap.factory.address, //address - multisigFactory: endowmentMultiSig.factory.address, //address - multisigEmitter: endowmentMultiSig.emitter.proxy.address, //address - charityApplications: charityApplications.proxy.address, //address - proxyAdmin: proxyAdminMultisig.address, //address + multisigFactory: endowmentMultiSig.factory.contract.address, //address + multisigEmitter: endowmentMultiSig.emitter.proxy.contract.address, //address + charityApplications: charityApplications.proxy.contract.address, //address + proxyAdmin: proxyAdminMultisig.contract.address, //address usdcAddress: thirdPartyAddresses.usdcToken.address, wMaticAddress: thirdPartyAddresses.wmaticToken.address, - gasFwdFactory: gasFwd.factory.address, + gasFwdFactory: gasFwd.factory.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); await hre.run("manage:registrar:setVaultEmitterAddress", { - to: vaultEmitter.proxy.address, + to: vaultEmitter.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); @@ -164,7 +173,7 @@ task("deploy:AngelProtocol", "Will deploy complete Angel Protocol") }); if (verify_contracts) { - const deployments: Array = [ + const deployments: Array> = [ apTeamMultisig.implementation, apTeamMultisig.proxy, proxyAdminMultisig, diff --git a/tasks/deploy/deployCharityApplications.ts b/tasks/deploy/deployCharityApplications.ts index 06eec0c17..b3bde3890 100644 --- a/tasks/deploy/deployCharityApplications.ts +++ b/tasks/deploy/deployCharityApplications.ts @@ -42,7 +42,7 @@ task("deploy:CharityApplications", "Will deploy CharityApplication contract") ); await hre.run("manage:registrar:updateConfig", { - charityApplications: charityApplications.proxy.address, + charityApplications: charityApplications.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); diff --git a/tasks/deploy/deployEndowmentMultisig.ts b/tasks/deploy/deployEndowmentMultisig.ts index d7a238ae7..092ae848e 100644 --- a/tasks/deploy/deployEndowmentMultisig.ts +++ b/tasks/deploy/deployEndowmentMultisig.ts @@ -41,8 +41,8 @@ task("deploy:EndowmentMultiSig", "Will deploy EndowmentMultiSig contract") ); await hre.run("manage:registrar:updateConfig", { - multisigFactory: deployData.factory.address, - multisigEmitter: deployData.emitter.proxy.address, + multisigFactory: deployData.factory.contract.address, + multisigEmitter: deployData.emitter.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); diff --git a/tasks/deploy/deployGasFwd.ts b/tasks/deploy/deployGasFwd.ts index 9656d8180..c0441de7a 100644 --- a/tasks/deploy/deployGasFwd.ts +++ b/tasks/deploy/deployGasFwd.ts @@ -37,7 +37,7 @@ task("deploy:GasFwd", "Will deploy the GasFwd implementation and factory") ); await hre.run("manage:registrar:updateConfig", { - gasFwdFactory: gasFwdDeployment.factory.address, + gasFwdFactory: gasFwdDeployment.factory.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); diff --git a/tasks/deploy/deployHaloImplementation.ts b/tasks/deploy/deployHaloImplementation.ts index 577697c4f..2e36bc8a8 100644 --- a/tasks/deploy/deployHaloImplementation.ts +++ b/tasks/deploy/deployHaloImplementation.ts @@ -40,7 +40,7 @@ const deployHalo = async (verify_contracts: boolean, hre: HardhatRuntimeEnvironm await Halo.deployed(); if (verify_contracts) { - await verify(hre, {contractName: getContractName(factory), address: Halo.address}); + await verify(hre, {contractName: getContractName(factory), contract: Halo}); } console.log("Halo Address (ERC20):", Halo.address); diff --git a/tasks/deploy/deployIndexFund.ts b/tasks/deploy/deployIndexFund.ts index a411a1f11..da8e72b6e 100644 --- a/tasks/deploy/deployIndexFund.ts +++ b/tasks/deploy/deployIndexFund.ts @@ -47,7 +47,7 @@ task("deploy:IndexFund", "Will deploy IndexFund contract") ); await hre.run("manage:registrar:updateConfig", { - indexFundContract: deployment.proxy.address, + indexFundContract: deployment.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); diff --git a/tasks/deploy/deployLocalRegistrar.ts b/tasks/deploy/deployLocalRegistrar.ts index 59323e011..9c3eb816e 100644 --- a/tasks/deploy/deployLocalRegistrar.ts +++ b/tasks/deploy/deployLocalRegistrar.ts @@ -47,7 +47,7 @@ task("deploy:LocalRegistrarAndRouter", "Will deploy the Local Registrar contract } const router = await deployRouter( - localRegistrar.proxy.address, + localRegistrar.proxy.contract.address, addresses.multiSig.proxyAdmin, deployer, hre diff --git a/tasks/deploy/deployRegistrar.ts b/tasks/deploy/deployRegistrar.ts index efd063cfb..c6ee801db 100644 --- a/tasks/deploy/deployRegistrar.ts +++ b/tasks/deploy/deployRegistrar.ts @@ -92,17 +92,17 @@ task( // update all contracts' registrar addresses await hre.run("manage:accounts:updateConfig", { - registrarContract: registrar.proxy.address, + registrarContract: registrar.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); await hre.run("manage:IndexFund:updateConfig", { - registrarContract: registrar.proxy.address, + registrarContract: registrar.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); await hre.run("manage:GasFwdFactory:updateRegistrar", { - newRegistrar: registrar.proxy.address, + newRegistrar: registrar.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); diff --git a/tasks/deploy/deploySideChain.ts b/tasks/deploy/deploySideChain.ts index 393828cdf..3fc2d4c0b 100644 --- a/tasks/deploy/deploySideChain.ts +++ b/tasks/deploy/deploySideChain.ts @@ -1,9 +1,10 @@ import {CONFIG} from "config"; import {deployAPTeamMultiSig, deployProxyAdminMultisig} from "contracts/multisigs/scripts/deploy"; +import {ContractFactory} from "ethers"; import {task} from "hardhat/config"; import {getOrDeployThirdPartyContracts} from "tasks/helpers"; +import {Deployment} from "types"; import { - Deployment, confirmAction, getSigners, isLocalNetwork, @@ -51,17 +52,21 @@ task("deploy:SideChain", "Will deploy complete side-chain infrastructure") hre ); - const apTeamMultisig = await deployAPTeamMultiSig(proxyAdminMultisig.address, deployer, hre); + const apTeamMultisig = await deployAPTeamMultiSig( + proxyAdminMultisig.contract.address, + deployer, + hre + ); await hre.run("deploy:LocalRegistrarAndRouter", { - owner: apTeamMultisig.proxy.address, + owner: apTeamMultisig.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, skipVerify: taskArgs.skipVerify, yes: true, }); if (!isLocalNetwork(hre) && !taskArgs.skipVerify) { - const deployments: Array = [ + const deployments: Array> = [ proxyAdminMultisig, apTeamMultisig.implementation, apTeamMultisig.proxy, diff --git a/tasks/deploy/deployVaultEmitter.ts b/tasks/deploy/deployVaultEmitter.ts index cbba31f2c..4aeef2c57 100644 --- a/tasks/deploy/deployVaultEmitter.ts +++ b/tasks/deploy/deployVaultEmitter.ts @@ -28,7 +28,7 @@ task("deploy:VaultEmitter", "Will deploy VaultEmitter contract") const deployment = await deployVaultEmitter(addresses.multiSig.proxyAdmin, deployer, hre); await hre.run("manage:registrar:setVaultEmitterAddress", { - to: deployment.proxy.address, + to: deployment.proxy.contract.address, apTeamSignerPkey: taskArgs.apTeamSignerPkey, yes: true, }); diff --git a/tasks/deploy/integrations/dummyIntegration.ts b/tasks/deploy/integrations/dummyIntegration.ts index 1f9a6df38..92d7b4171 100644 --- a/tasks/deploy/integrations/dummyIntegration.ts +++ b/tasks/deploy/integrations/dummyIntegration.ts @@ -1,13 +1,13 @@ import {task} from "hardhat/config"; -import {APVault_V1__factory, GoerliDummy__factory, DummyERC20__factory} from "typechain-types"; +import {APVault_V1__factory, DummyERC20__factory, GoerliDummy__factory} from "typechain-types"; +import {VaultType} from "types"; import { - logger, - getSigners, - getAddresses, StratConfig, - writeStrategyAddresses, - VaultType, StrategyObject, + getAddresses, + getSigners, + logger, + writeStrategyAddresses, } from "utils"; import {allStrategyConfigs} from "../../../contracts/integrations/stratConfig"; diff --git a/tasks/deploy/integrations/genericVault.ts b/tasks/deploy/integrations/genericVault.ts index 281c16e06..912231608 100644 --- a/tasks/deploy/integrations/genericVault.ts +++ b/tasks/deploy/integrations/genericVault.ts @@ -1,6 +1,11 @@ import {task} from "hardhat/config"; -import {APVault_V1__factory, DummyERC20__factory, IVaultEmitter__factory} from "typechain-types"; -import {getAddresses, getContractName, getSigners, logger, verify} from "utils"; +import { + APVault_V1__factory, + DummyERC20__factory, + IVault, + IVaultEmitter__factory, +} from "typechain-types"; +import {deploy, getAddresses, getSigners, logger, verify} from "utils"; task("Deploy:genericVault", "Will deploy a generic vault with the provided params") .addOptionalParam("yieldtoken", "The address of the yield token") @@ -27,9 +32,9 @@ task("Deploy:genericVault", "Will deploy a generic vault with the provided param yieldTokenAddress = taskArgs.yieldtoken; } - let Vault = new APVault_V1__factory(deployer); - - let vaultConfig = { + // data setup + const APVault_V1 = new APVault_V1__factory(deployer); + const vaultConfig: IVault.VaultConfigStruct = { vaultType: 1, strategyId: "0x12345678", strategy: hre.ethers.constants.AddressZero, @@ -40,26 +45,16 @@ task("Deploy:genericVault", "Will deploy a generic vault with the provided param apTokenSymbol: "TV", admin: deployer.address, }; - const ctorArgs: Parameters<(typeof Vault)["deploy"]> = [ - vaultConfig, - addresses.vaultEmitter.proxy, - ]; - let vault = await Vault.deploy(...ctorArgs); - logger.out(`Tx hash: ${vault.deployTransaction.hash}`); - await vault.deployed(); - logger.pad(30, "Vault deployed to", vault.address); + // deploy + const deployment = await deploy(APVault_V1, [vaultConfig, addresses.vaultEmitter.proxy]); logger.out("Emitting `VaultCreated` event..."); const vaultEmitter = IVaultEmitter__factory.connect(addresses.vaultEmitter.proxy, deployer); - const tx = await vaultEmitter.vaultCreated(vault.address, vaultConfig); + const tx = await vaultEmitter.vaultCreated(deployment.contract.address, vaultConfig); logger.out(`Tx hash: ${tx.hash}`); await tx.wait(); - await verify(hre, { - address: vault.address, - contractName: getContractName(Vault), - constructorArguments: ctorArgs, - }); + await verify(hre, deployment); } catch (error) { logger.out(error, logger.Level.Error); } diff --git a/tasks/deploy/integrations/goldfinch.ts b/tasks/deploy/integrations/goldfinch.ts index 7643fbc13..044c2bed6 100644 --- a/tasks/deploy/integrations/goldfinch.ts +++ b/tasks/deploy/integrations/goldfinch.ts @@ -78,7 +78,7 @@ // logger.divider(); // logger.out("Writing to contract-address.json", logger.Level.Info); -// // update address file & verify contracts +// // update address file // await updateAddresses( // { // goldfinch: { diff --git a/tasks/manage/registrar/setFeeSetting.ts b/tasks/manage/registrar/setFeeSetting.ts index 16a18b49d..1b0f267fe 100644 --- a/tasks/manage/registrar/setFeeSetting.ts +++ b/tasks/manage/registrar/setFeeSetting.ts @@ -1,9 +1,9 @@ +import {FEES} from "config"; import {task, types} from "hardhat/config"; import {submitMultiSigTx} from "tasks/helpers"; import {Registrar__factory} from "typechain-types"; -import {FeeTypes, getAPTeamOwner, getAddresses, getEnumKeys, logger} from "utils"; -import {FEES} from "config"; -import {Fees} from "config/types"; +import {FeeTypes} from "types"; +import {getAPTeamOwner, getAddresses, getEnumKeys, logger} from "utils"; type TaskArgs = {feeType: number; payoutAddress?: string; bps?: number; apTeamSignerPkey?: string}; @@ -43,7 +43,7 @@ task("manage:registrar:setFeeSettings") const registrar = Registrar__factory.connect(registrarAddress, apTeamOwner); logger.pad(50, "Connected to Registrar at: ", registrar.address); - let configFee = FEES[taskArguments.feeType as keyof Fees]; + let configFee = FEES[taskArguments.feeType as FeeTypes]; const bps = !taskArguments.bps ? configFee.bps : taskArguments.bps; const payoutAddress = !taskArguments.payoutAddress ? configFee.payoutAddress diff --git a/tasks/manage/registrar/setStratApproval.ts b/tasks/manage/registrar/setStratApproval.ts index fbfb56d27..33d1f243e 100644 --- a/tasks/manage/registrar/setStratApproval.ts +++ b/tasks/manage/registrar/setStratApproval.ts @@ -1,15 +1,9 @@ +import {allStrategyConfigs} from "contracts/integrations/stratConfig"; import {task, types} from "hardhat/config"; import {submitMultiSigTx} from "tasks/helpers"; import {Registrar__factory} from "typechain-types"; -import { - StratConfig, - StrategyApprovalState, - getAPTeamOwner, - getAddresses, - getEnumKeys, - logger, -} from "utils"; -import {allStrategyConfigs} from "../../../contracts/integrations/stratConfig"; +import {StrategyApprovalState} from "types"; +import {StratConfig, getAPTeamOwner, getAddresses, getEnumKeys, logger} from "utils"; type TaskArgs = {name: string; approvalState: number; apTeamSignerPkey?: string}; diff --git a/tasks/manage/registrar/updateNetworkConnections.ts b/tasks/manage/registrar/updateNetworkConnections.ts index a655cc6d5..800eeb7bb 100644 --- a/tasks/manage/registrar/updateNetworkConnections.ts +++ b/tasks/manage/registrar/updateNetworkConnections.ts @@ -2,9 +2,9 @@ import {task, types} from "hardhat/config"; import {submitMultiSigTx} from "tasks/helpers"; import {Registrar__factory} from "typechain-types"; import {LocalRegistrarLib} from "typechain-types/contracts/core/registrar/LocalRegistrar"; +import {NetworkConnectionAction} from "types"; import { AddressObj, - NetworkConnectionAction, getAPTeamOwner, getAddresses, getAddressesByNetworkId, diff --git a/tasks/manage/verifyRegistrar.ts b/tasks/manage/verifyRegistrar.ts index b78cb72f9..b7af5d514 100644 --- a/tasks/manage/verifyRegistrar.ts +++ b/tasks/manage/verifyRegistrar.ts @@ -1,11 +1,18 @@ import {task} from "hardhat/config"; +import {Registrar__factory} from "typechain-types"; import {getAddresses, logger, verify} from "utils"; task("manage:verifyRegistrar", "Will verify the Registrar implementation contract").setAction( async (_, hre) => { try { const addresses = await getAddresses(hre); - await verify(hre, {address: addresses.registrar.implementation, contractName: "Registrar"}); + await verify(hre, { + contract: Registrar__factory.connect( + addresses.registrar.implementation, + hre.ethers.provider + ), + contractName: "Registrar", + }); } catch (error) { logger.out(error, logger.Level.Error); } diff --git a/tasks/upgrade/endowmentMultiSig/upgradeEmitter.ts b/tasks/upgrade/endowmentMultiSig/upgradeEmitter.ts index b2cea92f3..8db8137d6 100644 --- a/tasks/upgrade/endowmentMultiSig/upgradeEmitter.ts +++ b/tasks/upgrade/endowmentMultiSig/upgradeEmitter.ts @@ -6,8 +6,8 @@ import { } from "typechain-types"; import { confirmAction, + deploy, getAddresses, - getContractName, getProxyAdminOwner, getSigners, isLocalNetwork, @@ -45,18 +45,16 @@ task( const addresses = await getAddresses(hre); - logger.out("Deploying implementation..."); - const Emitter = new EndowmentMultiSigEmitter__factory(deployer); - const emitter = await Emitter.deploy(); - logger.out(`Tx hash: ${emitter.deployTransaction.hash}`); - await emitter.deployed(); - logger.out(`Address: ${emitter.address}`); + const deployment = await deploy(new EndowmentMultiSigEmitter__factory(deployer)); logger.out("Upgrading proxy..."); - const payload = ITransparentUpgradeableProxy__factory.createInterface().encodeFunctionData( - "upgradeTo", - [emitter.address] + const proxy = ITransparentUpgradeableProxy__factory.connect( + addresses.multiSig.proxyAdmin, + hre.ethers.provider ); + const payload = proxy.interface.encodeFunctionData("upgradeTo", [ + deployment.contract.address, + ]); const isExecuted = await submitMultiSigTx( addresses.multiSig.proxyAdmin, proxyAdminOwner, @@ -66,13 +64,19 @@ task( if (!isExecuted) { return; } + const newImplAddr = await proxy.implementation(); + if (newImplAddr !== deployment.contract.address) { + throw new Error( + `Unexpected: expected value "${deployment.contract.address}", but got "${newImplAddr}"` + ); + } await updateAddresses( { multiSig: { endowment: { emitter: { - implementation: emitter.address, + implementation: deployment.contract.address, }, }, }, @@ -81,7 +85,7 @@ task( ); if (!isLocalNetwork(hre) && !taskArgs.skipVerify) { - await verify(hre, {address: emitter.address, contractName: getContractName(Emitter)}); + await verify(hre, deployment); } } catch (error) { logger.out(`EndowmentMultiSigEmitter upgrade failed, reason: ${error}`, logger.Level.Error); diff --git a/tasks/upgrade/endowmentMultiSig/upgradeImplementation.ts b/tasks/upgrade/endowmentMultiSig/upgradeImplementation.ts index ce067ebc1..b383de960 100644 --- a/tasks/upgrade/endowmentMultiSig/upgradeImplementation.ts +++ b/tasks/upgrade/endowmentMultiSig/upgradeImplementation.ts @@ -3,9 +3,9 @@ import {submitMultiSigTx} from "tasks/helpers"; import {EndowmentMultiSig__factory, EndowmentMultiSigFactory__factory} from "typechain-types"; import { confirmAction, + deploy, getAddresses, getAPTeamOwner, - getContractName, getSigners, isLocalNetwork, logger, @@ -53,11 +53,7 @@ task( const EndowmentMultiSigFactoryAddress = taskArgs.factory || addresses.multiSig.endowment.factory; - logger.out("Deploying a new EndowmentMultiSig contract..."); - const factory = new EndowmentMultiSig__factory(deployer); - const contract = await factory.deploy(); - await contract.deployed(); - logger.out(`Address: ${contract.address}`); + const deployment = await deploy(new EndowmentMultiSig__factory(deployer)); logger.out("Upgrading EndowmentMultiSigFactory's implementation address..."); const endowmentMultiSigFactory = EndowmentMultiSigFactory__factory.connect( @@ -66,7 +62,7 @@ task( ); const payload = endowmentMultiSigFactory.interface.encodeFunctionData( "updateImplementation", - [contract.address] + [deployment.contract.address] ); const isExecuted = await submitMultiSigTx( addresses.multiSig.apTeam.proxy, @@ -77,18 +73,20 @@ task( if (!isExecuted) { return; } - const newImplAddr = await endowmentMultiSigFactory.implementationAddress(); - if (newImplAddr !== contract.address) { + if (newImplAddr !== deployment.contract.address) { throw new Error( - `Unexpected: expected EndowmentMultiSigFactory.implementationAddress value "${contract.address}", but got "${newImplAddr}"` + `Unexpected: expected EndowmentMultiSigFactory.implementationAddress value "${deployment.contract.address}", but got "${newImplAddr}"` ); } - await updateAddresses({multiSig: {endowment: {implementation: contract.address}}}, hre); + await updateAddresses( + {multiSig: {endowment: {implementation: deployment.contract.address}}}, + hre + ); if (!isLocalNetwork(hre) && !taskArgs.skipVerify) { - await verify(hre, {address: contract.address, contractName: getContractName(factory)}); + await verify(hre, deployment); } } catch (error) { logger.out(`EndowmentMultiSig upgrade failed, reason: ${error}`, logger.Level.Error); diff --git a/tasks/upgrade/upgradeAPTeamMultiSig.ts b/tasks/upgrade/upgradeAPTeamMultiSig.ts index 84938b7c5..5133eb0b0 100644 --- a/tasks/upgrade/upgradeAPTeamMultiSig.ts +++ b/tasks/upgrade/upgradeAPTeamMultiSig.ts @@ -3,8 +3,8 @@ import {submitMultiSigTx} from "tasks/helpers"; import {APTeamMultiSig__factory, ITransparentUpgradeableProxy__factory} from "typechain-types"; import { confirmAction, + deploy, getAddresses, - getContractName, getProxyAdminOwner, getSigners, isLocalNetwork, @@ -33,16 +33,12 @@ task("upgrade:APTeamMultiSig", "Will upgrade the APTeamMultiSig") const addresses = await getAddresses(hre); // Update APTeamMultiSig - logger.out("Deploying APTeamMultiSig..."); - const apTeamFactory = new APTeamMultiSig__factory(deployer); - const apTeamMultiSig = await apTeamFactory.deploy(); - await apTeamMultiSig.deployed(); - logger.out(`Address: ${apTeamMultiSig.address}`); + const deployment = await deploy(new APTeamMultiSig__factory(deployer)); logger.out("Upgrading APTeamMultiSig proxy implementation..."); const payload = ITransparentUpgradeableProxy__factory.createInterface().encodeFunctionData( "upgradeTo", - [apTeamMultiSig.address] + [deployment.contract.address] ); const isExecuted = await submitMultiSigTx( addresses.multiSig.proxyAdmin, @@ -58,7 +54,7 @@ task("upgrade:APTeamMultiSig", "Will upgrade the APTeamMultiSig") { multiSig: { apTeam: { - implementation: apTeamMultiSig.address, + implementation: deployment.contract.address, }, }, }, @@ -66,11 +62,7 @@ task("upgrade:APTeamMultiSig", "Will upgrade the APTeamMultiSig") ); if (!isLocalNetwork(hre) && !taskArgs.skipVerify) { - await verify(hre, { - address: apTeamMultiSig.address, - contract: "contracts/multisigs/APTeamMultiSig.sol:APTeamMultiSig", - contractName: getContractName(apTeamFactory), - }); + await verify(hre, deployment); } } catch (error) { logger.out(error, logger.Level.Error); diff --git a/tasks/upgrade/upgradeCharityApplications.ts b/tasks/upgrade/upgradeCharityApplications.ts index f94884fa9..3245d4ff0 100644 --- a/tasks/upgrade/upgradeCharityApplications.ts +++ b/tasks/upgrade/upgradeCharityApplications.ts @@ -3,8 +3,8 @@ import {submitMultiSigTx} from "tasks/helpers"; import {CharityApplications__factory, ITransparentUpgradeableProxy__factory} from "typechain-types"; import { confirmAction, + deploy, getAddresses, - getContractName, getProxyAdminOwner, getSigners, isLocalNetwork, @@ -40,17 +40,13 @@ task("upgrade:CharityApplications", "Will upgrade the implementation of CharityA const addresses = await getAddresses(hre); // deploy implementation - logger.out("Deploying CharityApplications..."); - const charityApplicationsFactory = new CharityApplications__factory(deployer); - const charityApplications = await charityApplicationsFactory.deploy(); - await charityApplications.deployed(); - logger.out(`Address: ${charityApplications.address}`); + const deployment = await deploy(new CharityApplications__factory(deployer)); // upgrade proxy logger.out("Upgrading proxy..."); const payload = ITransparentUpgradeableProxy__factory.createInterface().encodeFunctionData( "upgradeTo", - [charityApplications.address] + [deployment.contract.address] ); const isExecuted = await submitMultiSigTx( addresses.multiSig.proxyAdmin, @@ -67,7 +63,7 @@ task("upgrade:CharityApplications", "Will upgrade the implementation of CharityA { multiSig: { charityApplications: { - implementation: charityApplications.address, + implementation: deployment.contract.address, }, }, }, @@ -75,10 +71,7 @@ task("upgrade:CharityApplications", "Will upgrade the implementation of CharityA ); if (!taskArgs.skipVerify && !isLocalNetwork(hre)) { - await verify(hre, { - address: charityApplications.address, - contractName: getContractName(charityApplicationsFactory), - }); + await verify(hre, deployment); } } catch (error) { logger.out(error, logger.Level.Error); diff --git a/tasks/upgrade/upgradeFacets/createFacetCuts/index.ts b/tasks/upgrade/upgradeFacets/createFacetCuts/index.ts deleted file mode 100644 index fedd66420..000000000 --- a/tasks/upgrade/upgradeFacets/createFacetCuts/index.ts +++ /dev/null @@ -1 +0,0 @@ -export {default} from "./createFacetCuts"; diff --git a/tasks/upgrade/upgradeFacets/deployFacets.ts b/tasks/upgrade/upgradeFacets/deployFacets.ts index 99eacb5f0..3f24bdb9d 100644 --- a/tasks/upgrade/upgradeFacets/deployFacets.ts +++ b/tasks/upgrade/upgradeFacets/deployFacets.ts @@ -1,36 +1,37 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import getFacetFactoryEntries from "contracts/core/accounts/scripts/deploy/getFacetFactoryEntries"; +import {ContractFactory} from "ethers"; import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {getContractName, logger, updateAddresses} from "utils"; -import {Facet} from "./types"; +import {Deployment} from "types"; +import {deploy, getContractName, logger, updateAddresses} from "utils"; export default async function deployFacets( facetNames: string[], diamondOwner: SignerWithAddress, hre: HardhatRuntimeEnvironment -): Promise { +): Promise[]> { logger.out("Deploying facets..."); - const facets: Facet[] = []; + const facetDeployments: Deployment[] = []; const facetEntries = getFacetsToUpgrade(facetNames, diamondOwner); for (const entry of facetEntries) { - const facetName = getContractName(entry.factory); try { - const facet = await entry.factory.deploy(); - await facet.deployed(); - logger.out(`${facetName} deployed: ${facet.address}`); + const deployment = await deploy(entry.factory); - await updateAddresses({accounts: {facets: {[entry.addressField]: facet.address}}}, hre); + await updateAddresses( + {accounts: {facets: {[entry.addressField]: deployment.contract.address}}}, + hre + ); - facets.push({name: facetName, contract: facet}); + facetDeployments.push(deployment); } catch (error) { - logger.out(`Failed to deploy ${facetName}, reason: ${error}`, logger.Level.Error); + logger.out(`Deployment failed, reason: ${error}`, logger.Level.Error); } } - return facets; + return facetDeployments; } function getFacetsToUpgrade(facetNames: string[], diamondOwner: SignerWithAddress) { diff --git a/tasks/upgrade/upgradeFacets/createFacetCuts/getFacetSelectors.ts b/tasks/upgrade/upgradeFacets/sortIntoFacetCuts/getFacetSelectors.ts similarity index 94% rename from tasks/upgrade/upgradeFacets/createFacetCuts/getFacetSelectors.ts rename to tasks/upgrade/upgradeFacets/sortIntoFacetCuts/getFacetSelectors.ts index 880d7989f..52e0fab52 100644 --- a/tasks/upgrade/upgradeFacets/createFacetCuts/getFacetSelectors.ts +++ b/tasks/upgrade/upgradeFacets/sortIntoFacetCuts/getFacetSelectors.ts @@ -1,15 +1,13 @@ +import {getSelectors} from "contracts/core/accounts/scripts/libraries/diamond"; +import {Contract} from "ethers"; import {DiamondLoupeFacet} from "typechain-types"; import {ADDRESS_ZERO, logger} from "utils"; -import {getSelectors} from "contracts/core/accounts/scripts/libraries/diamond"; - -import {Facet} from "../types"; - export default async function getFacetSelectors( - facet: Facet, + facet: Contract, loupe: DiamondLoupeFacet ): Promise<{toAdd: string[]; toRemove: string[]; toReplace: string[]}> { - const allSelectors = getSelectors(facet.contract); + const allSelectors = getSelectors(facet); const toAdd: string[] = []; const toReplace: string[] = []; diff --git a/tasks/upgrade/upgradeFacets/sortIntoFacetCuts/index.ts b/tasks/upgrade/upgradeFacets/sortIntoFacetCuts/index.ts new file mode 100644 index 000000000..5d25ddb7b --- /dev/null +++ b/tasks/upgrade/upgradeFacets/sortIntoFacetCuts/index.ts @@ -0,0 +1 @@ +export {default} from "./sortIntoFacetCuts"; diff --git a/tasks/upgrade/upgradeFacets/createFacetCuts/createFacetCuts.ts b/tasks/upgrade/upgradeFacets/sortIntoFacetCuts/sortIntoFacetCuts.ts similarity index 67% rename from tasks/upgrade/upgradeFacets/createFacetCuts/createFacetCuts.ts rename to tasks/upgrade/upgradeFacets/sortIntoFacetCuts/sortIntoFacetCuts.ts index e52e68410..1285eb509 100644 --- a/tasks/upgrade/upgradeFacets/createFacetCuts/createFacetCuts.ts +++ b/tasks/upgrade/upgradeFacets/sortIntoFacetCuts/sortIntoFacetCuts.ts @@ -1,14 +1,14 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; +import {FacetCutAction} from "contracts/core/accounts/scripts/libraries/diamond"; +import {ContractFactory} from "ethers"; import {DiamondLoupeFacet__factory} from "typechain-types"; +import {Deployment} from "types"; import {ADDRESS_ZERO, logger} from "utils"; - -import {FacetCutAction} from "contracts/core/accounts/scripts/libraries/diamond"; - -import {Facet, FacetCut} from "../types"; +import {FacetCut} from "../types"; import getFacetSelectors from "./getFacetSelectors"; -export default async function createFacetCuts( - facets: Facet[], +export default async function sortIntoFacetCuts( + facetDeployments: Deployment[], diamondAddress: string, diamondOwner: SignerWithAddress ): Promise { @@ -18,16 +18,16 @@ export default async function createFacetCuts( const loupe = DiamondLoupeFacet__factory.connect(diamondAddress, diamondOwner); - for (let i = 0; i < facets.length; i++) { - const facet = facets[i]; + for (let i = 0; i < facetDeployments.length; i++) { + const facetDeployment = facetDeployments[i]; - const {toAdd, toRemove, toReplace} = await getFacetSelectors(facet, loupe); + const {toAdd, toRemove, toReplace} = await getFacetSelectors(facetDeployment.contract, loupe); if (toAdd.length > 0) { facetCuts.push({ - facetName: facet.name, + deployment: facetDeployment, cut: { - facetAddress: facet.contract.address, + facetAddress: facetDeployment.contract.address, action: FacetCutAction.Add, functionSelectors: toAdd, }, @@ -35,9 +35,9 @@ export default async function createFacetCuts( } if (toReplace.length > 0) { facetCuts.push({ - facetName: facet.name, + deployment: facetDeployment, cut: { - facetAddress: facet.contract.address, + facetAddress: facetDeployment.contract.address, action: FacetCutAction.Replace, functionSelectors: toReplace, }, @@ -45,7 +45,7 @@ export default async function createFacetCuts( } if (toRemove.length > 0) { facetCuts.push({ - facetName: facet.name, + deployment: facetDeployment, cut: { facetAddress: ADDRESS_ZERO, action: FacetCutAction.Remove, diff --git a/tasks/upgrade/upgradeFacets/types.ts b/tasks/upgrade/upgradeFacets/types.ts index eb6bcc0d0..3a25e8756 100644 --- a/tasks/upgrade/upgradeFacets/types.ts +++ b/tasks/upgrade/upgradeFacets/types.ts @@ -1,6 +1,5 @@ -import {Contract} from "ethers"; +import {ContractFactory} from "ethers"; import {IDiamondCut} from "typechain-types"; +import {Deployment} from "types"; -export type Facet = {name: string; contract: Contract}; - -export type FacetCut = {facetName: string; cut: IDiamondCut.FacetCutStruct}; +export type FacetCut = {deployment: Deployment; cut: IDiamondCut.FacetCutStruct}; diff --git a/tasks/upgrade/upgradeFacets/upgradeFacets.ts b/tasks/upgrade/upgradeFacets/upgradeFacets.ts index 388268c21..c8b698bfe 100644 --- a/tasks/upgrade/upgradeFacets/upgradeFacets.ts +++ b/tasks/upgrade/upgradeFacets/upgradeFacets.ts @@ -10,9 +10,9 @@ import { verify, } from "utils"; import {ALL_FACET_NAMES} from "./constants"; -import createFacetCuts from "./createFacetCuts"; import cutDiamond from "./cutDiamond"; import deployFacets from "./deployFacets"; +import sortIntoFacetCuts from "./sortIntoFacetCuts"; type TaskArgs = { accountsDiamond?: string; @@ -59,16 +59,16 @@ task("upgrade:facets", "Will redeploy and upgrade all facets that use AccountSto const accountsDiamond = taskArgs.accountsDiamond || addresses.accounts.diamond; - const facets = await deployFacets(facetsToUpgrade, deployer, hre); + const facetDeployments = await deployFacets(facetsToUpgrade, deployer, hre); - const facetCuts = await createFacetCuts(facets, accountsDiamond, deployer); + const facetCuts = await sortIntoFacetCuts(facetDeployments, accountsDiamond, deployer); await cutDiamond(accountsDiamond, addresses.multiSig.proxyAdmin, proxyAdminOwner, facetCuts); if (!isLocalNetwork(hre) && !taskArgs.skipVerify) { const facetsToVerify = facetCuts.filter((cut) => cut.cut.action !== FacetCutAction.Remove); - for (const {facetName, cut} of facetsToVerify) { - await verify(hre, {address: cut.facetAddress.toString(), contractName: facetName}); + for (const {deployment} of facetsToVerify) { + await verify(hre, deployment); } } } catch (error) { diff --git a/tasks/upgrade/upgradeRegistrar.ts b/tasks/upgrade/upgradeRegistrar.ts index 49fbfb19a..2d19ffec5 100644 --- a/tasks/upgrade/upgradeRegistrar.ts +++ b/tasks/upgrade/upgradeRegistrar.ts @@ -3,8 +3,8 @@ import {submitMultiSigTx} from "tasks/helpers"; import {ITransparentUpgradeableProxy__factory, Registrar__factory} from "typechain-types"; import { confirmAction, + deploy, getAddresses, - getContractName, getProxyAdminOwner, getSigners, isLocalNetwork, @@ -31,16 +31,13 @@ task("upgrade:registrar", "Will upgrade the Registrar (use only on the primary c const addresses = await getAddresses(hre); - logger.out("Deploying a new Registrar implementation..."); - const Registrar = new Registrar__factory(deployer); - const registrar = await Registrar.deploy(); - await registrar.deployed(); - logger.out(`New impl address: ${registrar.address}`); + // deploy implementation + const deployment = await deploy(new Registrar__factory(deployer)); logger.out("Upgrading Registrar proxy implementation..."); const payload = ITransparentUpgradeableProxy__factory.createInterface().encodeFunctionData( "upgradeTo", - [registrar.address] + [deployment.contract.address] ); const isExecuted = await submitMultiSigTx( addresses.multiSig.proxyAdmin, @@ -55,18 +52,14 @@ task("upgrade:registrar", "Will upgrade the Registrar (use only on the primary c await updateAddresses( { registrar: { - implementation: registrar.address, + implementation: deployment.contract.address, }, }, hre ); if (!isLocalNetwork(hre) && !taskArgs.skipVerify) { - await verify(hre, { - address: registrar.address, - contract: "contracts/core/registrar/Registrar.sol:Registrar", - contractName: getContractName(Registrar), - }); + await verify(hre, deployment); } } catch (error) { logger.out(error, logger.Level.Error); diff --git a/tasks/upgrade/upgradeRouter.ts b/tasks/upgrade/upgradeRouter.ts index b7d732ec9..cea6c62d4 100644 --- a/tasks/upgrade/upgradeRouter.ts +++ b/tasks/upgrade/upgradeRouter.ts @@ -3,8 +3,8 @@ import {submitMultiSigTx} from "tasks/helpers"; import {ITransparentUpgradeableProxy__factory, Router__factory} from "typechain-types"; import { confirmAction, + deploy, getAddresses, - getContractName, getProxyAdminOwner, getSigners, isLocalNetwork, @@ -31,16 +31,13 @@ task("upgrade:router", "Will upgrade the Router") const addresses = await getAddresses(hre); - logger.out("Deploying a new Router implementation..."); - const Router = new Router__factory(deployer); - const router = await Router.deploy(); - await router.deployed(); - logger.out(`New impl address: ${router.address}`); + // deploy implementation + const deployment = await deploy(new Router__factory(deployer)); logger.out("Upgrading Router proxy implementation..."); const payload = ITransparentUpgradeableProxy__factory.createInterface().encodeFunctionData( "upgradeTo", - [router.address] + [deployment.contract.address] ); const isExecuted = await submitMultiSigTx( addresses.multiSig.proxyAdmin, @@ -55,18 +52,14 @@ task("upgrade:router", "Will upgrade the Router") await updateAddresses( { registrar: { - implementation: router.address, + implementation: deployment.contract.address, }, }, hre ); if (!isLocalNetwork(hre) && !taskArgs.skipVerify) { - await verify(hre, { - address: router.address, - contract: "contracts/core/router/Router.sol:Router", - contractName: getContractName(Router), - }); + await verify(hre, deployment); } } catch (error) { logger.out(error, logger.Level.Error); diff --git a/test/core/accounts/AccountsCreateEndowment.ts b/test/core/accounts/AccountsCreateEndowment.ts index dc7ffac2f..e24c00dc2 100644 --- a/test/core/accounts/AccountsCreateEndowment.ts +++ b/test/core/accounts/AccountsCreateEndowment.ts @@ -16,9 +16,8 @@ import { TestFacetProxyContract, } from "typechain-types"; import {AccountMessages} from "typechain-types/contracts/core/accounts/facets/AccountsCreateEndowment"; -import {LocalRegistrarLib} from "typechain-types/contracts/core/registrar/LocalRegistrar"; import {RegistrarStorage} from "typechain-types/contracts/core/registrar/Registrar"; -import {FeeTypes, genWallet, getProxyAdminOwner, getSigners} from "utils"; +import {genWallet, getProxyAdminOwner, getSigners} from "utils"; import {deployFacetAsProxy} from "./utils"; use(smock.matchers); diff --git a/test/core/accounts/AccountsDepositWithdrawEndowments.ts b/test/core/accounts/AccountsDepositWithdrawEndowments.ts index 6fdc0f247..1e88cad74 100644 --- a/test/core/accounts/AccountsDepositWithdrawEndowments.ts +++ b/test/core/accounts/AccountsDepositWithdrawEndowments.ts @@ -1,6 +1,6 @@ import {FakeContract, smock} from "@defi-wonderland/smock"; -import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {impersonateAccount, setBalance, time} from "@nomicfoundation/hardhat-network-helpers"; +import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {expect, use} from "chai"; import {BigNumber} from "ethers"; import hre from "hardhat"; @@ -8,11 +8,11 @@ import {DEFAULT_CHARITY_ENDOWMENT, DEFAULT_REGISTRAR_CONFIG, wait} from "test/ut import { AccountsDepositWithdrawEndowments, AccountsDepositWithdrawEndowments__factory, - IERC20, - IERC20__factory, DummyWMATIC, DummyWMATIC__factory, IAccountsDepositWithdrawEndowments, + IERC20, + IERC20__factory, Registrar, Registrar__factory, TestFacetProxyContract, @@ -20,7 +20,8 @@ import { import {AccountMessages} from "typechain-types/contracts/core/accounts/facets/AccountsDepositWithdrawEndowments"; import {RegistrarStorage} from "typechain-types/contracts/core/registrar/Registrar"; import {AccountStorage} from "typechain-types/contracts/test/accounts/TestFacetProxyContract"; -import {VaultType, genWallet, getProxyAdminOwner, getSigners} from "utils"; +import {VaultType} from "types"; +import {genWallet, getProxyAdminOwner, getSigners} from "utils"; import {deployFacetAsProxy} from "./utils"; use(smock.matchers); diff --git a/test/core/accounts/AccountsGasManager.ts b/test/core/accounts/AccountsGasManager.ts index 31b2446a8..747b2a36b 100644 --- a/test/core/accounts/AccountsGasManager.ts +++ b/test/core/accounts/AccountsGasManager.ts @@ -12,13 +12,14 @@ import { import { AccountsGasManager, AccountsGasManager__factory, - IERC20, - IERC20__factory, GasFwd, GasFwd__factory, + IERC20, + IERC20__factory, TestFacetProxyContract, } from "typechain-types"; -import {VaultType, getProxyAdminOwner, getSigners} from "utils"; +import {VaultType} from "types"; +import {getProxyAdminOwner, getSigners} from "utils"; import {deployFacetAsProxy} from "./utils"; use(smock.matchers); diff --git a/test/core/accounts/AccountsStrategy.ts b/test/core/accounts/AccountsStrategy.ts index a1f0c0512..f2139da01 100644 --- a/test/core/accounts/AccountsStrategy.ts +++ b/test/core/accounts/AccountsStrategy.ts @@ -42,14 +42,8 @@ import { } from "typechain-types/contracts/core/accounts/facets/AccountsStrategy"; import {LocalRegistrarLib} from "typechain-types/contracts/core/registrar/LocalRegistrar"; import {AccountStorage} from "typechain-types/contracts/test/accounts/TestFacetProxyContract"; -import { - StrategyApprovalState, - VaultActionStatus, - genWallet, - getChainId, - getProxyAdminOwner, - getSigners, -} from "utils"; +import {StrategyApprovalState, VaultActionStatus} from "types"; +import {genWallet, getChainId, getProxyAdminOwner, getSigners} from "utils"; import {deployFacetAsProxy} from "./utils"; use(smock.matchers); diff --git a/test/core/accounts/AccountsSwapRouter.ts b/test/core/accounts/AccountsSwapRouter.ts index a79a3fc56..8a3f83f25 100644 --- a/test/core/accounts/AccountsSwapRouter.ts +++ b/test/core/accounts/AccountsSwapRouter.ts @@ -1,4 +1,5 @@ import {FakeContract, smock} from "@defi-wonderland/smock"; +import {time} from "@nomicfoundation/hardhat-network-helpers"; import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {expect, use} from "chai"; import hre from "hardhat"; @@ -24,9 +25,9 @@ import { Registrar__factory, TestFacetProxyContract, } from "typechain-types"; -import {VaultType, genWallet, getProxyAdminOwner, getSigners} from "utils"; +import {VaultType} from "types"; +import {genWallet, getProxyAdminOwner, getSigners} from "utils"; import {deployFacetAsProxy} from "./utils"; -import {time} from "@nomicfoundation/hardhat-network-helpers"; use(smock.matchers); diff --git a/test/core/accounts/AccountsUpdate.ts b/test/core/accounts/AccountsUpdate.ts index bdadcdb58..884ee8c72 100644 --- a/test/core/accounts/AccountsUpdate.ts +++ b/test/core/accounts/AccountsUpdate.ts @@ -1,11 +1,12 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {expect} from "chai"; import hre from "hardhat"; +import {DEFAULT_CHARITY_ENDOWMENT, wait} from "test/utils"; import {AccountsUpdate, AccountsUpdate__factory, TestFacetProxyContract} from "typechain-types"; -import {getProxyAdminOwner, getSigners, EndowmentType} from "utils"; -import {deployFacetAsProxy} from "./utils"; -import {wait, DEFAULT_CHARITY_ENDOWMENT} from "test/utils"; import {AccountStorage} from "typechain-types/contracts/test/accounts/TestFacetProxyContract"; +import {EndowmentType} from "types"; +import {getProxyAdminOwner, getSigners} from "utils"; +import {deployFacetAsProxy} from "./utils"; describe("AccountsUpdate", function () { const {ethers} = hre; diff --git a/test/core/accounts/AccountsUpdateEndowments.ts b/test/core/accounts/AccountsUpdateEndowments.ts index 62a0fabf3..369519b9b 100644 --- a/test/core/accounts/AccountsUpdateEndowments.ts +++ b/test/core/accounts/AccountsUpdateEndowments.ts @@ -17,7 +17,8 @@ import { AccountStorage, LibAccounts, } from "typechain-types/contracts/test/accounts/TestFacetProxyContract"; -import {ControllerSettingOption, genWallet, getProxyAdminOwner, getSigners} from "utils"; +import {ControllerSettingOption} from "types"; +import {genWallet, getProxyAdminOwner, getSigners} from "utils"; import {deployFacetAsProxy, updateAllSettings, updateSettings} from "./utils"; use(smock.matchers); diff --git a/test/core/accounts/AccountsUpdateStatusEndowments.ts b/test/core/accounts/AccountsUpdateStatusEndowments.ts index 294fe5c35..15e4d915f 100644 --- a/test/core/accounts/AccountsUpdateStatusEndowments.ts +++ b/test/core/accounts/AccountsUpdateStatusEndowments.ts @@ -20,7 +20,8 @@ import { import {LibAccounts} from "typechain-types/contracts/core/accounts/facets/AccountsUpdateStatusEndowments"; import {RegistrarStorage} from "typechain-types/contracts/core/registrar/Registrar"; import {AccountStorage} from "typechain-types/contracts/test/accounts/TestFacetProxyContract"; -import {BeneficiaryEnum, EndowmentType, genWallet, getProxyAdminOwner, getSigners} from "utils"; +import {BeneficiaryEnum, EndowmentType} from "types"; +import {genWallet, getProxyAdminOwner, getSigners} from "utils"; import {deployFacetAsProxy} from "./utils"; use(smock.matchers); diff --git a/test/core/accounts/utils/updateSettings.ts b/test/core/accounts/utils/updateSettings.ts index 5c6049805..73df4453c 100644 --- a/test/core/accounts/utils/updateSettings.ts +++ b/test/core/accounts/utils/updateSettings.ts @@ -1,11 +1,11 @@ import {BigNumberish} from "ethers"; +import {wait} from "test/utils"; import { AccountStorage, LibAccounts, TestFacetProxyContract, } from "typechain-types/contracts/test/accounts/TestFacetProxyContract"; -import {DeepPartial} from "utils/types"; -import {wait} from "test/utils"; +import {DeepPartial} from "types"; /** * Updates endowment's setting's permissions field in a way that has no side-effects diff --git a/test/core/registrar/LocalRegistrar.ts b/test/core/registrar/LocalRegistrar.ts index f0f258e25..5ab8ad7fc 100644 --- a/test/core/registrar/LocalRegistrar.ts +++ b/test/core/registrar/LocalRegistrar.ts @@ -2,11 +2,11 @@ import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; import {expect} from "chai"; import {BigNumber} from "ethers"; import hre from "hardhat"; -import {FeeTypes, StrategyApprovalState, getSigners} from "utils"; - import {DEFAULT_NETWORK_INFO} from "test/utils"; import {LocalRegistrar, LocalRegistrar__factory} from "typechain-types"; import {LocalRegistrarLib} from "typechain-types/contracts/core/registrar/LocalRegistrar"; +import {FeeTypes, StrategyApprovalState} from "types"; +import {getSigners} from "utils"; describe("Local Registrar", function () { const {ethers, upgrades} = hre; diff --git a/test/core/router/Router.ts b/test/core/router/Router.ts index 2d96e3d84..ce6852f0c 100644 --- a/test/core/router/Router.ts +++ b/test/core/router/Router.ts @@ -24,7 +24,8 @@ import { Router__factory, } from "typechain-types"; import {LocalRegistrarLib} from "typechain-types/contracts/core/registrar/LocalRegistrar"; -import {StrategyApprovalState, VaultActionStatus, getProxyAdminOwner, getSigners} from "utils"; +import {StrategyApprovalState, VaultActionStatus} from "types"; +import {getProxyAdminOwner, getSigners} from "utils"; use(smock.matchers); diff --git a/test/core/vault/Vault.ts b/test/core/vault/Vault.ts index 16ac9210a..a86ce8d3f 100644 --- a/test/core/vault/Vault.ts +++ b/test/core/vault/Vault.ts @@ -26,7 +26,8 @@ import { LocalRegistrar__factory, } from "typechain-types"; import {LocalRegistrarLib} from "typechain-types/contracts/core/registrar/LocalRegistrar"; -import {StrategyApprovalState, getProxyAdminOwner, getSigners} from "utils"; +import {StrategyApprovalState} from "types"; +import {getProxyAdminOwner, getSigners} from "utils"; use(smock.matchers); diff --git a/tsconfig.json b/tsconfig.json index ca069883c..21618704a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,8 @@ "./utils", "./tasks/*", "./test", + "./types", "./typechain-types" ], - "files": ["./hardhat.config.ts"] + "files": ["./hardhat.config.ts", "./types/index.ts"] } diff --git a/utils/types/chai.d.ts b/types/chai.d.ts similarity index 100% rename from utils/types/chai.d.ts rename to types/chai.d.ts diff --git a/types/common.ts b/types/common.ts new file mode 100644 index 000000000..b6629ae89 --- /dev/null +++ b/types/common.ts @@ -0,0 +1,17 @@ +import {ContractFactory} from "ethers"; +import {ProxyContract__factory} from "typechain-types"; + +export type DeepPartial = { + [K in keyof T]?: T[K] extends object ? DeepPartial : T[K]; +}; + +export type Deployment = { + constructorArguments?: Parameters; + contract: Awaited>; + contractName: string; +}; + +export type ProxyDeployment = { + implementation: Deployment; + proxy: Deployment; +}; diff --git a/utils/types/enums.ts b/types/enums.ts similarity index 100% rename from utils/types/enums.ts rename to types/enums.ts diff --git a/utils/types/index.ts b/types/index.ts similarity index 68% rename from utils/types/index.ts rename to types/index.ts index 3c413d248..b5c59a32f 100644 --- a/utils/types/index.ts +++ b/types/index.ts @@ -1,3 +1,2 @@ export * from "./common"; export * from "./enums"; -export * from "./env"; diff --git a/utils/deploy.ts b/utils/deploy.ts new file mode 100644 index 000000000..3b4a33846 --- /dev/null +++ b/utils/deploy.ts @@ -0,0 +1,64 @@ +import {BytesLike, ContractFactory} from "ethers"; +import {ProxyContract__factory} from "typechain-types"; +import {Deployment, ProxyDeployment} from "types"; +import {getContractName, logger} from "."; + +/** + * Deploys a contract; includes logging of the relevant data + * + * Note: Deployment tx hash is logged only if the deployment fails. + * Otherwise the tx hash can be obtained by using the contract address to search the relevant Tx explorer. + * + * @param factory contract factory used to deploy the contract + * @param constructorArguments contract's constructor arguments + * @returns (Deployment) object containing deployment data (including the contract instance) + */ +export async function deploy( + factory: T, + constructorArguments?: Parameters +): Promise> { + const contractName = getContractName(factory); + logger.out(`Deploying ${contractName}...`); + + try { + const contract = await factory.deploy(...(constructorArguments ?? [])); + await contract.deployed(); + logger.out(`Address: ${contract.address}`); + return { + constructorArguments, + contractName, + contract: contract as Awaited>, + }; + } catch (error: any) { + if ("data" in error && "txHash" in error.data) { + logger.out(`Tx hash: ${error.data.txHash}`); + } + throw error; + } +} + +/** + * Deploys a contract behind a proxy; includes logging of the relevant data. + * + * Note: Deployment tx hash is logged only if the deployment fails. + * Otherwise the tx hash can be obtained by using the contract address to search the relevant Tx explorer. + * + * @param factory contract factory used to deploy the contract + * @param proxyAdmin proxy admin address + * @param initData data used to initialize the contract + * @returns object containing both implementation and proxy deployment data (including the contract instances) + */ +export async function deployBehindProxy( + factory: T, + proxyAdmin: string, + initData: BytesLike +): Promise> { + const implementation = await deploy(factory); + const proxy = await deploy(new ProxyContract__factory(factory.signer), [ + implementation.contract.address, + proxyAdmin, + initData, + ]); + + return {implementation, proxy}; +} diff --git a/utils/index.ts b/utils/index.ts index e86b5a1e9..bafd48a0d 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -1,6 +1,6 @@ export * from "./confirmAction"; export * from "./constants"; -export * from "./env.config"; +export * from "./deploy"; export * from "./getContractName"; export * from "./getEnumKeys"; export * from "./getKeysTyped"; @@ -12,6 +12,5 @@ export * from "./manageAddressFile"; export * from "./manageStratParams"; export * from "./networkHelpers"; export * from "./structToObject"; -export * from "./types"; export * from "./validation"; export * from "./verify"; diff --git a/utils/manageAddressFile/manageAddressFile.ts b/utils/manageAddressFile/manageAddressFile.ts index 2156af69b..8a1266d54 100644 --- a/utils/manageAddressFile/manageAddressFile.ts +++ b/utils/manageAddressFile/manageAddressFile.ts @@ -1,5 +1,5 @@ import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {DeepPartial} from "../types"; +import {DeepPartial} from "types"; import {DEFAULT_CONTRACT_ADDRESS_FILE_PATH, getChainId, isLocalNetwork} from ".."; import {createEmptyAddressObj, getAddressesByNetworkId, saveFrontendFiles} from "./helpers"; import {AddressObj} from "./types"; diff --git a/utils/manageStratParams/manageStratParams.ts b/utils/manageStratParams/manageStratParams.ts index db707292f..77e56758b 100644 --- a/utils/manageStratParams/manageStratParams.ts +++ b/utils/manageStratParams/manageStratParams.ts @@ -1,8 +1,8 @@ import fs from "fs"; - -import {StrategyObject} from "./types"; +import {VaultType} from "types"; +import {DEFAULT_STRATEGY_ADDRESSES_FILE_PATH} from ".."; import {readStrategyAddresses} from "./helpers"; -import {DEFAULT_STRATEGY_ADDRESSES_FILE_PATH, VaultType} from ".."; +import {StrategyObject} from "./types"; export function getVaultAddress(name: string, type: VaultType): string { let typeName: string; diff --git a/utils/types/common.ts b/utils/types/common.ts deleted file mode 100644 index efe33472a..000000000 --- a/utils/types/common.ts +++ /dev/null @@ -1,10 +0,0 @@ -export type DeepPartial = { - [K in keyof T]?: T[K] extends object ? DeepPartial : T[K]; -}; - -export type Deployment = { - address: string; - contractName: string; - constructorArguments?: readonly any[]; - contract?: string; -}; diff --git a/utils/types/env.ts b/utils/types/env.ts deleted file mode 100644 index fe82c2b82..000000000 --- a/utils/types/env.ts +++ /dev/null @@ -1,11 +0,0 @@ -export type EnvConfig = { - ETHERSCAN_API_KEY: string; - GANACHE_PRIVATE_KEY: string; - GANACHE_RPC_URL: string; - GOERLI_RPC_URL: string; - MAINNET_RPC_URL: string; - MUMBAI_RPC_URL: string; - POLYGON_RPC_URL: string; - POLYSCAN_API_KEY: string; - ACCOUNTS: string[]; -}; diff --git a/utils/verify.ts b/utils/verify.ts index bdce83a09..a33cef231 100644 --- a/utils/verify.ts +++ b/utils/verify.ts @@ -1,14 +1,23 @@ +import {ContractFactory} from "ethers"; import {HardhatRuntimeEnvironment} from "hardhat/types"; -import {Deployment, logger} from "."; +import {Deployment} from "types"; +import {logger} from "."; -export async function verify(hre: HardhatRuntimeEnvironment, deployment: Deployment) { +export async function verify( + hre: HardhatRuntimeEnvironment, + {contract: {address}, contractName, constructorArguments}: Deployment +) { try { - logger.out(`Verifying ${deployment.contractName} at: ${deployment.address}...`); + logger.out(`Verifying ${contractName} at: ${address}...`); const tenderlyVerif = hre.tenderly.verify({ - name: deployment.contractName, - address: deployment.address, + address: address, + name: contractName, + }); + const etherscanVerif = hre.run("verify:verify", { + address, + constructorArguments, + contractName, }); - const etherscanVerif = hre.run("verify:verify", deployment); await Promise.allSettled([tenderlyVerif, etherscanVerif]); } catch (error) { logger.out(error, logger.Level.Warn);