Skip to content

Commit

Permalink
Introduce CREATE3 (storyprotocol#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster-will authored Apr 15, 2024
1 parent ba93b71 commit f7ddbdf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "5.0.2",
"@openzeppelin/contracts-upgradeable-v4": "npm:@openzeppelin/[email protected]",
"erc6551": "^0.3.1"
"erc6551": "^0.3.1",
"solady": "^0.0.191"
}
}
3 changes: 2 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ds-test/=node_modules/ds-test/src/
forge-std/=node_modules/forge-std/src/
@openzeppelin/=node_modules/@openzeppelin/
@openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades
@openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades
@solady/=node_modules/solady/
33 changes: 22 additions & 11 deletions script/foundry/utils/DeployHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { stdJson } from "forge-std/StdJson.sol";
import { ERC6551Registry } from "erc6551/ERC6551Registry.sol";
import { AccessManager } from "@openzeppelin/contracts/access/manager/AccessManager.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { CREATE3 } from "@solady/src/utils/CREATE3.sol";

// contracts
import { ProtocolPauseAdmin } from "contracts/pause/ProtocolPauseAdmin.sol";
Expand Down Expand Up @@ -157,8 +158,16 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag
_endBroadcast(); // BroadcastManager.s.sol
}

function create3Deploy(bytes32 salt, bytes calldata creationCode, uint256 value) external returns (address) {
return CREATE3.deploy(salt, creationCode, value);
}

function _deployProtocolContracts() private {
require(address(erc20) != address(0), "Deploy: Asset Not Set");
bytes32 ipAccountImplSalt = keccak256(
abi.encode(type(IPAccountImpl).creationCode, address(this), block.timestamp)
);
address ipAccountImplAddr = CREATE3.getDeployed(ipAccountImplSalt);

string memory contractKey;

Expand Down Expand Up @@ -187,11 +196,6 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag
impl = address(0); // Make sure we don't deploy wrong impl
_postdeploy(contractKey, address(accessController));

contractKey = "IPAccountImpl";
_predeploy(contractKey);
ipAccountImpl = new IPAccountImpl(address(accessController));
_postdeploy(contractKey, address(ipAccountImpl));

contractKey = "ModuleRegistry";
_predeploy(contractKey);
impl = address(new ModuleRegistry());
Expand All @@ -206,12 +210,7 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag

contractKey = "IPAssetRegistry";
_predeploy(contractKey);
impl = address(
new IPAssetRegistry(
address(erc6551Registry),
address(ipAccountImpl)
)
);
impl = address(new IPAssetRegistry(address(erc6551Registry), ipAccountImplAddr));
ipAssetRegistry = IPAssetRegistry(
TestProxyHelper.deployUUPSProxy(
impl,
Expand All @@ -235,6 +234,18 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag
impl = address(0); // Make sure we don't deploy wrong impl
_postdeploy(contractKey, address(licenseRegistry));

contractKey = "IPAccountImpl";
bytes memory ipAccountImplCode = abi.encodePacked(
type(IPAccountImpl).creationCode,
abi.encode(
address(accessController)
)
);
_predeploy(contractKey);
this.create3Deploy(ipAccountImplSalt, ipAccountImplCode, 0);
ipAccountImpl = IPAccountImpl(payable(ipAccountImplAddr));
_postdeploy(contractKey, address(ipAccountImpl));

contractKey = "DisputeModule";
_predeploy(contractKey);
impl = address(new DisputeModule(address(accessController), address(ipAssetRegistry), address(licenseRegistry)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Test } from "forge-std/Test.sol";
import { ERC6551Registry } from "erc6551/ERC6551Registry.sol";
import { UpgradeableBeacon } from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import { AccessManager } from "@openzeppelin/contracts/access/manager/AccessManager.sol";
import { CREATE3 } from "@solady/src/utils/CREATE3.sol";

// contracts
import { AccessController } from "../../../../../contracts/access/AccessController.sol";
Expand Down Expand Up @@ -74,6 +75,12 @@ contract e2e is Test {
protocolAccessManager = new AccessManager(admin);

// Deploy contracts

bytes32 ipAccountImplSalt = keccak256(
abi.encode(type(IPAccountImpl).creationCode, address(this), block.timestamp)
);
address ipAccountImplAddr = CREATE3.getDeployed(ipAccountImplSalt);

address impl = address(new AccessController());
accessController = AccessController(
TestProxyHelper.deployUUPSProxy(
Expand All @@ -91,8 +98,7 @@ contract e2e is Test {
);

erc6551Registry = new ERC6551Registry();
ipAccountImpl = new IPAccountImpl(address(accessController));
impl = address(new IPAssetRegistry(address(erc6551Registry), address(ipAccountImpl)));
impl = address(new IPAssetRegistry(address(erc6551Registry), ipAccountImplAddr));
ipAssetRegistry = IPAssetRegistry(
TestProxyHelper.deployUUPSProxy(
impl,
Expand All @@ -108,6 +114,18 @@ contract e2e is Test {
)
);

bytes memory ipAccountImplCode = abi.encodePacked(
type(IPAccountImpl).creationCode,
abi.encode(
address(accessController),
address(ipAssetRegistry),
address(licenseRegistry),
address(moduleRegistry)
)
);
this.create3Deploy(ipAccountImplSalt, ipAccountImplCode, 0);
ipAccountImpl = IPAccountImpl(payable(ipAccountImplAddr));

impl = address(new LicenseToken());
licenseToken = LicenseToken(
TestProxyHelper.deployUUPSProxy(
Expand Down Expand Up @@ -229,6 +247,10 @@ contract e2e is Test {
vm.stopPrank();
}

function create3Deploy(bytes32 salt, bytes calldata creationCode, uint256 value) external returns (address) {
return CREATE3.deploy(salt, creationCode, value);
}

function test_e2e() public {
uint256 tokenId1 = mockNft.mint(alice);
uint256 tokenId2 = mockNft.mint(bob);
Expand Down

0 comments on commit f7ddbdf

Please sign in to comment.