@bananapus/core-v6 0.0.35 → 0.0.37

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/ADMINISTRATION.md CHANGED
@@ -7,30 +7,30 @@
7
7
  | Scope | Core Juicebox V6 control plane: directory, controller, terminals, permissions, prices, and global protocol switches |
8
8
  | Control posture | Mixed protocol-owner, project-owner, delegated-operator, controller, and terminal control |
9
9
  | Highest-risk actions | Controller migration, terminal migration, token binding, price-feed installation, and broad permission grants |
10
- | Recovery posture | Project-local mistakes may be fixable if rulesets permit; immutable infra mistakes usually require replacement layers and migration |
10
+ | Recovery posture | Project-local mistakes may be fixable if rulesets allow it; immutable infra mistakes usually require replacement and migration |
11
11
 
12
12
  ## Purpose
13
13
 
14
- `nana-core-v6` is the largest control plane in the stack. It combines protocol-owned contracts, project-local ownership, delegated operators through `JBPermissions`, and ruleset flags that selectively permit or forbid changes. This file is about who can still change project behavior once the core is live.
14
+ `nana-core-v6` is the main control plane in the stack. It mixes protocol-owned contracts, project-local ownership, delegated operators through `JBPermissions`, and ruleset flags that allow or block changes. This file explains who can still change project behavior after core is live.
15
15
 
16
16
  ## Control Model
17
17
 
18
18
  - Protocol-wide `Ownable` surfaces exist on `JBDirectory`, `JBProjects`, `JBPrices`, and `JBFeelessAddresses`.
19
- - Project-local control runs through the project NFT owner in `JBProjects`.
20
- - Fine-grained operator delegation runs through `JBPermissions`.
21
- - Controllers and terminals are privileged system callers once the directory points to them.
22
- - Current ruleset flags can further allow or deny certain owner or operator actions.
19
+ - Project-local control comes from the project NFT owner in `JBProjects`.
20
+ - Fine-grained operator delegation comes from `JBPermissions`.
21
+ - Controllers and terminals become privileged system callers once the directory points to them.
22
+ - The current ruleset can further allow or deny owner or operator actions.
23
23
 
24
24
  ## Roles
25
25
 
26
26
  | Role | How Assigned | Scope | Notes |
27
27
  | --- | --- | --- | --- |
28
- | Project owner | `JBProjects.ownerOf(projectId)` | Per project | Root human control surface for a project |
28
+ | Project owner | `JBProjects.ownerOf(projectId)` | Per project | Main human control surface |
29
29
  | Project operator | `JBPermissions` grant | Per project or wildcard | Can be narrow or dangerously broad |
30
30
  | Controller | `JBDirectory.controllerOf(projectId)` | Per project | Manages rulesets, token setup, splits, and fund-access config |
31
- | Terminal | `JBDirectory` terminal set | Per project | Can move funds through `JBTerminalStore` and terminal entrypoints |
32
- | Protocol owner | `Ownable(owner)` on protocol-wide contracts | Global | Different contracts have different owners |
33
- | Omnichain ruleset operator | `JBController` constructor immutable | Global or broad | Bypasses some ordinary owner paths for synchronized ruleset flows |
31
+ | Terminal | `JBDirectory` terminal set | Per project | Moves funds through `JBTerminalStore` and terminal entrypoints |
32
+ | Protocol owner | `Ownable(owner)` on protocol-wide contracts | Global | Different contracts can have different owners |
33
+ | Omnichain ruleset operator | `JBController` constructor immutable | Global or broad | Bypasses some owner checks for synchronized ruleset flows |
34
34
 
35
35
  ## Privileged Surfaces
36
36
 
@@ -44,48 +44,48 @@ High-value admin functions include:
44
44
  - `JBFeelessAddresses.setFeelessAddress(...)`
45
45
  - `JBProjects.setTokenUriResolver(...)`
46
46
 
47
- The most important practical distinction is:
47
+ The practical split is simple:
48
48
 
49
49
  - protocol owners change global infrastructure or defaults
50
- - project owners and their operators change project configuration
51
- - controllers and terminals are trusted system actors once the directory points to them
50
+ - project owners and operators change project configuration
51
+ - controllers and terminals act with the authority core gives them
52
52
 
