@croptop/core-v6 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/STYLE_GUIDE.md ADDED
@@ -0,0 +1,470 @@
1
+ # Style Guide
2
+
3
+ How we write Solidity and organize repos across the Juicebox V6 ecosystem. `nana-core-v6` is the gold standard — when in doubt, match what it does.
4
+
5
+ **This repo's scope:** `@croptop/` (not `@bananapus/`). Standard foundry config with no deviations.
6
+
7
+ ## File Organization
8
+
9
+ ```
10
+ src/
11
+ ├── Contract.sol # Main contracts in root
12
+ ├── abstract/ # Base contracts (JBPermissioned, JBControlled)
13
+ ├── enums/ # One enum per file
14
+ ├── interfaces/ # One interface per file, prefixed with I
15
+ ├── libraries/ # Pure/view logic, prefixed with JB
16
+ ├── periphery/ # Utility contracts (deadlines, price feeds)
17
+ └── structs/ # One struct per file, prefixed with JB
18
+ ```
19
+
20
+ One contract/interface/struct/enum per file. Name the file after the type it contains.
21
+
22
+ **Structs, enums, libraries, and interfaces always go in their subdirectories** (`src/structs/`, `src/enums/`, `src/libraries/`, `src/interfaces/`) — never inline in contract files or placed in `src/` root. This keeps type definitions discoverable and import paths consistent across repos.
23
+
24
+ ## Pragma Versions
25
+
26
+ ```solidity
27
+ // Contracts — pin to exact version
28
+ pragma solidity 0.8.26;
29
+
30
+ // Interfaces, structs, enums — caret for forward compatibility
31
+ pragma solidity ^0.8.0;
32
+
33
+ // Libraries — caret, may use newer features
34
+ pragma solidity ^0.8.17;
35
+ ```
36
+
37
+ ## Imports
38
+
39
+ Named imports only. Grouped by source, alphabetized within each group:
40
+
41
+ ```solidity
42
+ // External packages (alphabetized)
43
+ import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
44
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
45
+ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
46
+ import {mulDiv} from "@prb/math/src/Common.sol";
47
+
48
+ // Local: abstract contracts
49
+ import {JBPermissioned} from "./abstract/JBPermissioned.sol";
50
+
51
+ // Local: interfaces (alphabetized)
52
+ import {IJBController} from "./interfaces/IJBController.sol";
53
+ import {IJBDirectory} from "./interfaces/IJBDirectory.sol";
54
+ import {IJBMultiTerminal} from "./interfaces/IJBMultiTerminal.sol";
55
+
56
+ // Local: libraries (alphabetized)
57
+ import {JBConstants} from "./libraries/JBConstants.sol";
58
+ import {JBFees} from "./libraries/JBFees.sol";
59
+
60
+ // Local: structs (alphabetized)
61
+ import {JBAccountingContext} from "./structs/JBAccountingContext.sol";
62
+ import {JBSplit} from "./structs/JBSplit.sol";
63
+ ```
64
+
65
+ ## Contract Structure
66
+
67
+ Section banners divide the contract into a fixed ordering. Every contract with 50+ lines uses these banners:
68
+
69
+ ```solidity
70
+ /// @notice One-line description.
71
+ contract JBExample is JBPermissioned, IJBExample {
72
+ // A library that does X.
73
+ using SomeLib for SomeType;
74
+
75
+ //*********************************************************************//
76
+ // --------------------------- custom errors ------------------------- //
77
+ //*********************************************************************//
78
+
79
+ error JBExample_SomethingFailed(uint256 amount);
80
+
81
+ //*********************************************************************//
82
+ // ------------------------- public constants ------------------------ //
83
+ //*********************************************************************//
84
+
85
+ uint256 public constant override FEE = 25;
86
+
87
+ //*********************************************************************//
88
+ // ----------------------- internal constants ------------------------ //
89
+ //*********************************************************************//
90
+
91
+ uint256 internal constant _FEE_BENEFICIARY_PROJECT_ID = 1;
92
+
93
+ //*********************************************************************//
94
+ // --------------- public immutable stored properties ---------------- //
95
+ //*********************************************************************//
96
+
97
+ IJBDirectory public immutable override DIRECTORY;
98
+
99
+ //*********************************************************************//
100
+ // --------------------- public stored properties -------------------- //
101
+ //*********************************************************************//
102
+
103
+ //*********************************************************************//
104
+ // -------------------- internal stored properties ------------------- //
105
+ //*********************************************************************//
106
+
107
+ //*********************************************************************//
108
+ // -------------------------- constructor ---------------------------- //
109
+ //*********************************************************************//
110
+
111
+ //*********************************************************************//
112
+ // ---------------------- receive / fallback ------------------------- //
113
+ //*********************************************************************//
114
+
115
+ //*********************************************************************//
116
+ // --------------------------- modifiers ----------------------------- //
117
+ //*********************************************************************//
118
+
119
+ //*********************************************************************//
120
+ // ---------------------- external transactions ---------------------- //
121
+ //*********************************************************************//
122
+
123
+ //*********************************************************************//
124
+ // ----------------------- external views ---------------------------- //
125
+ //*********************************************************************//
126
+
127
+ //*********************************************************************//
128
+ // ----------------------- public transactions ----------------------- //
129
+ //*********************************************************************//
130
+
131
+ //*********************************************************************//
132
+ // ----------------------- internal helpers -------------------------- //
133
+ //*********************************************************************//
134
+
135
+ //*********************************************************************//
136
+ // ----------------------- internal views ---------------------------- //
137
+ //*********************************************************************//
138
+
139
+ //*********************************************************************//
140
+ // ----------------------- private helpers --------------------------- //
141
+ //*********************************************************************//
142
+ }
143
+ ```
144
+
145
+ **Section order:**
146
+ 1. `using` declarations
147
+ 2. Custom errors
148
+ 3. Public constants
149
+ 4. Internal constants
150
+ 5. Public immutable stored properties
151
+ 6. Internal immutable stored properties
152
+ 7. Public stored properties
153
+ 8. Internal stored properties
154
+ 9. Constructor
155
+ 10. `receive` / `fallback`
156
+ 11. Modifiers
157
+ 12. External transactions
158
+ 13. External views
159
+ 14. Public transactions
160
+ 15. Internal helpers
161
+ 16. Internal views
162
+ 17. Private helpers
163
+
164
+ Functions are alphabetized within each section.
165
+
166
+ **Events:** Events are declared in interfaces only, never in implementation contracts. Implementations inherit events from their interface and emit them unqualified. This keeps the ABI definition in one place and allows tests to use interface-qualified event expectations (e.g., `emit IJBController.LaunchProject(...)`).
167
+
168
+ ## Interface Structure
169
+
170
+ ```solidity
171
+ /// @notice One-line description.
172
+ interface IJBExample is IJBBase {
173
+ // Events (with full NatSpec)
174
+
175
+ /// @notice Emitted when X happens.
176
+ /// @param projectId The ID of the project.
177
+ /// @param amount The amount transferred.
178
+ event SomethingHappened(uint256 indexed projectId, uint256 amount);
179
+
180
+ // Views (alphabetized)
181
+
182
+ /// @notice The directory of terminals and controllers.
183
+ function DIRECTORY() external view returns (IJBDirectory);
184
+
185
+ // State-changing functions (alphabetized)
186
+
187
+ /// @notice Does the thing.
188
+ /// @param projectId The ID of the project.
189
+ /// @return result The result.
190
+ function doThing(uint256 projectId) external returns (uint256 result);
191
+ }
192
+ ```
193
+
194
+ **Rules:**
195
+ - Events first, then views, then state-changing functions
196
+ - No custom errors in interfaces — errors belong in the implementing contract
197
+ - Full NatSpec on every event, function, and parameter
198
+ - Alphabetized within each group
199
+
200
+ ## Naming
201
+
202
+ | Thing | Convention | Example |
203
+ |-------|-----------|---------|
204
+ | Contract | PascalCase | `JBMultiTerminal` |
205
+ | Interface | `I` + PascalCase | `IJBMultiTerminal` |
206
+ | Library | PascalCase | `JBCashOuts` |
207
+ | Struct | PascalCase | `JBRulesetConfig` |
208
+ | Enum | PascalCase | `JBApprovalStatus` |
209
+ | Enum value | PascalCase | `ApprovalExpected` |
210
+ | Error | `ContractName_ErrorName` | `JBMultiTerminal_FeeTerminalNotFound` |
211
+ | Public constant | `ALL_CAPS` | `FEE`, `MAX_FEE` |
212
+ | Internal constant | `_ALL_CAPS` | `_FEE_HOLDING_SECONDS` |
213
+ | Public immutable | `ALL_CAPS` | `DIRECTORY`, `PERMISSIONS` |
214
+ | Public/external function | `camelCase` | `cashOutTokensOf` |
215
+ | Internal/private function | `_camelCase` | `_processFee` |
216
+ | Internal storage | `_camelCase` | `_accountingContextForTokenOf` |
217
+ | Function parameter | `camelCase` | `projectId`, `cashOutCount` |
218
+
219
+ ## NatSpec
220
+
221
+ **Contracts:**
222
+ ```solidity
223
+ /// @notice One-line description of what the contract does.
224
+ contract JBExample is IJBExample {
225
+ ```
226
+
227
+ **Functions:**
228
+ ```solidity
229
+ /// @notice Records funds being added to a project's balance.
230
+ /// @param projectId The ID of the project which funds are being added to.
231
+ /// @param token The token being added.
232
+ /// @param amount The amount added, as a fixed point number with the same decimals as the terminal.
233
+ /// @return surplus The new surplus after adding.
234
+ function recordAddedBalanceFor(
235
+ uint256 projectId,
236
+ address token,
237
+ uint256 amount
238
+ ) external override returns (uint256 surplus) {
239
+ ```
240
+
241
+ **Structs:**
242
+ ```solidity
243
+ /// @custom:member duration The number of seconds the ruleset lasts for. 0 means it never expires.
244
+ /// @custom:member weight How many tokens to mint per unit paid (18 decimals).
245
+ /// @custom:member weightCutPercent How much weight decays each cycle (9 decimals).
246
+ struct JBRulesetConfig {
247
+ uint32 duration;
248
+ uint112 weight;
249
+ uint32 weightCutPercent;
250
+ }
251
+ ```
252
+
253
+ **Mappings:**
254
+ ```solidity
255
+ /// @notice Context describing how a token is accounted for by a project.
256
+ /// @custom:param projectId The ID of the project.
257
+ /// @custom:param token The address of the token.
258
+ mapping(uint256 projectId => mapping(address token => JBAccountingContext)) internal _accountingContextForTokenOf;
259
+ ```
260
+
261
+ ## Numbers
262
+
263
+ Use underscores for thousands separators:
264
+
265
+ ```solidity
266
+ uint256 internal constant _FEE_HOLDING_SECONDS = 2_419_200; // 28 days
267
+ uint32 public constant MAX_WEIGHT_CUT_PERCENT = 1_000_000_000;
268
+ uint256 public constant MAX_RESERVED_PERCENT = 10_000;
269
+ ```
270
+
271
+ ## Function Calls
272
+
273
+ Use named parameters for readability when calling functions with 3+ arguments:
274
+
275
+ ```solidity
276
+ PERMISSIONS.hasPermission({
277
+ operator: sender,
278
+ account: account,
279
+ projectId: projectId,
280
+ permissionId: permissionId,
281
+ includeRoot: true,
282
+ includeWildcardProjectId: true
283
+ });
284
+ ```
285
+
286
+ ## Multiline Signatures
287
+
288
+ ```solidity
289
+ function recordCashOutFor(
290
+ address holder,
291
+ uint256 projectId,
292
+ uint256 cashOutCount,
293
+ JBAccountingContext calldata accountingContext
294
+ )
295
+ external
296
+ override
297
+ returns (
298
+ JBRuleset memory ruleset,
299
+ uint256 reclaimAmount,
300
+ JBCashOutHookSpecification[] memory hookSpecifications
301
+ )
302
+ {
303
+ ```
304
+
305
+ Modifiers and return types go on their own indented lines.
306
+
307
+ ## Error Handling
308
+
309
+ - Validate inputs with explicit `revert` + custom error
310
+ - Use `try-catch` only for external calls to untrusted contracts (hooks, fee processing)
311
+ - Always include relevant context in error parameters
312
+
313
+ ```solidity
314
+ // Direct validation
315
+ if (amount > limit) revert JBTerminalStore_InadequateControllerPayoutLimit(amount, limit);
316
+
317
+ // External call to untrusted hook
318
+ try hook.afterPayRecordedWith(context) {} catch (bytes memory reason) {
319
+ emit HookAfterPayReverted(hook, context, reason, _msgSender());
320
+ }
321
+ ```
322
+
323
+ ---
324
+
325
+ ## DevOps
326
+
327
+ ### foundry.toml
328
+
329
+ Standard config across all repos:
330
+
331
+ ```toml
332
+ [profile.default]
333
+ solc = '0.8.26'
334
+ evm_version = 'cancun'
335
+ optimizer_runs = 200
336
+ libs = ["node_modules", "lib"]
337
+ fs_permissions = [{ access = "read-write", path = "./"}]
338
+
339
+ [profile.ci_sizes]
340
+ optimizer_runs = 200
341
+
342
+ [fuzz]
343
+ runs = 4096
344
+
345
+ [invariant]
346
+ runs = 1024
347
+ depth = 100
348
+ fail_on_revert = false
349
+
350
+ [fmt]
351
+ number_underscore = "thousands"
352
+ multiline_func_header = "all"
353
+ wrap_comments = true
354
+ ```
355
+
356
+ **Variations:**
357
+ - `evm_version = 'cancun'` for repos using transient storage (buyback-hook, router-terminal, univ4-router)
358
+ - `via_ir = true` for repos hitting stack-too-deep (buyback-hook, banny-retail, univ4-lp-split-hook, deploy-all)
359
+ - `optimizer = false` only for deploy-all-v6 (stack-too-deep with optimization)
360
+
361
+ ### CI Workflows
362
+
363
+ Every repo has at minimum `test.yml` and `lint.yml`:
364
+
365
+ **test.yml:**
366
+ ```yaml
367
+ name: test
368
+ on:
369
+ pull_request:
370
+ branches: [main]
371
+ push:
372
+ branches: [main]
373
+ jobs:
374
+ forge-test:
375
+ runs-on: ubuntu-latest
376
+ steps:
377
+ - uses: actions/checkout@v4
378
+ with:
379
+ submodules: recursive
380
+ - uses: actions/setup-node@v4
381
+ with:
382
+ node-version: 22.4.x
383
+ - name: Install npm dependencies
384
+ run: npm install --omit=dev
385
+ - name: Install Foundry
386
+ uses: foundry-rs/foundry-toolchain@v1
387
+ - name: Run tests
388
+ run: forge test --fail-fast --summary --detailed --skip "*/script/**"
389
+ - name: Check contract sizes
390
+ run: FOUNDRY_PROFILE=ci_sizes forge build --sizes --skip "*/test/**" --skip "*/script/**" --skip SphinxUtils
391
+ ```
392
+
393
+ **lint.yml:**
394
+ ```yaml
395
+ name: lint
396
+ on:
397
+ pull_request:
398
+ branches: [main]
399
+ push:
400
+ branches: [main]
401
+ jobs:
402
+ forge-fmt:
403
+ runs-on: ubuntu-latest
404
+ steps:
405
+ - uses: actions/checkout@v4
406
+ - name: Install Foundry
407
+ uses: foundry-rs/foundry-toolchain@v1
408
+ - name: Check formatting
409
+ run: forge fmt --check
410
+ ```
411
+
412
+ ### package.json
413
+
414
+ ```json
415
+ {
416
+ "name": "@croptop/core-v6",
417
+ "version": "x.x.x",
418
+ "license": "MIT",
419
+ "repository": { "type": "git", "url": "git+https://github.com/Org/repo.git" },
420
+ "engines": { "node": ">=20.0.0" },
421
+ "scripts": {
422
+ "test": "forge test",
423
+ "coverage": "forge coverage --match-path \"./src/*.sol\" --report lcov --report summary"
424
+ },
425
+ "dependencies": { ... },
426
+ "devDependencies": {
427
+ "@sphinx-labs/plugins": "^0.33.2"
428
+ }
429
+ }
430
+ ```
431
+
432
+ **Scoping:** `@bananapus/` for Bananapus repos, `@rev-net/` for revnet, `@croptop/` for croptop, `@bannynet/` for banny, `@ballkidz/` for defifa.
433
+
434
+ ### remappings.txt
435
+
436
+ Every repo has a `remappings.txt`. Minimal content:
437
+
438
+ ```
439
+ @sphinx-labs/contracts/=lib/sphinx/packages/contracts/contracts/foundry
440
+ ```
441
+
442
+ Additional mappings as needed for repo-specific dependencies.
443
+
444
+ ### Formatting
445
+
446
+ Run `forge fmt` before committing. The `[fmt]` config in `foundry.toml` enforces:
447
+ - Thousands separators on numbers (`1_000_000`)
448
+ - Multiline function headers when multiple parameters
449
+ - Wrapped comments at reasonable width
450
+
451
+ CI checks formatting via `forge fmt --check`.
452
+
453
+ ### Branching
454
+
455
+ - `main` is the primary branch
456
+ - Feature branches for PRs
457
+ - All PRs trigger test + lint workflows
458
+ - Submodule checkout with `--recursive` in CI
459
+
460
+ ### Dependencies
461
+
462
+ - Solidity dependencies via npm (`node_modules/`)
463
+ - `forge-std` as a git submodule in `lib/`
464
+ - Sphinx plugins as a devDependency
465
+ - Cross-repo references use `file:../sibling-repo` in local development
466
+ - Published versions use semver ranges (`^0.0.x`) for npm
467
+
468
+ ### Contract Size Checks
469
+
470
+ CI runs `FOUNDRY_PROFILE=ci_sizes forge build --sizes` to catch contracts approaching the 24KB limit. The `ci_sizes` profile uses `optimizer_runs = 200` for realistic size measurement even when the default profile has different optimizer settings.
package/foundry.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [profile.default]
2
2
  solc = '0.8.26'
