@bananapus/core-v6 0.0.34 → 0.0.36

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/ARCHITECTURE.md CHANGED
@@ -2,49 +2,75 @@
2
2
 
3
3
  ## Purpose
4
4
 
5
- `nana-core-v6` is the protocol root. It owns project identity, permissions, rulesets, token supply, treasury balances, payout limits, fee logic, and the hook interfaces that every extension repo composes with.
5
+ `nana-core-v6` is the root of the V6 stack. It owns project identity, rulesets, permissions, treasury balances, token issuance, fee behavior, payout limits, and the hook interfaces that extension repos use.
6
6
 
7
- If a change affects accounting, supply, fee behavior, terminal routing, or permission semantics, this is the repo that defines the source of truth.
7
+ If a change affects accounting, token supply, fees, terminal routing, or permission semantics, this repo is the source of truth.
8
8
 
9
- ## Boundaries
9
+ ## System Overview
10
10
 
11
- - The core owns balance and supply transitions.
12
- - Extensions may adjust economics through hooks, but they should not invent competing ledgers.
13
- - The core deliberately avoids app-specific behaviors like NFT composition, DEX routing strategy, or bridge-specific message transport.
11
+ `JBController`, `JBMultiTerminal`, and `JBTerminalStore` form the main execution and accounting path. `JBDirectory`, `JBRulesets`, `JBProjects`, `JBTokens`, `JBPermissions`, `JBSplits`, and related contracts provide routing, identity, and shared state for downstream repos.
14
12
 
15
- ## Main Components
13
+ `JBTerminalStore` is terminal-scoped through `msg.sender`, so each terminal tracks its own balances and usage while sharing the same ruleset and price surfaces. Hooks can change economics or add side effects, but they should not create a second ledger.
16
14
 
17
- | Component | Responsibility |
18
- | --- | --- |
19
- | `JBMultiTerminal` | Entry point for payments, cash outs, payouts, balance additions, and fee handling |
20
- | `JBTerminalStore` | Bookkeeping and preview math for payment, payout, allowance, and cash-out paths |
21
- | `JBController` | Project launch, ruleset queueing, token minting and burning, split-group updates |
22
- | `JBDirectory` | Maps projects to controllers and terminals |
23
- | `JBRulesets` | Time-ordered ruleset lifecycle and approval-hook integration |
24
- | `JBTokens`, `JBERC20`, `JBProjects` | Token and project identity surfaces |
25
- | `JBSplits`, `JBFundAccessLimits`, `JBPrices`, `JBPermissions` | Shared state for distribution, limits, price conversion, and authorization |
15
+ ## Core Invariants
26
16
 
27
- ## Runtime Model
17
+ - Preview functions should stay aligned with the state-changing functions they mirror.
18
+ - Data hooks run before settlement and may change economics. Pay and cash-out hooks run after settlement.
19
+ - Reserved tokens and other pending supply affect supply-sensitive math before distribution.
20
+ - Terminal balances, fee accounting, reclaim math, and surplus calculations must agree.
21
+ - Fee logic taxes value leaving the system, not every internal rebalance.
22
+ - Rulesets are time-ordered and approval-aware, and downstream deployers depend on predictable ID progression.
23
+ - Permission checks are protocol safety checks, not just UI hints.
24
+
25
+ ## Modules
26
+
27
+ | Module | Responsibility | Notes |
28
+ | --- | --- | --- |
29
+ | `JBMultiTerminal` | Payment, cash-out, payout, allowance, and fee entrypoints | Execution surface |
30
+ | `JBTerminalStore` | Shared accounting and preview math | Economic source of truth |
31
+ | `JBController` | Launch, queue rulesets, mint, burn, and update split groups | Supply and configuration |
32
+ | `JBDirectory`, `JBRulesets` | Project routing and time-based ruleset lifecycle | Coordination layer |
33
+ | `JBProjects`, `JBTokens`, `JBERC20` | Identity and token surfaces | Ownership and tokenization |
34
+ | `JBPermissions`, `JBSplits`, `JBFundAccessLimits`, `JBPrices` | Shared authorization and configuration state | Cross-repo dependencies |
35
+
36
+ ## Trust Boundaries
37
+
38
+ - This repo owns the canonical balance and supply transitions.
39
+ - Hook repos may change inputs and post-settlement behavior, but they should not replace the core ledger.
40
+ - External price feeds, Permit2, and ERC-20 behavior matter, but accounting truth still lives here.
41
+
42
+ ## Critical Flows
28
43
 
