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: Non transferable token extensions #692

Closed
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ export const ERC725YDataKeys = {
LSP9: {
SupportedStandards_LSP9: SupportedStandards.LSP9Vault.key,
},
LSP7: {
// keccak256('LSP7NonTransferable')
LSP7NonTransferable: '0xb48a0085fb2c841c614d8c650033c5b790f407c071b9176ca4f2003db3613a1f',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would have these data keys first. I would suggest opening an issue in the LIP repo to discuss this first.

@YamenMerhi @skimaharvey @b00ste
https://github.com/lukso-network/LIPs/issues

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue created: lukso-network/LIPs#231

},
LSP8: {
// keccak256('LSP8NonTransferable')
LSP8NonTransferable: '0x0c9f377ecc6456a1dd41eb14df797a662dd42fc0d4cbcc3f4532f70736eb56ba',
},
LSP10: {
// keccak256('LSP10VaultsMap') + bytes2(0)
LSP10VaultsMap: '0x192448c3c0f88c7f238c0000',
Expand Down
3 changes: 3 additions & 0 deletions contracts/LSP7DigitalAsset/LSP7Constants.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.4;

// keccak256('LSP7NonTransferable')
bytes32 constant _LSP7_NON_TRANSFERABLE = 0xb48a0085fb2c841c614d8c650033c5b790f407c071b9176ca4f2003db3613a1f;

// --- ERC165 interface ids
bytes4 constant _INTERFACEID_LSP7 = 0xda1f85e4;

Expand Down
7 changes: 7 additions & 0 deletions contracts/LSP7DigitalAsset/LSP7Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ error LSP7TokenOwnerCannotBeOperator();
* @dev Reverts when trying to decrease an operator's allowance to more than its current allowance.
*/
error LSP7DecreasedAllowanceBelowZero();

/**
* @dev Reverts when trying to edit the data key `LSP7NonTransferable` after the digital asset contract has been deployed.
* The `LSP7NonTransferable` 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.
*/
error LSP7NonTransferableNotEditable();
60 changes: 60 additions & 0 deletions contracts/LSP7DigitalAsset/extensions/LSP7NonTransferable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {_LSP7_NON_TRANSFERABLE} from "../LSP7Constants.sol";
import {LSP7NonTransferableNotEditable} from "../LSP7Errors.sol";
import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol";

/**
* @dev LSP7 extension, adds the concept of a non-transferable token.
*/
contract LSP7NonTransferable is LSP7DigitalAsset {
/**
* @notice Deploying a `LSP7NonTransferable` token contract with: token name = `name_`, token symbol = `symbol_`,
* address `newOwner_` as the token contract owner, and _isNonDivisible_ = `isNonDivisible_`.
* Switch ON the non-transferable flag.
*
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
* @param isNonDivisible_ Specify if the tokens from this contract can be divided in smaller units or not.
*/
constructor(
string memory name_,
string memory symbol_,
address newOwner_,
bool isNonDivisible_
) LSP7DigitalAsset(name_, symbol_, newOwner_, isNonDivisible_) {
// Set the non-transferable flag
super._setData(_LSP7_NON_TRANSFERABLE, hex"01");
}

/**
* @dev This function override the internal `_transfer` function to make it non-transferable
*/
function _transfer(
address /* from */,
address /* to */,
uint256 /* amount */,
bool /* allowNonLSP1Recipient */,
bytes memory /* data */
) internal virtual override {
revert("LSP7: Token is non-transferable");
}

/**
* @dev the ERC725Y data key `LSP7NonTransferable` cannot be changed
* via this function once the digital asset contract has been deployed.
*
* @notice This function override the _setData function to make the non-transferable flag not editable
*/
function _setData(
bytes32 dataKey,
bytes memory dataValue
) internal virtual override {
if (dataKey == _LSP7_NON_TRANSFERABLE) {
revert LSP7NonTransferableNotEditable();
}
super._setData(dataKey, dataValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {_LSP7_NON_TRANSFERABLE} from "../LSP7Constants.sol";
import {LSP7NonTransferableNotEditable} from "../LSP7Errors.sol";
import {
LSP7DigitalAssetInitAbstract
} from "../LSP7DigitalAssetInitAbstract.sol";

/**
* @dev LSP7 extension, adds the concept of a non-transferable token.
*/
abstract contract LSP7NonTransferableInitAbstract is
LSP7DigitalAssetInitAbstract
{
/**
* @notice Initializing a `LSP7NonTransferable` token contract with: token name = `name_`, token symbol = `symbol_`,
* address `newOwner_` as the token contract owner, and _isNonDivisible_ = `isNonDivisible_`.
* Switch ON the non-transferable flag.
*
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
* @param isNonDivisible_ Specify if the tokens from this contract can be divided in smaller units or not.
*/
function _initialize(
string memory name_,
string memory symbol_,
address newOwner_,
bool isNonDivisible_
) internal virtual override onlyInitializing {
// Set the non-transferable flag
super._setData(_LSP7_NON_TRANSFERABLE, hex"01");

LSP7DigitalAssetInitAbstract._initialize(
name_,
symbol_,
newOwner_,
isNonDivisible_
);
}

/**
* @dev This function override the internal `_transfer` function to make it non-transferable
*/
function _transfer(
address /* from */,
address /* to */,
uint256 /* amount */,
bool /* allowNonLSP1Recipient */,
bytes memory /* data */
) internal virtual override {
revert("LSP7: Token is non-transferable");
}

/**
* @dev the ERC725Y data key `LSP7NonTransferable` cannot be changed
* via this function once the digital asset contract has been deployed.
*
* @notice This function override the _setData function to make the non-transferable flag not editable
*/
function _setData(
bytes32 dataKey,
bytes memory dataValue
) internal virtual override {
if (dataKey == _LSP7_NON_TRANSFERABLE) {
revert LSP7NonTransferableNotEditable();
}
super._setData(dataKey, dataValue);
}
}
3 changes: 3 additions & 0 deletions contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ bytes12 constant _LSP8_METADATA_ADDRESS_KEY_PREFIX = 0x73dcc7c3c4096cdc7f8a0000;
// bytes10(keccak256('LSP8MetadataJSON')) + bytes2(0)
bytes12 constant _LSP8_METADATA_JSON_KEY_PREFIX = 0x9a26b4060ae7f7d5e3cd0000;

// keccak256('lsp8NonTransferable')
bytes32 constant _LSP8_NON_TRANSFERABLE = 0x0c9f377ecc6456a1dd41eb14df797a662dd42fc0d4cbcc3f4532f70736eb56ba;

// --- Token Hooks

// keccak256('LSP8Tokens_SenderNotification')
Expand Down
7 changes: 7 additions & 0 deletions contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ error LSP8NotifyTokenReceiverIsEOA(address tokenReceiver);
* @dev reverts when trying to authorize or revoke the token's owner as an operator.
*/
error LSP8TokenOwnerCannotBeOperator();

/**
* @dev Reverts when trying to edit the data key `LSP8NonTransferable` after the digital asset contract has been deployed.
* The `LSP8NonTransferable` 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.
*/
error LSP8NonTransferableNotEditable();
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {_LSP8_NON_TRANSFERABLE} from "../LSP8Constants.sol";
import {LSP8NonTransferableNotEditable} from "../LSP8Errors.sol";
import {
LSP8IdentifiableDigitalAsset
} from "../LSP8IdentifiableDigitalAsset.sol";

/**
* @dev LSP8 extension, adds the concept of a non-transferable token.
*/
contract LSP8NonTransferable is LSP8IdentifiableDigitalAsset {
/**
* @notice Deploying a `LSP8NonTransferable` token contract with: token name = `name_`, token symbol = `symbol_`,
* address `newOwner_` as the token contract owner.
* Switch ON the non-transferable flag.
*
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
*/
constructor(
string memory name_,
string memory symbol_,
address newOwner_
) LSP8IdentifiableDigitalAsset(name_, symbol_, newOwner_) {
// Set the non-transferable flag
super._setData(_LSP8_NON_TRANSFERABLE, hex"01");
}

/**
* @dev This function override the internal `_transfer` function to make it non-transferable
*/
function _transfer(
address /* from */,
address /* to */,
bytes32 /* tokenId */,
bool /* allowNonLSP1Recipient */,
bytes memory /* data */
) internal virtual override {
revert("LSP8: Token is non-transferable");
}

/**
* @dev the ERC725Y data key `LSP8NonTransferable` cannot be changed
* via this function once the digital asset contract has been deployed.
*
* @notice This function override the _setData function to make the non-transferable flag not editable
*/
function _setData(
bytes32 dataKey,
bytes memory dataValue
) internal virtual override {
if (dataKey == _LSP8_NON_TRANSFERABLE) {
revert LSP8NonTransferableNotEditable();
}
super._setData(dataKey, dataValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import {_LSP8_NON_TRANSFERABLE} from "../LSP8Constants.sol";
import {LSP8NonTransferableNotEditable} from "../LSP8Errors.sol";
import {
LSP8IdentifiableDigitalAssetInitAbstract
} from "../LSP8IdentifiableDigitalAssetInitAbstract.sol";

/**
* @dev LSP8 extension, adds the concept of a non-transferable token.
*/
abstract contract LSP8NonTransferableInitAbstract is
LSP8IdentifiableDigitalAssetInitAbstract
{
/**
* @notice Initializing a `LSP8NonTransferable` token contract with: token name = `name_`, token symbol = `symbol_`,
* address `newOwner_` as the token contract owner.
* Switch ON the non-transferable flag.
*
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
* @param newOwner_ The owner of the token contract.
*/
function _initialize(
string memory name_,
string memory symbol_,
address newOwner_
) internal virtual override onlyInitializing {
// Set the non-transferable flag
super._setData(_LSP8_NON_TRANSFERABLE, hex"01");

LSP8IdentifiableDigitalAssetInitAbstract._initialize(
name_,
symbol_,
newOwner_
);
}

/**
* @dev This function override the internal `_transfer` function to make it non-transferable
*/
function _transfer(
address /* from */,
address /* to */,
bytes32 /* tokenId */,
bool /* allowNonLSP1Recipient */,
bytes memory /* data */
) internal virtual override {
revert("LSP8: Token is non-transferable");
}

/**
* @dev the ERC725Y data key `LSP8NonTransferable` cannot be changed
* via this function once the digital asset contract has been deployed.
*
* @notice This function override the _setData function to make the non-transferable flag not editable
*/
function _setData(
bytes32 dataKey,
bytes memory dataValue
) internal virtual override {
if (dataKey == _LSP8_NON_TRANSFERABLE) {
revert LSP8NonTransferableNotEditable();
}
super._setData(dataKey, dataValue);
}
}
33 changes: 33 additions & 0 deletions contracts/Mocks/Tokens/LSP7NonTransferableInitTester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

// modules
import {
LSP7NonTransferableInitAbstract
} from "../../LSP7DigitalAsset/extensions/LSP7NonTransferableInitAbstract.sol";

contract LSP7NonTransferableInitTester is LSP7NonTransferableInitAbstract {
function initialize(
string memory name_,
string memory symbol_,
address newOwner_,
bool isNonDivisible_
) public virtual initializer {
LSP7NonTransferableInitAbstract._initialize(
name_,
symbol_,
newOwner_,
isNonDivisible_
);
}

function mint(
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bytes memory data
) public virtual {
_mint(to, amount, allowNonLSP1Recipient, data);
}
}
26 changes: 26 additions & 0 deletions contracts/Mocks/Tokens/LSP7NonTransferableTester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

// modules
import {
LSP7NonTransferable
} from "../../LSP7DigitalAsset/extensions/LSP7NonTransferable.sol";

contract LSP7NonTransferableTester is LSP7NonTransferable {
constructor(
string memory name_,
string memory symbol_,
address newOwner_,
bool isNonDivisible_
) LSP7NonTransferable(name_, symbol_, newOwner_, isNonDivisible_) {}

function mint(
address to,
uint256 amount,
bool allowNonLSP1Recipient,
bytes memory data
) public virtual {
_mint(to, amount, allowNonLSP1Recipient, data);
}
}
Loading
Loading