-
Notifications
You must be signed in to change notification settings - Fork 1
/
SimpleSS2ERC721.s.sol
51 lines (39 loc) · 1.98 KB
/
SimpleSS2ERC721.s.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "forge-std/Script.sol";
import {SimpleSS2ERC721} from "src/SimpleSS2ERC721.sol";
contract SimpleSS2ERC721Deploy is Script {
function pack(address[] memory recipients) internal pure returns (bytes memory packedRecipients) {
require(recipients.length != 0, "NO_RECIPIENTS");
require(recipients.length < 1228, "RECIPENTS_TOO_BIG");
// pack the recipients into a single bytes array
// this is just a script, so we don't need the loop to be gas efficient
for (uint256 i = 0; i < recipients.length; i++) {
packedRecipients = abi.encodePacked(packedRecipients, recipients[i]);
}
}
function run() public returns (SimpleSS2ERC721 token) {
uint256 pk = vm.envUint("PRIVATE_KEY");
address deployerAddr = vm.addr(pk);
// read the contract parameters from the config file
string memory config = vm.readFile(string.concat(vm.projectRoot(), "/token-config.json"));
address owner = vm.parseJsonAddress(config, ".owner");
string memory name = vm.parseJsonString(config, ".name");
string memory symbol = vm.parseJsonString(config, ".symbol");
string memory baseURI = vm.parseJsonString(config, ".baseURI");
address[] memory recipients = vm.parseJsonAddressArray(config, ".recipients");
// pack the recipients into a single bytes array
bytes memory packedRecipients = pack(recipients);
vm.startBroadcast(pk);
// 1st transaction: deploy the contract
token = new SimpleSS2ERC721(deployerAddr, name, symbol, baseURI);
console2.log("Deployed SimpleSS2ERC721 at", address(token));
// 2nd transaction: mint the tokens in 1 batch
token.mintBatch(packedRecipients);
// optionally, transfer ownership to the owner if it's not the deployer
if (owner != deployerAddr) {
token.transferOwnership(owner);
}
vm.stopBroadcast();
}
}