3
- evm_version = 'paris'
4
- optimizer_runs = 100000000
3
+ evm_version = 'cancun'
4
+ optimizer_runs = 200
5
5
  libs = ["node_modules", "lib"]
6
6
  fs_permissions = [{ access = "read-write", path = "./"}]
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croptop/core-v6",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,17 +16,17 @@
16
16
  "artifacts": "source ./.env && npx sphinx artifacts --org-id 'ea165b21-7cdc-4d7b-be59-ecdd4c26bee4' --project-name 'croptop-core-v5'"
17
17
  },
18
18
  "dependencies": {
19
- "@bananapus/721-hook-v6": "^0.0.9",
20
- "@bananapus/buyback-hook-v6": "^0.0.7",
21
- "@bananapus/core-v6": "^0.0.9",
22
- "@bananapus/ownable-v6": "^0.0.5",
23
- "@bananapus/permission-ids-v6": "^0.0.4",
24
- "@bananapus/suckers-v6": "^0.0.6",
25
- "@bananapus/router-terminal-v6": "^0.0.6",
19
+ "@bananapus/721-hook-v6": "^0.0.13",
20
+ "@bananapus/buyback-hook-v6": "^0.0.9",
21
+ "@bananapus/core-v6": "^0.0.13",
22
+ "@bananapus/ownable-v6": "^0.0.7",
23
+ "@bananapus/permission-ids-v6": "^0.0.6",
24
+ "@bananapus/router-terminal-v6": "^0.0.9",
25
+ "@bananapus/suckers-v6": "^0.0.8",
26
26
  "@openzeppelin/contracts": "^5.2.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@rev-net/core-v6": "^0.0.6",
29
+ "@rev-net/core-v6": "^0.0.8",
30
30
  "@sphinx-labs/plugins": "^0.33.1"
31
31
  }