29
44
  ### Payment
30
45
 
31
46
  ```text
32
47
  terminal receives funds
33
- -> terminal store reads the current ruleset and optional data hooks
34
- -> store computes weight-based minting results
48
+ -> terminal store reads the active ruleset and optional data hooks
49
+ -> before-pay data hook can change weight and return pay-hook specs
50
+ -> terminal store records the payment in the terminal-scoped ledger
35
51
  -> controller mints beneficiary tokens and accrues reserved tokens
36
- -> pay hooks execute only after settlement
52
+ -> pay hooks run after settlement
37
53
  ```
38
54
 
39
55
  ### Cash Out
40
56
 
41
57
  ```text
42
58
  holder requests redemption
43
- -> terminal store computes reclaim amount from surplus, supply, and tax settings
44
- -> optional data hooks can adjust the calculation inputs
59
+ -> terminal store reads the current ruleset, balances, and supply inputs
60
+ -> before-cash-out data hook can change reclaim inputs and hook specs
61
+ -> terminal store records the cash out in the terminal-scoped ledger
45
62
  -> controller burns tokens
46
- -> terminal pays the reclaim amount and routes protocol fees
47
- -> cash-out hooks execute only after settlement
63
+ -> terminal pays reclaim value and routes protocol fees
64
+ -> cash-out hooks run after settlement
65
+ ```
66
+
67
+ ### Launch And Queue Rulesets
68
+
69
+ ```text
70
+ owner, operator, or omnichain ruleset operator
71
+ -> controller launches or queues rulesets
72
+ -> launch also sets the controller in the directory and configures terminals
73
+ -> rulesets become the source of truth for later pay, cash-out, and admin constraints
48
74
  ```
49
75
 
50
76
  ### Payouts And Allowances
@@ -53,32 +79,55 @@ holder requests redemption
53
79
  authorized caller
54
80
  -> consumes payout limits or surplus allowances
55
81
  -> funds move to splits, projects, hooks, or direct recipients
