Skip to content

Commit

Permalink
fix: find repo helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
clauBv23 committed Feb 17, 2025
1 parent 4763e4d commit 8ccf6ca
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions packages/contracts/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
} from '../plugin-settings';
import {
SupportedNetworks,
getLatestNetworkDeployment,
getNetworkNameByAlias,
getPluginEnsDomain,
} from '@aragon/osx-commons-configs';
Expand Down Expand Up @@ -76,8 +75,7 @@ export function pluginEnsDomain(hre: HardhatRuntimeEnvironment): string {
* 1- env var PLUGIN_REPO_ADDRESS
* 2- try to get the latest network deployment
* 3- from the commons configs
* 3.1- plugin repo factory address from env var
* 3.2- plugin repo factory address from commons configs
* - plugin repo factory address from env var
*/
export async function findPluginRepo(
hre: HardhatRuntimeEnvironment
Expand All @@ -93,6 +91,7 @@ export async function findPluginRepo(
);
}

console.log('from env var PLUGIN_REPO_ADDRESS');
return {
pluginRepo: PluginRepo__factory.connect(
process.env.PLUGIN_REPO_ADDRESS,
Expand All @@ -105,49 +104,24 @@ export async function findPluginRepo(
// from deployments
const pluginRepo = await hre.deployments.getOrNull(PLUGIN_REPO_PROXY_NAME);
if (pluginRepo) {
console.log('from deployments');

return {
pluginRepo: PluginRepo__factory.connect(pluginRepo.address, deployer),
ensDomain,
};
}

// from commons configs
let subdomainRegistrarAddress;
const pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS;
if (pluginRepoFactoryAddress) {
if (!isValidAddress(pluginRepoFactoryAddress)) {
throw new Error(
'Plugin Repo Factory in .env is not valid address (is not an address or is address zero)'
);
}

// get ENS registrar from the plugin factory provided
const pluginRepoFactory = PluginRepoFactory__factory.connect(
pluginRepoFactoryAddress,
deployer
);

const pluginRepoRegistry = PluginRepoRegistry__factory.connect(
await pluginRepoFactory.pluginRepoRegistry(),
deployer
);
// get ENS registrar from the plugin factory provided
const pluginRepoFactory = await getPluginRepoFactory(hre);

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}.`;
}
const pluginRepoRegistry = PluginRepoRegistry__factory.connect(
await pluginRepoFactory.pluginRepoRegistry(),
deployer
);

subdomainRegistrarAddress =
networkDeployments.PluginENSSubdomainRegistrarProxy.address;
}
const subdomainRegistrarAddress =
await pluginRepoRegistry.subdomainRegistrar();

if (subdomainRegistrarAddress === ethers.constants.AddressZero) {
// the network does not support ENS and the plugin repo could not be found by env var or deployments
Expand Down Expand Up @@ -207,6 +181,11 @@ export async function getPluginRepoFactory(

const pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS;

console.log(
'pluginRepoFactoryAddress from env var PLUGIN_REPO_FACTORY_ADDRESS',
pluginRepoFactoryAddress
);

// from env var
if (!pluginRepoFactoryAddress || !isValidAddress(pluginRepoFactoryAddress)) {
throw new Error(
Expand Down

0 comments on commit 8ccf6ca

Please sign in to comment.