53
- ## Immutable And One-Way
53
+ ## Immutable And One-Way Decisions
54
54
 
55
55
  - Default or project-specific price feeds are write-once for a given pair.
56
- - ERC-20 token binding decisions for a project are effectively one-time.
56
+ - ERC-20 token binding for a project is effectively one-time.
57
57
  - The fee beneficiary project ID inside `JBMultiTerminal` is hardcoded.
58
- - Constructor immutables on controller, directory, terminal, store, prices, and tokens are not patchable.
58
+ - Constructor immutables on controller, directory, terminal, store, prices, and tokens cannot be patched.
59
59
 
60
60
  ## Operational Notes
61
61
 
62
- - Use narrow project-scoped permissions instead of wildcard or ROOT permissions whenever possible.
63
- - Validate whether the active ruleset allows the change before assuming the owner or operator can perform it.
64
- - Treat controller migration, terminal migration, token deployment, and price-feed installation as control-plane changes with large blast radius.
62
+ - Use narrow project-scoped permissions instead of wildcard or ROOT permissions when possible.
63
+ - Check whether the active ruleset allows the change before assuming the owner or operator can make it.
64
+ - Treat controller migration, terminal migration, token deployment, and price-feed installation as high-blast-radius control-plane changes.
65
65
  - Read both the permission check and the current ruleset flags before concluding an action is allowed.
66
- - Keep an eye on fee-route and payout-path failure semantics: some failures are intentionally caught so funds stay recoverable instead of being permanently trapped.
66
+ - Keep fee-route and payout-path failure semantics in mind. Some failures restore project balance instead of trapping funds.
67
67
 
68
68
  ## Machine Notes
69
69
 
70
- - Do not infer authority from project ownership alone; many paths also depend on the active ruleset and permission bitmap.
71
- - Treat `JBDirectory`, `JBController`, `JBMultiTerminal`, `JBPermissions`, `JBPrices`, `JBFeelessAddresses`, and `JBProjects` as the minimum source-of-truth set for control-plane crawling.
70
+ - Do not infer authority from project ownership alone. Many paths also depend on the active ruleset and permission bitmap.
71
+ - Treat `JBDirectory`, `JBController`, `JBMultiTerminal`, `JBPermissions`, `JBPrices`, `JBFeelessAddresses`, and `JBProjects` as the minimum control-plane source set.
72
72
  - If a controller, terminal, or price-feed action is not backed by the exact current directory entry, stop and resolve the mismatch first.
73
73
  - If a permission is not named explicitly in the call path, inspect the contract check before assuming delegated authority exists.
74
- - If a fee route or split payout failed, inspect whether the core intentionally restored project balance or left a retry path before calling it a permanent loss.
74
+ - If a fee route or split payout failed, check whether core restored balance or left a retry path before calling it a permanent loss.
75
75
 
76
76
  ## Recovery
77
77
 
78
- - Wrong immutable infra usually means a new controller, terminal, store, or price layer and then migration.
79
- - Wrong project-local config can often be corrected if the current ruleset still permits the change.
80
- - Wrong wildcard permissions are fixable only by updating the permission bitmap; they are dangerous mainly because of what can happen before revocation.
81
- - Some fee-route and payout-route failures are recoverable in place because the core prefers restoring balance and preserving retry paths over trapping funds.
78
+ - Wrong immutable infrastructure usually means deploying a new controller, terminal, store, or price layer and then migrating.
79
+ - Wrong project-local config can often be corrected if the current ruleset still allows it.
80
+ - Wrong wildcard permissions are fixed by updating the permission bitmap, but they are dangerous because of what can happen before revocation.
81
+ - Some fee-route and payout-route failures are recoverable in place because core prefers liveness over trapped funds.
82
82
 
83
83
  ## Admin Boundaries
84
84
 
85
85
  - Protocol owners cannot directly rewrite project economics without going through the contracts and ruleset constraints that enforce those changes.
86
86
  - Project owners cannot bypass immutable constructor references or rewrite existing price-feed entries.
