-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeployToken.s.sol
More file actions
72 lines (58 loc) · 3.23 KB
/
DeployToken.s.sol
File metadata and controls
72 lines (58 loc) · 3.23 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24 <0.9.0;
import {Script, console} from "lib/forge-std/src/Script.sol";
// for JSON parsing and chain info
import {HelperUtils} from "../utils/HelperUtils.s.sol";
import {BurnMintERC677WithCCIPAdmin} from "../../src/BurnMintERC677WithCCIPAdmin.sol";
import {BurnMintERC677} from "../../src/Dependencies.sol";
contract DeployToken is Script {
function run() external {
// chainName[id]
string memory chainName = HelperUtils.getChainName(block.chainid);
// path/to/config.json
string memory root = vm.projectRoot();
string memory configPath = string.concat(root, "/script/config.json");
// parameters from config.json
string memory name = HelperUtils.getStringFromJson(vm, configPath, ".BnMToken.name");
string memory symbol = HelperUtils.getStringFromJson(vm, configPath, ".BnMToken.symbol");
uint8 decimals = uint8(HelperUtils.getUintFromJson(vm, configPath, ".BnMToken.decimals"));
uint256 maxSupply = HelperUtils.getUintFromJson(vm, configPath, ".BnMToken.maxSupply");
bool withGetCCIPAdmin = HelperUtils.getBoolFromJson(vm, configPath, ".BnMToken.withGetCCIPAdmin");
address ccipAdminAddress = HelperUtils.getAddressFromJson(vm, configPath, ".BnMToken.ccipAdminAddress");
vm.startBroadcast();
address deployer = msg.sender;
address tokenAddress;
// IF token uses getCCIPAdmin()
if (withGetCCIPAdmin) {
// THEN token contract with CCIP admin functionality
BurnMintERC677WithCCIPAdmin token = new BurnMintERC677WithCCIPAdmin(name, symbol, decimals, maxSupply);
// ELSE IF CCIP admin address is specified,
if (ccipAdminAddress == address(0)) {
// THEN default to the deployer
ccipAdminAddress = deployer;
}
// THEN set the CCIP admin for the token
token.setCCIPAdmin(ccipAdminAddress);
tokenAddress = address(token);
console.log("Deployed BurnMintERC677WithCCIPAdmin at:", tokenAddress);
} else {
// THEN deploy the standard token contract without CCIP admin functionality
BurnMintERC677 token = new BurnMintERC677(name, symbol, decimals, maxSupply);
tokenAddress = address(token);
console.log("Deployed BurnMintERC677 at:", tokenAddress);
}
// grants: mint and burn roles to the deployer
BurnMintERC677(tokenAddress).grantMintAndBurnRoles(deployer);
console.log("Granted mint and burn roles to:", deployer);
vm.stopBroadcast();
// prepares to write the deployed token address to a JSON
string memory jsonObj = "internal_key";
string memory key = string(abi.encodePacked("deployedToken_", chainName));
string memory finalJson = vm.serializeAddress(jsonObj, key, tokenAddress);
// output file path: deployed token address
string memory fileName = string(abi.encodePacked("./script/output/deployedToken_", chainName, ".json"));
console.log("Writing deployed token address to file:", fileName);
// writes: the JSON containing the deployed token address
vm.writeJson(finalJson, fileName);
}
}