Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 1aa74e9

Browse files
authored
Feat: get deploymet needed addresses from env vars (#67)
* feat: add needed env vars to env example file * feat: define needed helper functions * feat: modify the create repo script to get the needed addresses from the env files * ci: remove not needed imports * feat: store the plugin repo proxy in the deployments * feat: get the addresses needed from the env vars * feat: add note in the env example files * fix: publish placeholder * fix: find repo helper function * try * feat: remove getting te addresses from commons config * fix lint * feat: define the needed env vars in the workflow * ci: add comments to the env variables to explain why and when they are used * Update packages/contracts/utils/helpers.ts
1 parent 4b97f56 commit 1aa74e9

File tree

7 files changed

+219
-80
lines changed

7 files changed

+219
-80
lines changed

.env.example

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# GENERAL
22

33
## The network used for testing purposes
4-
NETWORK_NAME="sepolia" # ["mainnet", "sepolia", "polygon", "baseMainnet", "arbitrum"]
4+
NETWORK_NAME="sepolia" # ["mainnet", "sepolia", "polygon"]
55

66
## To upload the metadata for deployed contracts
77
PUB_PINATA_JWT=
@@ -24,12 +24,22 @@ POLYGONSCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
2424
BASESCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
2525
ARBISCAN_API_KEY="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
2626

27-
# SUBGRAPH
27+
## Deployment addresses
28+
# Note that addresses will be also used for testing so ensure they are valid on the network you are running the forking tests on.
2829

29-
## The Graph credentials
30-
GRAPH_KEY="zzzzzzzzzzzz"
30+
# optional, address if not provided will get it from the latest deployment on the network or from the ens registrar
31+
# defined in the framework if it supports it. In case it is not found will create a new one.
32+
PLUGIN_REPO_ADDRESS=0x0000000000000000000000000000000000000000
33+
# not optional, if not provided will not be able to deploy the plugin or run the forking tests.
34+
PLUGIN_REPO_FACTORY_ADDRESS=0x0000000000000000000000000000000000000000
35+
# optional, only needed when a latest versions of the plugin are going to be deploy on a new network.
36+
PLACEHOLDER_SETUP=0x0000000000000000000000000000000000000000
37+
# not optional, if not provided will not be able to transfer the ownership of the plugin when deploying
38+
# the plugin or running the forking tests.
39+
MANAGEMENT_DAO_ADDRESS=0x0000000000000000000000000000000000000000
3140

3241
## Subgraph
42+
GRAPH_KEY="zzzzzzzzzzzz"
3343
SUBGRAPH_NAME="osx"
3444
SUBGRAPH_VERSION="v1.0.0"
3545
SUBGRAPH_NETWORK_NAME="mainnet" # ["mainnet", "sepolia", "polygon", "base", "arbitrum"]

.github/workflows/contracts-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ jobs:
3737
run: 'yarn coverage'
3838
env:
3939
NETWORK_NAME: ${{ vars.NETWORK_NAME }}
40+
PLUGIN_REPO_FACTORY_ADDRESS: ${{ vars.PLUGIN_REPO_FACTORY_ADDRESS }}
41+
MANAGEMENT_DAO_ADDRESS: ${{ vars.MANAGEMENT_DAO_ADDRESS }}
4042
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}

packages/contracts/deploy/10_create_repo/11_create_repo.ts

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
import {PLUGIN_REPO_ENS_SUBDOMAIN_NAME} from '../../plugin-settings';
1+
import {
2+
PLUGIN_REPO_ENS_SUBDOMAIN_NAME,
3+
PLUGIN_REPO_PROXY_NAME,
4+
} from '../../plugin-settings';
25
import {
36
findPluginRepo,
47
getProductionNetworkName,
58
pluginEnsDomain,
9+
getPluginRepoFactory,
10+
frameworkSupportsENS,
611
} from '../../utils/helpers';
7-
import {
8-
getLatestNetworkDeployment,
9-
getNetworkNameByAlias,
10-
} from '@aragon/osx-commons-configs';
11-
import {
12-
UnsupportedNetworkError,
13-
findEventTopicLog,
14-
} from '@aragon/osx-commons-sdk';
12+
import {findEventTopicLog} from '@aragon/osx-commons-sdk';
1513
import {
1614
PluginRepoRegistryEvents,
1715
PluginRepoRegistry__factory,
1816
PluginRepo__factory,
19-
PluginRepoFactory__factory,
2017
} from '@aragon/osx-ethers';
2118
import {DeployFunction} from 'hardhat-deploy/types';
2219
import {HardhatRuntimeEnvironment} from 'hardhat/types';
@@ -27,32 +24,21 @@ import path from 'path';
2724
* @param {HardhatRuntimeEnvironment} hre
2825
*/
2926
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
30-
console.log(
31-
`Creating the '${pluginEnsDomain(
32-
hre
33-
)}' plugin repo through Aragon's 'PluginRepoFactory'...`
34-
);
27+
console.log(`Creating plugin repo through Aragon's 'PluginRepoFactory'...`);
3528

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