87
- - Controllers and terminals only have the authority the directory and core contracts give them; they do not get arbitrary global power.
88
- - Nobody can change the hardcoded fee beneficiary or retroactively patch immutable deployment mistakes in place.
87
+ - Controllers and terminals only have the authority given by the directory and core contracts.
88
+ - Nobody can change the hardcoded fee beneficiary or patch immutable deployment mistakes in place.
89
89
 
90
90
  ## Source Map
91
91
 
package/ARCHITECTURE.md CHANGED
@@ -2,40 +2,42 @@
2
2
 
3
3
  ## Purpose
4
4
 
5
- `nana-core-v6` is the protocol root for the V6 stack. It owns project identity, rulesets, permissions, treasury balances, token issuance, fee behavior, payout limits, and the hook interfaces 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 logic, terminal routing, or permission semantics, this repo is 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
9
  ## System Overview
10
10
 
11
- `JBController`, `JBMultiTerminal`, and `JBTerminalStore` form the main execution and accounting pipeline. `JBDirectory`, `JBRulesets`, `JBProjects`, `JBTokens`, `JBPermissions`, `JBSplits`, and related contracts provide the routing, identity, and shared state that all downstream repos depend on. `JBTerminalStore` is terminal-scoped through `msg.sender`, so each terminal records its own balances and usage against the shared ruleset and price surfaces. Extensions may influence economics through hook interfaces, but they should not create competing ledgers.
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.
12
+
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.
12
14
 
13
15
  ## Core Invariants
14
16
 
15
- - Preview functions must remain behaviorally aligned with state-changing functions.
16
- - Data hooks run before settlement and may alter economics; pay and cash-out hooks run after settlement.
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.
17
19
  - Reserved tokens and other pending supply affect supply-sensitive math before distribution.
18
20
  - Terminal balances, fee accounting, reclaim math, and surplus calculations must agree.
19
- - Fee logic taxes fund egress, not every internal rebalance. Same-terminal project routing is a special case and must stay coherent with fee-free surplus tracking.
20
- - Rulesets are time-ordered and approval-aware, and many deployer repos depend on predictable ID progression.
21
- - Permission checks are protocol validity checks, not UI affordances.
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.
22
24
 
23
25
  ## Modules
24
26
 
25
27
  | Module | Responsibility | Notes |
26
28
  | --- | --- | --- |
27
- | `JBMultiTerminal` | Payment, cash-out, payout, allowance, and fee entrypoint | Execution surface |
29
+ | `JBMultiTerminal` | Payment, cash-out, payout, allowance, and fee entrypoints | Execution surface |
28
30
  | `JBTerminalStore` | Shared accounting and preview math | Economic source of truth |
29
- | `JBController` | Launch, queue rulesets, mint, burn, and split-group updates | Supply and configuration |
31
+ | `JBController` | Launch, queue rulesets, mint, burn, and update split groups | Supply and configuration |
30
32
  | `JBDirectory`, `JBRulesets` | Project routing and time-based ruleset lifecycle | Coordination layer |
31
33
  | `JBProjects`, `JBTokens`, `JBERC20` | Identity and token surfaces | Ownership and tokenization |
32
34
  | `JBPermissions`, `JBSplits`, `JBFundAccessLimits`, `JBPrices` | Shared authorization and configuration state | Cross-repo dependencies |
33
35
 
34
36
  ## Trust Boundaries
35
37
 
36
- - This repo owns canonical balance and supply transitions.
37
- - Hook repos may adjust inputs and post-settlement side effects, but they should not replace the ledger defined here.
38
- - External price feeds, Permit2, and ERC-20 behavior are dependencies, but accounting truth stays in core.
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.
39
41
 
40
42
  ## Critical Flows
41
43
 
@@ -44,22 +46,22 @@ If a change affects accounting, supply, fee logic, terminal routing, or permissi
44
46
  ```text
45
47
  terminal receives funds
46
48
  -> terminal store reads the active ruleset and optional data hooks
47
- -> before-pay data hook can modify weight and return pay-hook specs
48
- -> terminal store records payment against the terminal-scoped ledger
49
+ -> before-pay data hook can change weight and return pay-hook specs
50
+ -> terminal store records the payment in the terminal-scoped ledger
49
51
  -> controller mints beneficiary tokens and accrues reserved tokens
50
- -> pay hooks run only after settlement
52
+ -> pay hooks run after settlement
51
53
  ```
