From c4c2c15ba5398047638cf823c910657a5e873c06 Mon Sep 17 00:00:00 2001 From: MrDeadCe11 Date: Thu, 11 Apr 2024 11:49:51 -0500 Subject: [PATCH] updated hats adaptor and tests to use allowlistEligibility module from hats --- addresses.json | 16 ++++---- src/adaptors/HatsAdaptor.sol | 24 ++++++----- test/CharacterSheet.t.sol | 4 +- test/HatsEligibilityModules.t.sol | 61 ++++++++++++++++------------ test/setup/SetUp.t.sol | 11 ++++- test/setup/helpers/TestStructs.t.sol | 4 +- 6 files changed, 69 insertions(+), 51 deletions(-) diff --git a/addresses.json b/addresses.json index 77859c6..4dd2067 100644 --- a/addresses.json +++ b/addresses.json @@ -28,7 +28,7 @@ "ClonesAddressStorageImplementation": "0x20C270dD8F5F8A341AA90fB8Eb0B3bc44237cc29" }, "optimism": { - "chainId": "", + "chainId": "10", "network": "optimism", "Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921", "Dao": "", @@ -56,7 +56,7 @@ "ClonesAddressStorageImplementation": "" }, "base": { - "chainId": "", + "chainId": "8453", "network": "base", "Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921", "Dao": "", @@ -70,7 +70,7 @@ "CharacterSheetsLevelEligibilityModule": "", "AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986", "ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab", - "ERC6551HatsEligibilityModule": "0x36C55610d6043703bF7Ae29a8aa5768FC4772738", + "ERC6551HatsEligibilityModule": "", "MultiERC6511HatsEligibilityModule": "", "ExperienceImplementation": "", "ItemsManagerImplementation": "", @@ -84,7 +84,7 @@ "ClonesAddressStorageImplementation": "" }, "polygon": { - "chainId": "", + "chainId": "137", "network": "polygon", "Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921", "Dao": "", @@ -98,7 +98,7 @@ "CharacterSheetsLevelEligibilityModule": "", "AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986", "ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab", - "ERC6551HatsEligibilityModule": "0x36C55610d6043703bF7Ae29a8aa5768FC4772738", + "ERC6551HatsEligibilityModule": "", "MultiERC6511HatsEligibilityModule": "", "ExperienceImplementation": "", "ItemsManagerImplementation": "", @@ -148,8 +148,8 @@ "CharacterSheetsFactory": "", "CharacterEligibilityAdaptor": "", "ClassLevelAdaptor": "0xb0eB7213E37307CEAaBcc10E0F224D8982FcA7Ba", - "HatsAdaptor": "0xe984351769199faFb917a3c766676e176A45A579", - "AddressHatsEligibilityModule": "", + "HatsAdaptor": "0xC994B88a04841d8E4BCa7a2320eB1D4ef73c88Cb", + "AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986", "ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab", "ERC6551HatsEligibilityModule": "0x4f1a5769adE79e9e672454d958a39B9b4FBf1e45", "MultiERC6511HatsEligibilityModule": "", @@ -192,4 +192,4 @@ "ERC6551HatsEligibilityModule": "", "MultiERC6511HatsEligibilityModule": "" } -} \ No newline at end of file +} diff --git a/src/adaptors/HatsAdaptor.sol b/src/adaptors/HatsAdaptor.sol index 967772f..fb60ee6 100644 --- a/src/adaptors/HatsAdaptor.sol +++ b/src/adaptors/HatsAdaptor.sol @@ -8,7 +8,6 @@ import {IHats} from "hats-protocol/Interfaces/IHats.sol"; import {ERC1155HolderUpgradeable} from "openzeppelin-contracts-upgradeable/token/ERC1155/utils/ERC1155HolderUpgradeable.sol"; import {IHatsEligibility} from "hats-protocol/Interfaces/IHatsEligibility.sol"; -import {IAddressEligibilityModule} from "../interfaces/IAddressEligibilityModule.sol"; import {HatsModuleFactory} from "hats-module/HatsModuleFactory.sol"; import {ImplementationAddressStorage} from "../ImplementationAddressStorage.sol"; import {IClonesAddressStorage} from "../interfaces/IClonesAddressStorage.sol"; @@ -146,21 +145,21 @@ contract HatsAdaptor is Initializable, OwnableUpgradeable, UUPSUpgradeable, ERC1 /// @notice the following update functions will use the base implementation addresses stored in the implementationAddressStorage contract. - function updateAdminEligibilityModule(uint256 adminId, bytes calldata encodedAdmins, address adminImplementation) + function updateAdminEligibilityModule(uint256 adminId, uint256 arbitratorHatId, address adminImplementation) external onlyOwner { - adminHatEligibilityModule = _createAllowlistHatEligibilityModule(adminId, encodedAdmins, adminImplementation); + adminHatEligibilityModule = _createAllowlistHatEligibilityModule(adminId, arbitratorHatId, adminImplementation); emit AdminEligibilityModuleUpdated(adminHatEligibilityModule); } function updateGameMasterHatEligibilityModule( - uint256 gameMasterId, - bytes calldata gameMasters, + uint256 gameMasterHatId, + uint256 arbitratorHatId, address dmImplementation ) external onlyOwner { gameMasterHatEligibilityModule = - _createGameMasterHatEligibilityModule(gameMasterId, gameMasters, dmImplementation); + _createAllowlistHatEligibilityModule(gameMasterHatId, arbitratorHatId, dmImplementation); emit GameMasterHatEligibilityModuleUpdated(gameMasterHatEligibilityModule); } @@ -189,7 +188,12 @@ contract HatsAdaptor is Initializable, OwnableUpgradeable, UUPSUpgradeable, ERC1 } function addGameMasters(address[] calldata newGameMasters) external onlyAdmin { - IAddressEligibilityModule(gameMasterHatEligibilityModule).addEligibleAddresses(newGameMasters); + 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); @@ -419,7 +423,7 @@ contract HatsAdaptor is Initializable, OwnableUpgradeable, UUPSUpgradeable, ERC1 private returns (address) { - bytes memory encodedAllowlistData = abi.encodePacked(adminId, arbitratorId); + bytes memory encodedAllowlistData = abi.encodePacked(arbitratorId, arbitratorId); customAdminModule = customAdminModule == address(0) ? implementations.addressHatsEligibilityModule() : customAdminModule; @@ -452,11 +456,9 @@ contract HatsAdaptor is Initializable, OwnableUpgradeable, UUPSUpgradeable, ERC1 // predict gameMaster hat ID. gameMasterId = _hats.getNextId(_hatsData.adminHatId); - // encode game masters array for module creation - bytes memory encodedGameMasters = abi.encode(gameMasters); // create gameMaster hat Eligibility module gameMasterHatEligibilityModule = - _createAllowlistHatEligibilityModule(gameMasterId, _hatsData.adminHatId, customModuleImplementations); + _createAllowlistHatEligibilityModule(gameMasterId, _hatsData.adminHatId, customDmModule); // create gameMaster hat with eligibility module _hatsData.gameMasterHatId = _hats.createHat( diff --git a/test/CharacterSheet.t.sol b/test/CharacterSheet.t.sol index a9f0d43..dface64 100644 --- a/test/CharacterSheet.t.sol +++ b/test/CharacterSheet.t.sol @@ -262,7 +262,9 @@ contract CharacterSheetsTest is SetUp { vm.startPrank(accounts.admin); //admin adds player1 to eligible addresses array in admins module. - AddressHatsEligibilityModule(dungHatElig).addEligibleAddresses(newAdmins); + AllowlistEligibility(dungHatElig).addAccounts(newAdmins); + bool[] memory standings = _createStandings(newAdmins.length); + AllowlistEligibility(dungHatElig).setStandingForAccounts(newAdmins, standings); // admin mints dmHat to player1 hatsContracts.hats.mintHat(hatsData.gameMasterHatId, accounts.player1); diff --git a/test/HatsEligibilityModules.t.sol b/test/HatsEligibilityModules.t.sol index ca557f5..c25c8eb 100644 --- a/test/HatsEligibilityModules.t.sol +++ b/test/HatsEligibilityModules.t.sol @@ -16,6 +16,7 @@ import {Hats} from "hats-protocol/Hats.sol"; // hats eligibility modules import {AddressHatsEligibilityModule} from "../src/mocks/AddressHatsEligibilityModule.sol"; +import {AllowlistEligibility} from "../src/mocks/AllowlistHatsEligibilityModule.sol"; import {ERC721HatsEligibilityModule} from "../src/mocks/ERC721HatsEligibilityModule.sol"; import {ERC6551HatsEligibilityModule} from "../src/adaptors/hats-modules/ERC6551HatsEligibilityModule.sol"; import {MultiERC6551HatsEligibilityModule} from "../src/adaptors/hats-modules/MultiERC6551HatsEligibilityModule.sol"; @@ -27,8 +28,8 @@ import {IMultiERC6551HatsEligibilityModule} from "../src/interfaces/IMultiERC655 contract Base is SetUp { HatsAdaptor public newAdaptor; - AddressHatsEligibilityModule public adminModule; - AddressHatsEligibilityModule public dmModule; + AllowlistEligibility public adminModule; + AllowlistEligibility public dmModule; ERC721HatsEligibilityModule public playerModule; ERC6551HatsEligibilityModule public characterModule; CharacterSheetsLevelEligibilityModule public elderModule; @@ -74,8 +75,8 @@ contract Base is SetUp { newAdaptor.initialize(topHatWearer, encodedHatsAddresses, encodedHatsStrings, customModuleAddresses); - adminModule = AddressHatsEligibilityModule(newAdaptor.adminHatEligibilityModule()); - dmModule = AddressHatsEligibilityModule(newAdaptor.gameMasterHatEligibilityModule()); + adminModule = AllowlistEligibility(newAdaptor.adminHatEligibilityModule()); + dmModule = AllowlistEligibility(newAdaptor.gameMasterHatEligibilityModule()); characterModule = ERC6551HatsEligibilityModule(newAdaptor.characterHatEligibilityModule()); playerModule = ERC721HatsEligibilityModule(newAdaptor.playerHatEligibilityModule()); @@ -108,13 +109,15 @@ contract Test_AdminEligibilityModule is Base { testAdmins[0] = dmHatWearer; //should revert if called by wrong EOA - vm.prank(address(420)); + vm.startPrank(address(420)); vm.expectRevert(); - adminModule.addEligibleAddresses(testAdmins); - + bool[] memory standings = _createStandings(testAdmins.length); + adminModule.addAccounts(testAdmins); + vm.stopPrank(); //should succeed if called by topHatWearer; vm.startPrank(topHatWearer); - adminModule.addEligibleAddresses(testAdmins); + adminModule.addAccounts(testAdmins); + adminModule.setStandingForAccounts(testAdmins, standings); hatsContracts.hats.mintHat(newAdminHatId, dmHatWearer); vm.stopPrank(); @@ -127,18 +130,20 @@ contract Test_AdminEligibilityModule is Base { //add new admin vm.startPrank(topHatWearer); - adminModule.addEligibleAddresses(testAdmins); + bool[] memory standings = _createStandings(testAdmins.length); + adminModule.addAccounts(testAdmins); + adminModule.setStandingForAccounts(testAdmins, standings); hatsContracts.hats.mintHat(newAdminHatId, dmHatWearer); vm.stopPrank(); //should revert if called by wrong EOA vm.expectRevert(); vm.prank(adminHatWearer); - adminModule.removeEligibleAddresses(testAdmins); + adminModule.removeAccounts(testAdmins); //should succeed if called by top hat wearer; vm.prank(topHatWearer); - adminModule.removeEligibleAddresses(testAdmins); + adminModule.removeAccounts(testAdmins); assertEq(newAdaptor.isAdmin(dmHatWearer), false, "admin hat not removed"); } @@ -159,42 +164,44 @@ contract Test_GameMasterEligibilityModule is Base { function testAddNewGameMaster() public { address[] memory testAdmins = new address[](1); - testAdmins[0] = adminHatWearer; + testAdmins[0] = address(420); //should revert if called by wrong EOA - vm.prank(address(420)); + vm.startPrank(address(420)); vm.expectRevert(); - dmModule.addEligibleAddresses(testAdmins); - + dmModule.addAccounts(testAdmins); + vm.stopPrank(); //should succeed if called by topHatWearer; - vm.startPrank(topHatWearer); - dmModule.addEligibleAddresses(testAdmins); - hatsContracts.hats.mintHat(newGameMasterHatId, adminHatWearer); + bool[] memory standings = _createStandings(testAdmins.length); + vm.startPrank(adminHatWearer); + dmModule.addAccounts(testAdmins); + dmModule.setStandingForAccounts(testAdmins, standings); + hatsContracts.hats.mintHat(newGameMasterHatId, testAdmins[0]); vm.stopPrank(); - assertEq(newAdaptor.isAdmin(adminHatWearer), true, "new admin not assigned"); + assertEq(newAdaptor.isGameMaster(testAdmins[0]), true, "new admin not assigned"); } function testRemoveGameMaster() public { address[] memory testAdmins = new address[](1); - testAdmins[0] = adminHatWearer; + testAdmins[0] = address(420); - //add new admin - vm.startPrank(topHatWearer); - dmModule.addEligibleAddresses(testAdmins); - hatsContracts.hats.mintHat(newGameMasterHatId, adminHatWearer); + vm.startPrank(adminHatWearer); + bool[] memory standings = _createStandings(testAdmins.length); + dmModule.addAccounts(testAdmins); + dmModule.setStandingForAccounts(testAdmins, standings); vm.stopPrank(); //should revert if called by wrong EOA vm.expectRevert(); vm.prank(dmHatWearer); - dmModule.removeEligibleAddresses(testAdmins); + dmModule.removeAccounts(testAdmins); //should succeed if called by admin hat wearer; vm.prank(adminHatWearer); - dmModule.removeEligibleAddresses(testAdmins); + dmModule.removeAccounts(testAdmins); - assertEq(newAdaptor.isGameMaster(adminHatWearer), false, "admin hat not removed"); + assertEq(newAdaptor.isGameMaster(testAdmins[0]), false, "admin hat not removed"); } } diff --git a/test/setup/SetUp.t.sol b/test/setup/SetUp.t.sol index ec3def5..ce0dc26 100644 --- a/test/setup/SetUp.t.sol +++ b/test/setup/SetUp.t.sol @@ -48,7 +48,7 @@ import {HatsModuleFactory} from "hats-module/HatsModuleFactory.sol"; import {Hats} from "hats-protocol/Hats.sol"; // hats eligibility modules -import {AddressHatsEligibilityModule} from "../../src/mocks/AddressHatsEligibilityModule.sol"; +import {AllowlistEligibility} from "../../src/mocks/AllowlistHatsEligibilityModule.sol"; import {ERC721HatsEligibilityModule} from "../../src/mocks/ERC721HatsEligibilityModule.sol"; import {ERC6551HatsEligibilityModule} from "../../src/adaptors/hats-modules/ERC6551HatsEligibilityModule.sol"; import {MultiERC6551HatsEligibilityModule} from "../../src/adaptors/hats-modules/MultiERC6551HatsEligibilityModule.sol"; @@ -274,7 +274,7 @@ contract SetUp is Test, Accounts, TestStructs { adaptors.molochV3EligibilityAdaptor = new MolochV3EligibilityAdaptor(); adaptors.classLevelAdaptor = new ClassLevelAdaptor(); adaptors.hatsAdaptor = new HatsAdaptor(); - implementations.addressModule = new AddressHatsEligibilityModule("v 0.1"); + implementations.addressModule = new AllowlistEligibility("v 0.1"); implementations.erc721Module = new ERC721HatsEligibilityModule("v 0.1"); implementations.erc6551Module = new ERC6551HatsEligibilityModule("v 0.1"); implementations.multiErc6551Module = new MultiERC6551HatsEligibilityModule("v 0.1"); @@ -566,4 +566,11 @@ contract SetUp is Test, Accounts, TestStructs { return claimableItemId; } + + function _createStandings(uint256 _length) internal returns (bool[] memory standings) { + standings = new bool[](_length); + for (uint256 i; i < _length; i++) { + standings[i] = true; + } + } } diff --git a/test/setup/helpers/TestStructs.t.sol b/test/setup/helpers/TestStructs.t.sol index d32a954..8292503 100644 --- a/test/setup/helpers/TestStructs.t.sol +++ b/test/setup/helpers/TestStructs.t.sol @@ -34,7 +34,7 @@ import {Hats} from "hats-protocol/Hats.sol"; // hats eligibility modules // hats eligibility modules -import {AddressHatsEligibilityModule} from "../../../src/mocks/AddressHatsEligibilityModule.sol"; +import {AllowlistEligibility} from "../../../src/mocks/AllowlistHatsEligibilityModule.sol"; import {ERC721HatsEligibilityModule} from "../../../src/mocks/ERC721HatsEligibilityModule.sol"; import {ERC6551HatsEligibilityModule} from "../../../src/adaptors/hats-modules/ERC6551HatsEligibilityModule.sol"; import {MultiERC6551HatsEligibilityModule} from @@ -94,7 +94,7 @@ interface TestStructs { ItemsManagerImplementation itemsManager; ClassesImplementation classes; ClonesAddressStorageImplementation clonesAddressStorage; - AddressHatsEligibilityModule addressModule; + AllowlistEligibility addressModule; ERC721HatsEligibilityModule erc721Module; ERC6551HatsEligibilityModule erc6551Module; MultiERC6551HatsEligibilityModule multiErc6551Module;