@bananapus/address-registry-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.
- package/ADMINISTRATION.md +39 -0
- package/ARCHITECTURE.md +45 -0
- package/RISKS.md +20 -0
- package/STYLE_GUIDE.md +558 -0
- package/foundry.lock +5 -0
- package/foundry.toml +4 -4
- package/package.json +4 -1
- package/remappings.txt +1 -1
- package/script/Deploy.s.sol +1 -1
- package/script/helpers/AddressRegistryDeploymentLib.sol +1 -1
- package/test/JBAddressRegistryEdge.t.sol +2 -2
- package/test/JBAddressRegistry_Fork.t.sol +1 -7
- package/test/regression/{L67_NonceTruncation.t.sol → NonceTruncation.t.sol} +4 -4
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Administration
|
|
2
|
+
|
|
3
|
+
Admin privileges and their scope in nana-address-registry-v6.
|
|
4
|
+
|
|
5
|
+
## Roles
|
|
6
|
+
|
|
7
|
+
None. `JBAddressRegistry` has no owner, no admin, and no access control. The contract does not inherit from `Ownable`, `AccessControl`, or any permissioned pattern.
|
|
8
|
+
|
|
9
|
+
## Privileged Functions
|
|
10
|
+
|
|
11
|
+
### JBAddressRegistry
|
|
12
|
+
|
|
13
|
+
| Function | Required Role | Permission ID | Scope | What It Does |
|
|
14
|
+
|----------|--------------|---------------|-------|--------------|
|
|
15
|
+
| `registerAddress(address deployer, uint256 nonce)` | None | N/A | Global | Computes a `create` address from deployer + nonce and stores the deployer mapping |
|
|
16
|
+
| `registerAddress(address deployer, bytes32 salt, bytes bytecode)` | None | N/A | Global | Computes a `create2` address from deployer + salt + bytecode and stores the deployer mapping |
|
|
17
|
+
| `deployerOf(address)` | None | N/A | Global | View function — returns the registered deployer for a given address |
|
|
18
|
+
|
|
19
|
+
Every function is callable by any address. There are no restricted operations.
|
|
20
|
+
|
|
21
|
+
## Registration Model
|
|
22
|
+
|
|
23
|
+
- **Fully permissionless.** Any address can register any deployer/nonce or deployer/salt/bytecode combination.
|
|
24
|
+
- **No caller verification.** The registry does not check whether `msg.sender` is the deployer. It only verifies that the computed address is valid by storing the mapping.
|
|
25
|
+
- **Overwritable.** A second registration for the same computed address overwrites the previous deployer mapping. Last writer wins.
|
|
26
|
+
- **Permanent storage, no removal.** There is no `unregister` or `removeAddress` function. Entries can be overwritten but never deleted.
|
|
27
|
+
- **No approval or queue.** Registrations take effect immediately in the same transaction.
|
|
28
|
+
|
|
29
|
+
## Admin Boundaries
|
|
30
|
+
|
|
31
|
+
There are no admins. Specifically:
|
|
32
|
+
|
|
33
|
+
- **No pause mechanism.** The registry cannot be paused or frozen.
|
|
34
|
+
- **No upgrade path.** The contract is not proxied or upgradeable.
|
|
35
|
+
- **No fee extraction.** The contract holds no funds and collects no fees.
|
|
36
|
+
- **No blocklist.** No address can be prevented from registering.
|
|
37
|
+
- **No migration.** There is no way to transfer state to a new registry contract.
|
|
38
|
+
|
|
39
|
+
The only trust assumption is on the frontend side: clients must maintain their own list of trusted deployers and use `deployerOf()` to check whether a contract was deployed by one of them. The registry itself makes no trust judgments.
|
package/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# nana-address-registry-v6 — Architecture
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Deployer verification registry for Juicebox V6. Allows contracts deployed via `create` or `create2` to publicly register their deployer's address. Frontend clients use this to verify that hooks and other contracts were deployed by trusted deployers.
|
|
6
|
+
|
|
7
|
+
## Contract Map
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
src/
|
|
11
|
+
├── JBAddressRegistry.sol — Registry: registerAddress (create/create2), deployerOf mapping
|
|
12
|
+
└── interfaces/
|
|
13
|
+
└── IJBAddressRegistry.sol — Interface
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Key Operations
|
|
17
|
+
|
|
18
|
+
### Registration (create)
|
|
19
|
+
```
|
|
20
|
+
Deployer → JBAddressRegistry.registerAddress(deployer, nonce)
|
|
21
|
+
→ Compute address via RLP encoding of [deployer, nonce]
|
|
22
|
+
→ Store deployerOf[computedAddress] = deployer
|
|
23
|
+
→ Emit AddressRegistered
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Registration (create2)
|
|
27
|
+
```
|
|
28
|
+
Deployer → JBAddressRegistry.registerAddress(deployer, salt, bytecode)
|
|
29
|
+
→ Compute address via keccak256(0xff ++ deployer ++ salt ++ keccak256(bytecode))
|
|
30
|
+
→ Store deployerOf[computedAddress] = deployer
|
|
31
|
+
→ Emit AddressRegistered
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Verification
|
|
35
|
+
```
|
|
36
|
+
Frontend → JBAddressRegistry.deployerOf(hookAddress)
|
|
37
|
+
→ Returns deployer address (or address(0) if unregistered)
|
|
38
|
+
→ Frontend checks deployer against trusted deployer list
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Dependencies
|
|
42
|
+
|
|
43
|
+
- `@sphinx-labs/plugins` — Deployment tooling (devDependency only)
|
|
44
|
+
|
|
45
|
+
No runtime Solidity dependencies — this is a standalone contract.
|
package/RISKS.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# nana-address-registry-v6 — Risks
|
|
2
|
+
|
|
3
|
+
## Trust Assumptions
|
|
4
|
+
|
|
5
|
+
1. **Self-Registration** — Anyone can register any address. The registry does NOT verify that the caller actually deployed the contract. It only verifies that the computed address matches the provided parameters.
|
|
6
|
+
2. **Address Computation** — Relies on correct RLP encoding (create) and keccak256 (create2) for address derivation. Standard Ethereum address computation.
|
|
7
|
+
3. **Frontend Trust** — Frontends must maintain their own list of trusted deployers. The registry only provides the mapping, not a trust judgment.
|
|
8
|
+
|
|
9
|
+
## Known Risks
|
|
10
|
+
|
|
11
|
+
| Risk | Description | Mitigation |
|
|
12
|
+
|------|-------------|------------|
|
|
13
|
+
| False registration | Anyone can call registerAddress — the computed address must match, but the "deployer" parameter is not verified as the actual deployer | Address computation ensures the deployer/nonce pair produced the address |
|
|
14
|
+
| Overwrite | A second registration for the same address overwrites the first | By design; last writer wins |
|
|
15
|
+
| No unregister | Once registered, a deployer mapping cannot be removed | Intentional; provides permanent provenance |
|
|
16
|
+
| Nonce range | Supports nonces up to uint64 max | Covers any realistic Ethereum nonce |
|
|
17
|
+
|
|
18
|
+
## Privileged Roles
|
|
19
|
+
|
|
20
|
+
None — the contract is fully permissionless. Anyone can register, anyone can query.
|
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
|
|
|
@@ -20,3 +17,6 @@ fail_on_revert = false
|
|
|
20
17
|
number_underscore = "thousands"
|
|
21
18
|
multiline_func_header = "all"
|
|
22
19
|
wrap_comments = true
|
|
20
|
+
|
|
21
|
+
[rpc_endpoints]
|
|
22
|
+
ethereum = "${RPC_ETHEREUM_MAINNET}"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bananapus/address-registry-v6",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"artifacts": "source ./.env && npx sphinx artifacts --org-id 'ea165b21-7cdc-4d7b-be59-ecdd4c26bee4' --project-name 'nana-address-registry-v5'"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
+
"@openzeppelin/contracts": "^5.6.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
21
24
|
"@sphinx-labs/plugins": "^0.33.2"
|
|
22
25
|
}
|
|
23
26
|
}
|
package/remappings.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
forge-std/=lib/forge-std/src/
|
package/script/Deploy.s.sol
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.26;
|
|
3
3
|
|
|
4
|
-
import "@sphinx-labs/contracts/SphinxPlugin.sol";
|
|
4
|
+
import "@sphinx-labs/contracts/contracts/foundry/SphinxPlugin.sol";
|
|
5
5
|
import {Script, stdJson, VmSafe} from "forge-std/Script.sol";
|
|
6
6
|
|
|
7
7
|
import "src/JBAddressRegistry.sol";
|
|
@@ -4,7 +4,7 @@ pragma solidity 0.8.26;
|
|
|
4
4
|
import {stdJson} from "forge-std/Script.sol";
|
|
5
5
|
import {Vm} from "forge-std/Vm.sol";
|
|
6
6
|
|
|
7
|
-
import {SphinxConstants, NetworkInfo} from "@sphinx-labs/contracts/SphinxConstants.sol";
|
|
7
|
+
import {SphinxConstants, NetworkInfo} from "@sphinx-labs/contracts/contracts/foundry/SphinxConstants.sol";
|
|
8
8
|
import {IJBAddressRegistry} from "../../src/interfaces/IJBAddressRegistry.sol";
|
|
9
9
|
|
|
10
10
|
struct AddressRegistryDeployment {
|
|
@@ -276,7 +276,7 @@ contract JBAddressRegistryEdge is Test {
|
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
// =========================================================================
|
|
279
|
-
// Nonce > uint64 - reverts with NonceTooLarge (
|
|
279
|
+
// Nonce > uint64 - reverts with NonceTooLarge (extended to uint64)
|
|
280
280
|
// =========================================================================
|
|
281
281
|
|
|
282
282
|
/// @notice Nonces above uint64 max revert instead of silently truncating.
|
|
@@ -290,7 +290,7 @@ contract JBAddressRegistryEdge is Test {
|
|
|
290
290
|
registry.registerAddress(deployer1, tooLargeNonce);
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
/// @notice Nonces in the uint32-uint64 range now succeed (
|
|
293
|
+
/// @notice Nonces in the uint32-uint64 range now succeed (extended support).
|
|
294
294
|
function test_nonceInUint40Range_succeeds() public {
|
|
295
295
|
registry.registerAddress(deployer, uint256(type(uint40).max));
|
|
296
296
|
}
|
|
@@ -13,14 +13,8 @@ contract JBAddressRegistryTest_Fork is Test {
|
|
|
13
13
|
JBAddressRegistry registry;
|
|
14
14
|
|
|
15
15
|
function setUp() public {
|
|
16
|
-
// Skip fork tests when the RPC URL is not available (e.g. in CI).
|
|
17
|
-
string memory rpcUrl = vm.envOr("RPC_ETHEREUM_MAINNET", string(""));
|
|
18
|
-
if (bytes(rpcUrl).length == 0) {
|
|
19
|
-
vm.skip(true);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
// Start a mainnet fork.
|
|
23
|
-
vm.createSelectFork(
|
|
17
|
+
vm.createSelectFork("ethereum", blockHeight);
|
|
24
18
|
|
|
25
19
|
registry = new JBAddressRegistry();
|
|
26
20
|
}
|
|
@@ -4,11 +4,11 @@ pragma solidity ^0.8.26;
|
|
|
4
4
|
import {Test} from "forge-std/Test.sol";
|
|
5
5
|
import {JBAddressRegistry} from "../../src/JBAddressRegistry.sol";
|
|
6
6
|
|
|
7
|
-
/// @title
|
|
8
|
-
/// @notice
|
|
7
|
+
/// @title NonceTruncation
|
|
8
|
+
/// @notice _addressFrom originally only handled nonces up to uint32 max,
|
|
9
9
|
/// silently truncating larger values. The fix extends RLP encoding to uint64 max and adds
|
|
10
10
|
/// an explicit revert for nonces beyond that range.
|
|
11
|
-
contract
|
|
11
|
+
contract NonceTruncation is Test {
|
|
12
12
|
JBAddressRegistry registry;
|
|
13
13
|
address deployer = makeAddr("deployer");
|
|
14
14
|
|
|
@@ -21,7 +21,7 @@ contract L67_NonceTruncation is Test {
|
|
|
21
21
|
registry.registerAddress(deployer, type(uint32).max);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
/// @notice Nonce one above uint32 max should now succeed (uint64 support added
|
|
24
|
+
/// @notice Nonce one above uint32 max should now succeed (uint64 support added).
|
|
25
25
|
function test_nonceAboveUint32Max_succeeds() public {
|
|
26
26
|
uint256 nonce = uint256(type(uint32).max) + 1;
|
|
27
27
|
// Should not revert -- the fix extended support to uint64.
|