Skip to content

Commit c775cbd

Browse files
committed
feat: add admin private key support for deployment and configuration
1 parent 60a3308 commit c775cbd

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

.github/workflows/sharing-smart-contract-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
# For Deployment
8585
RPC_URL: ${{ secrets.RPC_URL }}
8686
DEPLOYER_PRIVATE_KEY: ${{ secrets.DEPLOYER_PRIVATE_KEY }}
87+
ADMIN_PRIVATE_KEY: ${{ secrets.ADMIN_PRIVATE_KEY }}
8788
POCO_ADDRESS: ${{ vars.POCO_ADDRESS }}
8889
DATASET_REGISTRY_ADDRESS: ${{ vars.DATASET_REGISTRY_ADDRESS }}
8990
# For Verification

packages/sharing-smart-contract/config/env.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ const envSchema = z.object({
1515
.optional()
1616
.or(z.literal('')),
1717

18+
// Private key of the admin wallet used for proxy admin ownership
19+
ADMIN_PRIVATE_KEY: z
20+
.string()
21+
.regex(privateKeyRegex, 'Invalid private key format')
22+
.optional()
23+
.or(z.literal('')),
24+
1825
// environment to use for configuration (prod/staging)
1926
ENV: z.enum(['prod', 'staging'], 'ENV must be either "prod" or "staging"').default('prod'),
2027

packages/sharing-smart-contract/hardhat.config.cjs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ const bellecourBase = {
1414
hardfork: 'berlin',
1515
};
1616

17+
// Helper function to get accounts array with both deployer and admin keys
18+
function getAccounts() {
19+
const accounts = [];
20+
if (env.DEPLOYER_PRIVATE_KEY) {
21+
accounts.push(env.DEPLOYER_PRIVATE_KEY);
22+
}
23+
if (env.ADMIN_PRIVATE_KEY && env.ADMIN_PRIVATE_KEY !== env.DEPLOYER_PRIVATE_KEY) {
24+
accounts.push(env.ADMIN_PRIVATE_KEY);
25+
}
26+
return accounts.length > 0 ? accounts : [];
27+
}
28+
1729
/**
1830
* @type import('hardhat/config').HardhatUserConfig
1931
*/
@@ -35,30 +47,24 @@ module.exports = {
3547
bellecour: {
3648
...bellecourBase,
3749
url: 'https://bellecour.iex.ec',
38-
accounts: env.DEPLOYER_PRIVATE_KEY ? [env.DEPLOYER_PRIVATE_KEY] : [],
50+
accounts: getAccounts(),
3951
},
4052
avalancheFujiTestnet: {
4153
chainId: 43113,
4254
url: env.RPC_URL || 'https://api.avax-test.network/ext/bc/C/rpc',
43-
accounts: [
44-
env.DEPLOYER_PRIVATE_KEY ||
45-
'0x0000000000000000000000000000000000000000000000000000000000000000',
46-
],
55+
accounts: getAccounts(),
4756
blockGasLimit: 8_000_000,
4857
},
4958
arbitrumSepolia: {
5059
chainId: 421614,
5160
url: env.RPC_URL || 'https://sepolia-rollup.arbitrum.io/rpc',
52-
accounts: [
53-
env.DEPLOYER_PRIVATE_KEY ||
54-
'0x0000000000000000000000000000000000000000000000000000000000000000',
55-
],
61+
accounts: getAccounts(),
5662
blockGasLimit: 30_000_000,
5763
},
5864
arbitrum: {
5965
chainId: 42161,
6066
url: env.RPC_URL || 'https://arb1.arbitrum.io/rpc',
61-
accounts: env.DEPLOYER_PRIVATE_KEY ? [env.DEPLOYER_PRIVATE_KEY] : [],
67+
accounts: getAccounts(),
6268
blockGasLimit: 30_000_000,
6369
},
6470
// poco-chain native config

packages/sharing-smart-contract/ignition/modules/DataProtectorSharingModule.cjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const env = require('../../config/env.cjs');
1111

1212
// @ts-ignore
1313
module.exports = buildModule('DataProtectorSharingModule', (m) => {
14-
const proxyAdminOwner = m.getAccount(0);
14+
// Use admin private key if provided, otherwise fall back to the first account
15+
const proxyAdminOwner = env.ADMIN_PRIVATE_KEY
16+
? m.getAccount(env.ADMIN_PRIVATE_KEY)
17+
: m.getAccount(0);
1518
const pocoAddress = env.POCO_ADDRESS || defaultPocoAddress;
1619
const datasetRegistryAddress = env.DATASET_REGISTRY_ADDRESS || defaultDatasetRegistryAddress;
1720

packages/sharing-smart-contract/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"compile": "hardhat clean && hardhat compile && npm run artifact-to-abis",
1111
"verify:ignition": "hardhat ignition verify --include-unrelated-contracts",
1212
"verify": "hardhat verify",
13-
"deploy": "hardhat ignition deploy ignition/modules/DataProtectorSharingModule.cjs --strategy create2",
13+
"deploy": "hardhat run scripts/deploy.js",
1414
"update-env": "hardhat run ./scripts/updateEnv.js",
1515
"upgrade": "hardhat run ./scripts/upgrade.js",
1616
"upgrade-local-fork": "mkdir -p .openzeppelin/local-fork && cp -r .openzeppelin/prod/. .openzeppelin/local-fork && MANIFEST_DEFAULT_DIR=.openzeppelin/local-fork ENV=prod hardhat run ./scripts/upgrade-local-fork.js",

packages/sharing-smart-contract/scripts/deploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function main() {
4949
},
5050
);
5151
await upgrades.forceImport(
52-
await dataProtectorSharing.getAddress(),
52+
dpsProxyAddress,
5353
await ethers.getContractFactory('DataProtectorSharing'),
5454
{
5555
kind: 'transparent',

0 commit comments

Comments
 (0)