Skip to content

Commit c2916cb

Browse files
committed
refactor: Enhance build and deployment scripts for improved development experience
- Added a new `build:contracts:dev` script in `package.json` to facilitate faster contract builds during development. - Updated existing test scripts to utilize the `FOUNDRY_PROFILE=dev` for improved testing speed and efficiency. - Enhanced deployment scripts to use the development profile for quicker contract deployment and seeding of the demo environment. - Introduced compilation cache and parallel compilation settings in `foundry.toml` for faster builds. - Refactored deployment scripts to streamline the process and improve clarity in the development workflow. These changes significantly enhance the development experience by optimizing build and deployment processes, leading to faster iterations and improved efficiency.
1 parent 4b64865 commit c2916cb

19 files changed

+923
-891
lines changed

contracts/foundry.toml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ optimizer = true
55
optimizer_runs = 1 # Aggressively optimize for size to stay under 24KB limit
66
bytecode_hash = "none" # Remove metadata hash to save ~53 bytes
77
cbor_metadata = false # Disable CBOR metadata encoding
8+
# Additional optimizations for faster compilation
9+
solc_version = "0.8.30" # Pin to specific version for consistent compilation
10+
cache = true # Enable compilation cache for faster subsequent builds
11+
parallel = 4 # Use 4 parallel threads for compilation
812
# Prioritize contract size to keep functionality
913
src = "src"
1014
out = "out"
@@ -27,22 +31,50 @@ fs_permissions = [
2731
{ access = "read", path = "../" }
2832
]
2933

34+
# Fast development profile - prioritizes compilation speed
35+
[profile.dev]
36+
evm_version = "cancun"
37+
via_ir = true # Required for complex contracts
38+
optimizer = true
39+
optimizer_runs = 200 # Higher runs = faster compilation (trade-off: larger bytecode)
40+
cache = true
41+
parallel = 4
42+
src = "src"
43+
out = "out"
44+
libs = ["lib"]
45+
test = "test"
46+
script = "script"
47+
skip = ["**/certora/**/*.sol", "lib/openzeppelin-contracts/certora/**"]
48+
remappings = [
49+
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/"
50+
]
51+
env_file = "../.env"
52+
fs_permissions = [
53+
{ access = "read-write", path = "./" },
54+
{ access = "read-write", path = "../client/config/" },
55+
{ access = "read-write", path = "../client/public/contracts/" },
56+
{ access = "read", path = "../" }
57+
]
58+
3059
# Size-optimized profile for deployment
3160
[profile.size]
3261
via_ir = true
3362
optimizer = true
3463
optimizer_runs = 1
3564
bytecode_hash = "none"
3665
cbor_metadata = false
66+
# Additional optimizations for faster compilation
67+
solc_version = "0.8.30" # Pin to specific version for consistent compilation
68+
cache = true # Enable compilation cache for faster subsequent builds
69+
parallel = 4 # Use 4 parallel threads for compilation
3770
# Disable some features for smaller bytecode
38-
solc_version = "0.8.25"
3971
src = "src"
4072
out = "out"
4173
libs = ["lib"]
4274
remappings = [
4375
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/"
4476
]
45-
# Load environment variables from root directory
77+
# Load environment variables from root directory
4678
env_file = "../.env.local"
4779
dot_env = "../.env.local"
4880
PRIVATE_KEY = "${PRIVATE_KEY}"