38-
// Get the Aragon `PluginRepoFactory` from the `osx-commons-configs`
39-
const productionNetworkName = getProductionNetworkName(hre);
40-
const network = getNetworkNameByAlias(productionNetworkName);
41-
if (network === null) {
42-
throw new UnsupportedNetworkError(productionNetworkName);
43-
}
44-
const networkDeployments = getLatestNetworkDeployment(network);
45-
if (networkDeployments === null) {
46-
throw `Deployments are not available on network ${network}.`;
47-
}
48-
const pluginRepoFactory = PluginRepoFactory__factory.connect(
49-
networkDeployments.PluginRepoFactory.address,
50-
deployer
51-
);
31+
// Get the Aragon `PluginRepoFactory`
32+
const pluginRepoFactory = await getPluginRepoFactory(hre);
33+
34+
// if the framework supports ENS, use the subdomain from the `./plugin-settings.ts` file
35+
// otherwise, use an empty string
36+
const supportsENS = await frameworkSupportsENS(pluginRepoFactory);
37+
const subdomain = supportsENS ? PLUGIN_REPO_ENS_SUBDOMAIN_NAME : '';
5238

5339
// Create the `PluginRepo` through the Aragon `PluginRepoFactory`
5440
const tx = await pluginRepoFactory.createPluginRepo(
55-
PLUGIN_REPO_ENS_SUBDOMAIN_NAME,
41+
subdomain,
5642
deployer.address
5743
);
5844

@@ -69,8 +55,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
6955
deployer
7056
);
7157

58+
// Save the plugin repo deployment
59+
await hre.deployments.save(PLUGIN_REPO_PROXY_NAME, {
60+
abi: PluginRepo__factory.abi,
61+
address: pluginRepo.address,
62+
receipt: await tx.wait(),
63+
transactionHash: tx.hash,
64+
});
65+
7266
console.log(
73-
`PluginRepo '${pluginEnsDomain(hre)}' deployed at '${pluginRepo.address}'.`
67+
`PluginRepo ${
68+
supportsENS ? 'with ens:' + pluginEnsDomain(hre) : 'without ens'
69+
} deployed at '${pluginRepo.address}'.`
7470
);
7571

