@bananapus/ownable-v6 0.0.34 → 0.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bananapus/ownable-v6",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,8 +17,8 @@
17
17
  "node": ">=20.0.0"
18
18
  },
19
19
  "dependencies": {
20
- "@bananapus/core-v6": "^0.0.72",
21
- "@bananapus/permission-ids-v6": "^0.0.27",
20
+ "@bananapus/core-v6": "^0.0.78",
21
+ "@bananapus/permission-ids-v6": "^0.0.28",
22
22
  "@openzeppelin/contracts": "5.6.1"
23
23
  },
24
24
  "scripts": {
package/src/JBOwnable.sol CHANGED
@@ -67,12 +67,8 @@ contract JBOwnable is JBOwnableOverrides {
67
67
  {
68
68
  address resolvedNewOwner = newOwner;
69
69
  if (newProjectId != 0) {
70
- try PROJECTS.ownerOf(newProjectId) returns (address projectOwner) {
71
- resolvedNewOwner = projectOwner;
72
- } catch {
73
- // Pre-bound future projects have no visible owner yet, so the event reports address(0).
74
- resolvedNewOwner = address(0);
75
- }
70
+ // Pre-bound future projects have no visible owner yet, so the event reports address(0).
71
+ resolvedNewOwner = _projectOwnerOf(newProjectId);
76
72
  }
77
73
 
78
74
  emit OwnershipTransferred({previousOwner: previousOwner, newOwner: resolvedNewOwner, caller: _msgSender()});
@@ -115,12 +115,8 @@ abstract contract JBOwnableOverrides is Context, JBPermissioned, IJBOwnable {
115
115
  return ownerInfo.owner;
116
116
  }
117
117
 
118
- // If the project owner cannot be read, expose the owner as zero instead of bubbling the upstream revert.
119
- try PROJECTS.ownerOf(ownerInfo.projectId) returns (address projectOwner) {
120
- return projectOwner;
121
- } catch {
122
- return address(0);
123
- }
118
+ // Expose the project owner, or zero if the project's NFT cannot be read, instead of bubbling the revert.
119
+ return _projectOwnerOf(ownerInfo.projectId);
124
120
  }
125
121
 
126
122
  //*********************************************************************//
@@ -150,11 +146,7 @@ abstract contract JBOwnableOverrides is Context, JBPermissioned, IJBOwnable {
150
146
  return;
151
147
  } else {
152
148
  // Resolve the project owner dynamically; unreadable projects fail closed to address(0).
153
- try PROJECTS.ownerOf(ownerInfo.projectId) returns (address projectOwner) {
154
- resolvedOwner = projectOwner;
155
- } catch {
156
- resolvedOwner = address(0);
157
- }
149
+ resolvedOwner = _projectOwnerOf(ownerInfo.projectId);
158
150
  }
159
151
 
160
152
  // Ignore the stored permission ID while the project NFT is held by a different owner than the one who set it.
@@ -179,6 +171,22 @@ abstract contract JBOwnableOverrides is Context, JBPermissioned, IJBOwnable {
179
171
  });
180
172
  }
181
173
 
174
+ /// @notice Resolves the current holder of a project's ownership NFT, or `address(0)` if the project's NFT cannot
175
+ /// be read.
176
+ /// @dev Wraps `PROJECTS.ownerOf` in a try-catch so an unreadable project (for example an NFT that has not been
177
+ /// minted yet) resolves to `address(0)` and owner-gated logic fails closed instead of bubbling the revert. The
178
+ /// resolution lives in one place so the try-catch lives in a single function rather than at every call site and in
179
+ /// every contract that inherits this.
180
+ /// @param projectId The ID of the project whose owner to resolve.
181
+ /// @return projectOwner The project's current owner, or `address(0)` if `PROJECTS.ownerOf` reverts.
182
+ function _projectOwnerOf(uint256 projectId) internal view virtual returns (address projectOwner) {
183
+ try PROJECTS.ownerOf(projectId) returns (address resolved) {
184
+ projectOwner = resolved;
185
+ } catch {
186
+ projectOwner = address(0);
187
+ }
188
+ }
189
+
182
190
  //*********************************************************************//
183
191
  // ---------------------- public transactions ------------------------ //
184
192
  //*********************************************************************//
@@ -288,11 +296,7 @@ abstract contract JBOwnableOverrides is Context, JBPermissioned, IJBOwnable {
288
296
  if (ownerInfo.projectId == 0) {
289
297
  oldOwner = ownerInfo.owner;
290
298
  } else {
291
- try PROJECTS.ownerOf(ownerInfo.projectId) returns (address projectOwner) {
292
- oldOwner = projectOwner;
293
- } catch {
294
- oldOwner = address(0);
295
- }
299
+ oldOwner = _projectOwnerOf(ownerInfo.projectId);
296
300
  }
297
301
  // Explicit ownership transfers clear delegated access and the owner who authorized it.
298
302
  jbOwner = JBOwner({owner: newOwner, projectId: projectId, permissionId: 0});