Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: update deploy script #33

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 75 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,55 @@ 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 &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of 2 lines, which is still not trustful, it's better to directly check if process.env.PLUGIN_REPO_FACTORY_ADDRESS is a type of address. This will eliminate 2 checks.

These 2 checks are not trustworthy because if i set PLUGIN_REPO_FACTORY_ADDRESS=blax, this will still work which is wrong.

process.env.PLUGIN_REPO_FACTORY_ADDRESS !== ethers.constants.AddressZero
) {
// use this factory
pluginRepoFactoryAddress = process.env.PLUGIN_REPO_FACTORY_ADDRESS;

const pluginRepoFactory = PluginRepoFactory__factory.connect(
pluginRepoFactoryAddress,
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why empty ? even if you make it equal to '', it will still work. no ?


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 +124,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
38 changes: 29 additions & 9 deletions packages/contracts/deploy/30_upgrade_repo/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import {
getNetworkNameByAlias,
} from '@aragon/osx-commons-configs';
import {UnsupportedNetworkError} from '@aragon/osx-commons-sdk';
import {PluginRepo, PluginRepo__factory} from '@aragon/osx-ethers';
import {
PluginRepo,
PluginRepo__factory,
PluginRepoFactory__factory,
} from '@aragon/osx-ethers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {ethers} from 'hardhat';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';
Expand All @@ -30,10 +35,6 @@ export async function fetchData(
if (network === null) {
throw new UnsupportedNetworkError(productionNetworkName);
}
const networkDeployments = getLatestNetworkDeployment(network);
if (networkDeployments === null) {
throw `Deployments are not available on network ${network}.`;
}

// Get PluginRepo
const {pluginRepo, ensDomain} = await findPluginRepo(hre);
Expand All @@ -46,10 +47,29 @@ export async function fetchData(
);

// Get the latest `PluginRepo` implementation as the upgrade target
const latestPluginRepoImplementation = PluginRepo__factory.connect(
networkDeployments.PluginRepoBase.address,
deployer
);
let latestPluginRepoImplementation;
if (
process.env.PLUGIN_REPO_FACTORY_ADDRESS &&
process.env.PLUGIN_REPO_FACTORY_ADDRESS !== ethers.constants.AddressZero
) {
const pluginRepoFactory = PluginRepoFactory__factory.connect(
process.env.PLUGIN_REPO_FACTORY_ADDRESS,
deployer
);
latestPluginRepoImplementation = PluginRepo__factory.connect(
await pluginRepoFactory.pluginRepoBase(),
deployer
);
} else {
const networkDeployments = getLatestNetworkDeployment(network);
if (networkDeployments === null) {
throw `Deployments are not available on network ${network}.`;
}
latestPluginRepoImplementation = PluginRepo__factory.connect(
networkDeployments.PluginRepoBase.address,
deployer
);
}

// Get the current OSX protocol version from the current plugin repo implementation
let current: SemVer;
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/mocks/Migration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pragma solidity ^0.8.8;
/* solhint-disable no-unused-import */

import {DAO} from "@aragon/osx/core/dao/DAO.sol";
import {PlaceholderSetup} from "@aragon/osx/framework/plugin/repo/placeholder/PlaceholderSetup.sol";

import {PluginRepo} from "@aragon/osx-v1.3.0/framework/plugin/repo/PluginRepo.sol";
import {ProxyFactory} from "@aragon/osx-commons-contracts/src/utils/deployment/ProxyFactory.sol";

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
Loading