From cfeedfc803178aedf6fe318258cda7bd14521173 Mon Sep 17 00:00:00 2001 From: Giorgi Lagidze Date: Mon, 27 Jan 2025 11:50:20 +0400 Subject: [PATCH] better approach --- packages/contracts/deploy/00_info/01_info.ts | 21 +++--- .../deploy/10_create_repo/11_create_repo.ts | 73 ++++++++----------- .../deploy/20_new_version/23_publish.ts | 31 +++----- .../deploy/30_upgrade_repo/_common.ts | 13 ++-- packages/contracts/deploy/helpers.ts | 16 ++++ packages/contracts/utils/helpers.ts | 33 ++++++--- 6 files changed, 98 insertions(+), 89 deletions(-) diff --git a/packages/contracts/deploy/00_info/01_info.ts b/packages/contracts/deploy/00_info/01_info.ts index d6f6acaa..73743d46 100644 --- a/packages/contracts/deploy/00_info/01_info.ts +++ b/packages/contracts/deploy/00_info/01_info.ts @@ -4,6 +4,7 @@ import { getProductionNetworkName, isLocal, } from '../../utils/helpers'; +import {forkNetwork} from '../helpers'; import {getNetworkByNameOrAlias} from '@aragon/osx-commons-configs'; import {UnsupportedNetworkError} from '@aragon/osx-commons-sdk'; import {DeployFunction} from 'hardhat-deploy/types'; @@ -20,7 +21,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { console.log(`\n✨ ${path.basename(__filename)}:`); const [deployer] = await hre.ethers.getSigners(); - if (isLocal(hre)) { + + if (process.env.FORKING_RPC_URL) { + await forkNetwork(hre, process.env.FORKING_RPC_URL); + } else if (isLocal(hre)) { const productionNetworkName: string = getProductionNetworkName(hre); console.log( @@ -32,16 +36,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { if (networkConfig === null) { throw new UnsupportedNetworkError(productionNetworkName); } - await hre.network.provider.request({ - method: 'hardhat_reset', - params: [ - { - forking: { - jsonRpcUrl: networkConfig.url, - }, - }, - ], - }); + if (!networkConfig.url) { + throw new Error('RPC Url on network not defined'); + } + + await forkNetwork(hre, networkConfig.url); } else { console.log(`Production deployment on network '${hre.network.name}'.`); } diff --git a/packages/contracts/deploy/10_create_repo/11_create_repo.ts b/packages/contracts/deploy/10_create_repo/11_create_repo.ts index b0c17e83..70334814 100644 --- a/packages/contracts/deploy/10_create_repo/11_create_repo.ts +++ b/packages/contracts/deploy/10_create_repo/11_create_repo.ts @@ -37,16 +37,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const [deployer] = await hre.ethers.getSigners(); - // Get the Aragon `PluginRepoFactory` from the `osx-commons-configs` - let pluginRepoFactoryAddress; + let pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS; let subdomainRegistrar; - if ( - process.env.PLUGIN_REPO_FACTORY_ADDRESS && - process.env.PLUGIN_REPO_FACTORY_ADDRESS !== ethers.constants.AddressZero - ) { - // use this factory - pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS; + if (pluginRepoFactoryAddress) { + // use this factory const pluginRepoFactory = PluginRepoFactory__factory.connect( pluginRepoFactoryAddress, deployer @@ -77,7 +72,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { const subdomain = subdomainRegistrar !== ethers.constants.AddressZero ? PLUGIN_REPO_ENS_SUBDOMAIN_NAME - : 'empty'; // todo set to empty when is possible + : ''; const pluginRepoFactory = PluginRepoFactory__factory.connect( pluginRepoFactoryAddress, @@ -104,7 +99,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { ); console.log( - `PluginRepo '${pluginEnsDomain(hre)}' deployed at '${pluginRepo.address}'.` + `PluginRepo ${ + subdomainRegistrar !== ethers.constants.AddressZero + } ? '${pluginEnsDomain(hre)}' : ${''} deployed at '${pluginRepo.address}'.` ); hre.aragonToVerifyContracts.push({ @@ -123,47 +120,35 @@ func.tags = ['CreateRepo']; func.skip = async (hre: HardhatRuntimeEnvironment) => { console.log(`\n🏗️ ${path.basename(__filename)}:`); - // Check if the ens record exists already - let pluginRepoAddress; - let ensDomain = ''; - if ( - !process.env.PLUGIN_REPO_ADDRESS || - process.env.PLUGIN_REPO_ADDRESS === ethers.constants.AddressZero - ) { - // try getting the plugin repo from the ens - const res = await findPluginRepo(hre); - pluginRepoAddress = res.pluginRepo?.address; - ensDomain = res.ensDomain; - } else { - // use the provided plugin repo address - pluginRepoAddress = process.env.PLUGIN_REPO_ADDRESS; - - console.log( - `Plugin Repo already deployed at '${pluginRepoAddress}' on network '${getProductionNetworkName( - hre - )}'. Skipping deployment...` - ); - return true; - } + // try getting the plugin repo. + const res = await findPluginRepo(hre); + let pluginRepoAddress = res.pluginRepo?.address; + let ensDomain = res.ensDomain; if (pluginRepoAddress) { - console.log( - `ENS name '${ensDomain}' was claimed already at '${pluginRepoAddress}' on network '${getProductionNetworkName( - hre - )}'. Skipping deployment...` - ); + if (ensDomain != '') { + console.log( + `ENS name '${ensDomain}' was claimed already at '${pluginRepoAddress}' on network '${getProductionNetworkName( + hre + )}'. Skipping deployment...` + ); + } else { + console.log( + `Plugin Repo already deployed at '${pluginRepoAddress}' on network '${getProductionNetworkName( + hre + )}'. Skipping deployment...` + ); + } - // todo if the plugin repo was already published should it be verified? hre.aragonToVerifyContracts.push({ address: pluginRepoAddress, args: [], }); + return true; - } else { - // todo change this log - console.log( - `ENS name '${ensDomain}' is unclaimed. Deploying Plugin Repo...` - ); - return false; } + + console.log('Deploying Plugin Repo'); + + return false; }; diff --git a/packages/contracts/deploy/20_new_version/23_publish.ts b/packages/contracts/deploy/20_new_version/23_publish.ts index 8aa78581..ed5a8ed9 100644 --- a/packages/contracts/deploy/20_new_version/23_publish.ts +++ b/packages/contracts/deploy/20_new_version/23_publish.ts @@ -76,7 +76,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { // Get PluginRepo const {pluginRepo, ensDomain} = await findPluginRepo(hre); if (pluginRepo === null) { - throw `PluginRepo '${ensDomain}' does not exist yet.`; + throw `Can't find Plugin Repo...`; } // Check release number @@ -140,26 +140,17 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { [] ) ) { - let placeholderSetup = getLatestContractAddress('PlaceholderSetup', hre); - - if (placeholderSetup == '') { - // deploy placeholder setup - const {deploy} = deployments; - const res = await deploy(PLUGIN_SETUP_CONTRACT_NAME, { - from: deployer.address, - args: [], - log: true, - }); - - placeholderSetup = res.address; - - // Queue the placeholder for verification - hre.aragonToVerifyContracts.push({ - address: placeholderSetup, - args: [], - }); - } if (latestBuild == 0 && VERSION.build > 1) { + // We are publishing the first version as build > 1. + // So we need to publish placeholders first.. + let placeholderSetup = + process.env.PLACEHOLDER_SETUP ?? + getLatestContractAddress('PlaceholderSetup', hre); + + if (!ethers.utils.isAddress(placeholderSetup)) { + ('Aborting. Placeholder setup not present in this network or in .env or is not an address'); + } + for (let i = 0; i < VERSION.build - 1; i++) { console.log('Publishing placeholder', i + 1); await createVersion( diff --git a/packages/contracts/deploy/30_upgrade_repo/_common.ts b/packages/contracts/deploy/30_upgrade_repo/_common.ts index e5f55140..6d6b8d2f 100644 --- a/packages/contracts/deploy/30_upgrade_repo/_common.ts +++ b/packages/contracts/deploy/30_upgrade_repo/_common.ts @@ -48,12 +48,15 @@ export async function fetchData( // Get the latest `PluginRepo` implementation as the upgrade target let latestPluginRepoImplementation; - if ( - process.env.PLUGIN_REPO_FACTORY_ADDRESS && - process.env.PLUGIN_REPO_FACTORY_ADDRESS !== ethers.constants.AddressZero - ) { + let pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS; + + if (pluginRepoFactoryAddress) { + if (!ethers.utils.isAddress(pluginRepoFactoryAddress)) { + throw new Error('Plugin Repo Factory in .env is not of type Address'); + } + const pluginRepoFactory = PluginRepoFactory__factory.connect( - process.env.PLUGIN_REPO_FACTORY_ADDRESS, + pluginRepoFactoryAddress, deployer ); latestPluginRepoImplementation = PluginRepo__factory.connect( diff --git a/packages/contracts/deploy/helpers.ts b/packages/contracts/deploy/helpers.ts index 04713a76..c84d5927 100644 --- a/packages/contracts/deploy/helpers.ts +++ b/packages/contracts/deploy/helpers.ts @@ -29,3 +29,19 @@ export function getLatestContractAddress( } return ''; } + +export async function forkNetwork( + hre: HardhatRuntimeEnvironment, + fork_url: string +) { + await hre.network.provider.request({ + method: 'hardhat_reset', + params: [ + { + forking: { + jsonRpcUrl: fork_url, + }, + }, + ], + }); +} diff --git a/packages/contracts/utils/helpers.ts b/packages/contracts/utils/helpers.ts index 01fe038a..8c4a17c3 100644 --- a/packages/contracts/utils/helpers.ts +++ b/packages/contracts/utils/helpers.ts @@ -72,14 +72,29 @@ export async function findPluginRepo( ): Promise<{pluginRepo: PluginRepo | null; ensDomain: string}> { const [deployer] = await hre.ethers.getSigners(); - let subdomainRegistrarAddress; if ( - process.env.PLUGIN_REPO_FACTORY_ADDRESS && - process.env.PLUGIN_REPO_FACTORY_ADDRESS !== ethers.constants.AddressZero + process.env.PLUGIN_REPO_ADDRESS && + ethers.utils.isAddress(process.env.PLUGIN_REPO_ADDRESS) ) { + return { + pluginRepo: PluginRepo__factory.connect( + process.env.PLUGIN_REPO_ADDRESS, + deployer + ), + ensDomain: '', + }; + } + + let subdomainRegistrarAddress; + let pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS; + + if (pluginRepoFactoryAddress) { + if (!ethers.utils.isAddress(pluginRepoFactoryAddress)) { + throw new Error('Plugin Repo Factory in .env is not of type Address'); + } // get ENS registrar from the plugin factory provided const pluginRepoFactory = PluginRepoFactory__factory.connect( - process.env.PLUGIN_REPO_FACTORY_ADDRESS, + pluginRepoFactoryAddress, deployer ); @@ -110,13 +125,13 @@ export async function findPluginRepo( if (subdomainRegistrarAddress === ethers.constants.AddressZero) { // the network does not support ENS return {pluginRepo: null, ensDomain: ''}; - } else { - registrar = ENSSubdomainRegistrar__factory.connect( - subdomainRegistrarAddress, - deployer - ); } + registrar = ENSSubdomainRegistrar__factory.connect( + subdomainRegistrarAddress, + deployer + ); + // Check if the ens record exists already const ens = ENS__factory.connect(await registrar.ens(), deployer); const ensDomain = pluginEnsDomain(hre);