@lukso/lsp7-contracts 0.16.8 → 0.18.1

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 +100 -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 +116 -0
  9. package/artifacts/ILSP7Revokable.json +112 -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 +1647 -0
  17. package/artifacts/LSP7CustomizableTokenInit.json +1644 -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 +1242 -0
  25. package/artifacts/LSP7NonTransferableInitAbstract.json +1250 -0
  26. package/artifacts/LSP7RevokableAbstract.json +1223 -0
  27. package/artifacts/LSP7RevokableInitAbstract.json +1231 -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 +54 -0
  52. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableAbstract.sol +192 -0
  53. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableErrors.sol +14 -0
  54. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableInitAbstract.sol +249 -0
  55. package/contracts/extensions/LSP7Revokable/ILSP7Revokable.sol +37 -0
  56. package/contracts/extensions/LSP7Revokable/LSP7RevokableAbstract.sol +138 -0
  57. package/contracts/extensions/LSP7Revokable/LSP7RevokableErrors.sol +4 -0
  58. package/contracts/extensions/LSP7Revokable/LSP7RevokableInitAbstract.sol +191 -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 +7664 -59
  68. package/dist/abi.d.cts +11223 -277
  69. package/dist/abi.d.mts +11223 -277
  70. package/dist/abi.d.ts +11223 -277
  71. package/dist/abi.mjs +7648 -59
  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,54 @@
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 nonTransferabilityEnabled Whether the non-transferability feature is enabled or not.
9
+ /// @param start The new start timestamp of the transfer lock period.
10
+ /// @param end The new end timestamp of the transfer lock period.
11
+ event TransferLockPeriodChanged(
12
+ bool indexed nonTransferabilityEnabled,
13
+ uint256 indexed start,
14
+ uint256 indexed end
15
+ );
16
+
17
+ /// @notice The start timestamp of the transfer lock period, at which point the token becomes non-transferable.
18
+ function transferLockStart() external view returns (uint256);
19
+
20
+ /// @notice The end timestamp of the transfer lock period, at which point the token becomes transferable again.
21
+ function transferLockEnd() external view returns (uint256);
22
+
23
+ /// @notice Returns whether the transfer lock feature is still enabled.
24
+ /// @dev When this returns `false`, the token has been permanently made transferable and the lock period can no longer be updated.
25
+ function nonTransferabilityEnabled() external view returns (bool);
26
+
27
+ /// @notice Checks if the token is currently transferable.
28
+ /// @dev Returns true if the token is currently transferable. When `nonTransferabilityEnabled` is true, this is derived from the configured lock period. When `nonTransferabilityEnabled` 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.
29
+ /// @return A `true` or `false` boolean indicating if the token is transferable or not.
30
+ function isTransferable() external view returns (bool);
31
+
32
+ /// @notice Removes all transfer lock periods, enabling token transfers for non-allowlisted addresses.
33
+ /// @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.
34
+ /// @custom:emits {TransferLockPeriodChanged} event.
35
+ function makeTransferable() external;
36
+
37
+ /// @notice Updates the transfer lock period with new start and end timestamps.
38
+ /// - 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`.
39
+ /// - 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).
40
+ ///
41
+ /// - To make the token always non-transferable, set `transferLockStart` to 0 and `transferLockEnd` to type(uint256).max.
42
+ /// - To remove the active lock while keeping the non-transferability feature configurable, set both `newTransferLockStart` and `newTransferLockEnd` to 0. In this state, transfers are currently unrestricted, but the owner can still configure a new lock period later.
43
+ /// - To permanently disable the non-transferability feature and prevent future lock-period updates, use the {makeTransferable} function.
44
+ ///
45
+ /// @dev Can only be called by the contract owner. Reverts once {makeTransferable} has been called.
46
+ ///
47
+ /// @custom:emits {TransferLockPeriodChanged} event.
48
+ /// @param newTransferLockStart The new start timestamp for the transfer lock period.
49
+ /// @param newTransferLockEnd The new end timestamp for the transfer lock period.
50
+ function updateTransferLockPeriod(
51
+ uint256 newTransferLockStart,
52
+ uint256 newTransferLockEnd
53
+ ) external;
54
+ }
@@ -0,0 +1,192 @@
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 nonTransferabilityEnabled;
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
+ nonTransferabilityEnabled = true;
53
+
54
+ emit TransferLockPeriodChanged({
55
+ nonTransferabilityEnabled: true,
56
+ start: transferLockStart_,
57
+ end: transferLockEnd_
58
+ });
59
+ _grantRole(NON_TRANSFERABLE_BYPASS_ROLE, owner());
60
+ }
61
+
62
+ function supportsInterface(
63
+ bytes4 interfaceId
64
+ )
65
+ public
66
+ view
67
+ virtual
68
+ override(AccessControlExtendedAbstract, LSP7DigitalAsset)
69
+ returns (bool)
70
+ {
71
+ return
72
+ AccessControlExtendedAbstract.supportsInterface(interfaceId) ||
73
+ LSP7DigitalAsset.supportsInterface(interfaceId);
74
+ }
75
+
76
+ /// @inheritdoc ILSP7NonTransferable
77
+ function isTransferable() public view virtual override returns (bool) {
78
+ if (!nonTransferabilityEnabled) return true;
79
+
80
+ bool isTransferLockStartEnabled = transferLockStart != 0;
81
+ bool isTransferLockEndEnabled = transferLockEnd != 0;
82
+
83
+ // If both lock periods are disabled, the token is transferable
84
+ if (!isTransferLockStartEnabled && !isTransferLockEndEnabled) {
85
+ return true;
86
+ }
87
+
88
+ // If the token is non-transferable up to a certain point in time, check if we have passed this period
89
+ if (!isTransferLockStartEnabled && isTransferLockEndEnabled) {
90
+ return transferLockEnd < block.timestamp;
91
+ }
92
+
93
+ // If the token becomes non-transferable starting at a specific point in time, check if we have reached this lock starting period
94
+ if (isTransferLockStartEnabled && !isTransferLockEndEnabled) {
95
+ return transferLockStart > block.timestamp;
96
+ }
97
+
98
+ // This last case checks if we are within the transfer lock period
99
+ return
100
+ transferLockStart > block.timestamp ||
101
+ transferLockEnd < block.timestamp;
102
+ }
103
+
104
+ /// @inheritdoc ILSP7NonTransferable
105
+ /// @custom:info The list of addresses holding the `NON_TRANSFERABLE_BYPASS_ROLE` remains populated after the non-transferable feature is switched off.
106
+ function makeTransferable() public virtual override onlyOwner {
107
+ require(nonTransferabilityEnabled, LSP7TokenAlreadyTransferable());
108
+
109
+ nonTransferabilityEnabled = false;
110
+ transferLockStart = 0;
111
+ transferLockEnd = 0;
112
+
113
+ emit TransferLockPeriodChanged({
114
+ nonTransferabilityEnabled: false,
115
+ start: 0,
116
+ end: 0
117
+ });
118
+ }
119
+
120
+ /// @inheritdoc ILSP7NonTransferable
121
+ function updateTransferLockPeriod(
122
+ uint256 newTransferLockStart,
123
+ uint256 newTransferLockEnd
124
+ ) public virtual override onlyOwner {
125
+ require(nonTransferabilityEnabled, LSP7CannotUpdateTransferLockPeriod());
126
+
127
+ // When `transferLockEnd` is 0, it means no end time is set (transfers locked indefinitely since `transferLockStart`)
128
+ // When `transferLockStart` is 0, it means no start time is set (transfers locked up until `transferLockEnd`)
129
+ // Allow to make the token always non-transferable, or ensure the end period for locking transfers is always later than the starting period
130
+ require(
131
+ newTransferLockEnd == 0 ||
132
+ newTransferLockEnd >= newTransferLockStart,
133
+ LSP7InvalidTransferLockPeriod()
134
+ );
135
+
136
+ transferLockStart = newTransferLockStart;
137
+ transferLockEnd = newTransferLockEnd;
138
+
139
+ emit TransferLockPeriodChanged({
140
+ nonTransferabilityEnabled: true,
141
+ start: newTransferLockStart,
142
+ end: newTransferLockEnd
143
+ });
144
+ }
145
+
146
+ /// @notice Checks if a token transfer is allowed based on transferability status.
147
+ /// @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).
148
+ /// @param to The address receiving the tokens.
149
+ function _nonTransferableCheck(
150
+ address from,
151
+ address to,
152
+ uint256 /* amount */,
153
+ bool /* force */,
154
+ bytes memory /* data */
155
+ ) internal virtual {
156
+ // Allow minting and burning
157
+ if (from == address(0) || to == address(0)) return;
158
+
159
+ // Do not check for addresses exempted from non transferable check
160
+ if (hasRole(NON_TRANSFERABLE_BYPASS_ROLE, from)) return;
161
+
162
+ // transferring tokens only if the transferability status is enabled
163
+ require(isTransferable(), LSP7TransferDisabled());
164
+ }
165
+
166
+ /// @notice Hook called before a token transfer to enforce transfer restrictions.
167
+ /// @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.
168
+ /// @param from The address sending the tokens.
169
+ /// @param to The address receiving the tokens.
170
+ /// @param amount The amount of tokens being transferred.
171
+ /// @param force Whether to force the transfer (passed to _nonTransferableCheck).
172
+ /// @param data Additional data for the transfer (passed to _nonTransferableCheck).
173
+ function _beforeTokenTransfer(
174
+ address from,
175
+ address to,
176
+ uint256 amount,
177
+ bool force,
178
+ bytes memory data
179
+ ) internal virtual override {
180
+ _nonTransferableCheck(from, to, amount, force, data);
181
+ super._beforeTokenTransfer(from, to, amount, force, data);
182
+ }
183
+
184
+ function _transferOwnership(
185
+ address newOwner
186
+ ) internal virtual override(AccessControlExtendedAbstract, Ownable) {
187
+ // restore default admin hierarchy so a previously-installed custom admin
188
+ // cannot grant NON_TRANSFERABLE_BYPASS_ROLE to new accounts post-transfer
189
+ _setRoleAdmin(NON_TRANSFERABLE_BYPASS_ROLE, DEFAULT_ADMIN_ROLE);
190
+ super._transferOwnership(newOwner);
191
+ }
192
+ }
@@ -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,249 @@
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 nonTransferabilityEnabled;
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
+ nonTransferabilityEnabled = true;
93
+
94
+ emit TransferLockPeriodChanged({
95
+ nonTransferabilityEnabled: true,
96
+ start: transferLockStart_,
97
+ end: transferLockEnd_
98
+ });
99
+ _grantRole(NON_TRANSFERABLE_BYPASS_ROLE, owner());
100
+ }
101
+
102
+ function supportsInterface(
103
+ bytes4 interfaceId
104
+ )
105
+ public
106
+ view
107
+ virtual
108
+ override(
109
+ AccessControlExtendedInitAbstract,
110
+ LSP7DigitalAssetInitAbstract
111
+ )
112
+ returns (bool)
113
+ {
114
+ return
115
+ AccessControlExtendedInitAbstract.supportsInterface(interfaceId) ||
116
+ LSP7DigitalAssetInitAbstract.supportsInterface(interfaceId);
117
+ }
118
+
119
+ /// @inheritdoc ILSP7NonTransferable
120
+ function isTransferable() public view virtual override returns (bool) {
121
+ if (!nonTransferabilityEnabled) return true;
122
+
123
+ bool isTransferLockStartEnabled = transferLockStart != 0;
124
+ bool isTransferLockEndEnabled = transferLockEnd != 0;
125
+
126
+ // If both lock periods are disabled, the token is transferable
127
+ if (!isTransferLockStartEnabled && !isTransferLockEndEnabled) {
128
+ return true;
129
+ }
130
+
131
+ // If the token is non-transferable up to a certain point in time, check if we have passed this period
132
+ if (!isTransferLockStartEnabled && isTransferLockEndEnabled) {
133
+ return transferLockEnd < block.timestamp;
134
+ }
135
+
136
+ // If the token becomes non-transferable starting at a specific point in time, check if we have reached this lock starting period
137
+ if (isTransferLockStartEnabled && !isTransferLockEndEnabled) {
138
+ return transferLockStart > block.timestamp;
139
+ }
140
+
141
+ // This last case checks if we are within the transfer lock period
142
+ return
143
+ transferLockStart > block.timestamp ||
144
+ transferLockEnd < block.timestamp;
145
+ }
146
+
147
+ /// @inheritdoc ILSP7NonTransferable
148
+ /// @custom:info The list of addresses holding the `NON_TRANSFERABLE_BYPASS_ROLE` remains populated after the non-transferable feature is switched off.
149
+ function makeTransferable() public virtual override onlyOwner {
150
+ require(nonTransferabilityEnabled, LSP7TokenAlreadyTransferable());
151
+
152
+ nonTransferabilityEnabled = false;
153
+ transferLockStart = 0;
154
+ transferLockEnd = 0;
155
+
156
+ emit TransferLockPeriodChanged({
157
+ nonTransferabilityEnabled: false,
158
+ start: 0,
159
+ end: 0
160
+ });
161
+ }
162
+
163
+ /// @inheritdoc ILSP7NonTransferable
164
+ function updateTransferLockPeriod(
165
+ uint256 newTransferLockStart,
166
+ uint256 newTransferLockEnd
167
+ ) public virtual override onlyOwner {
168
+ require(nonTransferabilityEnabled, LSP7CannotUpdateTransferLockPeriod());
169
+
170
+ // When transferLockEnd is 0, it means no end time is set (transfers locked indefinitely after transferLockStart)
171
+ // When transferLockStart is 0, it means no start time is set (transfers locked up until transferLockEnd)
172
+ // Allow to make the token always non-transferable, or ensure the end period for locking transfers is always later than the starting period
173
+ require(
174
+ newTransferLockEnd == 0 ||
175
+ newTransferLockEnd >= newTransferLockStart,
176
+ LSP7InvalidTransferLockPeriod()
177
+ );
178
+
179
+ transferLockStart = newTransferLockStart;
180
+ transferLockEnd = newTransferLockEnd;
181
+
182
+ emit TransferLockPeriodChanged({
183
+ nonTransferabilityEnabled: true,
184
+ start: newTransferLockStart,
185
+ end: newTransferLockEnd
186
+ });
187
+ }
188
+
189
+ /// @notice Checks if a token transfer is allowed based on transferability status.
190
+ /// @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).
191
+ /// @param to The address receiving the tokens.
192
+ function _nonTransferableCheck(
193
+ address from,
194
+ address to,
195
+ uint256 /* amount */,
196
+ bool /* force */,
197
+ bytes memory /* data */
198
+ ) internal virtual {
199
+ // Allow minting and burning
200
+ if (from == address(0) || to == address(0)) return;
201
+
202
+ // Do not check for addresses exempted from non transferable check
203
+ if (hasRole(NON_TRANSFERABLE_BYPASS_ROLE, from)) return;
204
+
205
+ // transferring tokens only if the transferability status is enabled
206
+ require(isTransferable(), LSP7TransferDisabled());
207
+ }
208
+
209
+ /// @notice Hook called before a token transfer to enforce transfer restrictions.
210
+ /// @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.
211
+ /// @param from The address sending the tokens.
212
+ /// @param to The address receiving the tokens.
213
+ /// @param amount The amount of tokens being transferred.
214
+ /// @param force Whether to force the transfer (passed to _nonTransferableCheck).
215
+ /// @param data Additional data for the transfer (passed to _nonTransferableCheck).
216
+ function _beforeTokenTransfer(
217
+ address from,
218
+ address to,
219
+ uint256 amount,
220
+ bool force,
221
+ bytes memory data
222
+ ) internal virtual override {
223
+ _nonTransferableCheck(from, to, amount, force, data);
224
+ super._beforeTokenTransfer(from, to, amount, force, data);
225
+ }
226
+
227
+ function _transferOwnership(
228
+ address newOwner
229
+ )
230
+ internal
231
+ virtual
232
+ override(AccessControlExtendedInitAbstract, OwnableUpgradeable)
233
+ {
234
+ // restore default admin hierarchy so a previously-installed custom admin
235
+ // cannot grant NON_TRANSFERABLE_BYPASS_ROLE to new accounts post-transfer
236
+ _setRoleAdmin(NON_TRANSFERABLE_BYPASS_ROLE, DEFAULT_ADMIN_ROLE);
237
+ super._transferOwnership(newOwner);
238
+ }
239
+
240
+ /**
241
+ * @dev This empty reserved space is put in place to allow future versions to add new
242
+ * variables without shifting down storage in the inheritance chain.
243
+ * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
244
+ *
245
+ * @custom:info The size of the `__gap` array is calculated so that the amount of storage used by the contract
246
+ * always adds up to the same number (in this case 50 storage slots).
247
+ */
248
+ uint256[47] private __gap;
249
+ }
@@ -0,0 +1,37 @@
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
+ /// @dev Emitted when tokens are revoked from a holder.
13
+ event TokenRevoked(
14
+ address indexed revoker,
15
+ address indexed from,
16
+ address indexed to,
17
+ uint256 amount,
18
+ bytes data
19
+ );
20
+
21
+ /// @notice Returns whether the feature to revoke tokens from users is enabled or not.
22
+ function isRevokable() external view returns (bool);
23
+
24
+ /// @notice Disables token revocation permanently.
25
+ /// @dev Can only be called by the contract owner. Prevents further calls to revoke after invocation.
26
+ function disableRevokable() external;
27
+
28
+ /// @notice Revokes tokens from a holder and transfers them to `to`.
29
+ /// @dev Can only be called by an address holding `REVOKER_ROLE`.
30
+ /// The destination must be either the contract owner or an address holding `REVOKER_ROLE`.
31
+ /// The original token holder will be notified via LSP1 universalReceiver.
32
+ /// @param from The address to revoke tokens from.
33
+ /// @param to The address receiving the revoked tokens.
34
+ /// @param amount The amount of tokens to revoke.
35
+ /// @param data Additional data to include in the transfer notification.
36
+ function revoke(address from, address to, uint256 amount, bytes memory data) external;
37
+ }