@bananapus/721-hook-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.
Files changed (100) hide show
  1. package/.gas-snapshot +152 -0
  2. package/LICENSE +21 -0
  3. package/README.md +253 -0
  4. package/SKILLS.md +140 -0
  5. package/docs/book.css +13 -0
  6. package/docs/book.toml +12 -0
  7. package/docs/solidity.min.js +74 -0
  8. package/docs/src/README.md +253 -0
  9. package/docs/src/SUMMARY.md +38 -0
  10. package/docs/src/src/JB721TiersHook.sol/contract.JB721TiersHook.md +645 -0
  11. package/docs/src/src/JB721TiersHookDeployer.sol/contract.JB721TiersHookDeployer.md +99 -0
  12. package/docs/src/src/JB721TiersHookProjectDeployer.sol/contract.JB721TiersHookProjectDeployer.md +288 -0
  13. package/docs/src/src/JB721TiersHookStore.sol/contract.JB721TiersHookStore.md +1096 -0
  14. package/docs/src/src/README.md +11 -0
  15. package/docs/src/src/abstract/ERC721.sol/abstract.ERC721.md +430 -0
  16. package/docs/src/src/abstract/JB721Hook.sol/abstract.JB721Hook.md +309 -0
  17. package/docs/src/src/abstract/README.md +5 -0
  18. package/docs/src/src/interfaces/IJB721Hook.sol/interface.IJB721Hook.md +29 -0
  19. package/docs/src/src/interfaces/IJB721TiersHook.sol/interface.IJB721TiersHook.md +203 -0
  20. package/docs/src/src/interfaces/IJB721TiersHookDeployer.sol/interface.IJB721TiersHookDeployer.md +25 -0
  21. package/docs/src/src/interfaces/IJB721TiersHookProjectDeployer.sol/interface.IJB721TiersHookProjectDeployer.md +64 -0
  22. package/docs/src/src/interfaces/IJB721TiersHookStore.sol/interface.IJB721TiersHookStore.md +265 -0
  23. package/docs/src/src/interfaces/IJB721TokenUriResolver.sol/interface.IJB721TokenUriResolver.md +12 -0
  24. package/docs/src/src/interfaces/README.md +9 -0
  25. package/docs/src/src/libraries/JB721Constants.sol/library.JB721Constants.md +14 -0
  26. package/docs/src/src/libraries/JB721TiersRulesetMetadataResolver.sol/library.JB721TiersRulesetMetadataResolver.md +68 -0
  27. package/docs/src/src/libraries/JBBitmap.sol/library.JBBitmap.md +82 -0
  28. package/docs/src/src/libraries/JBIpfsDecoder.sol/library.JBIpfsDecoder.md +61 -0
  29. package/docs/src/src/libraries/README.md +7 -0
  30. package/docs/src/src/structs/JB721InitTiersConfig.sol/struct.JB721InitTiersConfig.md +27 -0
  31. package/docs/src/src/structs/JB721Tier.sol/struct.JB721Tier.md +59 -0
  32. package/docs/src/src/structs/JB721TierConfig.sol/struct.JB721TierConfig.md +60 -0
  33. package/docs/src/src/structs/JB721TiersHookFlags.sol/struct.JB721TiersHookFlags.md +26 -0
  34. package/docs/src/src/structs/JB721TiersMintReservesConfig.sol/struct.JB721TiersMintReservesConfig.md +16 -0
  35. package/docs/src/src/structs/JB721TiersRulesetMetadata.sol/struct.JB721TiersRulesetMetadata.md +20 -0
  36. package/docs/src/src/structs/JB721TiersSetDiscountPercentConfig.sol/struct.JB721TiersSetDiscountPercentConfig.md +16 -0
  37. package/docs/src/src/structs/JBBitmapWord.sol/struct.JBBitmapWord.md +19 -0
  38. package/docs/src/src/structs/JBDeploy721TiersHookConfig.sol/struct.JBDeploy721TiersHookConfig.md +34 -0
  39. package/docs/src/src/structs/JBLaunchProjectConfig.sol/struct.JBLaunchProjectConfig.md +23 -0
  40. package/docs/src/src/structs/JBLaunchRulesetsConfig.sol/struct.JBLaunchRulesetsConfig.md +22 -0
  41. package/docs/src/src/structs/JBPayDataHookRulesetConfig.sol/struct.JBPayDataHookRulesetConfig.md +51 -0
  42. package/docs/src/src/structs/JBPayDataHookRulesetMetadata.sol/struct.JBPayDataHookRulesetMetadata.md +66 -0
  43. package/docs/src/src/structs/JBQueueRulesetsConfig.sol/struct.JBQueueRulesetsConfig.md +21 -0
  44. package/docs/src/src/structs/JBStored721Tier.sol/struct.JBStored721Tier.md +42 -0
  45. package/docs/src/src/structs/README.md +18 -0
  46. package/foundry.lock +11 -0
  47. package/foundry.toml +22 -0
  48. package/package.json +31 -0
  49. package/remappings.txt +1 -0
  50. package/script/Deploy.s.sol +140 -0
  51. package/script/helpers/Hook721DeploymentLib.sol +81 -0
  52. package/slither-ci.config.json +10 -0
  53. package/sphinx.lock +476 -0
  54. package/src/JB721TiersHook.sol +765 -0
  55. package/src/JB721TiersHookDeployer.sol +114 -0
  56. package/src/JB721TiersHookProjectDeployer.sol +413 -0
  57. package/src/JB721TiersHookStore.sol +1195 -0
  58. package/src/abstract/ERC721.sol +484 -0
  59. package/src/abstract/JB721Hook.sol +279 -0
  60. package/src/interfaces/IJB721Hook.sol +21 -0
  61. package/src/interfaces/IJB721TiersHook.sol +135 -0
  62. package/src/interfaces/IJB721TiersHookDeployer.sol +22 -0
  63. package/src/interfaces/IJB721TiersHookProjectDeployer.sol +76 -0
  64. package/src/interfaces/IJB721TiersHookStore.sol +220 -0
  65. package/src/interfaces/IJB721TokenUriResolver.sol +10 -0
  66. package/src/libraries/JB721Constants.sol +7 -0
  67. package/src/libraries/JB721TiersRulesetMetadataResolver.sol +44 -0
  68. package/src/libraries/JBBitmap.sol +57 -0
  69. package/src/libraries/JBIpfsDecoder.sol +95 -0
  70. package/src/structs/JB721InitTiersConfig.sol +20 -0
  71. package/src/structs/JB721Tier.sol +39 -0
  72. package/src/structs/JB721TierConfig.sol +40 -0
  73. package/src/structs/JB721TiersHookFlags.sol +17 -0
  74. package/src/structs/JB721TiersMintReservesConfig.sol +9 -0
  75. package/src/structs/JB721TiersRulesetMetadata.sol +12 -0
  76. package/src/structs/JB721TiersSetDiscountPercentConfig.sol +9 -0
  77. package/src/structs/JBBitmapWord.sol +11 -0
  78. package/src/structs/JBDeploy721TiersHookConfig.sol +25 -0
  79. package/src/structs/JBLaunchProjectConfig.sol +18 -0
  80. package/src/structs/JBLaunchRulesetsConfig.sol +17 -0
  81. package/src/structs/JBPayDataHookRulesetConfig.sol +44 -0
  82. package/src/structs/JBPayDataHookRulesetMetadata.sol +46 -0
  83. package/src/structs/JBQueueRulesetsConfig.sol +13 -0
  84. package/src/structs/JBStored721Tier.sol +24 -0
  85. package/test/721HookAttacks.t.sol +396 -0
  86. package/test/E2E/Pay_Mint_Redeem_E2E.t.sol +944 -0
  87. package/test/invariants/TierLifecycleInvariant.t.sol +187 -0
  88. package/test/invariants/TieredHookStoreInvariant.t.sol +81 -0
  89. package/test/invariants/handlers/TierLifecycleHandler.sol +262 -0
  90. package/test/invariants/handlers/TierStoreHandler.sol +155 -0
  91. package/test/unit/JB721TiersRulesetMetadataResolver.t.sol +141 -0
  92. package/test/unit/JBBitmap.t.sol +169 -0
  93. package/test/unit/JBIpfsDecoder.t.sol +131 -0
  94. package/test/unit/M6_TierSupplyCheck.t.sol +220 -0
  95. package/test/unit/adjustTier_Unit.t.sol +1740 -0
  96. package/test/unit/deployer_Unit.t.sol +103 -0
  97. package/test/unit/getters_constructor_Unit.t.sol +548 -0
  98. package/test/unit/mintFor_mintReservesFor_Unit.t.sol +443 -0
  99. package/test/unit/pay_Unit.t.sol +1537 -0
  100. package/test/unit/redeem_Unit.t.sol +459 -0
