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

reimplement createHatsTree #31

Closed
spengrah opened this issue Jul 2, 2022 · 1 comment
Closed

reimplement createHatsTree #31

spengrah opened this issue Jul 2, 2022 · 1 comment
Labels
v1 In-scope for v1 of the protocol

Comments

@spengrah
Copy link
Member

spengrah commented Jul 2, 2022

With addressable ids (#19), hats trees can likely be modeled in a more sophisticated way than previously. This also means that createHatsTree will need to be implemented;

Reference: old approach to createHatsTree:

hats-protocol/src/Hats.sol

Lines 168 to 223 in 8f40b1e

/// @notice Creates a tree new Hats, where the root Hat is under admin control by the msg.sender. Especially useful for forking an existing Hat tree or initiating a template Hat tree structure.
/// @dev The admin for each Hat must exist before the Hat is created, so Hats must be created before Hats for which they serve as admin
/// @param _details Descriptions of the Hats
/// @param _maxSupplies The total instances of the Hats that can be worn at once
/// @param _firstAdmin The hatId of the admin of the first Hat to create; it must already exist
/// @param _adminOffsets The deltas between the ids of the Hats that will control who wears the newly created hat
/// @param _oracles The addresses that can report on the Hat wearers' standings
/// @param _conditions The addresses that can deactivate the Hats
function createHatsTree(
string[] memory _details,
uint32[] memory _maxSupplies,
uint64 _firstAdmin,
uint64[] memory _adminOffsets, // _adminOffsets.length + 1 = _details.length
address[] memory _oracles,
address[] memory _conditions
) public {
// check that array lengths match
uint256 length = _maxSupplies.length; // saves an MLOAD
bool lengthsCheck = ((_details.length == length) &&
(length == _adminOffsets.length + 1) &&
(length == _oracles.length) &&
(length == _conditions.length));
if (!lengthsCheck) {
revert BatchArrayLengthMismatch();
}
// create a new Hat for each qualifying item
for (uint256 i = 0; i < length; ++i) {
// calculate the admin id for this Hat
uint64 admin;
if (i == 0) {
// first Hat created gets the _firstAdmin
admin = _firstAdmin;
} else {
/* subsequent Hats are assigned admins based on an offset.
Example: if nextHatId is 10, and the admin of the next Hat we want to create is id 8, then the offset would be 2.
*/
admin = nextHatId - _adminOffsets[i - 1];
}
/* Only create the new Hat if it would not be a topHat (a Hat that is its own admin) and if the msg.sender serves as its admin, otherwise skip to the next item.
This requires that Hats must be created prior to any Hat(s) they are an admin for.
*/
if ((admin != nextHatId) && isWearerOfHat(msg.sender, admin)) {
_createHat(
_details[i],
_maxSupplies[i],
admin,
_oracles[i],
_conditions[i]
);
}
}
}

@spengrah spengrah mentioned this issue Jul 2, 2022
@spengrah spengrah added the v1 In-scope for v1 of the protocol label Aug 17, 2022
@spengrah
Copy link
Member Author

re-imagined as batchCreateHats in #61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1 In-scope for v1 of the protocol
Projects
None yet
Development

No branches or pull requests

1 participant