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

fix(deploy&test): update deploy script and tests to use pre-deployed CREATE3 and apply minor fixes #160

Merged
merged 4 commits into from
Jan 6, 2025
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
18 changes: 10 additions & 8 deletions .github/workflows/foundry_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ jobs:
- name: Run solhint
run: npx solhint contracts/**/*.sol

Coverage:
needs: [foundry-test]
uses: storyprotocol/gha-workflows/.github/workflows/reusable-forge-code-coverage.yml@main
# FOR LOCAL TESTING ONLY
# uses: ./../gha-workflows/.github/workflows/reusable-forge-code-coverage.yml
with:
exclude_paths: 'test/*, script/*'
branch_coverage: true --ignore-errors unused
# TODO: need to update storyprotocol/gha-workflows/.github/workflows/reusable-forge-code-coverage.yml@main to accommodate the changes in the new lcov version
#
# Coverage:
# needs: [foundry-test]
# uses: storyprotocol/gha-workflows/.github/workflows/reusable-forge-code-coverage.yml@main
# # FOR LOCAL TESTING ONLY
# # uses: ./../gha-workflows/.github/workflows/reusable-forge-code-coverage.yml
# with:
# exclude_paths: 'test/*, script/*'
# branch_coverage: true
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@
"typechain": "^8.3.2"
},
"dependencies": {
"@openzeppelin/contracts": "5.0.1",
"@openzeppelin/contracts-upgradeable": "5.0.1",
"@story-protocol/create3-deployer": "github:storyprotocol/create3-deployer#main",
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "5.0.2",
"@story-protocol/protocol-core": "github:storyprotocol/protocol-core-v1#main",
"erc6551": "^0.3.1",
"solady": "^0.0.192"
"solady": "^0.0.281"
}
}
1 change: 0 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
@storyprotocol/core/=node_modules/@story-protocol/protocol-core/contracts/
@storyprotocol/script/=node_modules/@story-protocol/protocol-core/script/foundry/
@storyprotocol/test/=node_modules/@story-protocol/protocol-core/test/foundry/
@create3-deployer/=node_modules/@story-protocol/create3-deployer/
@solady/=node_modules/solady/
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
2 changes: 1 addition & 1 deletion script/deployment/Main.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma solidity 0.8.26;
import { DeployHelper } from "../utils/DeployHelper.sol";

