@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.
- package/.gas-snapshot +152 -0
- package/LICENSE +21 -0
- package/README.md +253 -0
- package/SKILLS.md +140 -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 +253 -0
- package/docs/src/SUMMARY.md +38 -0
- package/docs/src/src/JB721TiersHook.sol/contract.JB721TiersHook.md +645 -0
- package/docs/src/src/JB721TiersHookDeployer.sol/contract.JB721TiersHookDeployer.md +99 -0
- package/docs/src/src/JB721TiersHookProjectDeployer.sol/contract.JB721TiersHookProjectDeployer.md +288 -0
- package/docs/src/src/JB721TiersHookStore.sol/contract.JB721TiersHookStore.md +1096 -0
- package/docs/src/src/README.md +11 -0
- package/docs/src/src/abstract/ERC721.sol/abstract.ERC721.md +430 -0
- package/docs/src/src/abstract/JB721Hook.sol/abstract.JB721Hook.md +309 -0
- package/docs/src/src/abstract/README.md +5 -0
- package/docs/src/src/interfaces/IJB721Hook.sol/interface.IJB721Hook.md +29 -0
- package/docs/src/src/interfaces/IJB721TiersHook.sol/interface.IJB721TiersHook.md +203 -0
- package/docs/src/src/interfaces/IJB721TiersHookDeployer.sol/interface.IJB721TiersHookDeployer.md +25 -0
- package/docs/src/src/interfaces/IJB721TiersHookProjectDeployer.sol/interface.IJB721TiersHookProjectDeployer.md +64 -0
- package/docs/src/src/interfaces/IJB721TiersHookStore.sol/interface.IJB721TiersHookStore.md +265 -0
- package/docs/src/src/interfaces/IJB721TokenUriResolver.sol/interface.IJB721TokenUriResolver.md +12 -0
- package/docs/src/src/interfaces/README.md +9 -0
- package/docs/src/src/libraries/JB721Constants.sol/library.JB721Constants.md +14 -0
- package/docs/src/src/libraries/JB721TiersRulesetMetadataResolver.sol/library.JB721TiersRulesetMetadataResolver.md +68 -0
- package/docs/src/src/libraries/JBBitmap.sol/library.JBBitmap.md +82 -0
- package/docs/src/src/libraries/JBIpfsDecoder.sol/library.JBIpfsDecoder.md +61 -0
- package/docs/src/src/libraries/README.md +7 -0
- package/docs/src/src/structs/JB721InitTiersConfig.sol/struct.JB721InitTiersConfig.md +27 -0
- package/docs/src/src/structs/JB721Tier.sol/struct.JB721Tier.md +59 -0
- package/docs/src/src/structs/JB721TierConfig.sol/struct.JB721TierConfig.md +60 -0
- package/docs/src/src/structs/JB721TiersHookFlags.sol/struct.JB721TiersHookFlags.md +26 -0
- package/docs/src/src/structs/JB721TiersMintReservesConfig.sol/struct.JB721TiersMintReservesConfig.md +16 -0
- package/docs/src/src/structs/JB721TiersRulesetMetadata.sol/struct.JB721TiersRulesetMetadata.md +20 -0
- package/docs/src/src/structs/JB721TiersSetDiscountPercentConfig.sol/struct.JB721TiersSetDiscountPercentConfig.md +16 -0
- package/docs/src/src/structs/JBBitmapWord.sol/struct.JBBitmapWord.md +19 -0
- package/docs/src/src/structs/JBDeploy721TiersHookConfig.sol/struct.JBDeploy721TiersHookConfig.md +34 -0
- package/docs/src/src/structs/JBLaunchProjectConfig.sol/struct.JBLaunchProjectConfig.md +23 -0
- package/docs/src/src/structs/JBLaunchRulesetsConfig.sol/struct.JBLaunchRulesetsConfig.md +22 -0
- package/docs/src/src/structs/JBPayDataHookRulesetConfig.sol/struct.JBPayDataHookRulesetConfig.md +51 -0
- package/docs/src/src/structs/JBPayDataHookRulesetMetadata.sol/struct.JBPayDataHookRulesetMetadata.md +66 -0
- package/docs/src/src/structs/JBQueueRulesetsConfig.sol/struct.JBQueueRulesetsConfig.md +21 -0
- package/docs/src/src/structs/JBStored721Tier.sol/struct.JBStored721Tier.md +42 -0
- package/docs/src/src/structs/README.md +18 -0
- package/foundry.lock +11 -0
- package/foundry.toml +22 -0
- package/package.json +31 -0
- package/remappings.txt +1 -0
- package/script/Deploy.s.sol +140 -0
- package/script/helpers/Hook721DeploymentLib.sol +81 -0
- package/slither-ci.config.json +10 -0
- package/sphinx.lock +476 -0
- package/src/JB721TiersHook.sol +765 -0
- package/src/JB721TiersHookDeployer.sol +114 -0
- package/src/JB721TiersHookProjectDeployer.sol +413 -0
- package/src/JB721TiersHookStore.sol +1195 -0
- package/src/abstract/ERC721.sol +484 -0
- package/src/abstract/JB721Hook.sol +279 -0
- package/src/interfaces/IJB721Hook.sol +21 -0
- package/src/interfaces/IJB721TiersHook.sol +135 -0
- package/src/interfaces/IJB721TiersHookDeployer.sol +22 -0
- package/src/interfaces/IJB721TiersHookProjectDeployer.sol +76 -0
- package/src/interfaces/IJB721TiersHookStore.sol +220 -0
- package/src/interfaces/IJB721TokenUriResolver.sol +10 -0
- package/src/libraries/JB721Constants.sol +7 -0
- package/src/libraries/JB721TiersRulesetMetadataResolver.sol +44 -0
- package/src/libraries/JBBitmap.sol +57 -0
- package/src/libraries/JBIpfsDecoder.sol +95 -0
- package/src/structs/JB721InitTiersConfig.sol +20 -0
- package/src/structs/JB721Tier.sol +39 -0
- package/src/structs/JB721TierConfig.sol +40 -0
- package/src/structs/JB721TiersHookFlags.sol +17 -0
- package/src/structs/JB721TiersMintReservesConfig.sol +9 -0
- package/src/structs/JB721TiersRulesetMetadata.sol +12 -0
- package/src/structs/JB721TiersSetDiscountPercentConfig.sol +9 -0
- package/src/structs/JBBitmapWord.sol +11 -0
- package/src/structs/JBDeploy721TiersHookConfig.sol +25 -0
- package/src/structs/JBLaunchProjectConfig.sol +18 -0
- package/src/structs/JBLaunchRulesetsConfig.sol +17 -0
- package/src/structs/JBPayDataHookRulesetConfig.sol +44 -0
- package/src/structs/JBPayDataHookRulesetMetadata.sol +46 -0
- package/src/structs/JBQueueRulesetsConfig.sol +13 -0
- package/src/structs/JBStored721Tier.sol +24 -0
- package/test/721HookAttacks.t.sol +396 -0
- package/test/E2E/Pay_Mint_Redeem_E2E.t.sol +944 -0
- package/test/invariants/TierLifecycleInvariant.t.sol +187 -0
- package/test/invariants/TieredHookStoreInvariant.t.sol +81 -0
- package/test/invariants/handlers/TierLifecycleHandler.sol +262 -0
- package/test/invariants/handlers/TierStoreHandler.sol +155 -0
- package/test/unit/JB721TiersRulesetMetadataResolver.t.sol +141 -0
- package/test/unit/JBBitmap.t.sol +169 -0
- package/test/unit/JBIpfsDecoder.t.sol +131 -0
- package/test/unit/M6_TierSupplyCheck.t.sol +220 -0
- package/test/unit/adjustTier_Unit.t.sol +1740 -0
- package/test/unit/deployer_Unit.t.sol +103 -0
- package/test/unit/getters_constructor_Unit.t.sol +548 -0
- package/test/unit/mintFor_mintReservesFor_Unit.t.sol +443 -0
- package/test/unit/pay_Unit.t.sol +1537 -0
- package/test/unit/redeem_Unit.t.sol +459 -0
package/.gas-snapshot
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
NFTHookAttacks:test_adjustTiers_noPermission_reverts() (gas: 355534)
|
|
2
|
+
NFTHookAttacks:test_cannotIncreaseDiscountPercent_enforcement() (gas: 371175)
|
|
3
|
+
NFTHookAttacks:test_cashOutWeight_afterTierRemoval() (gas: 9879224)
|
|
4
|
+
NFTHookAttacks:test_duplicateTierIdsInMetadata_mintsMultiple() (gas: 9844592)
|
|
5
|
+
NFTHookAttacks:test_invalidTierIdInMetadata_reverts() (gas: 401784)
|
|
6
|
+
NFTHookAttacks:test_maxDiscountPercent_effectivePrice() (gas: 362841)
|
|
7
|
+
NFTHookAttacks:test_maxSupplyTier_noOverflow() (gas: 357301)
|
|
8
|
+
NFTHookAttacks:test_reserveDrain_highFrequency() (gas: 10193674)
|
|
9
|
+
NFTHookAttacks:test_supplyExhaustion_noOvermint() (gas: 9847419)
|
|
10
|
+
NFTHookAttacks:test_zeroPriceTier_mintBehavior() (gas: 9846210)
|
|
11
|
+
TestJB721TiersRulesetMetadataResolver:testFuzz_mintPendingReservesPaused_bitIsolation(uint256) (runs: 256, μ: 488, ~: 488)
|
|
12
|
+
TestJB721TiersRulesetMetadataResolver:testFuzz_packExpandRoundTrip(bool,bool) (runs: 256, μ: 1090, ~: 1091)
|
|
13
|
+
TestJB721TiersRulesetMetadataResolver:testFuzz_pack_onlyUsesLow2Bits(bool,bool) (runs: 256, μ: 733, ~: 734)
|
|
14
|
+
TestJB721TiersRulesetMetadataResolver:testFuzz_transfersPaused_bitIsolation(uint256) (runs: 256, μ: 459, ~: 459)
|
|
15
|
+
TestJB721TiersRulesetMetadataResolver:test_expandMetadata_one() (gas: 453)
|
|
16
|
+
TestJB721TiersRulesetMetadataResolver:test_expandMetadata_three() (gas: 475)
|
|
17
|
+
TestJB721TiersRulesetMetadataResolver:test_expandMetadata_two() (gas: 485)
|
|
18
|
+
TestJB721TiersRulesetMetadataResolver:test_expandMetadata_zero() (gas: 455)
|
|
19
|
+
TestJB721TiersRulesetMetadataResolver:test_mintPendingReservesPaused() (gas: 457)
|
|
20
|
+
TestJB721TiersRulesetMetadataResolver:test_packExpandRoundTrip_allCombinations() (gas: 2977)
|
|
21
|
+
TestJB721TiersRulesetMetadataResolver:test_pack_allFalse() (gas: 514)
|
|
22
|
+
TestJB721TiersRulesetMetadataResolver:test_pack_bothTrue() (gas: 477)
|
|
23
|
+
TestJB721TiersRulesetMetadataResolver:test_pack_pauseMintPendingReservesOnly() (gas: 505)
|
|
24
|
+
TestJB721TiersRulesetMetadataResolver:test_pack_pauseTransfersOnly() (gas: 486)
|
|
25
|
+
TestJB721TiersRulesetMetadataResolver:test_transfersPaused() (gas: 434)
|
|
26
|
+
TestJBBitmap:testFuzz_readId_depthMatchesIndex(uint16) (runs: 256, μ: 2886, ~: 2886)
|
|
27
|
+
TestJBBitmap:testFuzz_refreshBitmapNeeded_consistency(uint16,uint16) (runs: 256, μ: 3127, ~: 3127)
|
|
28
|
+
TestJBBitmap:testFuzz_removeTier_isolatedBit(uint16,uint16) (runs: 256, μ: 28176, ~: 28755)
|
|
29
|
+
TestJBBitmap:testFuzz_removeTier_multipleBits(uint8,uint8,uint8) (runs: 256, μ: 28174, ~: 28174)
|
|
30
|
+
TestJBBitmap:testFuzz_removeTier_roundTrip(uint16) (runs: 256, μ: 23824, ~: 23824)
|
|
31
|
+
TestJBBitmap:test_isTierIdRemoved_memoryStruct() (gas: 23394)
|
|
32
|
+
TestJBBitmap:test_isTierIdRemoved_wrongDepthReturnsWrong() (gas: 25144)
|
|
33
|
+
TestJBBitmap:test_readId_depthCalculation() (gas: 7636)
|
|
34
|
+
TestJBBitmap:test_readId_initiallyZero() (gas: 2859)
|
|
35
|
+
TestJBBitmap:test_refreshBitmapNeeded_differentDepth() (gas: 2965)
|
|
36
|
+
TestJBBitmap:test_refreshBitmapNeeded_sameDepth() (gas: 3052)
|
|
37
|
+
TestJBBitmap:test_removeTier_acrossWords() (gas: 70159)
|
|
38
|
+
TestJBBitmap:test_removeTier_doesNotAffectOtherBits() (gas: 24281)
|
|
39
|
+
TestJBBitmap:test_removeTier_idempotent() (gas: 23479)
|
|
40
|
+
TestJBBitmap:test_removeTier_multipleBitsInSameWord() (gas: 25337)
|
|
41
|
+
TestJBBitmap:test_removeTier_setsbit() (gas: 23638)
|
|
42
|
+
TestJBIpfsDecoder:testFuzz_decode_alwaysProduces46Chars(bytes32) (runs: 256, μ: 359415, ~: 359415)
|
|
43
|
+
TestJBIpfsDecoder:testFuzz_decode_alwaysStartsWithQm(bytes32) (runs: 256, μ: 359671, ~: 359671)
|
|
44
|
+
TestJBIpfsDecoder:testFuzz_decode_onlyBase58Chars(bytes32) (runs: 256, μ: 647995, ~: 649242)
|
|
45
|
+
TestJBIpfsDecoder:testFuzz_decode_prependsBaseUri(bytes32,uint8) (runs: 256, μ: 369117, ~: 362596)
|
|
46
|
+
TestJBIpfsDecoder:test_decode_deterministic() (gas: 718939)
|
|
47
|
+
TestJBIpfsDecoder:test_decode_differentHashesDifferentOutput() (gas: 718729)
|
|
48
|
+
TestJBIpfsDecoder:test_decode_emptyBaseUri() (gas: 359299)
|
|
49
|
+
TestJBIpfsDecoder:test_decode_onlyBase58Chars() (gas: 626479)
|
|
50
|
+
TestJBIpfsDecoder:test_decode_outputLength() (gas: 359327)
|
|
51
|
+
TestJBIpfsDecoder:test_decode_outputStartsWithQm() (gas: 359626)
|
|
52
|
+
TestJBIpfsDecoder:test_decode_prependsBaseUri() (gas: 361561)
|
|
53
|
+
TestTieredHookStoreInvariant:invariant_maxTierIdMonotonic() (runs: 256, calls: 128000, reverts: 0)
|
|
54
|
+
TestTieredHookStoreInvariant:invariant_reserveMintBounds() (runs: 256, calls: 128000, reverts: 0)
|
|
55
|
+
TestTieredHookStoreInvariant:invariant_supplyConservation() (runs: 256, calls: 128000, reverts: 0)
|
|
56
|
+
Test_Getters_Constructor_Unit:test_balanceOf_returnsCompleteBalance(uint256,address) (runs: 256, μ: 11423292, ~: 11326514)
|
|
57
|
+
Test_Getters_Constructor_Unit:test_bools_doesPackingAndUnpackingWork(bool,bool,bool,bool,bool) (runs: 256, μ: 3439343, ~: 3439343)
|
|
58
|
+
Test_Getters_Constructor_Unit:test_cashOutWeightOf_returnsCorrectWeightAsCumSumOfPrices(uint256,uint256,uint256) (runs: 256, μ: 11195261, ~: 10992258)
|
|
59
|
+
Test_Getters_Constructor_Unit:test_constructor_deployIfInitialSuppliesNotEmpty(uint256) (runs: 256, μ: 10167481, ~: 10200751)
|
|
60
|
+
Test_Getters_Constructor_Unit:test_constructor_revertDeploymentIfOneEmptyInitialSupply(uint256,uint256) (runs: 256, μ: 487693, ~: 400030)
|
|
61
|
+
Test_Getters_Constructor_Unit:test_firstOwnerOf_shouldReturnCurrentOwnerIfFirstOwner(uint256,address) (runs: 256, μ: 10587416, ~: 10587416)
|
|
62
|
+
Test_Getters_Constructor_Unit:test_firstOwnerOf_shouldReturnFirstOwnerIfOwnerChanged(address,address) (runs: 256, μ: 10485438, ~: 10485438)
|
|
63
|
+
Test_Getters_Constructor_Unit:test_firstOwnerOf_shouldReturnZeroAddressIfNotMinted(uint256) (runs: 256, μ: 10566284, ~: 10566284)
|
|
64
|
+
Test_Getters_Constructor_Unit:test_numberOfPendingReservesFor_returnsPendingReserves() (gas: 10915529)
|
|
65
|
+
Test_Getters_Constructor_Unit:test_pricingContext_packingFunctionsAsExpected(uint32,uint8,address,bytes32) (runs: 256, μ: 991314, ~: 991314)
|
|
66
|
+
Test_Getters_Constructor_Unit:test_setEncodedIPFSUriOf_returnsCorrectEncodedURI() (gas: 10971375)
|
|
67
|
+
Test_Getters_Constructor_Unit:test_tierOfTokenId_returnsCorrectTierNumber(uint16,uint16) (runs: 256, μ: 29544, ~: 29544)
|
|
68
|
+
Test_Getters_Constructor_Unit:test_tierOf_returnsAGivenTier(uint256,uint16) (runs: 256, μ: 11097249, ~: 11056900)
|
|
69
|
+
Test_Getters_Constructor_Unit:test_tiersOf_returnsAllTiers(uint256) (runs: 256, μ: 11333900, ~: 11133203)
|
|
70
|
+
Test_Getters_Constructor_Unit:test_tiersOf_returnsAllTiersExcludingRemovedOnes(uint256,uint256,uint256) (runs: 256, μ: 11587343, ~: 11564906)
|
|
71
|
+
Test_Getters_Constructor_Unit:test_tiersOf_returnsAllTiersWithResolver(uint256) (runs: 256, μ: 11605638, ~: 11393755)
|
|
72
|
+
Test_Getters_Constructor_Unit:test_tokenURI_returnsCorrectUriWithResolver(uint256) (runs: 256, μ: 10641767, ~: 10641767)
|
|
73
|
+
Test_Getters_Constructor_Unit:test_tokenURI_returnsCorrectUriWithoutResolver() (gas: 14291263)
|
|
74
|
+
Test_Getters_Constructor_Unit:test_totalCashOutWeight_returnsCorrectTotalWeightAsCumSumOfPrices(uint256) (runs: 256, μ: 11051332, ~: 10917296)
|
|
75
|
+
Test_Getters_Constructor_Unit:test_totalSupplyOf_returnsTotalSupply(uint256) (runs: 256, μ: 11036700, ~: 10904015)
|
|
76
|
+
Test_Getters_Constructor_Unit:test_votingUnitsOf_returnsVotingUnitsCorrectly(uint256,uint256,uint256) (runs: 256, μ: 11413665, ~: 11289995)
|
|
77
|
+
Test_ProjectDeployer_Unit:test_launchProjectFor_shouldLaunchProject(uint256,bytes32) (runs: 256, μ: 1007027, ~: 1006740)
|
|
78
|
+
Test_TiersHook_E2E:testCashOutAll(bytes32) (runs: 256, μ: 2638007, ~: 2638007)
|
|
79
|
+
Test_TiersHook_E2E:testCashOutToken(uint256,bytes32) (runs: 256, μ: 2384922, ~: 2389496)
|
|
80
|
+
Test_TiersHook_E2E:testFuzzMintWithDiscountOnPayIfOneTierIsPassed(uint256,uint256) (runs: 257, μ: 1265656, ~: 1308144)
|
|
81
|
+
Test_TiersHook_E2E:testLaunchProjectAndAddHookToRegistry(bytes32) (runs: 256, μ: 4570480, ~: 4570480)
|
|
82
|
+
Test_TiersHook_E2E:testMintOnPayIfMultipleTiersArePassed(bytes32) (runs: 256, μ: 2444650, ~: 2444650)
|
|
83
|
+
Test_TiersHook_E2E:testMintOnPayIfOneTierIsPassed(uint256,bytes32) (runs: 256, μ: 2049940, ~: 2050860)
|
|
84
|
+
Test_TiersHook_E2E:testMintReservedNft(uint256,bytes32) (runs: 256, μ: 2140927, ~: 2141363)
|
|
85
|
+
Test_TiersHook_E2E:testNoMintOnPayWhenNotIncludingMetadata(uint256,bytes32) (runs: 256, μ: 1868459, ~: 1868581)
|
|
86
|
+
Test_TiersHook_E2E:testNoMintOnPayWhenNotIncludingTierIds(uint256,bytes32) (runs: 256, μ: 1874747, ~: 1874869)
|
|
87
|
+
Test_adjustTier_Unit:test_adjustTiers_addAndRemoveTiers() (gas: 1343154)
|
|
88
|
+
Test_adjustTier_Unit:test_adjustTiers_addNewTiers(uint256,uint256,uint256) (runs: 256, μ: 2340387, ~: 2352813)
|
|
89
|
+
Test_adjustTier_Unit:test_adjustTiers_addNewTiersWithNonSequentialCategories(uint256,uint256,uint256) (runs: 256, μ: 2581968, ~: 2563953)
|
|
90
|
+
Test_adjustTier_Unit:test_adjustTiers_addNewTiers_fetchSpecificTier(uint256,uint256,uint256) (runs: 256, μ: 1660417, ~: 1683246)
|
|
91
|
+
Test_adjustTier_Unit:test_adjustTiers_removeTiers(uint256,uint256,uint256) (runs: 256, μ: 10170249, ~: 10150499)
|
|
92
|
+
Test_adjustTier_Unit:test_adjustTiers_removeTiersMultipleTimes(uint256,uint256,uint256) (runs: 256, μ: 2285592, ~: 2265940)
|
|
93
|
+
Test_adjustTier_Unit:test_adjustTiers_revertIfAddingWithReserveFrequency(uint256,uint256) (runs: 256, μ: 10169685, ~: 10166640)
|
|
94
|
+
Test_adjustTier_Unit:test_adjustTiers_revertIfAddingWithVotingPower(uint256,uint256) (runs: 256, μ: 10168360, ~: 10165321)
|
|
95
|
+
Test_adjustTier_Unit:test_adjustTiers_revertIfCannotRemoveTier() (gas: 394356)
|
|
96
|
+
Test_adjustTier_Unit:test_adjustTiers_revertIfEmptyQuantity(uint256,uint256) (runs: 256, μ: 10169424, ~: 10166381)
|
|
97
|
+
Test_adjustTier_Unit:test_adjustTiers_revertIfInvalidCategorySortOrder(uint256,uint256) (runs: 256, μ: 10897255, ~: 10925524)
|
|
98
|
+
Test_adjustTier_Unit:test_adjustTiers_revertIfMoreVotingUnitsNotAllowedUsingVotingUnits(uint256,uint256) (runs: 256, μ: 10778370, ~: 10808162)
|
|
99
|
+
Test_adjustTier_Unit:test_adjustTiers_revertIfMoreVotingUnitsNotAllowedWithPriceChange(uint256,uint256) (runs: 256, μ: 10141122, ~: 10138435)
|
|
100
|
+
Test_adjustTier_Unit:test_adjustTiers_withDifferentCategories(uint256,uint256,uint256) (runs: 256, μ: 2609853, ~: 2601407)
|
|
101
|
+
Test_adjustTier_Unit:test_adjustTiers_withDifferentCategoriesAndFetchedTogether(uint256,uint256,uint256) (runs: 256, μ: 2651662, ~: 2655539)
|
|
102
|
+
Test_adjustTier_Unit:test_adjustTiers_withSameCategoryMultipleTimes(uint256,uint256,uint256) (runs: 256, μ: 3211356, ~: 3174714)
|
|
103
|
+
Test_adjustTier_Unit:test_adjustTiers_withZeroCategory(uint256,uint256,uint256) (runs: 256, μ: 2019794, ~: 1998614)
|
|
104
|
+
Test_adjustTier_Unit:test_cleanTiers_removeInactiveTiers(uint256,uint256,uint256) (runs: 256, μ: 10396186, ~: 10378896)
|
|
105
|
+
Test_adjustTier_Unit:test_setDiscountPercentOf_revertIfCannotIncreaseDiscount() (gas: 338824)
|
|
106
|
+
Test_adjustTier_Unit:test_setDiscountPercentsOf_revertIfCannotIncreaseDiscounts() (gas: 395153)
|
|
107
|
+
Test_adjustTier_Unit:test_tiersOf_emptyArrayIfNoInitializedTiers(uint256) (runs: 256, μ: 217659, ~: 217659)
|
|
108
|
+
Test_adjustTier_Unit:test_tiersOf_recentlyAddedTiersFetchedFirstWhenSorted(uint256,uint256,uint256) (runs: 256, μ: 2200972, ~: 2196814)
|
|
109
|
+
Test_adjustTier_Unit:test_tiersOf_recentlyAddedTiersFetchedFirstWhenSortedAfterTiersCleaned(uint256,uint256,uint256) (runs: 256, μ: 3616874, ~: 3631859)
|
|
110
|
+
Test_afterPayRecorded_Unit:test_afterCashOutRecordedWith_cashOutEvenIfTransfersPausedInRuleset() (gas: 1385297)
|
|
111
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_doNotMintIfNotUsingCorrectToken(address) (runs: 257, μ: 85884, ~: 85884)
|
|
112
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_doNotMintWithSomeoneElsesCredits() (gas: 514975)
|
|
113
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_doesNotRevertOnAmountBelowPriceIfNoMetadata() (gas: 65557)
|
|
114
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_mintAndReserveCorrectAmounts(uint256,uint256,uint256) (runs: 256, μ: 14417219, ~: 14622413)
|
|
115
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_mintCorrectTier() (gas: 344650)
|
|
116
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_mintCorrectTierWithAnotherCurrency() (gas: 1574686)
|
|
117
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_mintCorrectTiersWhenPartiallyUsingPayCredits() (gas: 553961)
|
|
118
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_mintNoneIfNonePassed(uint8) (runs: 256, μ: 126870, ~: 130887)
|
|
119
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_mintTierAndTrackLeftover() (gas: 190328)
|
|
120
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_mintWithExistingCreditsWhenMoreExistingCreditsThanNewCredits() (gas: 439389)
|
|
121
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_revertIfAllowanceRunsOutInSpecifiedTier() (gas: 9359196)
|
|
122
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_revertIfAmountTooLow() (gas: 150759)
|
|
123
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_revertIfCallerIsNotATerminalOfProjectId(address) (runs: 256, μ: 25585, ~: 25585)
|
|
124
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_revertIfTierDoesNotExist(uint256) (runs: 256, μ: 177275, ~: 177754)
|
|
125
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_revertIfTierRemoved() (gas: 170846)
|
|
126
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_revertIfUnexpectedLeftover() (gas: 64790)
|
|
127
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_revertIfUnexpectedLeftoverAndOverspendingPrevented(bool) (runs: 256, μ: 65853, ~: 53252)
|
|
128
|
+
Test_afterPayRecorded_Unit:test_afterPayRecorded_revertsOnAmountBelowPriceIfNoMetadataAndOverspendingIsPrevented() (gas: 1325309)
|
|
129
|
+
Test_afterPayRecorded_Unit:test_transferFrom_pauseFlagOverridesRuleset() (gas: 1603935)
|
|
130
|
+
Test_afterPayRecorded_Unit:test_transferFrom_revertTransferIfPausedInRuleset() (gas: 1568089)
|
|
131
|
+
Test_cashOut_Unit:test_afterCashOutRecordedWith_burnCashOutNft(uint256) (runs: 256, μ: 13781545, ~: 13639188)
|
|
132
|
+
Test_cashOut_Unit:test_afterCashOutRecordedWith_revertIfCallerIsNotATerminalOfTheProject() (gas: 27783)
|
|
133
|
+
Test_cashOut_Unit:test_afterCashOutRecordedWith_revertIfNotCorrectProjectId(uint8) (runs: 256, μ: 28421, ~: 28421)
|
|
134
|
+
Test_cashOut_Unit:test_afterCashOutRecordedWith_revertIfWrongHolder(address,uint8) (runs: 256, μ: 9677720, ~: 9677720)
|
|
135
|
+
Test_cashOut_Unit:test_beforeCashOutContext_returnsCorrectAmount() (gas: 10828929)
|
|
136
|
+
Test_cashOut_Unit:test_beforeCashOutContext_returnsPartOfOverflowOwnedIfCashOutTaxRateIsMaximum() (gas: 10830525)
|
|
137
|
+
Test_cashOut_Unit:test_beforeCashOutContext_returnsZeroAmountIfReserveFrequencyIsZero() (gas: 10812126)
|
|
138
|
+
Test_cashOut_Unit:test_beforeCashOutContext_revertIfNonZeroTokenCount(uint256) (runs: 256, μ: 19456, ~: 19456)
|
|
139
|
+
Test_mintFor_mintReservesFor_Unit:test_mintFor_mintArrayOfTiers() (gas: 10129100)
|
|
140
|
+
Test_mintFor_mintReservesFor_Unit:test_mintFor_revertIfManualMintNotAllowed() (gas: 10585321)
|
|
141
|
+
Test_mintFor_mintReservesFor_Unit:test_mintPendingReservesFor_mintMultipleReservedTokens() (gas: 9977856)
|
|
142
|
+
Test_mintFor_mintReservesFor_Unit:test_mintPendingReservesFor_mintOddReservedTokens() (gas: 10344857)
|
|
143
|
+
Test_mintFor_mintReservesFor_Unit:test_mintPendingReservesFor_mintsCorrectly() (gas: 9984341)
|
|
144
|
+
Test_mintFor_mintReservesFor_Unit:test_mintPendingReservesFor_revertIfNotEnoughPendingReserves() (gas: 11010767)
|
|
145
|
+
Test_mintFor_mintReservesFor_Unit:test_mintPendingReservesFor_revertIfReservedMintingIsPausedInRuleset() (gas: 9954862)
|
|
146
|
+
Test_mintFor_mintReservesFor_Unit:test_numberOfPendingReservesFor_noReservesIfNoBeneficiarySet() (gas: 10812175)
|
|
147
|
+
TierLifecycleInvariant_Local:invariant_721_1_perTierSupplyAccounting() (runs: 256, calls: 128000, reverts: 0)
|
|
148
|
+
TierLifecycleInvariant_Local:invariant_721_2_totalCashOutWeightConsistency() (runs: 256, calls: 128000, reverts: 0)
|
|
149
|
+
TierLifecycleInvariant_Local:invariant_721_3_payCreditsNonNegative() (runs: 256, calls: 128000, reverts: 0)
|
|
150
|
+
TierLifecycleInvariant_Local:invariant_721_4_reserveMintsBounded() (runs: 256, calls: 128000, reverts: 0)
|
|
151
|
+
TierLifecycleInvariant_Local:invariant_721_5_removedTiersExcluded() (runs: 256, calls: 128000, reverts: 0)
|
|
152
|
+
TierLifecycleInvariant_Local:invariant_721_6_cashOutWeightBoundedByPrice() (runs: 256, calls: 128000, reverts: 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,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.
|
package/SKILLS.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# nana-721-hook-v5
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Tiered ERC-721 NFT hook for Juicebox V6 that mints NFTs when a project is paid and optionally allows NFT holders to burn them to reclaim project funds proportional to tier price.
|
|
6
|
+
|
|
7
|
+
## Contracts
|
|
8
|
+
|
|
9
|
+
| Contract | Role |
|
|
10
|
+
|----------|------|
|
|
11
|
+
| `JB721TiersHook` | Core hook: processes payments (mints NFTs), processes cash outs (burns NFTs), manages tiers, reserves, credits, metadata, and discount percents. Deployed as minimal clones. |
|
|
12
|
+
| `JB721TiersHookStore` | Shared singleton storage for all hook instances. Stores tiers (`JBStored721Tier`), balances, reserves, bitmaps for removed tiers, flags, and token URI resolvers. |
|
|
13
|
+
| `JB721TiersHookDeployer` | Factory: clones `JB721TiersHook` via `LibClone.clone` / `cloneDeterministic`, initializes, registers in address registry. |
|
|
14
|
+
| `JB721TiersHookProjectDeployer` | Convenience deployer: creates a Juicebox project + hook in one transaction. Wires the hook as the data hook with `useDataHookForPay: true`. |
|
|
15
|
+
| `JB721Hook` (abstract) | Base: implements `IJBRulesetDataHook` + `IJBPayHook` + `IJBCashOutHook`. Validates caller is a project terminal. |
|
|
16
|
+
| `ERC721` (abstract) | Clone-compatible ERC-721 with `_initialize(name, symbol)` instead of constructor args. |
|
|
17
|
+
|
|
18
|
+
## Key Functions
|
|
19
|
+
|
|
20
|
+
| Function | Contract | What it does |
|
|
21
|
+
|----------|----------|--------------|
|
|
22
|
+
| `initialize(projectId, name, symbol, baseUri, tokenUriResolver, contractUri, tiersConfig, flags)` | `JB721TiersHook` | One-time setup for a cloned hook instance. Stores pricing context (currency, decimals, prices contract packed into uint256), records tiers and flags in the store. |
|
|
23
|
+
| `afterPayRecordedWith(context)` | `JB721Hook` | Called by terminal after payment. Validates caller is a project terminal, delegates to `_processPayment`. |
|
|
24
|
+
| `_processPayment(context)` | `JB721TiersHook` | Normalizes payment value via pricing context, decodes payer metadata for tier IDs to mint, calls `_mintAll`, manages pay credits for overspending. |
|
|
25
|
+
| `afterCashOutRecordedWith(context)` | `JB721Hook` | Called by terminal during cash out. Decodes token IDs from metadata, validates ownership, burns NFTs, calls `_didBurn`. |
|
|
26
|
+
| `beforePayRecordedWith(context)` | `JB721Hook` | Data hook: returns original weight and sets this contract as the pay hook (amount=0). |
|
|
27
|
+
| `beforeCashOutRecordedWith(context)` | `JB721Hook` | Data hook: calculates `cashOutCount` (weight of NFTs being cashed out) and `totalSupply` (total weight of all NFTs). Rejects if fungible tokens are also being cashed out. |
|
|
28
|
+
| `adjustTiers(tiersToAdd, tierIdsToRemove)` | `JB721TiersHook` | Owner-only. Adds/removes tiers via the store. Requires `ADJUST_721_TIERS` permission. |
|
|
29
|
+
| `mintFor(tierIds, beneficiary)` | `JB721TiersHook` | Owner-only manual mint. Requires `MINT_721` permission. Passes `amount: type(uint256).max` and `isOwnerMint: true` to force the mint. |
|
|
30
|
+
| `mintPendingReservesFor(tierId, count)` | `JB721TiersHook` | Public. Mints pending reserve NFTs for a tier to the tier's `reserveBeneficiary`. Checks ruleset metadata for `mintPendingReservesPaused`. |
|
|
31
|
+
| `setMetadata(baseUri, contractUri, tokenUriResolver, encodedIPFSTUriTierId, encodedIPFSUri)` | `JB721TiersHook` | Owner-only. Updates base URI, contract URI, token URI resolver, or per-tier encoded IPFS URI. Requires `SET_721_METADATA` permission. |
|
|
32
|
+
| `setDiscountPercentOf(tierId, discountPercent)` | `JB721TiersHook` | Owner-only. Sets discount percent for a tier. Requires `SET_721_DISCOUNT_PERCENT` permission. |
|
|
33
|
+
| `deployHookFor(projectId, config, salt)` | `JB721TiersHookDeployer` | Clones the hook implementation, initializes it, transfers ownership to caller, registers in address registry. |
|
|
34
|
+
| `launchProjectFor(owner, deployConfig, launchConfig, controller, salt)` | `JB721TiersHookProjectDeployer` | Creates project via controller, deploys hook, wires hook as data hook with `useDataHookForPay: true`, transfers hook ownership to project. |
|
|
35
|
+
| `recordMint(amount, tierIds, isOwnerMint)` | `JB721TiersHookStore` | Records minting: validates supply, checks tier prices against amount (unless owner mint), generates token IDs (tierId * 1_000_000_000 + mintCount), tracks reserves. |
|
|
36
|
+
| `recordAddTiers(tiers)` | `JB721TiersHookStore` | Adds new tiers sorted by category. Validates against hook flags (no new reserves/votes/owner-minting if flagged). |
|
|
37
|
+
| `recordRemoveTierIds(tierIds)` | `JB721TiersHookStore` | Marks tiers as removed in the bitmap. Validates tier is not locked (`cannotBeRemoved`). |
|
|
38
|
+
|
|
39
|
+
## Integration Points
|
|
40
|
+
|
|
41
|
+
| Dependency | Import | Used For |
|
|
42
|
+
|------------|--------|----------|
|
|
43
|
+
| `@bananapus/core-v6` | `IJBDirectory`, `IJBRulesets`, `IJBPrices`, `IJBController`, `IJBTerminal`, `JBRuleset`, `JBRulesetMetadata`, `JBAfterPayRecordedContext`, `JBBeforeCashOutRecordedContext`, etc. | Terminal validation, ruleset metadata, pricing, payment/cash-out contexts |
|
|
44
|
+
| `@bananapus/ownable-v6` | `JBOwnable` | Project-based ownership for the hook (ownership can be transferred to a project NFT) |
|
|
45
|
+
| `@bananapus/permission-ids-v6` | `JBPermissionIds` | Permission IDs: `ADJUST_721_TIERS`, `MINT_721`, `SET_721_METADATA`, `SET_721_DISCOUNT_PERCENT`, `QUEUE_RULESETS`, `SET_TERMINALS` |
|
|
46
|
+
| `@bananapus/address-registry-v6` | `IJBAddressRegistry` | Registering deployed hook clones |
|
|
47
|
+
| `@openzeppelin/contracts` | `ERC2771Context`, `IERC165`, `IERC2981`, `IERC721` | Meta-transactions (trusted forwarder), interface detection, royalty standard |
|
|
48
|
+
| `@prb/math` | `mulDiv` | Safe fixed-point multiplication/division for price normalization |
|
|
49
|
+
| `solady` | `LibClone` | Minimal proxy (clone) deployment for hooks |
|
|
50
|
+
|
|
51
|
+
## Key Types
|
|
52
|
+
|
|
53
|
+
| Struct/Enum | Key Fields | Used In |
|
|
54
|
+
|-------------|------------|---------|
|
|
55
|
+
| `JB721TierConfig` | `uint104 price`, `uint32 initialSupply`, `uint32 votingUnits`, `uint16 reserveFrequency`, `address reserveBeneficiary`, `bytes32 encodedIPFSUri`, `uint24 category`, `uint8 discountPercent`, `bool allowOwnerMint`, `bool transfersPausable`, `bool cannotBeRemoved`, `bool cannotIncreaseDiscountPercent` | `adjustTiers`, `initialize`, `recordAddTiers` |
|
|
56
|
+
| `JB721Tier` | Same as config plus `uint32 id`, `uint32 remainingSupply`, `string resolvedUri` | Return type from `tierOf`, `tiersOf`, `tierOfTokenId` |
|
|
57
|
+
| `JBStored721Tier` | `uint104 price`, `uint32 remainingSupply`, `uint32 initialSupply`, `uint32 votingUnits`, `uint24 category`, `uint8 discountPercent`, `uint16 reserveFrequency`, `uint8 packedBools` | Internal storage in `JB721TiersHookStore` |
|
|
58
|
+
| `JB721InitTiersConfig` | `JB721TierConfig[] tiers`, `uint32 currency`, `uint8 decimals`, `IJBPrices prices` | `initialize` — defines tiers and pricing context |
|
|
59
|
+
| `JBDeploy721TiersHookConfig` | `string name`, `string symbol`, `string baseUri`, `IJB721TokenUriResolver tokenUriResolver`, `string contractUri`, `JB721InitTiersConfig tiersConfig`, `address reserveBeneficiary`, `JB721TiersHookFlags flags` | `deployHookFor`, `launchProjectFor` |
|
|
60
|
+
| `JB721TiersHookFlags` | `bool noNewTiersWithReserves`, `bool noNewTiersWithVotes`, `bool noNewTiersWithOwnerMinting`, `bool preventOverspending` | `initialize`, `recordFlags` |
|
|
61
|
+
| `JB721TiersRulesetMetadata` | `bool pauseTransfers`, `bool pauseMintPendingReserves` | Packed into `JBRulesetMetadata.metadata` per-ruleset |
|
|
62
|
+
| `JBPayDataHookRulesetConfig` | `uint48 mustStartAtOrAfter`, `uint32 duration`, `uint112 weight`, `uint32 weightCutPercent`, `IJBRulesetApprovalHook approvalHook`, `JBPayDataHookRulesetMetadata metadata`, `JBSplitGroup[] splitGroups`, `JBFundAccessLimitGroup[] fundAccessLimitGroups` | `JB721TiersHookProjectDeployer` — wraps core ruleset config with `useDataHookForPay: true` hardcoded |
|
|
63
|
+
| `JBPayDataHookRulesetMetadata` | Same as `JBRulesetMetadata` minus `allowSetCustomToken` (hardcoded false) and `useDataHookForPay` (hardcoded true) and `dataHook` (set to deployed hook) | `launchProjectFor`, `launchRulesetsFor`, `queueRulesetsOf` |
|
|
64
|
+
| `JB721TiersMintReservesConfig` | `uint32 tierId`, `uint16 count` | `mintPendingReservesFor` batch variant |
|
|
65
|
+
| `JB721TiersSetDiscountPercentConfig` | `uint32 tierId`, `uint16 discountPercent` | `setDiscountPercentsOf` batch variant |
|
|
66
|
+
| `JBBitmapWord` | `uint256 currentWord`, `uint256 currentDepth` | Internal tier removal tracking in store |
|
|
67
|
+
|
|
68
|
+
## Gotchas
|
|
69
|
+
|
|
70
|
+
- `JB721TiersHook` is deployed as a **minimal clone** (not a full deployment). The constructor sets immutables (`RULESETS`, `STORE`, `DIRECTORY`, `METADATA_ID_TARGET`), and `initialize()` sets per-instance state. Calling `initialize()` twice reverts with `JB721TiersHook_AlreadyInitialized`.
|
|
71
|
+
- **Pricing context is bit-packed** into a single `uint256`: currency (bits 0-31), decimals (bits 32-39), prices contract address (bits 40-199). Read it via `pricingContext()`.
|
|
72
|
+
- **Token IDs encode tier ID**: `tokenId = tierId * 1_000_000_000 + mintNumber`. Use `STORE.tierIdOfToken(tokenId)` to extract the tier ID.
|
|
73
|
+
- **Pay credits**: If a payer overpays (amount > total tier prices), the excess is stored as `payCreditsOf[beneficiary]` and can be applied to future mints. This only works when `preventOverspending` flag is `false`. Credits are only combined with payment when `payer == beneficiary`.
|
|
74
|
+
- **Cash outs reject fungible tokens**: `beforeCashOutRecordedWith` reverts with `JB721Hook_UnexpectedTokenCashedOut` if `context.cashOutCount > 0`. NFT cash outs and fungible token cash outs are mutually exclusive.
|
|
75
|
+
- **Reserve minting is permissionless** but governed by ruleset metadata. Anyone can call `mintPendingReservesFor` as long as `mintPendingReservesPaused` is not set in the current ruleset's metadata.
|
|
76
|
+
- `setMetadata` uses `address(this)` as the sentinel for "no change" on `tokenUriResolver` (not `address(0)`). Passing `address(0)` will clear the resolver.
|
|
77
|
+
- `JBPayDataHookRulesetConfig` hardcodes `allowSetCustomToken: false` and `useDataHookForPay: true` when wiring rulesets through the project deployer.
|
|
78
|
+
- The `_update` override in `JB721TiersHook` checks `tier.transfersPausable` and consults the current ruleset's metadata for `transfersPaused`. Transfers to `address(0)` (burns) are never blocked.
|
|
79
|
+
- `JB721TiersHookStore` is a **shared singleton** -- all hook instances on the same chain use the same store, keyed by `address(hook)`.
|
|
80
|
+
- The `ERC721` abstract uses `_initialize(name, symbol)` instead of a constructor, making it clone-compatible. The standard `_owners` mapping is `internal` (not `private`).
|
|
81
|
+
|
|
82
|
+
## Example Integration
|
|
83
|
+
|
|
84
|
+
```solidity
|
|
85
|
+
import {IJB721TiersHookProjectDeployer} from "@bananapus/721-hook-v6/src/interfaces/IJB721TiersHookProjectDeployer.sol";
|
|
86
|
+
import {JBDeploy721TiersHookConfig} from "@bananapus/721-hook-v6/src/structs/JBDeploy721TiersHookConfig.sol";
|
|
87
|
+
import {JB721TierConfig} from "@bananapus/721-hook-v6/src/structs/JB721TierConfig.sol";
|
|
88
|
+
import {JB721InitTiersConfig} from "@bananapus/721-hook-v6/src/structs/JB721InitTiersConfig.sol";
|
|
89
|
+
import {JB721TiersHookFlags} from "@bananapus/721-hook-v6/src/structs/JB721TiersHookFlags.sol";
|
|
90
|
+
import {JBLaunchProjectConfig} from "@bananapus/721-hook-v6/src/structs/JBLaunchProjectConfig.sol";
|
|
91
|
+
import {JBPayDataHookRulesetConfig} from "@bananapus/721-hook-v6/src/structs/JBPayDataHookRulesetConfig.sol";
|
|
92
|
+
import {IJBController} from "@bananapus/core-v6/src/interfaces/IJBController.sol";
|
|
93
|
+
|
|
94
|
+
// Build a single tier: 0.1 ETH, supply of 100, with IPFS artwork.
|
|
95
|
+
JB721TierConfig[] memory tiers = new JB721TierConfig[](1);
|
|
96
|
+
tiers[0] = JB721TierConfig({
|
|
97
|
+
price: 0.1 ether,
|
|
98
|
+
initialSupply: 100,
|
|
99
|
+
votingUnits: 0,
|
|
100
|
+
reserveFrequency: 0,
|
|
101
|
+
reserveBeneficiary: address(0),
|
|
102
|
+
encodedIPFSUri: 0x7D5A99F603F231D53A4F39D1521F98D2E8BB279CF29BEBFD0687DC98458E7F89, // example CID
|
|
103
|
+
category: 1,
|
|
104
|
+
discountPercent: 0,
|
|
105
|
+
allowOwnerMint: false,
|
|
106
|
+
useReserveBeneficiaryAsDefault: false,
|
|
107
|
+
transfersPausable: false,
|
|
108
|
+
useVotingUnits: false,
|
|
109
|
+
cannotBeRemoved: false,
|
|
110
|
+
cannotIncreaseDiscountPercent: false
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Deploy a project with the 721 hook attached.
|
|
114
|
+
(uint256 projectId, IJB721TiersHook hook) = projectDeployer.launchProjectFor({
|
|
115
|
+
owner: msg.sender,
|
|
116
|
+
deployTiersHookConfig: JBDeploy721TiersHookConfig({
|
|
117
|
+
name: "My NFT Collection",
|
|
118
|
+
symbol: "MNFT",
|
|
119
|
+
baseUri: "ipfs://",
|
|
120
|
+
tokenUriResolver: IJB721TokenUriResolver(address(0)),
|
|
121
|
+
contractUri: "",
|
|
122
|
+
tiersConfig: JB721InitTiersConfig({
|
|
123
|
+
tiers: tiers,
|
|
124
|
+
currency: 1, // ETH
|
|
125
|
+
decimals: 18,
|
|
126
|
+
prices: IJBPrices(address(0)) // no cross-currency pricing
|
|
127
|
+
}),
|
|
128
|
+
reserveBeneficiary: address(0),
|
|
129
|
+
flags: JB721TiersHookFlags({
|
|
130
|
+
noNewTiersWithReserves: false,
|
|
131
|
+
noNewTiersWithVotes: false,
|
|
132
|
+
noNewTiersWithOwnerMinting: false,
|
|
133
|
+
preventOverspending: false
|
|
134
|
+
})
|
|
135
|
+
}),
|
|
136
|
+
launchProjectConfig: launchConfig, // JBLaunchProjectConfig with rulesets, terminals, etc.
|
|
137
|
+
controller: IJBController(controllerAddress),
|
|
138
|
+
salt: bytes32(0)
|
|
139
|
+
});
|
|
140
|
+
```
|
package/docs/book.css
ADDED
package/docs/book.toml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[book]
|
|
2
|
+
src = "src"
|
|
3
|
+
title = ""
|
|
4
|
+
|
|
5
|
+
[output.html]
|
|
6
|
+
no-section-label = true
|
|
7
|
+
additional-js = ["solidity.min.js"]
|
|
8
|
+
additional-css = ["book.css"]
|
|
9
|
+
git-repository-url = "https://github.com/Bananapus/nana-721-hook-v6"
|
|
10
|
+
|
|
11
|
+
[output.html.fold]
|
|
12
|
+
enable = true
|