52
54
 
53
55
  ### Cash Out
54
56
 
55
57
  ```text
56
58
  holder requests redemption
57
- -> terminal store reads current ruleset, balances, and supply inputs
58
- -> before-cash-out data hook can modify reclaim inputs and hook specs
59
- -> terminal store records the cash out against the terminal-scoped ledger
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
60
62
  -> controller burns tokens
61
63
  -> terminal pays reclaim value and routes protocol fees
62
- -> cash-out hooks run only after settlement
64
+ -> cash-out hooks run after settlement
63
65
  ```
64
66
 
65
67
  ### Launch And Queue Rulesets
@@ -67,8 +69,8 @@ holder requests redemption
67
69
  ```text
68
70
  owner, operator, or omnichain ruleset operator
69
71
  -> controller launches or queues rulesets
70
- -> launch path also sets the controller in the directory and configures terminals
71
- -> rulesets become the source of truth for subsequent pay, cash-out, and admin constraints
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
72
74
  ```
73
75
 
74
76
  ### Payouts And Allowances
@@ -77,31 +79,36 @@ owner, operator, or omnichain ruleset operator
77
79
  authorized caller
78
80
  -> consumes payout limits or surplus allowances
79
81
  -> funds move to splits, projects, hooks, or direct recipients
80
- -> same-terminal project payouts stay inside terminal accounting, may accrue fee-free surplus, and must not accidentally mint against the payer's own balance
82
+ -> same-terminal project payouts stay inside terminal accounting and may add fee-free surplus
81
83
  ```
82
84
 
83
85
  ## Accounting Model
84
86
 
85
- 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 none should duplicate them.
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.
88
+
89
+ `JBTerminalStore` keeps terminal balances, payout-limit usage, and surplus-allowance usage. Those reset boundaries are not the same:
90
+
91
+ - payout-limit usage is tracked by ruleset cycle number
92
+ - surplus-allowance usage is tracked by `ruleset.id`
86
93
 
87
- `JBTerminalStore` keeps terminal balances, payout-limit usage, and surplus-allowance usage. That state is terminal-scoped, but not all reset boundaries are the same: payout-limit usage is tracked by ruleset cycle number, while surplus-allowance usage is tracked by `ruleset.id`. Auto-cycling a duration-based ruleset does not reset allowance usage; queueing a new ruleset does.
94
+ If a duration-based ruleset auto-cycles without a new ruleset ID, payout-limit usage resets but allowance usage does not.
88
95
 
89
96
  ## Security Model
90
97
 
91
- - `JBMultiTerminal`, `JBTerminalStore`, and `JBController` should be reviewed as one pipeline.
92
- - `JBTerminalStore` is shared logic but terminal-scoped state. Misunderstanding that split causes bad accounting assumptions.
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.
93
100
  - Small changes in fee or surplus logic can affect every downstream repo.
94
- - Same-terminal project payouts, fee-free surplus capping, and migration cleanup are coupled. Changing one without the others creates fee bypasses or overcharges.
95
- - `allowOwnerMinting` is not a universal mint kill switch. Terminals, the current data hook, and hook-authorized callers can still mint through the controller path.
96
- - Hook ordering and preview-execution alignment are permanent maintenance obligations.
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.
97
104
 
98
105
  ## Safe Change Guide
99
106
 
100
- - Trace both preview and state-changing paths for any nontrivial change.
107
+ - Trace both the preview path and the state-changing path for any nontrivial change.
101
108
  - Read downstream hook repos before changing hook metadata or interface expectations.
102
- - Keep fee logic, balance logic, reclaim math, and surplus math synchronized.
103
- - If you change payouts between projects on the same terminal, re-check self-pay revert behavior, fee-free surplus accumulation, and the post-pay cap against recorded balance.
104
- - If you change ruleset rollover semantics, re-check which usage counters reset on cycle progression versus new ruleset IDs.
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.
105
112
  - If permissions change, update shared docs and downstream assumptions at the same time.
106
113
 
107
114
  ## Canonical Checks
@@ -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
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,40 +43,44 @@ 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
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
72
+ Ordering to keep in mind:
73
+
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
69
77
 
70
78
  ## Roles And Privileges
71
79
 
72
80
  | Role | Powers | How constrained |
73
81
  |------|--------|-----------------|
74
82
  | Project owner and operators | Configure rulesets, limits, routing, and permissions | Must stay inside the explicit permission model |
75
- | Terminal | Hold funds and execute settlement | Must remain solvent relative to internal accounting |
83
+ | Terminal | Hold funds and execute settlement | Must stay solvent relative to internal accounting |
76
84
  | Controller | Mint, burn, and manage project lifecycle | Must not bypass project-scoped authorization |
77
85
  | Hooks and splits | Extend pay and cash-out behavior | Must not make previews and accounting irreconcilable |
78
86
 
@@ -86,29 +94,22 @@ Core ordering to keep in mind:
86
94
 
87
95
  ## Critical Invariants
88
96
 
89
- 1. Terminal solvency
90
- Internal balances and held-fee obligations must reconcile with actual terminal token balances.
91
-
92
- 2. No over-withdrawal
93
- Payouts and allowance usage must never exceed configured per-cycle limits.
94
-
95
- 3. Cash-out correctness
96
- Surplus, total supply, tax rate, fee treatment, and hook overrides must combine into the intended reclaim amount.
97
-
98
- 4. Ruleset integrity
99
- The active ruleset and any fallback or cycling behavior must reflect exact timing and approval-hook semantics.
100
-
101
- 5. Token accounting consistency
102
- Credits, ERC-20 total supply, reserved token balance, and burn/mint paths must remain internally coherent.
103
-
104
- 6. Privilege containment
105
- Permissions, wildcard grants, controller migration, and terminal routing must not allow unauthorized project control or fund movement.
106
-
107
- 7. Held-fee correctness
108
- When fee payment is deferred, later replenishment or migration behavior must not accidentally forgive, duplicate, or cross-charge the obligation.
109
-
110
- 8. Preview coherence
111
- `previewPayFor` and `previewCashOutFrom` should not become meaningfully inconsistent with execution in ways downstream repos can exploit.
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.
112
113
 
113
114
  ## Attack Surfaces
114
115
 
@@ -117,10 +118,11 @@ When fee payment is deferred, later replenishment or migration behavior must not
117
118
  - held-fee lifecycle and `_processFee`
118
119
  - surplus aggregation across terminals
119
120
  - controller migration and terminal migration
120
- - `setPermissionsFor` and any wildcard semantics
121
+ - `setPermissionsFor` and wildcard semantics
121
122
 
122
123
  Replay these sequences:
123
- 1. `pay` with a data hook that alters weight or hook specs and then reenters through a pay hook
124
+
125
+ 1. `pay` with a data hook that changes weight or hook specs and then reenters through a pay hook
124
126
  2. `cashOutTokensOf` when cross-terminal surplus and `useTotalSurplusForCashOuts` matter
125
127
  3. `sendPayoutsOf` into splits that route to another project, hook, or failing beneficiary
126
128
  4. held-fee accumulation followed by migration or balance depletion
@@ -128,7 +130,7 @@ Replay these sequences:
128
130
 
129
131
  ## Accepted Risks Or Behaviors
130
132
 
131
- - Hooks are intentionally powerful extension points; safety depends on clear sequencing and bounded trust, not on avoiding composition.
133
+ - Hooks are intentionally powerful. Safety comes from clear ordering and bounded trust, not from avoiding composition.
132
134
 
133
135
  ## Verification
134
136
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
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
6
  Architecture: [ARCHITECTURE.md](./ARCHITECTURE.md)
@@ -12,37 +12,37 @@ Audit instructions: [AUDIT_INSTRUCTIONS.md](./AUDIT_INSTRUCTIONS.md)
12
12
 
13
13
  ## Overview
14
14
 
15
- 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.
16
16
 
17
- The core package provides:
17
+ This package provides:
18
18
 
19
19
  - project ownership and metadata through `JBProjects`
20
20
  - ruleset lifecycle management through `JBRulesets`
21
- - issuance, queueing, token setup, and splits through `JBController`
21
+ - token issuance, ruleset queueing, token setup, and splits through `JBController`
22
22
  - multi-token terminal accounting through `JBMultiTerminal` and `JBTerminalStore`
23
23
  - operator permissions through `JBPermissions`
24
24
  - on-chain price-feed routing through `JBPrices`
25
25
 
26
- Use this repo when you need the canonical protocol accounting and execution surfaces. 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.
27
27
 
28
- 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.
29
29
 
30
30
  ## Mental Model
31
31
 
32
- The core protocol is easiest to reason about in four layers:
32
+ It helps to think about core in four layers:
33
33
 
34
34
  1. identity and configuration: `JBProjects`, `JBDirectory`, `JBRulesets`
35
35
  2. execution: `JBController` and `JBMultiTerminal`
36
36
  3. accounting: `JBTerminalStore`
37
- 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
38
38
 
39
- Many integrations touch only layer 2, while many economically important bugs are easiest to understand from layer 3.
39
+ Many integrations mostly touch layer 2. Many high-impact bugs are easier to understand in layer 3.
40
40
 
41
- The shortest path through the repo is:
41
+ The shortest reading path is:
42
42
 
43
43
  1. `JBController` for project launch and ruleset configuration
44
- 2. `JBMultiTerminal` for execution entrypoints
45
- 3. `JBTerminalStore` for economic truth
44
+ 2. `JBMultiTerminal` for user-facing execution entrypoints
45
+ 3. `JBTerminalStore` for the accounting model
46
46
  4. `JBDirectory` and `JBPermissions` for routing and authority
47
47
 
48
48
  ## Read These Files First
@@ -58,30 +58,30 @@ The shortest path through the repo is:
58
58
 
59
59
  | Contract | Role |
60
60
  | --- | --- |
61
- | `JBController` | Project launch, ruleset queueing, token configuration, and split management. |
62
- | `JBMultiTerminal` | Main payment, payout, allowance, and cash-out terminal surface. |
63
- | `JBTerminalStore` | Shared accounting store for balances, surplus, fees, and reclaim calculations. |
64
- | `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. |
65
65
  | `JBProjects` | ERC-721 project registry and ownership surface. |
