Skip to content

Commit

Permalink
Merge pull request #54 from immutable/feat/SMR-2372
Browse files Browse the repository at this point in the history
Added a script so we can grant the executor role to MultiCallDeploy
  • Loading branch information
shirren authored Feb 20, 2024
2 parents cdae5bb + 2bdbea4 commit 02fe406
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 7 deletions.
8 changes: 4 additions & 4 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ const config: HardhatUserConfig = {
// Define here to easily specify private keys
localhost: {
url: 'http://127.0.0.1:8545',
accounts: [process.env.DEPLOYER_PRIV_KEY!, process.env.WALLET_IMPL_CHANGER_PRIV_KEY!]
accounts: []
},
devnet: {
url: 'https://rpc.dev.immutable.com',
accounts: [process.env.DEPLOYER_PRIV_KEY!, process.env.WALLET_IMPL_CHANGER_PRIV_KEY!]
accounts: []
},
testnet: {
url: 'https://rpc.testnet.immutable.com',
accounts: [process.env.DEPLOYER_PRIV_KEY!, process.env.WALLET_IMPL_CHANGER_PRIV_KEY!]
accounts: []
},
mainnet: {
url: 'https://rpc.immutable.com',
accounts: [process.env.DEPLOYER_PRIV_KEY!, process.env.WALLET_IMPL_CHANGER_PRIV_KEY!]
accounts: []
},
},
mocha: {
Expand Down
57 changes: 57 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"hardhat": "2.12.2",
"hardhat-gas-reporter": "^1.0.9",
"husky": "^4.2.3",
"prompt-sync": "^4.2.0",
"rimraf": "^3.0.2",
"solhint": "^3.3.4",
"solidity-coverage": "^0.8.5",
Expand All @@ -96,4 +97,4 @@
"ethereum-private-key-to-public-key": "^0.0.5",
"ethereum-public-key-to-address": "^0.0.5"
}
}
}
4 changes: 3 additions & 1 deletion scripts/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface EnvironmentInfo {
signerAddress: string;
deployerContractAddress: string;
network: string;
multiCallDeployContractAddress: string;
}

/**
Expand All @@ -24,6 +25,7 @@ export function loadEnvironmentInfo(hreNetworkName: string): EnvironmentInfo {
submitterAddress: process.env.RELAYER_SUBMITTER_EOA_PUB_KEY || '',
signerAddress: process.env.IMMUTABLE_SIGNER_PUB_KEY || '',
deployerContractAddress: process.env.DEPLOYER_CONTRACT_ADDRESS || '',
network: hreNetworkName
network: hreNetworkName,
multiCallDeployContractAddress: process.env.MULTICALLDEPLOY_CONTRACT_ADDRESS || '',
};
}
59 changes: 59 additions & 0 deletions scripts/grant-executor-role.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as hre from 'hardhat';
import { Contract, ContractFactory, ContractFunction, Transaction } from 'ethers';
import promptSync from 'prompt-sync';

import { EnvironmentInfo, loadEnvironmentInfo } from './environment';
import { newContractFactory, waitForInput } from './helper-functions';
import { newWalletOptions, WalletOptions } from './wallet-options';

/**
* GrantExecutorRole grants the `EXECUTOR` role to a given address. This function can only
* be invoked by the wallet with the `DEFAULT_ADMIN_ROLE` role.
**/
async function grantExecutorRole(): Promise<EnvironmentInfo> {
const env = loadEnvironmentInfo(hre.network.name);
const { network, multiCallDeployContractAddress } = env;
const prompt = promptSync();

// Setup wallet with default admin role
const wallets: WalletOptions = await newWalletOptions(env);

// Attach to contract
const contractName = "MultiCallDeploy";
const contractFactory: ContractFactory = await newContractFactory(wallets.getWallet(), contractName);

console.log(`[${network}] Confirm contract address ${multiCallDeployContractAddress} ...`);
const multiCallDeploy: Contract = await contractFactory.attach(multiCallDeployContractAddress);

// Obtain the executor role reference
const executorRole = await multiCallDeploy.EXECUTOR_ROLE();
console.log(`[${network}] Executor role ${executorRole}`);

const newAddress = prompt(`[${network}] New address to be added to the executor role: `);
console.log(`[${network}] Confirm new address ${newAddress} ...`);

await waitForInput();

// Only grant the role if the wallet does not already have access to this to this role.
const isExecutor = await multiCallDeploy.hasRole(executorRole, newAddress.trim());
if (!isExecutor) {
const tx = await multiCallDeploy.grantExecutorRole(newAddress.trim());
await tx.wait();
console.log(`[${network}] Executor role granted to ${newAddress}`);
} else {
console.log(`[${network}] ${newAddress} already has the executor role`);
}

return env;
}

// Call primary function
grantExecutorRole()
.then((env: EnvironmentInfo) => {
console.log(`[${env.network}] Grant successful...`);
process.exit(0);
})
.catch(err => {
console.error(err.message);
process.exit(1);
});
2 changes: 1 addition & 1 deletion scripts/wallet-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class WalletOptions {
constructor(env: EnvironmentInfo, coldWallet: Signer, walletImplLocatorImplChanger: Signer) {
console.log(`[${env.network}] Using ledger for operations...`);
this.useLedger = true;
const accountIndex0 = 10;
const accountIndex0 = 0;
const derivationPath0 = `m/44'/60'/${accountIndex0.toString()}'/0/0`;
this.ledger = new LedgerSigner(hardhat.provider, derivationPath0);

Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,11 @@
"resolved" "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz"
"version" "3.0.1"

"ansi-regex@^4.1.0":
"integrity" "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g=="
"resolved" "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz"
"version" "4.1.1"

"ansi-regex@^5.0.1":
"integrity" "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="
"resolved" "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz"
Expand Down Expand Up @@ -6819,6 +6824,13 @@
dependencies:
"asap" "~2.0.6"

"prompt-sync@^4.2.0":
"integrity" "sha512-BuEzzc5zptP5LsgV5MZETjDaKSWfchl5U9Luiu8SKp7iZWD5tZalOxvNcZRwv+d2phNFr8xlbxmFNcRKfJOzJw=="
"resolved" "https://registry.npmjs.org/prompt-sync/-/prompt-sync-4.2.0.tgz"
"version" "4.2.0"
dependencies:
"strip-ansi" "^5.0.0"

"prompts@^2.4.2":
"integrity" "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q=="
"resolved" "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz"
Expand Down Expand Up @@ -7858,6 +7870,13 @@
dependencies:
"ansi-regex" "^3.0.0"

"strip-ansi@^5.0.0":
"integrity" "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA=="
"resolved" "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz"
"version" "5.2.0"
dependencies:
"ansi-regex" "^4.1.0"

"strip-ansi@^6.0.0", "strip-ansi@^6.0.1":
"integrity" "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="
"resolved" "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz"
Expand Down

0 comments on commit 02fe406

Please sign in to comment.