@ballkidz/defifa 0.0.2 → 0.0.4

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,489 @@
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`, `build_info = true`, `extra_output = ['storageLayout']`. Lower invariant runs (256/depth 50). Package scope: `@ballkidz/`.
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
+ **This repo uses:**
362
+ - `via-ir = true` (note: hyphen not underscore in this repo's foundry.toml)
363
+ - `build_info = true`, `extra_output = ['storageLayout']`
364
+ - `[rpc_endpoints]` for ethereum, optimism, arbitrum, base, and their testnets
365
+ - `[invariant]` with `runs = 256`, `depth = 50` (lower than standard)
366
+ - No `[fuzz]` section
367
+ - `[lint]` section with `lint_on_build = false`
368
+
369
+ ### CI Workflows
370
+
371
+ Every repo has at minimum `test.yml` and `lint.yml`:
372
+
373
+ **test.yml:**
374
+ ```yaml
375
+ name: test
376
+ on:
377
+ pull_request:
378
+ branches: [main]
379
+ push:
380
+ branches: [main]
381
+ jobs:
382
+ forge-test:
383
+ runs-on: ubuntu-latest
384
+ steps:
385
+ - uses: actions/checkout@v4
386
+ with:
387
+ submodules: recursive
388
+ - uses: actions/setup-node@v4
389
+ with:
390
+ node-version: 22.4.x
391
+ - name: Install npm dependencies
392
+ run: npm install --omit=dev
393
+ - name: Install Foundry
394
+ uses: foundry-rs/foundry-toolchain@v1
395
+ - name: Run tests
396
+ run: forge test --fail-fast --summary --detailed --skip "*/script/**"
397
+ env:
398
+ RPC_ETHEREUM_MAINNET: ${{ secrets.RPC_ETHEREUM_MAINNET }}
399
+ - name: Check contract sizes
400
+ run: FOUNDRY_PROFILE=ci_sizes forge build --sizes --skip "*/test/**" --skip "*/script/**" --skip SphinxUtils
401
+ ```
402
+
403
+ **lint.yml:**
404
+ ```yaml
405
+ name: lint
406
+ on:
407
+ pull_request:
408
+ branches: [main]
409
+ push:
410
+ branches: [main]
411
+ jobs:
412
+ forge-fmt:
413
+ runs-on: ubuntu-latest
414
+ steps:
415
+ - uses: actions/checkout@v4
416
+ - name: Install Foundry
417
+ uses: foundry-rs/foundry-toolchain@v1
418
+ - name: Check formatting
419
+ run: forge fmt --check
420
+ ```
421
+
422
+ ### package.json
423
+
424
+ ```json
425
+ {
426
+ "name": "@ballkidz/defifa",
427
+ "version": "x.x.x",
428
+ "license": "MIT",
429
+ "repository": { "type": "git", "url": "git+https://github.com/Org/repo.git" },
430
+ "engines": { "node": ">=20.0.0" },
431
+ "scripts": {
432
+ "test": "forge test",
433
+ "coverage": "forge coverage --match-path \"./src/*.sol\" --report lcov --report summary"
434
+ },
435
+ "dependencies": { ... },
436
+ "devDependencies": {
437
+ "@sphinx-labs/plugins": "^0.33.2"
438
+ }
439
+ }
440
+ ```
441
+
442
+ **Scoping:** `@bananapus/` for Bananapus repos, `@rev-net/` for revnet, `@croptop/` for croptop, `@bannynet/` for banny, `@ballkidz/` for defifa.
443
+
444
+ ### remappings.txt
445
+
446
+ Every repo has a `remappings.txt`. Minimal content:
447
+
448
+ ```
449
+ @sphinx-labs/contracts/=lib/sphinx/packages/contracts/contracts/foundry
450
+ ```
451
+
452
+ Additional mappings as needed for repo-specific dependencies.
453
+
454
+ ### Formatting
455
+
456
+ Run `forge fmt` before committing. The `[fmt]` config in `foundry.toml` enforces:
457
+ - Thousands separators on numbers (`1_000_000`)
458
+ - Multiline function headers when multiple parameters
459
+ - Wrapped comments at reasonable width
460
+
461
+ CI checks formatting via `forge fmt --check`.
462
+
463
+ ### CI Secrets
464
+
465
+ | Secret | Purpose |
466
+ |--------|--------|
467
+ | `NPM_TOKEN` | npm publish access (used by `publish.yml`) |
468
+ | `RPC_ETHEREUM_MAINNET` | Ethereum mainnet RPC URL for fork tests (used by `test.yml`) |
469
+
470
+ Fork tests require `RPC_ETHEREUM_MAINNET` — they fail if it's missing.
471
+
472
+ ### Branching
473
+
474
+ - `main` is the primary branch
475
+ - Feature branches for PRs
476
+ - All PRs trigger test + lint workflows
477
+ - Submodule checkout with `--recursive` in CI
478
+
479
+ ### Dependencies
480
+
481
+ - Solidity dependencies via npm (`node_modules/`)
482
+ - `forge-std` as a git submodule in `lib/`
483
+ - Sphinx plugins as a devDependency
484
+ - Cross-repo references use `file:../sibling-repo` in local development
485
+ - Published versions use semver ranges (`^0.0.x`) for npm
486
+
487
+ ### Contract Size Checks
488
+
489
+ 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,16 +1,14 @@
1
1
  [profile.default]
2
2
  solc = '0.8.26'
3
- evm_version = 'paris'
4
- src = 'src'
5
- out = 'out'
6
- test = 'test'
7
- libs = ["node_modules", "lib"]
3
+ evm_version = 'cancun'
4
+ via_ir = true
8
5
  optimizer_runs = 200
9
- via-ir = true
10
- build_info = true
11
- extra_output = ['storageLayout']
6
+ libs = ["node_modules", "lib"]
12
7
  fs_permissions = [{ access = "read-write", path = "./"}]
13
8
 
9
+ [profile.ci_sizes]
10
+ optimizer_runs = 200
11
+
14
12
  [rpc_endpoints]
15
13
  ethereum = "${RPC_ETHEREUM_MAINNET}"
16
14
  optimism = "${RPC_OPTIMISM_MAINNET}"
@@ -21,14 +19,14 @@ ethereum_sepolia = "${RPC_ETHEREUM_SEPOLIA}"
21
19
  optimism_sepolia = "${RPC_OPTIMISM_SEPOLIA}"
22
20
  base_sepolia = "${RPC_BASE_SEPOLIA}"
23
21
 
22
+ [fuzz]
23
+ runs = 4096
24
+
24
25
  [invariant]
25
- runs = 256
26
- depth = 50
26
+ runs = 1024
27
+ depth = 100
27
28
  fail_on_revert = false
28
29
 
29
- [lint]
30
- lint_on_build = false
31
-
32
30
  [fmt]
33
31
  number_underscore = "thousands"
34
32
  multiline_func_header = "all"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ballkidz/defifa",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": ">=20.0.0"
@@ -15,8 +15,8 @@
15
15
  "dependencies": {
16
16
  "@bananapus/721-hook-v6": "^0.0.9",
17
17
  "@bananapus/address-registry-v6": "^0.0.4",
18
- "@bananapus/core-v6": "^0.0.9",
19
- "@bananapus/permission-ids-v6": "^0.0.4",
18
+ "@bananapus/core-v6": "^0.0.10",
19
+ "@bananapus/permission-ids-v6": "^0.0.5",
20
20
  "@openzeppelin/contracts": "5.2.0",
21
21
  "@prb/math": "^4.1.1",
22
22
  "scripty.sol": "^2.1.1"