@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,179 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
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 {ILSP7CappedBalance} from "./ILSP7CappedBalance.sol";
17
+
18
+ // errors
19
+ import {LSP7CappedBalanceExceeded} from "./LSP7CappedBalanceErrors.sol";
20
+
21
+ /// @title LSP7CappedBalanceInitAbstract
22
+ /// @dev Abstract contract implementing a per-address balance cap for LSP7 tokens, with exemptions for allowlisted addresses. Inherits from LSP7AllowlistAbstract to integrate allowlist functionality.
23
+ abstract contract LSP7CappedBalanceInitAbstract is
24
+ ILSP7CappedBalance,
25
+ LSP7DigitalAssetInitAbstract,
26
+ AccessControlExtendedInitAbstract
27
+ {
28
+ /// @notice The dead address is also commonly used for burning tokens as an alternative to address(0).
29
+ address internal constant _DEAD_ADDRESS =
30
+ 0x000000000000000000000000000000000000dEaD;
31
+
32
+ /// @dev keccak256("UNCAPPED_BALANCE_ROLE")
33
+ bytes32 public constant UNCAPPED_BALANCE_ROLE =
34
+ 0x975773d1e0a917a74b57f36a377f439ffff6271648aebdbff75a52ab58eb7bad;
35
+
36
+ /// @notice The immutable maximum token balance allowed per address.
37
+ uint256 private _tokenBalanceCap;
38
+
39
+ /// @notice Initializes the LSP7CappedBalance contract with base token params, balance cap per address,
40
+ /// and `UNCAPPED_BALANCE_ROLE` exemptions for token contract `owner()`, `address(0)` and `0x...dead` addresses (for burning).
41
+ /// @param name_ The name of the token.
42
+ /// @param symbol_ The symbol of the token.
43
+ /// @param newOwner_ The owner of the contract, added to the allowlist.
44
+ /// @param lsp4TokenType_ The token type (see LSP4).
45
+ /// @param isNonDivisible_ Whether the token is non-divisible.
46
+ /// @param tokenBalanceCap_ The maximum balance per address in wei, 0 to disable.
47
+ function __LSP7CappedBalance_init(
48
+ string memory name_,
49
+ string memory symbol_,
50
+ address newOwner_,
51
+ uint256 lsp4TokenType_,
52
+ bool isNonDivisible_,
53
+ uint256 tokenBalanceCap_
54
+ ) internal virtual onlyInitializing {
55
+ LSP7DigitalAssetInitAbstract._initialize(
56
+ name_,
57
+ symbol_,
58
+ newOwner_,
59
+ lsp4TokenType_,
60
+ isNonDivisible_
61
+ );
62
+ __AccessControlExtended_init();
63
+ __LSP7CappedBalance_init_unchained(tokenBalanceCap_);
64
+ }
65
+
66
+ /// @notice Unchained initializer for the token balance cap.
67
+ /// @dev Sets the balance cap. If set, grants the initial uncapped balance role exemption to the contract owner.
68
+ /// @param tokenBalanceCap_ The maximum balance allowed per token holder (in wei). Set to 0 to disable.
69
+ function __LSP7CappedBalance_init_unchained(
70
+ uint256 tokenBalanceCap_
71
+ ) internal virtual onlyInitializing {
72
+ _tokenBalanceCap = tokenBalanceCap_;
73
+
74
+ if (tokenBalanceCap_ != 0) {
75
+ _grantRole(UNCAPPED_BALANCE_ROLE, owner());
76
+ }
77
+ }
78
+
79
+ /// @inheritdoc ILSP7CappedBalance
80
+ function tokenBalanceCap() public view virtual override returns (uint256) {
81
+ return _tokenBalanceCap;
82
+ }
83
+
84
+ function supportsInterface(
85
+ bytes4 interfaceId
86
+ )
87
+ public
88
+ view
89
+ virtual
90
+ override(
91
+ AccessControlExtendedInitAbstract,
92
+ LSP7DigitalAssetInitAbstract
93
+ )
94
+ returns (bool)
95
+ {
96
+ return
97
+ AccessControlExtendedInitAbstract.supportsInterface(interfaceId) ||
98
+ LSP7DigitalAssetInitAbstract.supportsInterface(interfaceId);
99
+ }
100
+
101
+ /// @notice Checks if a token transfer complies with the balance cap.
102
+ /// @dev The address(0) is not subject to balance cap checks as this address is used for burning tokens. Reverts with {LSP7CappedBalanceExceeded} if the recipient's balance after receiving tokens would exceed the maximum allowed balance.
103
+ /// @param from The address sending the tokens.
104
+ /// @param to The address receiving the tokens.
105
+ /// @param amount The amount of tokens being transferred.
106
+ function _tokenBalanceCapCheck(
107
+ address from,
108
+ address to,
109
+ uint256 amount,
110
+ bool,
111
+ /* force */
112
+ bytes memory /* data */
113
+ ) internal virtual {
114
+ // self-transfers do not increase the balance of the recipient, so we skip the check
115
+ if (from == to) return;
116
+
117
+ // Address(0) and 0x0000...dead addresses are used for burning tokens
118
+ if (to == address(0) || to == _DEAD_ADDRESS) return;
119
+
120
+ // Do not check for addresses exempted from balance cap
121
+ if (hasRole(UNCAPPED_BALANCE_ROLE, to)) return;
122
+
123
+ uint256 maxBalanceAllowed = tokenBalanceCap();
124
+ bool isBalanceCapEnabled = maxBalanceAllowed != 0;
125
+
126
+ if (!isBalanceCapEnabled) return;
127
+
128
+ require(
129
+ (balanceOf(to) + amount) <= maxBalanceAllowed,
130
+ LSP7CappedBalanceExceeded(
131
+ to,
132
+ amount,
133
+ balanceOf(to),
134
+ maxBalanceAllowed
135
+ )
136
+ );
137
+ }
138
+
139
+ /// @notice Hook called before a token transfer to enforce balance cap restrictions.
140
+ /// @dev Bypasses balance cap checks for allowlisted recipients. Applies cap checks for non-allowlisted recipients.
141
+ /// @param from The address sending the tokens.
142
+ /// @param to The address receiving the tokens.
143
+ /// @param amount The amount of tokens being transferred.
144
+ /// @param force Whether to force the transfer.
145
+ /// @param data Additional data for the transfer.
146
+ function _beforeTokenTransfer(
147
+ address from,
148
+ address to,
149
+ uint256 amount,
150
+ bool force,
151
+ bytes memory data
152
+ ) internal virtual override {
153
+ _tokenBalanceCapCheck(from, to, amount, force, data);
154
+ super._beforeTokenTransfer(from, to, amount, force, data);
155
+ }
156
+
157
+ function _transferOwnership(
158
+ address newOwner
159
+ )
160
+ internal
161
+ virtual
162
+ override(AccessControlExtendedInitAbstract, OwnableUpgradeable)
163
+ {
164
+ // restore default admin hierarchy so a previously-installed custom admin
165
+ // cannot grant UNCAPPED_BALANCE_ROLE to new accounts post-transfer
166
+ _setRoleAdmin(UNCAPPED_BALANCE_ROLE, DEFAULT_ADMIN_ROLE);
167
+ super._transferOwnership(newOwner);
168
+ }
169
+
170
+ /**
171
+ * @dev This empty reserved space is put in place to allow future versions to add new
172
+ * variables without shifting down storage in the inheritance chain.
173
+ * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
174
+ *
175
+ * @custom:info The size of the `__gap` array is calculated so that the amount of storage used by the contract
176
+ * always adds up to the same number (in this case 50 storage slots).
177
+ */
178
+ uint256[49] private __gap;
179
+ }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ /// @title ILSP7CappedSupply
5
+ /// @dev Interface for an LSP7 token extension that enforces a max token supply cap.
6
+ interface ILSP7CappedSupply {
7
+ /// @notice The maximum supply amount of tokens allowed to exist is `_TOKEN_SUPPLY_CAP`.
8
+ /// @dev Get the maximum number of tokens that can exist to circulate. Once {totalSupply} reaches {totalSupplyCap}, it is not possible to mint more tokens.
9
+ /// @return The maximum number of tokens that can exist in the contract.
10
+ function tokenSupplyCap() external view returns (uint256);
11
+ }
@@ -0,0 +1,56 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ // modules
5
+ import {LSP7DigitalAsset} from "../../LSP7DigitalAsset.sol";
6
+
7
+ // errors
8
+ import {LSP7CappedSupplyCannotMintOverCap} from "./LSP7CappedSupplyErrors.sol";
9
+
10
+ /// @title LSP7CappedSupplyAbstract
11
+ /// @dev Abstract contract implementing a token supply cap.
12
+ abstract contract LSP7CappedSupplyAbstract is LSP7DigitalAsset {
13
+ uint256 private immutable _TOKEN_SUPPLY_CAP;
14
+
15
+ /// @notice Deploying a `LSP7CappedSupply` token contract with max token supply cap set to `tokenSupplyCap_`.
16
+ /// @dev Deploy a `LSP7CappedSupply` token contract and set the maximum token supply token cap up to which it is not possible to mint more tokens.
17
+ /// @param tokenSupplyCap_ The maximum total supply in wei, 0 to disable.
18
+ constructor(uint256 tokenSupplyCap_) {
19
+ _TOKEN_SUPPLY_CAP = tokenSupplyCap_;
20
+ }
21
+
22
+ /// @notice The maximum supply amount of tokens allowed to exist is `_TOKEN_SUPPLY_CAP`.
23
+ /// @dev Get the maximum number of tokens that can exist to circulate. Once {totalSupply} reaches {totalSupplyCap}, it is not possible to mint more tokens.
24
+ /// @return The maximum number of tokens that can exist in the contract.
25
+ function tokenSupplyCap() public view virtual returns (uint256) {
26
+ return _TOKEN_SUPPLY_CAP;
27
+ }
28
+
29
+ /// @dev Checks if minting `amount` of tokens would exceed the token supply cap.
30
+ function _tokenSupplyCapCheck(
31
+ address,
32
+ /* to */
33
+ uint256 amount,
34
+ bool,
35
+ /* force */
36
+ bytes memory /* data */
37
+ ) internal virtual {
38
+ require(
39
+ tokenSupplyCap() == 0 ||
40
+ (totalSupply() + amount) <= tokenSupplyCap(),
41
+ LSP7CappedSupplyCannotMintOverCap()
42
+ );
43
+ }
44
+
45
+ /// @dev Same as {_mint} but allows to mint only if the {totalSupply}
46
+ /// does not exceed the {tokenSupplyCap} after `amount` of tokens have been minted.
47
+ function _mint(
48
+ address to,
49
+ uint256 amount,
50
+ bool force,
51
+ bytes memory data
52
+ ) internal virtual override {
53
+ _tokenSupplyCapCheck(to, amount, force, data);
54
+ super._mint(to, amount, force, data);
55
+ }
56
+ }
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ /// @notice Cannot mint anymore as total supply reached the maximum cap.
5
+ /// @dev Reverts when trying to mint tokens but the {totalSupply} has reached the maximum {tokenSupplyCap}.
6
+ error LSP7CappedSupplyCannotMintOverCap();
@@ -0,0 +1,96 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ // modules
5
+ import {
6
+ LSP7DigitalAssetInitAbstract
7
+ } from "../../LSP7DigitalAssetInitAbstract.sol";
8
+
9
+ // errors
10
+ import {LSP7CappedSupplyCannotMintOverCap} from "./LSP7CappedSupplyErrors.sol";
11
+
12
+ /**
13
+ * @dev LSP7 token extension to add a max token supply cap (proxy version).
14
+ */
15
+ abstract contract LSP7CappedSupplyInitAbstract is LSP7DigitalAssetInitAbstract {
16
+ /// @notice The maximum token supply.
17
+ uint256 private _tokenSupplyCap;
18
+
19
+ /// @notice Initializes the LSP7CappedSupply contract with base token params and supply cap.
20
+ /// @dev Initializes the LSP7DigitalAsset base and sets the maximum token supply cap.
21
+ /// @param name_ The name of the token.
22
+ /// @param symbol_ The symbol of the token.
23
+ /// @param newOwner_ The owner of the contract.
24
+ /// @param lsp4TokenType_ The token type (see LSP4).
25
+ /// @param isNonDivisible_ Whether the token is non-divisible.
26
+ /// @param tokenSupplyCap_ The maximum total supply in wei, 0 to disable.
27
+ function __LSP7CappedSupply_init(
28
+ string memory name_,
29
+ string memory symbol_,
30
+ address newOwner_,
31
+ uint256 lsp4TokenType_,
32
+ bool isNonDivisible_,
33
+ uint256 tokenSupplyCap_
34
+ ) internal virtual onlyInitializing {
35
+ LSP7DigitalAssetInitAbstract._initialize(
36
+ name_,
37
+ symbol_,
38
+ newOwner_,
39
+ lsp4TokenType_,
40
+ isNonDivisible_
41
+ );
42
+ __LSP7CappedSupply_init_unchained(tokenSupplyCap_);
43
+ }
44
+
45
+ /// @notice Unchained initializer for the token supply cap.
46
+ /// @dev Sets the maximum token supply cap.
47
+ /// @param tokenSupplyCap_ The maximum total supply in wei, 0 to disable.
48
+ function __LSP7CappedSupply_init_unchained(
49
+ uint256 tokenSupplyCap_
50
+ ) internal virtual onlyInitializing {
51
+ _tokenSupplyCap = tokenSupplyCap_;
52
+ }
53
+
54
+ /// @notice The maximum supply amount of tokens allowed to exist is `_tokenSupplyCap`.
55
+ /// @dev Get the maximum number of tokens that can exist to circulate. Once {totalSupply} reaches {totalSupplyCap}, it is not possible to mint more tokens.
56
+ /// @return The maximum number of tokens that can exist in the contract.
57
+ function tokenSupplyCap() public view virtual returns (uint256) {
58
+ return _tokenSupplyCap;
59
+ }
60
+
61
+ /// @dev Checks if minting `amount` of tokens would exceed the token supply cap.
62
+ function _tokenSupplyCapCheck(
63
+ address /* to */,
64
+ uint256 amount,
65
+ bool /* force */,
66
+ bytes memory /* data */
67
+ ) internal virtual {
68
+ require(
69
+ tokenSupplyCap() == 0 ||
70
+ (totalSupply() + amount) <= tokenSupplyCap(),
71
+ LSP7CappedSupplyCannotMintOverCap()
72
+ );
73
+ }
74
+
75
+ /// @dev Same as {_mint} but allows to mint only if the {totalSupply}
76
+ /// does not exceed the {tokenSupplyCap} after `amount` of tokens have been minted.
77
+ function _mint(
78
+ address to,
79
+ uint256 amount,
80
+ bool force,
81
+ bytes memory data
82
+ ) internal virtual override {
83
+ _tokenSupplyCapCheck(to, amount, force, data);
84
+ super._mint(to, amount, force, data);
85
+ }
86
+
87
+ /**
88
+ * @dev This empty reserved space is put in place to allow future versions to add new
89
+ * variables without shifting down storage in the inheritance chain.
90
+ * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
91
+ *
92
+ * @custom:info The size of the `__gap` array is calculated so that the amount of storage used by the contract
93
+ * always adds up to the same number (in this case 50 storage slots).
94
+ */
95
+ uint256[49] private __gap;
96
+ }
@@ -0,0 +1,27 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ /// @title ILSP7Mintable
5
+ /// @dev Interface for a isMintable LSP7 token extension, allowing the owner to mint new tokens and disable minting.
6
+ interface ILSP7Mintable {
7
+ /// @dev Emitted when minting status is changed.
8
+ event MintingStatusChanged(bool indexed enabled);
9
+
10
+ /// @notice Disables minting of new tokens permanently.
11
+ /// @dev Can only be called by the contract owner. Prevents further calls to mint after invocation.
12
+ /// @custom:events {MintingDisabled} event.
13
+ function disableMinting() external;
14
+
15
+ /// @notice Mints new tokens to a specified address.
16
+ /// @dev Mints `amount` tokens to `to`, callable only by the contract owner. Emits a Transfer event as defined in ILSP7DigitalAsset. Reverts if `to` is the zero address or if minting is disabled.
17
+ /// @param to The address to receive the minted tokens.
18
+ /// @param amount The number of tokens to mint.
19
+ /// @param force When true, allows minting to any address; when false, requires `to` to support LSP1 UniversalReceiver.
20
+ /// @param data Additional data included in the Transfer event and sent to `to`’s UniversalReceiver hook, if applicable.
21
+ function mint(
22
+ address to,
23
+ uint256 amount,
24
+ bool force,
25
+ bytes memory data
26
+ ) external;
27
+ }
@@ -0,0 +1,105 @@
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 {ILSP7Mintable} from "./ILSP7Mintable.sol";
13
+
14
+ // errors
15
+ import {LSP7MintDisabled} from "./LSP7MintableErrors.sol";
16
+
17
+ /// @title LSP7MintableAbstract
18
+ /// @dev Abstract contract implementing a mintable LSP7 token extension, allowing any address granted the `MINTER_ROLE` to mint new tokens until minting is disabled.
19
+ /// Inherits from LSP7DigitalAsset to provide core token functionality.
20
+ abstract contract LSP7MintableAbstract is
21
+ ILSP7Mintable,
22
+ LSP7DigitalAsset,
23
+ AccessControlExtendedAbstract
24
+ {
25
+ /// @notice Indicates whether minting is currently enabled or not.
26
+ bool public isMintable;
27
+
28
+ /// @dev keccak256("MINTER_ROLE")
29
+ bytes32 public constant MINTER_ROLE =
30
+ 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6;
31
+
32
+ /// @notice Initializes the contract with the minting status.
33
+ /// @dev Sets the initial minting status. Inherits LSP7DigitalAsset constructor logic.
34
+ /// @param mintable_ True to enable minting after deployment, false to disable it forever.
35
+ /// @custom:info If `mintable_` is set to `true` then it can be disabled using `disableMinting()` function later on.
36
+ constructor(bool mintable_) {
37
+ isMintable = mintable_;
38
+ emit MintingStatusChanged({enabled: mintable_});
39
+
40
+ if (mintable_) {
41
+ _grantRole(MINTER_ROLE, owner());
42
+ }
43
+ }
44
+
45
+ /// @inheritdoc ILSP7Mintable
46
+ /// @custom:warning Once this function is called, any address holding the `MINTER_ROLE` will be inoperable.
47
+ /// @custom:info The list of addresses holding the `MINTER_ROLE` remains populated after the minting feature is switched off.
48
+ function disableMinting() public virtual override onlyOwner {
49
+ require(isMintable, LSP7MintDisabled());
50
+ isMintable = false;
51
+ emit MintingStatusChanged({enabled: false});
52
+ }
53
+
54
+ /// @inheritdoc ILSP7Mintable
55
+ function mint(
56
+ address to,
57
+ uint256 amount,
58
+ bool force,
59
+ bytes memory data
60
+ ) public virtual override onlyRole(MINTER_ROLE) {
61
+ _mint(to, amount, force, data);
62
+ }
63
+
64
+ function supportsInterface(
65
+ bytes4 interfaceId
66
+ )
67
+ public
68
+ view
69
+ virtual
70
+ override(AccessControlExtendedAbstract, LSP7DigitalAsset)
71
+ returns (bool)
72
+ {
73
+ return
74
+ AccessControlExtendedAbstract.supportsInterface(interfaceId) ||
75
+ LSP7DigitalAsset.supportsInterface(interfaceId);
76
+ }
77
+
78
+ /// @notice Internal function to mint tokens, overridden to enforce minting status.
79
+ /// @dev Checks if minting is enabled, reverting with LSP7MintDisabled if not. Calls the parent _mint function from LSP7DigitalAsset.
80
+ /// @param to The address to receive the minted tokens.
81
+ /// @param amount The number of tokens to mint.
82
+ /// @param force When true, allows minting to any address; when false, requires `to` to support LSP1 UniversalReceiver.
83
+ /// @param data Additional data included in the Transfer event and sent to `to`’s UniversalReceiver hook, if applicable.
84
+ ///
85
+ /// @custom:warning This internal function does not check for `MINTER_ROLE` access control.
86
+ /// Derived contracts that expose this function publicly and want to gate it by `MINTER_ROLE` must enforce it with `onlyRole(MINTER_ROLE)`.
87
+ function _mint(
88
+ address to,
89
+ uint256 amount,
90
+ bool force,
91
+ bytes memory data
92
+ ) internal virtual override {
93
+ require(isMintable, LSP7MintDisabled());
94
+ super._mint(to, amount, force, data);
95
+ }
96
+
97
+ function _transferOwnership(
98
+ address newOwner
99
+ ) internal virtual override(AccessControlExtendedAbstract, Ownable) {
100
+ // restore default admin hierarchy so a previously-installed custom admin
101
+ // cannot grant MINTER_ROLE to new accounts post-transfer
102
+ _setRoleAdmin(MINTER_ROLE, DEFAULT_ADMIN_ROLE);
103
+ super._transferOwnership(newOwner);
104
+ }
105
+ }
@@ -0,0 +1,5 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ /// @dev Error thrown when attempting to mint tokens after minting has been disabled.
5
+ error LSP7MintDisabled();
@@ -0,0 +1,156 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ // modules
5
+ import {
6
+ OwnableUpgradeable
7
+ } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
8
+ import {
9
+ AccessControlExtendedInitAbstract
10
+ } from "../AccessControlExtended/AccessControlExtendedInitAbstract.sol";
11
+
12
+ import {
13
+ LSP7DigitalAssetInitAbstract
14
+ } from "../../LSP7DigitalAssetInitAbstract.sol";
15
+
16
+ // interfaces
17
+ import {ILSP7Mintable} from "./ILSP7Mintable.sol";
18
+
19
+ // errors
20
+ import {LSP7MintDisabled} from "./LSP7MintableErrors.sol";
21
+
22
+ /// @title LSP7MintableInitAbstract
23
+ /// @dev Abstract contract implementing a mintable LSP7 token extension, allowing any address granted the `MINTER_ROLE` to mint new tokens until minting is disabled.
24
+ /// Inherits from LSP7DigitalAsset to provide core token functionality.
25
+ abstract contract LSP7MintableInitAbstract is
26
+ ILSP7Mintable,
27
+ LSP7DigitalAssetInitAbstract,
28
+ AccessControlExtendedInitAbstract
29
+ {
30
+ /// @notice Indicates whether minting is currently enabled or not.
31
+ bool public isMintable;
32
+
33
+ /// @dev keccak256("MINTER_ROLE")
34
+ bytes32 public constant MINTER_ROLE =
35
+ 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6;
36
+
37
+ /// @notice Initializes the LSP7Mintable contract with base token params and minting status.
38
+ /// @dev Initializes the LSP7DigitalAsset base and sets the minting status.
39
+ /// @param name_ The name of the token.
40
+ /// @param symbol_ The symbol of the token.
41
+ /// @param newOwner_ The owner of the contract.
42
+ /// @param lsp4TokenType_ The token type (see LSP4).
43
+ /// @param isNonDivisible_ Whether the token is non-divisible.
44
+ /// @param mintable_ True to enable minting after deployment, false to disable it forever.
45
+ /// @custom:info If `mintable_` is set to `true` then it can be disabled using `disableMinting()` function later on.
46
+ function __LSP7Mintable_init(
47
+ string memory name_,
48
+ string memory symbol_,
49
+ address newOwner_,
50
+ uint256 lsp4TokenType_,
51
+ bool isNonDivisible_,
52
+ bool mintable_
53
+ ) internal virtual onlyInitializing {
54
+ LSP7DigitalAssetInitAbstract._initialize(
55
+ name_,
56
+ symbol_,
57
+ newOwner_,
58
+ lsp4TokenType_,
59
+ isNonDivisible_
60
+ );
61
+ __AccessControlExtended_init();
62
+ __LSP7Mintable_init_unchained(mintable_);
63
+ }
64
+
65
+ /// @notice Unchained initializer for the minting status.
66
+ /// @dev Sets the initial minting status.
67
+ /// @param mintable_ True to enable minting after deployment, false to disable it forever.
68
+ function __LSP7Mintable_init_unchained(
69
+ bool mintable_
70
+ ) internal virtual onlyInitializing {
71
+ isMintable = mintable_;
72
+ emit MintingStatusChanged({enabled: mintable_});
73
+
74
+ if (mintable_) {
75
+ _grantRole(MINTER_ROLE, owner());
76
+ }
77
+ }
78
+
79
+ /// @inheritdoc ILSP7Mintable
80
+ /// @custom:warning Once this function is called, any address holding the `MINTER_ROLE` will be inoperable.
81
+ /// @custom:info The list of addresses holding the `MINTER_ROLE` remains populated after the minting feature is switched off.
82
+ function disableMinting() public virtual override onlyOwner {
83
+ require(isMintable, LSP7MintDisabled());
84
+ isMintable = false;
85
+ emit MintingStatusChanged({enabled: false});
86
+ }
87
+
88
+ /// @inheritdoc ILSP7Mintable
89
+ function mint(
90
+ address to,
91
+ uint256 amount,
92
+ bool force,
93
+ bytes memory data
94
+ ) public virtual override onlyRole(MINTER_ROLE) {
95
+ _mint(to, amount, force, data);
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
+ /// @notice Internal function to mint tokens, overridden to enforce minting status.
116
+ /// @dev Checks if minting is enabled, reverting with LSP7MintDisabled if not. Calls the parent _mint function from LSP7DigitalAsset.
117
+ /// @param to The address to receive the minted tokens.
118
+ /// @param amount The number of tokens to mint.
119
+ /// @param force When true, allows minting to any address; when false, requires `to` to support LSP1 UniversalReceiver.
120
+ /// @param data Additional data included in the Transfer event and sent to `to`’s UniversalReceiver hook, if applicable.
121
+ ///
122
+ /// @custom:warning This internal function does not check for `MINTER_ROLE` access control.
123
+ /// Derived contracts that expose this function publicly and want to gate it by `MINTER_ROLE` must enforce it with `onlyRole(MINTER_ROLE)`.
124
+ function _mint(
125
+ address to,
126
+ uint256 amount,
127
+ bool force,
128
+ bytes memory data
129
+ ) internal virtual override {
130
+ require(isMintable, LSP7MintDisabled());
131
+ super._mint(to, amount, force, data);
132
+ }
133
+
134
+ function _transferOwnership(
135
+ address newOwner
136
+ )
137
+ internal
138
+ virtual
139
+ override(AccessControlExtendedInitAbstract, OwnableUpgradeable)
140
+ {
141
+ // restore default admin hierarchy so a previously-installed custom admin
142
+ // cannot grant MINTER_ROLE to new accounts post-transfer
143
+ _setRoleAdmin(MINTER_ROLE, DEFAULT_ADMIN_ROLE);
144
+ super._transferOwnership(newOwner);
145
+ }
146
+
147
+ /**
148
+ * @dev This empty reserved space is put in place to allow future versions to add new
149
+ * variables without shifting down storage in the inheritance chain.
150
+ * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
151
+ *
152
+ * @custom:info The size of the `__gap` array is calculated so that the amount of storage used by the contract
153
+ * always adds up to the same number (in this case 50 storage slots).
154
+ */
155
+ uint256[49] private __gap;
156
+ }