Skip to content

Commit 8d95ab5

Browse files
committed
add script to deploy
1 parent 5bdaf37 commit 8d95ab5

4 files changed

Lines changed: 72 additions & 17 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ docs/
1515

1616
# other
1717
.DS_Store
18+
.vscode

script/deploy.s.sol

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.23;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {console} from "forge-std/console.sol";
6+
import {MasterOwnerModifier} from "../src/MasterOwnerModifier.sol";
7+
import {MasterContract} from "../src/Master.sol";
8+
import {TreasuryFund} from "../src/TreasuryFund.sol";
9+
import {MockERC20} from "../src/MockERC20.sol";
10+
11+
contract DeployScript is Script {
12+
function run() external {
13+
14+
address usdc_token_testnet_address = address(0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238); // USDC testnet address
15+
address usdc_token_mainnet_address = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); // USDC mainnet address
16+
17+
// Ambil private key dan RPC URL dari .env
18+
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_PRIVATE_KEY");
19+
string memory network = vm.envString("NETWORK");
20+
string memory rpcUrl;
21+
22+
if (keccak256(bytes(network)) == keccak256(bytes("sepolia"))) {
23+
rpcUrl = vm.envString("SEPOLIA_RPC_URL");
24+
console.log(" Deploying to Sepolia...");
25+
} else if (keccak256(bytes(network)) == keccak256(bytes("mainnet"))) {
26+
rpcUrl = vm.envString("MAINNET_RPC_URL");
27+
console.log(" Deploying to Ethereum Mainnet...");
28+
} else {
29+
revert(" Unsupported network! Use 'sepolia' or 'mainnet'.");
30+
}
31+
32+
vm.startBroadcast(deployerPrivateKey);
33+
34+
// Deploy MasterOwnerModifier
35+
MasterOwnerModifier masterOwnerModifier = new MasterOwnerModifier();
36+
console.log(" MasterOwnerModifier deployed at:", address(masterOwnerModifier));
37+
38+
// Deploy TreasuryFund
39+
TreasuryFund treasuryFund = new TreasuryFund();
40+
console.log("TreasuryFund deployed at:", address(treasuryFund));
41+
42+
// Deploy MasterContract
43+
MasterContract masterContract = new MasterContract(
44+
address(treasuryFund),
45+
usdc_token_testnet_address,
46+
address(masterOwnerModifier)
47+
);
48+
console.log("MasterContract deployed at:", address(masterContract));
49+
50+
vm.stopBroadcast();
51+
}
52+
}
53+
/*
54+
forge script script/deploy.s.sol --rpc-url $(grep ${NETWORK}_RPC_URL .env | cut -d '=' -f2) --broadcast --private-key $DEPLOYER_PRIVATE_KEY
55+
56+
57+
*/

src/Master.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ import "./MasterOwnerModifier.sol";
77
contract MasterContract {
88
address public owner;
99
address public immutable treasuryContract;
10+
address public immutable usdc_token;
1011
MasterOwnerModifier public immutable masterOwnerModifier;
1112

1213
address[] public eventContracts;
1314

1415
event EventCreated(address indexed eventAddress);
1516
event FundsWithdrawn(address indexed owner, uint256 amount);
1617

18+
constructor(address _treasuryContract, address _usdc_token,address _ownerModifierAddress) {
19+
owner = msg.sender;
20+
treasuryContract = _treasuryContract;
21+
usdc_token = _usdc_token;
22+
masterOwnerModifier = MasterOwnerModifier(_ownerModifierAddress);
23+
}
24+
1725
modifier onlyOwner() {
1826
require(masterOwnerModifier.isMasterOwner(msg.sender), "Caller is not an owner");
1927
_;
@@ -33,13 +41,6 @@ contract MasterContract {
3341
uint256 startSale;
3442
uint256 endSale;
3543
TicketInfo[] ticketInfos;
36-
address usdcToken;
37-
}
38-
39-
constructor(address _treasuryContract, address _ownerModifierAddress) {
40-
owner = msg.sender;
41-
treasuryContract = _treasuryContract;
42-
masterOwnerModifier = MasterOwnerModifier(_ownerModifierAddress);
4344
}
4445

4546
function addOwner(address _newOwner) external onlyOwner {
@@ -72,7 +73,7 @@ contract MasterContract {
7273
EventContract newEvent = new EventContract(
7374
msg.sender, // Vendor as eventOwner
7475
owner, // Main owner of the MasterContract
75-
params.usdcToken,
76+
usdc_token,
7677
treasuryContract,
7778
address(masterOwnerModifier), // Pass the ownerModifier address
7879
params.name,

test/Master.t.sol

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ contract MasterContractTest is Test {
3131
treasury = new TreasuryFund();
3232

3333
// Deploy MasterContract
34-
masterContract = new MasterContract(address(treasury), address(ownerModifier));
34+
masterContract = new MasterContract(address(treasury),address(usdc), address(ownerModifier));
3535

3636
// // Add owner to Owner Modifier contract
3737
// ownerModifier.addMasterOwner(owner);
@@ -50,8 +50,7 @@ contract MasterContractTest is Test {
5050
end: block.timestamp + 2 days,
5151
startSale: block.timestamp,
5252
endSale: block.timestamp + 1 days,
53-
ticketInfos: tickets,
54-
usdcToken: address(usdc)
53+
ticketInfos: tickets
5554
});
5655

5756
// Create event
@@ -75,8 +74,7 @@ contract MasterContractTest is Test {
7574
end: block.timestamp + 1 days, // Error: start > end
7675
startSale: block.timestamp,
7776
endSale: block.timestamp + 1 days,
78-
ticketInfos: tickets,
79-
usdcToken: address(usdc)
77+
ticketInfos: tickets
8078
});
8179

8280
vm.prank(owner);
@@ -95,8 +93,7 @@ contract MasterContractTest is Test {
9593
end: block.timestamp + 2 days,
9694
startSale: block.timestamp + 2 days, // Error: startSale > endSale
9795
endSale: block.timestamp + 1 days,
98-
ticketInfos: tickets,
99-
usdcToken: address(usdc)
96+
ticketInfos: tickets
10097
});
10198

10299
vm.prank(owner);
@@ -114,8 +111,7 @@ contract MasterContractTest is Test {
114111
end: block.timestamp + 2 days,
115112
startSale: block.timestamp,
116113
endSale: block.timestamp + 1 days,
117-
ticketInfos: tickets, // Error: No ticket types
118-
usdcToken: address(usdc)
114+
ticketInfos: tickets // Error: No ticket types
119115
});
120116

121117
vm.prank(owner);

0 commit comments

Comments
 (0)