@lukso/lsp7-contracts 0.16.8 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +55 -5
  3. package/artifacts/IAccessControlExtended.json +285 -0
  4. package/artifacts/ILSP7CappedBalance.json +27 -0
  5. package/artifacts/ILSP7CappedSupply.json +27 -0
  6. package/artifacts/ILSP7DigitalAsset.json +6 -3
  7. package/artifacts/ILSP7Mintable.json +62 -0
  8. package/artifacts/ILSP7NonTransferable.json +110 -0
  9. package/artifacts/ILSP7Revokable.json +75 -0
  10. package/artifacts/LSP7Burnable.json +7 -4
  11. package/artifacts/LSP7BurnableInitAbstract.json +7 -4
  12. package/artifacts/LSP7CappedBalanceAbstract.json +1159 -0
  13. package/artifacts/LSP7CappedBalanceInitAbstract.json +1167 -0
  14. package/artifacts/{LSP7CappedSupply.json → LSP7CappedSupplyAbstract.json} +8 -15
  15. package/artifacts/LSP7CappedSupplyInitAbstract.json +7 -14
  16. package/artifacts/LSP7CustomizableToken.json +1604 -0
  17. package/artifacts/LSP7CustomizableTokenInit.json +1601 -0
  18. package/artifacts/LSP7DigitalAsset.json +6 -3
  19. package/artifacts/LSP7DigitalAssetInitAbstract.json +6 -3
  20. package/artifacts/LSP7Mintable.json +376 -5
  21. package/artifacts/LSP7MintableAbstract.json +1186 -0
  22. package/artifacts/LSP7MintableInit.json +369 -5
  23. package/artifacts/LSP7MintableInitAbstract.json +1194 -0
  24. package/artifacts/LSP7NonTransferableAbstract.json +1236 -0
  25. package/artifacts/LSP7NonTransferableInitAbstract.json +1244 -0
  26. package/artifacts/LSP7RevokableAbstract.json +1186 -0
  27. package/artifacts/LSP7RevokableInitAbstract.json +1194 -0
  28. package/artifacts/LSP7Votes.json +66 -4
  29. package/artifacts/LSP7VotesInitAbstract.json +66 -4
  30. package/contracts/LSP7DigitalAsset.sol +56 -65
  31. package/contracts/LSP7DigitalAssetInitAbstract.sol +49 -71
  32. package/contracts/extensions/AccessControlExtended/AccessControlExtendedAbstract.sol +368 -0
  33. package/contracts/extensions/AccessControlExtended/AccessControlExtendedConstants.sol +13 -0
  34. package/contracts/extensions/AccessControlExtended/AccessControlExtendedErrors.sol +23 -0
  35. package/contracts/extensions/AccessControlExtended/AccessControlExtendedInitAbstract.sol +389 -0
  36. package/contracts/extensions/AccessControlExtended/IAccessControlExtended.sol +51 -0
  37. package/contracts/extensions/{LSP7Burnable.sol → LSP7Burnable/LSP7Burnable.sol} +2 -2
  38. package/contracts/extensions/{LSP7BurnableInitAbstract.sol → LSP7Burnable/LSP7BurnableInitAbstract.sol} +2 -4
  39. package/contracts/extensions/LSP7CappedBalance/ILSP7CappedBalance.sol +11 -0
  40. package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceAbstract.sol +129 -0
  41. package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceErrors.sol +10 -0
  42. package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceInitAbstract.sol +179 -0
  43. package/contracts/extensions/LSP7CappedSupply/ILSP7CappedSupply.sol +11 -0
  44. package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyAbstract.sol +56 -0
  45. package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyErrors.sol +6 -0
  46. package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyInitAbstract.sol +96 -0
  47. package/contracts/extensions/LSP7Mintable/ILSP7Mintable.sol +27 -0
  48. package/contracts/extensions/LSP7Mintable/LSP7MintableAbstract.sol +105 -0
  49. package/contracts/extensions/LSP7Mintable/LSP7MintableErrors.sol +5 -0
  50. package/contracts/extensions/LSP7Mintable/LSP7MintableInitAbstract.sol +156 -0
  51. package/contracts/extensions/LSP7NonTransferable/ILSP7NonTransferable.sol +48 -0
  52. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableAbstract.sol +183 -0
  53. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableErrors.sol +14 -0
  54. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableInitAbstract.sol +240 -0
  55. package/contracts/extensions/LSP7Revokable/ILSP7Revokable.sol +28 -0
  56. package/contracts/extensions/LSP7Revokable/LSP7RevokableAbstract.sol +130 -0
  57. package/contracts/extensions/LSP7Revokable/LSP7RevokableErrors.sol +4 -0
  58. package/contracts/extensions/LSP7Revokable/LSP7RevokableInitAbstract.sol +183 -0
  59. package/contracts/extensions/{LSP7Votes.sol → LSP7Votes/LSP7Votes.sol} +37 -20
  60. package/contracts/extensions/LSP7Votes/LSP7VotesErrors.sol +24 -0
  61. package/contracts/extensions/{LSP7VotesInitAbstract.sol → LSP7Votes/LSP7VotesInitAbstract.sol} +37 -21
  62. package/contracts/presets/LSP7CustomizableToken.sol +262 -0
  63. package/contracts/presets/LSP7CustomizableTokenConstants.sol +32 -0
  64. package/contracts/presets/LSP7CustomizableTokenInit.sol +294 -0
  65. package/contracts/presets/LSP7Mintable.sol +14 -23
  66. package/contracts/presets/LSP7MintableInit.sol +16 -11
  67. package/dist/abi.cjs +7519 -54
  68. package/dist/abi.d.cts +11109 -338
  69. package/dist/abi.d.mts +11109 -338
  70. package/dist/abi.d.ts +11109 -338
  71. package/dist/abi.mjs +7503 -54
  72. package/dist/constants.cjs +21 -0
  73. package/dist/constants.d.cts +12 -1
  74. package/dist/constants.d.mts +12 -1
  75. package/dist/constants.d.ts +12 -1
  76. package/dist/constants.mjs +16 -1
  77. package/package.json +33 -9
  78. package/contracts/extensions/LSP7CappedSupply.sol +0 -83
  79. package/contracts/extensions/LSP7CappedSupplyInitAbstract.sol +0 -86
  80. package/contracts/presets/ILSP7Mintable.sol +0 -32
  81. package/contracts/presets/LSP7MintableInitAbstract.sol +0 -57
  82. /package/contracts/extensions/{LSP7VotesConstants.sol → LSP7Votes/LSP7VotesConstants.sol} +0 -0
