Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy returns the hook address #36

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,057 changes: 1,057 additions & 0 deletions deployments/compiler-inputs/2fd444c97aa0fa789adae5192c86e854.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bananapus/721-hook",
"version": "0.0.23",
"version": "0.0.24",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
19 changes: 11 additions & 8 deletions src/JB721TiersHookProjectDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
/// @param launchProjectConfig Configuration which dictates the behavior of the project which is being launched.
/// @param controller The controller that the project's rulesets will be queued with.
/// @return projectId The ID of the newly launched project.
/// @return hook The 721 tiers hook that was deployed for the project.
function launchProjectFor(
address owner,
JBDeploy721TiersHookConfig calldata deployTiersHookConfig,
Expand All @@ -71,13 +72,13 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
)
external
override
returns (uint256 projectId)
returns (uint256 projectId, IJB721TiersHook hook)
{
// Get the project's ID, optimistically knowing it will be one greater than the current number of projects.
projectId = DIRECTORY.PROJECTS().count() + 1;

// Deploy the hook.
IJB721TiersHook hook = HOOK_DEPLOYER.deployHookFor(projectId, deployTiersHookConfig);
hook = HOOK_DEPLOYER.deployHookFor(projectId, deployTiersHookConfig);

// Launch the project.
_launchProjectFor(owner, launchProjectConfig, hook, controller);
Expand All @@ -94,6 +95,7 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
/// @param launchRulesetsConfig Configuration which dictates the project's new rulesets.
/// @param controller The controller that the project's rulesets will be queued with.
/// @return rulesetId The ID of the successfully created ruleset.
/// @return hook The 721 tiers hook that was deployed for the project.
function launchRulesetsFor(
uint256 projectId,
JBDeploy721TiersHookConfig calldata deployTiersHookConfig,
Expand All @@ -102,7 +104,7 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
)
external
override
returns (uint256 rulesetId)
returns (uint256 rulesetId, IJB721TiersHook hook)
{
// Enforce permissions.
_requirePermissionFrom({
Expand All @@ -112,13 +114,13 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
});

// Deploy the hook.
IJB721TiersHook hook = HOOK_DEPLOYER.deployHookFor(projectId, deployTiersHookConfig);
hook = HOOK_DEPLOYER.deployHookFor(projectId, deployTiersHookConfig);

// Transfer the hook's ownership to the project.
JBOwnable(address(hook)).transferOwnershipToProject(projectId);

// Launch the rulesets.
return _launchRulesetsFor(projectId, launchRulesetsConfig, hook, controller);
rulesetId = _launchRulesetsFor(projectId, launchRulesetsConfig, hook, controller);
}

/// @notice Queues rulesets for a project with an attached 721 tiers hook.
Expand All @@ -129,6 +131,7 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
/// @param queueRulesetsConfig Configuration which dictates the project's newly queued rulesets.
/// @param controller The controller that the project's rulesets will be queued with.
/// @return rulesetId The ID of the successfully created ruleset.
/// @return hook The 721 tiers hook that was deployed for the project.
function queueRulesetsOf(
uint256 projectId,
JBDeploy721TiersHookConfig calldata deployTiersHookConfig,
Expand All @@ -137,7 +140,7 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
)
external
override
returns (uint256 rulesetId)
returns (uint256 rulesetId, IJB721TiersHook hook)
{
// Enforce permissions.
_requirePermissionFrom({
Expand All @@ -147,13 +150,13 @@ contract JB721TiersHookProjectDeployer is JBPermissioned, IJB721TiersHookProject
});

// Deploy the hook.
IJB721TiersHook hook = HOOK_DEPLOYER.deployHookFor(projectId, deployTiersHookConfig);
hook = HOOK_DEPLOYER.deployHookFor(projectId, deployTiersHookConfig);

// Transfer the hook's ownership to the project.
JBOwnable(address(hook)).transferOwnershipToProject(projectId);

// Queue the rulesets.
return _queueRulesetsOf(projectId, queueRulesetsConfig, hook, controller);
rulesetId = _queueRulesetsOf(projectId, queueRulesetsConfig, hook, controller);
}

//*********************************************************************//
Expand Down
7 changes: 4 additions & 3 deletions src/interfaces/IJB721TiersHookProjectDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import {IJBDirectory} from "@bananapus/core/src/interfaces/IJBDirectory.sol";
import {IJBController} from "@bananapus/core/src/interfaces/IJBController.sol";

import {IJB721TiersHook} from "./IJB721TiersHook.sol";
import {IJB721TiersHookDeployer} from "./IJB721TiersHookDeployer.sol";
import {JBDeploy721TiersHookConfig} from "../structs/JBDeploy721TiersHookConfig.sol";
import {JBLaunchProjectConfig} from "../structs/JBLaunchProjectConfig.sol";
Expand All @@ -21,7 +22,7 @@ interface IJB721TiersHookProjectDeployer {
IJBController controller
)
external
returns (uint256 projectId);
returns (uint256 projectId, IJB721TiersHook hook);

function launchRulesetsFor(
uint256 projectId,
Expand All @@ -30,7 +31,7 @@ interface IJB721TiersHookProjectDeployer {
IJBController controller
)
external
returns (uint256 rulesetId);
returns (uint256 rulesetId, IJB721TiersHook hook);

function queueRulesetsOf(
uint256 projectId,
Expand All @@ -39,5 +40,5 @@ interface IJB721TiersHookProjectDeployer {
IJBController controller
)
external
returns (uint256 rulesetId);
returns (uint256 rulesetId, IJB721TiersHook hook);
}
56 changes: 39 additions & 17 deletions test/E2E/Pay_Mint_Redeem_E2E.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
function testLaunchProjectAndAddHookToRegistry() external {
(JBDeploy721TiersHookConfig memory tiersHookConfig, JBLaunchProjectConfig memory launchProjectConfig) =
createData();
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
// Check: is the first project's ID 1?
assertEq(projectId, 1);
// Check: was the hook added to the address registry?
address dataHook = jbRulesets.currentOf(projectId).dataHook();
assertEq(address(_hook), dataHook);
assertEq(addressRegistry.deployerOf(dataHook), address(deployer.HOOK_DEPLOYER()));
}

Expand All @@ -85,7 +87,8 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
uint256 highestTier = valueSent <= 100 ? (valueSent / 10) : 10;
(JBDeploy721TiersHookConfig memory tiersHookConfig, JBLaunchProjectConfig memory launchProjectConfig) =
createData();
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);

// Crafting the payment metadata: add the highest tier ID.
uint16[] memory rawMetadata = new uint16[](1);
Expand All @@ -96,7 +99,7 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
data[0] = abi.encode(true, rawMetadata);

address dataHook = jbRulesets.currentOf(projectId).dataHook();

assertEq(address(_hook), dataHook);
// Pass the hook ID.
bytes4[] memory ids = new bytes4[](1);
ids[0] = JBMetadataResolver.getId("pay", address(hook));
Expand Down Expand Up @@ -165,7 +168,8 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {

(JBDeploy721TiersHookConfig memory tiersHookConfig, JBLaunchProjectConfig memory launchProjectConfig) =
createDiscountedData(tierStartPrice, uint8(discountPercent));
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);

// Crafting the payment metadata: add the highest tier ID.
uint16[] memory rawMetadata = new uint16[](1);
Expand All @@ -176,13 +180,16 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
data[0] = abi.encode(true, rawMetadata);

address dataHook = jbRulesets.currentOf(projectId).dataHook();
assertEq(address(_hook), dataHook);
bytes memory hookMetadata;
{
// Pass the hook ID.
bytes4[] memory ids = new bytes4[](1);
ids[0] = JBMetadataResolver.getId("pay", address(hook));

// Pass the hook ID.
bytes4[] memory ids = new bytes4[](1);
ids[0] = JBMetadataResolver.getId("pay", address(hook));

// Generate the metadata.
bytes memory hookMetadata = metadataHelper.createMetadata(ids, data);
// Generate the metadata.
hookMetadata = metadataHelper.createMetadata(ids, data);
}

/* // Check: was an NFT with the correct tier ID and token ID minted?
vm.expectEmit(true, true, true, true);
Expand All @@ -195,7 +202,9 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
); */

if (totalSupplyAfterPay > type(uint208).max) {
vm.expectPartialRevert(JBTokens.JBTokens_OverflowAlert.selector);
vm.expectRevert(
abi.encodeWithSelector(JBTokens.JBTokens_OverflowAlert.selector, totalSupplyAfterPay, type(uint208).max)
);
}

// Pay the terminal to mint the NFTs.
Expand Down Expand Up @@ -252,7 +261,8 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
function testMintOnPayIfMultipleTiersArePassed() external {
(JBDeploy721TiersHookConfig memory tiersHookConfig, JBLaunchProjectConfig memory launchProjectConfig) =
createData();
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);

// Prices of the first 5 tiers (10 * `tierId`)
uint256 amountNeeded = 50 + 40 + 30 + 20 + 10;
Expand All @@ -277,6 +287,7 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
data[0] = abi.encode(true, rawMetadata);

address dataHook = jbRulesets.currentOf(projectId).dataHook();
assertEq(address(_hook), dataHook);

// Pass the hook ID.
bytes4[] memory ids = new bytes4[](1);
Expand Down Expand Up @@ -314,9 +325,11 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
valueSent = bound(valueSent, 10, 2000);
(JBDeploy721TiersHookConfig memory tiersHookConfig, JBLaunchProjectConfig memory launchProjectConfig) =
createData();
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);

