@bananapus/ownable-v6 0.0.1
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/LICENSE +21 -0
- package/README.md +51 -0
- package/SKILLS.md +62 -0
- package/docs/book.css +13 -0
- package/docs/book.toml +12 -0
- package/docs/solidity.min.js +74 -0
- package/docs/src/README.md +131 -0
- package/docs/src/SUMMARY.md +9 -0
- package/docs/src/src/JBOwnable.sol/contract.JBOwnable.md +71 -0
- package/docs/src/src/JBOwnableOverrides.sol/abstract.JBOwnableOverrides.md +216 -0
- package/docs/src/src/README.md +7 -0
- package/docs/src/src/interfaces/IJBOwnable.sol/interface.IJBOwnable.md +67 -0
- package/docs/src/src/interfaces/README.md +4 -0
- package/docs/src/src/structs/JBOwner.sol/struct.JBOwner.md +23 -0
- package/docs/src/src/structs/README.md +4 -0
- package/foundry.toml +12 -0
- package/package.json +17 -0
- package/slither-ci.config.json +10 -0
- package/src/JBOwnable.sol +76 -0
- package/src/JBOwnableOverrides.sol +203 -0
- package/src/interfaces/IJBOwnable.sol +38 -0
- package/src/structs/JBOwner.sol +14 -0
- package/test/Ownable.t.sol +374 -0
- package/test/OwnableAttacks.t.sol +185 -0
- package/test/OwnableInvariantTests.sol +57 -0
- package/test/handlers/OwnableHandler.sol +78 -0
- package/test/mocks/MockOwnable.sol +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Bananapus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# nana-ownable-v6
|
|
2
|
+
|
|
3
|
+
Juicebox-aware ownership model that ties contract ownership to a Juicebox project NFT or an address, with delegated access through `JBPermissions`.
|
|
4
|
+
|
|
5
|
+
This is a variation on OpenZeppelin [`Ownable`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol) that adds:
|
|
6
|
+
|
|
7
|
+
- The ability to transfer contract ownership to a Juicebox project instead of a specific address.
|
|
8
|
+
- The ability to grant other addresses `onlyOwner` access using `JBPermissions`.
|
|
9
|
+
- `JBPermissioned` modifiers with support for OpenZeppelin `Context` (enabling optional meta-transaction support).
|
|
10
|
+
|
|
11
|
+
All features are backwards compatible with OpenZeppelin `Ownable`. This should be a drop-in replacement. Only use `JBOwnableOverrides` if you are overriding OpenZeppelin `Ownable` v4.7.0 or higher.
|
|
12
|
+
|
|
13
|
+
Forked from [`jbx-protocol/juice-ownable`](https://github.com/jbx-protocol/juice-ownable).
|
|
14
|
+
|
|
15
|
+
_If you have questions, take a look at the [core protocol contracts](https://github.com/Bananapus/nana-core) and the [documentation](https://docs.juicebox.money/) first, or reach out on [Discord](https://discord.com/invite/ErQYmth4dS)._
|
|
16
|
+
|
|
17
|
+
## Architecture
|
|
18
|
+
|
|
19
|
+
| Contract | Description |
|
|
20
|
+
|----------|-------------|
|
|
21
|
+
| `JBOwnable` | Concrete implementation providing an `onlyOwner` modifier and ownership transfer events. Inherits `JBOwnableOverrides`. |
|
|
22
|
+
| `JBOwnableOverrides` | Abstract base containing all ownership logic: owner resolution, transfers, renunciation, and permission delegation via `JBPermissions`. |
|
|
23
|
+
|
|
24
|
+
### Supporting Types
|
|
25
|
+
|
|
26
|
+
| Type | Description |
|
|
27
|
+
|------|-------------|
|
|
28
|
+
| `JBOwner` | Struct packing `address owner`, `uint88 projectId`, and `uint8 permissionId` into a single slot. |
|
|
29
|
+
| `IJBOwnable` | Interface exposing ownership queries, transfers, renunciation, and permission ID management. |
|
|
30
|
+
|
|
31
|
+
### Ownership Modes
|
|
32
|
+
|
|
33
|
+
1. **Project ownership** -- If `JBOwner.projectId` is nonzero, the holder of that `JBProjects` ERC-721 is the owner.
|
|
34
|
+
2. **Address ownership** -- If `projectId` is zero, `JBOwner.owner` is the owner directly.
|
|
35
|
+
3. **Delegated access** -- The owner can grant others access via `JBPermissions.setPermissionsFor(...)` using the configured `permissionId`.
|
|
36
|
+
|
|
37
|
+
The `permissionId` resets to 0 on every ownership transfer to prevent permission clashes.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Develop
|
|
46
|
+
|
|
47
|
+
| Command | Description |
|
|
48
|
+
|---------|-------------|
|
|
49
|
+
| `forge build` | Compile contracts |
|
|
50
|
+
| `forge test` | Run tests |
|
|
51
|
+
| `forge coverage --match-path "./src/*.sol" --report lcov --report summary` | Generate coverage report |
|
package/SKILLS.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# nana-ownable-v6
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Drop-in Juicebox-aware replacement for OpenZeppelin `Ownable` that lets a contract be owned by a Juicebox project (via its ERC-721) or a plain address, with delegated access through `JBPermissions`.
|
|
6
|
+
|
|
7
|
+
## Contracts
|
|
8
|
+
|
|
9
|
+
| Contract | Role |
|
|
10
|
+
|----------|------|
|
|
11
|
+
| `JBOwnable` | Concrete modifier (`onlyOwner`) and event emission for ownership transfers. |
|
|
12
|
+
| `JBOwnableOverrides` | Abstract base with ownership state, resolution, transfers, renunciation, and permission delegation. |
|
|
13
|
+
|
|
14
|
+
## Key Functions
|
|
15
|
+
|
|
16
|
+
| Function | Contract | What it does |
|
|
17
|
+
|----------|----------|--------------|
|
|
18
|
+
| `owner()` | `JBOwnableOverrides` | Returns the current owner address -- resolves project NFT holder if `projectId` is set. |
|
|
19
|
+
| `transferOwnership(address)` | `JBOwnableOverrides` | Transfers ownership to a new address. Resets `permissionId`. |
|
|
20
|
+
| `transferOwnershipToProject(uint256)` | `JBOwnableOverrides` | Transfers ownership to a Juicebox project. The project NFT holder becomes owner. |
|
|
21
|
+
| `renounceOwnership()` | `JBOwnableOverrides` | Permanently gives up ownership (sets owner to zero address, projectId to 0). |
|
|
22
|
+
| `setPermissionId(uint8)` | `JBOwnableOverrides` | Changes which `JBPermissions` permission ID grants delegated owner access. |
|
|
23
|
+
| `_checkOwner()` | `JBOwnableOverrides` | Internal view used by `onlyOwner`; calls `_requirePermissionFrom` against the resolved owner. |
|
|
24
|
+
|
|
25
|
+
## Integration Points
|
|
26
|
+
|
|
27
|
+
| Dependency | Import | Used For |
|
|
28
|
+
|------------|--------|----------|
|
|
29
|
+
| `nana-core-v6` | `IJBPermissions`, `JBPermissioned` | Permission checks for delegated access |
|
|
30
|
+
| `nana-core-v6` | `IJBProjects` | Resolving project NFT holder as owner |
|
|
31
|
+
| `@openzeppelin/contracts` | `Context` | `_msgSender()` support |
|
|
32
|
+
|
|
33
|
+
## Key Types
|
|
34
|
+
|
|
35
|
+
| Struct/Enum | Key Fields | Used In |
|
|
36
|
+
|-------------|------------|---------|
|
|
37
|
+
| `JBOwner` | `address owner`, `uint88 projectId`, `uint8 permissionId` | `JBOwnableOverrides.jbOwner` -- single storage slot (160+88+8=256 bits) |
|
|
38
|
+
|
|
39
|
+
## Gotchas
|
|
40
|
+
|
|
41
|
+
- You cannot set both `owner` and `projectId` to nonzero values simultaneously -- `_transferOwnership` reverts with `JBOwnableOverrides_InvalidNewOwner`.
|
|
42
|
+
- Constructor reverts if both `initialOwner` and `initialProjectIdOwner` are zero. To create an unowned contract, set an owner then call `renounceOwnership()` in the constructor body.
|
|
43
|
+
- `_transferOwnership` resets `permissionId` to 0 on every transfer, which revokes all previously delegated access.
|
|
44
|
+
- `projectId` is `uint88`, so project IDs above `type(uint88).max` are rejected by `transferOwnershipToProject`.
|
|
45
|
+
|
|
46
|
+
## Example Integration
|
|
47
|
+
|
|
48
|
+
```solidity
|
|
49
|
+
import {JBOwnable} from "@bananapus/ownable-v6/src/JBOwnable.sol";
|
|
50
|
+
|
|
51
|
+
contract MyHook is JBOwnable {
|
|
52
|
+
constructor(
|
|
53
|
+
IJBPermissions permissions,
|
|
54
|
+
IJBProjects projects,
|
|
55
|
+
uint88 projectId
|
|
56
|
+
) JBOwnable(permissions, projects, address(0), projectId) {}
|
|
57
|
+
|
|
58
|
+
function restrictedAction() external onlyOwner {
|
|
59
|
+
// Only the project NFT holder (or delegated addresses) can call this.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
package/docs/book.css
ADDED
package/docs/book.toml
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
hljs.registerLanguage("solidity",(()=>{"use strict";function e(){try{return!0
|
|
2
|
+
}catch(e){return!1}}
|
|
3
|
+
var a=/-?(\b0[xX]([a-fA-F0-9]_?)*[a-fA-F0-9]|(\b[1-9](_?\d)*(\.((\d_?)*\d)?)?|\.\d(_?\d)*)([eE][-+]?\d(_?\d)*)?|\b0)(?!\w|\$)/
|
|
4
|
+
;e()&&(a=a.source.replace(/\\b/g,"(?<!\\$)\\b"));var s={className:"number",
|
|
5
|
+
begin:a,relevance:0},n={
|
|
6
|
+
keyword:"assembly let function if switch case default for leave break continue u256 jump jumpi stop return revert selfdestruct invalid",
|
|
7
|
+
built_in:"add sub mul div sdiv mod smod exp not lt gt slt sgt eq iszero and or xor byte shl shr sar addmod mulmod signextend keccak256 pc pop dup1 dup2 dup3 dup4 dup5 dup6 dup7 dup8 dup9 dup10 dup11 dup12 dup13 dup14 dup15 dup16 swap1 swap2 swap3 swap4 swap5 swap6 swap7 swap8 swap9 swap10 swap11 swap12 swap13 swap14 swap15 swap16 mload mstore mstore8 sload sstore msize gas address balance selfbalance caller callvalue calldataload calldatasize calldatacopy codesize codecopy extcodesize extcodecopy returndatasize returndatacopy extcodehash create create2 call callcode delegatecall staticcall log0 log1 log2 log3 log4 chainid origin gasprice basefee blockhash coinbase timestamp number difficulty gaslimit",
|
|
8
|
+
literal:"true false"},i={className:"string",
|
|
9
|
+
begin:/\bhex'(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?'/},t={className:"string",
|
|
10
|
+
begin:/\bhex"(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?"/};function r(e){
|
|
11
|
+
return e.inherit(e.APOS_STRING_MODE,{begin:/(\bunicode)?'/})}function l(e){
|
|
12
|
+
return e.inherit(e.QUOTE_STRING_MODE,{begin:/(\bunicode)?"/})}var o={
|
|
13
|
+
SOL_ASSEMBLY_KEYWORDS:n,baseAssembly:e=>{
|
|
14
|
+
var a=r(e),o=l(e),c=/[A-Za-z_$][A-Za-z_$0-9.]*/,d=e.inherit(e.TITLE_MODE,{
|
|
15
|
+
begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:c,keywords:n}),u={className:"params",
|
|
16
|
+
begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:c,keywords:n,
|
|
17
|
+
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,o,s]},_={
|
|
18
|
+
className:"operator",begin:/:=|->/};return{keywords:n,lexemes:c,
|
|
19
|
+
contains:[a,o,i,t,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,_,{
|
|
20
|
+
className:"function",lexemes:c,beginKeywords:"function",end:"{",excludeEnd:!0,
|
|
21
|
+
contains:[d,u,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,_]}]}},
|
|
22
|
+
solAposStringMode:r,solQuoteStringMode:l,HEX_APOS_STRING_MODE:i,
|
|
23
|
+
HEX_QUOTE_STRING_MODE:t,SOL_NUMBER:s,isNegativeLookbehindAvailable:e}
|
|
24
|
+
;const{baseAssembly:c,solAposStringMode:d,solQuoteStringMode:u,HEX_APOS_STRING_MODE:_,HEX_QUOTE_STRING_MODE:m,SOL_NUMBER:b,isNegativeLookbehindAvailable:E}=o
|
|
25
|
+
;return e=>{for(var a=d(e),s=u(e),n=[],i=0;i<32;i++)n[i]=i+1
|
|
26
|
+
;var t=n.map((e=>8*e)),r=[];for(i=0;i<=80;i++)r[i]=i
|
|
27
|
+
;var l=n.map((e=>"bytes"+e)).join(" ")+" ",o=t.map((e=>"uint"+e)).join(" ")+" ",g=t.map((e=>"int"+e)).join(" ")+" ",M=[].concat.apply([],t.map((e=>r.map((a=>e+"x"+a))))),p={
|
|
28
|
+
keyword:"var bool string int uint "+g+o+"byte bytes "+l+"fixed ufixed "+M.map((e=>"fixed"+e)).join(" ")+" "+M.map((e=>"ufixed"+e)).join(" ")+" enum struct mapping address new delete if else for while continue break return throw emit try catch revert unchecked _ function modifier event constructor fallback receive error virtual override constant immutable anonymous indexed storage memory calldata external public internal payable pure view private returns import from as using pragma contract interface library is abstract type assembly",
|
|
29
|
+
literal:"true false wei gwei szabo finney ether seconds minutes hours days weeks years",
|
|
30
|
+
built_in:"self this super selfdestruct suicide now msg block tx abi blockhash gasleft assert require Error Panic sha3 sha256 keccak256 ripemd160 ecrecover addmod mulmod log0 log1 log2 log3 log4"
|
|
31
|
+
},O={className:"operator",begin:/[+\-!~*\/%<>&^|=]/
|
|
32
|
+
},C=/[A-Za-z_$][A-Za-z_$0-9]*/,N={className:"params",begin:/\(/,end:/\)/,
|
|
33
|
+
excludeBegin:!0,excludeEnd:!0,lexemes:C,keywords:p,
|
|
34
|
+
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,b,"self"]},f={
|
|
35
|
+
begin:/\.\s*/,end:/[^A-Za-z0-9$_\.]/,excludeBegin:!0,excludeEnd:!0,keywords:{
|
|
36
|
+
built_in:"gas value selector address length push pop send transfer call callcode delegatecall staticcall balance code codehash wrap unwrap name creationCode runtimeCode interfaceId min max"
|
|
37
|
+
},relevance:2},y=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/,
|
|
38
|
+
lexemes:C,keywords:p}),w={className:"built_in",
|
|
39
|
+
begin:(E()?"(?<!\\$)\\b":"\\b")+"(gas|value|salt)(?=:)"};function x(e,a){return{
|
|
40
|
+
begin:(E()?"(?<!\\$)\\b":"\\b")+e+"\\.\\s*",end:/[^A-Za-z0-9$_\.]/,
|
|
41
|
+
excludeBegin:!1,excludeEnd:!0,lexemes:C,keywords:{built_in:e+" "+a},
|
|
42
|
+
contains:[f],relevance:10}}var h=c(e),v=e.inherit(h,{
|
|
43
|
+
contains:h.contains.concat([{begin:/\./,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,
|
|
44
|
+
excludeEnd:!0,keywords:{built_in:"slot offset length address selector"},
|
|
45
|
+
relevance:2},{begin:/_/,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,excludeEnd:!0,
|
|
46
|
+
keywords:{built_in:"slot offset"},relevance:2}])});return{aliases:["sol"],
|
|
47
|
+
keywords:p,lexemes:C,
|
|
48
|
+
contains:[a,s,_,m,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,b,w,O,{
|
|
49
|
+
className:"function",lexemes:C,
|
|
50
|
+
beginKeywords:"function modifier event constructor fallback receive error",
|
|
51
|
+
end:/[{;]/,excludeEnd:!0,
|
|
52
|
+
contains:[y,N,w,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE],illegal:/%/
|
|
53
|
+
},x("msg","gas value data sender sig"),x("block","blockhash coinbase difficulty gaslimit basefee number timestamp chainid"),x("tx","gasprice origin"),x("abi","decode encode encodePacked encodeWithSelector encodeWithSignature encodeCall"),x("bytes","concat"),f,{
|
|
54
|
+
className:"class",lexemes:C,beginKeywords:"contract interface library",end:"{",
|
|
55
|
+
excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"is",lexemes:C
|
|
56
|
+
},y,N,w,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{lexemes:C,
|
|
57
|
+
beginKeywords:"struct enum",end:"{",excludeEnd:!0,illegal:/[:"\[\]]/,
|
|
58
|
+
contains:[y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{
|
|
59
|
+
beginKeywords:"import",end:";",lexemes:C,keywords:"import from as",
|
|
60
|
+
contains:[y,a,s,_,m,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,O]},{
|
|
61
|
+
beginKeywords:"using",end:";",lexemes:C,keywords:"using for",
|
|
62
|
+
contains:[y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,O]},{className:"meta",
|
|
63
|
+
beginKeywords:"pragma",end:";",lexemes:C,keywords:{
|
|
64
|
+
keyword:"pragma solidity experimental abicoder",
|
|
65
|
+
built_in:"ABIEncoderV2 SMTChecker v1 v2"},
|
|
66
|
+
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(a,{
|
|
67
|
+
className:"meta-string"}),e.inherit(s,{className:"meta-string"})]},{
|
|
68
|
+
beginKeywords:"assembly",end:/\b\B/,
|
|
69
|
+
contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(v,{begin:"{",
|
|
70
|
+
end:"}",endsParent:!0,contains:v.contains.concat([e.inherit(v,{begin:"{",
|
|
71
|
+
end:"}",contains:v.contains.concat(["self"])})])})]}],illegal:/#/}}})());
|
|
72
|
+
|
|
73
|
+
// Ugly hack to reload HLJS
|
|
74
|
+
hljs.initHighlightingOnLoad();
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Bananapus Ownable
|
|
2
|
+
|
|
3
|
+
A Bananapus variation on OpenZeppelin [`Ownable`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol) to enable owner-based access control incorporating Juicebox project ownership and `JBPermissions`.
|
|
4
|
+
|
|
5
|
+
<details>
|
|
6
|
+
<summary>Table of Contents</summary>
|
|
7
|
+
<ol>
|
|
8
|
+
<li><a href="#repository-layout">Repository Layout</a></li>
|
|
9
|
+
<li><a href="#usage">Usage</a></li>
|
|
10
|
+
<ul>
|
|
11
|
+
<li><a href="#install">Install</a></li>
|
|
12
|
+
<li><a href="#develop">Develop</a></li>
|
|
13
|
+
<li><a href="#scripts">Scripts</a></li>
|
|
14
|
+
<li><a href="#tips">Tips</a></li>
|
|
15
|
+
</ul>
|
|
16
|
+
</ul>
|
|
17
|
+
</ol>
|
|
18
|
+
</details>
|
|
19
|
+
|
|
20
|
+
This implementation adds:
|
|
21
|
+
|
|
22
|
+
- The ability to transfer contract ownership to a Juicebox Project instead of a specific address.
|
|
23
|
+
- The ability to grant other addresses `OnlyOwner` access using `JBPermissions`.
|
|
24
|
+
- Includes the `JBPermissioned` modifiers with support for OpenZeppelin [`Context`](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Context.sol). This enables optional meta-transaction support.
|
|
25
|
+
|
|
26
|
+
All features are backwards compatible with OpenZeppelin `Ownable`. This should be a drop-in replacement.
|
|
27
|
+
|
|
28
|
+
This repo contains 2 contracts:
|
|
29
|
+
|
|
30
|
+
1. If your contract does not already use `Ownable` or access controls, use `JBOwnable`.
|
|
31
|
+
2. If your contract extends a contract you cannot easily modify (e.g. a core dependency), and that contract inherits from OpenZeppelin `Ownable`, use `JBOwnableOverride`.
|
|
32
|
+
|
|
33
|
+
**NOTICE:** Only use `JBOwnableOverride` if you are overriding OpenZeppelin `Ownable` v4.7.0 or higher. Otherwise, `JBPermissions` functionality for `onlyOwner` will not work.
|
|
34
|
+
|
|
35
|
+
This repo was forked from [`jbx-protocol/juice-ownable`](https://github.com/jbx-protocol/juice-ownable).
|
|
36
|
+
|
|
37
|
+
_If you're having trouble understanding this contract, take a look at the [core protocol contracts](https://github.com/Bananapus/nana-core) and the [documentation](https://docs.juicebox.money/) first. If you have questions, reach out on [Discord](https://discord.com/invite/ErQYmth4dS)._
|
|
38
|
+
|
|
39
|
+
## Repository Layout
|
|
40
|
+
|
|
41
|
+
The root directory contains this README, an MIT license, and config files.
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
nana-ownable/
|
|
45
|
+
├── src/ - The Solidity source code for the contracts.
|
|
46
|
+
│ ├── JBOwnable.sol - Implements ownable access control for Juicebox projects/permissions.
|
|
47
|
+
│ ├── JBOwnableOverrides.sol - Abstract base contract used by JBOwnable.
|
|
48
|
+
│ ├── interfaces/ - Contract interfaces.
|
|
49
|
+
│ │ └── IJBOwnable.sol - Interface used by JBOwnableOverrides.
|
|
50
|
+
│ └── structs/ - Structs.
|
|
51
|
+
│ └── JBOwner.sol - Owner information for a given instance of JBOwnableOverrides.
|
|
52
|
+
├── test/ - Forge tests and testing utilities. Top level contains the main test files.
|
|
53
|
+
│ ├── handlers/ - Custom handlers for tests.
|
|
54
|
+
│ ├── mock/ - Mocking utilities.
|
|
55
|
+
│ ├── Ownable.t.sol - Main tests.
|
|
56
|
+
│ └── OwnableInvariantTests.t.sol - Invariant test.
|
|
57
|
+
└── .github/
|
|
58
|
+
└── workflows/ - CI/CD workflows.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### Install
|
|
64
|
+
|
|
65
|
+
How to install `nana-ownable` in another project.
|
|
66
|
+
|
|
67
|
+
For projects using `npm` to manage dependencies (recommended):
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npm install @bananapus/ownable
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For projects using `forge` to manage dependencies (not recommended):
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
forge install Bananapus/nana-ownable
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
If you're using `forge` to manage dependencies, add `@bananapus/ownable/=lib/nana-ownable/` to `remappings.txt`. You'll also need to install `nana-ownable`'s dependencies and add similar remappings for them.
|
|
80
|
+
|
|
81
|
+
### Develop
|
|
82
|
+
|
|
83
|
+
`nana-ownable` uses [npm](https://www.npmjs.com/) (version >=20.0.0) for package management and the [Foundry](https://github.com/foundry-rs/foundry) development toolchain for builds, tests, and deployments. To get set up, [install Node.js](https://nodejs.org/en/download) and install [Foundry](https://github.com/foundry-rs/foundry):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
curl -L https://foundry.paradigm.xyz | sh
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
You can download and install dependencies with:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm ci && forge install
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
If you run into trouble with `forge install`, try using `git submodule update --init --recursive` to ensure that nested submodules have been properly initialized.
|
|
96
|
+
|
|
97
|
+
Some useful commands:
|
|
98
|
+
|
|
99
|
+
| Command | Description |
|
|
100
|
+
| --------------------- | --------------------------------------------------- |
|
|
101
|
+
| `forge build` | Compile the contracts and write artifacts to `out`. |
|
|
102
|
+
| `forge fmt` | Lint. |
|
|
103
|
+
| `forge test` | Run the tests. |
|
|
104
|
+
| `forge build --sizes` | Get contract sizes. |
|
|
105
|
+
| `forge coverage` | Generate a test coverage report. |
|
|
106
|
+
| `foundryup` | Update foundry. Run this periodically. |
|
|
107
|
+
| `forge clean` | Remove the build artifacts and cache directories. |
|
|
108
|
+
|
|
109
|
+
To learn more, visit the [Foundry Book](https://book.getfoundry.sh/) docs.
|
|
110
|
+
|
|
111
|
+
### Scripts
|
|
112
|
+
|
|
113
|
+
For convenience, several utility commands are available in `package.json`.
|
|
114
|
+
|
|
115
|
+
| Command | Description |
|
|
116
|
+
| --------------------------------- | -------------------------------------- |
|
|
117
|
+
| `npm test` | Run local tests. |
|
|
118
|
+
| `npm run test:fork` | Run fork tests (for use in CI). |
|
|
119
|
+
| `npm run coverage` | Generate an LCOV test coverage report. |
|
|
120
|
+
|
|
121
|
+
### Tips
|
|
122
|
+
|
|
123
|
+
To view test coverage, run `npm run coverage` to generate an LCOV test report. You can use an extension like [Coverage Gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) to view coverage in your editor.
|
|
124
|
+
|
|
125
|
+
If you're using Nomic Foundation's [Solidity](https://marketplace.visualstudio.com/items?itemName=NomicFoundation.hardhat-solidity) extension in VSCode, you may run into LSP errors because the extension cannot find dependencies outside of `lib`. You can often fix this by running:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
forge remappings >> remappings.txt
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
This makes the extension aware of default remappings.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Summary
|
|
2
|
+
- [Home](README.md)
|
|
3
|
+
# src
|
|
4
|
+
- [❱ interfaces](src/interfaces/README.md)
|
|
5
|
+
- [IJBOwnable](src/interfaces/IJBOwnable.sol/interface.IJBOwnable.md)
|
|
6
|
+
- [❱ structs](src/structs/README.md)
|
|
7
|
+
- [JBOwner](src/structs/JBOwner.sol/structs.JBOwner.md)
|
|
8
|
+
- [JBOwnable](src/JBOwnable.sol/contract.JBOwnable.md)
|
|
9
|
+
- [JBOwnableOverrides](src/JBOwnableOverrides.sol/abstract.JBOwnableOverrides.md)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# JBOwnable
|
|
2
|
+
[Git Source](https://github.com/Bananapus/nana-ownable/blob/a74b3181e75adaf0ee0c93cb00bcc5709ca8f314/src/JBOwnable.sol)
|
|
3
|
+
|
|
4
|
+
**Inherits:**
|
|
5
|
+
[JBOwnableOverrides](/src/JBOwnableOverrides.sol/abstract.JBOwnableOverrides.md)
|
|
6
|
+
|
|
7
|
+
A function restricted by `JBOwnable` can only be called by a Juicebox project's owner, a specified owner
|
|
8
|
+
address (if set), or addresses with permission from the owner.
|
|
9
|
+
|
|
10
|
+
*A function with the `onlyOwner` modifier from `JBOwnable` can only be called by addresses with owner access
|
|
11
|
+
based on a `JBOwner` struct:
|
|
12
|
+
1. If `JBOwner.projectId` isn't zero, the address holding the `JBProjects` NFT with the `JBOwner.projectId` ID is
|
|
13
|
+
the owner.
|
|
14
|
+
2. If `JBOwner.projectId` is set to `0`, the `JBOwner.owner` address is the owner.
|
|
15
|
+
3. The owner can give other addresses access with `JBPermissions.setPermissionsFor(...)`, using the
|
|
16
|
+
`JBOwner.permissionId` permission.*
|
|
17
|
+
|
|
18
|
+
*To use `onlyOwner`, inherit this contract and apply the modifier to a function.*
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Functions
|
|
22
|
+
### constructor
|
|
23
|
+
|
|
24
|
+
*To make a Juicebox project's owner this contract's owner, pass that project's ID as the
|
|
25
|
+
`initialProjectIdOwner`.*
|
|
26
|
+
|
|
27
|
+
*To make a specific address the owner, pass that address as the `initialOwner` and `0` as the
|
|
28
|
+
`initialProjectIdOwner`.*
|
|
29
|
+
|
|
30
|
+
*The owner can give other addresses owner access through the `permissions` contract.*
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
```solidity
|
|
34
|
+
constructor(
|
|
35
|
+
IJBPermissions permissions,
|
|
36
|
+
IJBProjects projects,
|
|
37
|
+
address initialOwner,
|
|
38
|
+
uint88 initialProjectIdOwner
|
|
39
|
+
)
|
|
40
|
+
JBOwnableOverrides(permissions, projects, initialOwner, initialProjectIdOwner);
|
|
41
|
+
```
|
|
42
|
+
**Parameters**
|
|
43
|
+
|
|
44
|
+
|Name|Type|Description|
|
|
45
|
+
|----|----|-----------|
|
|
46
|
+
|`permissions`|`IJBPermissions`|A contract storing permissions.|
|
|
47
|
+
|`projects`|`IJBProjects`|Mints ERC-721s that represent project ownership and transfers.|
|
|
48
|
+
|`initialOwner`|`address`|An address with owner access (until ownership is transferred).|
|
|
49
|
+
|`initialProjectIdOwner`|`uint88`|The ID of the Juicebox project whose owner has owner access (until ownership is transferred).|
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### onlyOwner
|
|
53
|
+
|
|
54
|
+
Reverts if called by an address without owner access.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
```solidity
|
|
58
|
+
modifier onlyOwner() virtual;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### _emitTransferEvent
|
|
62
|
+
|
|
63
|
+
Either `newOwner` or `newProjectId` is non-zero or both are zero. But they can never both be non-zero.
|
|
64
|
+
|
|
65
|
+
*This function exists because some contracts will try to deploy contracts for a project before*
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
```solidity
|
|
69
|
+
function _emitTransferEvent(address previousOwner, address newOwner, uint88 newProjectId) internal virtual override;
|
|
70
|
+
```
|
|
71
|
+
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# JBOwnableOverrides
|
|
2
|
+
[Git Source](https://github.com/Bananapus/nana-ownable/blob/a74b3181e75adaf0ee0c93cb00bcc5709ca8f314/src/JBOwnableOverrides.sol)
|
|
3
|
+
|
|
4
|
+
**Inherits:**
|
|
5
|
+
Context, JBPermissioned, [IJBOwnable](/src/interfaces/IJBOwnable.sol/interface.IJBOwnable.md)
|
|
6
|
+
|
|
7
|
+
An abstract base for `JBOwnable`, which restricts functions so they can only be called by a Juicebox
|
|
8
|
+
project's owner or a specific owner address. The owner can give access permission to other addresses with
|
|
9
|
+
`JBPermissions`.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## State Variables
|
|
13
|
+
### PROJECTS
|
|
14
|
+
Mints ERC-721s that represent project ownership and transfers.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
```solidity
|
|
18
|
+
IJBProjects public immutable override PROJECTS;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### jbOwner
|
|
23
|
+
This contract's owner information.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
```solidity
|
|
27
|
+
JBOwner public override jbOwner;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Functions
|
|
32
|
+
### constructor
|
|
33
|
+
|
|
34
|
+
*To restrict access to a Juicebox project's owner, pass that project's ID as the `initialProjectIdOwner` and
|
|
35
|
+
the zero address as the `initialOwner`.
|
|
36
|
+
To restrict access to a specific address, pass that address as the `initialOwner` and `0` as the
|
|
37
|
+
`initialProjectIdOwner`.*
|
|
38
|
+
|
|
39
|
+
*The owner can give owner access to other addresses through the `permissions` contract.*
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
```solidity
|
|
43
|
+
constructor(
|
|
44
|
+
IJBPermissions permissions,
|
|
45
|
+
IJBProjects projects,
|
|
46
|
+
address initialOwner,
|
|
47
|
+
uint88 initialProjectIdOwner
|
|
48
|
+
)
|
|
49
|
+
JBPermissioned(permissions);
|
|
50
|
+
```
|
|
51
|
+
**Parameters**
|
|
52
|
+
|
|
53
|
+
|Name|Type|Description|
|
|
54
|
+
|----|----|-----------|
|
|
55
|
+
|`permissions`|`IJBPermissions`|A contract storing permissions.|
|
|
56
|
+
|`projects`|`IJBProjects`|Mints ERC-721s that represent project ownership and transfers.|
|
|
57
|
+
|`initialOwner`|`address`|The owner if the `intialProjectIdOwner` is 0 (until ownership is transferred).|
|
|
58
|
+
|`initialProjectIdOwner`|`uint88`|The ID of the Juicebox project whose owner is this contract's owner (until ownership is transferred).|
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### owner
|
|
62
|
+
|
|
63
|
+
Returns the owner's address based on this contract's `JBOwner`.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
```solidity
|
|
67
|
+
function owner() public view virtual returns (address);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### _checkOwner
|
|
71
|
+
|
|
72
|
+
Reverts if the sender is not the owner.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
```solidity
|
|
76
|
+
function _checkOwner() internal view virtual;
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### renounceOwnership
|
|
80
|
+
|
|
81
|
+
Gives up ownership of this contract, making it impossible to call `onlyOwner` and `_checkOwner`
|
|
82
|
+
functions.
|
|
83
|
+
|
|
84
|
+
This can only be called by the current owner.
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
```solidity
|
|
88
|
+
function renounceOwnership() public virtual override;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### setPermissionId
|
|
92
|
+
|
|
93
|
+
Sets the permission ID the owner can use to give other addresses owner access.
|
|
94
|
+
|
|
95
|
+
This can only be called by the current owner.
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
```solidity
|
|
99
|
+
function setPermissionId(uint8 permissionId) public virtual override;
|
|
100
|
+
```
|
|
101
|
+
**Parameters**
|
|
102
|
+
|
|
103
|
+
|Name|Type|Description|
|
|
104
|
+
|----|----|-----------|
|
|
105
|
+
|`permissionId`|`uint8`|The permission ID to use for `onlyOwner`.|
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
### transferOwnership
|
|
109
|
+
|
|
110
|
+
Transfers ownership of this contract to a new address (the `newOwner`). Can only be called by the
|
|
111
|
+
current owner.
|
|
112
|
+
|
|
113
|
+
This can only be called by the current owner.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
```solidity
|
|
117
|
+
function transferOwnership(address newOwner) public virtual override;
|
|
118
|
+
```
|
|
119
|
+
**Parameters**
|
|
120
|
+
|
|
121
|
+
|Name|Type|Description|
|
|
122
|
+
|----|----|-----------|
|
|
123
|
+
|`newOwner`|`address`|The address to transfer ownership to.|
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
### transferOwnershipToProject
|
|
127
|
+
|
|
128
|
+
Transfer ownership of this contract to a new Juicebox project.
|
|
129
|
+
|
|
130
|
+
This can only be called by the current owner.
|
|
131
|
+
|
|
132
|
+
*The `projectId` must fit within a `uint88`.*
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
```solidity
|
|
136
|
+
function transferOwnershipToProject(uint256 projectId) public virtual override;
|
|
137
|
+
```
|
|
138
|
+
**Parameters**
|
|
139
|
+
|
|
140
|
+
|Name|Type|Description|
|
|
141
|
+
|----|----|-----------|
|
|
142
|
+
|`projectId`|`uint256`|The ID of the project to transfer ownership to.|
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### _emitTransferEvent
|
|
146
|
+
|
|
147
|
+
Either `newOwner` or `newProjectId` is non-zero or both are zero. But they can never both be non-zero.
|
|
148
|
+
|
|
149
|
+
*This function exists because some contracts will try to deploy contracts for a project before*
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
```solidity
|
|
153
|
+
function _emitTransferEvent(address previousOwner, address newOwner, uint88 newProjectId) internal virtual;
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### _setPermissionId
|
|
157
|
+
|
|
158
|
+
Sets the permission ID the owner can use to give other addresses owner access.
|
|
159
|
+
|
|
160
|
+
*Internal function without access restriction.*
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
```solidity
|
|
164
|
+
function _setPermissionId(uint8 permissionId) internal virtual;
|
|
165
|
+
```
|
|
166
|
+
**Parameters**
|
|
167
|
+
|
|
168
|
+
|Name|Type|Description|
|
|
169
|
+
|----|----|-----------|
|
|
170
|
+
|`permissionId`|`uint8`|The permission ID to use for `onlyOwner`.|
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
### _transferOwnership
|
|
174
|
+
|
|
175
|
+
Helper to allow for drop-in replacement of OpenZeppelin `Ownable`.
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
```solidity
|
|
179
|
+
function _transferOwnership(address newOwner) internal virtual;
|
|
180
|
+
```
|
|
181
|
+
**Parameters**
|
|
182
|
+
|
|
183
|
+
|Name|Type|Description|
|
|
184
|
+
|----|----|-----------|
|
|
185
|
+
|`newOwner`|`address`|The address that should receive ownership of this contract.|
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
### _transferOwnership
|
|
189
|
+
|
|
190
|
+
Transfers this contract's ownership to an address (`newOwner`) OR a Juicebox project (`projectId`).
|
|
191
|
+
|
|
192
|
+
*Updates this contract's `JBOwner` owner information and resets the `JBOwner.permissionId`.*
|
|
193
|
+
|
|
194
|
+
*If both `newOwner` and `projectId` are set, this will revert.*
|
|
195
|
+
|
|
196
|
+
*Internal function without access restriction.*
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
```solidity
|
|
200
|
+
function _transferOwnership(address newOwner, uint88 projectId) internal virtual;
|
|
201
|
+
```
|
|
202
|
+
**Parameters**
|
|
203
|
+
|
|
204
|
+
|Name|Type|Description|
|
|
205
|
+
|----|----|-----------|
|
|
206
|
+
|`newOwner`|`address`|The address that should become this contract's owner.|
|
|
207
|
+
|`projectId`|`uint88`|The ID of the project whose owner should become this contract's owner.|
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
## Errors
|
|
211
|
+
### JBOwnableOverrides_InvalidNewOwner
|
|
212
|
+
|
|
213
|
+
```solidity
|
|
214
|
+
error JBOwnableOverrides_InvalidNewOwner();
|
|
215
|
+
```
|
|
216
|
+
|