82
+ -> same-terminal project payouts stay inside terminal accounting and may add fee-free surplus
56
83
  ```
57
84
 
58
- ## Critical Invariants
85
+ ## Accounting Model
86
+
87
+ This repo owns the canonical ledger for balances, fees, supply-sensitive reclaim math, payout limits, allowances, reserved tokens, and preview calculations. Other repos may wrap or influence these values, but they should not duplicate them.
59
88
 
60
- - Preview functions must remain behaviorally aligned with state-changing functions.
61
- - Data hooks run before settlement and may alter the economics; pay and cash-out hooks run after settlement. That phase boundary is intentional.
62
- - Reserved tokens and pending reserves affect supply-sensitive math even before distribution.
63
- - Terminal balances, fee accounting, and surplus calculations must agree. Any drift here contaminates every product repo.
64
- - Rulesets are time-ordered and approval-aware; deployment wrappers depend on predictable ID progression and activation semantics.
65
- - Permission checks are not a UI concern. They are part of protocol state transition validity.
89
+ `JBTerminalStore` keeps terminal balances, payout-limit usage, and surplus-allowance usage. Those reset boundaries are not the same:
66
90
 
67
- ## Where Complexity Lives
91
+ - payout-limit usage is tracked by ruleset cycle number
92
+ - surplus-allowance usage is tracked by `ruleset.id`
68
93
 
69
- - `JBMultiTerminal`, `JBTerminalStore`, and `JBController` form one accounting pipeline and are easiest to misunderstand when read separately.
70
- - Preview paths deliberately mirror state-changing paths; keeping them aligned is a permanent maintenance burden.
71
- - Fee-free surplus, held fees, and payout/allowance interactions create edge cases that are small in code size but large in blast radius.
94
+ If a duration-based ruleset auto-cycles without a new ruleset ID, payout-limit usage resets but allowance usage does not.
72
95
 
73
- ## Dependencies
96
+ ## Security Model
74
97
 
75
- - `nana-permission-ids-v6` for the shared permission namespace
76
- - OpenZeppelin, PRBMath, Chainlink, and Permit2 for standards and math utilities
98
+ - Review `JBMultiTerminal`, `JBTerminalStore`, and `JBController` as one pipeline.
99
+ - `JBTerminalStore` uses shared logic with terminal-scoped state. Misreading that split leads to bad accounting assumptions.
100
+ - Small changes in fee or surplus logic can affect every downstream repo.
101
+ - Same-terminal project payouts, fee-free surplus capping, and migration cleanup are coupled.
102
+ - `allowOwnerMinting` is not a universal mint kill switch. Other allowed paths can still mint.
103
+ - Hook ordering and preview-execution alignment are ongoing maintenance requirements.
77
104
 
78
105
  ## Safe Change Guide
79
106
 
80
- - Start any nontrivial change by tracing both the preview path and the state-changing path.
81
- - Read downstream hook repos before changing hook interfaces or metadata expectations.
82
- - Keep fee logic, balance logic, and surplus logic in sync; "small" tweaks here are almost always ecosystem-wide changes.
83
- - When adding permissions or changing who is checked against a permission, update ecosystem docs and downstream assumptions immediately.
84
- - If a change seems local inside core, assume it is not until proven otherwise.
107
+ - Trace both the preview path and the state-changing path for any nontrivial change.
108
+ - Read downstream hook repos before changing hook metadata or interface expectations.
109
+ - Keep fee logic, balance logic, reclaim math, and surplus math in sync.
110
+ - If you change same-terminal payouts between projects, re-check self-pay reverts, fee-free surplus accumulation, and post-pay caps.
111
+ - If you change ruleset rollover semantics, re-check which counters reset on cycle progression versus new ruleset IDs.
112
+ - If permissions change, update shared docs and downstream assumptions at the same time.
113
+
114
+ ## Canonical Checks
115
+
116
+ - fee-free surplus and same-terminal payout behavior:
117
+ `test/TestFeeFreeCashOutBypass.sol`
118
+ - migration and terminal-accounting continuity:
119
+ `test/TestTerminalMigration.sol`
120
+ - ruleset ordering and transition behavior:
121
+ `test/RulesetTransitions.t.sol`
122
+
123
+ ## Source Map
124
+
125
+ - `src/JBController.sol`
126
+ - `src/JBMultiTerminal.sol`
127
+ - `src/JBTerminalStore.sol`
128
+ - `src/JBDirectory.sol`
129
+ - `src/JBRulesets.sol`
130
+ - `src/JBPermissions.sol`
131
+ - `test/TestFeeFreeCashOutBypass.sol`
132
+ - `test/TestTerminalMigration.sol`
133
+ - `test/RulesetTransitions.t.sol`
@@ -1,10 +1,11 @@
1
1
  # Audit Instructions
2
2
 
3
- This is the core Juicebox V6 protocol. Most ecosystem invariants reduce to this repo eventually.
3
+ This is the core Juicebox V6 protocol. Most ecosystem invariants eventually reduce to this repo.
4
4
 
5
- ## Objective
5
+ ## Audit Objective
6
6
 
7
7
  Find issues that:
8
+
8
9
  - break terminal solvency or internal accounting
9
10
  - let projects extract more than payout or surplus-allowance limits
10
11
  - miscompute payment minting, reserved tokens, or cash-out reclaim amounts
@@ -14,11 +15,13 @@ Find issues that:
14
15
  ## Scope
15
16
 
16
17
  In scope:
18
+
17
19
  - all Solidity under `src/`
18
20
  - deployment scripts in `script/`
19
21
  - price-feed setup and periphery contracts under `src/periphery/`
20
22
 
21
23
  Especially critical contracts:
24
+
22
25
  - `JBMultiTerminal`
23
26
  - `JBTerminalStore`
24
27
  - `JBController`
@@ -32,6 +35,7 @@ Especially critical contracts:
32
35
  ## Start Here
33
36
 
34
37
  For the fastest serious review, read in this order:
38
+
35
39
  - `JBTerminalStore`
36
40
  - `JBMultiTerminal`
37
41
  - `JBController`
@@ -39,112 +43,97 @@ For the fastest serious review, read in this order:
39
43
  - `JBPermissions`
40
44
  - `JBPrices`
41
45
 
42
- That order mirrors how most high-severity issues emerge:
46
+ That order mirrors how most high-severity issues appear:
47
+
43
48
  - accounting is computed
44
- - funds are moved
45
- - tokens are minted or burned
46
- - permissions and price context decide whether the move was legitimate
49
+ - funds move
50
+ - tokens mint or burn
51
+ - permissions and price context determine whether the move is allowed
47
52
 
48
- ## System Model
53
+ ## Security Model
49
54
 
50
55
  Core roles:
56
+
51
57
  - `JBMultiTerminal`: holds funds and executes pay, payout, cash-out, allowance, and fee-processing flows
52
- - `JBTerminalStore`: accounting and surplus logic
53
- - `JBController`: project lifecycle, token mint/burn, and permissions-sensitive operations
54
- - `JBRulesets`: current and queued economic parameters
55
- - `JBTokens`: ERC-20 and credit accounting
56
- - `JBPermissions`: access-control backbone
58
+ - `JBTerminalStore`: owns accounting and surplus logic
59
+ - `JBController`: owns project lifecycle, token mint and burn, and permission-sensitive operations
60
+ - `JBRulesets`: stores current and queued economic parameters
61
+ - `JBTokens`: handles ERC-20 and credit accounting
62
+ - `JBPermissions`: provides the access-control backbone
63
+
64
+ Extension points:
57
65
 
58
- The rest of the ecosystem plugs into these extension points:
59
66
  - data hooks
60
67
  - pay hooks
61
68
  - cash-out hooks
62
69
  - split hooks
63
70
  - approval hooks
64
71
 
65
- Core ordering to keep in mind:
66
- - store records accounting before terminal fulfillment finishes
67
- - controller mint and burn operations happen around terminal flows, not as a separate settlement layer
68
- - hooks can turn what looks like a simple pay or cash-out into a multi-contract composition
69
-
70
- ## Critical Invariants
72
+ Ordering to keep in mind:
71
73
 
72
- 1. Terminal solvency
73
- Internal balances and held-fee obligations must reconcile with actual terminal token balances.
74
+ - the store records accounting before terminal fulfillment is finished
75
+ - controller mint and burn operations happen inside terminal flows, not in a separate settlement layer
76
+ - hooks can turn a simple pay or cash-out into a multi-contract flow
74
77
 
75
- 2. No over-withdrawal
76
- Payouts and allowance usage must never exceed configured per-cycle limits.
78
+ ## Roles And Privileges
77
79
 
78
- 3. Cash-out correctness
79
- Surplus, total supply, tax rate, fee treatment, and hook overrides must combine into the intended reclaim amount.
80
+ | Role | Powers | How constrained |
81
+ |------|--------|-----------------|
82
+ | Project owner and operators | Configure rulesets, limits, routing, and permissions | Must stay inside the explicit permission model |
83
+ | Terminal | Hold funds and execute settlement | Must stay solvent relative to internal accounting |
84
+ | Controller | Mint, burn, and manage project lifecycle | Must not bypass project-scoped authorization |
85
+ | Hooks and splits | Extend pay and cash-out behavior | Must not make previews and accounting irreconcilable |
80
86
 
81
- 4. Ruleset integrity
82
- The active ruleset and any fallback or cycling behavior must reflect exact timing and approval-hook semantics.
87
+ ## Integration Assumptions
83
88
 
84
- 5. Token accounting consistency
85
- Credits, ERC-20 total supply, reserved token balance, and burn/mint paths must remain internally coherent.
89
+ | Dependency | Assumption | What breaks if wrong |
90
+ |------------|------------|----------------------|
91
+ | Price feeds | Currency conversions are fresh and coherent | Cross-currency flows misprice |
92
+ | Hook ecosystem | External hooks obey documented interfaces | Settlement becomes unsafe after control transfer |
93
+ | Directory and migration surfaces | Canonical routing changes are authentic | Funds or permissions shift to the wrong place |
86
94
 
87
- 6. Privilege containment
88
- Permissions, wildcard grants, controller migration, and terminal routing must not allow unauthorized project control or fund movement.
89
-
90
- 7. Held-fee correctness
91
- When fee payment is deferred, later replenishment or migration behavior must not accidentally forgive, duplicate, or cross-charge the obligation.
92
-
93
- 8. Preview coherence
94
- `previewPayFor` and `previewCashOutFrom` should not become meaningfully inconsistent with execution in ways downstream repos can exploit.
95
-
96
- ## Threat Model
97
-
98
- Prioritize:
99
- - hook-driven reentrancy or state-ordering issues
100
- - price-feed failure and cross-currency conversions
101
- - fee-processing failure paths
102
- - migration and feeless-address edge cases
103
- - ruleset-boundary timing attacks
104
- - wildcard or root permission escalation
105
-
106
- The highest-yield attacker mindsets here are:
107
- - a malicious hook that receives control after balances move but before the full user flow is conceptually finished
108
- - a project owner exploiting migration, limits, or feeless settings rather than breaking access control directly
109
- - a cross-currency user extracting value from rounding or stale price conversions
95
+ ## Critical Invariants
110
96
 
111
- ## Hotspots
97
+ 1. Terminal solvency
98
+ Internal balances and held-fee obligations must reconcile with actual terminal token balances.
99
+ 2. No over-withdrawal
100
+ Payouts and allowance usage must never exceed configured per-cycle limits.
101
+ 3. Cash-out correctness
102
+ Surplus, total supply, tax rate, fee treatment, and hook overrides must combine into the intended reclaim amount.
103
+ 4. Ruleset integrity
104
+ The active ruleset and any fallback or cycling behavior must match exact timing and approval-hook semantics.
105
+ 5. Token accounting consistency
106
+ Credits, ERC-20 total supply, reserved token balance, and burn/mint paths must stay coherent.
107
+ 6. Privilege containment
108
+ Permissions, wildcard grants, controller migration, and terminal routing must not allow unauthorized control or fund movement.
109
+ 7. Held-fee correctness
110
+ Deferred fees must not be accidentally forgiven, duplicated, or charged to the wrong place.
111
+ 8. Preview coherence
112
+ `previewPayFor` and `previewCashOutFrom` should not drift from execution in ways downstream repos can exploit.
113
+
114
+ ## Attack Surfaces
112
115
 
113
116
  - `pay`, `cashOutTokensOf`, `sendPayoutsOf`, and `useAllowanceOf`
114
117
  - `preview*` paths when downstream repos treat them as execution truth
115
118
  - held-fee lifecycle and `_processFee`
116
119
  - surplus aggregation across terminals
117
120
  - controller migration and terminal migration
118
- - `setPermissionsFor` and any wildcard semantics
121
+ - `setPermissionsFor` and wildcard semantics
119
122
 
120
- ## Sequences Worth Replaying
123
+ Replay these sequences:
121
124
 
122
- 1. `pay` with a data hook that returns altered weight and hook specs, then re-enter through a pay hook.
123
- 2. `cashOutTokensOf` when `useTotalSurplusForCashOuts` or cross-terminal surplus logic matters.
124
- 3. `sendPayoutsOf` into splits that route to another project, hook, or failing beneficiary.
125
- 4. held-fee accumulation -> migration or balance depletion -> `processHeldFeesOf`.
126
- 5. permission grants involving operators, wildcard project IDs, or later controller changes.
125
+ 1. `pay` with a data hook that changes weight or hook specs and then reenters through a pay hook
126
+ 2. `cashOutTokensOf` when cross-terminal surplus and `useTotalSurplusForCashOuts` matter
127
+ 3. `sendPayoutsOf` into splits that route to another project, hook, or failing beneficiary
128
+ 4. held-fee accumulation followed by migration or balance depletion
129
+ 5. permission grants involving operators, wildcard project IDs, or later controller changes
127
130
 
128
- ## Finding Bar
131
+ ## Accepted Risks Or Behaviors
129
132
 
130
- The best findings in this repo usually prove one of these:
131
- - the store records more value than the terminal can safely honor
132
- - a limit is consumed too late, after externally controlled code can already profit
133
- - a migration or held-fee edge path changes who ultimately bears an obligation
134
- - permissions that look project-scoped become ecosystem-relevant through wildcard or routing semantics
133
+ - Hooks are intentionally powerful. Safety comes from clear ordering and bounded trust, not from avoiding composition.
135
134
 
136
- ## Build And Verification
135
+ ## Verification
137
136
 
138
- Standard workflow:
139
137
  - `npm install`
140
138
  - `forge build`
141
139
  - `forge test`
142
-
143
- The current test suite already targets:
144
- - flash-loan and economic exploits
145
- - permissions invariants
146
- - ruleset transitions
147
- - fee and migration edge cases
148
- - multi-token and cross-currency surplus behavior
149
-
150
- The highest-value findings in this repo are the ones that make downstream hooks or deployers unsafe even when those repos are otherwise correct.
package/README.md CHANGED
@@ -1,43 +1,48 @@
1
1
  # Juicebox Core V6
2
2
 
3
- `@bananapus/core-v6` is the core protocol package for Juicebox on EVM chains. It defines projects, rulesets, terminals, permissions, token issuance, cash outs, splits, price feeds, and the accounting surfaces that the rest of the V6 ecosystem builds on.
3
+ `@bananapus/core-v6` is the base protocol package for Juicebox on EVM chains. It defines projects, rulesets, terminals, permissions, token issuance, cash outs, splits, price feeds, and the accounting that the rest of the V6 ecosystem builds on.
4
4
 
5
5
  Docs: <https://docs.juicebox.money>
6
- Architecture: [ARCHITECTURE.md](./ARCHITECTURE.md)
6
+ Architecture: [ARCHITECTURE.md](./ARCHITECTURE.md)
7
+ User journeys: [USER_JOURNEYS.md](./USER_JOURNEYS.md)
8
+ Skills: [SKILLS.md](./SKILLS.md)
9
+ Risks: [RISKS.md](./RISKS.md)
10
+ Administration: [ADMINISTRATION.md](./ADMINISTRATION.md)
11
+ Audit instructions: [AUDIT_INSTRUCTIONS.md](./AUDIT_INSTRUCTIONS.md)
7
12
 
8
13
  ## Overview
9
14
 
10
- If a V6 package moves value, mints tokens, checks permissions, or reasons about project configuration, it almost certainly depends on this repo.
15
+ If a V6 package moves value, mints tokens, checks permissions, or reads project configuration, it probably depends on this repo.
11
16
 
12
- The core package provides:
17
+ This package provides:
13
18
 
14
19
  - project ownership and metadata through `JBProjects`
15
20
  - ruleset lifecycle management through `JBRulesets`
16
- - issuance, queueing, token setup, and splits through `JBController`
21
+ - token issuance, ruleset queueing, token setup, and splits through `JBController`
17
22
  - multi-token terminal accounting through `JBMultiTerminal` and `JBTerminalStore`
18
23
  - operator permissions through `JBPermissions`
19
24
  - on-chain price-feed routing through `JBPrices`
20
25
 
21
- Use this repo when you need the canonical protocol invariant. Do not duplicate its logic in downstream packages unless the repo is explicitly intended to wrap or extend the core surface.
26
+ Use this repo when you need the protocol's canonical accounting and execution logic. Do not copy that logic into downstream repos unless the repo is explicitly meant to wrap or extend core.
22
27
 
23
- If you only read one repo before auditing the rest of the ecosystem, read this one.
28
+ If you only read one V6 repo before reading the rest, read this one.
24
29
 
25
30
  ## Mental Model
26
31
 
27
- The core protocol is easiest to reason about in four layers:
32
+ It helps to think about core in four layers:
28
33
 
29
34
  1. identity and configuration: `JBProjects`, `JBDirectory`, `JBRulesets`
30
35
  2. execution: `JBController` and `JBMultiTerminal`
31
36
  3. accounting: `JBTerminalStore`
32
- 4. permissions and external context: `JBPermissions`, `JBPrices`, feeless-address and deadline helpers
37
+ 4. permissions and shared context: `JBPermissions`, `JBPrices`, feeless-address and deadline helpers
33
38
 
34
- Most integrations touch only layer 2. Most economically important bugs leak through layer 3.
39
+ Many integrations mostly touch layer 2. Many high-impact bugs are easier to understand in layer 3.
35
40
 
36
- The shortest path through the repo is:
41
+ The shortest reading path is:
37
42
 
38
43
  1. `JBController` for project launch and ruleset configuration
39
- 2. `JBMultiTerminal` for execution entrypoints
40
- 3. `JBTerminalStore` for economic truth
44
+ 2. `JBMultiTerminal` for user-facing execution entrypoints
45
+ 3. `JBTerminalStore` for the accounting model
41
46
  4. `JBDirectory` and `JBPermissions` for routing and authority
42
47
 
43
48
  ## Read These Files First
@@ -53,30 +58,38 @@ The shortest path through the repo is:
53
58
 
54
59
  | Contract | Role |
55
60
  | --- | --- |
56
- | `JBController` | Project launch, ruleset queueing, token configuration, and split management. |
57
- | `JBMultiTerminal` | Main payment, payout, allowance, and cash-out terminal surface. |
58
- | `JBTerminalStore` | Shared accounting store for balances, surplus, fees, and reclaim calculations. |
59
- | `JBDirectory` | Project-to-controller and project-to-terminal routing registry. |
61
+ | `JBController` | Launches projects, queues rulesets, configures tokens, and manages split groups. |
62
+ | `JBMultiTerminal` | Main payment, payout, allowance, and cash-out surface. |
63
+ | `JBTerminalStore` | Shared accounting for balances, surplus, fees, and reclaim math. |
64
+ | `JBDirectory` | Registry for controller and terminal routing. |
60
65
  | `JBProjects` | ERC-721 project registry and ownership surface. |
61
- | `JBPermissions` | Packed operator permissions registry. |
62
- | `JBPrices` | Price feed routing used by terminals and integrations. |
66
+ | `JBPermissions` | Packed operator-permission registry. |
67
+ | `JBPrices` | Price-feed routing used by terminals and integrations. |
63
68
 
64
69
  ## Integration Traps
65
70
 
66
- - `JBMultiTerminal` is not a single-token terminal. Integrations that assume one token, one balance, or one primary path usually misread the accounting model.
67
- - data hooks and cash-out hooks are not cosmetic. They can change effective issuance, reclaim value, and side effects on the path.
68
- - permission checks are not always against the project owner. Some flows are scoped to the token holder instead.
69
- - previews and execution are intentionally close, but integrators should still treat them as distinct surfaces when hooks or dynamic routing are involved.
71
+ - `JBMultiTerminal` is multi-token and multi-terminal. Do not assume one token or one balance.
72
+ - Data hooks and cash-out hooks can change economics and side effects. They are part of the protocol surface.
73
+ - Permission checks are not always against the project owner. Some flows are scoped to the token holder instead.
74
+ - Preview and execution are intentionally close, but callers should still treat them as separate surfaces when hooks or routing can change behavior.
70
75
 
71
76
  ## Where State Lives
72
77
 
73
- - project identity and ownership live in `JBProjects`
74
- - controller and terminal routing live in `JBDirectory`
75
- - ruleset history and activation live in `JBRulesets`
76
- - balances, surplus, fees, and reclaim accounting live in `JBTerminalStore`
77
- - operator authority lives in `JBPermissions`
78
+ - project identity and ownership: `JBProjects`
79
+ - controller and terminal routing: `JBDirectory`
80
+ - ruleset history and activation: `JBRulesets`
81
+ - balances, surplus, fees, and reclaim accounting: `JBTerminalStore`
82
+ - operator authority: `JBPermissions`
78
83
 
79
- When in doubt, read the state-owning contract before the contract that merely forwards into it.
84
+ When a flow is unclear, read the contract that owns the state before the contract that forwards into it.
85
+
86
+ ## High-Signal Tests
87
+
88
+ 1. `test/TestPayBurnRedeemFlow.sol`
89
+ 2. `test/TestTerminalPreviewParity.sol`
90
+ 3. `test/invariants/TerminalStoreInvariant.t.sol`
91
+ 4. `test/invariants/RulesetsInvariant.t.sol`
92
+ 5. `test/audit/CrossTerminalSurplusSpoof.t.sol`
80
93
 
81
94
  ## Install
82
95
 
@@ -102,7 +115,7 @@ Useful scripts:
102
115
 
103
116
  ## Deployment Notes
104
117
 
105
- This repo contains both core deployments and periphery deployment helpers. Most other V6 packages assume these contracts exist first and treat them as the stable base layer of the ecosystem.
118
+ This repo contains the main core deployments and periphery deployment helpers. Most other V6 packages assume these contracts exist first and treat them as the stable base layer.
106
119
 
107
120
  ## Repository Layout
108
121
 
@@ -119,9 +132,15 @@ script/
119
132
 
120
133
  ## Risks And Notes
121
134
 
122
- - hooks can meaningfully change payment and cash-out behavior, so core integrations must treat hook composition as part of the protocol surface
123
- - permissions are flexible enough to be dangerous when scoped broadly or granted with wildcard project IDs
124
- - multi-terminal and multi-token accounting is powerful but increases the chance of integration mistakes when callers assume a single-terminal model
125
- - fee, surplus, and reclaim logic are economically sensitive and remain high-priority audit surfaces
135
+ - Hooks can materially change payment and cash-out behavior.
136
+ - Permissions are flexible, which makes broad or wildcard grants risky.
137
+ - Multi-terminal and multi-token accounting is powerful, but it is easy to misuse if an integration assumes a single-terminal model.
138
+ - Fee, surplus, and reclaim logic stay high-priority audit areas.
139
+
140
+ The easiest way to misread V6 is to treat core like a simple crowdfunding terminal. It is closer to a configurable accounting and settlement layer.
141
+
142
+ ## For AI Agents
126
143
 
127
- The fastest way to misunderstand V6 is to treat the core contracts like a simple crowdfunding terminal. They are closer to a configurable accounting and settlement substrate.
144
+ - Start with `JBController`, `JBMultiTerminal`, and `JBTerminalStore`.
145
+ - Keep controller configuration, terminal execution, and store accounting separate in your mental model.
146
+ - If hooks are involved, inspect the hook repo before treating preview or execution behavior as final.