Skip to content

Commit

Permalink
feat: update the scripts to be able to get the plugin reo and the plu…
Browse files Browse the repository at this point in the history
…gin repo address from the env vars
  • Loading branch information
clauBv23 committed Jan 24, 2025
1 parent 68f8cc9 commit 6d34798
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 35 deletions.
91 changes: 72 additions & 19 deletions packages/contracts/deploy/10_create_repo/11_create_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
PluginRepo__factory,
PluginRepoFactory__factory,
} from '@aragon/osx-ethers';
import {ethers} from 'hardhat';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';
Expand All @@ -27,6 +28,7 @@ import path from 'path';
* @param {HardhatRuntimeEnvironment} hre
*/
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// todo change this log
console.log(
`Creating the '${pluginEnsDomain(
hre
Expand All @@ -36,23 +38,52 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const [deployer] = await hre.ethers.getSigners();

// Get the Aragon `PluginRepoFactory` from the `osx-commons-configs`
const productionNetworkName = getProductionNetworkName(hre);
const network = getNetworkNameByAlias(productionNetworkName);
if (network === null) {
throw new UnsupportedNetworkError(productionNetworkName);
}
const networkDeployments = getLatestNetworkDeployment(network);
if (networkDeployments === null) {
throw `Deployments are not available on network ${network}.`;
let pluginRepoFactoryAddress;
let subdomainRegistrar;
if (process.env.PLUGIN_REPO_FACTORY_ADDRESS) {
// use this factory
pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS;

const pluginRepoFactory = PluginRepoFactory__factory.connect(
process.env.PLUGIN_REPO_FACTORY_ADDRESS,
deployer
);

const pluginRepoRegistry = PluginRepoRegistry__factory.connect(
await pluginRepoFactory.pluginRepoRegistry(),
deployer
);
subdomainRegistrar = await pluginRepoRegistry.subdomainRegistrar();
} else {
// get the factory from osx-commons-configs deployments
const productionNetworkName = getProductionNetworkName(hre);
const network = getNetworkNameByAlias(productionNetworkName);
if (network === null) {
throw new UnsupportedNetworkError(productionNetworkName);
}
const networkDeployments = getLatestNetworkDeployment(network);
if (networkDeployments === null) {
throw `Deployments are not available on network ${network}.`;
}
pluginRepoFactoryAddress = networkDeployments.PluginRepoFactory.address;

subdomainRegistrar =
networkDeployments.PluginENSSubdomainRegistrarProxy.address;
}
// subdomain will depend on if the framework has the ens or not
const subdomain =
subdomainRegistrar !== ethers.constants.AddressZero
? PLUGIN_REPO_ENS_SUBDOMAIN_NAME
: 'empty'; // todo set to empty when is possible

const pluginRepoFactory = PluginRepoFactory__factory.connect(
networkDeployments.PluginRepoFactory.address,
pluginRepoFactoryAddress,
deployer
);

// Create the `PluginRepo` through the Aragon `PluginRepoFactory`
const tx = await pluginRepoFactory.createPluginRepo(
PLUGIN_REPO_ENS_SUBDOMAIN_NAME,
subdomain,
deployer.address
);

Expand Down Expand Up @@ -90,24 +121,46 @@ func.skip = async (hre: HardhatRuntimeEnvironment) => {
console.log(`\n🏗️ ${path.basename(__filename)}:`);

// Check if the ens record exists already
const {pluginRepo, ensDomain} = await findPluginRepo(hre);
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;

if (pluginRepo !== null) {
console.log(
`ENS name '${ensDomain}' was claimed already at '${
pluginRepo.address
}' on network '${getProductionNetworkName(hre)}'. Skipping deployment...`
`Plugin Repo already deployed at '${pluginRepoAddress}' on network '${getProductionNetworkName(
hre
)}'. Skipping deployment...`
);
return true;
}