32
32
  }
package/remappings.txt CHANGED
@@ -1,2 +1,3 @@
1
1
  @sphinx-labs/contracts/=node_modules/@sphinx-labs/contracts/contracts/foundry
2
2
  @croptop/core-v5=./
3
+ @croptop/core-v6=./
@@ -75,6 +75,7 @@ contract ConfigureFeeProjectScript is Script, Sphinx {
75
75
  address TRUSTED_FORWARDER;
76
76
  uint48 CPN_START_TIME = 1_740_089_444;
77
77
  uint104 CPN_MAINNET_AUTO_ISSUANCE_ = 250_003_875_000_000_000_000_000;
78
+ uint104 CPN_OP_AUTO_ISSUANCE_ = 844_894_881_600_000_000_000;
78
79
  uint104 CPN_BASE_AUTO_ISSUANCE_ = 844_894_881_600_000_000_000;
79
80
  uint104 CPN_ARB_AUTO_ISSUANCE_ = 3_844_000_000_000_000_000;
80
81
 
@@ -145,10 +146,11 @@ contract ConfigureFeeProjectScript is Script, Sphinx {
145
146
  accountingContextsToAccept: new JBAccountingContext[](0)
146
147
  });
147
148
 
148
- REVAutoIssuance[] memory issuanceConfs = new REVAutoIssuance[](3);
149
+ REVAutoIssuance[] memory issuanceConfs = new REVAutoIssuance[](4);
149
150
  issuanceConfs[0] = REVAutoIssuance({chainId: 1, count: CPN_MAINNET_AUTO_ISSUANCE_, beneficiary: OPERATOR});
