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 1 commit
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
2 changes: 1 addition & 1 deletion lib/sphinx
Submodule sphinx updated 90 files
+4 −5 .github/workflows/docker-image.yml
+19 −11 README.md
+0 −57 docs/breaking/registration.md
+31 −38 docs/cli-existing-project.md
+15 −19 docs/cli-quickstart.md
+1 −1 package.json
+0 −19 packages/contracts/CHANGELOG.md
+0 −1 packages/contracts/contract-artifacts/sphinx/PermissionlessRelay.sol/PermissionlessRelay.json
+0 −764,220 packages/contracts/contract-artifacts/sphinx/permissionless-relay-build-info.json
+0 −61 packages/contracts/contracts/core/PermissionlessRelay.sol
+11 −10 packages/contracts/contracts/foundry/Sphinx.sol
+4 −58 packages/contracts/contracts/foundry/SphinxConstants.sol
+3 −34 packages/contracts/contracts/foundry/SphinxPluginTypes.sol
+89 −83 packages/contracts/contracts/foundry/SphinxUtils.sol
+6 −1 packages/contracts/package.json
+3 −3 packages/contracts/scripts/write-constants.ts
+0 −30 packages/contracts/sphinx.lock
+14 −151 packages/contracts/src/addresses.ts
+15 −7 packages/contracts/src/contract-info.ts
+3 −4 packages/contracts/src/ifaces.ts
+2 −196 packages/contracts/src/networks.ts
+22 −0 packages/contracts/src/utils.ts
+1 −1 packages/contracts/src/version.ts
+1 −1 packages/contracts/test/ManagedService.t.sol
+15 −9 packages/contracts/test/ScriptConfiguration.t.sol
+13 −7 packages/contracts/test/Sphinx.t.sol
+4 −3 packages/contracts/test/SphinxInitCode.sol
+7 −8 packages/contracts/test/SphinxTestUtils.sol
+4 −5 packages/contracts/test/SphinxUtils.t.sol
+21 −0 packages/contracts/test/issues/CHU572.s.sol
+4 −1 packages/contracts/test/issues/CHU663.s.sol
+23 −0 packages/contracts/test/issues/CHU663/CHU663.s.sol
+0 −38 packages/contracts/test/mocha/address.spec.ts
+35 −0 packages/contracts/test/mocha/utils.spec.ts
+0 −44 packages/core/CHANGELOG.md
+7 −0 packages/core/config/local.ts
+14 −0 packages/core/config/standard.ts
+44 −67 packages/core/hardhat.config.ts
+2 −2 packages/core/package.json
+16 −12 packages/core/src/actions/execute.ts
+8 −3 packages/core/src/actions/types.ts
+4 −2 packages/core/src/artifacts.ts
+4 −7 packages/core/src/config/types.ts
+4 −0 packages/core/src/constants.ts
+1 −11 packages/core/src/etherscan.ts
+174 −2 packages/core/src/languages/solidity/predeploys.ts
+1 −2 packages/core/src/languages/solidity/types.ts
+0 −18 packages/core/src/types.ts
+95 −54 packages/core/src/utils.ts
+6 −16 packages/core/test/convert.spec.ts
+0 −22 packages/demo/CHANGELOG.md
+4 −4 packages/demo/package.json
+0 −18 packages/demo/sphinx.lock
+2 −2 packages/demo/test/Solc.spec.ts
+16 −22 packages/demo/test/init.spec.ts
+0 −53 packages/plugins/CHANGELOG.md
+5 −1 packages/plugins/contracts/test/script/Cases.s.sol
+4 −0 packages/plugins/contracts/test/script/Empty.s.sol
+5 −1 packages/plugins/contracts/test/script/Large.s.sol
+5 −1 packages/plugins/contracts/test/script/PartiallyEmpty.s.sol
+5 −1 packages/plugins/contracts/test/script/RevertDuringSimulation.s.sol
+15 −3 packages/plugins/contracts/test/script/Simple.s.sol
+4 −1 packages/plugins/contracts/test/script/issues/CHU676.s.sol
+0 −4 packages/plugins/foundry.toml
+6 −6 packages/plugins/package.json
+7 −3 packages/plugins/script/Sample.s.sol
+0 −12 packages/plugins/script/write-version.ts
+0 −18 packages/plugins/sphinx.lock
+4 −0 packages/plugins/src/cli/context.ts
+3 −0 packages/plugins/src/cli/deploy.ts
+20 −11 packages/plugins/src/cli/propose/index.ts
+5 −30 packages/plugins/src/cli/setup.ts
+8 −0 packages/plugins/src/cli/types.ts
+0 −1 packages/plugins/src/cli/version.ts
+4 −1 packages/plugins/src/foundry/decode.ts
+145 −37 packages/plugins/src/foundry/utils/index.ts
+48 −0 packages/plugins/src/hardhat.config.js
+71 −0 packages/plugins/src/hardhat/hardhatRunner.ts
+618 −0 packages/plugins/src/hardhat/simulate.ts
+1 −0 packages/plugins/src/index.ts
+8 −6 packages/plugins/src/sample-project/index.ts
+11 −4 packages/plugins/src/sample-project/sample-contracts.ts
+1 −2 packages/plugins/src/sample-project/sample-foundry-config.ts
+2 −5 packages/plugins/test/mocha/artifacts.spec.ts
+52 −2 packages/plugins/test/mocha/cli/deploy.spec.ts
+335 −12 packages/plugins/test/mocha/cli/propose.spec.ts
+135 −4 packages/plugins/test/mocha/common.ts
+151 −41 packages/plugins/test/mocha/foundry/utils.spec.ts
+11 −0 packages/plugins/test/mocha/mock.ts
+437 −0 packages/plugins/test/mocha/simulate.spec.ts
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