Skip to content

Commit 02fe406

Browse files
authored
Merge pull request #54 from immutable/feat/SMR-2372
Added a script so we can grant the executor role to MultiCallDeploy
2 parents cdae5bb + 2bdbea4 commit 02fe406

7 files changed

Lines changed: 145 additions & 7 deletions

File tree

hardhat.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ const config: HardhatUserConfig = {
3535
// Define here to easily specify private keys
3636
localhost: {
3737
url: 'http://127.0.0.1:8545',
38-
accounts: [process.env.DEPLOYER_PRIV_KEY!, process.env.WALLET_IMPL_CHANGER_PRIV_KEY!]
38+
accounts: []
3939
},
4040
devnet: {
4141
url: 'https://rpc.dev.immutable.com',
42-
accounts: [process.env.DEPLOYER_PRIV_KEY!, process.env.WALLET_IMPL_CHANGER_PRIV_KEY!]
42+
accounts: []
4343
},
4444
testnet: {
4545
url: 'https://rpc.testnet.immutable.com',
46-
accounts: [process.env.DEPLOYER_PRIV_KEY!, process.env.WALLET_IMPL_CHANGER_PRIV_KEY!]
46+
accounts: []
4747
},
4848
mainnet: {
4949
url: 'https://rpc.immutable.com',
50-
accounts: [process.env.DEPLOYER_PRIV_KEY!, process.env.WALLET_IMPL_CHANGER_PRIV_KEY!]
50+
accounts: []
5151
},
5252
},
5353
mocha: {

package-lock.json

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"hardhat": "2.12.2",
7575
"hardhat-gas-reporter": "^1.0.9",
7676
"husky": "^4.2.3",
77+
"prompt-sync": "^4.2.0",
7778
"rimraf": "^3.0.2",
7879
"solhint": "^3.3.4",
7980
"solidity-coverage": "^0.8.5",
@@ -96,4 +97,4 @@
9697
"ethereum-private-key-to-public-key": "^0.0.5",
9798
"ethereum-public-key-to-address": "^0.0.5"
9899
}
99-
}
100+
}

scripts/environment.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface EnvironmentInfo {
99
signerAddress: string;
1010
deployerContractAddress: string;
1111
network: string;
12+
multiCallDeployContractAddress: string;
1213
}
1314

1415
/**
@@ -24,6 +25,7 @@ export function loadEnvironmentInfo(hreNetworkName: string): EnvironmentInfo {
2425
submitterAddress: process.env.RELAYER_SUBMITTER_EOA_PUB_KEY || '',
2526
signerAddress: process.env.IMMUTABLE_SIGNER_PUB_KEY || '',
2627
deployerContractAddress: process.env.DEPLOYER_CONTRACT_ADDRESS || '',
27-
network: hreNetworkName
28+
network: hreNetworkName,
29+
multiCallDeployContractAddress: process.env.MULTICALLDEPLOY_CONTRACT_ADDRESS || '',
2830
};
2931
}

scripts/grant-executor-role.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as hre from 'hardhat';
2+
import { Contract, ContractFactory, ContractFunction, Transaction } from 'ethers';
3+
import promptSync from 'prompt-sync';
4+
5+
import { EnvironmentInfo, loadEnvironmentInfo } from './environment';
6+
import { newContractFactory, waitForInput } from './helper-functions';
7+
import { newWalletOptions, WalletOptions } from './wallet-options';
8+
9+
/**
10+
* GrantExecutorRole grants the `EXECUTOR` role to a given address. This function can only
11+
* be invoked by the wallet with the `DEFAULT_ADMIN_ROLE` role.
12+
**/
13+
async function grantExecutorRole(): Promise<EnvironmentInfo> {
14+
const env = loadEnvironmentInfo(hre.network.name);
15+
const { network, multiCallDeployContractAddress } = env;
16+
const prompt = promptSync();
17+
18+
// Setup wallet with default admin role
19+
const wallets: WalletOptions = await newWalletOptions(env);
20+
21+
// Attach to contract
22+
const contractName = "MultiCallDeploy";
23+
const contractFactory: ContractFactory = await newContractFactory(wallets.getWallet(), contractName);
24+
25+
console.log(`[${network}] Confirm contract address ${multiCallDeployContractAddress} ...`);
26+
const multiCallDeploy: Contract = await contractFactory.attach(multiCallDeployContractAddress);
27+
28+
// Obtain the executor role reference
29+
const executorRole = await multiCallDeploy.EXECUTOR_ROLE();
30+
console.log(`[${network}] Executor role ${executorRole}`);
31+
32+
const newAddress = prompt(`[${network}] New address to be added to the executor role: `);
33+
console.log(`[${network}] Confirm new address ${newAddress} ...`);
34+
35+
await waitForInput();
36+
37+
// Only grant the role if the wallet does not already have access to this to this role.
38+
const isExecutor = await multiCallDeploy.hasRole(executorRole, newAddress.trim());
39+
if (!isExecutor) {
40+
const tx = await multiCallDeploy.grantExecutorRole(newAddress.trim());
41+
await tx.wait();
42+
console.log(`[${network}] Executor role granted to ${newAddress}`);
43+
} else {
44+
console.log(`[${network}] ${newAddress} already has the executor role`);
45+
}
46+
47+
return env;
48+
}
49+
50+
// Call primary function
51+
grantExecutorRole()
52+
.then((env: EnvironmentInfo) => {
53+
console.log(`[${env.network}] Grant successful...`);
54+
process.exit(0);
55+
})
56+
.catch(err => {
57+
console.error(err.message);
58+
process.exit(1);
59+
});