@@ -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,253 @@
1
+ # Bananapus NFT Hook
2
+
3
+ `nana-721-hook` is:
4
+
5
+ 1. A pay hook for Juicebox projects to sell tiered NFTs (ERC-721s) with different prices and artwork.
6
+ 2. (Optionally) a redeem hook which allows holders to burn their NFTs to reclaim funds from the project, in proportion to the NFT's price.
7
+
8
+ <details>
9
+ <summary>Table of Contents</summary>
10
+ <ol>
11
+ <li><a href="#usage">Usage</a></li>
12
+ <ul>
13
+ <li><a href="#install">Install</a></li>
14
+ <li><a href="#develop">Develop</a></li>
15
+ <li><a href="#scripts">Scripts</a></li>
16
+ <li><a href="#deployments">Deployments</a></li>
17
+ <ul>
18
+ <li><a href="#with-sphinx">With Sphinx</a></li>
19
+ <li><a href="#without-sphinx">Without Sphinx</a></li>
20
+ </ul>
21
+ <li><a href="#tips">Tips</a></li>
22
+ </ul>
23
+ <li><a href="#repository-layout">Repository Layout</a></li>
24
+ <li><a href="#architecture">Architecture</a></li>
25
+ <ul>
26
+ <li><a href="#contracts">Contracts</a></li>
27
+ </ul>
28
+ <li><a href="#description">Description</a></li>
29
+ <ul>
30
+ <li><a href="#hooks">Hooks</a></li>
31
+ <li><a href="#mechanism">Mechanism</a></li>
32
+ <li><a href="#setup">Setup</a></li>
33
+ </ul>
34
+ </ul>
35
+ </ol>
36
+ </details>
37
+
38
+ _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)._
39
+
40
+ ## Usage
41
+
42
+ ### Install
43
+
44
+ How to install `nana-721-hook` in another project.
45
+
46
+ For projects using `npm` to manage dependencies (recommended):
47
+
48
+ ```bash
49
+ npm install @bananapus/721-hook
50
+ ```
51
+
52
+ For projects using `forge` to manage dependencies (not recommended):
53
+
54
+ ```bash
55
+ forge install Bananapus/nana-721-hook
56
+ ```
57
+
58
+ If you're using `forge` to manage dependencies, add `@bananapus/721-hook/=lib/nana-721-hook/` to `remappings.txt`. You'll also need to install `nana-721-hook`'s dependencies and add similar remappings for them.
59
+
60
+ ### Develop
61
+
62
+ `nana-721-hook` 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):
63
+
64
+ ```bash
65
+ curl -L https://foundry.paradigm.xyz | sh
66
+ ```
67
+
68
+ You can download and install dependencies with:
69
+
70
+ ```bash
71
+ npm ci && forge install
72
+ ```
73
+
74
+ If you run into trouble with `forge install`, try using `git submodule update --init --recursive` to ensure that nested submodules have been properly initialized.
75
+
76
+ Some useful commands:
77
+
78
+ | Command | Description |
79
+ | --------------------- | --------------------------------------------------- |
80
+ | `forge build` | Compile the contracts and write artifacts to `out`. |
81
+ | `forge fmt` | Lint. |
82
+ | `forge test` | Run the tests. |
83
+ | `forge build --sizes` | Get contract sizes. |
84
+ | `forge coverage` | Generate a test coverage report. |
85
+ | `foundryup` | Update foundry. Run this periodically. |
86
+ | `forge clean` | Remove the build artifacts and cache directories. |
87
+
88
+ To learn more, visit the [Foundry Book](https://book.getfoundry.sh/) docs.
89
+
90
+ ### Scripts
91
+
92
+ For convenience, several utility commands are available in `package.json`.
93
+
94
+ | Command | Description |
95
+ | ------------------- | ------------------------------------------------------- |
96
+ | `npm test` | Run local tests. |
97
+ | `npm run coverage` | Generate an LCOV test coverage report. |
98
+ | `npm run artifacts` | Fetch Sphinx artifacts and write them to `deployments/` |
99
+
100
+ ### Deployments
101
+
102
+ #### With Sphinx
103
+
104
+ `nana-721-hook` manages deployments with [Sphinx](https://www.sphinx.dev). To run the deployment scripts, install the npm `devDependencies` with:
105
+
106
+ ```bash
107
+ `npm ci --also=dev`
108
+ ```
109
+
110
+ You'll also need to set up a `.env` file based on `.example.env`. Then run one of the following commands:
111
+
112
+ | Command | Description |
113
+ | ------------------------- | ---------------------------- |
114
+ | `npm run deploy:mainnets` | Propose mainnet deployments. |
115
+ | `npm run deploy:testnets` | Propose testnet deployments. |
116
+
117
+ Your teammates can review and approve the proposed deployments in the Sphinx UI. Once approved, the deployments will be executed.
118
+
119
+ #### Without Sphinx
120
+
121
+ You can use the Sphinx CLI to run the deployment scripts without paying for Sphinx. First, install the npm `devDependencies` with:
122
+
123
+ ```bash
124
+ `npm ci --also=dev`
125
+ ```
126
+
127
+ You can deploy the contracts like so:
128
+
129
+ ```bash
130
+ PRIVATE_KEY="0x123..." RPC_ETHEREUM_SEPOLIA="https://rpc.ankr.com/eth_sepolia" npx sphinx deploy script/Deploy.s.sol --network ethereum_sepolia
131
+ ```
132
+
133
+ This example deploys `nana-721-hook` to the Sepolia testnet using the specified private key. You can configure new networks in `foundry.toml`.
134
+
135
+ ### Tips
136
+
137
+ 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.
138
+
139
+ 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:
140
+
141
+ ```bash
142
+ forge remappings >> remappings.txt
143
+ ```
144
+
145
+ This makes the extension aware of default remappings.
146
+
147
+ ## Repository Layout
148
+
149
+ The root directory contains this README, an MIT license, and config files. The important source directories are:
150
+
151
+ ```
152
+ nana-721-hook/
153
+ ├── script/
154
+ │ ├── Deploy.s.sol - Deploys core contracts - the hook store, deployer, and project deployer.
155
+ │ ├── LaunchProjectFor.s.sol - (DEPRECATED) Deploys a project with a 721 tiers hook.
156
+ │ └── helpers/
157
+ │ └── Hook721DeploymentLib.sol - Internal helpers for deployment scripts.
158
+ ├── src/ - Contract source code. Top level contains implementation contracts.
159
+ │ ├── JB721TiersHook.sol - The core tiered NFT pay/redeem hook.
160
+ │ ├── JB721TiersHookDeployer.sol - Deploys an NFT hook for a project.
161
+ │ ├── JB721TiersHookProjectDeployer.sol - Deploys a project with a tiered NFT hook.
162
+ │ ├── JB721TiersHookStore.sol - Stores and manages data for tiered NFT hooks.
163
+ │ ├── abstract/
164
+ │ │ ├── ERC721.sol - Abstract ERC-721 implementation.
165
+ │ │ └── JB721Hook.sol - Abstract NFT hook implementation.
166
+ │ ├── interfaces/ - Contract interfaces.
167
+ │ ├── libraries/ - Libraries.
168
+ │ └── structs/ - Structs.
169
+ └── test/ - Forge tests and testing utilities.
170
+ ├── E2E/
171
+ │ └── Pay_Mint_Redeem_E2E.t.sol - End-to-end test for minting and redeeming NFTs.
172
+ ├── unit/ - Unit tests for various components..
173
+ └── utils/ - Miscellaneous testing utilities.
174
+ ```
175
+
176
+ Other directories:
177
+
178
+ ```
179
+ nana-721-hook/
180
+ ├── .github/
181
+ │ └── workflows/ - CI/CD workflows.
182
+ └── deployments/ - Sphinx deployment logs.
183
+ ```
184
+
185
+ ## Architecture
186
+
187
+ ```mermaid
188
+ graph TD;
189
+ A[JB721TiersHookProjectDeployer] -->|Launches & queues rulesets for| B[Juicebox projects]
190
+ D[JB721TiersHookDeployer] -->|Adds NFT hooks to| B
191
+ A -->|Deploys| C[JB721TiersHook]
192
+ D -->|Deploys| C
193
+ B -->|Calls upon pay/redeem| C
194
+ C -->|Stores data in| E[JB721TiersHookStore]
195
+ B -->|Uses| F[Pay/redeem terminal]
196
+ C -->|Mints NFTs upon payment through| F
197
+ C -->|Burns NFTs to reclaim funds through| F
198
+ ```
199
+
200
+ ### Contracts
201
+
202
+ | Contract | Description |
203
+ | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
204
+ | [`JB721TiersHook.sol`](https://github.com/Bananapus/nana-721-hook/blob/main/src/JB721TiersHook.sol) | The core tiered NFT pay/redeem hook implementation. |
205
+ | [`JB721TiersHookDeployer.sol`](https://github.com/Bananapus/nana-721-hook/blob/main/src/JB721TiersHookDeployer.sol) | Exposes a `deployHookFor(…)` function which allows deploys an NFT hook for a project. |
206
+ | [`JB721TiersHookProjectDeployer.sol`](https://github.com/Bananapus/nana-721-hook/blob/main/src/JB721TiersHookProjectDeployer.sol) | Exposes a `launchProjectFor(…)` function which deploys a project with a tiered NFT hook already set up. |
207
+ | [`JB721TiersHookStore.sol`](https://github.com/Bananapus/nana-721-hook/blob/main/src/JB721TiersHookStore.sol) | Stores and manages data for tiered NFT hooks. |
208
+
209
+ ## Description
210
+
211
+ ### Hooks
212
+
213
+ This contract is a _data hook_, a _pay hook_, and a _redeem hook_. Data hooks receive information about a payment or a redemption, and put together a payload for the pay/redeem hook to execute.
214
+
215
+ Juicebox projects can specify a data hook in their `JBRulesetMetadata`. When someone attempts to pay or redeem from the project, the project's terminal records the payment in the terminal store, passing information about the payment/redemption to the data hook in the process. The data hook responds with a list of payloads – each payload specifies the address of a pay/redeem hook, as well as some custom data and an amount of funds to send to that pay/redeem hook.
216
+
217
+ Each pay/redeem hook can then execute custom behavior based on the custom data (and funds) they receive.
218
+
219
+ ### Mechanism
220
+
221
+ A project using a 721 tiers hook can specify any number of NFT tiers.
222
+
223
+ - NFT tiers can be removed by the project owner as long as they are not locked.
224
+ - NFT tiers can be added by the project owner as long as they respect the hook's `flags`. The flags specify if newly added tiers can have votes (voting units), if new tiers can have non-zero reserve frequencies, if new tiers can allow on-demand minting by the project's owner, and if the tier can be removed.
225
+
226
+ Each tier has the following optional properties:
227
+
228
+ - A price.
229
+ - A supply (the maximum number of NFTs which can be minted from the tier).
230
+ - A token URI (artwork and metadata), which can be overridden by a URI resolver. The URI resolver can return unique values for each NFT in the tier.
231
+ - A category, so tiers can be organized and accessed for different purposes.
232
+ - A reserve frequency (optional). With a reserve frequency of 5, an extra NFT will be minted to a pre-specified beneficiary address for every 5 NFTs purchased and minted from the tier.
233
+ - A number of votes each NFT should represent on-chain (optional).
234
+ - A flag to specify whether the NFTs in the tier can always be transferred, or if transfers can be paused depending on the project's ruleset.
235
+ - A flag to specify whether the contract's owner can mint NFTs from the tier on-demand.
236
+ - A set of flags which restrict tiers added in the future (the votes/reserved frequency/on-demand minting/can be removed flags noted above).
237
+
238
+ Additional notes:
239
+
240
+ - A payer can specify any number of tiers to mint as long as the total price does not exceed the amount being paid. If tiers aren't specified, their payment mints the most expensive tier possible, unless they specify that the hook should not mint any NFTs.
241
+ - If the payment and a tier's price are specified in different currencies, the `JBPrices` contract is used to normalize the values.
242
+ - If some of a payment does not go towards purchasing an NFT, those extra funds will be stored as "NFT credits" which can be used for future purchases. Optionally, the hook can disallow credits and reject payments with leftover funds.
243
+ - If enabled by the project owner, holders can burn their NFTs to reclaim funds from the project. These redemptions are proportional to the NFTs price, relative to the combined price of all the NFTs.
244
+ - NFT redemptions can be enabled by setting `useDataHookForRedeem` to `true` in the project's `JBRulesetMetadata`. If NFT redemptions are enabled, project token redemptions are disabled.
245
+ - The hook's deployer can choose if the NFTs should support on-chain voting (as `ERC721Votes`). This increases the gas fees to interact with the NFTs, and should be disabled if not needed.
246
+
247
+ ### Setup
248
+
249
+ To use a 721 tiers hook, a Juicebox project should be created by a `JB721TiersHookProjectDeployer` instead of a `JBController`. The deployer will create a `JB721TiersHook` (through an associated `JB721TiersHookDeployer`) and add it to the project's first ruleset. New rulesets can be queued with `JB721TiersHookProjectDeployer.queueRulesetsOf(…)` if the project's owner gives the project deployer the permission [`JBPermissions.QUEUE_RULESETS`](https://github.com/Bananapus/nana-permission-ids/blob/master/src/JBPermissionIds.sol) (ID `2`) in [`JBPermissions`](https://github.com/Bananapus/nana-core/blob/main/src/JBPermissions.sol).
250
+
251
+ It's also possible to add a 721 tiers hook to an existing project by calling `JB721TiersHookDeployer.deployHookFor(…)` and adding the hook to the project's ruleset – specifically, the project must set their [`JBRulesetMetadata.dataHook`](https://github.com/Bananapus/nana-core/blob/main/src/structs/JBRulesetMetadata.sol) to the newly deployed hook, and enable `JBRulesetMetadata.useDataHookForPay` and/or `JBRulesetMetadata.useDataHookForRedeem` depending on the functionality they'd like to enable.
252
+
253
+ All `JB721TiersHook`s store their data in the `JB721TiersHookStore` contract.
@@ -0,0 +1,38 @@
1
+ # Summary
2
+ - [Home](README.md)
3
+ # src
4
+ - [❱ abstract](src/abstract/README.md)
5
+ - [ERC721](src/abstract/ERC721.sol/abstract.ERC721.md)
6
+ - [JB721Hook](src/abstract/JB721Hook.sol/abstract.JB721Hook.md)
7
+ - [❱ interfaces](src/interfaces/README.md)
8
+ - [IJB721Hook](src/interfaces/IJB721Hook.sol/interface.IJB721Hook.md)
9
+ - [IJB721TiersHook](src/interfaces/IJB721TiersHook.sol/interface.IJB721TiersHook.md)
10
+ - [IJB721TiersHookDeployer](src/interfaces/IJB721TiersHookDeployer.sol/interface.IJB721TiersHookDeployer.md)
11
+ - [IJB721TiersHookProjectDeployer](src/interfaces/IJB721TiersHookProjectDeployer.sol/interface.IJB721TiersHookProjectDeployer.md)
12
+ - [IJB721TiersHookStore](src/interfaces/IJB721TiersHookStore.sol/interface.IJB721TiersHookStore.md)
13
+ - [IJB721TokenUriResolver](src/interfaces/IJB721TokenUriResolver.sol/interface.IJB721TokenUriResolver.md)
14
+ - [❱ libraries](src/libraries/README.md)
15
+ - [JB721Constants](src/libraries/JB721Constants.sol/library.JB721Constants.md)
16
+ - [JB721TiersRulesetMetadataResolver](src/libraries/JB721TiersRulesetMetadataResolver.sol/library.JB721TiersRulesetMetadataResolver.md)
17
+ - [JBBitmap](src/libraries/JBBitmap.sol/library.JBBitmap.md)
18
+ - [JBIpfsDecoder](src/libraries/JBIpfsDecoder.sol/library.JBIpfsDecoder.md)
19
+ - [❱ structs](src/structs/README.md)
20
+ - [JB721InitTiersConfig](src/structs/JB721InitTiersConfig.sol/struct.JB721InitTiersConfig.md)
21
+ - [JB721Tier](src/structs/JB721Tier.sol/struct.JB721Tier.md)
22
+ - [JB721TierConfig](src/structs/JB721TierConfig.sol/struct.JB721TierConfig.md)
23
+ - [JB721TiersHookFlags](src/structs/JB721TiersHookFlags.sol/struct.JB721TiersHookFlags.md)
24
+ - [JB721TiersMintReservesConfig](src/structs/JB721TiersMintReservesConfig.sol/struct.JB721TiersMintReservesConfig.md)
25
+ - [JB721TiersRulesetMetadata](src/structs/JB721TiersRulesetMetadata.sol/struct.JB721TiersRulesetMetadata.md)
26
+ - [JB721TiersSetDiscountPercentConfig](src/structs/JB721TiersSetDiscountPercentConfig.sol/struct.JB721TiersSetDiscountPercentConfig.md)
27
+ - [JBBitmapWord](src/structs/JBBitmapWord.sol/struct.JBBitmapWord.md)
28
+ - [JBDeploy721TiersHookConfig](src/structs/JBDeploy721TiersHookConfig.sol/struct.JBDeploy721TiersHookConfig.md)
29
+ - [JBLaunchProjectConfig](src/structs/JBLaunchProjectConfig.sol/struct.JBLaunchProjectConfig.md)
30
+ - [JBLaunchRulesetsConfig](src/structs/JBLaunchRulesetsConfig.sol/struct.JBLaunchRulesetsConfig.md)
31
+ - [JBPayDataHookRulesetConfig](src/structs/JBPayDataHookRulesetConfig.sol/struct.JBPayDataHookRulesetConfig.md)
32
+ - [JBPayDataHookRulesetMetadata](src/structs/JBPayDataHookRulesetMetadata.sol/struct.JBPayDataHookRulesetMetadata.md)
33
+ - [JBQueueRulesetsConfig](src/structs/JBQueueRulesetsConfig.sol/struct.JBQueueRulesetsConfig.md)
34
+ - [JBStored721Tier](src/structs/JBStored721Tier.sol/struct.JBStored721Tier.md)
35
+ - [JB721TiersHook](src/JB721TiersHook.sol/contract.JB721TiersHook.md)
36
+ - [JB721TiersHookDeployer](src/JB721TiersHookDeployer.sol/contract.JB721TiersHookDeployer.md)
37
+ - [JB721TiersHookProjectDeployer](src/JB721TiersHookProjectDeployer.sol/contract.JB721TiersHookProjectDeployer.md)
38
+ - [JB721TiersHookStore](src/JB721TiersHookStore.sol/contract.JB721TiersHookStore.md)