@bananapus/permission-ids-v6 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,106 @@
1
+ # Administration
2
+
3
+ Admin privileges and their scope in nana-permission-ids-v6.
4
+
5
+ ## Overview
6
+
7
+ This repo defines permission ID constants. It contains no admin functions itself -- it is a reference library for the permission system used across the Juicebox V6 ecosystem. The constants in `JBPermissionIds` are consumed by contracts in nana-core-v6, nana-721-hook-v6, nana-buyback-hook-v6, nana-router-terminal-v6, and nana-suckers-v6 to gate privileged operations.
8
+
9
+ There are no ownable contracts, no upgrade mechanisms, and no mutable state. The library compiles to inline constants.
10
+
11
+ ## Permission IDs
12
+
13
+ All 32 defined permission IDs and what they control:
14
+
15
+ | ID | Constant | Used By | What It Controls |
16
+ |----|----------|---------|-----------------|
17
+ | 1 | `ROOT` | All contracts | Grants every permission. See [ROOT Permission](#root-permission). |
18
+ | 2 | `QUEUE_RULESETS` | nana-core | `JBController.queueRulesetsOf` -- queue new rulesets for a project. |
19
+ | 3 | `LAUNCH_RULESETS` | nana-core | `JBController.launchRulesetsFor` -- launch a project's initial rulesets. Also requires `SET_TERMINALS` (ID 15). |
20
+ | 4 | `CASH_OUT_TOKENS` | nana-core | `JBMultiTerminal.cashOutTokensOf` -- redeem tokens for surplus. Checked against the **token holder**, not the project owner. |
21
+ | 5 | `SEND_PAYOUTS` | nana-core | `JBMultiTerminal.sendPayoutsOf` -- distribute payouts to splits. |
22
+ | 6 | `MIGRATE_TERMINAL` | nana-core | `JBMultiTerminal.migrateBalanceOf` -- migrate a project's balance to another terminal. |
23
+ | 7 | `SET_PROJECT_URI` | nana-core | `JBController.setUriOf` -- set project metadata URI. |
24
+ | 8 | `DEPLOY_ERC20` | nana-core | `JBController.deployERC20For` -- deploy a new ERC-20 token for a project. |
25
+ | 9 | `SET_TOKEN` | nana-core | `JBController.setTokenFor` -- set an existing ERC-20 token for a project. |
26
+ | 10 | `MINT_TOKENS` | nana-core | `JBController.mintTokensOf` -- mint new project tokens. Only effective when the current ruleset allows owner minting. |
27
+ | 11 | `BURN_TOKENS` | nana-core | `JBController.burnTokensOf` -- burn tokens. Checked against the **token holder**. |
28
+ | 12 | `CLAIM_TOKENS` | nana-core | `JBController.claimTokensFor` -- claim internal credits as ERC-20. Checked against the **token holder**. |
29
+ | 13 | `TRANSFER_CREDITS` | nana-core | `JBController.transferCreditsFrom` -- transfer internal credits. Checked against the **token holder**. |
30
+ | 14 | `SET_CONTROLLER` | nana-core | `JBDirectory.setControllerOf` -- set a project's controller. |
31
+ | 15 | `SET_TERMINALS` | nana-core | `JBDirectory.setTerminalsOf` -- set a project's terminals. **Warning:** can remove the primary terminal. |
32
+ | 16 | `SET_PRIMARY_TERMINAL` | nana-core | `JBDirectory.setPrimaryTerminalOf` -- set the primary terminal for a token. |
33
+ | 17 | `USE_ALLOWANCE` | nana-core | `JBMultiTerminal.useAllowanceOf` -- spend surplus allowance to an arbitrary address. |
34
+ | 18 | `SET_SPLIT_GROUPS` | nana-core | `JBController.setSplitGroupsOf` -- configure payout and reserved token splits. |
35
+ | 19 | `ADD_PRICE_FEED` | nana-core | `JBPrices.addPriceFeedFor` (via `JBController.addPriceFeed`) -- add a price feed for a project. |
36
+ | 20 | `ADD_ACCOUNTING_CONTEXTS` | nana-core | `JBMultiTerminal.addAccountingContextsFor` -- add accepted tokens to a terminal. |
37
+ | 21 | `ADJUST_721_TIERS` | nana-721-hook | `JB721TiersHook.adjustTiers` -- add or remove NFT tiers. |
38
+ | 22 | `SET_721_METADATA` | nana-721-hook | `JB721TiersHook.setMetadata` -- set NFT metadata URIs. |
39
+ | 23 | `MINT_721` | nana-721-hook | `JB721TiersHook.mintFor` -- manually mint NFTs to a beneficiary. |
40
+ | 24 | `SET_721_DISCOUNT_PERCENT` | nana-721-hook | `JB721TiersHook.setDiscountPercentOf` -- set discount percent on NFT tiers. |
41
+ | 25 | `SET_BUYBACK_TWAP` | nana-buyback-hook | `JBBuybackHook.setTwapWindowOf` -- configure the TWAP oracle window. |
42
+ | 26 | `SET_BUYBACK_POOL` | nana-buyback-hook | `JBBuybackHook.setPoolFor` -- set the Uniswap pool for buybacks. |
43
+ | 27 | `SET_BUYBACK_HOOK` | nana-buyback-hook | `JBBuybackHookRegistry.setHookFor` and `lockHookFor` -- configure and permanently lock the buyback hook. |
44
+ | 28 | `SET_ROUTER_TERMINAL` | nana-router-terminal | `JBRouterTerminalRegistry.setTerminalFor` and `lockTerminalFor` -- configure and permanently lock the router terminal. |
45
+ | 29 | `MAP_SUCKER_TOKEN` | nana-suckers | `JBSucker.mapToken` -- map an ERC-20 to its remote chain counterpart. Immutable once the outbox tree has entries. |
46
+ | 30 | `DEPLOY_SUCKERS` | nana-suckers | `JBSuckerRegistry.deploySuckersFor` -- deploy sucker contracts for cross-chain bridging. |
47
+ | 31 | `SUCKER_SAFETY` | nana-suckers | `JBSucker.enableEmergencyHatchFor` -- enable the emergency hatch to recover stuck tokens. |
48
+ | 32 | `SET_SUCKER_DEPRECATION` | nana-suckers | `JBSucker.setDeprecation` -- set deprecation status (ENABLED, DEPRECATION_PENDING, SENDING_DISABLED, DEPRECATED). |
49
+
50
+ IDs 0 and 33-255 are unused. ID 0 is reserved and cannot be set. IDs 33-255 are available for future ecosystem extensions.
51
+
52
+ ## ROOT Permission
53
+
54
+ `ROOT` (ID 1) is a superuser permission. When an operator has ROOT for a given project, `JBPermissions` treats every permission check as passing for that project. It is the only permission that grants blanket access.
55
+
56
+ Restrictions enforced by `JBPermissions`:
57
+
58
+ - **Cannot be granted for the wildcard project ID (0).** Attempting to set ROOT with `projectId = 0` reverts with `JBPermissions_CantSetRootPermissionForWildcardProject()`. This prevents a single operator from controlling all projects owned by an account.
59
+ - **ROOT operators cannot grant ROOT to others.** A ROOT operator can call `setPermissionsFor` on behalf of the account, but the new permission set must not include ROOT and must not target the wildcard project ID.
60
+ - **ROOT is scoped per project.** Having ROOT for project 5 does not grant any permissions for project 6.
61
+
62
+ ## Wildcard Project ID
63
+
64
+ When permissions are granted with `projectId = 0`, they apply to **every project** owned by the granting account. This is checked by `JBPermissions` as a fallback: if the operator does not have a specific permission for the target project, the contract checks whether the operator has that permission for `projectId = 0`.
65
+
66
+ ROOT cannot be set for the wildcard project ID. All other permissions can.
67
+
68
+ ## How Permissions Are Checked
69
+
70
+ Permissions are stored in `JBPermissions` as a 256-bit packed integer per (operator, account, projectId) tuple:
71
+
72
+ ```
73
+ permissionsOf[operator][account][projectId] => uint256 (packed bits)
74
+ ```
75
+
76
+ Each bit position corresponds to a permission ID. When a contract checks whether an operator has a permission, it calls `JBPermissions.hasPermission(operator, account, projectId, permissionId)`, which:
77
+
78
+ 1. Checks whether the operator has ROOT (bit 1) for the specific project -- if so, returns true.
79
+ 2. Checks whether the specific permission bit is set for the project.
80
+ 3. Falls back to checking the wildcard `projectId = 0` for both ROOT and the specific permission.
81
+
82
+ Contracts that use this system inherit from `JBPermissioned`, which provides the `_requirePermissionFrom(account, projectId, permissionId)` modifier. This modifier passes if the caller is the account itself or has the required permission via `JBPermissions`.
83
+
84
+ ## High-Risk Permissions
85
+
86
+ Some permissions warrant extra caution when granting:
87
+
88
+ - **`ROOT` (1):** Full access to all gated functions for a project.
89
+ - **`SET_TERMINALS` (15):** Can remove the primary terminal, breaking payments and cashouts.
90
+ - **`USE_ALLOWANCE` (17):** Can send surplus funds to any address.
91
+ - **`SET_BUYBACK_HOOK` (27):** Can permanently lock the buyback hook configuration.
92
+ - **`SET_ROUTER_TERMINAL` (28):** Can permanently lock the router terminal configuration.
93
+ - **`MINT_TOKENS` (10):** Can inflate token supply (subject to ruleset allowing owner minting).
94
+
95
+ ## Holder vs. Owner Permissions
96
+
97
+ Most permissions are checked against the **project owner** (the account that owns the project NFT). Four permissions are instead checked against the **token holder**:
98
+
99
+ | Permission | Checked Against |
100
+ |-----------|----------------|
101
+ | `CASH_OUT_TOKENS` (4) | Token holder |
102
+ | `BURN_TOKENS` (11) | Token holder |
103
+ | `CLAIM_TOKENS` (12) | Token holder |
104
+ | `TRANSFER_CREDITS` (13) | Token holder |
105
+
106
+ This means a token holder can grant an operator permission to cash out, burn, claim, or transfer their own tokens -- independent of the project owner's permissions.
@@ -0,0 +1,53 @@
1
+ # nana-permission-ids-v6 — Architecture
2
+
3
+ ## Purpose
4
+
5
+ Constants library defining permission IDs used throughout the Juicebox V6 ecosystem. These IDs are used with `JBPermissions` to control access to protocol functions.
6
+
7
+ ## Contract Map
8
+
9
+ ```
10
+ src/
11
+ └── JBPermissionIds.sol — Library of uint8 permission ID constants
12
+ ```
13
+
14
+ ## Permission ID Registry
15
+
16
+ | ID | Name | Used By | Gated Function |
17
+ |----|------|---------|----------------|
18
+ | 1 | `ROOT` | nana-core | All permissions (dangerous) |
19
+ | 2 | `QUEUE_RULESETS` | nana-core | `JBController.queueRulesetsOf` |
20
+ | 3 | `LAUNCH_RULESETS` | nana-core | `JBController.launchRulesetsFor` |
21
+ | 4 | `CASH_OUT_TOKENS` | nana-core | `JBMultiTerminal.cashOutTokensOf` |
22
+ | 5 | `SEND_PAYOUTS` | nana-core | `JBMultiTerminal.sendPayoutsOf` |
23
+ | 6 | `MIGRATE_TERMINAL` | nana-core | `JBMultiTerminal.migrateBalanceOf` |
24
+ | 7 | `SET_PROJECT_URI` | nana-core | `JBController.setUriOf` |
25
+ | 8 | `DEPLOY_ERC20` | nana-core | `JBController.deployERC20For` |
26
+ | 9 | `SET_TOKEN` | nana-core | `JBController.setTokenFor` |
27
+ | 10 | `MINT_TOKENS` | nana-core | `JBController.mintTokensOf` |
28
+ | 11 | `BURN_TOKENS` | nana-core | `JBController.burnTokensOf` |
29
+ | 12 | `CLAIM_TOKENS` | nana-core | `JBController.claimTokensFor` |
30
+ | 13 | `TRANSFER_CREDITS` | nana-core | `JBController.transferCreditsFrom` |
31
+ | 14 | `SET_CONTROLLER` | nana-core | `JBDirectory.setControllerOf` |
32
+ | 15 | `SET_TERMINALS` | nana-core | `JBDirectory.setTerminalsOf` |
33
+ | 16 | `SET_PRIMARY_TERMINAL` | nana-core | `JBDirectory.setPrimaryTerminalOf` |
34
+ | 17 | `USE_ALLOWANCE` | nana-core | `JBMultiTerminal.useAllowanceOf` |
35
+ | 18 | `SET_SPLIT_GROUPS` | nana-core | `JBController.setSplitGroupsOf` |
36
+ | 19 | `ADD_PRICE_FEED` | nana-core | `JBPrices.addPriceFeedFor` |
37
+ | 20 | `ADD_ACCOUNTING_CONTEXTS` | nana-core | `JBMultiTerminal.addAccountingContextsFor` |
38
+ | 21 | `ADJUST_721_TIERS` | nana-721-hook | `JB721TiersHook.adjustTiers` |
39
+ | 22 | `SET_721_METADATA` | nana-721-hook | `JB721TiersHook.setMetadata` |
40
+ | 23 | `MINT_721` | nana-721-hook | `JB721TiersHook.mintFor` |
41
+ | 24 | `SET_721_DISCOUNT_PERCENT` | nana-721-hook | `JB721TiersHook.setDiscountPercentOf` |
42
+ | 25 | `SET_BUYBACK_TWAP` | nana-buyback-hook | `JBBuybackHook.setTwapWindowOf` |
43
+ | 26 | `SET_BUYBACK_POOL` | nana-buyback-hook | `JBBuybackHook.setPoolFor` |
44
+ | 27 | `SET_BUYBACK_HOOK` | nana-buyback-hook | `JBBuybackHookRegistry.setHookFor` + `lockHookFor` |
45
+ | 28 | `SET_ROUTER_TERMINAL` | nana-router-terminal | `JBRouterTerminalRegistry.setTerminalFor` + `lockTerminalFor` |
46
+ | 29 | `MAP_SUCKER_TOKEN` | nana-suckers | `JBSucker.mapToken` |
47
+ | 30 | `DEPLOY_SUCKERS` | nana-suckers | `JBSuckerRegistry.deploySuckersFor` |
48
+ | 31 | `SUCKER_SAFETY` | nana-suckers | `JBSucker.enableEmergencyHatchFor` |
49
+ | 32 | `SET_SUCKER_DEPRECATION` | nana-suckers | `JBSucker.setDeprecation` |
50
+
51
+ ## Dependencies
52
+
53
+ None — this is a leaf dependency with no imports.
package/RISKS.md ADDED
@@ -0,0 +1,21 @@
1
+ # nana-permission-ids-v6 — Risks
2
+
3
+ ## Trust Assumptions
4
+
5
+ This is a constants-only library with no runtime behavior. The risk surface is limited to the correctness of the ID assignments.
6
+
7
+ ## Known Risks
8
+
9
+ | Risk | Description | Mitigation |
10
+ |------|-------------|------------|
11
+ | ID collision | If two repos use the same ID for different permissions, access control breaks | IDs are centrally managed in this single file |
12
+ | ROOT scope | ROOT (ID 1) grants ALL permissions across all contracts | Cannot be set for wildcard projectId=0; ROOT operators cannot grant ROOT |
13
+ | SET_TERMINALS scope | Includes ability to remove the primary terminal | Documented warning in source |
14
+ | SET_BUYBACK_HOOK / SET_ROUTER_TERMINAL scope | Each gates both setting AND locking (permanent) | Documented in source; granting means operator can lock |
15
+
16
+ ## Design Notes
17
+
18
+ - Permission 0 is reserved and cannot be set
19
+ - IDs are `uint8` (0-255), with 1-32 currently assigned
20
+ - IDs 33-255 are available for future ecosystem extensions
21
+ - This library has zero dependencies — it is the leaf of the dependency graph
package/STYLE_GUIDE.md ADDED
@@ -0,0 +1,468 @@
1
+ # Style Guide
2
+
3
+ How we write Solidity and organize repos across the Juicebox V6 ecosystem. `nana-core-v6` is the gold standard — when in doubt, match what it does.
4
+
5
+ ## File Organization
6
+
7
+ ```
8
+ src/
9
+ ├── Contract.sol # Main contracts in root
10
+ ├── abstract/ # Base contracts (JBPermissioned, JBControlled)
11
+ ├── enums/ # One enum per file
12
+ ├── interfaces/ # One interface per file, prefixed with I
13
+ ├── libraries/ # Pure/view logic, prefixed with JB
14
+ ├── periphery/ # Utility contracts (deadlines, price feeds)
15
+ └── structs/ # One struct per file, prefixed with JB
16
+ ```
17
+
18
+ One contract/interface/struct/enum per file. Name the file after the type it contains.
19
+
20
+ **Structs, enums, libraries, and interfaces always go in their subdirectories** (`src/structs/`, `src/enums/`, `src/libraries/`, `src/interfaces/`) — never inline in contract files or placed in `src/` root. This keeps type definitions discoverable and import paths consistent across repos.
21
+
22
+ ## Pragma Versions
23
+
24
+ ```solidity
25
+ // Contracts — pin to exact version
26
+ pragma solidity 0.8.26;
27
+
28
+ // Interfaces, structs, enums — caret for forward compatibility
29
+ pragma solidity ^0.8.0;
30
+
31
+ // Libraries — caret, may use newer features
32
+ pragma solidity ^0.8.17;
33
+ ```
34
+
35
+ ## Imports
36
+
37
+ Named imports only. Grouped by source, alphabetized within each group:
38
+
39
+ ```solidity
40
+ // External packages (alphabetized)
41
+ import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
42
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
43
+ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
44
+ import {mulDiv} from "@prb/math/src/Common.sol";
45
+
46
+ // Local: abstract contracts
47
+ import {JBPermissioned} from "./abstract/JBPermissioned.sol";
48
+
49
+ // Local: interfaces (alphabetized)
50
+ import {IJBController} from "./interfaces/IJBController.sol";
51
+ import {IJBDirectory} from "./interfaces/IJBDirectory.sol";
52
+ import {IJBMultiTerminal} from "./interfaces/IJBMultiTerminal.sol";
53
+
54
+ // Local: libraries (alphabetized)
55
+ import {JBConstants} from "./libraries/JBConstants.sol";
56
+ import {JBFees} from "./libraries/JBFees.sol";
57
+
58
+ // Local: structs (alphabetized)
59
+ import {JBAccountingContext} from "./structs/JBAccountingContext.sol";
60
+ import {JBSplit} from "./structs/JBSplit.sol";
61
+ ```
62
+
63
+ ## Contract Structure
64
+
65
+ Section banners divide the contract into a fixed ordering. Every contract with 50+ lines uses these banners:
66
+
67
+ ```solidity
68
+ /// @notice One-line description.
69
+ contract JBExample is JBPermissioned, IJBExample {
70
+ // A library that does X.
71
+ using SomeLib for SomeType;
72
+
73
+ //*********************************************************************//
74
+ // --------------------------- custom errors ------------------------- //
75
+ //*********************************************************************//
76
+
77
+ error JBExample_SomethingFailed(uint256 amount);
78
+
79
+ //*********************************************************************//
80
+ // ------------------------- public constants ------------------------ //
81
+ //*********************************************************************//
82
+
83
+ uint256 public constant override FEE = 25;
84
+
85
+ //*********************************************************************//
86
+ // ----------------------- internal constants ------------------------ //
87
+ //*********************************************************************//
88
+
89
+ uint256 internal constant _FEE_BENEFICIARY_PROJECT_ID = 1;
90
+
91
+ //*********************************************************************//
92
+ // --------------- public immutable stored properties ---------------- //
93
+ //*********************************************************************//
94
+
95
+ IJBDirectory public immutable override DIRECTORY;
96
+
97
+ //*********************************************************************//
98
+ // --------------------- public stored properties -------------------- //
99
+ //*********************************************************************//
100
+
101
+ //*********************************************************************//
102
+ // -------------------- internal stored properties ------------------- //
103
+ //*********************************************************************//
104
+
105
+ //*********************************************************************//
106
+ // -------------------------- constructor ---------------------------- //
107
+ //*********************************************************************//
108
+
109
+ //*********************************************************************//
110
+ // ---------------------- receive / fallback ------------------------- //
111
+ //*********************************************************************//
112
+
113
+ //*********************************************************************//
114
+ // --------------------------- modifiers ----------------------------- //
115
+ //*********************************************************************//
116
+
117
+ //*********************************************************************//
118
+ // ---------------------- external transactions ---------------------- //
119
+ //*********************************************************************//
120
+
121
+ //*********************************************************************//
122
+ // ----------------------- external views ---------------------------- //
123
+ //*********************************************************************//
124
+
125
+ //*********************************************************************//
126
+ // ----------------------- public transactions ----------------------- //
127
+ //*********************************************************************//
128
+
129
+ //*********************************************************************//
130
+ // ----------------------- internal helpers -------------------------- //
131
+ //*********************************************************************//
132
+
133
+ //*********************************************************************//
134
+ // ----------------------- internal views ---------------------------- //
135
+ //*********************************************************************//
136
+
137
+ //*********************************************************************//
138
+ // ----------------------- private helpers --------------------------- //
139
+ //*********************************************************************//
140
+ }
141
+ ```
142
+
143
+ **Section order:**
144
+ 1. `using` declarations
145
+ 2. Custom errors
146
+ 3. Public constants
147
+ 4. Internal constants
148
+ 5. Public immutable stored properties
149
+ 6. Internal immutable stored properties
150
+ 7. Public stored properties
151
+ 8. Internal stored properties
152
+ 9. Constructor
153
+ 10. `receive` / `fallback`
154
+ 11. Modifiers
155
+ 12. External transactions
156
+ 13. External views
157
+ 14. Public transactions
158
+ 15. Internal helpers
159
+ 16. Internal views
160
+ 17. Private helpers
161
+
162
+ Functions are alphabetized within each section.
163
+
164
+ **Events:** Events are declared in interfaces only, never in implementation contracts. Implementations inherit events from their interface and emit them unqualified. This keeps the ABI definition in one place and allows tests to use interface-qualified event expectations (e.g., `emit IJBController.LaunchProject(...)`).
165
+
166
+ ## Interface Structure
167
+
168
+ ```solidity
169
+ /// @notice One-line description.
170
+ interface IJBExample is IJBBase {
171
+ // Events (with full NatSpec)
172
+
173
+ /// @notice Emitted when X happens.
174
+ /// @param projectId The ID of the project.
175
+ /// @param amount The amount transferred.
176
+ event SomethingHappened(uint256 indexed projectId, uint256 amount);
177
+
178
+ // Views (alphabetized)
179
+
180
+ /// @notice The directory of terminals and controllers.
181
+ function DIRECTORY() external view returns (IJBDirectory);
182
+
183
+ // State-changing functions (alphabetized)
184
+
185
+ /// @notice Does the thing.
186
+ /// @param projectId The ID of the project.
187
+ /// @return result The result.
188
+ function doThing(uint256 projectId) external returns (uint256 result);
189
+ }
190
+ ```
191
+
192
+ **Rules:**
193
+ - Events first, then views, then state-changing functions
194
+ - No custom errors in interfaces — errors belong in the implementing contract
195
+ - Full NatSpec on every event, function, and parameter
196
+ - Alphabetized within each group
197
+
198
+ ## Naming
199
+
200
+ | Thing | Convention | Example |
201
+ |-------|-----------|---------|
202
+ | Contract | PascalCase | `JBMultiTerminal` |
203
+ | Interface | `I` + PascalCase | `IJBMultiTerminal` |
204
+ | Library | PascalCase | `JBCashOuts` |
205
+ | Struct | PascalCase | `JBRulesetConfig` |
206
+ | Enum | PascalCase | `JBApprovalStatus` |
207
+ | Enum value | PascalCase | `ApprovalExpected` |
208
+ | Error | `ContractName_ErrorName` | `JBMultiTerminal_FeeTerminalNotFound` |
209
+ | Public constant | `ALL_CAPS` | `FEE`, `MAX_FEE` |
210
+ | Internal constant | `_ALL_CAPS` | `_FEE_HOLDING_SECONDS` |
211
+ | Public immutable | `ALL_CAPS` | `DIRECTORY`, `PERMISSIONS` |
212
+ | Public/external function | `camelCase` | `cashOutTokensOf` |
213
+ | Internal/private function | `_camelCase` | `_processFee` |
214
+ | Internal storage | `_camelCase` | `_accountingContextForTokenOf` |
215
+ | Function parameter | `camelCase` | `projectId`, `cashOutCount` |
216
+
217
+ ## NatSpec
218
+
219
+ **Contracts:**
220
+ ```solidity
221
+ /// @notice One-line description of what the contract does.
222
+ contract JBExample is IJBExample {
223
+ ```
224
+
225
+ **Functions:**
226
+ ```solidity
227
+ /// @notice Records funds being added to a project's balance.
228
+ /// @param projectId The ID of the project which funds are being added to.
229
+ /// @param token The token being added.
230
+ /// @param amount The amount added, as a fixed point number with the same decimals as the terminal.
231
+ /// @return surplus The new surplus after adding.
232
+ function recordAddedBalanceFor(
233
+ uint256 projectId,
234
+ address token,
235
+ uint256 amount
236
+ ) external override returns (uint256 surplus) {
237
+ ```
238
+
239
+ **Structs:**
240
+ ```solidity
241
+ /// @custom:member duration The number of seconds the ruleset lasts for. 0 means it never expires.
242
+ /// @custom:member weight How many tokens to mint per unit paid (18 decimals).
243
+ /// @custom:member weightCutPercent How much weight decays each cycle (9 decimals).
244
+ struct JBRulesetConfig {
245
+ uint32 duration;
246
+ uint112 weight;
247
+ uint32 weightCutPercent;
248
+ }
249
+ ```
250
+
251
+ **Mappings:**
252
+ ```solidity
253
+ /// @notice Context describing how a token is accounted for by a project.
254
+ /// @custom:param projectId The ID of the project.
255
+ /// @custom:param token The address of the token.
256
+ mapping(uint256 projectId => mapping(address token => JBAccountingContext)) internal _accountingContextForTokenOf;
257
+ ```
258
+
259
+ ## Numbers
260
+
261
+ Use underscores for thousands separators:
262
+
263
+ ```solidity
264
+ uint256 internal constant _FEE_HOLDING_SECONDS = 2_419_200; // 28 days
265
+ uint32 public constant MAX_WEIGHT_CUT_PERCENT = 1_000_000_000;
266
+ uint256 public constant MAX_RESERVED_PERCENT = 10_000;
267
+ ```
268
+
269
+ ## Function Calls
270
+
271
+ Use named parameters for readability when calling functions with 3+ arguments:
272
+
273
+ ```solidity
274
+ PERMISSIONS.hasPermission({
275
+ operator: sender,
276
+ account: account,
277
+ projectId: projectId,
278
+ permissionId: permissionId,
279
+ includeRoot: true,
280
+ includeWildcardProjectId: true
281
+ });
282
+ ```
283
+
284
+ ## Multiline Signatures
285
+
286
+ ```solidity
287
+ function recordCashOutFor(
288
+ address holder,
289
+ uint256 projectId,
290
+ uint256 cashOutCount,
291
+ JBAccountingContext calldata accountingContext
292
+ )
293
+ external
294
+ override
295
+ returns (
296
+ JBRuleset memory ruleset,
297
+ uint256 reclaimAmount,
298
+ JBCashOutHookSpecification[] memory hookSpecifications
299
+ )
300
+ {
301
+ ```
302
+
303
+ Modifiers and return types go on their own indented lines.
304
+
305
+ ## Error Handling
306
+
307
+ - Validate inputs with explicit `revert` + custom error
308
+ - Use `try-catch` only for external calls to untrusted contracts (hooks, fee processing)
309
+ - Always include relevant context in error parameters
310
+
311
+ ```solidity
312
+ // Direct validation
313
+ if (amount > limit) revert JBTerminalStore_InadequateControllerPayoutLimit(amount, limit);
314
+
315
+ // External call to untrusted hook
316
+ try hook.afterPayRecordedWith(context) {} catch (bytes memory reason) {
317
+ emit HookAfterPayReverted(hook, context, reason, _msgSender());
318
+ }
319
+ ```
320
+
321
+ ---
322
+
323
+ ## DevOps
324
+
325
+ ### foundry.toml
326
+
327
+ Standard config across all repos:
328
+
329
+ ```toml
330
+ [profile.default]
331
+ solc = '0.8.26'
332
+ evm_version = 'cancun'
333
+ optimizer_runs = 200
334
+ libs = ["node_modules", "lib"]
335
+ fs_permissions = [{ access = "read-write", path = "./"}]
336
+
337
+ [profile.ci_sizes]
338
+ optimizer_runs = 200
339
+
340
+ [fuzz]
341
+ runs = 4096
342
+
343
+ [invariant]
344
+ runs = 1024
345
+ depth = 100
346
+ fail_on_revert = false
347
+
348
+ [fmt]
349
+ number_underscore = "thousands"
350
+ multiline_func_header = "all"
351
+ wrap_comments = true
352
+ ```
353
+
354
+ **Variations:**
355
+ - `evm_version = 'cancun'` for repos using transient storage (buyback-hook, router-terminal, univ4-router)
356
+ - `via_ir = true` for repos hitting stack-too-deep (buyback-hook, banny-retail, univ4-lp-split-hook, deploy-all)
357
+ - `optimizer = false` only for deploy-all-v6 (stack-too-deep with optimization)
358
+
359
+ ### CI Workflows
360
+
361
+ Every repo has at minimum `test.yml` and `lint.yml`:
362
+
363
+ **test.yml:**
364
+ ```yaml
365
+ name: test
366
+ on:
367
+ pull_request:
368
+ branches: [main]
369
+ push:
370
+ branches: [main]
371
+ jobs:
372
+ forge-test:
373
+ runs-on: ubuntu-latest
374
+ steps:
375
+ - uses: actions/checkout@v4
376
+ with:
377
+ submodules: recursive
378
+ - uses: actions/setup-node@v4
379
+ with:
380
+ node-version: 22.4.x
381
+ - name: Install npm dependencies
382
+ run: npm install --omit=dev
383
+ - name: Install Foundry
384
+ uses: foundry-rs/foundry-toolchain@v1
385
+ - name: Run tests
386
+ run: forge test --fail-fast --summary --detailed --skip "*/script/**"
387
+ - name: Check contract sizes
388
+ run: FOUNDRY_PROFILE=ci_sizes forge build --sizes --skip "*/test/**" --skip "*/script/**" --skip SphinxUtils
389
+ ```
390
+
391
+ **lint.yml:**
392
+ ```yaml
393
+ name: lint
394
+ on:
395
+ pull_request:
396
+ branches: [main]
397
+ push:
398
+ branches: [main]
399
+ jobs:
400
+ forge-fmt:
401
+ runs-on: ubuntu-latest
402
+ steps:
403
+ - uses: actions/checkout@v4
404
+ - name: Install Foundry
405
+ uses: foundry-rs/foundry-toolchain@v1
406
+ - name: Check formatting
407
+ run: forge fmt --check
408
+ ```
409
+
410
+ ### package.json
411
+
412
+ ```json
413
+ {
414
+ "name": "@bananapus/permission-ids-v6",
415
+ "version": "x.x.x",
416
+ "license": "MIT",
417
+ "repository": { "type": "git", "url": "git+https://github.com/Org/repo.git" },
418
+ "engines": { "node": ">=20.0.0" },
419
+ "scripts": {
420
+ "test": "forge test",
421
+ "coverage": "forge coverage --match-path \"./src/*.sol\" --report lcov --report summary"
422
+ },
423
+ "dependencies": { ... },
424
+ "devDependencies": {
425
+ "@sphinx-labs/plugins": "^0.33.2"
426
+ }
427
+ }
428
+ ```
429
+
430
+ **Scoping:** `@bananapus/` for Bananapus repos, `@rev-net/` for revnet, `@croptop/` for croptop, `@bannynet/` for banny, `@ballkidz/` for defifa.
431
+
432
+ ### remappings.txt
433
+
434
+ Every repo has a `remappings.txt`. Minimal content:
435
+
436
+ ```
437
+ @sphinx-labs/contracts/=lib/sphinx/packages/contracts/contracts/foundry
438
+ ```
439
+
440
+ Additional mappings as needed for repo-specific dependencies.
441
+
442
+ ### Formatting
443
+
444
+ Run `forge fmt` before committing. The `[fmt]` config in `foundry.toml` enforces:
445
+ - Thousands separators on numbers (`1_000_000`)
446
+ - Multiline function headers when multiple parameters
447
+ - Wrapped comments at reasonable width
448
+
449
+ CI checks formatting via `forge fmt --check`.
450
+
451
+ ### Branching
452
+
453
+ - `main` is the primary branch
454
+ - Feature branches for PRs
455
+ - All PRs trigger test + lint workflows
456
+ - Submodule checkout with `--recursive` in CI
457
+
458
+ ### Dependencies
459
+
460
+ - Solidity dependencies via npm (`node_modules/`)
461
+ - `forge-std` as a git submodule in `lib/`
462
+ - Sphinx plugins as a devDependency
463
+ - Cross-repo references use `file:../sibling-repo` in local development
464
+ - Published versions use semver ranges (`^0.0.x`) for npm
465
+
466
+ ### Contract Size Checks
467
+
468
+ CI runs `FOUNDRY_PROFILE=ci_sizes forge build --sizes` to catch contracts approaching the 24KB limit. The `ci_sizes` profile uses `optimizer_runs = 200` for realistic size measurement even when the default profile has different optimizer settings.
package/foundry.toml CHANGED
@@ -1,18 +1,20 @@
1
1
  [profile.default]
2
2
  solc = '0.8.26'
3
- evm_version = 'paris' # Required for L2s (Optimism, Arbitrum, etc.)
4
- match_contract = "_Local" # Do not run fork tests
5
- sizes = true
6
- verbosity = 3 # display errors
3
+ evm_version = 'cancun'
7
4
  optimizer_runs = 200
8
- block_number = 14126430
9
- block_timestamp = 1643802347
10
- runs = 4096
11
5
  libs = ["node_modules", "lib"]
6
+ fs_permissions = [{ access = "read-write", path = "./"}]
7
+
8
+ [profile.ci_sizes]
9
+ optimizer_runs = 200
10
+
11
+ [fuzz]
12
+ runs = 4096
12
13
 
13
- [profile.fork] # run via FOUNDRY_PROFILE=fork foundry test
14
- fs_permissions = [{ access = "read", path = "./deployments/mainnet" }] # Get the deployment addresses for forking
15
- match_contract = "_Fork"
14
+ [invariant]
15
+ runs = 1024
16
+ depth = 100
17
+ fail_on_revert = false
16
18
 
17
19
  [fmt]
18
20
  number_underscore = "thousands"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/permission-ids-v6",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/remappings.txt ADDED
@@ -0,0 +1 @@
1
+ forge-std/=lib/forge-std/src/