Skip to content

Commit

Permalink
refactor: deploy script simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
heueristik committed Feb 6, 2024
1 parent 8d5c04b commit 47a2991
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 355 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ packages/subgraph/tests/.bin
.pnp.*
coverage.json

local-network-deployments.json

packages/subgraph/deploy-output.txt
packages/subgraph/subgraph.yaml
packages/subgraph/tests/.latest.json
Expand Down
7 changes: 1 addition & 6 deletions packages/contracts/deploy/0_info/00_info.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
AragonOSxAsciiArt,
copyAragonDeploymentsInfoFromProdToLocal,
getProductionNetworkName,
isLocal,
} from '../../utils/helpers';
Expand All @@ -20,17 +19,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const [deployer] = await hre.ethers.getSigners();

const local = isLocal(hre);
if (local) {
if (isLocal(hre)) {
const productionNetworkName: string = getProductionNetworkName(hre);

console.log(
`Simulated deployment on local network '${hre.network.name}'. Forking production network '${productionNetworkName}'...`
);

// Copy the entries of the forked network from `production-network-deployments.json` into `local-network-deployments.json`.
copyAragonDeploymentsInfoFromProdToLocal(hre);

// Fork the network provided in the `.env` file
const networkConfig = getNetworkByNameOrAlias(productionNetworkName)!;
await hre.network.provider.request({
Expand Down
64 changes: 25 additions & 39 deletions packages/contracts/deploy/1_create_repo/10_create_repo.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import {PLUGIN_REPO_ENS_NAME} from '../../plugin-settings';
import {addDeployedRepo, getProductionNetworkName} from '../../utils/helpers';
import {
PLUGIN_REPO_ENS_DOMAIN,
PLUGIN_REPO_ENS_SUBDOMAIN_NAME,
} from '../../plugin-settings';
import {findPluginRepo, getProductionNetworkName} from '../../utils/helpers';
import {
getLatestNetworkDeployment,
getNetworkNameByAlias,
} from '@aragon/osx-commons-configs';
import {findEventTopicLog} from '@aragon/osx-commons-sdk';
import {
ENS__factory,
PluginRepoRegistryEvents,
PluginRepoRegistry__factory,
PluginRepo__factory,
ENSSubdomainRegistrar__factory,
PluginRepoFactory__factory,
IAddrResolver__factory,
} from '@aragon/osx-ethers';
import {Contract} from 'ethers';
import {ethers} from 'hardhat';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(
`Creating the '${PLUGIN_REPO_ENS_NAME}.plugin.dao.eth' plugin repo through Aragon's 'PluginRepoFactory'...`
`Creating the '${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}.plugin.dao.eth' plugin repo through Aragon's 'PluginRepoFactory'...`
);

const [deployer] = await hre.ethers.getSigners();
Expand All @@ -37,7 +35,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

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

Expand All @@ -56,53 +54,41 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const blockNumberOfDeployment = (await tx.wait()).blockNumber;

console.log(
`"${PLUGIN_REPO_ENS_NAME}" PluginRepo deployed at: ${pluginRepo.address} at block ${blockNumberOfDeployment}.`
`"${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}" PluginRepo deployed at: ${pluginRepo.address} at block ${blockNumberOfDeployment}.`
);

// Store the information
addDeployedRepo(
hre.network.name,
PLUGIN_REPO_ENS_NAME,
pluginRepo.address,
[PLUGIN_REPO_ENS_NAME, deployer.address],
blockNumberOfDeployment
);
hre.aragonToVerifyContracts.push({
address: pluginRepo.address,
args: [],
});
};

export default func;
func.tags = ['CreateRepo'];
func.skip = async (hre: HardhatRuntimeEnvironment) => {
console.log(`\n🏗️ ${path.basename(__filename)}:`);

const [deployer] = await hre.ethers.getSigners();
const productionNetworkName: string = getProductionNetworkName(hre);

const registrar = ENSSubdomainRegistrar__factory.connect(
getLatestNetworkDeployment(getNetworkNameByAlias(productionNetworkName)!)!
.PluginENSSubdomainRegistrarProxy.address,
deployer
);

// Check if the ens record exists already
const ens = ENS__factory.connect(await registrar.ens(), deployer);
const node = ethers.utils.namehash(`${PLUGIN_REPO_ENS_NAME}.plugin.dao.eth`);
const recordExists = await ens.recordExists(node);
const pluginRepo = await findPluginRepo(hre, PLUGIN_REPO_ENS_DOMAIN);

if (recordExists) {
const resolver = IAddrResolver__factory.connect(
await ens.resolver(node),
deployer
);
const repoAddr = await resolver.addr(node);
const skip = pluginRepo !== null;

if (skip) {
console.log(
`ENS name '${PLUGIN_REPO_ENS_NAME}.plugin.dao.eth' exists already at '${repoAddr}' on network '${productionNetworkName}'. Skipping deployment...`
`ENS name '${PLUGIN_REPO_ENS_DOMAIN}' exists already at '${
pluginRepo.address
}' on network '${getProductionNetworkName(hre)}'. Skipping deployment...`
);

hre.aragonToVerifyContracts.push({
address: pluginRepo.address,
args: [],
});
} else {
console.log(
`ENS name '${PLUGIN_REPO_ENS_NAME}.plugin.dao.eth' does not exist. Deploying...`
`ENS name '${PLUGIN_REPO_ENS_DOMAIN}' does not exist. Deploying...`
);
}

return recordExists;
return skip;
};
30 changes: 0 additions & 30 deletions packages/contracts/deploy/1_create_repo/11_create_repo_conclude.ts

This file was deleted.

76 changes: 26 additions & 50 deletions packages/contracts/deploy/2_new_version/22_publish.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import {
PLUGIN_REPO_ENS_DOMAIN,
METADATA,
PLUGIN_CONTRACT_NAME,
PLUGIN_REPO_ENS_NAME,
PLUGIN_REPO_ENS_SUBDOMAIN_NAME,
PLUGIN_SETUP_CONTRACT_NAME,
VERSION,
} from '../../plugin-settings';
import {IPluginSetup__factory} from '../../typechain';
import {addCreatedVersion, getAragonDeploymentsInfo} from '../../utils/helpers';
import {findPluginRepo, getPastVersionCreatedEvents} from '../../utils/helpers';
import {
PLUGIN_REPO_PERMISSIONS,
toHex,
uploadToIPFS,
} from '@aragon/osx-commons-sdk';
import {PluginRepo__factory} from '@aragon/osx-ethers';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(
`Publishing ${PLUGIN_SETUP_CONTRACT_NAME} as v${VERSION.release}.${VERSION.build} in the "${PLUGIN_REPO_ENS_NAME}" plugin repo`
`Publishing ${PLUGIN_SETUP_CONTRACT_NAME} as v${VERSION.release}.${VERSION.build} in the "${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}" plugin repo`
);

const {deployments} = hre;
Expand All @@ -40,10 +38,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const setup = await deployments.get(PLUGIN_SETUP_CONTRACT_NAME);

// Get PluginRepo
const pluginRepo = PluginRepo__factory.connect(
getAragonDeploymentsInfo(hre.network.name)[hre.network.name].address,
deployer
);
const pluginRepo = await findPluginRepo(hre, PLUGIN_REPO_ENS_DOMAIN);
if (pluginRepo === null) {
throw `PluginRepo '${PLUGIN_REPO_ENS_DOMAIN}' does not exist yet.`;
}

// Check release number
const latestRelease = await pluginRepo.latestRelease();
Expand Down Expand Up @@ -73,7 +71,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}

// Create Version
let tx;
if (
await pluginRepo.callStatic.isGranted(
pluginRepo.address,
Expand All @@ -82,53 +79,28 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
[]
)
) {
tx = await pluginRepo.createVersion(
const tx = await pluginRepo.createVersion(
VERSION.release,
setup.address,
toHex(buildMetadataURI),
toHex(releaseMetadataURI)
);

const blockNumberOfPublication = (await tx.wait()).blockNumber;

if (setup == undefined || setup?.receipt == undefined) {
throw Error('setup deployment unavailable');
}

await tx.wait();

const version = await pluginRepo['getLatestVersion(uint8)'](
VERSION.release
);
if (VERSION.release !== version.tag.release) {
throw Error('something went wrong');
}

const implementationAddress = await IPluginSetup__factory.connect(
setup.address,
deployer
).implementation();

console.log(
`Published ${PLUGIN_SETUP_CONTRACT_NAME} at ${setup.address} in PluginRepo ${PLUGIN_REPO_ENS_NAME} at ${pluginRepo.address} at block ${blockNumberOfPublication}.`
);

addCreatedVersion(
hre.network.name,
{release: VERSION.release, build: version.tag.build},
{release: releaseMetadataURI, build: buildMetadataURI},
blockNumberOfPublication,
{
name: PLUGIN_SETUP_CONTRACT_NAME,
address: setup.address,
args: [],
blockNumberOfDeployment: setup.receipt.blockNumber,
},
{
name: PLUGIN_CONTRACT_NAME,
address: implementationAddress,
args: [],
blockNumberOfDeployment: setup.receipt.blockNumber,
},
[]
`Published ${PLUGIN_SETUP_CONTRACT_NAME} at ${setup.address} in PluginRepo ${PLUGIN_REPO_ENS_SUBDOMAIN_NAME} at ${pluginRepo.address}.`
);
} else {
throw Error(
Expand All @@ -142,19 +114,23 @@ func.tags = [PLUGIN_SETUP_CONTRACT_NAME, 'NewVersion', 'Publication'];
func.skip = async (hre: HardhatRuntimeEnvironment) => {
console.log(`\n📢 ${path.basename(__filename)}:`);

const [deployer] = await hre.ethers.getSigners();
const network: string = hre.network.name;

// Get PluginRepo
const pluginRepo = PluginRepo__factory.connect(
getAragonDeploymentsInfo(network)[network]['address'],
deployer
);

// Check build number
const latestBuild = (await pluginRepo.buildCount(VERSION.release)).toNumber();
const pluginRepo = await findPluginRepo(hre, PLUGIN_REPO_ENS_DOMAIN);
if (pluginRepo === null) {
throw `PluginRepo '${PLUGIN_REPO_ENS_DOMAIN}' does not exist yet.`;
}

const pastVersions = await getPastVersionCreatedEvents(pluginRepo);

// Check if the version was published already
const filteredLogs = pastVersions.filter(
items =>
items.event.args.release === VERSION.release &&
items.event.args.build === VERSION.build
);

if (VERSION.build === latestBuild) {
if (filteredLogs.length !== 0) {
console.log(
`Build number ${VERSION.build} has already been published for release ${VERSION.release}. Skipping publication...`
);
Expand Down
30 changes: 15 additions & 15 deletions packages/contracts/deploy/3_upgrade_repo/30_upgrade_repo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {PLUGIN_REPO_ENS_NAME} from '../../plugin-settings';
import {
getProductionNetworkName,
getAragonDeploymentsInfo,
} from '../../utils/helpers';
PLUGIN_REPO_ENS_DOMAIN,
PLUGIN_REPO_ENS_SUBDOMAIN_NAME,
} from '../../plugin-settings';
import {findPluginRepo, getProductionNetworkName} from '../../utils/helpers';
import {
getLatestNetworkDeployment,
getNetworkNameByAlias,
Expand All @@ -17,17 +17,17 @@ import path from 'path';
type SemVer = [number, number, number];

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {network} = hre;
const [deployer] = await hre.ethers.getSigners();
const productionNetworkName: string = getProductionNetworkName(hre);

const pluginRepo = PluginRepo__factory.connect(
getAragonDeploymentsInfo(network.name)[network.name]['address'],
deployer
);
// Get PluginRepo
const pluginRepo = await findPluginRepo(hre, PLUGIN_REPO_ENS_DOMAIN);
if (pluginRepo === null) {
throw `PluginRepo '${PLUGIN_REPO_ENS_DOMAIN}' does not exist yet.`;
}

console.log(
`Upgrading plugin repo '${PLUGIN_REPO_ENS_NAME}.plugin.dao.eth' (${pluginRepo.address})...`
`Upgrading plugin repo '${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}.plugin.dao.eth' (${pluginRepo.address})...`
);

const newPluginRepoImplementation = PluginRepo__factory.connect(
Expand Down Expand Up @@ -105,10 +105,10 @@ func.skip = async (hre: HardhatRuntimeEnvironment) => {
deployer
);

const pluginRepo = PluginRepo__factory.connect(
getAragonDeploymentsInfo(hre.network.name)[hre.network.name]['address'],
deployer
);
const pluginRepo = await findPluginRepo(hre, PLUGIN_REPO_ENS_DOMAIN);
if (pluginRepo === null) {
throw `PluginRepo '${PLUGIN_REPO_ENS_DOMAIN}' does not exist yet.`;
}

// Compare the current protocol version of the `PluginRepo`
// TODO Use the `getProtocolVersion` function from osx-commons-sdk
Expand All @@ -125,7 +125,7 @@ func.skip = async (hre: HardhatRuntimeEnvironment) => {
// Compare versions
if (JSON.stringify(current) == JSON.stringify(latest)) {
console.log(
`PluginRepo '${PLUGIN_REPO_ENS_NAME}.plugin.dao.eth' (${pluginRepo.address}) has already been upgraded to
`PluginRepo '${PLUGIN_REPO_ENS_SUBDOMAIN_NAME}.plugin.dao.eth' (${pluginRepo.address}) has already been upgraded to
the current protocol version v${latest[0]}.${latest[1]}.${latest[2]}. Skipping upgrade...`
);
return true;
Expand Down
Loading

0 comments on commit 47a2991

Please sign in to comment.