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: use osx-commons-contracts and osx-commons-configs #28

Merged
merged 34 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3ba7e25
build: use ts 5.2.2
heueristik Jan 24, 2024
108c8db
refactor: use osx-commons
heueristik Jan 24, 2024
bbe0f19
refactor: use osx-commons
heueristik Jan 24, 2024
4fdfb64
build: use osx-commons-sdk
heueristik Jan 24, 2024
c63d259
build: use osx-commons-sdk
heueristik Jan 24, 2024
b878f80
refactor: contract improvements
heueristik Jan 24, 2024
4c37ebd
build: print coverage report
heueristik Jan 25, 2024
e0d6b07
chore: bump osx-commons-sdk version
heueristik Jan 25, 2024
8681e2c
feat: use the latest osx-commons-contracts
heueristik Jan 25, 2024
b305f04
refactor: use osx-commons-configs and deploy script refactor
heueristik Feb 1, 2024
bd62677
build: subgraph fix
heueristik Feb 1, 2024
b36aba2
docs: improve .env example
heueristik Feb 1, 2024
9c7468f
style: fix prettier
heueristik Feb 1, 2024
5695001
build: use osx-commons
heueristik Feb 6, 2024
36df455
chore: bump subgraph osx-ethers dependency
heueristik Feb 6, 2024
6a7151a
chore: remove todo
heueristik Feb 6, 2024
277e8f6
test: remove redundant expect
heueristik Feb 6, 2024
0299d35
fix: use unknown instead of any
heueristik Feb 6, 2024
34490d7
fix: imports
heueristik Feb 6, 2024
c5e5b39
fix: wrong type
heueristik Feb 6, 2024
a5520e0
fix: import
heueristik Feb 6, 2024
ded453a
fix: import
heueristik Feb 6, 2024
8d5c04b
feat: use typechain binding
heueristik Feb 6, 2024
47a2991
refactor: deploy script simplification
heueristik Feb 6, 2024
ad06cb7
refactor: findPluginRepo and domain
heueristik Feb 7, 2024
aa9de1a
refactor: improve code, comments, and tests
heueristik Feb 7, 2024
ca32ccd
refactor: improved helpers
heueristik Feb 7, 2024
c98800b
style: fix linting issues
heueristik Feb 7, 2024
652a55d
chore: remove todos
heueristik Feb 7, 2024
9de4b30
revert: deletion of hashHelpers
heueristik Feb 7, 2024
0025388
feat: catch errors properly
heueristik Feb 7, 2024
32c87a6
refactor: folder structure
heueristik Feb 8, 2024
0d42043
refactor: help gh to track files
heueristik Feb 8, 2024
090b594
refactor: help gh to track files
heueristik Feb 8, 2024
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
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# GENERAL

## The network used for testing purposes
NETWORK_NAME="mainnet" # ["mainnet", "goerli", "sepolia", "polygon", "polygonMumbai", "base", "baseGoerli", "arbitrum", "arbitrumGoerli"]
NETWORK_NAME="sepolia" # ["mainnet", "sepolia", "polygon", "polygonMumbai", "base", "baseSepolia", "arbitrum", "arbitrumSepolia"]

# CONTRACTS

## Hex encoded private keys separated by a comma `,`a
## One or multiple hex encoded private keys separated by commas `,` replacing the hardhat default accounts.
PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" # Default hardhat account 0 private key. DON'T USE FOR DEPLOYMENTS

## Infura credentials
Expand Down
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

plugin-info-testing.json

packages/subgraph/deploy-output.txt
packages/subgraph/subgraph.yaml
packages/subgraph/tests/.latest.json
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/.solcover.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
istanbulReporter: ['html', 'lcov'],
istanbulReporter: ['html', 'lcov', 'text'],
providerOptions: {
privateKey: process.env.PRIVATE_KEY,
},
skipFiles: ['test'],
skipFiles: ['mocks'],
};
45 changes: 41 additions & 4 deletions packages/contracts/deploy/00_info/01_account_info.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
import {
AragonOSxAsciiArt,
getProductionNetworkName,
isLocal,
} from '../../utils/helpers';
import {getNetworkByNameOrAlias} from '@aragon/osx-commons-configs';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';

