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

[WIP]: decouple framework and ens #585

Draft
wants to merge 16 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
34 changes: 30 additions & 4 deletions packages/contracts/deploy/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
} from '../typechain';
import {VersionCreatedEvent} from '../typechain/PluginRepo';
import {PluginRepoRegisteredEvent} from '../typechain/PluginRepoRegistry';
import {ensLabelHash} from '../utils/ens';
import {isLocal, pluginDomainEnv} from '../utils/environment';
import {
getNetworkNameByAlias,
getLatestNetworkDeployment,
} from '@aragon/osx-commons-configs';
import {findEvent, findEventTopicLog, Operation} from '@aragon/osx-commons-sdk';
import {ENSSubdomainRegistrar__factory} from '@aragon/osx-ethers-v1.2.0';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {Contract} from 'ethers';
import {ethers} from 'hardhat';
Expand Down Expand Up @@ -158,6 +160,25 @@ export async function detemineDeployerNextAddress(
return futureAddress;
}

export async function registerPluginRepoSubdomain(
hre: HardhatRuntimeEnvironment,
repoAddress: string,
subdomain: string,
ensRegistrar: any
): Promise<void> {
const [deployer] = await ethers.getSigners();

const ensRegistrarContract = ENSSubdomainRegistrar__factory.connect(
ensRegistrar,
deployer
);

await ensRegistrarContract.registerSubnode(
ensLabelHash(subdomain),
repoAddress
);
}