contract Main is DeployHelper {
address internal CREATE3_DEPLOYER = 0x384a891dFDE8180b054f04D66379f16B7a678Ad6;
address internal CREATE3_DEPLOYER = 0x9fBB3DF7C40Da2e5A0dE984fFE2CCB7C47cd0ABf;
uint256 private constant CREATE3_DEFAULT_SEED = 12;

constructor() DeployHelper(CREATE3_DEPLOYER){}
Expand Down
2 changes: 1 addition & 1 deletion script/utils/BroadcastManager.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract BroadcastManager is Script {
deployer = vm.envAddress("MAINNET_DEPLOYER_ADDRESS");
multisig = vm.envAddress("MAINNET_MULTISIG_ADDRESS");
vm.startBroadcast(deployerPrivateKey);
} else if (block.chainid == 1513 || block.chainid == 1516 || block.chainid == 11155111) {
} else if (block.chainid == 1513 || block.chainid == 1514 || block.chainid == 1516) {
deployerPrivateKey = vm.envUint("TESTNET_PRIVATEKEY");
deployer = vm.envAddress("TESTNET_DEPLOYER_ADDRESS");
multisig = vm.envAddress("TESTNET_MULTISIG_ADDRESS");
Expand Down
77 changes: 43 additions & 34 deletions script/utils/DeployHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { console2 } from "forge-std/console2.sol";
import { Script } from "forge-std/Script.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { ERC6551Registry } from "erc6551/ERC6551Registry.sol";
import { ICreate3Deployer } from "@create3-deployer/contracts/ICreate3Deployer.sol";
import { AccessManager } from "@openzeppelin/contracts/access/manager/AccessManager.sol";
import { UpgradeableBeacon } from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
import { ICreate3Deployer } from "@storyprotocol/script/utils/ICreate3Deployer.sol";
import { AccessController } from "@storyprotocol/core/access/AccessController.sol";
import { CoreMetadataModule } from "@storyprotocol/core/modules/metadata/CoreMetadataModule.sol";
import { CoreMetadataViewModule } from "@storyprotocol/core/modules/metadata/CoreMetadataViewModule.sol";
Expand All @@ -24,13 +24,15 @@ import { IpRoyaltyVault } from "@storyprotocol/core/modules/royalty/policies/IpR
import { LicenseRegistry } from "@storyprotocol/core/registries/LicenseRegistry.sol";
import { LicenseToken } from "@storyprotocol/core/LicenseToken.sol";
import { LicensingModule } from "@storyprotocol/core/modules/licensing/LicensingModule.sol";
import { IModuleRegistry } from "@storyprotocol/core/interfaces/registries/IModuleRegistry.sol";
import { ModuleRegistry } from "@storyprotocol/core/registries/ModuleRegistry.sol";
import { PILFlavors } from "@storyprotocol/core/lib/PILFlavors.sol";
import { PILicenseTemplate } from "@storyprotocol/core/modules/licensing/PILicenseTemplate.sol";
import { RoyaltyModule } from "@storyprotocol/core/modules/royalty/RoyaltyModule.sol";
import { RoyaltyPolicyLAP } from "@storyprotocol/core/modules/royalty/policies/LAP/RoyaltyPolicyLAP.sol";
import { RoyaltyPolicyLRP } from "@storyprotocol/core/modules/royalty/policies/LRP/RoyaltyPolicyLRP.sol";
import { StorageLayoutChecker } from "@storyprotocol/script/utils/upgrades/StorageLayoutCheck.s.sol";
import { TestProxyHelper } from "@storyprotocol/test/utils/TestProxyHelper.sol";

// contracts
import { SPGNFT } from "../../contracts/SPGNFT.sol";
Expand All @@ -55,7 +57,6 @@ import { StringUtil } from "./StringUtil.sol";

// test
import { MockERC20 } from "../../test/mocks/MockERC20.sol";
import { TestProxyHelper } from "../../test/utils/TestProxyHelper.t.sol";

contract DeployHelper is
Script,
Expand All @@ -71,6 +72,9 @@ contract DeployHelper is
// PROXY 1967 IMPLEMENTATION STORAGE SLOTS
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

// WIP address
address internal wipAddr = 0x1516000000000000000000000000000000000000;

error DeploymentConfigError(string message);

ICreate3Deployer internal immutable create3Deployer;
Expand Down Expand Up @@ -243,9 +247,9 @@ contract DeployHelper is
// Upgradeable Beacon for DefaultOrgStoryNFTTemplate
_predeploy("DefaultOrgStoryNFTBeacon");
defaultOrgStoryNftBeacon = address(UpgradeableBeacon(
create3Deployer.deploy(
_getSalt("DefaultOrgStoryNFTBeacon"),
abi.encodePacked(type(UpgradeableBeacon).creationCode, abi.encode(defaultOrgStoryNftTemplate, deployer))
create3Deployer.deployDeterministic(
abi.encodePacked(type(UpgradeableBeacon).creationCode, abi.encode(defaultOrgStoryNftTemplate, deployer)),
_getSalt("DefaultOrgStoryNFTBeacon")
)
));
_postdeploy("DefaultOrgStoryNFTBeacon", address(defaultOrgStoryNftBeacon));
Expand Down Expand Up @@ -432,8 +436,7 @@ contract DeployHelper is
// SPGNFT contracts
_predeploy("SPGNFTImpl");
spgNftImpl = SPGNFT(
create3Deployer.deploy(
_getSalt(type(SPGNFT).name),
create3Deployer.deployDeterministic(
abi.encodePacked(type(SPGNFT).creationCode,
abi.encode(
address(derivativeWorkflows),
Expand All @@ -442,29 +445,30 @@ contract DeployHelper is
address(registrationWorkflows),
address(royaltyTokenDistributionWorkflows)
)
)
),
_getSalt(type(SPGNFT).name)
)
);
_postdeploy("SPGNFTImpl", address(spgNftImpl));

_predeploy("SPGNFTBeacon");
spgNftBeacon = UpgradeableBeacon(
create3Deployer.deploy(
_getSalt(type(UpgradeableBeacon).name),
abi.encodePacked(type(UpgradeableBeacon).creationCode, abi.encode(address(spgNftImpl), deployer))
create3Deployer.deployDeterministic(
abi.encodePacked(type(UpgradeableBeacon).creationCode, abi.encode(address(spgNftImpl), deployer)),
_getSalt(type(UpgradeableBeacon).name)
)
);
_postdeploy("SPGNFTBeacon", address(spgNftBeacon));

// Tokenizer Module
_predeploy("TokenizerModule");
impl = address(new TokenizerModule(address(accessController), address(ipAssetRegistry), address(licenseRegistry), address(disputeModule)));
impl = address(new TokenizerModule(accessControllerAddr, ipAssetRegistryAddr, licenseRegistryAddr, disputeModuleAddr));
tokenizerModule = TokenizerModule(
TestProxyHelper.deployUUPSProxy(
create3Deployer,
_getSalt(type(TokenizerModule).name),
impl,
abi.encodeCall(TokenizerModule.initialize, address(protocolAccessManager))
abi.encodeCall(TokenizerModule.initialize, protocolAccessManagerAddr)
)
);
impl = address(0);
Expand All @@ -480,9 +484,9 @@ contract DeployHelper is
// Upgradeable Beacon for OwnableERC20Template
_predeploy("OwnableERC20Beacon");
ownableERC20Beacon = address(UpgradeableBeacon(
create3Deployer.deploy(
_getSalt("OwnableERC20Beacon"),
abi.encodePacked(type(UpgradeableBeacon).creationCode, abi.encode(ownableERC20Template, deployer))
create3Deployer.deployDeterministic(
abi.encodePacked(type(UpgradeableBeacon).creationCode, abi.encode(ownableERC20Template, deployer)),
_getSalt("OwnableERC20Beacon")
)
));
_postdeploy("OwnableERC20Beacon", address(ownableERC20Beacon));
Expand All @@ -501,7 +505,7 @@ contract DeployHelper is
// Transfer ownership of beacon proxy to RegistrationWorkflows
spgNftBeacon.transferOwnership(address(registrationWorkflows));
tokenizerModule.whitelistTokenTemplate(address(ownableERC20Template), true);
moduleRegistry.registerModule("TOKENIZER_MODULE", address(tokenizerModule));
IModuleRegistry(moduleRegistryAddr).registerModule("TOKENIZER_MODULE", address(tokenizerModule));
// more configurations may be added here
}

Expand All @@ -511,9 +515,9 @@ contract DeployHelper is

// protocolAccessManager
protocolAccessManager = AccessManager(
create3Deployer.deploy(
_getSalt(type(AccessManager).name),
abi.encodePacked(type(AccessManager).creationCode, abi.encode(deployer))
create3Deployer.deployDeterministic(
abi.encodePacked(type(AccessManager).creationCode, abi.encode(deployer)),
_getSalt(type(AccessManager).name)
)
);
protocolAccessManagerAddr = address(protocolAccessManager);
Expand All @@ -535,6 +539,7 @@ contract DeployHelper is
abi.encodeCall(ModuleRegistry.initialize, address(protocolAccessManager))
)
);
moduleRegistryAddr = address(moduleRegistry);
require(
_getDeployedAddress(type(ModuleRegistry).name) == address(moduleRegistry),
"Deploy: Module Registry Address Mismatch"
Expand Down Expand Up @@ -620,7 +625,10 @@ contract DeployHelper is
)
);
IPAccountImpl ipAccountImpl = IPAccountImpl(
payable(create3Deployer.deploy(_getSalt(type(IPAccountImpl).name), ipAccountImplCode))
payable(create3Deployer.deployDeterministic(
ipAccountImplCode,
_getSalt(type(IPAccountImpl).name)
))
);
require(
_getDeployedAddress(type(IPAccountImpl).name) == address(ipAccountImpl),
Expand All @@ -640,6 +648,7 @@ contract DeployHelper is
abi.encodeCall(DisputeModule.initialize, address(protocolAccessManager))
)
);
disputeModuleAddr = address(disputeModule);
require(
_getDeployedAddress(type(DisputeModule).name) == address(disputeModule),
"Deploy: Dispute Module Address Mismatch"
Expand Down Expand Up @@ -737,23 +746,23 @@ contract DeployHelper is

// ipRoyaltyVaultImpl
ipRoyaltyVaultImpl = IpRoyaltyVault(
create3Deployer.deploy(
_getSalt(type(IpRoyaltyVault).name),
create3Deployer.deployDeterministic(
abi.encodePacked(
type(IpRoyaltyVault).creationCode,
abi.encode(address(disputeModule), address(royaltyModule), address(ipAssetRegistry), _getDeployedAddress(type(GroupingModule).name))
)
),
_getSalt(type(IpRoyaltyVault).name)
)
);

// ipRoyaltyVaultBeacon
ipRoyaltyVaultBeacon = UpgradeableBeacon(
create3Deployer.deploy(
_getSalt("ipRoyaltyVaultBeacon"),
create3Deployer.deployDeterministic(
abi.encodePacked(
type(UpgradeableBeacon).creationCode,
abi.encode(address(ipRoyaltyVaultImpl), deployer)
)
),
_getSalt("ipRoyaltyVaultBeacon")
)
);

Expand Down Expand Up @@ -815,24 +824,24 @@ contract DeployHelper is

// coreMetadataModule
coreMetadataModule = CoreMetadataModule(
create3Deployer.deploy(
_getSalt(type(CoreMetadataModule).name),
create3Deployer.deployDeterministic(
abi.encodePacked(
type(CoreMetadataModule).creationCode,
abi.encode(address(accessController), address(ipAssetRegistry))
)
),
_getSalt(type(CoreMetadataModule).name)
)
);
coreMetadataModuleAddr = address(coreMetadataModule);

// coreMetadataViewModule
coreMetadataViewModule = CoreMetadataViewModule(
create3Deployer.deploy(
_getSalt(type(CoreMetadataViewModule).name),
create3Deployer.deployDeterministic(
abi.encodePacked(
type(CoreMetadataViewModule).creationCode,
abi.encode(address(ipAssetRegistry), address(moduleRegistry))
)
),
_getSalt(type(CoreMetadataViewModule).name)
)
);

Expand Down Expand Up @@ -948,7 +957,7 @@ contract DeployHelper is

/// @dev Get the deterministic deployed address of a contract with CREATE3
function _getDeployedAddress(string memory name) internal view returns (address) {
return create3Deployer.getDeployed(_getSalt(name));
return create3Deployer.predictDeterministicAddress(_getSalt(name));
}

/// @dev Load the implementation address from the proxy contract
Expand Down
7 changes: 4 additions & 3 deletions script/utils/StoryProtocolCoreAddressManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ contract StoryProtocolCoreAddressManager is Script {
address internal royaltyPolicyLAPAddr;
address internal royaltyPolicyLRPAddr;
address internal evenSplitGroupPoolAddr;
address internal wipAddr;

address internal disputeModuleAddr;
address internal moduleRegistryAddr;
function _readStoryProtocolCoreAddresses() internal {
string memory root = vm.projectRoot();
string memory path = string.concat(
Expand Down Expand Up @@ -52,6 +52,7 @@ contract StoryProtocolCoreAddressManager is Script {
royaltyPolicyLAPAddr = json.readAddress(".main.RoyaltyPolicyLAP");
royaltyPolicyLRPAddr = json.readAddress(".main.RoyaltyPolicyLRP");
evenSplitGroupPoolAddr = json.readAddress(".main.EvenSplitGroupPool");
wipAddr = json.readAddress(".main.WIP");
disputeModuleAddr = json.readAddress(".main.DisputeModule");
moduleRegistryAddr = json.readAddress(".main.ModuleRegistry");
}
}
2 changes: 1 addition & 1 deletion test/integration/BaseIntegration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract BaseIntegration is Test, Script, StoryProtocolCoreAddressManager, Story
RoyaltyWorkflows internal royaltyWorkflows;

/// @dev Story USD
SUSD internal StoryUSD = SUSD(0x6058bB8A2a51a8e63Bd18cE897D08616331C25a7);
SUSD internal StoryUSD = SUSD(0x48D80f8b87F7f1B6f2fBF3A7C45Eb7De6C8374F9);

/// @dev Test data
string internal testCollectionName;
Expand Down
Loading
Loading