Skip to content

Commit

Permalink
Adds methods to get and set attributes metadata for a collection.
Browse files Browse the repository at this point in the history
  • Loading branch information
steven2308 committed Mar 5, 2024
1 parent bdd9ec5 commit 97aedc7
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 10 deletions.
30 changes: 30 additions & 0 deletions contracts/RMRK/extension/tokenAttributes/IERC7508.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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];
}
Expand Down
56 changes: 56 additions & 0 deletions docs/RMRK/extension/tokenAttributes/IERC7508.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 97aedc7

Please sign in to comment.