From 7c9d05d11852f22cd863096a684f7a2a71151683 Mon Sep 17 00:00:00 2001 From: steven2308 Date: Tue, 5 Mar 2024 15:27:42 -0500 Subject: [PATCH] Adds methods to get and set attributes metadata for a collection. --- .../extension/tokenAttributes/IERC7508.sol | 30 ++++++++++ .../RMRKTokenAttributesRepository.sol | 41 +++++++++++--- .../extension/tokenAttributes/IERC7508.md | 56 +++++++++++++++++++ .../RMRKTokenAttributesRepository.md | 56 +++++++++++++++++++ test/interfaces.ts | 2 +- 5 files changed, 175 insertions(+), 10 deletions(-) diff --git a/contracts/RMRK/extension/tokenAttributes/IERC7508.sol b/contracts/RMRK/extension/tokenAttributes/IERC7508.sol index d709991b..dc0dcc12 100644 --- a/contracts/RMRK/extension/tokenAttributes/IERC7508.sol +++ b/contracts/RMRK/extension/tokenAttributes/IERC7508.sol @@ -105,6 +105,16 @@ interface IERC7508 is IERC165 { address specificAddress ); + /** + * @notice Used to notify listeners that the metadata URI for a collection has been updated. + * @param collection Address of the collection + * @param attributesMetadataURI The new attributes metadata URI + */ + event MetadataURIUpdated( + address indexed collection, + string attributesMetadataURI + ); + /** * @notice Used to notify listeners that a new collaborator has been added or removed. * @param collection Address of the collection @@ -244,6 +254,26 @@ interface IERC7508 is IERC165 { bool[] memory collaboratorAddressAccess ) external; + /** + * @notice Used to retrieve the attributes metadata URI for a collection, which contains all the information about the collection attributes. + * @param collection Address of the collection + * @return attributesMetadataURI The URI of the attributes metadata + */ + function getAttributesMetadataURI( + address collection + ) external view returns (string memory attributesMetadataURI); + + /** + * @notice Used to set the metadata URI for a collection, which contains all the information about the collection attributes. + * @dev Emits a {MetadataURIUpdated} event. + * @param collection Address of the collection + * @param attributesMetadataURI The URI of the attributes metadata + */ + function setAttributesMetadataURI( + address collection, + string memory attributesMetadataURI + ) external; + /** * @notice Used to set a number attribute. * @dev Emits a {UintAttributeUpdated} event. diff --git a/contracts/RMRK/extension/tokenAttributes/RMRKTokenAttributesRepository.sol b/contracts/RMRK/extension/tokenAttributes/RMRKTokenAttributesRepository.sol index fe3d4ab5..f1711765 100644 --- a/contracts/RMRK/extension/tokenAttributes/RMRKTokenAttributesRepository.sol +++ b/contracts/RMRK/extension/tokenAttributes/RMRKTokenAttributesRepository.sol @@ -44,19 +44,22 @@ contract RMRKTokenAttributesRepository is IERC7508, Context { "setAddressAttribute(address collection,uint256 tokenId,string memory key,address value)" ); - mapping(address collection => mapping(uint256 => AccessType)) + mapping(address collection => mapping(uint256 parameterId => AccessType accessType)) private _parameterAccessType; - mapping(address collection => mapping(uint256 => address)) + mapping(address collection => mapping(uint256 parameterId => address specificAddress)) private _parameterSpecificAddress; - mapping(address collection => IssuerSetting) private _issuerSettings; - mapping(address collection => mapping(address collaborator => bool)) + mapping(address collection => IssuerSetting setting) + private _issuerSettings; + mapping(address collection => mapping(address collaborator => bool isCollaborator)) private _collaborators; // For keys, we use a mapping from strings to IDs. // The purpose is to store unique string keys only once, since they are more expensive. - mapping(string => uint256) private _keysToIds; - uint256 private _totalAttributes; + mapping(string key => uint256 id) private _keysToIds; + uint256 private _nextKeyId; + mapping(address collection => string attributesMetadataURI) + private _attributesMetadataURIs; mapping(address collection => mapping(uint256 => mapping(uint256 => address))) private _addressValues; mapping(address collection => mapping(uint256 => mapping(uint256 => bytes))) @@ -177,6 +180,26 @@ contract RMRKTokenAttributesRepository is IERC7508, Context { } } + /** + * @inheritdoc IERC7508 + */ + function getAttributesMetadataURI( + address collection + ) external view returns (string memory attributesMetadataURI) { + attributesMetadataURI = _attributesMetadataURIs[collection]; + } + + /** + * @inheritdoc IERC7508 + */ + function setAttributesMetadataURI( + address collection, + string memory attributesMetadataURI + ) external onlyIssuer(collection) { + _attributesMetadataURIs[collection] = attributesMetadataURI; + emit MetadataURIUpdated(collection, attributesMetadataURI); + } + /** * @inheritdoc IERC7508 */ @@ -1287,9 +1310,9 @@ contract RMRKTokenAttributesRepository is IERC7508, Context { */ function _getIdForKey(string memory key) internal returns (uint256 keyID) { if (_keysToIds[key] == 0) { - _totalAttributes++; - _keysToIds[key] = _totalAttributes; - keyID = _totalAttributes; + _nextKeyId++; + _keysToIds[key] = _nextKeyId; + keyID = _nextKeyId; } else { keyID = _keysToIds[key]; } diff --git a/docs/RMRK/extension/tokenAttributes/IERC7508.md b/docs/RMRK/extension/tokenAttributes/IERC7508.md index df3e0435..28ee97a7 100644 --- a/docs/RMRK/extension/tokenAttributes/IERC7508.md +++ b/docs/RMRK/extension/tokenAttributes/IERC7508.md @@ -90,6 +90,28 @@ Used to retrieve multiple token attributes of any type at once. | addressAttributes | address[] | An array of addresses, in the same order as the addressKeys | | bytesAttributes | bytes[] | An array of bytes, in the same order as the bytesKeys | +### getAttributesMetadataURI + +```solidity +function getAttributesMetadataURI(address collection) external view returns (string attributesMetadataURI) +``` + +Used to retrieve the attributes metadata URI for a collection, which contains all the information about the collection attributes. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| collection | address | Address of the collection | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| attributesMetadataURI | string | The URI of the attributes metadata | + ### getBoolAttribute ```solidity @@ -693,6 +715,23 @@ function setAttributes(address collection, uint256 tokenId, IERC7508.StringAttri | addressAttributes | IERC7508.AddressAttribute[] | undefined | | bytesAttributes | IERC7508.BytesAttribute[] | undefined | +### setAttributesMetadataURI + +```solidity +function setAttributesMetadataURI(address collection, string attributesMetadataURI) external nonpayable +``` + +Used to set the metadata URI for a collection, which contains all the information about the collection attributes. + +*Emits a {MetadataURIUpdated} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| collection | address | Address of the collection | +| attributesMetadataURI | string | The URI of the attributes metadata | + ### setBoolAttribute ```solidity @@ -980,6 +1019,23 @@ Used to notify listeners that a new collaborator has been added or removed. | collaborator `indexed` | address | Address of the collaborator | | isCollaborator | bool | A boolean value indicating whether the collaborator has been added (`true`) or removed (`false`) | +### MetadataURIUpdated + +```solidity +event MetadataURIUpdated(address indexed collection, string attributesMetadataURI) +``` + +Used to notify listeners that the metadata URI for a collection has been updated. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| collection `indexed` | address | Address of the collection | +| attributesMetadataURI | string | The new attributes metadata URI | + ### StringAttributeUpdated ```solidity diff --git a/docs/RMRK/extension/tokenAttributes/RMRKTokenAttributesRepository.md b/docs/RMRK/extension/tokenAttributes/RMRKTokenAttributesRepository.md index 884f3cac..352f69a3 100644 --- a/docs/RMRK/extension/tokenAttributes/RMRKTokenAttributesRepository.md +++ b/docs/RMRK/extension/tokenAttributes/RMRKTokenAttributesRepository.md @@ -192,6 +192,28 @@ Used to retrieve multiple token attributes of any type at once. | addressAttributes | address[] | An array of addresses, in the same order as the addressKeys | | bytesAttributes | bytes[] | An array of bytes, in the same order as the bytesKeys | +### getAttributesMetadataURI + +```solidity +function getAttributesMetadataURI(address collection) external view returns (string attributesMetadataURI) +``` + +Used to retrieve the attributes metadata URI for a collection, which contains all the information about the collection attributes. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| collection | address | Address of the collection | + +#### Returns + +| Name | Type | Description | +|---|---|---| +| attributesMetadataURI | string | The URI of the attributes metadata | + ### getBoolAttribute ```solidity @@ -795,6 +817,23 @@ function setAttributes(address collection, uint256 tokenId, IERC7508.StringAttri | addressAttributes | IERC7508.AddressAttribute[] | undefined | | bytesAttributes | IERC7508.BytesAttribute[] | undefined | +### setAttributesMetadataURI + +```solidity +function setAttributesMetadataURI(address collection, string attributesMetadataURI) external nonpayable +``` + +Used to set the metadata URI for a collection, which contains all the information about the collection attributes. + +*Emits a {MetadataURIUpdated} event.* + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| collection | address | Address of the collection | +| attributesMetadataURI | string | The URI of the attributes metadata | + ### setBoolAttribute ```solidity @@ -1082,6 +1121,23 @@ Used to notify listeners that a new collaborator has been added or removed. | collaborator `indexed` | address | Address of the collaborator | | isCollaborator | bool | A boolean value indicating whether the collaborator has been added (`true`) or removed (`false`) | +### MetadataURIUpdated + +```solidity +event MetadataURIUpdated(address indexed collection, string attributesMetadataURI) +``` + +Used to notify listeners that the metadata URI for a collection has been updated. + + + +#### Parameters + +| Name | Type | Description | +|---|---|---| +| collection `indexed` | address | Address of the collection | +| attributesMetadataURI | string | The new attributes metadata URI | + ### StringAttributeUpdated ```solidity diff --git a/test/interfaces.ts b/test/interfaces.ts index dd0aaf6e..aab29664 100644 --- a/test/interfaces.ts +++ b/test/interfaces.ts @@ -7,7 +7,7 @@ export const IERC6220 = '0x28bc9ae4'; // Equippable and Composable export const IERC6454 = '0x91a6262f'; // Soulbound export const IERC7401 = '0x42b0e56f'; // Nestable export const IERC7409 = '0x1b3327ab'; // Emotes Repository -export const IERC7508 = '0x9f89917b'; // Attributes Repository +export const IERC7508 = '0x62ee8e7a'; // Attributes Repository export const IERC7590 = '0x6f87c75c'; // ERC20 Token Holder export const IOtherInterface = '0xffffffff'; export const IRMRKCatalog = '0xd912401f'; // ERC6220