150
- issuanceConfs[1] = REVAutoIssuance({chainId: 8453, count: CPN_BASE_AUTO_ISSUANCE_, beneficiary: OPERATOR});
151
- issuanceConfs[2] = REVAutoIssuance({chainId: 42_161, count: CPN_ARB_AUTO_ISSUANCE_, beneficiary: OPERATOR});
151
+ issuanceConfs[1] = REVAutoIssuance({chainId: 10, count: CPN_OP_AUTO_ISSUANCE_, beneficiary: OPERATOR});
152
+ issuanceConfs[2] = REVAutoIssuance({chainId: 8453, count: CPN_BASE_AUTO_ISSUANCE_, beneficiary: OPERATOR});
153
+ issuanceConfs[3] = REVAutoIssuance({chainId: 42_161, count: CPN_ARB_AUTO_ISSUANCE_, beneficiary: OPERATOR});
152
154
 
153
155
  JBSplit[] memory splits = new JBSplit[](1);
154
156
  splits[0] = JBSplit({
@@ -311,7 +313,8 @@ contract ConfigureFeeProjectScript is Script, Sphinx {
311
313
  noNewTiersWithReserves: false,
312
314
  noNewTiersWithVotes: true,
313
315
  noNewTiersWithOwnerMinting: true,
314
- preventOverspending: false
316
+ preventOverspending: false,
317
+ issueTokensForSplits: false
315
318
  })
316
319
  }),
317
320
  salt: HOOK_SALT,