@bananapus/ownable-v6 0.0.6 → 0.0.8
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 +75 -0
- package/ARCHITECTURE.md +49 -0
- package/RISKS.md +23 -0
- package/STYLE_GUIDE.md +558 -0
- package/foundry.lock +5 -0
- package/foundry.toml +1 -4
- package/package.json +4 -3
- package/test/regression/L65_BurnLockProtection.t.sol +1 -1
- package/test/regression/L66_ZeroAddressValidation.t.sol +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Administration
|
|
2
|
+
|
|
3
|
+
Admin privileges and their scope in nana-ownable-v6.
|
|
4
|
+
|
|
5
|
+
## Roles
|
|
6
|
+
|
|
7
|
+
| Role | Who | How Access Is Determined |
|
|
8
|
+
|------|-----|------------------------|
|
|
9
|
+
| **Direct Owner** | An EOA or contract stored in `JBOwner.owner` | Used when `JBOwner.projectId == 0`. Set at construction or via `transferOwnership(address)`. |
|
|
10
|
+
| **Project Owner** | The holder of the `JBProjects` ERC-721 for `JBOwner.projectId` | Used when `JBOwner.projectId != 0`. Resolved dynamically via `PROJECTS.ownerOf(projectId)` on every call. |
|
|
11
|
+
| **Permission Delegate** | Any address granted `JBOwner.permissionId` through `JBPermissions` | The owner (direct or project) calls `JBPermissions.setPermissionsFor(...)` to grant `permissionId` to an operator. That operator then passes the `_checkOwner()` / `_requirePermissionFrom()` check. |
|
|
12
|
+
|
|
13
|
+
Only one of Direct Owner or Project Owner is active at a time, never both. Permission Delegates extend whichever mode is active.
|
|
14
|
+
|
|
15
|
+
## Privileged Functions
|
|
16
|
+
|
|
17
|
+
### JBOwnableOverrides (abstract base)
|
|
18
|
+
|
|
19
|
+
| Function | Required Role | Permission ID | Scope | What It Does |
|
|
20
|
+
|----------|--------------|---------------|-------|--------------|
|
|
21
|
+
| `renounceOwnership()` | Owner or delegate | `jbOwner.permissionId` | Per-contract | Sets `owner` to `address(0)` and `projectId` to `0`. Permanently disables all `onlyOwner`-guarded functions. Irreversible. |
|
|
22
|
+
| `setPermissionId(uint8)` | Owner or delegate | `jbOwner.permissionId` | Per-contract | Changes which permission ID grants owner-equivalent access via `JBPermissions`. Resets the delegation surface -- previous delegates with the old ID lose access. |
|
|
23
|
+
| `transferOwnership(address)` | Owner or delegate | `jbOwner.permissionId` | Per-contract | Transfers ownership to a new address. Resets `projectId` to `0` and `permissionId` to `0`. The new owner must call `setPermissionId()` to re-enable delegation. |
|
|
24
|
+
| `transferOwnershipToProject(uint256)` | Owner or delegate | `jbOwner.permissionId` | Per-contract | Transfers ownership to a Juicebox project. Resets `owner` to `address(0)` and `permissionId` to `0`. Validates that the project exists (`projectId <= PROJECTS.count()`). |
|
|
25
|
+
|
|
26
|
+
### JBOwnable (concrete contract)
|
|
27
|
+
|
|
28
|
+
`JBOwnable` inherits all functions above and adds no additional privileged functions. It provides the `onlyOwner` modifier for use by inheriting contracts.
|
|
29
|
+
|
|
30
|
+
Any contract that inherits `JBOwnable` and applies the `onlyOwner` modifier to its own functions effectively creates additional privileged functions gated by the same ownership and permission model described here.
|
|
31
|
+
|
|
32
|
+
## Ownership Model
|
|
33
|
+
|
|
34
|
+
JBOwnable bridges Juicebox project ownership to the OpenZeppelin `Ownable` pattern through the `JBOwner` struct:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
JBOwner {
|
|
38
|
+
address owner; // Direct owner address (when projectId == 0)
|
|
39
|
+
uint88 projectId; // JB project whose NFT holder is owner (when != 0)
|
|
40
|
+
uint8 permissionId; // Permission ID for delegation via JBPermissions
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Resolution logic** (in `_checkOwner()` and `owner()`):
|
|
45
|
+
|
|
46
|
+
1. If `projectId != 0`, the owner is `PROJECTS.ownerOf(projectId)` -- resolved dynamically on every call. If `ownerOf()` reverts (e.g., hypothetical NFT burn), the resolved owner becomes `address(0)`, effectively renouncing the contract.
|
|
47
|
+
2. If `projectId == 0`, the owner is `JBOwner.owner` directly.
|
|
48
|
+
3. In both cases, `_checkOwner()` calls `_requirePermissionFrom(resolvedOwner, projectId, permissionId)`, which passes if `msg.sender` is the resolved owner OR has the configured `permissionId` granted through `JBPermissions`.
|
|
49
|
+
|
|
50
|
+
**Permission delegation** uses the nana-core `JBPermissions` contract. The owner calls `JBPermissions.setPermissionsFor(...)` to grant `permissionId` to an operator address. That operator can then call any `onlyOwner` function on this contract. The ROOT permission (ID 255) in `JBPermissions` grants all permission IDs, including whatever `permissionId` is configured here.
|
|
51
|
+
|
|
52
|
+
**Ownership transfer resets `permissionId` to 0.** This prevents the previous owner's delegates from retaining access after a transfer. The new owner must explicitly call `setPermissionId()` to configure delegation.
|
|
53
|
+
|
|
54
|
+
## Immutable Configuration
|
|
55
|
+
|
|
56
|
+
| Property | Set At | Can Change? |
|
|
57
|
+
|----------|--------|-------------|
|
|
58
|
+
| `PERMISSIONS` (IJBPermissions) | Construction (via `JBPermissioned`) | No -- immutable |
|
|
59
|
+
| `PROJECTS` (IJBProjects) | Construction | No -- immutable |
|
|
60
|
+
|
|
61
|
+
The `JBPermissions` and `JBProjects` contract references are baked in at deploy time and cannot be changed. If either contract is upgraded or replaced, the `JBOwnable` instance must be redeployed.
|
|
62
|
+
|
|
63
|
+
## Admin Boundaries
|
|
64
|
+
|
|
65
|
+
What admins **cannot** do:
|
|
66
|
+
|
|
67
|
+
- **Change the `PERMISSIONS` or `PROJECTS` contracts.** These are immutable references set at construction.
|
|
68
|
+
- **Set both `owner` and `projectId` simultaneously.** The `_transferOwnership` internal function reverts if both are non-zero.
|
|
69
|
+
- **Transfer to `address(0)` via `transferOwnership()`.** This reverts with `JBOwnableOverrides_InvalidNewOwner`. Use `renounceOwnership()` instead.
|
|
70
|
+
- **Transfer to a non-existent project.** `transferOwnershipToProject()` checks `projectId <= PROJECTS.count()` and reverts if the project does not exist.
|
|
71
|
+
- **Transfer to `projectId` 0 via `transferOwnershipToProject()`.** Reverts with `JBOwnableOverrides_InvalidNewOwner`.
|
|
72
|
+
- **Transfer to `projectId` exceeding `uint88`.** Reverts with `JBOwnableOverrides_InvalidNewOwner`.
|
|
73
|
+
- **Undo `renounceOwnership()`.** Once ownership is renounced, all `onlyOwner` functions are permanently disabled. There is no recovery mechanism.
|
|
74
|
+
- **Bypass `JBPermissions` for delegation.** Permission delegation is exclusively handled through the external `JBPermissions` contract; `JBOwnable` itself has no operator registry.
|
|
75
|
+
- **Prevent project NFT transfers from changing ownership.** When owned by a project, whoever holds the `JBProjects` ERC-721 is the owner. There is no veto or lock mechanism within `JBOwnable`.
|
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# nana-ownable-v6 — Architecture
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Juicebox-aware ownership module. Extends OpenZeppelin's Ownable pattern to support ownership by either a Juicebox project (via ERC-721) or a direct address, with permission delegation through JBPermissions.
|
|
6
|
+
|
|
7
|
+
## Contract Map
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
src/
|
|
11
|
+
├── JBOwnable.sol — Concrete ownable with constructor
|
|
12
|
+
├── JBOwnableOverrides.sol — Abstract base with onlyOwner modifier logic
|
|
13
|
+
├── interfaces/
|
|
14
|
+
│ └── IJBOwnable.sol — Interface for ownership queries and transfers
|
|
15
|
+
└── structs/
|
|
16
|
+
└── JBOwner.sol — Owner struct: {owner, projectId, permissionId}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Ownership Model
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
JBOwner {
|
|
23
|
+
address owner; — Direct owner address (if projectId == 0)
|
|
24
|
+
uint88 projectId; — JB project ID whose NFT holder is owner (if != 0)
|
|
25
|
+
uint8 permissionId; — Permission ID that grants owner access via JBPermissions
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Resolution order:
|
|
29
|
+
1. If projectId != 0 → owner = JBProjects.ownerOf(projectId)
|
|
30
|
+
2. If projectId == 0 → owner = JBOwner.owner address
|
|
31
|
+
3. Additional access via JBPermissions.hasPermission(operator, owner, projectId, permissionId)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Key Operations
|
|
35
|
+
|
|
36
|
+
### Ownership Transfer
|
|
37
|
+
```
|
|
38
|
+
Current owner → transferOwnership(newOwner)
|
|
39
|
+
→ Can transfer to address or project ID
|
|
40
|
+
→ Emits OwnershipTransferred
|
|
41
|
+
|
|
42
|
+
Current owner → renounceOwnership()
|
|
43
|
+
→ Sets owner to address(0), projectId to 0
|
|
44
|
+
→ Permanently disables owner-only functions
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Dependencies
|
|
48
|
+
- `@bananapus/core-v6` — JBPermissioned, IJBProjects, IJBPermissions
|
|
49
|
+
- `@openzeppelin/contracts` — Context
|
package/RISKS.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# nana-ownable-v6 — Risks
|
|
2
|
+
|
|
3
|
+
## Trust Assumptions
|
|
4
|
+
|
|
5
|
+
1. **JBPermissions** — Permission checks delegate to JBPermissions contract. A bug in JBPermissions affects all JBOwnable contracts.
|
|
6
|
+
2. **JBProjects ERC-721** — When owned by a project, ownership follows the ERC-721 token. Whoever holds the project NFT has owner access.
|
|
7
|
+
3. **Permission Delegation** — Anyone granted the configured `permissionId` via JBPermissions gets owner-equivalent access.
|
|
8
|
+
|
|
9
|
+
## Known Risks
|
|
10
|
+
|
|
11
|
+
| Risk | Description | Mitigation |
|
|
12
|
+
|------|-------------|------------|
|
|
13
|
+
| Permission escalation | Granting `permissionId` gives full owner access to that function | Only grant to trusted operators |
|
|
14
|
+
| Project NFT transfer | Transferring the project NFT transfers ownership of all JBOwnable contracts tied to it | Intentional design; use multisig for project NFT |
|
|
15
|
+
| Renounce is permanent | `renounceOwnership()` is irreversible | Standard OpenZeppelin pattern |
|
|
16
|
+
| Zero address project | Setting `projectId = 0` with `owner = address(0)` permanently locks ownership | Validate before calling |
|
|
17
|
+
|
|
18
|
+
## Privileged Roles
|
|
19
|
+
|
|
20
|
+
| Role | Access | Scope |
|
|
21
|
+
|------|--------|-------|
|
|
22
|
+
| Owner (address or project holder) | All `onlyOwner` functions | Per-contract |
|
|
23
|
+
| Permission delegates | `onlyOwner` functions via JBPermissions | Per-contract, per-permissionId |
|
package/STYLE_GUIDE.md
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
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` as the **single source of truth** for import remappings. Never add remappings to `foundry.toml`.
|
|
472
|
+
|
|
473
|
+
**Principle:** Import paths in Solidity source must match npm package names exactly. With `libs = ["node_modules", "lib"]`, Foundry auto-resolves `@scope/package/path/File.sol` → `node_modules/@scope/package/path/File.sol`. No remapping needed for packages installed as real directories.
|
|
474
|
+
|
|
475
|
+
**Note:** Auto-resolution does **not** work for symlinked packages (e.g. npm workspace links). Workspace repos like `deploy-all-v6` and `nana-cli-v6` need explicit `@scope/package/=node_modules/@scope/package/` remappings for each symlinked dependency.
|
|
476
|
+
|
|
477
|
+
**Minimal content** (most repos):
|
|
478
|
+
|
|
479
|
+
```
|
|
480
|
+
forge-std/=lib/forge-std/src/
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Only add extra remappings for:
|
|
484
|
+
- **`forge-std`** — always needed (git submodule with `src/` subdirectory)
|
|
485
|
+
- **Repo-specific `lib/` submodules** that have no npm package (e.g., `hookmate/=lib/hookmate/src/`)
|
|
486
|
+
- **Symlinked npm packages** — need explicit `@scope/package/=node_modules/@scope/package/` entries
|
|
487
|
+
- **Nested transitive deps** — e.g., `@chainlink/contracts-ccip/` nested inside `@bananapus/suckers-v6/node_modules/`
|
|
488
|
+
|
|
489
|
+
**Never add remappings for:**
|
|
490
|
+
- npm packages that match their import path and are installed as real directories — they auto-resolve
|
|
491
|
+
- Short-form aliases (e.g., `@bananapus/core/` → `@bananapus/core-v6/src/`) — fix the import instead
|
|
492
|
+
- Packages available via npm that are also git submodules — remove the submodule, use npm
|
|
493
|
+
|
|
494
|
+
**Import path convention:**
|
|
495
|
+
|
|
496
|
+
| Package | Import path | Resolves to |
|
|
497
|
+
|---------|------------|-------------|
|
|
498
|
+
| `@bananapus/core-v6` | `@bananapus/core-v6/src/libraries/JBConstants.sol` | `node_modules/@bananapus/core-v6/src/...` |
|
|
499
|
+
| `@openzeppelin/contracts` | `@openzeppelin/contracts/token/ERC20/IERC20.sol` | `node_modules/@openzeppelin/contracts/...` |
|
|
500
|
+
| `@uniswap/v4-core` | `@uniswap/v4-core/src/interfaces/IPoolManager.sol` | `node_modules/@uniswap/v4-core/src/...` |
|
|
501
|
+
|
|
502
|
+
### Linting
|
|
503
|
+
|
|
504
|
+
Solar (Foundry's built-in linter) runs automatically during `forge build`. It scans all `.sol` files in `libs` directories, including `node_modules`.
|
|
505
|
+
|
|
506
|
+
**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.
|
|
507
|
+
|
|
508
|
+
### Fork Tests
|
|
509
|
+
|
|
510
|
+
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.
|
|
511
|
+
|
|
512
|
+
```solidity
|
|
513
|
+
function setUp() public {
|
|
514
|
+
vm.createSelectFork("ethereum");
|
|
515
|
+
// ... setup code
|
|
516
|
+
}
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
The endpoint name (e.g. `"ethereum"`) maps to an env var via `foundry.toml`:
|
|
520
|
+
|
|
521
|
+
```toml
|
|
522
|
+
[rpc_endpoints]
|
|
523
|
+
ethereum = "${RPC_ETHEREUM_MAINNET}"
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
For multi-chain fork tests, add all needed endpoints.
|
|
527
|
+
|
|
528
|
+
### Formatting
|
|
529
|
+
|
|
530
|
+
Run `forge fmt` before committing. The `[fmt]` config in `foundry.toml` enforces:
|
|
531
|
+
- Thousands separators on numbers (`1_000_000`)
|
|
532
|
+
- Multiline function headers when multiple parameters
|
|
533
|
+
- Wrapped comments at reasonable width
|
|
534
|
+
|
|
535
|
+
CI checks formatting via `forge fmt --check`.
|
|
536
|
+
|
|
537
|
+
### Branching
|
|
538
|
+
|
|
539
|
+
- `main` is the primary branch
|
|
540
|
+
- Feature branches for PRs
|
|
541
|
+
- All PRs trigger test + lint workflows
|
|
542
|
+
- Submodule checkout with `--recursive` in CI
|
|
543
|
+
|
|
544
|
+
### Dependencies
|
|
545
|
+
|
|
546
|
+
- Solidity dependencies via npm (`node_modules/`)
|
|
547
|
+
- `forge-std` as a git submodule in `lib/`
|
|
548
|
+
- Sphinx plugins as a devDependency
|
|
549
|
+
- Cross-repo references use `file:../sibling-repo` in local development
|
|
550
|
+
- Published versions use semver ranges (`^0.0.x`) for npm
|
|
551
|
+
|
|
552
|
+
### Contract Size Checks
|
|
553
|
+
|
|
554
|
+
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`.
|
|
555
|
+
|
|
556
|
+
## Repo-Specific Deviations
|
|
557
|
+
|
|
558
|
+
None. This repo follows the standard configuration exactly.
|
package/foundry.lock
ADDED
package/foundry.toml
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
[profile.default]
|
|
2
2
|
solc = '0.8.26'
|
|
3
|
-
evm_version = '
|
|
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/ownable-v6",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"node": ">=20.0.0"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@bananapus/core-v6": "^0.0.
|
|
14
|
-
"@
|
|
13
|
+
"@bananapus/core-v6": "^0.0.15",
|
|
14
|
+
"@bananapus/permission-ids-v6": "^0.0.7",
|
|
15
|
+
"@openzeppelin/contracts": "^5.6.1"
|
|
15
16
|
},
|
|
16
17
|
"scripts": {
|
|
17
18
|
"test": "forge test",
|
|
@@ -12,7 +12,7 @@ import {IJBProjects} from "@bananapus/core-v6/src/interfaces/IJBProjects.sol";
|
|
|
12
12
|
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
13
13
|
|
|
14
14
|
/// @title L65_BurnLockProtection
|
|
15
|
-
/// @notice
|
|
15
|
+
/// @notice Verifies that if a project NFT is burned/invalidated,
|
|
16
16
|
/// owner() returns address(0) and _checkOwner() reverts gracefully instead of
|
|
17
17
|
/// permanently locking the contract with an unrecoverable revert.
|
|
18
18
|
contract L65_BurnLockProtection is Test {
|
|
@@ -11,7 +11,7 @@ import {IJBPermissions} from "@bananapus/core-v6/src/interfaces/IJBPermissions.s
|
|
|
11
11
|
import {IJBProjects} from "@bananapus/core-v6/src/interfaces/IJBProjects.sol";
|
|
12
12
|
|
|
13
13
|
/// @title L66_ZeroAddressValidation
|
|
14
|
-
/// @notice
|
|
14
|
+
/// @notice Verifies that deploying with a zero-address PROJECTS
|
|
15
15
|
/// contract and a non-zero projectId reverts at construction time, preventing
|
|
16
16
|
/// permanently broken project-based ownership.
|
|
17
17
|
contract L66_ZeroAddressValidation is Test {
|