Skip to content

Commit

Permalink
fix: replacing getContractFactory and getContractAt by typechain fact…
Browse files Browse the repository at this point in the history
…ory calls and added missing awaits
  • Loading branch information
heueristik committed May 12, 2023
1 parent 559a756 commit df4a9e3
Show file tree
Hide file tree
Showing 64 changed files with 508 additions and 423 deletions.
50 changes: 28 additions & 22 deletions packages/contracts/deploy/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {findEvent} from '../utils/event';
import {getMergedABI} from '../utils/abi';
import {Operation} from '../utils/types';
import {VersionTag} from '../test/test-utils/psp/types';
import {PluginRepo__factory} from '../typechain';
import {ENSRegistry__factory, PluginRepo__factory} from '../typechain';
import {VersionCreatedEvent} from '../typechain/PluginRepo';
import {PluginRepoRegisteredEvent} from '../typechain/PluginRepoRegistry';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';

// TODO: Add support for L2 such as Arbitrum. (https://discuss.ens.domains/t/register-using-layer-2/688)
// Make sure you own the ENS set in the {{NETWORK}}_ENS_DOMAIN variable in .env
Expand Down Expand Up @@ -124,12 +125,12 @@ export async function updateActiveContractsJSON(payload: {

export async function detemineDeployerNextAddress(
index: number,
deployer: any
deployer: SignerWithAddress
): Promise<string> {
const [owner] = await ethers.getSigners();
const nonce = await owner.getTransactionCount();
const futureAddress = ethers.utils.getContractAddress({
from: deployer,
from: deployer.address,
nonce: nonce + index,
});
return futureAddress;
Expand All @@ -140,21 +141,22 @@ export async function createPluginRepo(
pluginName: string
): Promise<void> {
const {network} = hre;
const signers = await ethers.getSigners();

const pluginDomain =
process.env[`${network.name.toUpperCase()}_PLUGIN_ENS_DOMAIN`] || '';
if (
await isENSDomainRegistered(
`${pluginName}.${pluginDomain}`,
await getENSAddress(hre)
await getENSAddress(hre),
signers[0]
)
) {
// not beeing able to register the plugin repo means that something is not right with the framework deployment used.
// Either a frontrun happened or something else. Thus we abort here
throw new Error(`${pluginName} is already present! Aborting...`);
}

const signers = await ethers.getSigners();

const pluginRepoFactoryAddress = await getContractAddress(
'PluginRepoFactory',
hre
Expand Down Expand Up @@ -416,11 +418,12 @@ export async function managePermissions(

export async function isENSDomainRegistered(
domain: string,
ensRegistryAddress: string
ensRegistryAddress: string,
signer: SignerWithAddress
): Promise<boolean> {
const ensRegistryContract = await ethers.getContractAt(
'ENSRegistry',
ensRegistryAddress
const ensRegistryContract = ENSRegistry__factory.connect(
ensRegistryAddress,
signer
);

return ensRegistryContract.recordExists(ethers.utils.namehash(domain));
Expand Down Expand Up @@ -458,23 +461,22 @@ export async function getPublicResolverAddress(

export async function registerSubnodeRecord(
domain: string,
owner: string,
owner: SignerWithAddress,
ensRegistryAddress: string,
publicResolver: string
): Promise<string> {
const domainSplitted = domain.split('.');
const subdomain = domainSplitted.splice(0, 1)[0];
const parentDomain = domainSplitted.join('.');

const ensRegistryContract = await ethers.getContractAt(
'ENSRegistry',
ensRegistryAddress
const ensRegistryContract = ENSRegistry__factory.connect(
ensRegistryAddress,
owner
);

const tx = await ensRegistryContract.setSubnodeRecord(
ethers.utils.namehash(parentDomain),
ethers.utils.keccak256(ethers.utils.toUtf8Bytes(subdomain)),
owner,
owner.address,
publicResolver,
0
);
Expand All @@ -491,9 +493,11 @@ export async function transferSubnodeRecord(
const subdomain = domainSplitted.splice(0, 1)[0];
const parentDomain = domainSplitted.join('.');

const ensRegistryContract = await ethers.getContractAt(
'ENSRegistry',
ensRegistryAddress
const [deployer] = await ethers.getSigners();

const ensRegistryContract = ENSRegistry__factory.connect(
ensRegistryAddress,
deployer
);

const tx = await ensRegistryContract.setSubnodeOwner(
Expand All @@ -514,9 +518,11 @@ export async function transferSubnodeChain(
currentOwner: string,
ensRegistryAddress: string
): Promise<void> {
const ensRegistryContract = await ethers.getContractAt(
'ENSRegistry',
ensRegistryAddress
const [deployer] = await ethers.getSigners();

const ensRegistryContract = ENSRegistry__factory.connect(
ensRegistryAddress,
deployer
);

const daoDomainSplitted = fullDomain.split('.').reverse();
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/deploy/new/00_managing-dao/00_managing-dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import daoArtifactJson from '../../../artifacts/src/core/dao/DAO.sol/DAO.json';
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`\nDeploying ManagingDao.`);

const {deployments, getNamedAccounts, ethers} = hre;
const {deployments, ethers} = hre;
const {deploy} = deployments;
const {deployer} = await getNamedAccounts();
const [deployer] = await ethers.getSigners();

console.log(
`ManagingDAO will be owned by the (Deployer: ${deployer}) temporarily, while the entire framework is getting deployed.` +
`ManagingDAO will be owned by the (Deployer: ${deployer.address}) temporarily, while the entire framework is getting deployed.` +
` At the final step when Multisig is available, it will be installed on managingDAO and all roles for the Deployer will be revoked.`
);

const initializeParams = {
metadata: '0x',
initialOwner: deployer,
initialOwner: deployer.address,
trustedForwarder: ethers.constants.AddressZero,
daoURI: '0x',
};
Expand All @@ -29,11 +29,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

await deploy('DAO', {
contract: daoArtifactData,
from: deployer,
from: deployer.address,
args: [],
log: true,
proxy: {
owner: deployer,
owner: deployer.address,
proxyContract: 'ERC1967Proxy',
proxyArgs: ['{implementation}', '{data}'],
execute: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {Operation} from '../../../utils/types';

import {getContractAddress, managePermissions} from '../../helpers';
import {DAO__factory} from '../../../typechain';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {getNamedAccounts, ethers} = hre;
const {deployer} = await getNamedAccounts();
const {ethers} = hre;
const [deployer] = await ethers.getSigners();

console.log(`Granting ${deployer.address} temp execute permissions`);

console.log(`Granting ${deployer} temp execute permissions`);
// Get `managingDAO` address.
const managingDAOAddress = await getContractAddress('DAO', hre);

// Get `DAO` contract.
const managingDaoContract = await ethers.getContractAt(
'src/core/dao/DAO.sol:DAO',
managingDAOAddress
const managingDaoContract = DAO__factory.connect(
managingDAOAddress,
deployer
);

// grant the deployer execute permissions during deployment. This will be revoked in 40_finalize-managing-dao/40_revoke-permissions
await managePermissions(managingDaoContract, [
{
operation: Operation.Grant,
where: {name: 'DAO', address: managingDAOAddress},
who: {name: 'Deployer', address: deployer},
who: {name: 'Deployer', address: deployer.address},
permission: 'EXECUTE_PERMISSION',
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import {
getContractAddress,
managePermissions,
} from '../../helpers';
import {DAO__factory} from '../../../typechain';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nSetting ManagingDao permissions.');
const {ethers} = hre;
const [deployer] = await ethers.getSigners();

// Get `managingDAO` address.
const managingDAOAddress = await getContractAddress('DAO', hre);

// Get `DAO` contract.
const managingDaoContract = await ethers.getContractAt(
'src/core/dao/DAO.sol:DAO',
managingDAOAddress
const managingDaoContract = DAO__factory.connect(
managingDAOAddress,
deployer
);

// Set all the permission needed for a DAO to operate normally as if it was created via DAOFactory.
Expand Down
11 changes: 6 additions & 5 deletions packages/contracts/deploy/new/00_managing-dao/99_verify_step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ import {
DAO_PERMISSIONS,
getContractAddress,
} from '../../helpers';
import {DAO__factory} from '../../../typechain';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log('\nVerifying managing DAO deployment.');

const {getNamedAccounts, ethers} = hre;
const {deployer} = await getNamedAccounts();
const [deployer] = await ethers.getSigners();

// Get `managingDAO` address.
const managingDAOAddress = await getContractAddress('DAO', hre);
// Get `DAO` contract.
const managingDaoContract = await ethers.getContractAt(
'src/core/dao/DAO.sol:DAO',
managingDAOAddress
const managingDaoContract = DAO__factory.connect(
managingDAOAddress,
deployer
);

// Check that deployer has root permission.
await checkPermission(managingDaoContract, {
operation: Operation.Grant,
where: {name: 'ManagingDAO', address: managingDAOAddress},
who: {name: 'Deployer', address: deployer},
who: {name: 'Deployer', address: deployer.address},
permission: 'ROOT_PERMISSION',
});

Expand Down
27 changes: 16 additions & 11 deletions packages/contracts/deploy/new/10_framework/01_ens_subdomains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import {
registerSubnodeRecord,
transferSubnodeChain,
} from '../../helpers';
import {ENSRegistry__factory} from '../../../typechain';

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

// Get ENS subdomains
const daoDomain =
Expand All @@ -23,9 +24,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}

const ensRegistryAddress = await getENSAddress(hre);
const ensRegistryContract = await ethers.getContractAt(
'ENSRegistry',
ensRegistryAddress
const ensRegistryContract = ENSRegistry__factory.connect(
ensRegistryAddress,
deployer
);

// Check if domains are owned by the managingDAO
Expand All @@ -43,8 +44,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await getPublicResolverAddress(hre)
);
}
if (daoDomainOwnerAddress != deployer) {
throw new Error(`${daoDomain} is not owned by deployer: ${deployer}.`);
if (daoDomainOwnerAddress != deployer.address) {
throw new Error(
`${daoDomain} is not owned by deployer: ${deployer.address}.`
);
}

let pluginDomainOwnerAddress = await ensRegistryContract.owner(pluginNode);
Expand All @@ -57,22 +60,24 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await getPublicResolverAddress(hre)
);
}
if (pluginDomainOwnerAddress != deployer) {
throw new Error(`${pluginDomain} is not owned by deployer: ${deployer}.`);
if (pluginDomainOwnerAddress != deployer.address) {
throw new Error(
`${pluginDomain} is not owned by deployer: ${deployer.address}.`
);
}

// Registration is now complete. Lets move the ownership of all domains to the managing DAO
const managingDAOAddress = await getContractAddress('DAO', hre);
await transferSubnodeChain(
daoDomain,
managingDAOAddress,
deployer,
deployer.address,
await getENSAddress(hre)
);
await transferSubnodeChain(
pluginDomain,
managingDAOAddress,
deployer,
deployer.address,
await getENSAddress(hre)
);
};
Expand Down
Loading

0 comments on commit df4a9e3

Please sign in to comment.