export async function createPluginRepo(
hre: HardhatRuntimeEnvironment,
pluginName: string,
Expand Down Expand Up @@ -191,10 +212,7 @@ export async function createPluginRepo(

const {deployer} = await hre.getNamedAccounts();

const tx = await pluginRepoFactoryContract.createPluginRepo(
subdomain,
deployer
);
const tx = await pluginRepoFactoryContract.createPluginRepo(deployer);
console.log(
`Creating & registering repo for ${pluginName} with tx ${tx.hash}`
);
Expand All @@ -209,6 +227,14 @@ export async function createPluginRepo(

hre.aragonPluginRepos[pluginName] = repoAddress;

// register subdomain
await registerPluginRepoSubdomain(
hre,
repoAddress,
subdomain,
await getContractAddress('PluginENSSubdomainRegistrarProxy', hre)
);

console.log(
`Created & registered repo for ${pluginName} at address: ${repoAddress}` //, with contentURI ${ethers.utils.toUtf8String(releaseMetadata)}`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
);

// Get DAO's `ENSSubdomainRegistrar` contract.
const ensSubdomainRegistrarAddress = await getContractAddress(
'DAOENSSubdomainRegistrarProxy',
hre
);
//! no longer neede
// const ensSubdomainRegistrarAddress = await getContractAddress(
// 'DAOENSSubdomainRegistrarProxy',
// hre
// );

await deploy('DAORegistryProxy', {
contract: daoRegistryArtifact,
Expand All @@ -32,7 +33,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
execute: {
init: {
methodName: 'initialize',
args: [managementDAOAddress, ensSubdomainRegistrarAddress],
args: [managementDAOAddress],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
);

// Get DAO's `ENSSubdomainRegistrar` address.
const ensSubdomainRegistrarAddress = await getContractAddress(
'PluginENSSubdomainRegistrarProxy',
hre
);
// ! no longer needed
// const ensSubdomainRegistrarAddress = await getContractAddress(
// 'PluginENSSubdomainRegistrarProxy',
// hre
// );

await deploy('PluginRepoRegistryProxy', {
contract: pluginRepoRegistryArtifact,
Expand All @@ -32,7 +33,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
execute: {
init: {
methodName: 'initialize',
args: [managementDAOAddress, ensSubdomainRegistrarAddress],
args: [managementDAOAddress],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const daoNode = ethers.utils.namehash(daoDomain);
const pluginNode = ethers.utils.namehash(pluginDomain);

// Get DAO's `DAORegistry` address.
const daoRegistry = await getContractAddress('DAORegistryProxy', hre);

await deploy('DAOENSSubdomainRegistrarProxy', {
contract: ensSubdomainRegistrarArtifact,
from: deployer.address,
Expand All @@ -38,7 +41,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
execute: {
init: {
methodName: 'initialize',
args: [managementDAOAddress, ensRegistryAddress, daoNode],
args: [
managementDAOAddress,
ensRegistryAddress,
daoRegistry,
daoNode,
],
},
},
},
Expand All @@ -50,6 +58,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
hre
);

// Get DAO's `PluginRepoRegistry` address.
const pluginRepoRegistry = await getContractAddress(
'PluginRepoRegistryProxy',
hre
);

await deploy('PluginENSSubdomainRegistrarProxy', {
contract: ensSubdomainRegistrarArtifact,
from: deployer.address,
Expand All @@ -62,7 +76,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
execute: {
init: {
methodName: 'initialize',
args: [managementDAOAddress, ensRegistryAddress, pluginNode],
args: [
managementDAOAddress,
ensRegistryAddress,
pluginRepoRegistry,
pluginNode,
],
},
},
},
Expand Down
94 changes: 62 additions & 32 deletions packages/contracts/deploy/new/10_framework/99_verifiy_step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
hre
);

// VERIFYING DAO REGISTRY
const DAORegistryAddress = await getContractAddress('DAORegistryProxy', hre);
const DAORegistry = DAORegistry__factory.connect(
DAORegistryAddress,
deployer
);

await checkSetManagementDao(DAORegistry, managementDAOAddress);
// ! not nedded as the registry no longer has the subdomain registrar
// // scope to reuse same const again
// {
// const SubdomainRegistrarAddress = await DAORegistry.subdomainRegistrar();
// if (SubdomainRegistrarAddress !== DAOENSSubdomainRegistrarAddress) {
// throw new Error(
// `${DAORegistry} has wrong SubdomainRegistrarAddress set. Expected ${DAOENSSubdomainRegistrarAddress} to be ${SubdomainRegistrarAddress}`
// );
// }
// }

// VERIFYING DAO ENS SUBDOMAIN REGISTRAR
const DAOENSSubdomainRegistrarAddress = await getContractAddress(
'DAOENSSubdomainRegistrarProxy',
Expand All @@ -33,6 +52,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
DAOENSSubdomainRegistrarAddress,
deployer
);

await checkSetManagementDao(DAOENSSubdomainRegistrar, managementDAOAddress);
// scope to reuse same const again
{
Expand All @@ -57,6 +77,42 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
}

// check is the correct registry
{
const SubdomainRegistry = await DAOENSSubdomainRegistrar.registry();
console.log('SubdomainRegistry', SubdomainRegistry);
console.log('DAORegistryAddress', DAORegistryAddress);

if (SubdomainRegistry !== DAORegistryAddress) {
throw new Error(
`${DAOENSSubdomainRegistrar} has wrong Registry set. Expected ${DAORegistryAddress} to be ${SubdomainRegistry}`
);
}
}

// VERIFYING PLUGIN REPO REGISTRY
const PluginRepoRegistryAddress = await getContractAddress(
'PluginRepoRegistryProxy',
hre
);
const PluginRepoRegistry = PluginRepoRegistry__factory.connect(
PluginRepoRegistryAddress,
deployer
);
await checkSetManagementDao(PluginRepoRegistry, managementDAOAddress);

// ! not needed as the registry no longer has the subdomain registrar
// scope to reuse same const again
// {
// const SubdomainRegistrarAddress =
// await PluginRepoRegistry.subdomainRegistrar();
// if (SubdomainRegistrarAddress !== PluginENSSubdomainRegistrarAddress) {
// throw new Error(
// `${PluginRepoRegistry} has wrong SubdomainRegistrarAddress set. Expected ${PluginENSSubdomainRegistrarAddress} to be ${SubdomainRegistrarAddress}`
// );
// }
// }

// VERIFYING PLUGIN ENS SUBDOMAIN REGISTRAR
const PluginENSSubdomainRegistrarAddress = await getContractAddress(
'PluginENSSubdomainRegistrarProxy',
Expand Down Expand Up @@ -93,40 +149,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
}

// VERIFYING DAO REGISTRY
const DAORegistryAddress = await getContractAddress('DAORegistryProxy', hre);
const DAORegistry = DAORegistry__factory.connect(
DAORegistryAddress,
deployer
);
await checkSetManagementDao(DAORegistry, managementDAOAddress);
// scope to reuse same const again
{
const SubdomainRegistrarAddress = await DAORegistry.subdomainRegistrar();
if (SubdomainRegistrarAddress !== DAOENSSubdomainRegistrarAddress) {
throw new Error(
`${DAORegistry} has wrong SubdomainRegistrarAddress set. Expected ${DAOENSSubdomainRegistrarAddress} to be ${SubdomainRegistrarAddress}`
);
}
}

// VERIFYING PLUGIN REPO REGISTRY
const PluginRepoRegistryAddress = await getContractAddress(
'PluginRepoRegistryProxy',
hre
);
const PluginRepoRegistry = PluginRepoRegistry__factory.connect(
PluginRepoRegistryAddress,
deployer
);
await checkSetManagementDao(PluginRepoRegistry, managementDAOAddress);
// scope to reuse same const again
// check is the correct registry
{
const SubdomainRegistrarAddress =
await PluginRepoRegistry.subdomainRegistrar();
if (SubdomainRegistrarAddress !== PluginENSSubdomainRegistrarAddress) {
const SubdomainRegistry = await PluginENSSubdomainRegistrar.registry();
console.log('SubdomainRegistry', SubdomainRegistry);
console.log('PluginRepoRegistryAddress', PluginRepoRegistryAddress);
if (SubdomainRegistry !== PluginRepoRegistryAddress) {
throw new Error(
`${PluginRepoRegistry} has wrong SubdomainRegistrarAddress set. Expected ${PluginENSSubdomainRegistrarAddress} to be ${SubdomainRegistrarAddress}`
`${PluginENSSubdomainRegistrar} has wrong Registry set. Expected ${PluginRepoRegistryAddress} to be ${SubdomainRegistry}`
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// Register `managementDAO` on `DAORegistry`.
const registerTx = await daoRegistryContract.register(
managementDAOAddress,
deployer.address,
daoSubdomain
deployer.address
);
await registerTx.wait();
console.log(
Expand Down
18 changes: 15 additions & 3 deletions packages/contracts/src/framework/dao/DAOFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ contract DAOFactory is ERC165, ProtocolVersion {
struct DAOSettings {
address trustedForwarder;
string daoURI;
string subdomain;
bytes metadata;
}

Expand Down Expand Up @@ -78,7 +77,8 @@ contract DAOFactory is ERC165, ProtocolVersion {
/// @param _pluginSettings The array containing references to plugins and their settings to be installed after the DAO has been created.
function createDao(
DAOSettings calldata _daoSettings,
PluginSettings[] calldata _pluginSettings
PluginSettings[] calldata _pluginSettings,
IDAO.Action[] calldata _actions
) external returns (DAO createdDao) {
// Check if no plugin is provided.
if (_pluginSettings.length == 0) {
Expand All @@ -89,7 +89,7 @@ contract DAOFactory is ERC165, ProtocolVersion {
createdDao = _createDAO(_daoSettings);

// Register DAO.
daoRegistry.register(createdDao, msg.sender, _daoSettings.subdomain);
daoRegistry.register(createdDao, msg.sender);

// Get Permission IDs
bytes32 rootPermissionID = createdDao.ROOT_PERMISSION_ID();
Expand Down Expand Up @@ -133,6 +133,18 @@ contract DAOFactory is ERC165, ProtocolVersion {
);
}

if (_actions.length > 0) {
// grant temporary execute action permission to this DAOFactory
bytes32 executeActionPermissionID = createdDao.EXECUTE_PERMISSION_ID();
createdDao.grant(address(createdDao), address(this), executeActionPermissionID);

// Execute actions on the newly created DAO.
createdDao.execute(bytes32("callID"), _actions, 0);

// revoke the execute action permission
createdDao.revoke(address(createdDao), address(this), executeActionPermissionID);
}

// Set the rest of DAO's permissions.
_setDAOPermissions(createdDao);

Expand Down
Loading
Loading