address dataHook = jbRulesets.currentOf(projectId).dataHook();
assertEq(address(_hook), dataHook);

// Build the metadata with no tiers specified and the overspending flag.
bool allowOverspending = true;
Expand Down Expand Up @@ -347,8 +360,11 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
valueSent = bound(valueSent, 10, 2000);
(JBDeploy721TiersHookConfig memory tiersHookConfig, JBLaunchProjectConfig memory launchProjectConfig) =
createData();
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);

address dataHook = jbRulesets.currentOf(projectId).dataHook();
assertEq(address(_hook), dataHook);

// Pay the terminal with empty metadata (`bytes(0)`).
vm.prank(caller);
Expand Down Expand Up @@ -378,8 +394,10 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {

(JBDeploy721TiersHookConfig memory tiersHookConfig, JBLaunchProjectConfig memory launchProjectConfig) =
createData();
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
address dataHook = jbRulesets.currentOf(projectId).dataHook();
assertEq(address(_hook), dataHook);

// Check: Ensure no pending reserves at start (since no minting has happened).
assertEq(IJB721TiersHook(dataHook).STORE().numberOfPendingReservesFor(dataHook, highestTier), 0);
Expand Down Expand Up @@ -468,13 +486,15 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
uint256 highestTier = valueSent <= 100 ? (valueSent / 10) : 10;
(JBDeploy721TiersHookConfig memory tiersHookConfig, JBLaunchProjectConfig memory launchProjectConfig) =
createData();
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);

