@bananapus/core-v6 0.0.35 → 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/ADMINISTRATION.md +29 -29
- package/ARCHITECTURE.md +41 -34
- package/AUDIT_INSTRUCTIONS.md +44 -42
- package/README.md +37 -37
- package/RISKS.md +115 -154
- package/SKILLS.md +17 -18
- package/USER_JOURNEYS.md +49 -51
- package/package.json +1 -1
- package/test/TestAccessToFunds.sol +24 -0
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
|
|
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
|
|
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
|
|
20
|
-
- Fine-grained operator delegation
|
|
21
|
-
- Controllers and terminals
|
|
22
|
-
-
|
|
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 |
|
|
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 |
|
|
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
|
|
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
|
|
47
|
+
The practical split is simple:
|
|
48
48
|
|
|
49
49
|
- protocol owners change global infrastructure or defaults
|
|
50
|
-
- project owners and
|
|
51
|
-
- controllers and terminals
|
|
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
|
|
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
|
|
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
|
|
63
|
-
-
|
|
64
|
-
- Treat controller migration, terminal migration, token deployment, and price-feed installation as control-plane changes
|
|
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
|
|
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
|
|
71
|
-
- Treat `JBDirectory`, `JBController`, `JBMultiTerminal`, `JBPermissions`, `JBPrices`, `JBFeelessAddresses`, and `JBProjects` as the minimum
|
|
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,
|
|
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
|
|
79
|
-
- Wrong project-local config can often be corrected if the current ruleset still
|
|
80
|
-
- Wrong wildcard permissions are
|
|
81
|
-
- Some fee-route and payout-route failures are recoverable in place because
|
|
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
|
|
88
|
-
- Nobody can change the hardcoded fee beneficiary or
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
16
|
-
- Data hooks run before settlement and may
|
|
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
|
|
20
|
-
- Rulesets are time-ordered and approval-aware, and
|
|
21
|
-
- Permission checks are protocol
|
|
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
|
|
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
|
|
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
|
|
38
|
-
- External price feeds, Permit2, and ERC-20 behavior
|
|
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
|
|
48
|
-
-> terminal store records payment
|
|
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
|
|
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
|
|
59
|
-
-> terminal store records the cash out
|
|
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
|
|
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
|
|
71
|
-
-> rulesets become the source of truth for
|
|
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
|
|
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
|
|
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
|
-
|
|
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`
|
|
92
|
-
- `JBTerminalStore`
|
|
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.
|
|
95
|
-
- `allowOwnerMinting` is not a universal mint kill switch.
|
|
96
|
-
- Hook ordering and preview-execution alignment are
|
|
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
|
|
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
|
|
103
|
-
- If you change payouts between projects
|
|
104
|
-
- If you change ruleset rollover semantics, re-check which
|
|
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
|
package/AUDIT_INSTRUCTIONS.md
CHANGED
|
@@ -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
|
|
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
|
|
46
|
+
That order mirrors how most high-severity issues appear:
|
|
47
|
+
|
|
43
48
|
- accounting is computed
|
|
44
|
-
- funds
|
|
45
|
-
- tokens
|
|
46
|
-
- permissions and price context
|
|
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
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
-
|
|
68
|
-
-
|
|
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
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
|
121
|
+
- `setPermissionsFor` and wildcard semantics
|
|
121
122
|
|
|
122
123
|
Replay these sequences:
|
|
123
|
-
|
|
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
|
|
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
|
|
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
|
|
15
|
+
If a V6 package moves value, mints tokens, checks permissions, or reads project configuration, it probably depends on this repo.
|
|
16
16
|
|
|
17
|
-
|
|
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
|
|
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
|
|
28
|
+
If you only read one V6 repo before reading the rest, read this one.
|
|
29
29
|
|
|
30
30
|
## Mental Model
|
|
31
31
|
|
|
32
|
-
|
|
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
|
|
37
|
+
4. permissions and shared context: `JBPermissions`, `JBPrices`, feeless-address and deadline helpers
|
|
38
38
|
|
|
39
|
-
Many integrations touch
|
|
39
|
+
Many integrations mostly touch layer 2. Many high-impact bugs are easier to understand in layer 3.
|
|
40
40
|
|
|
41
|
-
The shortest path
|
|
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
|
|
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` |
|
|
62
|
-
| `JBMultiTerminal` | Main payment, payout, allowance, and cash-out
|
|
63
|
-
| `JBTerminalStore` | Shared accounting
|
|
64
|
-
| `JBDirectory` |
|
|
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
|
|
67
|
-
| `JBPrices` | Price
|
|
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
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
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
|
|
79
|
-
- controller and terminal routing
|
|
80
|
-
- ruleset history and activation
|
|
81
|
-
- balances, surplus, fees, and reclaim accounting
|
|
82
|
-
- operator authority
|
|
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
|
|
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
|
|
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
|
-
-
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
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
|
|
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
|
|
145
|
-
-
|
|
146
|
-
- If
|
|
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.
|