Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: set LSP4TokenType on deployment of LSP7/8 Digital Assets #806

Merged
merged 13 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export const ERC725YDataKeys = {
// keccak256('LSP4TokenSymbol')
LSP4TokenSymbol: '0x2f0a68ab07768e01943a599e73362a0e17a63a72e94dd2e384d2c1d4db932756',

// keccak256('LSP4TokenType)
LSP4TokenType: '0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3',

// keccak256('LSP4Metadata')
LSP4Metadata: '0x9afb95cacc9f95858ec44aa8c3b685511002e30ae54415823f406128b85b238e',

Expand Down Expand Up @@ -390,11 +393,24 @@ export const LSP1_TYPE_IDS = {
'0xe32c7debcb817925ba4883fdbfc52797187f28f73f860641dab1a68d9b32902c',
};

// LSP4
// ----------

/**
* @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 = {
TOKEN: 0,
NFT: 1,
COLLECTION: 2,
};

// LSP8
// ----------

/**
* @dev list of LSP8 Token ID types that can be used to create different types of NFTs.
* @dev list of LSP8 Token ID types 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#lsp8tokenidtype
*/
export const LSP8_TOKEN_ID_TYPES = {
Expand Down
9 changes: 9 additions & 0 deletions contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.4;

// Token types

uint256 constant _LSP4_TOKEN_TYPE_TOKEN = 0;
uint256 constant _LSP4_TOKEN_TYPE_NFT = 1;
uint256 constant _LSP4_TOKEN_TYPE_COLLECTION = 2;

// --- ERC725Y entries

// bytes10(keccak256('SupportedStandards')) + bytes2(0) + bytes20(keccak256('LSP4DigitalAsset'))
Expand All @@ -15,6 +21,9 @@ bytes32 constant _LSP4_TOKEN_NAME_KEY = 0xdeba1e292f8ba88238e10ab3c7f88bd4be4fac
// keccak256('LSP4TokenSymbol')
bytes32 constant _LSP4_TOKEN_SYMBOL_KEY = 0x2f0a68ab07768e01943a599e73362a0e17a63a72e94dd2e384d2c1d4db932756;

// keccak256('LSP4TokenType')
bytes32 constant _LSP4_TOKEN_TYPE_KEY = 0xe0261fa95db2eb3b5439bd033cda66d56b96f92f243a8228fd87550ed7bdfdb3;

// keccak256('LSP4Creators[]')
bytes32 constant _LSP4_CREATORS_ARRAY_KEY = 0x114bd03b3a46d48759680d81ebb2b414fda7d030a7105a851867accf1c2352e7;

Expand Down
20 changes: 14 additions & 6 deletions contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import {
_LSP4_SUPPORTED_STANDARDS_KEY,
_LSP4_SUPPORTED_STANDARDS_VALUE,
_LSP4_TOKEN_NAME_KEY,
_LSP4_TOKEN_SYMBOL_KEY
_LSP4_TOKEN_SYMBOL_KEY,
_LSP4_TOKEN_TYPE_KEY
} from "./LSP4Constants.sol";

// errors
import {
LSP4TokenNameNotEditable,
LSP4TokenSymbolNotEditable
LSP4TokenSymbolNotEditable,
LSP4TokenTypeNotEditable
} from "./LSP4Errors.sol";

/**
Expand All @@ -30,14 +32,16 @@ abstract contract LSP4DigitalAssetMetadata is ERC725Y {
/**
* @notice Deploying a digital asset `name_` with the `symbol_` symbol.
*
* @param name_ The name of the token
* @param symbol_ The symbol of the token
* @param initialOwner_ The owner of the token contract
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param initialOwner_ The owner of the token contract.
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection).
*/
constructor(
string memory name_,
string memory symbol_,
address initialOwner_
address initialOwner_,
uint256 lsp4TokenType_
) ERC725Y(initialOwner_) {
// set data key SupportedStandards:LSP4DigitalAsset
super._setData(
Expand All @@ -47,6 +51,7 @@ abstract contract LSP4DigitalAssetMetadata is ERC725Y {

super._setData(_LSP4_TOKEN_NAME_KEY, bytes(name_));
super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
super._setData(_LSP4_TOKEN_TYPE_KEY, abi.encode(lsp4TokenType_));
b00ste marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -63,8 +68,11 @@ abstract contract LSP4DigitalAssetMetadata is ERC725Y {
revert LSP4TokenNameNotEditable();
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
revert LSP4TokenSymbolNotEditable();
} else if (dataKey == _LSP4_TOKEN_TYPE_KEY) {
revert LSP4TokenTypeNotEditable();
} else {
_store[dataKey] = dataValue;

emit DataChanged(
dataKey,
dataValue.length <= 256
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import {
_LSP4_SUPPORTED_STANDARDS_KEY,
_LSP4_SUPPORTED_STANDARDS_VALUE,
_LSP4_TOKEN_NAME_KEY,
_LSP4_TOKEN_SYMBOL_KEY
_LSP4_TOKEN_SYMBOL_KEY,
_LSP4_TOKEN_TYPE_KEY
} from "./LSP4Constants.sol";

// errors
import {
LSP4TokenNameNotEditable,
LSP4TokenSymbolNotEditable
LSP4TokenSymbolNotEditable,
LSP4TokenTypeNotEditable
} from "./LSP4Errors.sol";

/**
Expand All @@ -35,11 +37,13 @@ abstract contract LSP4DigitalAssetMetadataInitAbstract is ERC725YInitAbstract {
* @param name_ The name of the token
* @param symbol_ The symbol of the token
* @param initialOwner_ The owner of the token contract
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection)
*/
function _initialize(
string memory name_,
string memory symbol_,
address initialOwner_
address initialOwner_,
uint256 lsp4TokenType_
) internal virtual onlyInitializing {
ERC725YInitAbstract._initialize(initialOwner_);

Expand All @@ -51,6 +55,7 @@ abstract contract LSP4DigitalAssetMetadataInitAbstract is ERC725YInitAbstract {

super._setData(_LSP4_TOKEN_NAME_KEY, bytes(name_));
super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
super._setData(_LSP4_TOKEN_TYPE_KEY, abi.encode(lsp4TokenType_));
b00ste marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -67,8 +72,11 @@ abstract contract LSP4DigitalAssetMetadataInitAbstract is ERC725YInitAbstract {
revert LSP4TokenNameNotEditable();
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
revert LSP4TokenSymbolNotEditable();
} else if (dataKey == _LSP4_TOKEN_TYPE_KEY) {
revert LSP4TokenTypeNotEditable();
} else {
_store[dataKey] = dataValue;

emit DataChanged(
dataKey,
dataValue.length <= 256
Expand Down
19 changes: 13 additions & 6 deletions contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
pragma solidity ^0.8.4;

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

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

/**
* @dev Reverts when trying to edit the data key `LSP4TokenType` after the digital asset contract has been deployed / initialized.
* The `LSP4TokenType` data key is located inside the ERC725Y data key-value store of the digital asset contract.
* It can be set only once inside the constructor / initializer when the digital asset contract is being deployed / initialized.
*/
error LSP4TokenTypeNotEditable();
12 changes: 7 additions & 5 deletions contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ abstract contract LSP7DigitalAsset is
{
/**
* @notice Sets the token-Metadata
* @param name_ The name of the token
* @param symbol_ The symbol of the token
* @param newOwner_ The owner of the the token-Metadata
* @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token
* @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 (`1` = Token, `2` = NFT, `3` = Collection).
* @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token.
*/
constructor(
string memory name_,
string memory symbol_,
address newOwner_,
uint256 lsp4TokenType_,
bool isNonDivisible_
) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {
) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_, lsp4TokenType_) {
_isNonDivisible = isNonDivisible_;
}

Expand Down
7 changes: 5 additions & 2 deletions contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,17 @@ abstract contract LSP7DigitalAssetInitAbstract is
string memory name_,
string memory symbol_,
address newOwner_,
uint256 lsp4TokenType_,
bool isNonDivisible_
) internal virtual onlyInitializing {
_isNonDivisible = isNonDivisible_;
LSP4DigitalAssetMetadataInitAbstract._initialize(
name_,
symbol_,
newOwner_
newOwner_,
lsp4TokenType_
);

_isNonDivisible = isNonDivisible_;
}

// fallback function
Expand Down
6 changes: 4 additions & 2 deletions contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ abstract contract LSP7CompatibleERC20 is IERC20Metadata, LSP7DigitalAsset {
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection).
*/
constructor(
string memory name_,
string memory symbol_,
address newOwner_
) LSP7DigitalAsset(name_, symbol_, newOwner_, false) {}
address newOwner_,
uint256 lsp4TokenType_
) LSP7DigitalAsset(name_, symbol_, newOwner_, lsp4TokenType_, false) {}

/**
* @inheritdoc IERC20Metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@ abstract contract LSP7CompatibleERC20InitAbstract is
* @notice Initializing a `LSP7CompatibleERC20` token contract with: token name = `name_`, token symbol = `symbol_`, and
* address `newOwner_` as the token contract owner.
*
* @param name_ The name of the token
* @param symbol_ The symbol of the token
* @param newOwner_ The owner of the token
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token.
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection).
*/
function _initialize(
string memory name_,
string memory symbol_,
address newOwner_
address newOwner_,
uint256 lsp4TokenType_
) internal virtual override onlyInitializing {
LSP7DigitalAssetInitAbstract._initialize(
name_,
symbol_,
newOwner_,
lsp4TokenType_,
false
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ contract LSP7CompatibleERC20Mintable is LSP7CompatibleERC20 {
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection).
*/
constructor(
string memory name_,
string memory symbol_,
address newOwner_
) LSP7CompatibleERC20(name_, symbol_, newOwner_) {}
address newOwner_,
uint256 lsp4TokenType_
) LSP7CompatibleERC20(name_, symbol_, newOwner_, lsp4TokenType_) {}

/**
* @dev Public {_mint} function only callable by the {owner}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ contract LSP7CompatibleERC20MintableInit is
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection).
*/
function initialize(
string memory name_,
string memory symbol_,
address newOwner_
address newOwner_,
uint256 lsp4TokenType_
) external virtual initializer {
LSP7CompatibleERC20MintableInitAbstract._initialize(
name_,
symbol_,
newOwner_
newOwner_,
lsp4TokenType_
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ abstract contract LSP7CompatibleERC20MintableInitAbstract is
function _initialize(
string memory name_,
string memory symbol_,
address newOwner_
address newOwner_,
uint256 lsp4TokenType_
) internal virtual override onlyInitializing {
LSP7CompatibleERC20InitAbstract._initialize(name_, symbol_, newOwner_);
LSP7CompatibleERC20InitAbstract._initialize(
name_,
symbol_,
newOwner_,
lsp4TokenType_
);
}

/**
Expand Down
13 changes: 12 additions & 1 deletion contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ contract LSP7Mintable is LSP7DigitalAsset, ILSP7Mintable {
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection).
* @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token.
*/
constructor(
string memory name_,
string memory symbol_,
address newOwner_,
uint256 lsp4TokenType_,
bool isNonDivisible_
) LSP7DigitalAsset(name_, symbol_, newOwner_, isNonDivisible_) {}
)
LSP7DigitalAsset(
name_,
symbol_,
newOwner_,
lsp4TokenType_,
isNonDivisible_
)
{}

/**
* @dev Public {_mint} function only callable by the {owner}.
Expand Down
4 changes: 4 additions & 0 deletions contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@ contract LSP7MintableInit is LSP7MintableInitAbstract {
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
* @param lsp4TokenType_ The type of token this digital asset contract represents (`1` = Token, `2` = NFT, `3` = Collection).
* @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token.
*/
function initialize(
string memory name_,
string memory symbol_,
address newOwner_,
uint256 lsp4TokenType_,
bool isNonDivisible_
) external virtual initializer {
LSP7MintableInitAbstract._initialize(
name_,
symbol_,
newOwner_,
lsp4TokenType_,
isNonDivisible_
);
}
Expand Down
Loading
Loading