diff --git a/EIPS/eip-998.md b/EIPS/eip-998.md index 25491748..77d7b1a0 100644 --- a/EIPS/eip-998.md +++ b/EIPS/eip-998.md @@ -90,6 +90,32 @@ The rootOwner of a composable is gotten by calling `rootOwnerOf(uint256 _tokenId ERC998ERC721 top-down and bottom-up composables are interoperable with each other. It is possible for a top-down composable to own a bottom-up composable or for a top-down composable to own an ERC721 token that owns a bottom-up token. In any configuration calling `rootOwnerOf(uint256 _tokenID)` on a composable will return the root owner address at the top of the ownership tree. +It is important to get the traversal logic of `rootOwnerOf` right. The logic for `rootOwnerOf` is the same whether or not a composable is bottom-up or top-down or both. +Here is the logic: + +``` +Logic for rootOwnerOf(uint256 _tokenId) + +If the token is a bottom-up composable and has a parent token then call rootOwnerOf for the parent token. + If the call was successful then the returned address is the rootOwner. + Otherwise call rootOwnerOfChild for the parent token. + If the call was successful then the returned address is the rootOwner. + Otherwise get the owner address of the token and that is the rootOwner. +Otherwise call rootOwnerOfChild for the token + If the call was successful then the returned address is the rootOwner. + Otherwise get the owner address of the token and that is the rootOwner. +``` + +Calling `rootOwnerOfChild` for a token means the following logic: +```solidity +// Logic for calling rootOwnerOfChild for a tokenId +address tokenOwner = ownerOf(tokenId); +address childContract = address(this); +bytes32 rootOwner = ERC998ERC721(tokenOwner).rootOwnerOfChild(childContract, tokenId); +``` + +But understand that the real call to `rootOwnerOfChild` should be made with assembly so that the code can check if the call failed and so that the `staticcall` opcode is used to ensure that no state is modified. + Tokens/contracts that implement the above authentication and traversal functionality are "composable aware". ### Composable Transfer Function Parameter Format