7672
hre.aragonToVerifyContracts.push({
@@ -90,11 +86,11 @@ func.skip = async (hre: HardhatRuntimeEnvironment) => {
9086
console.log(`\n🏗️ ${path.basename(__filename)}:`);
9187

9288
// Check if the ens record exists already
93-
const {pluginRepo, ensDomain} = await findPluginRepo(hre);
89+
const {pluginRepo} = await findPluginRepo(hre);
9490

9591
if (pluginRepo !== null) {
9692
console.log(
97-
`ENS name '${ensDomain}' was claimed already at '${
93+
`Plugin Repo already deployed at '${
9894
pluginRepo.address
9995
}' on network '${getProductionNetworkName(hre)}'. Skipping deployment...`
10096
);
@@ -106,7 +102,7 @@ func.skip = async (hre: HardhatRuntimeEnvironment) => {
106102

107103
return true;
108104
} else {
109-
console.log(`ENS name '${ensDomain}' is unclaimed. Deploying...`);
105+
console.log('Deploying Plugin Repo');
110106

111107
return false;
112108
}

packages/contracts/deploy/20_new_version/23_publish.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
impersonatedManagementDaoSigner,
1111
isLocal,
1212
pluginEnsDomain,
13+
isValidAddress,
14+
publishPlaceholderVersion,
1315
} from '../../utils/helpers';
1416
import {pluginSetupContractName} from '../helpers';
1517
import {PLUGIN_REPO_PERMISSIONS, uploadToPinata} from '@aragon/osx-commons-sdk';
@@ -79,18 +81,24 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
7981

8082
// Check build number
8183
const latestBuild = (await pluginRepo.buildCount(VERSION.release)).toNumber();
82-
if (VERSION.build < latestBuild) {
83-
throw Error(
84-
`Publishing with build number ${VERSION.build} is not possible. The latest build is ${latestBuild}. Aborting publication...`
85-
);
86-
}
87-
if (VERSION.build > latestBuild + 1) {
88-
throw Error(
89-
`Publishing with build number ${VERSION.build} is not possible.
84+
if (latestBuild == 0 && VERSION.build > 1) {
85+
// it means there's no build yet on the repo on the specific VERSION.release
86+
// and build version in the plugin settings is > 1, meaning that
87+
// it must push placeholder contracts and as the last one, push the actual plugin setup.
88+
} else {
89+
if (VERSION.build < latestBuild) {
90+
throw Error(
91+
`Publishing with build number ${VERSION.build} is not possible. The latest build is ${latestBuild}. Aborting publication...`
92+
);
93+
}
94+
if (VERSION.build > latestBuild + 1) {
95+
throw Error(
96+
`Publishing with build number ${VERSION.build} is not possible.
9097
The latest build is ${latestBuild} and the next release you can publish is release number ${
91-
latestBuild + 1
92-
}. Aborting publication...`
93-
);
98+
latestBuild + 1
99+
}. Aborting publication...`
100+
);
101+
}
94102
}
95103

96104
if (setup == undefined || setup?.receipt == undefined) {
@@ -120,6 +128,25 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
120128
[]
121129
)
122130
) {
131+
if (latestBuild == 0 && VERSION.build > 1) {
132+
// We are publishing the first version as build > 1.
133+
// So we need to publish placeholders first..
134+
const placeholderSetup = process.env.PLACEHOLDER_SETUP;
135+
136+
if (!placeholderSetup || !isValidAddress(placeholderSetup)) {
137+
throw new Error(
138+
'Aborting. Placeholder setup not defined in .env or is not a valid address (is not an address or is address zero)'
139+
);
140+
}
141+
await publishPlaceholderVersion(
142+
placeholderSetup,
143+
VERSION.build,
144+
VERSION.release,
145+
pluginRepo,
146+
signer
147+
);
148+
}
149+
123150
// Create the new version
124151
const tx = await pluginRepo
125152
.connect(signer)

packages/contracts/deploy/30_upgrade_repo/_common.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import {findPluginRepo, getProductionNetworkName} from '../../utils/helpers';
21
import {
3-
getLatestNetworkDeployment,
4-
getNetworkNameByAlias,
5-
} from '@aragon/osx-commons-configs';
2+
findPluginRepo,
3+
getProductionNetworkName,
4+
getPluginRepoFactory,
5+
} from '../../utils/helpers';
6+
import {getNetworkNameByAlias} from '@aragon/osx-commons-configs';
67
import {UnsupportedNetworkError} from '@aragon/osx-commons-sdk';
78
import {PluginRepo, PluginRepo__factory} from '@aragon/osx-ethers';
89
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
@@ -30,10 +31,6 @@ export async function fetchData(
3031
if (network === null) {
3132
throw new UnsupportedNetworkError(productionNetworkName);
3233
}
33-
const networkDeployments = getLatestNetworkDeployment(network);
34-
if (networkDeployments === null) {
35-
throw `Deployments are not available on network ${network}.`;
36-
}
3734

3835
// Get PluginRepo
3936
const {pluginRepo, ensDomain} = await findPluginRepo(hre);
@@ -46,8 +43,10 @@ export async function fetchData(
4643
);
4744

4845
// Get the latest `PluginRepo` implementation as the upgrade target
46+
const pluginRepoFactory = await getPluginRepoFactory(hre);
47+
4948
const latestPluginRepoImplementation = PluginRepo__factory.connect(
50-
networkDeployments.PluginRepoBase.address,
49+
await pluginRepoFactory.pluginRepoBase(),
5150
deployer
5251
);
5352

packages/contracts/plugin-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {GovernanceERC20} from './test/test-utils/typechain-versions';
44
import {VersionTag} from '@aragon/osx-commons-sdk';
55
import {ethers} from 'hardhat';
66

7+
export const PLUGIN_REPO_PROXY_NAME = 'TokenVotingProxy';
78
export const PLUGIN_CONTRACT_NAME = 'TokenVoting'; // This must match the filename `packages/contracts/src/MyPlugin.sol` and the contract name `MyPlugin` within.
89
export const PLUGIN_SETUP_CONTRACT_NAME = 'TokenVotingSetup'; // This must match the filename `packages/contracts/src/MyPluginSetup.sol` and the contract name `MyPluginSetup` within.
910
export const PLUGIN_SETUP_CONTRACT_NAME_ZKSYNC = 'TokenVotingSetupZkSync';

0 commit comments

Comments
 (0)