if (pluginRepoAddress) {
console.log(
`ENS name '${ensDomain}' was claimed already at '${pluginRepoAddress}' on network '${getProductionNetworkName(
hre
)}'. Skipping deployment...`
);

// todo if the plugin repo was already published should it be verified?
hre.aragonToVerifyContracts.push({
address: pluginRepo.address,
address: pluginRepoAddress,
args: [],
});

return true;
} else {
console.log(`ENS name '${ensDomain}' is unclaimed. Deploying...`);

// todo change this log
console.log(
`ENS name '${ensDomain}' is unclaimed. Deploying Plugin Repo...`
);
return false;
}
};
21 changes: 17 additions & 4 deletions packages/contracts/deploy/20_new_version/23_publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,24 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
[]
)
) {
const placeholderSetup = getLatestContractAddress('PlaceholderSetup', hre);
let placeholderSetup = getLatestContractAddress('PlaceholderSetup', hre);

if (placeholderSetup == '') {
throw new Error(
'Aborting. Placeholder setup not present in this network'
);
// 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) {
for (let i = 0; i < VERSION.build - 1; i++) {
Expand Down
56 changes: 44 additions & 12 deletions packages/contracts/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
PluginRepo,
PluginRepoEvents,
PluginRepo__factory,
PluginRepoFactory__factory,
PluginRepoRegistry__factory,
} from '@aragon/osx-ethers';
import {setBalance} from '@nomicfoundation/hardhat-network-helpers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
Expand Down Expand Up @@ -69,21 +71,51 @@ export async function findPluginRepo(
hre: HardhatRuntimeEnvironment
): Promise<{pluginRepo: PluginRepo | null; ensDomain: string}> {
const [deployer] = await hre.ethers.getSigners();
const productionNetworkName: string = getProductionNetworkName(hre);

const network = getNetworkNameByAlias(productionNetworkName);
if (network === null) {
throw new UnsupportedNetworkError(productionNetworkName);
}
const networkDeployments = getLatestNetworkDeployment(network);
if (networkDeployments === null) {
throw `Deployments are not available on network ${network}.`;
let subdomainRegistrarAddress;
if (
process.env.PLUGIN_REPO_FACTORY_ADDRESS &&
process.env.PLUGIN_REPO_FACTORY_ADDRESS !== ethers.constants.AddressZero
) {
// get ENS registrar from the plugin factory provided
const pluginRepoFactory = PluginRepoFactory__factory.connect(
process.env.PLUGIN_REPO_FACTORY_ADDRESS,
deployer
);

const pluginRepoRegistry = PluginRepoRegistry__factory.connect(
await pluginRepoFactory.pluginRepoRegistry(),
deployer
);

subdomainRegistrarAddress = await pluginRepoRegistry.subdomainRegistrar();
} else {
// get ENS registrar from the commons configs deployments
const productionNetworkName: string = getProductionNetworkName(hre);

const network = getNetworkNameByAlias(productionNetworkName);
if (network === null) {
throw new UnsupportedNetworkError(productionNetworkName);
}
const networkDeployments = getLatestNetworkDeployment(network);
if (networkDeployments === null) {
throw `Deployments are not available on network ${network}.`;
}

subdomainRegistrarAddress =
networkDeployments.PluginENSSubdomainRegistrarProxy.address;
}

const registrar = ENSSubdomainRegistrar__factory.connect(
networkDeployments.PluginENSSubdomainRegistrarProxy.address,
deployer
);
let registrar;
if (subdomainRegistrarAddress === ethers.constants.AddressZero) {
// the network does not support ENS
return {pluginRepo: null, ensDomain: ''};
} else {
registrar = ENSSubdomainRegistrar__factory.connect(
subdomainRegistrarAddress,
deployer
);
}

// Check if the ens record exists already
const ens = ENS__factory.connect(await registrar.ens(), deployer);
Expand Down

0 comments on commit 6d34798

Please sign in to comment.