From cd5a14a462a19e7a33def6a09ded4fbc91247021 Mon Sep 17 00:00:00 2001 From: dan13ram Date: Mon, 15 Apr 2024 00:23:46 +0530 Subject: [PATCH] deployed to sepolia --- Makefile | 11 +--- addresses.json | 66 ++++++------------- foundry.toml | 2 +- scripts/BaseDeployer.sol | 26 +++++++- scripts/CharacterAccount.s.sol | 9 ++- scripts/CharacterSheetsFactory.s.sol | 22 ++++--- scripts/CharacterSheetsImplementation.s.sol | 9 ++- ...haracterSheetsLevelEligibilityModule.s.sol | 9 ++- scripts/ClassLevelAdaptor.s.sol | 9 ++- scripts/ClassesImplementation.s.sol | 9 ++- .../ClonesAddressStorageImplementation.s.sol | 9 ++- scripts/ERC6551HatsEligibilityModule.s.sol | 9 ++- scripts/ExperienceImplementation.s.sol | 9 ++- scripts/HatsAdaptor.s.sol | 9 ++- scripts/ImplementationAddressStorage.s.sol | 32 +++++---- scripts/ItemsImplementation.s.sol | 9 ++- scripts/ItemsManagerImplementation.s.sol | 9 ++- scripts/MolochV2EligibilityAdaptor.s.sol | 9 ++- scripts/MolochV3EligibilityAdaptor.s.sol | 9 ++- .../MultiERC6551HatsEligibilityModule.s.sol | 14 +++- scripts/deploy.sh | 22 ++++--- scripts/verify.sh | 10 +-- src/adaptors/HatsAdaptor.sol | 5 -- src/mocks/AllowlistHatsEligibilityModule.sol | 31 +++++---- test/CharacterAccount.t.sol | 1 - 25 files changed, 218 insertions(+), 141 deletions(-) diff --git a/Makefile b/Makefile index 478eaa2..4c2557c 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ snapshot :; forge snapshot slither :; slither --config-file slither.config.json src/. -format :; forge fmt +format :; forge fmt src/**/*.sol && forge fmt scripts/**/*.sol && forge fmt test/**/*.sol # solhint should be installed globally lint :; solhint "src/**/*.sol" @@ -44,15 +44,6 @@ deploy :; verify :; ./scripts/verify.sh ${network} ${contract} CONTRACTS = \ -CharacterAccount \ -CharacterSheetsImplementation \ -ExperienceImplementation \ -ItemsImplementation \ -ItemsManagerImplementation \ -ClassesImplementation \ -MolochV2EligibilityAdaptor \ -MolochV3EligibilityAdaptor \ -ClassLevelAdaptor \ HatsAdaptor \ CharacterSheetsLevelEligibilityModule \ ERC6551HatsEligibilityModule \ diff --git a/addresses.json b/addresses.json index 1fe838c..dcf0a4a 100644 --- a/addresses.json +++ b/addresses.json @@ -39,6 +39,7 @@ "HatsAdaptor": "", "CharacterSheetsLevelEligibilityModule": "", "AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986", + "AllowListHatsEligibilityModule": "0xaC208e6668DE569C6ea1db76DeCea70430335Ed5", "ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab", "ERC6551HatsEligibilityModule": "0x36C55610d6043703bF7Ae29a8aa5768FC4772738", "MultiERC6511HatsEligibilityModule": "", @@ -66,6 +67,7 @@ "HatsAdaptor": "", "CharacterSheetsLevelEligibilityModule": "", "AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986", + "AllowListHatsEligibilityModule": "0xaC208e6668DE569C6ea1db76DeCea70430335Ed5", "ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab", "ERC6551HatsEligibilityModule": "", "MultiERC6511HatsEligibilityModule": "", @@ -93,6 +95,7 @@ "HatsAdaptor": "", "CharacterSheetsLevelEligibilityModule": "", "AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986", + "AllowListHatsEligibilityModule": "0xaC208e6668DE569C6ea1db76DeCea70430335Ed5", "ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab", "ERC6551HatsEligibilityModule": "", "MultiERC6511HatsEligibilityModule": "", @@ -107,57 +110,30 @@ "MolochV3EligibilityAdaptor": "", "ClonesAddressStorageImplementation": "" }, - "goerli": { - "chainId": "5", - "network": "goerli", - "Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921", - "HatsContract": "0x3bc1A0Ad72417f2d411118085256fC53CBdDd137", - "HatsModuleFactory": "0xfE661c01891172046feE16D3a57c3Cf456729efA", - "CharacterAccount": "0x3cD942A7902b955E0a5222d80376B29062Ea9DaA", - "ClassesImplementation": "0x62b97b232Ed8b11409ff8a7648214010426355ed", - "CharacterSheetsFactory": "0x570F219D3FA620E7Fd48ff4787F2Da169Ed12244", - "ExperienceImplementation": "0x8065d9c66d41bF35473B71D17aCBD535dd2a3488", - "ItemsManagerImplementation": "0xEC48EB7BE3B867cB9Af481533008752d64514d84", - "CloneAddressStorage": "0xbc0A467b8100c87282988c6ff71d4227C822bF2e", - "ImplementationAddressStorage": "0x07ECa0752E074C981fB0a5eE16E7114d809ed3ff", - "ItemsImplementation": "0x8117C81B65dF2d899E413F65dd1230Ccd92Ea80a", - "CharacterSheetsImplementation": "0x5d429668Cc7FAE3657359548B413Ced02398F030", - "CharacterEligibilityAdaptorV2": "", - "CharacterEligibilityAdaptorV3": "0xC557D0a20e0BfC06adFA2eD0503523dF011E850B", - "ClassLevelAdaptor": "0x1F4Bf13C531f4875fb5d2859dCD88591b8d471f1", - "HatsAdaptor": "0x163920D269760feB9eD161601648832d963e4143", - "AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986", - "CharacterSheetsLevelEligibilityModule": "0x6f52b30a4730C5Cb765E7c762249dc4Ae02fB8eD", - "ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab", - "ERC6551HatsEligibilityModule": "0xa25B005B82209B2D2dC6E86006ae75649b1dAb5b", - "MultiERC6511HatsEligibilityModule": "", - "ClonesAddressStorageImplementation": "0xfFE77f170cEFcC2248e6697c32ef665FcF685E14" - }, "sepolia": { "chainId": "11155111", "network": "sepolia", "Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921", - "CharacterAccount": "0xb37557c4d1208A786fE0C28Dd865034c3e3d9038", - "ExperienceImplementation": "0xCA8d9B4c514B28a1aD5240F3071E3167E9074A53", - "CharacterSheetsImplementation": "0xF4A596FC9a70CDB508Ea21686ae20d42e6068423", - "ClassesImplementation": "0xA32b0d22cf72556D9caa1397E3c1096bFBb9CdCe", - "CharacterSheetsFactory": "0xc3158e0aB9aa1623022FeFdF4a3Ac022ff0dfcc1", - "ClassLevelAdaptor": "0x1d598591374D314AfFB2aed1370D8c81CbbA261F", - "HatsAdaptor": "0x1D5B39612a354C2Ff1f50cfd8D9FDEdB4d4F9e62", - "AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986", + "AllowListHatsEligibilityModule": "0xaC208e6668DE569C6ea1db76DeCea70430335Ed5", "ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab", - "ERC6551HatsEligibilityModule": "0x74e35a750DF66D3845a9359afb9EE0B4D7E41B99", - "MultiERC6511HatsEligibilityModule": "", - "CharacterSheetsLevelEligibilityModule": "0xb2Fe75E4FF7520A85938ff755BD6d2fCEFb9196E", - "ItemsManagerImplementation": "0x982EFC86035e838de7967De1b1A8f72097d84733", - "ClonesAddressStorage": "", - "ImplementationAddressStorage": "0x33018D9cCF2FE77130Cf22AA81CbA07E8B098dF3", - "ItemsImplementation": "0xE27109834a24838c2659b9a023803cb15e7633Ef", "HatsContract": "0x3bc1A0Ad72417f2d411118085256fC53CBdDd137", "HatsModuleFactory": "0xfE661c01891172046feE16D3a57c3Cf456729efA", - "MolochV2EligibilityAdaptor": "0x0E0514a13c905F4DEd5e46769aC5FD049fB8aC6F", - "MolochV3EligibilityAdaptor": "0xCb6787d033750D610107C96bcff4d925dde026b5", - "ClonesAddressStorageImplementation": "0xeCb73607DD8fD80F4E8f50b5B46A3286eA3e1854" + "CharacterAccount": "0x936aa7A9882725D6678751BCe43b834cFEB104d6", + "CharacterSheetsImplementation": "0xF925c147EB2d829693Dbd396ECFe0370627e7513", + "ExperienceImplementation": "0xd4d0f703a1B1205EC1a6C45499d2a8b7292B726c", + "ItemsImplementation": "0x6605D4F26e87b0bc034e5A059B448509bEd45577", + "ItemsManagerImplementation": "0x473017Ee3dF48C194f19688d39Cb9a83903A9CeF", + "ClassesImplementation": "0x6db7DF9a3bdF2c2dF76CA679f5954CCF88a34D94", + "MolochV2EligibilityAdaptor": "0x993c409E0f37238b97F45fe2D6223D8e3118d498", + "MolochV3EligibilityAdaptor": "0xFb38767DD77Ab247AA71F51774e0d9BdfC0238b3", + "ClassLevelAdaptor": "0x9888797415B7d5a976325972b3585bC1bbc390F3", + "HatsAdaptor": "0x966A24e86A6F4fe47C07A442bdA636Ae19cd9a50", + "CharacterSheetsLevelEligibilityModule": "0x6c904AF082FB429f5389278923EBA0Fe9dd59dc4", + "ERC6551HatsEligibilityModule": "0x2FB64E7cC67466f9dAA627c893D47AF3E42b06A9", + "MultiERC6551HatsEligibilityModule": "0x5a1551E7821eE6c56108761c301382B89f7bb08d", + "ClonesAddressStorageImplementation": "0x5768c8B53930C3971357c78EF91C1Edf33F4b1B3", + "ImplementationAddressStorage": "0xEd3551A9A4807134C568EFa7D2Db6f3C66558179", + "CharacterSheetsFactory": "0xC31cd47907ED2C2693182506Df6437d9151f37a6" }, "anvil": { "chainId": "31337", @@ -186,4 +162,4 @@ "ERC6551HatsEligibilityModule": "", "MultiERC6511HatsEligibilityModule": "" } -} \ No newline at end of file +} diff --git a/foundry.toml b/foundry.toml index 53a3a79..747ef3d 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,5 +1,5 @@ [profile.default] - solc_version = "0.8.24" + solc_version = "0.8.25" evm_version = "cancun" bytecode_hash = "none" optimizer = true diff --git a/scripts/BaseDeployer.sol b/scripts/BaseDeployer.sol index b7b1a07..022e914 100644 --- a/scripts/BaseDeployer.sol +++ b/scripts/BaseDeployer.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; //solhint-disable @@ -11,14 +11,36 @@ import {ForkManagement} from "./helpers/ForkManagement.sol"; abstract contract BaseDeployer is Script, ForkManagement { using stdJson for string; - string public _version = "version 0.1"; + string public _version = "0.0.1"; uint256 deployerPrivateKey; address deployer; + bytes32 public SALT = bytes32(keccak256(abi.encode("CS"))); + address public CREATE2_DEPLOYER = address(0x4e59b44847b379578588920cA78FbF26c0B4956C); + function loadBaseAddresses(string memory json, string memory targetEnv) internal virtual { // empty } + function getDeploymentAddress(bytes memory creationCode, bytes memory params) internal view returns (address) { + bytes32 newContract = keccak256( + abi.encodePacked(bytes1(0xff), CREATE2_DEPLOYER, SALT, keccak256(abi.encodePacked(creationCode, params))) + ); + return address(uint160(uint256(newContract))); + } + + function getDeploymentAddress(bytes memory creationCode) internal view returns (address) { + return getDeploymentAddress(creationCode, ""); + } + + function isContract(address a) public view returns (bool) { + uint32 size; + assembly { + size := extcodesize(a) + } + return (size > 0); + } + function loadPrivateKeys() internal { string memory mnemonic = vm.envString("MNEMONIC"); diff --git a/scripts/CharacterAccount.s.sol b/scripts/CharacterAccount.s.sol index 51e94fa..911e3da 100644 --- a/scripts/CharacterAccount.s.sol +++ b/scripts/CharacterAccount.s.sol @@ -17,10 +17,15 @@ contract DeployCharacterAccount is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - characterAccount = new CharacterAccount(); + address newContractAddress = getDeploymentAddress(type(CharacterAccount).creationCode); + + if (!isContract(newContractAddress)) { + characterAccount = new CharacterAccount{salt: SALT}(); + assert(address(characterAccount) == newContractAddress); + } vm.stopBroadcast(); - return address(characterAccount); + return newContractAddress; } } diff --git a/scripts/CharacterSheetsFactory.s.sol b/scripts/CharacterSheetsFactory.s.sol index 443b532..33fdb09 100644 --- a/scripts/CharacterSheetsFactory.s.sol +++ b/scripts/CharacterSheetsFactory.s.sol @@ -48,13 +48,18 @@ contract DeployCharacterSheetsFactory is BaseDeployer { vm.startBroadcast(deployerPrivateKey); - characterSheetsFactory = new CharacterSheetsFactory(); + address newContractAddress = getDeploymentAddress(type(CharacterSheetsFactory).creationCode); - characterSheetsFactory.initialize(implementationAddressStorage); + if (!isContract(newContractAddress)) { + characterSheetsFactory = new CharacterSheetsFactory{salt: SALT}(); + + characterSheetsFactory.initialize(implementationAddressStorage); + assert(address(characterSheetsFactory) == newContractAddress); + } vm.stopBroadcast(); - return address(characterSheetsFactory); + return newContractAddress; } } @@ -80,7 +85,8 @@ contract Create is BaseExecutor { function loadBaseData(string memory json, string memory targetEnv) internal override { // addresses dao = json.readAddress(string(abi.encodePacked(".", targetEnv, ".Dao"))); - address characterSheetsFactory = json.readAddress(string(abi.encodePacked(".", targetEnv, ".CharacterSheetsFactory"))); + address characterSheetsFactory = + json.readAddress(string(abi.encodePacked(".", targetEnv, ".CharacterSheetsFactory"))); gameMasters = json.readAddressArray(string(abi.encodePacked(".", targetEnv, ".GameMasters"))); implementationStorageAddress = json.readAddress(string(abi.encodePacked(".", targetEnv, ".ImplementationAddressStorage"))); @@ -110,12 +116,12 @@ contract Create is BaseExecutor { // init and encode factory = CharacterSheetsFactory(characterSheetsFactory); encodedSheetsStrings = ""; - // abi.encode(characterSheetsMetadataUri, characterSheetsBaseUri, itemsBaseUri, classesBaseUri); - encodedHatsAddresses = ""; - // abi.encode(arg); + // abi.encode(characterSheetsMetadataUri, characterSheetsBaseUri, itemsBaseUri, classesBaseUri); + encodedHatsAddresses = ""; + // abi.encode(arg); } - function execute() internal override { + function execute() internal override { vm.startBroadcast(deployerPrivateKey); clonesAddressStorage = factory.create(dao); vm.stopBroadcast(); diff --git a/scripts/CharacterSheetsImplementation.s.sol b/scripts/CharacterSheetsImplementation.s.sol index c191252..331ee82 100644 --- a/scripts/CharacterSheetsImplementation.s.sol +++ b/scripts/CharacterSheetsImplementation.s.sol @@ -56,10 +56,15 @@ contract DeployCharacterSheetsImplementation is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - characterSheetsImplementation = new CharacterSheetsImplementation(); + address newContractAddress = getDeploymentAddress(type(CharacterSheetsImplementation).creationCode); + + if (!isContract(newContractAddress)) { + characterSheetsImplementation = new CharacterSheetsImplementation{salt: SALT}(); + assert(address(characterSheetsImplementation) == newContractAddress); + } vm.stopBroadcast(); - return address(characterSheetsImplementation); + return newContractAddress; } } diff --git a/scripts/CharacterSheetsLevelEligibilityModule.s.sol b/scripts/CharacterSheetsLevelEligibilityModule.s.sol index 5e2341e..b40cc3a 100644 --- a/scripts/CharacterSheetsLevelEligibilityModule.s.sol +++ b/scripts/CharacterSheetsLevelEligibilityModule.s.sol @@ -16,10 +16,15 @@ contract DeployCharacterSheetsLevelEligibilityModule is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - characterSheetsLevelEligibilityModule = new CharacterSheetsLevelEligibilityModule(_version); + address newContractAddress = getDeploymentAddress(type(CharacterSheetsLevelEligibilityModule).creationCode, abi.encode(_version)); + + if (!isContract(newContractAddress)) { + characterSheetsLevelEligibilityModule = new CharacterSheetsLevelEligibilityModule{salt: SALT}(_version); + assert(address(characterSheetsLevelEligibilityModule) == newContractAddress); + } vm.stopBroadcast(); - return address(characterSheetsLevelEligibilityModule); + return newContractAddress; } } diff --git a/scripts/ClassLevelAdaptor.s.sol b/scripts/ClassLevelAdaptor.s.sol index 8144616..ccb8d8f 100644 --- a/scripts/ClassLevelAdaptor.s.sol +++ b/scripts/ClassLevelAdaptor.s.sol @@ -15,10 +15,15 @@ contract DeployClassLevelAdaptor is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - classLevelAdaptor = new ClassLevelAdaptor(); + address newContractAddress = getDeploymentAddress(type(ClassLevelAdaptor).creationCode); + + if (!isContract(newContractAddress)) { + classLevelAdaptor = new ClassLevelAdaptor{salt: SALT}(); + assert(address(classLevelAdaptor) == newContractAddress); + } vm.stopBroadcast(); - return address(classLevelAdaptor); + return newContractAddress; } } diff --git a/scripts/ClassesImplementation.s.sol b/scripts/ClassesImplementation.s.sol index e736e54..40f350d 100644 --- a/scripts/ClassesImplementation.s.sol +++ b/scripts/ClassesImplementation.s.sol @@ -18,11 +18,16 @@ contract DeployClassesImplementation is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - classesImplementation = new ClassesImplementation(); + address newContractAddress = getDeploymentAddress(type(ClassesImplementation).creationCode); + + if (!isContract(newContractAddress)) { + classesImplementation = new ClassesImplementation{salt: SALT}(); + assert(address(classesImplementation) == newContractAddress); + } vm.stopBroadcast(); - return address(classesImplementation); + return newContractAddress; } } diff --git a/scripts/ClonesAddressStorageImplementation.s.sol b/scripts/ClonesAddressStorageImplementation.s.sol index fde43e3..12bd8ac 100644 --- a/scripts/ClonesAddressStorageImplementation.s.sol +++ b/scripts/ClonesAddressStorageImplementation.s.sol @@ -15,10 +15,15 @@ contract DeployClonesAddressStorageImplementation is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - clonesAddressStorage = new ClonesAddressStorageImplementation(); + address newContractAddress = getDeploymentAddress(type(ClonesAddressStorageImplementation).creationCode); + + if (!isContract(newContractAddress)) { + clonesAddressStorage = new ClonesAddressStorageImplementation{salt: SALT}(); + assert(address(clonesAddressStorage) == newContractAddress); + } vm.stopBroadcast(); - return address(clonesAddressStorage); + return newContractAddress; } } diff --git a/scripts/ERC6551HatsEligibilityModule.s.sol b/scripts/ERC6551HatsEligibilityModule.s.sol index 87f99b4..508720e 100644 --- a/scripts/ERC6551HatsEligibilityModule.s.sol +++ b/scripts/ERC6551HatsEligibilityModule.s.sol @@ -15,10 +15,15 @@ contract DeployERC6551HatsEligibilityModule is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - erc6551HatsEligibilityModule = new ERC6551HatsEligibilityModule(_version); + address newContractAddress = getDeploymentAddress(type(ERC6551HatsEligibilityModule).creationCode, abi.encode(_version)); + + if (!isContract(newContractAddress)) { + erc6551HatsEligibilityModule = new ERC6551HatsEligibilityModule{salt: SALT}(_version); + assert(address(erc6551HatsEligibilityModule) == newContractAddress); + } vm.stopBroadcast(); - return address(erc6551HatsEligibilityModule); + return newContractAddress; } } diff --git a/scripts/ExperienceImplementation.s.sol b/scripts/ExperienceImplementation.s.sol index 36ff725..679b377 100644 --- a/scripts/ExperienceImplementation.s.sol +++ b/scripts/ExperienceImplementation.s.sol @@ -17,11 +17,16 @@ contract DeployExperienceImplementation is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - experienceImplementation = new ExperienceImplementation(); + address newContractAddress = getDeploymentAddress(type(ExperienceImplementation).creationCode); + + if (!isContract(newContractAddress)) { + experienceImplementation = new ExperienceImplementation{salt: SALT}(); + assert(address(experienceImplementation) == newContractAddress); + } vm.stopBroadcast(); - return address(experienceImplementation); + return newContractAddress; } } diff --git a/scripts/HatsAdaptor.s.sol b/scripts/HatsAdaptor.s.sol index 3226188..a10cb31 100644 --- a/scripts/HatsAdaptor.s.sol +++ b/scripts/HatsAdaptor.s.sol @@ -15,10 +15,15 @@ contract DeployHatsAdaptor is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - hatsAdaptor = new HatsAdaptor(); + address newContractAddress = getDeploymentAddress(type(HatsAdaptor).creationCode); + + if (!isContract(newContractAddress)) { + hatsAdaptor = new HatsAdaptor{salt: SALT}(); + assert(address(hatsAdaptor) == newContractAddress); + } vm.stopBroadcast(); - return address(hatsAdaptor); + return newContractAddress; } } diff --git a/scripts/ImplementationAddressStorage.s.sol b/scripts/ImplementationAddressStorage.s.sol index d0977d1..f574a54 100644 --- a/scripts/ImplementationAddressStorage.s.sol +++ b/scripts/ImplementationAddressStorage.s.sol @@ -27,7 +27,7 @@ struct HatsAddresses { address hatsContract; address hatsModuleFactory; //eligibility modules - address addressHatsEligibilityModule; + address allowListHatsEligibilityModule; address erc721HatsEligibilityModule; address erc6551HatsEligitbilityModule; address multiErc6551HatsEligitbilityModule; @@ -49,7 +49,7 @@ struct HatsAddresses { * * function _initAdaptorsAndModules(bytes calldata encodedAdaptorsAndModuleAddresses) internal { * ( - * _implementationsAddresses.addressHatsEligibilityModule, + * _implementationsAddresses.allowListHatsEligibilityModule, * _implementationsAddresses.gameMasterHatsEligibilityModule, * _implementationsAddresses.erc721HatsEligibilityModule, * _implementationsAddresses.erc6551HatsEligitbilityModule, @@ -87,16 +87,22 @@ contract DeployImplementationAddressStorage is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - implementationAddressStorage = new ImplementationAddressStorage(); - implementationAddressStorage.initialize( - _encodeImplementationAddresses(), - _encodeModuleAddresses(), - _encodeAdaptorAddresses(), - _encodeExternalAddresses() - ); + address newContractAddress = getDeploymentAddress(type(ImplementationAddressStorage).creationCode); + + if (!isContract(newContractAddress)) { + implementationAddressStorage = new ImplementationAddressStorage{salt: SALT}(); + implementationAddressStorage.initialize( + _encodeImplementationAddresses(), + _encodeModuleAddresses(), + _encodeAdaptorAddresses(), + _encodeExternalAddresses() + ); + assert(address(implementationAddressStorage) == newContractAddress); + } + vm.stopBroadcast(); - return address(implementationAddressStorage); + return newContractAddress; } function _loadImplementationaddresses(string memory json, string memory targetEnv) internal { @@ -119,8 +125,8 @@ contract DeployImplementationAddressStorage is BaseDeployer { json.readAddress(string(abi.encodePacked(".", targetEnv, ".MolochV2EligibilityAdaptor"))); implementationAddresses.molochV3EligibilityAdaptorImplementation = json.readAddress(string(abi.encodePacked(".", targetEnv, ".MolochV3EligibilityAdaptor"))); - hatsAddresses.addressHatsEligibilityModule = - json.readAddress(string(abi.encodePacked(".", targetEnv, ".AddressHatsEligibilityModule"))); + hatsAddresses.allowListHatsEligibilityModule = + json.readAddress(string(abi.encodePacked(".", targetEnv, ".AllowListHatsEligibilityModule"))); hatsAddresses.erc721HatsEligibilityModule = json.readAddress(string(abi.encodePacked(".", targetEnv, ".ERC721HatsEligibilityModule"))); hatsAddresses.erc6551HatsEligitbilityModule = @@ -168,7 +174,7 @@ contract DeployImplementationAddressStorage is BaseDeployer { function _encodeModuleAddresses() internal view returns (bytes memory) { bytes memory encodedModuleAddresses = abi.encode( - hatsAddresses.addressHatsEligibilityModule, + hatsAddresses.allowListHatsEligibilityModule, hatsAddresses.erc721HatsEligibilityModule, hatsAddresses.erc6551HatsEligitbilityModule, hatsAddresses.multiErc6551HatsEligitbilityModule diff --git a/scripts/ItemsImplementation.s.sol b/scripts/ItemsImplementation.s.sol index c83b23d..b447402 100644 --- a/scripts/ItemsImplementation.s.sol +++ b/scripts/ItemsImplementation.s.sol @@ -17,11 +17,16 @@ contract DeployItemsImplementation is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - itemsImplementation = new ItemsImplementation(); + address newContractAddress = getDeploymentAddress(type(ItemsImplementation).creationCode); + + if (!isContract(newContractAddress)) { + itemsImplementation = new ItemsImplementation{salt: SALT}(); + assert(address(itemsImplementation) == newContractAddress); + } vm.stopBroadcast(); - return address(itemsImplementation); + return newContractAddress; } } diff --git a/scripts/ItemsManagerImplementation.s.sol b/scripts/ItemsManagerImplementation.s.sol index 84d9945..22ebfe8 100644 --- a/scripts/ItemsManagerImplementation.s.sol +++ b/scripts/ItemsManagerImplementation.s.sol @@ -17,10 +17,15 @@ contract DeployItemsManagerImplementation is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - itemsManagerImplementation = new ItemsManagerImplementation(); + address newContractAddress = getDeploymentAddress(type(ItemsManagerImplementation).creationCode); + + if (!isContract(newContractAddress)) { + itemsManagerImplementation = new ItemsManagerImplementation{salt: SALT}(); + assert(address(itemsManagerImplementation) == newContractAddress); + } vm.stopBroadcast(); - return address(itemsManagerImplementation); + return newContractAddress; } } diff --git a/scripts/MolochV2EligibilityAdaptor.s.sol b/scripts/MolochV2EligibilityAdaptor.s.sol index c18b347..006f79a 100644 --- a/scripts/MolochV2EligibilityAdaptor.s.sol +++ b/scripts/MolochV2EligibilityAdaptor.s.sol @@ -15,10 +15,15 @@ contract DeployMolochV2EligibilityAdaptor is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - molochV2EligibilityAdaptor = new MolochV2EligibilityAdaptor(); + address newContractAddress = getDeploymentAddress(type(MolochV2EligibilityAdaptor).creationCode); + + if (!isContract(newContractAddress)) { + molochV2EligibilityAdaptor = new MolochV2EligibilityAdaptor{salt: SALT}(); + assert(address(molochV2EligibilityAdaptor) == newContractAddress); + } vm.stopBroadcast(); - return address(molochV2EligibilityAdaptor); + return newContractAddress; } } diff --git a/scripts/MolochV3EligibilityAdaptor.s.sol b/scripts/MolochV3EligibilityAdaptor.s.sol index c92bec6..e8f9c09 100644 --- a/scripts/MolochV3EligibilityAdaptor.s.sol +++ b/scripts/MolochV3EligibilityAdaptor.s.sol @@ -15,10 +15,15 @@ contract DeployMolochV3EligibilityAdaptor is BaseDeployer { function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - molochV3EligibilityAdaptor = new MolochV3EligibilityAdaptor(); + address newContractAddress = getDeploymentAddress(type(MolochV3EligibilityAdaptor).creationCode); + + if (!isContract(newContractAddress)) { + molochV3EligibilityAdaptor = new MolochV3EligibilityAdaptor{salt: SALT}(); + assert(address(molochV3EligibilityAdaptor) == newContractAddress); + } vm.stopBroadcast(); - return address(molochV3EligibilityAdaptor); + return newContractAddress; } } diff --git a/scripts/MultiERC6551HatsEligibilityModule.s.sol b/scripts/MultiERC6551HatsEligibilityModule.s.sol index 6d1597e..f6a26e9 100644 --- a/scripts/MultiERC6551HatsEligibilityModule.s.sol +++ b/scripts/MultiERC6551HatsEligibilityModule.s.sol @@ -10,15 +10,23 @@ import "forge-std/StdJson.sol"; contract DeployMultiERC6551HatsEligibilityModule is BaseDeployer { using stdJson for string; - MultiERC6551HatsEligibilityModule public erc6551HatsEligibilityModule; + MultiERC6551HatsEligibilityModule public multiERC6551HatsEligibilityModule; function deploy() internal override returns (address) { vm.startBroadcast(deployerPrivateKey); - erc6551HatsEligibilityModule = new MultiERC6551HatsEligibilityModule(_version); + address newContractAddress = getDeploymentAddress(type(MultiERC6551HatsEligibilityModule).creationCode, abi.encode(_version)); + + bytes memory params = abi.encode(_version); + console2.logBytes32(bytes32(params)); + + if (!isContract(newContractAddress)) { + multiERC6551HatsEligibilityModule = new MultiERC6551HatsEligibilityModule{salt: SALT}(_version); + assert(address(multiERC6551HatsEligibilityModule) == newContractAddress); + } vm.stopBroadcast(); - return address(erc6551HatsEligibilityModule); + return newContractAddress; } } diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 7b1c785..7a7ee72 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -64,13 +64,14 @@ CALLDATA=$(cast calldata "run(string)" $1) CONFIRMATION="n" if [[ $FORCE == false ]]; then - PRIVATE_KEY=$PRIVATE_KEY forge script scripts/$2.s.sol:Deploy$2 -s $CALLDATA --rpc-url $NETWORK + MNEMONIC=$MNEMONIC PRIVATE_KEY=$PRIVATE_KEY forge script scripts/$2.s.sol:Deploy$2 -s $CALLDATA --rpc-url $NETWORK read -p "Please verify the data and confirm the deployment (y/n):" CONFIRMATION fi if [[ $CONFIRMATION == "y" || $CONFIRMATION == "Y" || $FORCE == true ]]; then - FORGE_OUTPUT=$(PRIVATE_KEY=$PRIVATE_KEY forge script scripts/$2.s.sol:Deploy$2 --broadcast -s $CALLDATA --rpc-url $NETWORK) - DEPLOYED_ADDRESS=$(echo "$FORGE_OUTPUT" | grep "Contract Address:" | sed -n 's/.*: \(0x[0-9a-hA-H]\{40\}\)/\1/p') + FORGE_OUTPUT=$(MNEMONIC=$MNEMONIC PRIVATE_KEY=$PRIVATE_KEY forge script scripts/$2.s.sol:Deploy$2 --broadcast -s $CALLDATA --rpc-url $NETWORK) + echo "$FORGE_OUTPUT" + DEPLOYED_ADDRESS=$(echo "$FORGE_OUTPUT" | grep "New Deployment Address:" | sed -n 's/.*: \(0x[0-9a-hA-H]\{40\}\)/\1/p') TX_HASH=$(echo "$FORGE_OUTPUT" | grep "Hash:" | head -1 | sed -n 's/.*: \(0x[0-9a-hA-H]\{64\}\)/\1/p') else echo "Deployment skipped..." @@ -81,6 +82,11 @@ echo "Deployment completed: $DEPLOYED_ADDRESS" echo "Transaction hash: $TX_HASH" echo "" +if [[ $DEPLOYED_ADDRESS == "" || $TX_HASH == "" ]]; then + echo "Deployment failed. Exiting script" + exit 1 +fi + node scripts/helpers/saveAddress.js $1 $2 $DEPLOYED_ADDRESS VERIFY=false @@ -125,14 +131,14 @@ fi if [[ $2 == *"Implementation" ]]; then - forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.20+commit.a1b79de6 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $DEPLOYED_ADDRESS src/implementations/$2.sol:$2 + forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.25+commit.b61c2a91 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $DEPLOYED_ADDRESS src/implementations/$2.sol:$2 elif [[ $2 == *"Adaptor" ]]; then - forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.20+commit.a1b79de6 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $DEPLOYED_ADDRESS src/adaptors/$2.sol:$2 + forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.25+commit.b61c2a91 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $DEPLOYED_ADDRESS src/adaptors/$2.sol:$2 elif [[ $2 == *"EligibilityModule" ]]; then - CONSTRUCTOR_ARGS="0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b76657273696f6e20302e31000000000000000000000000000000000000000000" - forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.20+commit.a1b79de6 --etherscan-api-key $API_KEY --num-of-optimizations 20000 --constructor-args $CONSTRUCTOR_ARGS $DEPLOYED_ADDRESS src/adaptors/hats-modules/$2.sol:$2 + CONSTRUCTOR_ARGS="00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005302e302e31000000000000000000000000000000000000000000000000000000" + forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.25+commit.b61c2a91 --etherscan-api-key $API_KEY --num-of-optimizations 20000 --constructor-args $CONSTRUCTOR_ARGS $DEPLOYED_ADDRESS src/adaptors/hats-modules/$2.sol:$2 else - forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.20+commit.a1b79de6 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $DEPLOYED_ADDRESS src/$2.sol:$2 + forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.25+commit.b61c2a91 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $DEPLOYED_ADDRESS src/$2.sol:$2 fi echo "end verification" diff --git a/scripts/verify.sh b/scripts/verify.sh index fd04c54..cd3dca1 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -73,14 +73,14 @@ if [[ $NETWORK == "gnosis" ]]; then fi if [[ $2 == *"Implementation" ]]; then - forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.20+commit.a1b79de6 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $SAVED_ADDRESS src/implementations/$2.sol:$2 + forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.25+commit.b61c2a91 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $SAVED_ADDRESS src/implementations/$2.sol:$2 elif [[ $2 == *"Adaptor" ]]; then - forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.20+commit.a1b79de6 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $SAVED_ADDRESS src/adaptors/$2.sol:$2 + forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.25+commit.b61c2a91 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $SAVED_ADDRESS src/adaptors/$2.sol:$2 elif [[ $2 == *"EligibilityModule" ]]; then - CONSTRUCTOR_ARGS="0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b76657273696f6e20302e31000000000000000000000000000000000000000000" - forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.20+commit.a1b79de6 --etherscan-api-key $API_KEY --num-of-optimizations 20000 --constructor-args $CONSTRUCTOR_ARGS $SAVED_ADDRESS src/adaptors/hats-modules/$2.sol:$2 + CONSTRUCTOR_ARGS="00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005302e302e31000000000000000000000000000000000000000000000000000000" + forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.25+commit.b61c2a91 --etherscan-api-key $API_KEY --num-of-optimizations 20000 --constructor-args $CONSTRUCTOR_ARGS $SAVED_ADDRESS src/adaptors/hats-modules/$2.sol:$2 else - forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.20+commit.a1b79de6 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $SAVED_ADDRESS src/$2.sol:$2 + forge verify-contract --watch --chain-id $CHAIN_ID --compiler-version v0.8.25+commit.b61c2a91 --etherscan-api-key $API_KEY --num-of-optimizations 20000 $SAVED_ADDRESS src/$2.sol:$2 fi echo "end verification" diff --git a/src/adaptors/HatsAdaptor.sol b/src/adaptors/HatsAdaptor.sol index f84fa60..a9a6b94 100644 --- a/src/adaptors/HatsAdaptor.sol +++ b/src/adaptors/HatsAdaptor.sol @@ -192,11 +192,6 @@ contract HatsAdaptor is Initializable, OwnableUpgradeable, UUPSUpgradeable, ERC1 function addGameMasters(address[] calldata newGameMasters) external onlyAdmin { AllowlistEligibility(gameMasterHatEligibilityModule).addAccounts(newGameMasters); - bool[] memory standings = new bool[](newGameMasters.length); - for (uint256 i; i < newGameMasters.length; i++) { - standings[i] = true; - } - AllowlistEligibility(gameMasterHatEligibilityModule).setStandingForAccounts(newGameMasters, standings); //check eligibility module for emitted event for (uint256 i = 0; i < newGameMasters.length; i++) { _ifNotHatMint(newGameMasters[i], _hatsData.gameMasterHatId); diff --git a/src/mocks/AllowlistHatsEligibilityModule.sol b/src/mocks/AllowlistHatsEligibilityModule.sol index 8108217..90368b3 100644 --- a/src/mocks/AllowlistHatsEligibilityModule.sol +++ b/src/mocks/AllowlistHatsEligibilityModule.sol @@ -27,6 +27,20 @@ error AllowlistEligibility_NotWearer(); * It must be set as the eligibility for {hatId} in order to be used. */ contract AllowlistEligibility is HatsEligibilityModule { + /*////////////////////////////////////////////////////////////// + DATA MODELS + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Eligibility and standing data for an account + * @param eligible Whether the account is eligible to wear the hat. Defaults to not eligible. + * @param badStanding Whether the account is in bad standing for the hat. Defaults to good standing. + */ + struct EligibilityData { + bool eligible; + bool badStanding; + } + /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ @@ -44,20 +58,6 @@ contract AllowlistEligibility is HatsEligibilityModule { /// @notice Emitted when multiple accounts' standing are changed event AccountsStandingChanged(address[] accounts, bool[] standing); - /*////////////////////////////////////////////////////////////// - DATA MODELS - //////////////////////////////////////////////////////////////*/ - - /** - * @notice Eligibility and standing data for an account - * @param eligible Whether the account is eligible to wear the hat. Defaults to not eligible. - * @param badStanding Whether the account is in bad standing for the hat. Defaults to good standing. - */ - struct EligibilityData { - bool eligible; - bool badStanding; - } - /*////////////////////////////////////////////////////////////// CONSTANTS //////////////////////////////////////////////////////////////*/ @@ -87,12 +87,14 @@ contract AllowlistEligibility is HatsEligibilityModule { /// @notice The hat ID for the owner hat. The wearer(s) of this hat are authorized to add and remove accounts from the /// allowlist + // solhint-disable-next-line func-name-mixedcase function OWNER_HAT() public pure returns (uint256) { return _getArgUint256(72); } /// @notice The hat ID for the arbitrator hat. The wearer(s) of this hat are authorized to set the standing for /// accounts. + // solhint-disable-next-line func-name-mixedcase function ARBITRATOR_HAT() public pure returns (uint256) { return _getArgUint256(104); } @@ -106,6 +108,7 @@ contract AllowlistEligibility is HatsEligibilityModule { * @custom:param account The account to get eligibility data for * @custom:return eligibility The eligibility data for the account */ + // solhint-disable-next-line ordering mapping(address account => EligibilityData eligibility) public allowlist; /*////////////////////////////////////////////////////////////// diff --git a/test/CharacterAccount.t.sol b/test/CharacterAccount.t.sol index a7163a8..d3072f4 100644 --- a/test/CharacterAccount.t.sol +++ b/test/CharacterAccount.t.sol @@ -8,7 +8,6 @@ import "forge-std/Test.sol"; import "./setup/SetUp.t.sol"; contract CharacterAccountTest is SetUp { - function testEquipItemToCharacter() public { dao.addMember(accounts.rando); vm.prank(accounts.rando);