HatsIdUtilities.sol
HatsIdUtilities
Inherits: IHatsIdUtilities
Author: Haberdasher Labs
Functions for working with Hat Ids from Hats Protocol. Factored out of Hats.sol for easier use by other contracts.
State Variables
linkedTreeRequests
Mapping of tophats requesting to link to admin hats in other trees
Linkage only occurs if request is approved by the new admin
linkedTreeAdmins
Mapping of approved & linked tophats to admin hats in other trees, used for grafting one hats tree onto another
Trees can only be linked to another tree via their tophat
TOPHAT_ADDRESS_SPACE
Hat Ids serve as addresses. A given Hat's Id represents its location in its hat tree: its level, its admin, its admin's admin (etc, all the way up to the tophat). The top level consists of 4 bytes and references all tophats. Each level below consists of 16 bits, and contains up to 65,536 child hats. A uint256 contains 4 bytes of space for tophat addresses, giving room for ((256 - 32) / 16) = 14 levels of delegation, with the admin at each level having space for 65,536 different child hats. A hat tree consists of a single tophat and has a max depth of 14 levels.
Number of bits of address space for tophat ids, ie the tophat domain
LOWER_LEVEL_ADDRESS_SPACE
Number of bits of address space for each level below the tophat
MAX_LEVELS
Maximum number of levels below the tophat, ie max tree depth (256 - TOPHAT_ADDRESS_SPACE) / LOWER_LEVEL_ADDRESS_SPACE;
Functions
buildHatId
Constructs a valid hat id for a new hat underneath a given admin
Reverts if the admin has already reached MAX_LEVELS
Parameters
Returns
getHatLevel
Identifies the level a given hat in its hat tree
Parameters
Returns
getLocalHatLevel
Identifies the level a given hat in its local hat tree
Similar to getHatLevel, but does not account for linked trees
Parameters
Returns
isTopHat
Checks whether a hat is a topHat
Parameters
Returns
isLocalTopHat
Checks whether a hat is a topHat in its local hat tree
Similar to isTopHat, but does not account for linked trees
Parameters
Returns
isValidHatId
getAdminAtLevel
Gets the hat id of the admin at a given level of a given hat
This function traverses trees by following the linkedTreeAdmin pointer to a hat located in a different tree
Parameters
Returns
getAdminAtLocalLevel
Gets the hat id of the admin at a given level of a given hat local to the tree containing the hat.
Parameters
Returns
getTopHatDomain
Gets the tophat domain of a given hat
A domain is the identifier for a given hat tree, stored in the first 4 bytes of a hat's id
Parameters
Returns
getTippyTopHatDomain
Gets the domain of the highest parent tophat โ the "tippy tophat"
Parameters
Returns
noCircularLinkage
Checks For any circular linkage of trees
Parameters
Returns
sameTippyTopHatDomain
Checks that a tophat domain and its potential linked admin are from the same tree, ie have the same tippy tophat domain
Parameters
Returns
Last updated