66
- | `JBPermissions` | Packed operator permissions registry. |
67
- | `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. |
68
68
 
69
69
  ## Integration Traps
70
70
 
71
- - `JBMultiTerminal` is not a single-token terminal. Integrations that assume one token, one balance, or one primary path usually misread the accounting model.
72
- - data hooks and cash-out hooks are not cosmetic. They can change effective issuance, reclaim value, and side effects on the path.
73
- - permission checks are not always against the project owner. Some flows are scoped to the token holder instead.
74
- - 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.
75
75
 
76
76
  ## Where State Lives
77
77
 
78
- - project identity and ownership live in `JBProjects`
79
- - controller and terminal routing live in `JBDirectory`
80
- - ruleset history and activation live in `JBRulesets`
81
- - balances, surplus, fees, and reclaim accounting live in `JBTerminalStore`
82
- - 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`
83
83
 
84
- 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
85
 
86
86
  ## High-Signal Tests
87
87
 
@@ -115,7 +115,7 @@ Useful scripts:
115
115
 
116
116
  ## Deployment Notes
117
117
 
118
- 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.
119
119
 
120
120
  ## Repository Layout
121
121
 
@@ -132,15 +132,15 @@ script/
132
132
 
133
133
  ## Risks And Notes
134
134
 
135
- - hooks can meaningfully change payment and cash-out behavior, so core integrations must treat hook composition as part of the protocol surface
136
- - permissions are flexible enough to be dangerous when scoped broadly or granted with wildcard project IDs
137
- - multi-terminal and multi-token accounting is powerful but increases the chance of integration mistakes when callers assume a single-terminal model
138
- - 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
139
 
140
- 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.
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
141
 
142
142
  ## For AI Agents
143
143
 
144
- - Start with `JBController`, `JBMultiTerminal`, and `JBTerminalStore`; do not summarize core behavior from helper libraries alone.
145
- - Distinguish controller configuration from terminal execution and from store accounting.
146
- - If a behavior involves hooks, inspect the hook repo too before treating the preview or execution path as canonical.
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.