Skip to content

Commit

Permalink
refactor!: change set/get TokenId function name in LSP8 and `LSP8Toke…
Browse files Browse the repository at this point in the history
…nIdSchema` to `LSP8TokenIdFormat` (#822)

* refactor!: change lsp8TokenIdSchema to lsp8TokenIdFormat

* refactor!: rename setData and getData tokenId functions

* refactor!: change lsp8 interfaceId

* docs: generate docs

* chore: resolver linter problem

* chore: fix natspec comment

* chore: make params names plural for LSP8 get/setDataBatch functions

* refactor!: rename constant `LSP8_TOKENID_FORMAT`

* chore: move view `getDataForTokenId` functions before state changing functions

* refactor!: increase minimum pragma solc for remaining LSP8 contracts

---------

Co-authored-by: CJ42 <cavallerajean@gmail.com>
Co-authored-by: Jean Cvllr <31145285+CJ42@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 6, 2023
1 parent e8b20c1 commit 2bf84f6
Show file tree
Hide file tree
Showing 64 changed files with 807 additions and 812 deletions.
12 changes: 6 additions & 6 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const INTERFACE_IDS = {
LSP1UniversalReceiverDelegate: '0xa245bbda',
LSP6KeyManager: '0x23f34c62',
LSP7DigitalAsset: '0xb3c4928f',
LSP8IdentifiableDigitalAsset: '0xecad9f75',
LSP8IdentifiableDigitalAsset: '0x3a271706',
LSP9Vault: '0x28af17e6',
LSP11BasicSocialRecovery: '0x049a28f1',
LSP14Ownable2Step: '0x94be5999',
Expand Down Expand Up @@ -236,7 +236,7 @@ export const ERC725YDataKeys = {
'AddressPermissions:AllowedCalls': '0x4b80742de2bf393a64c70000',
},
LSP8: {
LSP8TokenIdSchema: '0x341bc44e55234544c70af9d37b2cb8cc7ba74685b58526221de2cc977f469924',
LSP8TokenIdFormat: '0xf675e9361af1c1664c1868cfa3eb97672d6b1a513aa5b81dec34c9ee330e818d',
LSP8TokenMetadataBaseURI: '0x1a7628600c3bac7101f53697f48df381ddc36b9015e7d7c9c5633d1252aa2843',
LSP8ReferenceContract: '0x708e7b881795f2e6b6c2752108c177ec89248458de3bf69d0d43480b3e5034e6',
},
Expand Down Expand Up @@ -396,7 +396,7 @@ export const LSP1_TYPE_IDS = {
// ----------

/**
* @dev list of LSP4 Token types to describe the type of token a digital asset contract represents.
* @dev List of LSP4 Token types to describe the type of token a digital asset contract represents.
* @see for details see: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-4-DigitalAsset-Metadata.md#lsp4tokentype
*/
export const LSP4_TOKEN_TYPES = {
Expand All @@ -409,10 +409,10 @@ export const LSP4_TOKEN_TYPES = {
// ----------

/**
* @dev list of LSP8 Token ID Schemas that can be used to create different types of NFTs and represent each NFT identifiers differently.
* @see for details see: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-8-IdentifiableDigitalAsset.md#lsp8tokenidschema
* @dev List of LSP8 Token ID Formats that can be used to create different types of NFTs and represent each NFT identifiers (= tokenIds) differently.
* @see For details see: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-8-IdentifiableDigitalAsset.md#lsp8tokenidformat
*/
export const LSP8_TOKEN_ID_SCHEMA = {
export const LSP8_TOKEN_ID_FORMAT = {
NUMBER: 0,
STRING: 1,
ADDRESS: 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.4;

// interfaces
Expand Down Expand Up @@ -114,54 +113,54 @@ interface ILSP8IdentifiableDigitalAsset is IERC165, IERC725Y {

// --- TokenId Metadata functionality

/**
* @notice Retrieves data for a specific `tokenId` and `dataKey`.
* @param tokenId The unique identifier for a token.
* @param dataKey The key for the data to retrieve.
* @return dataValues The data value associated with the given `tokenId` and `dataKey`.
*/
function getDataForTokenId(
bytes32 tokenId,
bytes32 dataKey
) external returns (bytes memory dataValues);

/**
* @notice Retrieves data in batch for multiple `tokenId` and `dataKey` pairs.
* @param tokenIds An array of token IDs.
* @param dataKeys An array of data keys corresponding to the token IDs.
* @return dataValues An array of data values for each pair of `tokenId` and `dataKey`.
*/
function getDataBatchForTokenIds(
bytes32[] memory tokenIds,
bytes32[] memory dataKeys
) external returns (bytes[] memory dataValues);

/**
* @notice Sets data for a specific `tokenId` and `dataKey`.
* @param tokenId The unique identifier for a token.
* @param dataKey The key for the data to set.
* @param dataValue The value to set for the given data key.
* @custom:events {TokenIdDataChanged} event.
*/
function setTokenIdData(
function setDataForTokenId(
bytes32 tokenId,
bytes32 dataKey,
bytes memory dataValue
) external;

/**
* @notice Sets data in batch for multiple `tokenId` and `dataKey` pairs.
* @param tokenId An array of token IDs.
* @param dataKey An array of data keys corresponding to the token IDs.
* @param dataValue An array of values to set for the given data keys.
* @param tokenIds An array of token IDs.
* @param dataKeys An array of data keys corresponding to the token IDs.
* @param dataValues An array of values to set for the given data keys.
* @custom:events {TokenIdDataChanged} event for each pair.
*/
function setTokenIdDataBatch(
bytes32[] memory tokenId,
bytes32[] memory dataKey,
bytes[] memory dataValue
function setDataBatchForTokenIds(
bytes32[] memory tokenIds,
bytes32[] memory dataKeys,
bytes[] memory dataValues
) external;

/**
* @notice Retrieves data for a specific `tokenId` and `dataKey`.
* @param tokenId The unique identifier for a token.
* @param dataKey The key for the data to retrieve.
* @return dataValues The data value associated with the given `tokenId` and `dataKey`.
*/
function getTokenIdData(
bytes32 tokenId,
bytes32 dataKey
) external returns (bytes memory dataValues);

/**
* @notice Retrieves data in batch for multiple `tokenId` and `dataKey` pairs.
* @param tokenId An array of token IDs.
* @param dataKey An array of data keys corresponding to the token IDs.
* @return dataValues An array of data values for each pair of `tokenId` and `dataKey`.
*/
function getTokenIdDataBatch(
bytes32[] memory tokenId,
bytes32[] memory dataKey
) external returns (bytes[] memory dataValues);

// --- Operator functionality

/**
Expand Down
28 changes: 14 additions & 14 deletions contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
pragma solidity ^0.8.4;

// --- ERC165 interface ids
bytes4 constant _INTERFACEID_LSP8 = 0xecad9f75;
bytes4 constant _INTERFACEID_LSP8 = 0x3a271706;

// --- ERC725Y Data Keys

// keccak256('LSP8TokenIdSchema')
bytes32 constant _LSP8_TOKENID_SCHEMA_KEY = 0x341bc44e55234544c70af9d37b2cb8cc7ba74685b58526221de2cc977f469924;
// keccak256('LSP8TokenIdFormat')
bytes32 constant _LSP8_TOKENID_FORMAT_KEY = 0xf675e9361af1c1664c1868cfa3eb97672d6b1a513aa5b81dec34c9ee330e818d;

// keccak256('LSP8TokenMetadataBaseURI')
bytes32 constant _LSP8_TOKEN_METADATA_BASE_URI = 0x1a7628600c3bac7101f53697f48df381ddc36b9015e7d7c9c5633d1252aa2843;
Expand All @@ -26,16 +26,16 @@ bytes32 constant _TYPEID_LSP8_TOKENSRECIPIENT = 0x0b084a55ebf70fd3c06fd755269dac
// keccak256('LSP8Tokens_OperatorNotification')
bytes32 constant _TYPEID_LSP8_TOKENOPERATOR = 0x8a1c15a8799f71b547e08e2bcb2e85257e81b0a07eee2ce6712549eef1f00970;

// --- Token IDs Schema
// --- Token IDs Format

uint256 constant _LSP8_TOKENID_SCHEMA_NUMBER = 0;
uint256 constant _LSP8_TOKENID_SCHEMA_STRING = 1;
uint256 constant _LSP8_TOKENID_SCHEMA_ADDRESS = 2;
uint256 constant _LSP8_TOKENID_SCHEMA_UNIQUE_ID = 3;
uint256 constant _LSP8_TOKENID_SCHEMA_HASH = 4;
uint256 constant _LSP8_TOKENID_FORMAT_NUMBER = 0;
uint256 constant _LSP8_TOKENID_FORMAT_STRING = 1;
uint256 constant _LSP8_TOKENID_FORMAT_ADDRESS = 2;
uint256 constant _LSP8_TOKENID_FORMAT_UNIQUE_ID = 3;
uint256 constant _LSP8_TOKENID_FORMAT_HASH = 4;

uint256 constant _LSP8_TOKENID_SCHEMA_MIXED_DEFAULT_NUMBER = 100;
uint256 constant _LSP8_TOKENID_SCHEMA_MIXED_DEFAULT_STRING = 101;
uint256 constant _LSP8_TOKENID_SCHEMA_MIXED_DEFAULT_ADDRESS = 102;
uint256 constant _LSP8_TOKENID_SCHEMA_MIXED_DEFAULT_UNIQUE_ID = 103;
uint256 constant _LSP8_TOKENID_SCHEMA_MIXED_DEFAULT_HASH = 104;
uint256 constant _LSP8_TOKENID_FORMAT_MIXED_DEFAULT_NUMBER = 100;
uint256 constant _LSP8_TOKENID_FORMAT_MIXED_DEFAULT_STRING = 101;
uint256 constant _LSP8_TOKENID_FORMAT_MIXED_DEFAULT_ADDRESS = 102;
uint256 constant _LSP8_TOKENID_FORMAT_MIXED_DEFAULT_UNIQUE_ID = 103;
uint256 constant _LSP8_TOKENID_FORMAT_MIXED_DEFAULT_HASH = 104;
6 changes: 3 additions & 3 deletions contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ error LSP8TokenOwnerCannotBeOperator();
error LSP8TokenContractCannotHoldValue();

/**
* @dev Reverts when trying to edit the data key `LSP8TokenIdSchema` after the identifiable digital asset contract has been deployed.
* The `LSP8TokenIdSchema` data key is located inside the ERC725Y Data key-value store of the identifiable digital asset contract.
* @dev Reverts when trying to edit the data key `LSP8TokenIdFormat` after the identifiable digital asset contract has been deployed.
* The `LSP8TokenIdFormat` data key is located inside the ERC725Y Data key-value store of the identifiable digital asset contract.
* It can be set only once inside the constructor/initializer when the identifiable digital asset contract is being deployed.
*/
error LSP8TokenIdSchemaNotEditable();
error LSP8TokenIdFormatNotEditable();

/**
* @dev Reverts when the length of the token IDs data arrays is not equal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol";
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";

// constants
import {_INTERFACEID_LSP8, _LSP8_TOKENID_SCHEMA_KEY} from "./LSP8Constants.sol";
import {_INTERFACEID_LSP8, _LSP8_TOKENID_FORMAT_KEY} from "./LSP8Constants.sol";

// errors
import {
LSP8TokenContractCannotHoldValue,
LSP8TokenIdSchemaNotEditable
LSP8TokenIdFormatNotEditable
} from "./LSP8Errors.sol";

import {
Expand Down Expand Up @@ -61,30 +61,30 @@ abstract contract LSP8IdentifiableDigitalAsset is
{
/**
* @notice Deploying a LSP8IdentifiableDigitalAsset with name `name_`, symbol `symbol_`, owned by address `newOwner_`
* with tokenId schema `lsp8TokenIdSchema_`.
* with tokenId format `lsp8TokenIdFormat_`.
*
* @dev Deploy a `LSP8IdentifiableDigitalAsset` contract and set the tokenId schema inside the ERC725Y storage of the contract.
* @dev Deploy a `LSP8IdentifiableDigitalAsset` contract and set the tokenId format inside the ERC725Y storage of the contract.
* This will also set the token `name_` and `symbol_` under the ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol`.
*
* @param name_ The name of the token
* @param symbol_ The symbol of the token
* @param newOwner_ The owner of the the token-Metadata
* @param lsp4TokenType_ The type of token this digital asset contract represents (`0` = Token, `1` = NFT, `2` = Collection).
* @param lsp8TokenIdSchema_ The schema of tokenIds (= NFTs) that this contract will create.
* @param lsp8TokenIdFormat_ The format of tokenIds (= NFTs) that this contract will create.
*
* @custom:warning Make sure the tokenId schema provided on deployment is correct, as it can only be set once
* @custom:warning Make sure the tokenId format provided on deployment is correct, as it can only be set once
* and cannot be changed in the ERC725Y storage after the contract has been deployed.
*/
constructor(
string memory name_,
string memory symbol_,
address newOwner_,
uint256 lsp4TokenType_,
uint256 lsp8TokenIdSchema_
uint256 lsp8TokenIdFormat_
) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_, lsp4TokenType_) {
LSP4DigitalAssetMetadata._setData(
_LSP8_TOKENID_SCHEMA_KEY,
abi.encode(lsp8TokenIdSchema_)
_LSP8_TOKENID_FORMAT_KEY,
abi.encode(lsp8TokenIdFormat_)
);
}

Expand Down Expand Up @@ -220,7 +220,7 @@ abstract contract LSP8IdentifiableDigitalAsset is

/**
* @inheritdoc LSP4DigitalAssetMetadata
* @dev The ERC725Y data key `_LSP8_TOKENID_SCHEMA_KEY` cannot be changed
* @dev The ERC725Y data key `_LSP8_TOKENID_FORMAT_KEY` cannot be changed
* once the identifiable digital asset contract has been deployed.
*/
function _setData(
Expand All @@ -231,8 +231,8 @@ abstract contract LSP8IdentifiableDigitalAsset is
virtual
override(LSP4DigitalAssetMetadata, LSP4DigitalAssetMetadataCore)
{
if (dataKey == _LSP8_TOKENID_SCHEMA_KEY) {
revert LSP8TokenIdSchemaNotEditable();
if (dataKey == _LSP8_TOKENID_FORMAT_KEY) {
revert LSP8TokenIdFormatNotEditable();
}
LSP4DigitalAssetMetadata._setData(dataKey, dataValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,49 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
/**
* @inheritdoc ILSP8IdentifiableDigitalAsset
*/
function setTokenIdData(
function getDataForTokenId(
bytes32 tokenId,
bytes32 dataKey
) public view virtual override returns (bytes memory dataValue) {
return _getDataForTokenId(tokenId, dataKey);
}

/**
* @inheritdoc ILSP8IdentifiableDigitalAsset
*/
function getDataBatchForTokenIds(
bytes32[] memory tokenIds,
bytes32[] memory dataKeys
) public view virtual override returns (bytes[] memory dataValues) {
dataValues = new bytes[](tokenIds.length);

for (uint256 i; i < tokenIds.length; ) {
dataValues[i] = _getDataForTokenId(tokenIds[i], dataKeys[i]);

// Increment the iterator in unchecked block to save gas
unchecked {
++i;
}
}

return dataValues;
}

/**
* @inheritdoc ILSP8IdentifiableDigitalAsset
*/
function setDataForTokenId(
bytes32 tokenId,
bytes32 dataKey,
bytes memory dataValue
) public virtual override onlyOwner {
_setTokenIdData(tokenId, dataKey, dataValue);
_setDataForTokenId(tokenId, dataKey, dataValue);
}

/**
* @inheritdoc ILSP8IdentifiableDigitalAsset
*/
function setTokenIdDataBatch(
function setDataBatchForTokenIds(
bytes32[] memory tokenIds,
bytes32[] memory dataKeys,
bytes[] memory dataValues
Expand All @@ -156,7 +187,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
}

for (uint256 i; i < tokenIds.length; ) {
_setTokenIdData(tokenIds[i], dataKeys[i], dataValues[i]);
_setDataForTokenId(tokenIds[i], dataKeys[i], dataValues[i]);

// Increment the iterator in unchecked block to save gas
unchecked {
Expand Down Expand Up @@ -204,37 +235,6 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
}
}

/**
* @inheritdoc ILSP8IdentifiableDigitalAsset
*/
function getTokenIdData(
bytes32 tokenId,
bytes32 dataKey
) public view virtual override returns (bytes memory dataValues) {
return _getTokenIdData(tokenId, dataKey);
}

/**
* @inheritdoc ILSP8IdentifiableDigitalAsset
*/
function getTokenIdDataBatch(
bytes32[] memory tokenIds,
bytes32[] memory dataKeys
) public view virtual override returns (bytes[] memory dataValues) {
dataValues = new bytes[](tokenIds.length);

for (uint256 i; i < tokenIds.length; ) {
dataValues[i] = _getTokenIdData(tokenIds[i], dataKeys[i]);

// Increment the iterator in unchecked block to save gas
unchecked {
++i;
}
}

return dataValues;
}

// --- Operator functionality

/**
Expand Down Expand Up @@ -662,7 +662,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
* @param dataValue The value to set for the given data key.
* @custom:events {TokenIdDataChanged} event.
*/
function _setTokenIdData(
function _setDataForTokenId(
bytes32 tokenId,
bytes32 dataKey,
bytes memory dataValue
Expand All @@ -678,7 +678,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
* @param dataKey The key for the data to retrieve.
* @return dataValues The data value associated with the given `tokenId` and `dataKey`.
*/
function _getTokenIdData(
function _getDataForTokenId(
bytes32 tokenId,
bytes32 dataKey
) internal view virtual returns (bytes memory dataValues) {
Expand Down
Loading

0 comments on commit 2bf84f6

Please sign in to comment.