contracts/script/Deploy.s.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ contract Deploy is Script {
1515
address feeCollector = vm.envAddress("FEE_COLLECTOR");
1616
address owner = vm.envAddress("FACTORY_OWNER");
1717
uint256 feePercentage = vm.envUint("FEE_PERCENTAGE");
18-
uint256 minETHDeposit = vm.envUint("MIN_ETH_DEPOSIT");
19-
uint256 minERC20Deposit = vm.envUint("MIN_ERC20_DEPOSIT");
18+
uint256 minEthDeposit = vm.envUint("MIN_ETH_DEPOSIT");
19+
uint256 minErc20Deposit = vm.envUint("MIN_ERC20_DEPOSIT");
2020

2121
// Log deployment configuration
2222
console.log("=== Cookie Jar Factory Deployment ===");
2323
console.log("Chain ID:", block.chainid);
2424
console.log("Fee Collector:", feeCollector);
2525
console.log("Factory Owner:", owner);
2626
console.log("Fee Percentage:", feePercentage, "bps");
27-
console.log("Min ETH Deposit:", minETHDeposit, "wei");
28-
console.log("Min ERC20 Deposit:", minERC20Deposit, "wei");
27+
console.log("Min ETH Deposit:", minEthDeposit, "wei");
28+
console.log("Min ERC20 Deposit:", minErc20Deposit, "wei");
2929
console.log("=====================================");
3030

3131
// Deploy the factory
@@ -35,8 +35,8 @@ contract Deploy is Script {
3535
feeCollector,
3636
owner,
3737
feePercentage,
38-
uint128(minETHDeposit),
39-
uint128(minERC20Deposit)
38+
uint128(minEthDeposit),
39+
uint128(minErc20Deposit)
4040
);
4141

4242
vm.stopBroadcast();

contracts/script/DeployLocal.s.sol

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ contract DeployLocalScript is Script {
2828
address constant COOKIE_FAN = 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC; // User B
2929

3030
CookieJarFactory factory;
31-
CookieMonsterNFT cookieMonsterNFT;
31+
CookieMonsterNFT cookieMonsterNft;
3232
DummyERC20 demoToken;
3333

3434
function run() external {
@@ -70,13 +70,13 @@ contract DeployLocalScript is Script {
7070

7171
// Deploy Cookie Monster NFT collection
7272
console.log(" Deploying Cookie Monster NFT collection...");
73-
cookieMonsterNFT = new CookieMonsterNFT();
74-
73+
cookieMonsterNft = new CookieMonsterNFT();
74+
7575
// Mint Cookie Monster NFTs to test users
76-
cookieMonsterNFT.mint(COOKIE_MONSTER); // Token #0 to Cookie Monster
77-
cookieMonsterNFT.mint(COOKIE_FAN); // Token #1 to Cookie Fan
76+
cookieMonsterNft.mint(COOKIE_MONSTER); // Token #0 to Cookie Monster
77+
cookieMonsterNft.mint(COOKIE_FAN); // Token #1 to Cookie Fan
7878
console.log(" SUCCESS: Cookie Monster NFTs minted to special accounts!");
79-
console.log(" NFT Contract Address:", address(cookieMonsterNFT));
79+
console.log(" NFT Contract Address:", address(cookieMonsterNft));
8080
console.log(" NOTE: NFT address will change on Anvil restart. Use 'pnpm nft:address' to get current address.");
8181

8282
// Deploy demo ERC20 token
@@ -111,7 +111,7 @@ contract DeployLocalScript is Script {
111111
console.log("SUMMARY:");
112112
console.log(" - CookieJarFactory deployed at:", address(factory));
113113
console.log(" - 4 Cookie Jars created with different configurations");
114-
console.log(" - Cookie Monster NFT deployed at:", address(cookieMonsterNFT));
114+
console.log(" - Cookie Monster NFT deployed at:", address(cookieMonsterNft));
115115
console.log(" - DEMO ERC20 token deployed at:", address(demoToken));
116116
console.log(" - NFTs minted to User A (Cookie Monster) and User B (Cookie Fan)");
117117
console.log(" - Jars funded with ETH and DEMO tokens");
@@ -148,28 +148,28 @@ contract DeployLocalScript is Script {
148148

149149
address[] memory emptyTokens = new address[](0);
150150

151-
CookieJarLib.JarConfig memory params1 = CookieJarLib.JarConfig({
152-
jarOwner: DEPLOYER,
153-
supportedCurrency: CookieJarLib.ETH_ADDRESS,
154-
accessType: CookieJarLib.AccessType.Allowlist,
155-
withdrawalOption: CookieJarLib.WithdrawalTypeOptions.Fixed,
156-
fixedAmount: 0.1 ether,
157-
maxWithdrawal: 1 ether,
158-
withdrawalInterval: 7 days,
159-
minDeposit: 0.01 ether,
160-
feePercentageOnDeposit: 0,
161-
strictPurpose: false,
162-
feeCollector: DEPLOYER,
163-
emergencyWithdrawalEnabled: true,
164-
oneTimeWithdrawal: false,
165-
maxWithdrawalPerPeriod: 0,
166-
metadata: "Community Stipend - Weekly 0.1 ETH for community members",
167-
multiTokenConfig: defaultMultiToken
168-
});
151+
CookieJarLib.JarConfig memory params1 = CookieJarLib.JarConfig(
152+
DEPLOYER, // jarOwner
153+
CookieJarLib.ETH_ADDRESS, // supportedCurrency
154+
DEPLOYER, // feeCollector
155+
CookieJarLib.AccessType.Allowlist, // accessType
156+
CookieJarLib.WithdrawalTypeOptions.Fixed, // withdrawalOption
157+
false, // strictPurpose
158+
true, // emergencyWithdrawalEnabled
159+
false, // oneTimeWithdrawal
160+
0.1 ether, // fixedAmount
161+
1 ether, // maxWithdrawal
162+
7 days, // withdrawalInterval
163+
0.01 ether, // minDeposit
164+
0, // feePercentageOnDeposit
165+
0, // maxWithdrawalPerPeriod
166+
"Community Stipend - Weekly 0.1 ETH for community members", // metadata
167+
defaultMultiToken // multiTokenConfig
168+
);
169169

170170
CookieJarLib.AccessConfig memory accessConfig1 = CookieJarLib.AccessConfig({
171171
allowlist: allowlist1,
172-
nftRequirement: CookieJarLib.NFTRequirement({
172+
nftRequirement: CookieJarLib.NftRequirement({
173173
nftContract: address(0),
174174
tokenId: 0,
175175
minBalance: 0
@@ -202,28 +202,28 @@ contract DeployLocalScript is Script {
202202

203203
address[] memory emptyTokens2 = new address[](0);
204204

205-
CookieJarLib.JarConfig memory params2 = CookieJarLib.JarConfig({
206-
jarOwner: DEPLOYER,
207-
supportedCurrency: address(demoToken),
208-
accessType: CookieJarLib.AccessType.Allowlist,
209-
withdrawalOption: CookieJarLib.WithdrawalTypeOptions.Variable,
210-
fixedAmount: 0,
211-
maxWithdrawal: 1000 * 10**18,
212-
withdrawalInterval: 30 days,
213-
minDeposit: 1000 * 10**18,
214-
feePercentageOnDeposit: 0,
215-
strictPurpose: true,
216-
feeCollector: DEPLOYER,
217-
emergencyWithdrawalEnabled: false,
218-
oneTimeWithdrawal: false,
219-
maxWithdrawalPerPeriod: 0,
220-
metadata: "Development Grants - Up to 1000 DEMO tokens monthly for contributors",
221-
multiTokenConfig: defaultMultiToken2
222-
});
205+
CookieJarLib.JarConfig memory params2 = CookieJarLib.JarConfig(
206+
DEPLOYER, // jarOwner
207+
address(demoToken), // supportedCurrency
208+
DEPLOYER, // feeCollector
209+
CookieJarLib.AccessType.Allowlist, // accessType
210+
CookieJarLib.WithdrawalTypeOptions.Variable, // withdrawalOption
211+
true, // strictPurpose
212+
false, // emergencyWithdrawalEnabled
213+
false, // oneTimeWithdrawal
214+
0, // fixedAmount
215+
1000 * 10**18, // maxWithdrawal
216+
30 days, // withdrawalInterval
217+
1000 * 10**18, // minDeposit
218+
0, // feePercentageOnDeposit
219+
0, // maxWithdrawalPerPeriod
220+
"Development Grants - Up to 1000 DEMO tokens monthly for contributors", // metadata
221+
defaultMultiToken2 // multiTokenConfig
222+
);
223223

224224
CookieJarLib.AccessConfig memory accessConfig2 = CookieJarLib.AccessConfig({
225225
allowlist: allowlist2,
226-
nftRequirement: CookieJarLib.NFTRequirement({
226+
nftRequirement: CookieJarLib.NftRequirement({
227227
nftContract: address(0),
228228
tokenId: 0,
229229
minBalance: 0
@@ -243,7 +243,7 @@ contract DeployLocalScript is Script {
243243
function _createJar3() internal {
244244
// 3. NFT Holder Rewards (NFT-Gated, ETH, Fixed 0.05 ETH)
245245
address[] memory nftAddresses = new address[](1);
246-
nftAddresses[0] = address(cookieMonsterNFT);
246+
nftAddresses[0] = address(cookieMonsterNft);
247247

248248
// Default configurations for Jar 3
249249
CookieJarLib.MultiTokenConfig memory defaultMultiToken3 = CookieJarLib.MultiTokenConfig({
@@ -255,29 +255,29 @@ contract DeployLocalScript is Script {
255255

256256
address[] memory emptyTokens3 = new address[](0);
257257

258-
CookieJarLib.JarConfig memory params3 = CookieJarLib.JarConfig({
259-
jarOwner: DEPLOYER,
260-
supportedCurrency: CookieJarLib.ETH_ADDRESS,
261-
accessType: CookieJarLib.AccessType.ERC721,
262-
withdrawalOption: CookieJarLib.WithdrawalTypeOptions.Fixed,
263-
fixedAmount: 0.05 ether,
264-
maxWithdrawal: 1 ether,
265-
withdrawalInterval: 14 days,
266-
minDeposit: 0.01 ether,
267-
feePercentageOnDeposit: 0,
268-
strictPurpose: false,
269-
feeCollector: DEPLOYER,
270-
emergencyWithdrawalEnabled: true,
271-
oneTimeWithdrawal: false,
272-
maxWithdrawalPerPeriod: 0,
273-
metadata: "NFT Holder Rewards - 0.05 ETH bi-weekly for Cookie Monster NFT holders",
274-
multiTokenConfig: defaultMultiToken3
275-
});
258+
CookieJarLib.JarConfig memory params3 = CookieJarLib.JarConfig(
259+
DEPLOYER, // jarOwner
260+
CookieJarLib.ETH_ADDRESS, // supportedCurrency
261+
DEPLOYER, // feeCollector
262+
CookieJarLib.AccessType.ERC721, // accessType
263+
CookieJarLib.WithdrawalTypeOptions.Fixed, // withdrawalOption
264+
false, // strictPurpose
265+
true, // emergencyWithdrawalEnabled
266+
false, // oneTimeWithdrawal
267+
0.05 ether, // fixedAmount
268+
1 ether, // maxWithdrawal
269+
14 days, // withdrawalInterval
270+
0.01 ether, // minDeposit
271+
0, // feePercentageOnDeposit
272+
0, // maxWithdrawalPerPeriod
273+
"NFT Holder Rewards - 0.05 ETH bi-weekly for Cookie Monster NFT holders", // metadata
274+
defaultMultiToken3 // multiTokenConfig
275+
);
276276

277277

278278
CookieJarLib.AccessConfig memory accessConfig3 = CookieJarLib.AccessConfig({
279279
allowlist: new address[](0),
280-
nftRequirement: CookieJarLib.NFTRequirement({
280+
nftRequirement: CookieJarLib.NftRequirement({
281281
nftContract: nftAddresses[0],
282282
tokenId: 0, // Any token from contract
283283
minBalance: 1
@@ -296,7 +296,7 @@ contract DeployLocalScript is Script {
296296
function _createJar4() internal {
297297
// 4. NFT Airdrop (NFT-Gated, ERC20, One-time 500 DEMO)
298298
address[] memory nftAddresses = new address[](1);
299-
nftAddresses[0] = address(cookieMonsterNFT);
299+
nftAddresses[0] = address(cookieMonsterNft);
300300

301301
// Default configurations for Jar 4
302302
CookieJarLib.MultiTokenConfig memory defaultMultiToken4 = CookieJarLib.MultiTokenConfig({
@@ -308,29 +308,29 @@ contract DeployLocalScript is Script {
308308

309309
address[] memory emptyTokens4 = new address[](0);
310310

311-
CookieJarLib.JarConfig memory params4 = CookieJarLib.JarConfig({
312-
jarOwner: DEPLOYER,
313-
supportedCurrency: address(demoToken),
314-
accessType: CookieJarLib.AccessType.ERC721,
315-
withdrawalOption: CookieJarLib.WithdrawalTypeOptions.Fixed,
316-
fixedAmount: 500 * 10**18,
317-
maxWithdrawal: 500 * 10**18,
318-
withdrawalInterval: 0,
319-
minDeposit: 100 * 10**18,
320-
feePercentageOnDeposit: 0,
321-
strictPurpose: false,
322-
feeCollector: DEPLOYER,
323-
emergencyWithdrawalEnabled: false,
324-
oneTimeWithdrawal: true,
325-
maxWithdrawalPerPeriod: 0,
326-
metadata: "NFT Airdrop - One-time 500 DEMO tokens for Cookie Monster NFT holders",
327-
multiTokenConfig: defaultMultiToken4
328-
});
311+
CookieJarLib.JarConfig memory params4 = CookieJarLib.JarConfig(
312+
DEPLOYER, // jarOwner
313+
address(demoToken), // supportedCurrency
314+
DEPLOYER, // feeCollector
315+
CookieJarLib.AccessType.ERC721, // accessType
316+
CookieJarLib.WithdrawalTypeOptions.Fixed, // withdrawalOption
317+
false, // strictPurpose
318+
false, // emergencyWithdrawalEnabled
319+
true, // oneTimeWithdrawal
320+
500 * 10**18, // fixedAmount
321+
500 * 10**18, // maxWithdrawal
322+
0, // withdrawalInterval
323+
100 * 10**18, // minDeposit
324+
0, // feePercentageOnDeposit
325+
0, // maxWithdrawalPerPeriod
326+
"NFT Airdrop - One-time 500 DEMO tokens for Cookie Monster NFT holders", // metadata
327+
defaultMultiToken4 // multiTokenConfig
328+
);
329329

330330

331331
CookieJarLib.AccessConfig memory accessConfig4 = CookieJarLib.AccessConfig({
332332
allowlist: new address[](0),
333-
nftRequirement: CookieJarLib.NFTRequirement({
333+
nftRequirement: CookieJarLib.NftRequirement({
334334
nftContract: nftAddresses[0],
335335
tokenId: 0, // Any token from contract
336336
minBalance: 1

contracts/script/HelperConfig.s.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ pragma solidity ^0.8.19;
44
/// @title HelperConfig
55
/// @notice Configuration helper for deployment scripts
66
contract HelperConfig {
7-
address DEFAULT_FEE_COLLECTOR = address(0xcFF556854A07A8Ff47F8b178abb617901682D4eb);
8-
uint256 FEE_PERCENT_ON_DEPOSIT = 100;
7+
address defaultFeeCollector = address(0xcFF556854A07A8Ff47F8b178abb617901682D4eb);
8+
uint256 feePercentOnDeposit = 100;
99
/// @dev 1% fee on deposit. 100=1% 1000=10%
10-
uint256 MIN_ETH_DEPOSIT = 0;
11-
uint256 MIN_ERC20_DEPOST = 0;
10+
uint256 minETHDeposit = 0;
11+
uint256 minERC20Deposit = 0;
1212

1313
struct NetworkConfig {
1414
address defaultFeeCollector;
@@ -19,19 +19,19 @@ contract HelperConfig {
1919

2020
function getBaseSepoliaConfig() public view returns (NetworkConfig memory baseSepoliaConfig) {
2121
baseSepoliaConfig = NetworkConfig({
22-
defaultFeeCollector: DEFAULT_FEE_COLLECTOR,
23-
feePercentageOnDeposit: FEE_PERCENT_ON_DEPOSIT,
24-
minETHDeposit: uint128(MIN_ETH_DEPOSIT),
25-
minERC20Deposit: uint128(MIN_ERC20_DEPOST)
22+
defaultFeeCollector: defaultFeeCollector,
23+
feePercentageOnDeposit: feePercentOnDeposit,
24+
minETHDeposit: uint128(minETHDeposit),
25+
minERC20Deposit: uint128(minERC20Deposit)
2626
});
2727
}
2828

2929
function getAnvilConfig() public view returns (NetworkConfig memory anvilConfig) {
3030
anvilConfig = NetworkConfig({
31-
defaultFeeCollector: DEFAULT_FEE_COLLECTOR,
32-
feePercentageOnDeposit: FEE_PERCENT_ON_DEPOSIT,
33-
minETHDeposit: uint128(MIN_ETH_DEPOSIT),
34-
minERC20Deposit: uint128(MIN_ERC20_DEPOST)
31+
defaultFeeCollector: defaultFeeCollector,
32+
feePercentageOnDeposit: feePercentOnDeposit,
33+
minETHDeposit: uint128(minETHDeposit),
34+
minERC20Deposit: uint128(minERC20Deposit)
3535
});
3636
}
3737
}

0 commit comments

Comments
 (0)