-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAcceptAdmin.s.sol
More file actions
54 lines (39 loc) · 2.49 KB
/
AcceptAdmin.s.sol
File metadata and controls
54 lines (39 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24 <0.9.0;
import {Script, console} from "lib/forge-std/src/Script.sol";
import {HelperUtils} from "../utils/HelperUtils.s.sol"; // Utility functions for JSON parsing and chain info
import {HelperConfig} from "../utils/HelperConfig.s.sol"; // Network configuration helper
import {TokenAdminRegistry} from "lib/ccip/contracts/src/v0.8/ccip/tokenAdminRegistry/TokenAdminRegistry.sol";
contract AcceptAdmin is Script {
function run() external {
// Get the chain name based on the current chain ID
string memory chainName = HelperUtils.getChainName(block.chainid);
// Construct the path to the deployed token JSON file
string memory root = vm.projectRoot();
string memory deployedTokenPath = string.concat(root, "/script/output/deployedToken_", chainName, ".json");
// Extract the deployed token address from the JSON file
address tokenAddress =
HelperUtils.getAddressFromJson(vm, deployedTokenPath, string.concat(".deployedToken_", chainName));
// Fetch the network configuration to get the TokenAdminRegistry address
HelperConfig helperConfig = new HelperConfig();
(,,, address tokenAdminRegistry,,,,) = helperConfig.activeNetworkConfig();
// Ensure the token address and TokenAdminRegistry address are valid
require(tokenAddress != address(0), "Invalid token address");
require(tokenAdminRegistry != address(0), "TokenAdminRegistry is not defined for this network");
vm.startBroadcast();
// Get the address of the signer (the account executing the script)
address signer = msg.sender;
// Instantiate the TokenAdminRegistry contract
TokenAdminRegistry tokenAdminRegistryContract = TokenAdminRegistry(tokenAdminRegistry);
// Fetch the token configuration for the given token address
TokenAdminRegistry.TokenConfig memory tokenConfig = tokenAdminRegistryContract.getTokenConfig(tokenAddress);
// Get the pending administrator for the token
address pendingAdministrator = tokenConfig.pendingAdministrator;
// Ensure the signer is the pending administrator
require(pendingAdministrator == signer, "Only the pending administrator can accept the admin role");
// Accept the admin role for the token
tokenAdminRegistryContract.acceptAdminRole(tokenAddress);
console.log("Accepted admin role for token:", tokenAddress);
vm.stopBroadcast();
}
}