-
Notifications
You must be signed in to change notification settings - Fork 50
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
samuel-videau
wants to merge
1
commit into
lukso-network:develop
from
samuel-videau:feat/non_transferable_tokens
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
contracts/LSP7DigitalAsset/extensions/LSP7NonTransferable.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
contracts/LSP7DigitalAsset/extensions/LSP7NonTransferableInitAbstract.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8NonTransferable.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8NonTransferableInitAbstract.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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