Skip to content

Commit

Permalink
better approach
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Jan 27, 2025
1 parent d582907 commit cfeedfc
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 89 deletions.
21 changes: 10 additions & 11 deletions packages/contracts/deploy/00_info/01_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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(
Expand All @@ -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}'.`);
}
Expand Down
73 changes: 29 additions & 44 deletions packages/contracts/deploy/10_create_repo/11_create_repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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({
Expand All @@ -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;

Check failure on line 125 in packages/contracts/deploy/10_create_repo/11_create_repo.ts

View workflow job for this annotation

GitHub Actions / checks

'pluginRepoAddress' is never reassigned. Use 'const' instead

Check failure on line 125 in packages/contracts/deploy/10_create_repo/11_create_repo.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'pluginRepoAddress' is never reassigned. Use 'const' instead

Check failure on line 125 in packages/contracts/deploy/10_create_repo/11_create_repo.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'pluginRepoAddress' is never reassigned. Use 'const' instead
let ensDomain = res.ensDomain;

Check failure on line 126 in packages/contracts/deploy/10_create_repo/11_create_repo.ts

View workflow job for this annotation

GitHub Actions / checks

'ensDomain' is never reassigned. Use 'const' instead

Check failure on line 126 in packages/contracts/deploy/10_create_repo/11_create_repo.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'ensDomain' is never reassigned. Use 'const' instead

Check failure on line 126 in packages/contracts/deploy/10_create_repo/11_create_repo.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'ensDomain' is never reassigned. Use 'const' instead

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;
};
31 changes: 11 additions & 20 deletions packages/contracts/deploy/20_new_version/23_publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =

Check failure on line 146 in packages/contracts/deploy/20_new_version/23_publish.ts

View workflow job for this annotation

GitHub Actions / checks

'placeholderSetup' is never reassigned. Use 'const' instead

Check failure on line 146 in packages/contracts/deploy/20_new_version/23_publish.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'placeholderSetup' is never reassigned. Use 'const' instead

Check failure on line 146 in packages/contracts/deploy/20_new_version/23_publish.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'placeholderSetup' is never reassigned. Use 'const' instead
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(
Expand Down
13 changes: 8 additions & 5 deletions packages/contracts/deploy/30_upgrade_repo/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 51 in packages/contracts/deploy/30_upgrade_repo/_common.ts

View workflow job for this annotation

GitHub Actions / checks

'pluginRepoFactoryAddress' is never reassigned. Use 'const' instead

Check failure on line 51 in packages/contracts/deploy/30_upgrade_repo/_common.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'pluginRepoFactoryAddress' is never reassigned. Use 'const' instead

Check failure on line 51 in packages/contracts/deploy/30_upgrade_repo/_common.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'pluginRepoFactoryAddress' is never reassigned. Use 'const' instead

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(
Expand Down
16 changes: 16 additions & 0 deletions packages/contracts/deploy/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
],
});
}
33 changes: 24 additions & 9 deletions packages/contracts/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 89 in packages/contracts/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / checks

'pluginRepoFactoryAddress' is never reassigned. Use 'const' instead

Check failure on line 89 in packages/contracts/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'pluginRepoFactoryAddress' is never reassigned. Use 'const' instead

Check failure on line 89 in packages/contracts/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'pluginRepoFactoryAddress' is never reassigned. Use 'const' instead

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
);

Expand Down Expand Up @@ -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(

Check failure on line 130 in packages/contracts/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / checks

'registrar' is never reassigned. Use 'const' instead

Check failure on line 130 in packages/contracts/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'registrar' is never reassigned. Use 'const' instead

Check failure on line 130 in packages/contracts/utils/helpers.ts

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

'registrar' is never reassigned. Use 'const' instead
subdomainRegistrarAddress,
deployer
);

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

0 comments on commit cfeedfc

Please sign in to comment.