@@ -39,15 +39,6 @@ contract NftChanceBoosterHook is IPrizeHooks {
39
39
/// @param pickAttempts The number of times the hook tried to pick a winner
40
40
event BoostedVaultWithPrize (address indexed prizePool , address indexed boostedVault , uint256 prizeAmount , uint256 pickAttempts );
41
41
42
- /// @notice Emitted when an NFT holder wins a prize.
43
- /// @param nftWinner The NFT holder that won the prize
44
- /// @param vault The vault that the prize was won through
45
- /// @param donor The original winner of the prize before it was redirected
46
- /// @param tier The prize tier
47
- /// @param prizeIndex The prize index
48
- /// @param prizeAmount The amount of prize tokens won
49
- event PrizeWonByNftHolder (address indexed nftWinner , address indexed vault , address indexed donor , uint8 tier , uint32 prizeIndex , uint256 prizeAmount );
50
-
51
42
/// @notice The ERC721 token whose holders will have a chance to win prizes
52
43
IERC721 public immutable nftCollection;
53
44
@@ -72,9 +63,9 @@ contract NftChanceBoosterHook is IPrizeHooks {
72
63
/// @notice Constructor to deploy the hook contract
73
64
/// @param nftCollection_ The ERC721 token whose holders will have a chance to win prizes
74
65
/// @param prizePool_ The prize pool that is awarding prizes
75
- /// @param boostedVault_ The The vault that is being boosted
76
- /// @param minTwabOverPrizePeriod_ The minimum TWAB that the selected winner must have over the prize
77
- /// period to win the prize; if set to zero, no balance is needed.
66
+ /// @param boostedVault_ The The vault that is boosted if a winner cannot be determined
67
+ /// @param minTwabOverPrizePeriod_ The minimum TWAB on the `boostedVault_` that the selected winner
68
+ /// must have over the prize period to win the prize; if set to zero, no balance is needed.
78
69
/// @param tokenIdLowerBound_ The lower bound of eligible NFT IDs (inclusive)
79
70
/// @param tokenIdUpperBound_ The upper bound of eligible NFT IDs (inclusive)
80
71
constructor (
@@ -105,7 +96,7 @@ contract NftChanceBoosterHook is IPrizeHooks {
105
96
/// variance in the entropy for each prize so there can be multiple winners per draw.
106
97
/// @dev Tries to select a winner until the call runs out of gas before reverting to the backup action of
107
98
/// contributing the prize on behalf of the boosted vault.
108
- /// @dev Returns the winning token holder in data if successful or the number of pick attempts if not successful .
99
+ /// @dev Returns the number of pick attempts used in the extra hook data .
109
100
function beforeClaimPrize (address _winner , uint8 _tier , uint32 _prizeIndex , uint96 , address ) external view returns (address , bytes memory ) {
110
101
uint256 _tierStartTime;
111
102
uint256 _tierEndTime;
@@ -143,8 +134,8 @@ contract NftChanceBoosterHook is IPrizeHooks {
143
134
_recipientTwab = twabController.getTwabBetween (boostedVault, _ownerOfToken, _tierStartTime, _tierEndTime);
144
135
}
145
136
if (_recipientTwab >= minTwabOverPrizePeriod) {
146
- // The owner of the selected NFT will be awarded the prize in the `afterClaimPrize` callback.
147
- return (address ( this ) , abi.encode (_ownerOfToken ));
137
+ // The prize will be redirected to the owner of the selected NFT
138
+ return (_ownerOfToken , abi.encode (_pickAttempt + 1 ));
148
139
}
149
140
}
150
141
}
@@ -155,19 +146,13 @@ contract NftChanceBoosterHook is IPrizeHooks {
155
146
156
147
/// @inheritdoc IPrizeHooks
157
148
/// @dev If the recipient is set to the prize pool, the prize will be contributed on behalf of the vault
158
- /// that is being boosted. Otherwise if this contract received the prize, it will transfer it to the
159
- /// winner passed in through the extra hook data.
160
- function afterClaimPrize (address _winner , uint8 _tier , uint32 _prizeIndex , uint256 _prizeAmount , address _prizeRecipient , bytes memory _data ) external {
161
- if (_prizeAmount > 0 ) {
162
- if (_prizeRecipient == address (prizePool)) {
163
- uint256 _pickAttempts = abi.decode (_data, (uint256 ));
164
- prizePool.contributePrizeTokens (boostedVault, _prizeAmount);
165
- emit BoostedVaultWithPrize (address (prizePool), boostedVault, _prizeAmount, _pickAttempts);
166
- } else if (_prizeRecipient == address (this )) {
167
- address _nftWinner = abi.decode (_data, (address ));
168
- prizePool.prizeToken ().safeTransfer (_nftWinner, _prizeAmount);
169
- emit PrizeWonByNftHolder (_nftWinner, msg .sender , _winner, _tier, _prizeIndex, _prizeAmount);
170
- }
149
+ /// that is being boosted. Otherwise this hook does nothing since the prize will have already been redirected
150
+ /// to the recipient.
151
+ function afterClaimPrize (address , uint8 , uint32 , uint256 _prizeAmount , address _prizeRecipient , bytes memory _data ) external {
152
+ if (_prizeAmount > 0 && _prizeRecipient == address (prizePool)) {
153
+ uint256 _pickAttempts = abi.decode (_data, (uint256 ));
154
+ prizePool.contributePrizeTokens (boostedVault, _prizeAmount);
155
+ emit BoostedVaultWithPrize (address (prizePool), boostedVault, _prizeAmount, _pickAttempts);
171
156
}
172
157
}
173
158
}
0 commit comments