@bannynet/core-v6 0.0.4 → 0.0.6

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,482 @@
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 deviations:** `via_ir = true` (stack depth). Package scope: `@bannynet/`.
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
+ via_ir = true
337
+ libs = ["node_modules", "lib"]
338
+ fs_permissions = [{ access = "read-write", path = "./"}]
339
+
340
+ [profile.ci_sizes]
341
+ optimizer_runs = 200
342
+
343
+ [fuzz]
344
+ runs = 4096
345
+
346
+ [invariant]
347
+ runs = 1024
348
+ depth = 100
349
+ fail_on_revert = false
350
+
351
+ [fmt]
352
+ number_underscore = "thousands"
353
+ multiline_func_header = "all"
354
+ wrap_comments = true
355
+ ```
356
+
357
+ **Variations:**
358
+ - `evm_version = 'cancun'` for repos using transient storage (buyback-hook, router-terminal, univ4-router)
359
+ - `via_ir = true` for repos hitting stack-too-deep (buyback-hook, banny-retail, univ4-lp-split-hook, deploy-all)
360
+ - `optimizer = false` only for deploy-all-v6 (stack-too-deep with optimization)
361
+
362
+ ### CI Workflows
363
+
364
+ Every repo has at minimum `test.yml` and `lint.yml`:
365
+
366
+ **test.yml:**
367
+ ```yaml
368
+ name: test
369
+ on:
370
+ pull_request:
371
+ branches: [main]
372
+ push:
373
+ branches: [main]
374
+ jobs:
375
+ forge-test:
376
+ runs-on: ubuntu-latest
377
+ steps:
378
+ - uses: actions/checkout@v4
379
+ with:
380
+ submodules: recursive
381
+ - uses: actions/setup-node@v4
382
+ with:
383
+ node-version: 22.4.x
384
+ - name: Install npm dependencies
385
+ run: npm install --omit=dev
386
+ - name: Install Foundry
387
+ uses: foundry-rs/foundry-toolchain@v1
388
+ - name: Run tests
389
+ run: forge test --fail-fast --summary --detailed --skip "*/script/**"
390
+ env:
391
+ RPC_ETHEREUM_MAINNET: ${{ secrets.RPC_ETHEREUM_MAINNET }}
392
+ - name: Check contract sizes
393
+ run: FOUNDRY_PROFILE=ci_sizes forge build --sizes --skip "*/test/**" --skip "*/script/**" --skip SphinxUtils
394
+ ```
395
+
396
+ **lint.yml:**
397
+ ```yaml
398
+ name: lint
399
+ on:
400
+ pull_request:
401
+ branches: [main]
402
+ push:
403
+ branches: [main]
404
+ jobs:
405
+ forge-fmt:
406
+ runs-on: ubuntu-latest
407
+ steps:
408
+ - uses: actions/checkout@v4
409
+ - name: Install Foundry
410
+ uses: foundry-rs/foundry-toolchain@v1
411
+ - name: Check formatting
412
+ run: forge fmt --check
413
+ ```
414
+
415
+ ### package.json
416
+
417
+ ```json
418
+ {
419
+ "name": "@bannynet/core-v6",
420
+ "version": "x.x.x",
421
+ "license": "MIT",
422
+ "repository": { "type": "git", "url": "git+https://github.com/Org/repo.git" },
423
+ "engines": { "node": ">=20.0.0" },
424
+ "scripts": {
425
+ "test": "forge test",
426
+ "coverage": "forge coverage --match-path \"./src/*.sol\" --report lcov --report summary"
427
+ },
428
+ "dependencies": { ... },
429
+ "devDependencies": {
430
+ "@sphinx-labs/plugins": "^0.33.2"
431
+ }
432
+ }
433
+ ```
434
+
435
+ **Scoping:** `@bananapus/` for Bananapus repos, `@rev-net/` for revnet, `@croptop/` for croptop, `@bannynet/` for banny, `@ballkidz/` for defifa.
436
+
437
+ ### remappings.txt
438
+
439
+ Every repo has a `remappings.txt`. Minimal content:
440
+
441
+ ```
442
+ @sphinx-labs/contracts/=lib/sphinx/packages/contracts/contracts/foundry
443
+ ```
444
+
445
+ Additional mappings as needed for repo-specific dependencies.
446
+
447
+ ### Formatting
448
+
449
+ Run `forge fmt` before committing. The `[fmt]` config in `foundry.toml` enforces:
450
+ - Thousands separators on numbers (`1_000_000`)
451
+ - Multiline function headers when multiple parameters
452
+ - Wrapped comments at reasonable width
453
+
454
+ CI checks formatting via `forge fmt --check`.
455
+
456
+ ### CI Secrets
457
+
458
+ | Secret | Purpose |
459
+ |--------|--------|
460
+ | `NPM_TOKEN` | npm publish access (used by `publish.yml`) |
461
+ | `RPC_ETHEREUM_MAINNET` | Ethereum mainnet RPC URL for fork tests (used by `test.yml`) |
462
+
463
+ Fork tests require `RPC_ETHEREUM_MAINNET` — they fail if it's missing.
464
+
465
+ ### Branching
466
+
467
+ - `main` is the primary branch
468
+ - Feature branches for PRs
469
+ - All PRs trigger test + lint workflows
470
+ - Submodule checkout with `--recursive` in CI
471
+
472
+ ### Dependencies
473
+
474
+ - Solidity dependencies via npm (`node_modules/`)
475
+ - `forge-std` as a git submodule in `lib/`
476
+ - Sphinx plugins as a devDependency
477
+ - Cross-repo references use `file:../sibling-repo` in local development
478
+ - Published versions use semver ranges (`^0.0.x`) for npm
479
+
480
+ ### Contract Size Checks
481
+
482
+ 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 = 800
3
+ evm_version = 'cancun'
4
+ optimizer_runs = 200
5
5
  via_ir = true
6
6
  libs = ["node_modules", "lib"]
7
7
  fs_permissions = [{ access = "read-write", path = "./"}]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bannynet/core-v6",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "scripts": {
13
13
  "test": "forge test",
14
- "coverage:integration": "forge coverage --match-path \"./src/*.sol\" --report lcov --report summary",
14
+ "coverage": "forge coverage --match-path \"./src/*.sol\" --report lcov --report summary",
15
15
  "generate:migration": "node ./script/outfit_drop/generate-migration.js",
16
16
  "deploy:mainnets": "source ./.env && export START_TIME=$(date +%s) && npx sphinx propose ./script/Deploy.s.sol --networks mainnets",
17
17
  "deploy:testnets": "source ./.env && export START_TIME=$(date +%s) && npx sphinx propose ./script/Deploy.s.sol --networks testnets",
@@ -21,14 +21,14 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@bananapus/721-hook-v6": "^0.0.9",
24
- "@bananapus/core-v6": "^0.0.9",
24
+ "@bananapus/core-v6": "^0.0.10",
25
25
  "@bananapus/router-terminal-v6": "^0.0.6",
26
- "@bananapus/suckers-v6": "^0.0.6",
26
+ "@bananapus/suckers-v6": "^0.0.7",
27
27
  "@openzeppelin/contracts": "5.2.0",
28
28
  "@rev-net/core-v6": "^0.0.6",
29
29
  "keccak": "^3.0.4"
30
30
  },
31
31
  "devDependencies": {
32
- "@sphinx-labs/plugins": "0.33.3"
32
+ "@sphinx-labs/plugins": "^0.33.2"
33
33
  }
34
34
  }
@@ -346,7 +346,8 @@ contract DeployScript is Script, Sphinx {
346
346
  noNewTiersWithReserves: false,
347
347
  noNewTiersWithVotes: false,
348
348
  noNewTiersWithOwnerMinting: false,
349
- preventOverspending: false
349
+ preventOverspending: false,
350
+ issueTokensForSplits: false
350
351
  })
351
352
  }),
352
353
  salt: HOOK_SALT,