scripts/wallet-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class WalletOptions {
1919
constructor(env: EnvironmentInfo, coldWallet: Signer, walletImplLocatorImplChanger: Signer) {
2020
console.log(`[${env.network}] Using ledger for operations...`);
2121
this.useLedger = true;
22-
const accountIndex0 = 10;
22+
const accountIndex0 = 0;
2323
const derivationPath0 = `m/44'/60'/${accountIndex0.toString()}'/0/0`;
2424
this.ledger = new LedgerSigner(hardhat.provider, derivationPath0);
2525

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,11 @@
18241824
"resolved" "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz"
18251825
"version" "3.0.1"
18261826

1827+
"ansi-regex@^4.1.0":
1828+
"integrity" "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g=="
1829+
"resolved" "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz"
1830+
"version" "4.1.1"
1831+
18271832
"ansi-regex@^5.0.1":
18281833
"integrity" "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="
18291834
"resolved" "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz"
@@ -6819,6 +6824,13 @@
68196824
dependencies:
68206825
"asap" "~2.0.6"
68216826

6827+
"prompt-sync@^4.2.0":
6828+
"integrity" "sha512-BuEzzc5zptP5LsgV5MZETjDaKSWfchl5U9Luiu8SKp7iZWD5tZalOxvNcZRwv+d2phNFr8xlbxmFNcRKfJOzJw=="
6829+
"resolved" "https://registry.npmjs.org/prompt-sync/-/prompt-sync-4.2.0.tgz"
6830+
"version" "4.2.0"
6831+
dependencies:
6832+
"strip-ansi" "^5.0.0"
6833+
68226834
"prompts@^2.4.2":
68236835
"integrity" "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q=="
68246836
"resolved" "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz"
@@ -7858,6 +7870,13 @@
78587870
dependencies:
78597871
"ansi-regex" "^3.0.0"
78607872

7873+
"strip-ansi@^5.0.0":
7874+
"integrity" "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA=="
7875+
"resolved" "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz"
7876+
"version" "5.2.0"
7877+
dependencies:
7878+
"ansi-regex" "^4.1.0"
7879+
78617880
"strip-ansi@^6.0.0", "strip-ansi@^6.0.1":
78627881
"integrity" "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="
78637882
"resolved" "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"

0 commit comments

Comments
 (0)