// Craft the metadata: buy 1 NFT from the highest tier.
bytes memory hookMetadata;
bytes[] memory data;
bytes4[] memory ids;
address dataHook = jbRulesets.currentOf(projectId).dataHook();
assertEq(address(_hook), dataHook);
{
uint16[] memory rawMetadata = new uint16[](1);
rawMetadata[0] = uint16(highestTier);
Expand Down Expand Up @@ -566,7 +586,8 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
createData();
uint256 tier = 10;
uint256 tierPrice = tiersHookConfig.tiersConfig.tiers[tier - 1].price;
uint256 projectId = deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);
(uint256 projectId, IJB721TiersHook _hook) =
deployer.launchProjectFor(projectOwner, tiersHookConfig, launchProjectConfig, jbController);

// Craft the metadata: buy 5 NFTs from tier 10.
uint16[] memory rawMetadata = new uint16[](5);
Expand All @@ -579,6 +600,7 @@ contract Test_TiersHook_E2E is TestBaseWorkflow {
data[0] = abi.encode(true, rawMetadata);

address dataHook = jbRulesets.currentOf(projectId).dataHook();
assertEq(address(_hook), dataHook);

// Pass the hook ID.
bytes4[] memory ids = new bytes4[](1);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/deployer_Unit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract Test_ProjectDeployer_Unit is UnitTestSetup {
);

// Launch the project.
uint256 projectId = deployer.launchProjectFor(
(uint256 projectId,) = deployer.launchProjectFor(
owner, deploy721TiersHookConfig, launchProjectConfig, IJBController(mockJBController)
);

Expand Down