/**
* Prints information about the used/forked network and initial deployer wallet balance.
* @param {HardhatRuntimeEnvironment} hre
*/
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(AragonOSxAsciiArt);
console.log(`${'-'.repeat(60)}`);
console.log(`\n✨ ${path.basename(__filename)}:`);

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

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

// Fork the network provided in the `.env` file
const networkConfig = getNetworkByNameOrAlias(productionNetworkName)!;
await hre.network.provider.request({
method: 'hardhat_reset',
params: [
{
forking: {
jsonRpcUrl: networkConfig.url,
},
},
],
});
} else {
console.log(`Production deployment on network '${hre.network.name}'.`);
}

console.log(
`Using account "${
`Using account '${
deployer.address
}" with a balance of ${hre.ethers.utils.formatEther(
}' with a balance of ${hre.ethers.utils.formatEther(
await deployer.getBalance()
)} for deployment...`
)} native tokens.`
);
};

export default func;
func.tags = ['Info', 'Deployment'];
func.tags = ['Info', 'CreateRepo', 'NewVersion', 'UpgradeRepo'];
135 changes: 73 additions & 62 deletions packages/contracts/deploy/01_repo/10_create_repo.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,113 @@
import {PLUGIN_REPO_ENS_NAME} from '../../plugin-settings';
import {ENS__factory} from '../../typechain';
import {PluginRepoRegisteredEvent} from '../../typechain/@aragon/osx/framework/plugin/repo/PluginRepoRegistry';
import {PLUGIN_REPO_ENS_SUBDOMAIN_NAME} from '../../plugin-settings';
import {
findEventTopicLog,
addDeployedRepo as addCreatedRepo,
getPluginRepoFactoryAddress,
getPluginRepoRegistryAddress,
findPluginRepo,
getProductionNetworkName,
pluginEnsDomain,
} from '../../utils/helpers';
import {
PluginRepoFactory__factory,
getLatestNetworkDeployment,
getNetworkNameByAlias,
} from '@aragon/osx-commons-configs';
import {
UnsupportedNetworkError,
findEventTopicLog,
} from '@aragon/osx-commons-sdk';
import {
PluginRepoRegistryEvents,
PluginRepoRegistry__factory,
PluginRepo__factory,
ENSSubdomainRegistrar__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';

/**
* Creates a plugin repo under Aragon's ENS base domain with subdomain requested in the `./plugin-settings.ts` file.
* @param {HardhatRuntimeEnvironment} hre
*/
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`\nDeploying the "${PLUGIN_REPO_ENS_NAME}" plugin repo`);
console.log(
`Creating the '${pluginEnsDomain(
hre
)}' plugin repo through Aragon's 'PluginRepoFactory'...`
);

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

// Get the PluginRepoFactory address
const pluginRepoFactoryAddr: string = getPluginRepoFactoryAddress(
network.name
);

// 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}.`;
}
const pluginRepoFactory = PluginRepoFactory__factory.connect(
pluginRepoFactoryAddr,
networkDeployments.PluginRepoFactory.address,
deployer
);

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

const eventLog = await findEventTopicLog<PluginRepoRegisteredEvent>(
tx,
PluginRepoRegistry__factory.createInterface(),
'PluginRepoRegistered'
);
if (!eventLog) {
throw new Error('Failed to get PluginRepoRegistered event log');
}
// Get the PluginRepo address and deployment block number from the txn and event therein
const eventLog =
await findEventTopicLog<PluginRepoRegistryEvents.PluginRepoRegisteredEvent>(
tx,
PluginRepoRegistry__factory.createInterface(),
'PluginRepoRegistered'
);

const pluginRepo = PluginRepo__factory.connect(
eventLog.args.pluginRepo,
deployer
);

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

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

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