@@ -0,0 +1,48 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ /// @title ILSP7NonTransferable
5
+ /// @dev Interface for a non-transferable LSP7 token, enabling control over transferability, lock periods, and allowlist exemptions.
6
+ interface ILSP7NonTransferable {
7
+ /// @dev Emitted when the transfer lock period is updated.
8
+ /// @param start The new start timestamp of the transfer lock period.
9
+ /// @param end The new end timestamp of the transfer lock period.
10
+ event TransferLockPeriodChanged(uint256 indexed start, uint256 indexed end);
11
+
12
+ /// @notice The start timestamp of the transfer lock period, at which point the token becomes non-transferable.
13
+ function transferLockStart() external view returns (uint256);
14
+
15
+ /// @notice The end timestamp of the transfer lock period, at which point the token becomes transferable again.
16
+ function transferLockEnd() external view returns (uint256);
17
+
18
+ /// @notice Returns whether the transfer lock feature is still enabled.
19
+ /// @dev When this returns `false`, the token has been permanently made transferable and the lock period can no longer be updated.
20
+ function transferLockEnabled() external view returns (bool);
21
+
22
+ /// @notice Checks if the token is currently transferable.
23
+ /// @dev Returns true if the token is currently transferable. When `transferLockEnabled` is true, this is derived from the configured lock period. When `transferLockEnabled` is false, this always returns true. Note that transfers from allowlisted addresses and burning (transfers to address(0)) is always allowed, regardless of transferability status.
24
+ /// @return A `true` or `false` boolean indicating if the token is transferable or not.
25
+ function isTransferable() external view returns (bool);
26
+
27
+ /// @notice Removes all transfer lock periods, enabling token transfers for non-allowlisted addresses.
28
+ /// @dev Can only be called by the contract owner. Permanently disables the transfer lock feature, sets both lock periods to 0, and prevents any future lock period updates.
29
+ /// @custom:emits {TransferLockPeriodChanged} event.
30
+ function makeTransferable() external;
31
+
32
+ /// @notice Updates the transfer lock period with new start and end timestamps.
33
+ /// - When `transferLockStart` is 0 and `transferLockEnd` is set to a non-zero value, it means no start time is set. The token is non-transferable immediately until `transferLockEnd`.
34
+ /// - When `transferLockStart` is set to a value and `transferLockEnd` is 0, it means the tokens becomes non-transferable at a certain point in time and indefinitely (no end time).
35
+ ///
36
+ /// - To make the token always non-transferable, set `transferLockStart` to 0 and `transferLockEnd` to type(uint256).max.
37
+ /// - To disable completely the non-transferable feature (= make the token always transferable), set both `transferLockStart` and `transferLockEnd` to 0.
38
+ ///
39
+ /// @dev Can only be called by the contract owner. Reverts once {makeTransferable} has been called.
40
+ ///
41
+ /// @custom:emits {TransferLockPeriodChanged} event.
42
+ /// @param newTransferLockStart The new start timestamp for the transfer lock period.
43
+ /// @param newTransferLockEnd The new end timestamp for the transfer lock period.
44
+ function updateTransferLockPeriod(
45
+ uint256 newTransferLockStart,
46
+ uint256 newTransferLockEnd
47
+ ) external;
48
+ }
@@ -0,0 +1,183 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ // modules
5
+ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
6
+ import {LSP7DigitalAsset} from "../../LSP7DigitalAsset.sol";
7
+ import {
8
+ AccessControlExtendedAbstract
9
+ } from "../AccessControlExtended/AccessControlExtendedAbstract.sol";
10
+
11
+ // interfaces
12
+ import {ILSP7NonTransferable} from "./ILSP7NonTransferable.sol";
13
+
14
+ // errors
15
+ import {
16
+ LSP7TransferDisabled,
17
+ LSP7InvalidTransferLockPeriod,
18
+ LSP7CannotUpdateTransferLockPeriod,
19
+ LSP7TokenAlreadyTransferable
20
+ } from "./LSP7NonTransferableErrors.sol";
21
+
22
+ /// @title LSP7NonTransferableAbstract
23
+ /// @dev Abstract contract implementing non-transferable LSP7 token functionality with transfer lock periods and allowlist support.
24
+ abstract contract LSP7NonTransferableAbstract is
25
+ ILSP7NonTransferable,
26
+ LSP7DigitalAsset,
27
+ AccessControlExtendedAbstract
28
+ {
29
+ /// @dev keccak256("NON_TRANSFERABLE_BYPASS_ROLE")
30
+ bytes32 public constant NON_TRANSFERABLE_BYPASS_ROLE =
31
+ 0xb4b3a36d7c2b72add3151898671aaed843238e580f7d6d4bc5077ce2023b0659;
32
+
33
+ /// @inheritdoc ILSP7NonTransferable
34
+ uint256 public transferLockStart;
35
+
36
+ /// @inheritdoc ILSP7NonTransferable
37
+ uint256 public transferLockEnd;
38
+
39
+ /// @inheritdoc ILSP7NonTransferable
40
+ bool public transferLockEnabled;
41
+
42
+ /// @notice Initializes the contract with non-transferable locking period.
43
+ /// @param transferLockStart_ The start timestamp of the transfer lock period, 0 to disable.
44
+ /// @param transferLockEnd_ The end timestamp of the transfer lock period, 0 to disable.
45
+ constructor(uint256 transferLockStart_, uint256 transferLockEnd_) {
46
+ require(
47
+ transferLockEnd_ == 0 || transferLockEnd_ >= transferLockStart_,
48
+ LSP7InvalidTransferLockPeriod()
49
+ );
50
+ transferLockStart = transferLockStart_;
51
+ transferLockEnd = transferLockEnd_;
52
+ transferLockEnabled = true;
53
+
54
+ emit TransferLockPeriodChanged(transferLockStart_, transferLockEnd_);
55
+ _grantRole(NON_TRANSFERABLE_BYPASS_ROLE, owner());
56
+ }
57
+
58
+ function supportsInterface(
59
+ bytes4 interfaceId
60
+ )
61
+ public
62
+ view
63
+ virtual
64
+ override(AccessControlExtendedAbstract, LSP7DigitalAsset)
65
+ returns (bool)
66
+ {
67
+ return
68
+ AccessControlExtendedAbstract.supportsInterface(interfaceId) ||
69
+ LSP7DigitalAsset.supportsInterface(interfaceId);
70
+ }
71
+
72
+ /// @inheritdoc ILSP7NonTransferable
73
+ function isTransferable() public view virtual override returns (bool) {
74
+ if (!transferLockEnabled) return true;
75
+
76
+ bool isTransferLockStartEnabled = transferLockStart != 0;
77
+ bool isTransferLockEndEnabled = transferLockEnd != 0;
78
+
79
+ // If both lock periods are disabled, the token is transferable
80
+ if (!isTransferLockStartEnabled && !isTransferLockEndEnabled) {
81
+ return true;
82
+ }
83
+
84
+ // If the token is non-transferable up to a certain point in time, check if we have passed this period
85
+ if (!isTransferLockStartEnabled && isTransferLockEndEnabled) {
86
+ return transferLockEnd < block.timestamp;
87
+ }
88
+
89
+ // If the token becomes non-transferable starting at a specific point in time, check if we have reached this lock starting period
90
+ if (isTransferLockStartEnabled && !isTransferLockEndEnabled) {
91
+ return transferLockStart > block.timestamp;
92
+ }
93
+
94
+ // This last case checks if we are within the transfer lock period
95
+ return
96
+ transferLockStart > block.timestamp ||
97
+ transferLockEnd < block.timestamp;
98
+ }
99
+
100
+ /// @inheritdoc ILSP7NonTransferable
101
+ /// @custom:info The list of addresses holding the `NON_TRANSFERABLE_BYPASS_ROLE` remains populated after the non-transferable feature is switched off.
102
+ function makeTransferable() public virtual override onlyOwner {
103
+ require(transferLockEnabled, LSP7TokenAlreadyTransferable());
104
+
105
+ transferLockEnabled = false;
106
+ transferLockStart = 0;
107
+ transferLockEnd = 0;
108
+
109
+ emit TransferLockPeriodChanged({start: 0, end: 0});
110
+ }
111
+
112
+ /// @inheritdoc ILSP7NonTransferable
113
+ function updateTransferLockPeriod(
114
+ uint256 newTransferLockStart,
115
+ uint256 newTransferLockEnd
116
+ ) public virtual override onlyOwner {
117
+ require(transferLockEnabled, LSP7CannotUpdateTransferLockPeriod());
118
+
119
+ // When `transferLockEnd` is 0, it means no end time is set (transfers locked indefinitely since `transferLockStart`)
120
+ // When `transferLockStart` is 0, it means no start time is set (transfers locked up until `transferLockEnd`)
121
+ // Allow to make the token always non-transferable, or ensure the end period for locking transfers is always later than the starting period
122
+ require(
123
+ newTransferLockEnd == 0 ||
124
+ newTransferLockEnd >= newTransferLockStart,
125
+ LSP7InvalidTransferLockPeriod()
126
+ );
127
+
128
+ transferLockStart = newTransferLockStart;
129
+ transferLockEnd = newTransferLockEnd;
130
+
131
+ emit TransferLockPeriodChanged({
132
+ start: newTransferLockStart,
133
+ end: newTransferLockEnd
134
+ });
135
+ }
136
+
137
+ /// @notice Checks if a token transfer is allowed based on transferability status.
138
+ /// @dev Allows burning to address(0) even when transfers are disabled, bypassing transferability restrictions. Reverts with {LSP7TransferDisabled} if the token is non-transferable and the destination is not address(0).
139
+ /// @param to The address receiving the tokens.
140
+ function _nonTransferableCheck(
141
+ address from,
142
+ address to,
143
+ uint256 /* amount */,
144
+ bool /* force */,
145
+ bytes memory /* data */
146
+ ) internal virtual {
147
+ // Allow minting and burning
148
+ if (from == address(0) || to == address(0)) return;
149
+
150
+ // Do not check for addresses exempted from non transferable check
151
+ if (hasRole(NON_TRANSFERABLE_BYPASS_ROLE, from)) return;
152
+
153
+ // transferring tokens only if the transferability status is enabled
154
+ require(isTransferable(), LSP7TransferDisabled());
155
+ }
156
+
157
+ /// @notice Hook called before a token transfer to enforce transfer restrictions.
158
+ /// @dev Bypasses transfer restrictions for addresses in the allowlist, allowing them to transfer tokens even when {isTransferable} returns false. For non-allowlisted addresses, applies non-transferable checks.
159
+ /// @param from The address sending the tokens.
160
+ /// @param to The address receiving the tokens.
161
+ /// @param amount The amount of tokens being transferred.
162
+ /// @param force Whether to force the transfer (passed to _nonTransferableCheck).
163
+ /// @param data Additional data for the transfer (passed to _nonTransferableCheck).
164
+ function _beforeTokenTransfer(
165
+ address from,
166
+ address to,
167
+ uint256 amount,
168
+ bool force,
169
+ bytes memory data
170
+ ) internal virtual override {
171
+ _nonTransferableCheck(from, to, amount, force, data);
172
+ super._beforeTokenTransfer(from, to, amount, force, data);
173
+ }
174
+
175
+ function _transferOwnership(
176
+ address newOwner
177
+ ) internal virtual override(AccessControlExtendedAbstract, Ownable) {
178
+ // restore default admin hierarchy so a previously-installed custom admin
179
+ // cannot grant NON_TRANSFERABLE_BYPASS_ROLE to new accounts post-transfer
180
+ _setRoleAdmin(NON_TRANSFERABLE_BYPASS_ROLE, DEFAULT_ADMIN_ROLE);
181
+ super._transferOwnership(newOwner);
182
+ }
183
+ }
@@ -0,0 +1,14 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ /// @dev Error thrown when attempting a token transfer while transfers are disabled.
5
+ error LSP7TransferDisabled();
6
+
7
+ /// @dev Error thrown when the transfer lock period is invalid, such as when the end timestamp is earlier than the start timestamp.
8
+ error LSP7InvalidTransferLockPeriod();
9
+
10
+ /// @dev Error thrown when attempting to update the transfer lock period after it has begun.
11
+ error LSP7CannotUpdateTransferLockPeriod();
12
+
13
+ /// @dev Error thrown when attempting to make a token transferable that is already transferable.
14
+ error LSP7TokenAlreadyTransferable();
@@ -0,0 +1,240 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.4;
3
+
4
+ // modules
5
+ import {
6
+ OwnableUpgradeable
7
+ } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
8
+ import {
9
+ LSP7DigitalAssetInitAbstract
10
+ } from "../../LSP7DigitalAssetInitAbstract.sol";
11
+ import {
12
+ AccessControlExtendedInitAbstract
13
+ } from "../AccessControlExtended/AccessControlExtendedInitAbstract.sol";
14
+
15
+ // interfaces
16
+ import {ILSP7NonTransferable} from "./ILSP7NonTransferable.sol";
17
+
18
+ // errors
19
+ import {
20
+ LSP7TransferDisabled,
21
+ LSP7InvalidTransferLockPeriod,
22
+ LSP7CannotUpdateTransferLockPeriod,
23
+ LSP7TokenAlreadyTransferable
24
+ } from "./LSP7NonTransferableErrors.sol";
25
+
26
+ /// @title LSP7NonTransferableInitAbstract
27
+ /// @dev Abstract contract implementing non-transferable LSP7 token functionality with transfer lock periods
28
+ /// and support to bypass non-transferable checks through a role.
29
+ abstract contract LSP7NonTransferableInitAbstract is
30
+ ILSP7NonTransferable,
31
+ LSP7DigitalAssetInitAbstract,
32
+ AccessControlExtendedInitAbstract
33
+ {
34
+ /// @dev keccak256("NON_TRANSFERABLE_BYPASS_ROLE")
35
+ bytes32 public constant NON_TRANSFERABLE_BYPASS_ROLE =
36
+ 0xb4b3a36d7c2b72add3151898671aaed843238e580f7d6d4bc5077ce2023b0659;
37
+
38
+ /// @inheritdoc ILSP7NonTransferable
39
+ uint256 public transferLockStart;
40
+
41
+ /// @inheritdoc ILSP7NonTransferable
42
+ uint256 public transferLockEnd;
43
+
44
+ /// @inheritdoc ILSP7NonTransferable
45
+ bool public transferLockEnabled;
46
+
47
+ /// @notice Initializes the LSP7NonTransferable contract with base token params, allowlist, and transfer settings.
48
+ /// @dev Initializes the LSP7Allowlist (which initializes LSP7DigitalAsset) and sets the lock period.
49
+ /// @param name_ The name of the token.
50
+ /// @param symbol_ The symbol of the token.
51
+ /// @param newOwner_ The owner of the contract, added to the allowlist.
52
+ /// @param lsp4TokenType_ The token type (see LSP4).
53
+ /// @param isNonDivisible_ Whether the token is non-divisible.
54
+ /// @param transferLockStart_ The start timestamp of the transfer lock period, 0 to disable.
55
+ /// @param transferLockEnd_ The end timestamp of the transfer lock period, 0 to disable.
56
+ function __LSP7NonTransferable_init(
57
+ string memory name_,
58
+ string memory symbol_,
59
+ address newOwner_,
60
+ uint256 lsp4TokenType_,
61
+ bool isNonDivisible_,
62
+ uint256 transferLockStart_,
63
+ uint256 transferLockEnd_
64
+ ) internal virtual onlyInitializing {
65
+ LSP7DigitalAssetInitAbstract._initialize(
66
+ name_,
67
+ symbol_,
68
+ newOwner_,
69
+ lsp4TokenType_,
70
+ isNonDivisible_
71
+ );
72
+ __AccessControlExtended_init();
73
+ __LSP7NonTransferable_init_unchained(
74
+ transferLockStart_,
75
+ transferLockEnd_
76
+ );
77
+ }
78
+
79
+ /// @notice Unchained initializer for the lock period.
80
+ /// @param transferLockStart_ The start timestamp of the transfer lock period, 0 to disable.
81
+ /// @param transferLockEnd_ The end timestamp of the transfer lock period, 0 to disable.
82
+ function __LSP7NonTransferable_init_unchained(
83
+ uint256 transferLockStart_,
84
+ uint256 transferLockEnd_
85
+ ) internal virtual onlyInitializing {
86
+ require(
87
+ transferLockEnd_ == 0 || transferLockEnd_ >= transferLockStart_,
88
+ LSP7InvalidTransferLockPeriod()
89
+ );
90
+ transferLockStart = transferLockStart_;
91
+ transferLockEnd = transferLockEnd_;
92
+ transferLockEnabled = true;
93
+
94
+ emit TransferLockPeriodChanged(transferLockStart_, transferLockEnd_);
95
+ _grantRole(NON_TRANSFERABLE_BYPASS_ROLE, owner());
96
+ }
97
+
98
+ function supportsInterface(
99
+ bytes4 interfaceId
100
+ )
101
+ public
102
+ view
103
+ virtual
104
+ override(
105
+ AccessControlExtendedInitAbstract,
106
+ LSP7DigitalAssetInitAbstract
107
+ )
108
+ returns (bool)
109
+ {
110
+ return
111
+ AccessControlExtendedInitAbstract.supportsInterface(interfaceId) ||
112
+ LSP7DigitalAssetInitAbstract.supportsInterface(interfaceId);
113
+ }
114
+
115
+ /// @inheritdoc ILSP7NonTransferable
116
+ function isTransferable() public view virtual override returns (bool) {
117
+ if (!transferLockEnabled) return true;
118
+
119
+ bool isTransferLockStartEnabled = transferLockStart != 0;
120
+ bool isTransferLockEndEnabled = transferLockEnd != 0;
121
+
122
+ // If both lock periods are disabled, the token is transferable
123
+ if (!isTransferLockStartEnabled && !isTransferLockEndEnabled) {
124
+ return true;
125
+ }
126
+
127
+ // If the token is non-transferable up to a certain point in time, check if we have passed this period
128
+ if (!isTransferLockStartEnabled && isTransferLockEndEnabled) {
129
+ return transferLockEnd < block.timestamp;
130
+ }
131
+
132
+ // If the token becomes non-transferable starting at a specific point in time, check if we have reached this lock starting period
133
+ if (isTransferLockStartEnabled && !isTransferLockEndEnabled) {
134
+ return transferLockStart > block.timestamp;
135
+ }
136
+
137
+ // This last case checks if we are within the transfer lock period
138
+ return
139
+ transferLockStart > block.timestamp ||
140
+ transferLockEnd < block.timestamp;
141
+ }
142
+
143
+ /// @inheritdoc ILSP7NonTransferable
144
+ /// @custom:info The list of addresses holding the `NON_TRANSFERABLE_BYPASS_ROLE` remains populated after the non-transferable feature is switched off.
145
+ function makeTransferable() public virtual override onlyOwner {
146
+ require(transferLockEnabled, LSP7TokenAlreadyTransferable());
147
+
148
+ transferLockEnabled = false;
149
+ transferLockStart = 0;
150
+ transferLockEnd = 0;
151
+
152
+ emit TransferLockPeriodChanged({start: 0, end: 0});
153
+ }
154
+
155
+ /// @inheritdoc ILSP7NonTransferable
156
+ function updateTransferLockPeriod(
157
+ uint256 newTransferLockStart,
158
+ uint256 newTransferLockEnd
159
+ ) public virtual override onlyOwner {
160
+ require(transferLockEnabled, LSP7CannotUpdateTransferLockPeriod());
161
+
162
+ // When transferLockEnd is 0, it means no end time is set (transfers locked indefinitely after transferLockStart)
163
+ // When transferLockStart is 0, it means no start time is set (transfers locked up until transferLockEnd)
164
+ // Allow to make the token always non-transferable, or ensure the end period for locking transfers is always later than the starting period
165
+ require(
166
+ newTransferLockEnd == 0 ||
167
+ newTransferLockEnd >= newTransferLockStart,
168
+ LSP7InvalidTransferLockPeriod()
169
+ );
170
+
171
+ transferLockStart = newTransferLockStart;
172
+ transferLockEnd = newTransferLockEnd;
173
+
174
+ emit TransferLockPeriodChanged({
175
+ start: newTransferLockStart,
176
+ end: newTransferLockEnd
177
+ });
178
+ }
179
+
180
+ /// @notice Checks if a token transfer is allowed based on transferability status.
181
+ /// @dev Allows burning to address(0) even when transfers are disabled, bypassing transferability restrictions. Reverts with {LSP7TransferDisabled} if the token is non-transferable and the destination is not address(0).
182
+ /// @param to The address receiving the tokens.
183
+ function _nonTransferableCheck(
184
+ address from,
185
+ address to,
186
+ uint256 /* amount */,
187
+ bool /* force */,
188
+ bytes memory /* data */
189
+ ) internal virtual {
190
+ // Allow minting and burning
191
+ if (from == address(0) || to == address(0)) return;
192
+
193
+ // Do not check for addresses exempted from non transferable check
194
+ if (hasRole(NON_TRANSFERABLE_BYPASS_ROLE, from)) return;
195
+
196
+ // transferring tokens only if the transferability status is enabled
197
+ require(isTransferable(), LSP7TransferDisabled());
198
+ }
199
+
200
+ /// @notice Hook called before a token transfer to enforce transfer restrictions.
201
+ /// @dev Bypasses transfer restrictions for addresses in the allowlist, allowing them to transfer tokens even when {isTransferable} returns false. For non-allowlisted addresses, applies non-transferable checks.
202
+ /// @param from The address sending the tokens.
203
+ /// @param to The address receiving the tokens.
204
+ /// @param amount The amount of tokens being transferred.
205
+ /// @param force Whether to force the transfer (passed to _nonTransferableCheck).
206
+ /// @param data Additional data for the transfer (passed to _nonTransferableCheck).
207
+ function _beforeTokenTransfer(
208
+ address from,
209
+ address to,
210
+ uint256 amount,
211
+ bool force,
212
+ bytes memory data
213
+ ) internal virtual override {
214
+ _nonTransferableCheck(from, to, amount, force, data);
215
+ super._beforeTokenTransfer(from, to, amount, force, data);
216
+ }
217
+
218
+ function _transferOwnership(
219
+ address newOwner
220
+ )
221
+ internal
222
+ virtual
223
+ override(AccessControlExtendedInitAbstract, OwnableUpgradeable)
224
+ {
225
+ // restore default admin hierarchy so a previously-installed custom admin
226
+ // cannot grant NON_TRANSFERABLE_BYPASS_ROLE to new accounts post-transfer
227
+ _setRoleAdmin(NON_TRANSFERABLE_BYPASS_ROLE, DEFAULT_ADMIN_ROLE);
228
+ super._transferOwnership(newOwner);
229
+ }
230
+
231
+ /**
232
+ * @dev This empty reserved space is put in place to allow future versions to add new
233
+ * variables without shifting down storage in the inheritance chain.
234
+ * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
235
+ *
236
+ * @custom:info The size of the `__gap` array is calculated so that the amount of storage used by the contract
237
+ * always adds up to the same number (in this case 50 storage slots).
238
+ */
239
+ uint256[47] private __gap;
240
+ }
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ /// @title ILSP7Revokable
5
+ /// @dev Interface for LSP7 tokens that can be revoked by addresses holding `REVOKER_ROLE`.
6
+ /// This extension allows authorized revokers to reclaim tokens from any holder back to the
7
+ /// contract owner or another authorized revoker.
8
+ interface ILSP7Revokable {
9
+ /// @dev Emitted when revokable status is changed.
10
+ event RevokableStatusChanged(bool indexed enabled);
11
+
12
+ /// @notice Returns whether the feature to revoke tokens from users is enabled or not.
13
+ function isRevokable() external view returns (bool);
14
+
15
+ /// @notice Disables token revocation permanently.
16
+ /// @dev Can only be called by the contract owner. Prevents further calls to revoke after invocation.
17
+ function disableRevokable() external;
18
+
19
+ /// @notice Revokes tokens from a holder and transfers them to `to`.
20
+ /// @dev Can only be called by an address holding `REVOKER_ROLE`.
21
+ /// The destination must be either the contract owner or an address holding `REVOKER_ROLE`.
22
+ /// The original token holder will be notified via LSP1 universalReceiver.
23
+ /// @param from The address to revoke tokens from.
24
+ /// @param to The address receiving the revoked tokens.
25
+ /// @param amount The amount of tokens to revoke.
26
+ /// @param data Additional data to include in the transfer notification.
27
+ function revoke(address from, address to, uint256 amount, bytes memory data) external;
28
+ }
@@ -0,0 +1,130 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ // modules
5
+ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
6
+ import {LSP7DigitalAsset} from "../../LSP7DigitalAsset.sol";
7
+ import {
8
+ AccessControlExtendedAbstract
9
+ } from "../AccessControlExtended/AccessControlExtendedAbstract.sol";
10
+
11
+ // interfaces
12
+ import {ILSP7Revokable} from "./ILSP7Revokable.sol";
13
+
14
+ // errors
15
+ import {
16
+ AccessControlUnauthorizedAccount
17
+ } from "../AccessControlExtended/AccessControlExtendedErrors.sol";
18
+ import {LSP7RevokableFeatureDisabled} from "./LSP7RevokableErrors.sol";
19
+
20
+ /// @title LSP7RevokableAbstract
21
+ /// @dev Abstract contract implementing revokable functionality for LSP7 tokens.
22
+ /// Allows addresses with the `REVOKER_ROLE` to revoke tokens from any holder
23
+ /// back to the contract owner or any other address that also has revoke rights.
24
+ ///
25
+ /// Use cases include:
26
+ /// - Memberships: Revoke membership tokens when they expire or are terminated
27
+ /// - Role badges: Remove role badges from community members
28
+ /// - Compliance: Freeze or reverse tokens for regulatory requirements
29
+ /// - Vesting: Revoke unvested tokens if conditions are not met
30
+ abstract contract LSP7RevokableAbstract is
31
+ ILSP7Revokable,
32
+ LSP7DigitalAsset,
33
+ AccessControlExtendedAbstract
34
+ {
35
+ bool internal _isRevokable;
36
+
37
+ /// @dev keccak256("REVOKER_ROLE")
38
+ bytes32 public constant REVOKER_ROLE =
39
+ 0xce3f34913921da558f105cefb578d87278debbbd073a8d552b5de0d168deee30;
40
+
41
+ constructor(bool isRevokable_) {
42
+ _isRevokable = isRevokable_;
43
+
44
+ if (isRevokable_) {
45
+ _grantRole(REVOKER_ROLE, owner());
46
+ }
47
+ }
48
+
49
+ /// @inheritdoc ILSP7Revokable
50
+ function isRevokable() public view virtual override returns (bool) {
51
+ return _isRevokable;
52
+ }
53
+
54
+ /// @inheritdoc ILSP7Revokable
55
+ /// @custom:warning Once this function is called, any address holding the `REVOKER_ROLE` will be inoperable.
56
+ /// @custom:info The list of addresses holding the `REVOKER_ROLE` remains populated after the revokable feature is switched off.
57
+ function disableRevokable() public virtual override onlyOwner {
58
+ require(isRevokable(), LSP7RevokableFeatureDisabled());
59
+ _isRevokable = false;
60
+ emit RevokableStatusChanged({enabled: false});
61
+ }
62
+
63
+ /// @inheritdoc ILSP7Revokable
64
+ function revoke(
65
+ address from,
66
+ address to,
67
+ uint256 amount,
68
+ bytes memory data
69
+ ) public virtual override onlyRole(REVOKER_ROLE) {
70
+ require(isRevokable(), LSP7RevokableFeatureDisabled());
71
+ require(
72
+ to == owner() || hasRole(REVOKER_ROLE, to),
73
+ AccessControlUnauthorizedAccount(to, REVOKER_ROLE)
74
+ );
75
+
76
+ // We assume revokers are trusted when specifying revocation destinations.
77
+ // Therefore, we bypass LSP1 receiver checks.
78
+ _transfer({
79
+ from: from,
80
+ to: to,
81
+ amount: amount,
82
+ force: true,
83
+ data: data
84
+ });
85
+ }
86
+
87
+ function supportsInterface(
88
+ bytes4 interfaceId
89
+ )
90
+ public
91
+ view
92
+ virtual
93
+ override(AccessControlExtendedAbstract, LSP7DigitalAsset)
94
+ returns (bool)
95
+ {
96
+ return
97
+ AccessControlExtendedAbstract.supportsInterface(interfaceId) ||
98
+ LSP7DigitalAsset.supportsInterface(interfaceId);
99
+ }
100
+
101
+ /// @dev Overridden function to ensure previous revokers do not persist after contract ownership has been transferred.
102
+ /// The only exception is if the old contract owner had the `REVOKER_ROLE`. This role will be given to the new owner.
103
+ ///
104
+ /// @custom:warning This function clears the entire `REVOKER_ROLE` member set.
105
+ /// - Gas cost scales linearly with the number of addresses with the `REVOKER_ROLE`.
106
+ /// - If the number of addresses with the `REVOKER_ROLE` is large, it might consume a lot of gas,
107
+ /// leading the transaction to approach or exceed the block gas limit and fail.
108
+ /// Consider revoking addresses with the `REVOKER_ROLE` in batches in separate transactions to mitigate this.
109
+ function _transferOwnership(
110
+ address newOwner
111
+ ) internal virtual override(AccessControlExtendedAbstract, Ownable) {
112
+ // restore default admin hierarchy so a previously-installed custom admin
113
+ // cannot grant REVOKER_ROLE to new accounts post-transfer
114
+ _setRoleAdmin(REVOKER_ROLE, DEFAULT_ADMIN_ROLE);
115
+
116
+ // Transfer all roles from old owner to new owner first (including the `REVOKER_ROLE`)
117
+ // before clearing the list of revokers.
118
+ super._transferOwnership(newOwner);
119
+
120
+ address[] memory revokers = getRoleMembers(REVOKER_ROLE);
121
+
122
+ for (uint256 ii = 0; ii < revokers.length; ++ii) {
123
+ // Exclude the new owner from the list of revokers to delete.
124
+ address revoker = revokers[ii];
125
+ if (revoker == newOwner) continue;
126
+
127
+ _revokeRole(REVOKER_ROLE, revoker);
128
+ }
129
+ }
130
+ }
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ error LSP7RevokableFeatureDisabled();