@bananapus/721-hook-v6 0.0.34 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/JB721TiersHook.sol +6 -4
- package/test/TestCheckpoints.t.sol +16 -4
package/package.json
CHANGED
package/src/JB721TiersHook.sol
CHANGED
|
@@ -110,7 +110,7 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
|
|
|
110
110
|
uint256 internal _packedPricingContext;
|
|
111
111
|
|
|
112
112
|
/// @notice The checkpoint module that manages IVotes-compatible checkpointed voting power for this hook's NFTs.
|
|
113
|
-
/// @dev
|
|
113
|
+
/// @dev Lazily deployed on the first transfer. Pass this to JBTokenDistributor as the IVotes token.
|
|
114
114
|
IJB721Checkpoints public override CHECKPOINTS;
|
|
115
115
|
|
|
116
116
|
//*********************************************************************//
|
|
@@ -307,9 +307,6 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
|
|
|
307
307
|
|| flags.preventOverspending || flags.issueTokensForSplits
|
|
308
308
|
) STORE.recordFlags(flags);
|
|
309
309
|
|
|
310
|
-
// Deploy the checkpoint module for IVotes-compatible voting power.
|
|
311
|
-
CHECKPOINTS = CHECKPOINTS_DEPLOYER.deploy({hook: address(this), store: STORE});
|
|
312
|
-
|
|
313
310
|
// Transfer ownership to the initializer.
|
|
314
311
|
_transferOwnership(_msgSender());
|
|
315
312
|
}
|
|
@@ -794,6 +791,11 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
|
|
|
794
791
|
// slither-disable-next-line reentrency-events,calls-loop
|
|
795
792
|
STORE.recordTransferForTier({tierId: tierId, from: from, to: to});
|
|
796
793
|
|
|
794
|
+
// Deploy the checkpoint module lazily on the first transfer.
|
|
795
|
+
if (address(CHECKPOINTS) == address(0)) {
|
|
796
|
+
CHECKPOINTS = CHECKPOINTS_DEPLOYER.deploy({hook: address(this), store: STORE});
|
|
797
|
+
}
|
|
798
|
+
|
|
797
799
|
// Notify the checkpoint module to update checkpointed voting power.
|
|
798
800
|
CHECKPOINTS.onTransfer({from: from, to: to, tokenId: tokenId});
|
|
799
801
|
}
|
|
@@ -48,17 +48,29 @@ contract TestCheckpoints is UnitTestSetup {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// -------------------------------------------------------------------
|
|
51
|
-
// Test 1: Checkpoint module is deployed
|
|
51
|
+
// Test 1: Checkpoint module is deployed lazily on first transfer
|
|
52
52
|
// -------------------------------------------------------------------
|
|
53
|
-
function
|
|
53
|
+
function test_checkpointModule_isDeployedLazily() public {
|
|
54
54
|
defaultTierConfig.flags.allowOwnerMint = true;
|
|
55
55
|
defaultTierConfig.reserveFrequency = 0;
|
|
56
56
|
|
|
57
57
|
ForTest_JB721TiersHook tiersHook = _initializeHookWithCheckpoints(1);
|
|
58
58
|
|
|
59
|
-
// CHECKPOINTS should be deployed
|
|
59
|
+
// CHECKPOINTS should NOT be deployed after initialization (lazy deployment).
|
|
60
60
|
assertTrue(
|
|
61
|
-
address(tiersHook.CHECKPOINTS())
|
|
61
|
+
address(tiersHook.CHECKPOINTS()) == address(0),
|
|
62
|
+
"Checkpoint module should not be deployed after initialization"
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// Mint a token to trigger lazy deployment.
|
|
66
|
+
uint16[] memory tiersToMint = new uint16[](1);
|
|
67
|
+
tiersToMint[0] = 1;
|
|
68
|
+
vm.prank(owner);
|
|
69
|
+
tiersHook.mintFor(tiersToMint, owner);
|
|
70
|
+
|
|
71
|
+
// CHECKPOINTS should now be deployed after the first mint.
|
|
72
|
+
assertTrue(
|
|
73
|
+
address(tiersHook.CHECKPOINTS()) != address(0), "Checkpoint module should be deployed after first mint"
|
|
62
74
|
);
|
|
63
75
|
}
|
|
64
76
|
|