export default func;
func.tags = ['PluginRepo', 'Deployment'];
func.skip = async (hre: HardhatRuntimeEnvironment) => {
// Skip plugin repo creation if the ENS name is taken already
func.tags = ['CreateRepo'];

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

const pluginRepoRegistry = PluginRepoRegistry__factory.connect(
getPluginRepoRegistryAddress(hre.network.name),
deployer
);
/**
* Skips `PluginRepo` creation if the ENS name is claimed already
* @param {HardhatRuntimeEnvironment} hre
*/
func.skip = async (hre: HardhatRuntimeEnvironment) => {
console.log(`\n🏗️ ${path.basename(__filename)}:`);

const registrar = ENSSubdomainRegistrar__factory.connect(
await pluginRepoRegistry.subdomainRegistrar(),
deployer
);
// Check if the ens record exists already
const {pluginRepo, ensDomain} = await findPluginRepo(hre);

const ens = ENS__factory.connect(await registrar.ens(), deployer);
if (pluginRepo !== null) {
console.log(
`ENS name '${ensDomain}' was claimed already at '${
pluginRepo.address
}' on network '${getProductionNetworkName(hre)}'. Skipping deployment...`
);

const recordExists = await ens.recordExists(
ethers.utils.namehash(`${PLUGIN_REPO_ENS_NAME}.plugin.dao.eth`)
);
hre.aragonToVerifyContracts.push({
address: pluginRepo.address,
args: [],
});

console.log(
`ENS name ${PLUGIN_REPO_ENS_NAME}.plugin.dao.eth does ${
recordExists ? 'exist already' : 'not exist yet'
}`
);
return true;
} else {
console.log(`ENS name '${ensDomain}' is unclaimed. Deploying...`);

return recordExists;
return false;
}
};
9 changes: 7 additions & 2 deletions packages/contracts/deploy/02_setup/10_setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import {PLUGIN_SETUP_CONTRACT_NAME} from '../../plugin-settings';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import path from 'path';

/**
* Deploys the plugin setup contract with the plugin implementation inside.
* @param {HardhatRuntimeEnvironment} hre
*/
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`\nDeploying ${PLUGIN_SETUP_CONTRACT_NAME}`);
console.log(`\n🏗️ ${path.basename(__filename)}:`);

const {deployments, getNamedAccounts} = hre;
const {deploy} = deployments;
Expand All @@ -17,4 +22,4 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
};

export default func;
func.tags = [PLUGIN_SETUP_CONTRACT_NAME, 'Deployment'];
func.tags = [PLUGIN_SETUP_CONTRACT_NAME, 'NewVersion', 'Deployment'];
26 changes: 14 additions & 12 deletions packages/contracts/deploy/02_setup/11_setup_conclude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@ import {PLUGIN_SETUP_CONTRACT_NAME} from '../../plugin-settings';
import {MyPluginSetup__factory, MyPlugin__factory} from '../../typechain';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';
import {setTimeout} from 'timers/promises';
import path from 'path';

/**
* Concludes the plugin setup and implementation contract deployment by queuing the addresses in the verification array.
* @param {HardhatRuntimeEnvironment} hre
*/
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`Concluding ${PLUGIN_SETUP_CONTRACT_NAME} deployment.\n`);
const [deployer] = await hre.ethers.getSigners();
console.log(`\n🔎 ${path.basename(__filename)}:`);
console.log(`Concluding '${PLUGIN_SETUP_CONTRACT_NAME}' deployment.`);

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

// Get the plugin setup address
const setupDeployment = await deployments.get(PLUGIN_SETUP_CONTRACT_NAME);
const setup = MyPluginSetup__factory.connect(
setupDeployment.address,
deployer
);
// Get the plugin implementation address
const implementation = MyPlugin__factory.connect(
await setup.implementation(),
deployer
);

// Add a timeout for polygon because the call to `implementation()` can fail for newly deployed contracts in the first few seconds
if (network.name === 'polygon') {
console.log(`Waiting 30secs for ${network.name} to finish up...`);
await setTimeout(30000);
}

// Queue the plugin setup and implementation for verification on the block explorers
hre.aragonToVerifyContracts.push({
address: setupDeployment.address,
address: setup.address,
args: setupDeployment.args,
});
hre.aragonToVerifyContracts.push({
Expand All @@ -37,4 +39,4 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
};

export default func;
func.tags = [PLUGIN_SETUP_CONTRACT_NAME, 'Verification'];
func.tags = [PLUGIN_SETUP_CONTRACT_NAME, 'NewVersion', 'Verification'];
Loading
Loading