Skip to content

Commit

Permalink
updated hats adaptor and tests to use allowlistEligibility module fro…
Browse files Browse the repository at this point in the history
…m hats
  • Loading branch information
MrDeadCe11 committed Apr 11, 2024
1 parent c989dbf commit c4c2c15
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 51 deletions.
16 changes: 8 additions & 8 deletions addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"ClonesAddressStorageImplementation": "0x20C270dD8F5F8A341AA90fB8Eb0B3bc44237cc29"
},
"optimism": {
"chainId": "",
"chainId": "10",
"network": "optimism",
"Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921",
"Dao": "",
Expand Down Expand Up @@ -56,7 +56,7 @@
"ClonesAddressStorageImplementation": ""
},
"base": {
"chainId": "",
"chainId": "8453",
"network": "base",
"Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921",
"Dao": "",
Expand All @@ -70,7 +70,7 @@
"CharacterSheetsLevelEligibilityModule": "",
"AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986",
"ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab",
"ERC6551HatsEligibilityModule": "0x36C55610d6043703bF7Ae29a8aa5768FC4772738",
"ERC6551HatsEligibilityModule": "",
"MultiERC6511HatsEligibilityModule": "",
"ExperienceImplementation": "",
"ItemsManagerImplementation": "",
Expand All @@ -84,7 +84,7 @@
"ClonesAddressStorageImplementation": ""
},
"polygon": {
"chainId": "",
"chainId": "137",
"network": "polygon",
"Erc6551Registry": "0x02101dfB77FDE026414827Fdc604ddAF224F0921",
"Dao": "",
Expand All @@ -98,7 +98,7 @@
"CharacterSheetsLevelEligibilityModule": "",
"AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986",
"ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab",
"ERC6551HatsEligibilityModule": "0x36C55610d6043703bF7Ae29a8aa5768FC4772738",
"ERC6551HatsEligibilityModule": "",
"MultiERC6511HatsEligibilityModule": "",
"ExperienceImplementation": "",
"ItemsManagerImplementation": "",
Expand Down Expand Up @@ -148,8 +148,8 @@
"CharacterSheetsFactory": "",
"CharacterEligibilityAdaptor": "",
"ClassLevelAdaptor": "0xb0eB7213E37307CEAaBcc10E0F224D8982FcA7Ba",
"HatsAdaptor": "0xe984351769199faFb917a3c766676e176A45A579",
"AddressHatsEligibilityModule": "",
"HatsAdaptor": "0xC994B88a04841d8E4BCa7a2320eB1D4ef73c88Cb",
"AddressHatsEligibilityModule": "0x9AaF0df5657b634131784523F4F5e83459c61986",
"ERC721HatsEligibilityModule": "0xF37cf12fB4493D29270806e826fDDf50dd722bab",
"ERC6551HatsEligibilityModule": "0x4f1a5769adE79e9e672454d958a39B9b4FBf1e45",
"MultiERC6511HatsEligibilityModule": "",
Expand Down Expand Up @@ -192,4 +192,4 @@
"ERC6551HatsEligibilityModule": "",
"MultiERC6511HatsEligibilityModule": ""
}
}
}
24 changes: 13 additions & 11 deletions src/adaptors/HatsAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion test/CharacterSheet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
61 changes: 34 additions & 27 deletions test/HatsEligibilityModules.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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();

Expand All @@ -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");
}
Expand All @@ -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");
}
}

Expand Down
11 changes: 9 additions & 2 deletions test/setup/SetUp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions test/setup/helpers/TestStructs.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -94,7 +94,7 @@ interface TestStructs {
ItemsManagerImplementation itemsManager;
ClassesImplementation classes;
ClonesAddressStorageImplementation clonesAddressStorage;
AddressHatsEligibilityModule addressModule;
AllowlistEligibility addressModule;
ERC721HatsEligibilityModule erc721Module;
ERC6551HatsEligibilityModule erc6551Module;
MultiERC6551HatsEligibilityModule multiErc6551Module;
Expand Down

0 comments on commit c4c2c15

Please sign in to comment.