@bananapus/permission-ids-v6 0.0.5 → 0.0.7

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,531 @@
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
+ ## Pragma Versions
21
+
22
+ ```solidity
23
+ // Contracts — pin to exact version
24
+ pragma solidity 0.8.26;
25
+
26
+ // Interfaces, structs, enums — caret for forward compatibility
27
+ pragma solidity ^0.8.0;
28
+
29
+ // Libraries — caret, may use newer features
30
+ pragma solidity ^0.8.17;
31
+ ```
32
+
33
+ ## Imports
34
+
35
+ Named imports only. Grouped by source, alphabetized within each group:
36
+
37
+ ```solidity
38
+ // External packages (alphabetized)
39
+ import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
40
+ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
41
+ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
42
+ import {mulDiv} from "@prb/math/src/Common.sol";
43
+
44
+ // Local: abstract contracts
45
+ import {JBPermissioned} from "./abstract/JBPermissioned.sol";
46
+
47
+ // Local: interfaces (alphabetized)
48
+ import {IJBController} from "./interfaces/IJBController.sol";
49
+ import {IJBDirectory} from "./interfaces/IJBDirectory.sol";
50
+ import {IJBMultiTerminal} from "./interfaces/IJBMultiTerminal.sol";
51
+
52
+ // Local: libraries (alphabetized)
53
+ import {JBConstants} from "./libraries/JBConstants.sol";
54
+ import {JBFees} from "./libraries/JBFees.sol";
55
+
56
+ // Local: structs (alphabetized)
57
+ import {JBAccountingContext} from "./structs/JBAccountingContext.sol";
58
+ import {JBSplit} from "./structs/JBSplit.sol";
59
+ ```
60
+
61
+ ## Contract Structure
62
+
63
+ Section banners divide the contract into a fixed ordering. Every contract with 50+ lines uses these banners:
64
+
65
+ ```solidity
66
+ /// @notice One-line description.
67
+ contract JBExample is JBPermissioned, IJBExample {
68
+ // A library that does X.
69
+ using SomeLib for SomeType;
70
+
71
+ //*********************************************************************//
72
+ // --------------------------- custom errors ------------------------- //
73
+ //*********************************************************************//
74
+
75
+ error JBExample_SomethingFailed(uint256 amount);
76
+
77
+ //*********************************************************************//
78
+ // ------------------------- public constants ------------------------ //
79
+ //*********************************************************************//
80
+
81
+ uint256 public constant override FEE = 25;
82
+
83
+ //*********************************************************************//
84
+ // ----------------------- internal constants ------------------------ //
85
+ //*********************************************************************//
86
+
87
+ uint256 internal constant _FEE_BENEFICIARY_PROJECT_ID = 1;
88
+
89
+ //*********************************************************************//
90
+ // --------------- public immutable stored properties ---------------- //
91
+ //*********************************************************************//
92
+
93
+ IJBDirectory public immutable override DIRECTORY;
94
+
95
+ //*********************************************************************//
96
+ // --------------------- public stored properties -------------------- //
97
+ //*********************************************************************//
98
+
99
+ //*********************************************************************//
100
+ // -------------------- internal stored properties ------------------- //
101
+ //*********************************************************************//
102
+
103
+ //*********************************************************************//
104
+ // -------------------------- constructor ---------------------------- //
105
+ //*********************************************************************//
106
+
107
+ //*********************************************************************//
108
+ // ---------------------- external transactions ---------------------- //
109
+ //*********************************************************************//
110
+
111
+ //*********************************************************************//
112
+ // ----------------------- external views ---------------------------- //
113
+ //*********************************************************************//
114
+
115
+ //*********************************************************************//
116
+ // ----------------------- public transactions ----------------------- //
117
+ //*********************************************************************//
118
+
119
+ //*********************************************************************//
120
+ // ----------------------- internal helpers -------------------------- //
121
+ //*********************************************************************//
122
+
123
+ //*********************************************************************//
124
+ // ----------------------- internal views ---------------------------- //
125
+ //*********************************************************************//
126
+
127
+ //*********************************************************************//
128
+ // ----------------------- private helpers --------------------------- //
129
+ //*********************************************************************//
130
+ }
131
+ ```
132
+
133
+ **Section order:**
134
+ 1. Custom errors
135
+ 2. Public constants
136
+ 3. Internal constants
137
+ 4. Public immutable stored properties
138
+ 5. Internal immutable stored properties
139
+ 6. Public stored properties
140
+ 7. Internal stored properties
141
+ 8. Constructor
142
+ 9. External transactions
143
+ 10. External views
144
+ 11. Public transactions
145
+ 12. Internal helpers
146
+ 13. Internal views
147
+ 14. Private helpers
148
+
149
+ Functions are alphabetized within each section.
150
+
151
+ ## Interface Structure
152
+
153
+ ```solidity
154
+ /// @notice One-line description.
155
+ interface IJBExample is IJBBase {
156
+ // Events (with full NatSpec)
157
+
158
+ /// @notice Emitted when X happens.
159
+ /// @param projectId The ID of the project.
160
+ /// @param amount The amount transferred.
161
+ event SomethingHappened(uint256 indexed projectId, uint256 amount);
162
+
163
+ // Views (alphabetized)
164
+
165
+ /// @notice The directory of terminals and controllers.
166
+ function DIRECTORY() external view returns (IJBDirectory);
167
+
168
+ // State-changing functions (alphabetized)
169
+
170
+ /// @notice Does the thing.
171
+ /// @param projectId The ID of the project.
172
+ /// @return result The result.
173
+ function doThing(uint256 projectId) external returns (uint256 result);
174
+ }
175
+ ```
176
+
177
+ **Rules:**
178
+ - Events first, then views, then state-changing functions
179
+ - No custom errors in interfaces — errors belong in the implementing contract
180
+ - Full NatSpec on every event, function, and parameter
181
+ - Alphabetized within each group
182
+
183
+ ## Naming
184
+
185
+ | Thing | Convention | Example |
186
+ |-------|-----------|---------|
187
+ | Contract | PascalCase | `JBMultiTerminal` |
188
+ | Interface | `I` + PascalCase | `IJBMultiTerminal` |
189
+ | Library | PascalCase | `JBCashOuts` |
190
+ | Struct | PascalCase | `JBRulesetConfig` |
191
+ | Enum | PascalCase | `JBApprovalStatus` |
192
+ | Enum value | PascalCase | `ApprovalExpected` |
193
+ | Error | `ContractName_ErrorName` | `JBMultiTerminal_FeeTerminalNotFound` |
194
+ | Public constant | `ALL_CAPS` | `FEE`, `MAX_FEE` |
195
+ | Internal constant | `_ALL_CAPS` | `_FEE_HOLDING_SECONDS` |
196
+ | Public immutable | `ALL_CAPS` | `DIRECTORY`, `PERMISSIONS` |
197
+ | Public/external function | `camelCase` | `cashOutTokensOf` |
198
+ | Internal/private function | `_camelCase` | `_processFee` |
199
+ | Internal storage | `_camelCase` | `_accountingContextForTokenOf` |
200
+ | Function parameter | `camelCase` | `projectId`, `cashOutCount` |
201
+
202
+ ## NatSpec
203
+
204
+ **Contracts:**
205
+ ```solidity
206
+ /// @notice One-line description of what the contract does.
207
+ contract JBExample is IJBExample {
208
+ ```
209
+
210
+ **Functions:**
211
+ ```solidity
212
+ /// @notice Records funds being added to a project's balance.
213
+ /// @param projectId The ID of the project which funds are being added to.
214
+ /// @param token The token being added.
215
+ /// @param amount The amount added, as a fixed point number with the same decimals as the terminal.
216
+ /// @return surplus The new surplus after adding.
217
+ function recordAddedBalanceFor(
218
+ uint256 projectId,
219
+ address token,
220
+ uint256 amount
221
+ ) external override returns (uint256 surplus) {
222
+ ```
223
+
224
+ **Structs:**
225
+ ```solidity
226
+ /// @custom:member duration The number of seconds the ruleset lasts for. 0 means it never expires.
227
+ /// @custom:member weight How many tokens to mint per unit paid (18 decimals).
228
+ /// @custom:member weightCutPercent How much weight decays each cycle (9 decimals).
229
+ struct JBRulesetConfig {
230
+ uint32 duration;
231
+ uint112 weight;
232
+ uint32 weightCutPercent;
233
+ }
234
+ ```
235
+
236
+ **Mappings:**
237
+ ```solidity
238
+ /// @notice Context describing how a token is accounted for by a project.
239
+ /// @custom:param projectId The ID of the project.
240
+ /// @custom:param token The address of the token.
241
+ mapping(uint256 projectId => mapping(address token => JBAccountingContext)) internal _accountingContextForTokenOf;
242
+ ```
243
+
244
+ ## Numbers
245
+
246
+ Use underscores for thousands separators:
247
+
248
+ ```solidity
249
+ uint256 internal constant _FEE_HOLDING_SECONDS = 2_419_200; // 28 days
250
+ uint32 public constant MAX_WEIGHT_CUT_PERCENT = 1_000_000_000;
251
+ uint256 public constant MAX_RESERVED_PERCENT = 10_000;
252
+ ```
253
+
254
+ ## Function Calls
255
+
256
+ Use named parameters for readability when calling functions with 3+ arguments:
257
+
258
+ ```solidity
259
+ PERMISSIONS.hasPermission({
260
+ operator: sender,
261
+ account: account,
262
+ projectId: projectId,
263
+ permissionId: permissionId,
264
+ includeRoot: true,
265
+ includeWildcardProjectId: true
266
+ });
267
+ ```
268
+
269
+ ## Multiline Signatures
270
+
271
+ ```solidity
272
+ function recordCashOutFor(
273
+ address holder,
274
+ uint256 projectId,
275
+ uint256 cashOutCount,
276
+ JBAccountingContext calldata accountingContext
277
+ )
278
+ external
279
+ override
280
+ returns (
281
+ JBRuleset memory ruleset,
282
+ uint256 reclaimAmount,
283
+ JBCashOutHookSpecification[] memory hookSpecifications
284
+ )
285
+ {
286
+ ```
287
+
288
+ Modifiers and return types go on their own indented lines.
289
+
290
+ ## Error Handling
291
+
292
+ - Validate inputs with explicit `revert` + custom error
293
+ - Use `try-catch` only for external calls to untrusted contracts (hooks, fee processing)
294
+ - Always include relevant context in error parameters
295
+
296
+ ```solidity
297
+ // Direct validation
298
+ if (amount > limit) revert JBTerminalStore_InadequateControllerPayoutLimit(amount, limit);
299
+
300
+ // External call to untrusted hook
301
+ try hook.afterPayRecordedWith(context) {} catch (bytes memory reason) {
302
+ emit HookAfterPayReverted(hook, context, reason, _msgSender());
303
+ }
304
+ ```
305
+
306
+ ---
307
+
308
+ ## DevOps
309
+
310
+ ### foundry.toml
311
+
312
+ Standard config across all repos:
313
+
314
+ ```toml
315
+ [profile.default]
316
+ solc = '0.8.26'
317
+ evm_version = 'cancun'
318
+ optimizer_runs = 200
319
+ libs = ["node_modules", "lib"]
320
+ fs_permissions = [{ access = "read-write", path = "./"}]
321
+
322
+ [fuzz]
323
+ runs = 4096
324
+
325
+ [invariant]
326
+ runs = 1024
327
+ depth = 100
328
+ fail_on_revert = false
329
+
330
+ [fmt]
331
+ number_underscore = "thousands"
332
+ multiline_func_header = "all"
333
+ wrap_comments = true
334
+ ```
335
+
336
+ **Optional sections (add only when needed):**
337
+ - `[rpc_endpoints]` — repos with fork tests. Maps named endpoints to env vars (e.g. `ethereum = "${RPC_ETHEREUM_MAINNET}"`).
338
+ - `[profile.ci_sizes]` — only when CI needs different optimizer settings than defaults for the size check step (e.g. `optimizer_runs = 200` when the default profile uses a lower value).
339
+
340
+ **Common variations:**
341
+ - `via_ir = true` when hitting stack-too-deep
342
+ - `optimizer = false` when optimization causes stack-too-deep
343
+ - `optimizer_runs` reduced when deep struct nesting causes stack-too-deep at 200 runs
344
+
345
+ ### CI Workflows
346
+
347
+ Every repo has at minimum `test.yml` and `lint.yml`:
348
+
349
+ **test.yml:**
350
+ ```yaml
351
+ name: test
352
+ on:
353
+ pull_request:
354
+ branches: [main]
355
+ push:
356
+ branches: [main]
357
+ jobs:
358
+ forge-test:
359
+ runs-on: ubuntu-latest
360
+ steps:
361
+ - uses: actions/checkout@v4
362
+ with:
363
+ submodules: recursive
364
+ - uses: actions/setup-node@v4
365
+ with:
366
+ node-version: 22.4.x
367
+ - name: Install npm dependencies
368
+ run: npm install --omit=dev
369
+ - name: Install Foundry
370
+ uses: foundry-rs/foundry-toolchain@v1
371
+ - name: Run tests
372
+ run: forge test --fail-fast --summary --detailed --skip "*/script/**"
373
+ env:
374
+ RPC_ETHEREUM_MAINNET: ${{ secrets.RPC_ETHEREUM_MAINNET }}
375
+ - name: Check contract sizes
376
+ run: forge build --sizes --skip "*/test/**" --skip "*/script/**" --skip SphinxUtils
377
+ ```
378
+
379
+ **lint.yml:**
380
+ ```yaml
381
+ name: lint
382
+ on:
383
+ pull_request:
384
+ branches: [main]
385
+ push:
386
+ branches: [main]
387
+ jobs:
388
+ forge-fmt:
389
+ runs-on: ubuntu-latest
390
+ steps:
391
+ - uses: actions/checkout@v4
392
+ - name: Install Foundry
393
+ uses: foundry-rs/foundry-toolchain@v1
394
+ - name: Check formatting
395
+ run: forge fmt --check
396
+ ```
397
+
398
+ **slither.yml** (repos with `src/` contracts only):
399
+ ```yaml
400
+ name: slither
401
+ on:
402
+ pull_request:
403
+ branches:
404
+ - main
405
+ push:
406
+ branches:
407
+ - main
408
+ jobs:
409
+ analyze:
410
+ runs-on: ubuntu-latest
411
+ steps:
412
+ - uses: actions/checkout@v4
413
+ with:
414
+ submodules: recursive
415
+ - uses: actions/setup-node@v4
416
+ with:
417
+ node-version: latest
418
+ - name: Install npm dependencies
419
+ run: npm install --omit=dev
420
+ - name: Install Foundry
421
+ uses: foundry-rs/foundry-toolchain@v1
422
+ - name: Run slither
423
+ uses: crytic/slither-action@v0.3.1
424
+ with:
425
+ slither-config: slither-ci.config.json
426
+ fail-on: medium
427
+ ```
428
+
429
+ **slither-ci.config.json:**
430
+ ```json
431
+ {
432
+ "detectors_to_exclude": "timestamp,uninitialized-local,naming-convention,solc-version,shadowing-local",
433
+ "exclude_informational": true,
434
+ "exclude_low": false,
435
+ "exclude_medium": false,
436
+ "exclude_high": false,
437
+ "disable_color": false,
438
+ "filter_paths": "(mocks/|test/|node_modules/|lib/)",
439
+ "legacy_ast": false
440
+ }
441
+ ```
442
+
443
+ **Variations:**
444
+ - Deployer-only repos (no `src/`, only `script/`) skip slither entirely — the action's internal `forge build` skips `test/` and `script/` by default, leaving nothing to compile.
445
+ - Use inline `// slither-disable-next-line <detector>` to suppress known false positives rather than adding to `detectors_to_exclude` in the config. The comment must be on the line immediately before the flagged expression.
446
+
447
+ ### package.json
448
+
449
+ ```json
450
+ {
451
+ "name": "@bananapus/package-name-v6",
452
+ "version": "x.x.x",
453
+ "license": "MIT",
454
+ "repository": { "type": "git", "url": "git+https://github.com/Org/repo.git" },
455
+ "engines": { "node": ">=20.0.0" },
456
+ "scripts": {
457
+ "test": "forge test",
458
+ "coverage": "forge coverage --match-path \"./src/*.sol\" --report lcov --report summary"
459
+ },
460
+ "dependencies": { ... },
461
+ "devDependencies": {
462
+ "@sphinx-labs/plugins": "^0.33.2"
463
+ }
464
+ }
465
+ ```
466
+
467
+ **Scoping:** `@bananapus/` for Bananapus repos, `@rev-net/` for revnet, `@croptop/` for croptop, `@bannynet/` for banny, `@ballkidz/` for defifa.
468
+
469
+ ### remappings.txt
470
+
471
+ Every repo has a `remappings.txt`. Minimal content:
472
+
473
+ ```
474
+ @sphinx-labs/contracts/=lib/sphinx/packages/contracts/contracts/foundry
475
+ ```
476
+
477
+ Additional mappings as needed for repo-specific dependencies.
478
+
479
+ ### Linting
480
+
481
+ Solar (Foundry's built-in linter) runs automatically during `forge build`. It scans all `.sol` files in `libs` directories, including `node_modules`.
482
+
483
+ **All test helpers must use relative imports** (e.g. `../../src/structs/JBRuleset.sol`), not bare `src/` imports. This ensures solar can resolve paths when the helper is consumed via npm in downstream repos.
484
+
485
+ ### Fork Tests
486
+
487
+ Fork tests use named RPC endpoints defined in `[rpc_endpoints]` of `foundry.toml`. No skip guards — fork tests should hard-fail if the RPC endpoint is unavailable, making CI failures explicit.
488
+
489
+ ```solidity
490
+ function setUp() public {
491
+ vm.createSelectFork("ethereum");
492
+ // ... setup code
493
+ }
494
+ ```
495
+
496
+ The endpoint name (e.g. `"ethereum"`) maps to an env var via `foundry.toml`:
497
+
498
+ ```toml
499
+ [rpc_endpoints]
500
+ ethereum = "${RPC_ETHEREUM_MAINNET}"
501
+ ```
502
+
503
+ For multi-chain fork tests, add all needed endpoints.
504
+
505
+ ### Formatting
506
+
507
+ Run `forge fmt` before committing. The `[fmt]` config in `foundry.toml` enforces:
508
+ - Thousands separators on numbers (`1_000_000`)
509
+ - Multiline function headers when multiple parameters
510
+ - Wrapped comments at reasonable width
511
+
512
+ CI checks formatting via `forge fmt --check`.
513
+
514
+ ### Branching
515
+
516
+ - `main` is the primary branch
517
+ - Feature branches for PRs
518
+ - All PRs trigger test + lint workflows
519
+ - Submodule checkout with `--recursive` in CI
520
+
521
+ ### Dependencies
522
+
523
+ - Solidity dependencies via npm (`node_modules/`)
524
+ - `forge-std` as a git submodule in `lib/`
525
+ - Sphinx plugins as a devDependency
526
+ - Cross-repo references use `file:../sibling-repo` in local development
527
+ - Published versions use semver ranges (`^0.0.x`) for npm
528
+
529
+ ### Contract Size Checks
530
+
531
+ CI runs `forge build --sizes` to catch contracts approaching the 24KB limit. When the repo's default `optimizer_runs` differs from what you want for size checking, use `FOUNDRY_PROFILE=ci_sizes forge build --sizes` with a `[profile.ci_sizes]` section in `foundry.toml`.
package/foundry.toml CHANGED
@@ -1,13 +1,10 @@
1
1
  [profile.default]
2
2
  solc = '0.8.26'
3
- evm_version = 'paris'
3
+ evm_version = 'cancun'
4
4
  optimizer_runs = 200
5
5
  libs = ["node_modules", "lib"]
6
6
  fs_permissions = [{ access = "read-write", path = "./"}]
7
7
 
8
- [profile.ci_sizes]
9
- optimizer_runs = 200
10
-
11
8
  [fuzz]
12
9
  runs = 4096
13
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/permission-ids-v6",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",