Skip to content

Commit

Permalink
Merge pull request #34 from Bananapus/touchup/error-params
Browse files Browse the repository at this point in the history
fixed loops and errors
  • Loading branch information
mejango authored Sep 3, 2024
2 parents 1242bbb + aea8efe commit 4c5a6a4
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 119 deletions.
34 changes: 14 additions & 20 deletions src/JB721TiersHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
// --------------------------- custom errors ------------------------- //
//*********************************************************************//

error JB721TiersHook_AlreadyInitialized();
error JB721TiersHook_Overspending();
error JB721TiersHook_AlreadyInitialized(uint256 projectId);
error JB721TiersHook_NoProjectId();
error JB721TiersHook_Overspending(uint256 leftoverAmount);
error JB721TiersHook_MintReserveNftsPaused();
error JB721TiersHook_TierTransfersPaused();

Expand Down Expand Up @@ -178,7 +179,10 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
override
{
// Stop re-initialization by ensuring a projectId is provided and doesn't already exist.
if (PROJECT_ID != 0 || projectId == 0) revert JB721TiersHook_AlreadyInitialized();
if (PROJECT_ID != 0) revert JB721TiersHook_AlreadyInitialized(PROJECT_ID);

// Make sure a projectId is provided.
if (projectId == 0) revert JB721TiersHook_NoProjectId();

// Initialize the superclass.
JB721Hook._initialize(projectId, name, symbol);
Expand Down Expand Up @@ -293,10 +297,6 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
function adjustTiers(JB721TierConfig[] calldata tiersToAdd, uint256[] calldata tierIdsToRemove) external override {
// Enforce permissions.
_requirePermissionFrom({account: owner(), projectId: PROJECT_ID, permissionId: JBPermissionIds.ADJUST_721_TIERS});

// Get a reference to the number of tiers being added.
uint256 numberOfTiersToAdd = tiersToAdd.length;

// Get a reference to the number of tiers being removed.
uint256 numberOfTiersToRemove = tierIdsToRemove.length;

Expand All @@ -312,6 +312,9 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
STORE.recordRemoveTierIds(tierIdsToRemove);
}

// Get a reference to the number of tiers being added.
uint256 numberOfTiersToAdd = tiersToAdd.length;

// Add the tiers.
if (numberOfTiersToAdd != 0) {
// Record the added tiers in the store.
Expand Down Expand Up @@ -350,12 +353,9 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
// Keep a reference to the number of NFTs being minted.
uint256 numberOfTiers = tierIds.length;

// Keep a reference to the token ID being iterated upon.
uint256 tokenId;

for (uint256 i; i < numberOfTiers; i++) {
// Set the token ID.
tokenId = tokenIds[i];
uint256 tokenId = tokenIds[i];

// Mint the NFT.
_mint(beneficiary, tokenId);
Expand Down Expand Up @@ -415,12 +415,9 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
// Keep a reference to the number of configs being set.
uint256 numberOfConfigs = configs.length;

// Keep a reference to the config being iterated on.
JB721TiersSetDiscountPercentConfig memory config;

for (uint256 i; i < numberOfConfigs; i++) {
// Set the config being iterated on.
config = configs[i];
JB721TiersSetDiscountPercentConfig memory config = configs[i];

_setDiscountPercentOf(config.tierId, config.discountPercent);
}
Expand Down Expand Up @@ -496,12 +493,9 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
// slither-disable-next-line calls-loop
address reserveBeneficiary = STORE.reserveBeneficiaryOf(address(this), tierId);

// Keep a reference to the token ID being iterated upon.
uint256 tokenId;

for (uint256 i; i < count; i++) {
// Set the token ID.
tokenId = tokenIds[i];
uint256 tokenId = tokenIds[i];

emit MintReservedNft({
tokenId: tokenId,
Expand Down Expand Up @@ -687,7 +681,7 @@ contract JB721TiersHook is JBOwnable, ERC2771Context, JB721Hook, IJB721TiersHook
// If overspending is allowed and there are leftover funds, add those funds to the beneficiary's NFT credits.
if (leftoverAmount != 0) {
// If overspending isn't allowed, revert.
if (!allowOverspending) revert JB721TiersHook_Overspending();
if (!allowOverspending) revert JB721TiersHook_Overspending(leftoverAmount);

// Increment the leftover amount.
unchecked {
Expand Down
15 changes: 3 additions & 12 deletions src/JB721TiersHookProjectDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,10 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
// Initialize an array of ruleset configurations.
JBRulesetConfig[] memory rulesetConfigurations = new JBRulesetConfig[](numberOfRulesetConfigurations);

// Keep a reference to the pay data ruleset config being iterated on.
JBPayDataHookRulesetConfig memory payDataRulesetConfig;

// Set the data hook to be active for pay transactions for each ruleset configuration.
for (uint256 i; i < numberOfRulesetConfigurations; i++) {
// Set the pay data ruleset config being iterated on.
payDataRulesetConfig = launchProjectConfig.rulesetConfigurations[i];
JBPayDataHookRulesetConfig memory payDataRulesetConfig = launchProjectConfig.rulesetConfigurations[i];

// Add the ruleset config.
rulesetConfigurations[i] = JBRulesetConfig({
Expand Down Expand Up @@ -253,13 +250,10 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
// Initialize an array of ruleset configurations.
JBRulesetConfig[] memory rulesetConfigurations = new JBRulesetConfig[](numberOfRulesetConfigurations);

// Keep a reference to the pay data ruleset config being iterated on.
JBPayDataHookRulesetConfig memory payDataRulesetConfig;

// Set the data hook to be active for pay transactions for each ruleset configuration.
for (uint256 i; i < numberOfRulesetConfigurations; i++) {
// Set the pay data ruleset config being iterated on.
payDataRulesetConfig = launchRulesetsConfig.rulesetConfigurations[i];
JBPayDataHookRulesetConfig memory payDataRulesetConfig = launchRulesetsConfig.rulesetConfigurations[i];

// Add the ruleset config.
rulesetConfigurations[i] = JBRulesetConfig({
Expand Down Expand Up @@ -325,13 +319,10 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
// Initialize an array of ruleset configurations.
JBRulesetConfig[] memory rulesetConfigurations = new JBRulesetConfig[](numberOfRulesetConfigurations);

// Keep a reference to the pay data ruleset config being iterated on.
JBPayDataHookRulesetConfig memory payDataRulesetConfig;

// Set the data hook to be active for pay transactions for each ruleset configuration.
for (uint256 i; i < numberOfRulesetConfigurations; i++) {
// Set the pay data ruleset config being iterated on.
payDataRulesetConfig = queueRulesetsConfig.rulesetConfigurations[i];
JBPayDataHookRulesetConfig memory payDataRulesetConfig = queueRulesetsConfig.rulesetConfigurations[i];

// Add the ruleset config.
rulesetConfigurations[i] = JBRulesetConfig({
Expand Down
Loading

0 comments on commit 4c5a6a4

Please sign in to comment.