@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.
- package/LICENSE +201 -0
- package/README.md +55 -5
- package/artifacts/IAccessControlExtended.json +285 -0
- package/artifacts/ILSP7CappedBalance.json +27 -0
- package/artifacts/ILSP7CappedSupply.json +27 -0
- package/artifacts/ILSP7DigitalAsset.json +6 -3
- package/artifacts/ILSP7Mintable.json +62 -0
- package/artifacts/ILSP7NonTransferable.json +110 -0
- package/artifacts/ILSP7Revokable.json +75 -0
- package/artifacts/LSP7Burnable.json +7 -4
- package/artifacts/LSP7BurnableInitAbstract.json +7 -4
- package/artifacts/LSP7CappedBalanceAbstract.json +1159 -0
- package/artifacts/LSP7CappedBalanceInitAbstract.json +1167 -0
- package/artifacts/{LSP7CappedSupply.json → LSP7CappedSupplyAbstract.json} +8 -15
- package/artifacts/LSP7CappedSupplyInitAbstract.json +7 -14
- package/artifacts/LSP7CustomizableToken.json +1604 -0
- package/artifacts/LSP7CustomizableTokenInit.json +1601 -0
- package/artifacts/LSP7DigitalAsset.json +6 -3
- package/artifacts/LSP7DigitalAssetInitAbstract.json +6 -3
- package/artifacts/LSP7Mintable.json +376 -5
- package/artifacts/LSP7MintableAbstract.json +1186 -0
- package/artifacts/LSP7MintableInit.json +369 -5
- package/artifacts/LSP7MintableInitAbstract.json +1194 -0
- package/artifacts/LSP7NonTransferableAbstract.json +1236 -0
- package/artifacts/LSP7NonTransferableInitAbstract.json +1244 -0
- package/artifacts/LSP7RevokableAbstract.json +1186 -0
- package/artifacts/LSP7RevokableInitAbstract.json +1194 -0
- package/artifacts/LSP7Votes.json +66 -4
- package/artifacts/LSP7VotesInitAbstract.json +66 -4
- package/contracts/LSP7DigitalAsset.sol +56 -65
- package/contracts/LSP7DigitalAssetInitAbstract.sol +49 -71
- package/contracts/extensions/AccessControlExtended/AccessControlExtendedAbstract.sol +368 -0
- package/contracts/extensions/AccessControlExtended/AccessControlExtendedConstants.sol +13 -0
- package/contracts/extensions/AccessControlExtended/AccessControlExtendedErrors.sol +23 -0
- package/contracts/extensions/AccessControlExtended/AccessControlExtendedInitAbstract.sol +389 -0
- package/contracts/extensions/AccessControlExtended/IAccessControlExtended.sol +51 -0
- package/contracts/extensions/{LSP7Burnable.sol → LSP7Burnable/LSP7Burnable.sol} +2 -2
- package/contracts/extensions/{LSP7BurnableInitAbstract.sol → LSP7Burnable/LSP7BurnableInitAbstract.sol} +2 -4
- package/contracts/extensions/LSP7CappedBalance/ILSP7CappedBalance.sol +11 -0
- package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceAbstract.sol +129 -0
- package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceErrors.sol +10 -0
- package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceInitAbstract.sol +179 -0
- package/contracts/extensions/LSP7CappedSupply/ILSP7CappedSupply.sol +11 -0
- package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyAbstract.sol +56 -0
- package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyErrors.sol +6 -0
- package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyInitAbstract.sol +96 -0
- package/contracts/extensions/LSP7Mintable/ILSP7Mintable.sol +27 -0
- package/contracts/extensions/LSP7Mintable/LSP7MintableAbstract.sol +105 -0
- package/contracts/extensions/LSP7Mintable/LSP7MintableErrors.sol +5 -0
- package/contracts/extensions/LSP7Mintable/LSP7MintableInitAbstract.sol +156 -0
- package/contracts/extensions/LSP7NonTransferable/ILSP7NonTransferable.sol +48 -0
- package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableAbstract.sol +183 -0
- package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableErrors.sol +14 -0
- package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableInitAbstract.sol +240 -0
- package/contracts/extensions/LSP7Revokable/ILSP7Revokable.sol +28 -0
- package/contracts/extensions/LSP7Revokable/LSP7RevokableAbstract.sol +130 -0
- package/contracts/extensions/LSP7Revokable/LSP7RevokableErrors.sol +4 -0
- package/contracts/extensions/LSP7Revokable/LSP7RevokableInitAbstract.sol +183 -0
- package/contracts/extensions/{LSP7Votes.sol → LSP7Votes/LSP7Votes.sol} +37 -20
- package/contracts/extensions/LSP7Votes/LSP7VotesErrors.sol +24 -0
- package/contracts/extensions/{LSP7VotesInitAbstract.sol → LSP7Votes/LSP7VotesInitAbstract.sol} +37 -21
- package/contracts/presets/LSP7CustomizableToken.sol +262 -0
- package/contracts/presets/LSP7CustomizableTokenConstants.sol +32 -0
- package/contracts/presets/LSP7CustomizableTokenInit.sol +294 -0
- package/contracts/presets/LSP7Mintable.sol +14 -23
- package/contracts/presets/LSP7MintableInit.sol +16 -11
- package/dist/abi.cjs +7519 -54
- package/dist/abi.d.cts +11109 -338
- package/dist/abi.d.mts +11109 -338
- package/dist/abi.d.ts +11109 -338
- package/dist/abi.mjs +7503 -54
- package/dist/constants.cjs +21 -0
- package/dist/constants.d.cts +12 -1
- package/dist/constants.d.mts +12 -1
- package/dist/constants.d.ts +12 -1
- package/dist/constants.mjs +16 -1
- package/package.json +33 -9
- package/contracts/extensions/LSP7CappedSupply.sol +0 -83
- package/contracts/extensions/LSP7CappedSupplyInitAbstract.sol +0 -86
- package/contracts/presets/ILSP7Mintable.sol +0 -32
- package/contracts/presets/LSP7MintableInitAbstract.sol +0 -57
- /package/contracts/extensions/{LSP7VotesConstants.sol → LSP7Votes/LSP7VotesConstants.sol} +0 -0
|
@@ -0,0 +1,262 @@
|
|
|
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 {
|
|
7
|
+
AccessControlExtendedAbstract
|
|
8
|
+
} from "../extensions/AccessControlExtended/AccessControlExtendedAbstract.sol";
|
|
9
|
+
import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol";
|
|
10
|
+
|
|
11
|
+
// extensions
|
|
12
|
+
import {LSP7Burnable} from "../extensions/LSP7Burnable/LSP7Burnable.sol";
|
|
13
|
+
import {
|
|
14
|
+
LSP7MintableAbstract
|
|
15
|
+
} from "../extensions/LSP7Mintable/LSP7MintableAbstract.sol";
|
|
16
|
+
import {
|
|
17
|
+
LSP7CappedSupplyAbstract
|
|
18
|
+
} from "../extensions/LSP7CappedSupply/LSP7CappedSupplyAbstract.sol";
|
|
19
|
+
import {
|
|
20
|
+
LSP7CappedBalanceAbstract
|
|
21
|
+
} from "../extensions/LSP7CappedBalance/LSP7CappedBalanceAbstract.sol";
|
|
22
|
+
import {
|
|
23
|
+
LSP7NonTransferableAbstract
|
|
24
|
+
} from "../extensions/LSP7NonTransferable/LSP7NonTransferableAbstract.sol";
|
|
25
|
+
import {
|
|
26
|
+
LSP7RevokableAbstract
|
|
27
|
+
} from "../extensions/LSP7Revokable/LSP7RevokableAbstract.sol";
|
|
28
|
+
|
|
29
|
+
// constants
|
|
30
|
+
import {
|
|
31
|
+
LSP7MintableParams,
|
|
32
|
+
LSP7CappedParams,
|
|
33
|
+
LSP7NonTransferableParams,
|
|
34
|
+
LSP7RevokableParams
|
|
35
|
+
} from "./LSP7CustomizableTokenConstants.sol";
|
|
36
|
+
|
|
37
|
+
// errors
|
|
38
|
+
import {
|
|
39
|
+
LSP7MintDisabled
|
|
40
|
+
} from "../extensions/LSP7Mintable/LSP7MintableErrors.sol";
|
|
41
|
+
import {
|
|
42
|
+
LSP7CappedSupplyCannotMintOverCap
|
|
43
|
+
} from "../extensions/LSP7CappedSupply/LSP7CappedSupplyErrors.sol";
|
|
44
|
+
|
|
45
|
+
/// @title LSP7CustomizableToken
|
|
46
|
+
/// @dev A customizable LSP7 token that implements multiple features and uses role-based exemptions.
|
|
47
|
+
/// Implements {LSP7Burnable} to allow burning.
|
|
48
|
+
/// Implements {LSP7Mintable} to allow minting.
|
|
49
|
+
/// Implements {LSP7CappedSupply} to set total supply cap.
|
|
50
|
+
/// Implements {LSP7CappedBalance} to set balance caps.
|
|
51
|
+
/// Implements {LSP7NonTransferable} to restrict transfers.
|
|
52
|
+
/// Implements {LSP7Revokable} to allow revoking tokens.
|
|
53
|
+
contract LSP7CustomizableToken is
|
|
54
|
+
LSP7Burnable,
|
|
55
|
+
LSP7MintableAbstract,
|
|
56
|
+
LSP7CappedSupplyAbstract,
|
|
57
|
+
LSP7CappedBalanceAbstract,
|
|
58
|
+
LSP7NonTransferableAbstract,
|
|
59
|
+
LSP7RevokableAbstract
|
|
60
|
+
{
|
|
61
|
+
/// @notice Initializes the token with name, symbol, owner, and customizable features.
|
|
62
|
+
/// @dev Sets up minting, balance cap, total supply caps, transfer restrictions, and revoking feature. Mints initial tokens if specified. Reverts if initialMintAmount_ exceeds tokenSupplyCap. Inherits constructor logic from parent contracts.
|
|
63
|
+
/// @param name_ The name of the token.
|
|
64
|
+
/// @param symbol_ The symbol of the token.
|
|
65
|
+
/// @param newOwner_ The initial owner of the token.
|
|
66
|
+
/// @param lsp4TokenType_ The LSP4 token type (e.g., 0 for token).
|
|
67
|
+
/// @param isNonDivisible_ True if the token is non-divisible (e.g., for NDTs).
|
|
68
|
+
/// @param mintableParams Deployment configuration for minting feature (see above).
|
|
69
|
+
/// @param cappedParams Deployment configuration for capped balance and capped supply features (see above).
|
|
70
|
+
/// @param nonTransferableParams Deployment configuration for non-transferable feature (see above).
|
|
71
|
+
/// @param revokableParams Deployment configuration for revokable feature (see above).
|
|
72
|
+
constructor(
|
|
73
|
+
string memory name_,
|
|
74
|
+
string memory symbol_,
|
|
75
|
+
address newOwner_,
|
|
76
|
+
uint256 lsp4TokenType_,
|
|
77
|
+
bool isNonDivisible_,
|
|
78
|
+
LSP7MintableParams memory mintableParams,
|
|
79
|
+
LSP7CappedParams memory cappedParams,
|
|
80
|
+
LSP7NonTransferableParams memory nonTransferableParams,
|
|
81
|
+
LSP7RevokableParams memory revokableParams
|
|
82
|
+
)
|
|
83
|
+
LSP7DigitalAsset(
|
|
84
|
+
name_,
|
|
85
|
+
symbol_,
|
|
86
|
+
newOwner_,
|
|
87
|
+
lsp4TokenType_,
|
|
88
|
+
isNonDivisible_
|
|
89
|
+
)
|
|
90
|
+
AccessControlExtendedAbstract()
|
|
91
|
+
LSP7MintableAbstract(mintableParams.isMintable)
|
|
92
|
+
LSP7CappedSupplyAbstract(cappedParams.tokenSupplyCap)
|
|
93
|
+
LSP7CappedBalanceAbstract(cappedParams.tokenBalanceCap)
|
|
94
|
+
LSP7NonTransferableAbstract(
|
|
95
|
+
nonTransferableParams.transferLockStart,
|
|
96
|
+
nonTransferableParams.transferLockEnd
|
|
97
|
+
)
|
|
98
|
+
LSP7RevokableAbstract(revokableParams.isRevokable)
|
|
99
|
+
{
|
|
100
|
+
if (mintableParams.initialMintAmount > 0) {
|
|
101
|
+
_initialMint({
|
|
102
|
+
to: newOwner_,
|
|
103
|
+
amount: mintableParams.initialMintAmount
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/// @inheritdoc LSP7CappedSupplyAbstract
|
|
109
|
+
/// @notice Returns the token supply cap.
|
|
110
|
+
/// @dev If minting is enabled, returns the configured supply cap defining the maximum amount of tokens that can be minted.
|
|
111
|
+
/// If minting is disabled, returns the current total supply as the effective cap (no more tokens can be created).
|
|
112
|
+
function tokenSupplyCap() public view virtual override returns (uint256) {
|
|
113
|
+
return isMintable ? super.tokenSupplyCap() : totalSupply();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/// @dev Required override to resolve multiple inheritance. Calls every parent {supportsInterface} functions
|
|
117
|
+
/// via `super` to aggregate the interface IDs supported across all inherited modules.
|
|
118
|
+
function supportsInterface(
|
|
119
|
+
bytes4 interfaceId
|
|
120
|
+
)
|
|
121
|
+
public
|
|
122
|
+
view
|
|
123
|
+
virtual
|
|
124
|
+
override(
|
|
125
|
+
LSP7DigitalAsset,
|
|
126
|
+
LSP7MintableAbstract,
|
|
127
|
+
LSP7CappedBalanceAbstract,
|
|
128
|
+
LSP7NonTransferableAbstract,
|
|
129
|
+
LSP7RevokableAbstract
|
|
130
|
+
)
|
|
131
|
+
returns (bool)
|
|
132
|
+
{
|
|
133
|
+
return super.supportsInterface(interfaceId);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// @dev Override to bypass the non transferable check when revokers revoke users' tokens.
|
|
137
|
+
function _nonTransferableCheck(
|
|
138
|
+
address from,
|
|
139
|
+
address to,
|
|
140
|
+
uint256 amount,
|
|
141
|
+
bool force,
|
|
142
|
+
bytes memory data
|
|
143
|
+
) internal virtual override {
|
|
144
|
+
if (_isRevocationBypass(to)) return;
|
|
145
|
+
super._nonTransferableCheck(from, to, amount, force, data);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// @dev Override to bypass the token balance cap check when revokers revoke users' tokens.
|
|
149
|
+
function _tokenBalanceCapCheck(
|
|
150
|
+
address from,
|
|
151
|
+
address to,
|
|
152
|
+
uint256 amount,
|
|
153
|
+
bool force,
|
|
154
|
+
bytes memory data
|
|
155
|
+
) internal virtual override {
|
|
156
|
+
if (_isRevocationBypass(to)) return;
|
|
157
|
+
super._tokenBalanceCapCheck(from, to, amount, force, data);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// @inheritdoc LSP7MintableAbstract
|
|
161
|
+
/// @dev Overridden function to allow minting only if:
|
|
162
|
+
/// - the minting feature is enabled, from {LSP7MintableAbstract}
|
|
163
|
+
/// - the total amount of tokens does not exceed the capped supply after minting, from {LSP7CappedSupplyAbstract}
|
|
164
|
+
function _mint(
|
|
165
|
+
address to,
|
|
166
|
+
uint256 amount,
|
|
167
|
+
bool force,
|
|
168
|
+
bytes memory data
|
|
169
|
+
)
|
|
170
|
+
internal
|
|
171
|
+
virtual
|
|
172
|
+
override(
|
|
173
|
+
LSP7DigitalAsset,
|
|
174
|
+
LSP7MintableAbstract,
|
|
175
|
+
LSP7CappedSupplyAbstract
|
|
176
|
+
)
|
|
177
|
+
{
|
|
178
|
+
require(isMintable, LSP7MintDisabled());
|
|
179
|
+
LSP7CappedSupplyAbstract._mint(to, amount, force, data);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/// @notice Hook called before a token transfer to enforce restrictions.
|
|
183
|
+
/// @dev Combines checks from {LSP7CappedBalance} and {LSP7NonTransferable}.
|
|
184
|
+
/// - Bypasses {LSP7NonTransferable} checks for senders (`from`) holding the `NON_TRANSFERABLE_BYPASS_ROLE` role.
|
|
185
|
+
/// - Bypasses {LSP7CappedBalance} checks for recipients (`to`) holding the `UNCAPPED_BALANCE_ROLE` role.
|
|
186
|
+
/// - Allows minting (from address(0)) and burning to address(0) regardless of restrictions.
|
|
187
|
+
/// @param from The address sending the tokens.
|
|
188
|
+
/// @param to The address receiving the tokens.
|
|
189
|
+
/// @param amount The amount of tokens being transferred.
|
|
190
|
+
/// @param force Whether to force the transfer.
|
|
191
|
+
/// @param data Additional data for the transfer.
|
|
192
|
+
function _beforeTokenTransfer(
|
|
193
|
+
address from,
|
|
194
|
+
address to,
|
|
195
|
+
uint256 amount,
|
|
196
|
+
bool force,
|
|
197
|
+
bytes memory data
|
|
198
|
+
)
|
|
199
|
+
internal
|
|
200
|
+
virtual
|
|
201
|
+
override(
|
|
202
|
+
LSP7DigitalAsset,
|
|
203
|
+
LSP7CappedBalanceAbstract,
|
|
204
|
+
LSP7NonTransferableAbstract
|
|
205
|
+
)
|
|
206
|
+
{
|
|
207
|
+
super._beforeTokenTransfer(from, to, amount, force, data);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/// @dev Required override to resolve multiple inheritance. Calls every parent {_transferOwnership} function
|
|
211
|
+
/// via `super` so that each inherited module updates its ownership-dependent state.
|
|
212
|
+
///
|
|
213
|
+
/// When contract ownership changes, this will:
|
|
214
|
+
/// - clear the admin role for: `MINTER_ROLE`, `REVOKER_ROLE`, `NON_TRANSFERABLE_BYPASS_ROLE`, `UNCAPPED_BALANCE_ROLE`
|
|
215
|
+
/// - clear the list of addresses holding the `REVOKER_ROLE`
|
|
216
|
+
function _transferOwnership(
|
|
217
|
+
address newOwner
|
|
218
|
+
)
|
|
219
|
+
internal
|
|
220
|
+
virtual
|
|
221
|
+
override(
|
|
222
|
+
Ownable,
|
|
223
|
+
LSP7MintableAbstract,
|
|
224
|
+
LSP7CappedBalanceAbstract,
|
|
225
|
+
LSP7NonTransferableAbstract,
|
|
226
|
+
LSP7RevokableAbstract
|
|
227
|
+
)
|
|
228
|
+
{
|
|
229
|
+
super._transferOwnership(newOwner);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/// @dev Mint initial tokens without enforcing check if the token contract is mintable or not.
|
|
233
|
+
/// Enforces the configured capped-supply value directly before bypassing the mintable check.
|
|
234
|
+
function _initialMint(address to, uint256 amount) private {
|
|
235
|
+
uint256 configuredTokenSupplyCap = LSP7CappedSupplyAbstract
|
|
236
|
+
.tokenSupplyCap();
|
|
237
|
+
|
|
238
|
+
bool exceedsSupplyCap = amount > configuredTokenSupplyCap;
|
|
239
|
+
|
|
240
|
+
require(
|
|
241
|
+
configuredTokenSupplyCap == 0 || !exceedsSupplyCap,
|
|
242
|
+
LSP7CappedSupplyCannotMintOverCap()
|
|
243
|
+
);
|
|
244
|
+
LSP7DigitalAsset._mint(to, amount, true, "");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/// @dev Returns whether the current call is a legitimate revocation that should bypass the
|
|
248
|
+
/// {LSP7NonTransferable} and {LSP7CappedBalance} restrictions when revoking tokens from a token holder.
|
|
249
|
+
///
|
|
250
|
+
/// Returns `true` only when all of the following conditions are met:
|
|
251
|
+
/// - the function being called is {revoke}.
|
|
252
|
+
/// - the revoking feature is enabled.
|
|
253
|
+
/// - the caller (`msg.sender`) holds the `REVOKER_ROLE`.
|
|
254
|
+
/// - the recipient (`to`) is either the contract `owner()` or a revoker (an address holding the `REVOKER_ROLE`).
|
|
255
|
+
function _isRevocationBypass(address to) private view returns (bool) {
|
|
256
|
+
return
|
|
257
|
+
msg.sig == this.revoke.selector &&
|
|
258
|
+
isRevokable() &&
|
|
259
|
+
hasRole(REVOKER_ROLE, msg.sender) &&
|
|
260
|
+
(to == owner() || hasRole(REVOKER_ROLE, to));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.27;
|
|
3
|
+
|
|
4
|
+
/// @dev Deployment configuration for minting feature.
|
|
5
|
+
/// @param isMintable True to enable minting after deployment, false to disable it forever.
|
|
6
|
+
/// @param initialMintAmount The amount of tokens to mint to `newOwner_` on deployment in wei.
|
|
7
|
+
struct LSP7MintableParams {
|
|
8
|
+
bool isMintable;
|
|
9
|
+
uint256 initialMintAmount;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/// @dev Deployment configuration for capped balance and capped supply features.
|
|
13
|
+
/// @param tokenBalanceCap The maximum balance per address in wei, 0 to disable.
|
|
14
|
+
/// @param tokenSupplyCap The maximum total supply in wei, 0 to disable.
|
|
15
|
+
struct LSP7CappedParams {
|
|
16
|
+
uint256 tokenBalanceCap;
|
|
17
|
+
uint256 tokenSupplyCap;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// @dev Deployment configuration for non-transferable feature.
|
|
21
|
+
/// @param transferLockStart The start timestamp of the transfer lock period, 0 to disable.
|
|
22
|
+
/// @param transferLockEnd The end timestamp of the transfer lock period, 0 to disable.
|
|
23
|
+
struct LSP7NonTransferableParams {
|
|
24
|
+
uint256 transferLockStart;
|
|
25
|
+
uint256 transferLockEnd;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// @dev Deployment configuration for revokable feature.
|
|
29
|
+
/// @param isRevokable True to enable token revocation after deployment, false to disable it.
|
|
30
|
+
struct LSP7RevokableParams {
|
|
31
|
+
bool isRevokable;
|
|
32
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
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
|
+
|
|
12
|
+
// extensions
|
|
13
|
+
import {
|
|
14
|
+
LSP7BurnableInitAbstract
|
|
15
|
+
} from "../extensions/LSP7Burnable/LSP7BurnableInitAbstract.sol";
|
|
16
|
+
import {
|
|
17
|
+
LSP7MintableInitAbstract
|
|
18
|
+
} from "../extensions/LSP7Mintable/LSP7MintableInitAbstract.sol";
|
|
19
|
+
import {
|
|
20
|
+
LSP7CappedSupplyInitAbstract
|
|
21
|
+
} from "../extensions/LSP7CappedSupply/LSP7CappedSupplyInitAbstract.sol";
|
|
22
|
+
import {
|
|
23
|
+
LSP7CappedBalanceInitAbstract
|
|
24
|
+
} from "../extensions/LSP7CappedBalance/LSP7CappedBalanceInitAbstract.sol";
|
|
25
|
+
import {
|
|
26
|
+
LSP7NonTransferableInitAbstract
|
|
27
|
+
} from "../extensions/LSP7NonTransferable/LSP7NonTransferableInitAbstract.sol";
|
|
28
|
+
import {
|
|
29
|
+
LSP7RevokableInitAbstract
|
|
30
|
+
} from "../extensions/LSP7Revokable/LSP7RevokableInitAbstract.sol";
|
|
31
|
+
|
|
32
|
+
// constants
|
|
33
|
+
import {
|
|
34
|
+
LSP7MintableParams,
|
|
35
|
+
LSP7NonTransferableParams,
|
|
36
|
+
LSP7CappedParams,
|
|
37
|
+
LSP7RevokableParams
|
|
38
|
+
} from "./LSP7CustomizableTokenConstants.sol";
|
|
39
|
+
|
|
40
|
+
// errors
|
|
41
|
+
import {
|
|
42
|
+
LSP7MintDisabled
|
|
43
|
+
} from "../extensions/LSP7Mintable/LSP7MintableErrors.sol";
|
|
44
|
+
import {
|
|
45
|
+
LSP7CappedSupplyCannotMintOverCap
|
|
46
|
+
} from "../extensions/LSP7CappedSupply/LSP7CappedSupplyErrors.sol";
|
|
47
|
+
|
|
48
|
+
/// @title LSP7CustomizableTokenInit
|
|
49
|
+
/// @dev A customizable LSP7 token that implements multiple features and uses role-based exemptions. This version of the contract is the implementation to use behind proxies.
|
|
50
|
+
/// Implements {LSP7BurnableInitAbstract} to allow burning.
|
|
51
|
+
/// Implements {LSP7MintableInitAbstract} to allow minting.
|
|
52
|
+
/// Implements {LSP7CappedSupplyInitAbstract} to set balance caps.
|
|
53
|
+
/// Implements {LSP7CappedBalanceInitAbstract} to set balance caps.
|
|
54
|
+
/// Implements {LSP7NonTransferableInitAbstract} to restrict transfers.
|
|
55
|
+
/// Implement {LSP7RevokableInitAbstract} to allow revoking tokens.
|
|
56
|
+
contract LSP7CustomizableTokenInit is
|
|
57
|
+
LSP7BurnableInitAbstract,
|
|
58
|
+
LSP7MintableInitAbstract,
|
|
59
|
+
LSP7CappedSupplyInitAbstract,
|
|
60
|
+
LSP7CappedBalanceInitAbstract,
|
|
61
|
+
LSP7NonTransferableInitAbstract,
|
|
62
|
+
LSP7RevokableInitAbstract
|
|
63
|
+
{
|
|
64
|
+
/// @dev Locks the base implementation contract from being initialized.
|
|
65
|
+
constructor() {
|
|
66
|
+
_disableInitializers();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function initialize(
|
|
70
|
+
string calldata name_,
|
|
71
|
+
string calldata symbol_,
|
|
72
|
+
address newOwner_,
|
|
73
|
+
uint256 lsp4TokenType_,
|
|
74
|
+
bool isNonDivisible_,
|
|
75
|
+
LSP7MintableParams calldata mintableParams,
|
|
76
|
+
LSP7CappedParams calldata cappedParams,
|
|
77
|
+
LSP7NonTransferableParams calldata nonTransferableParams,
|
|
78
|
+
LSP7RevokableParams calldata revokableParams
|
|
79
|
+
) external virtual initializer {
|
|
80
|
+
__LSP7CustomizableToken_init(
|
|
81
|
+
name_,
|
|
82
|
+
symbol_,
|
|
83
|
+
newOwner_,
|
|
84
|
+
lsp4TokenType_,
|
|
85
|
+
isNonDivisible_,
|
|
86
|
+
mintableParams,
|
|
87
|
+
cappedParams,
|
|
88
|
+
nonTransferableParams,
|
|
89
|
+
revokableParams
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// @notice Initializes the token with name, symbol, owner, and customizable features.
|
|
94
|
+
/// @dev Sets up minting, balance cap, transfer restrictions, allowlist, and supply cap. Mints initial tokens if specified. Reverts if initialMintAmount_ exceeds tokenSupplyCap. Inherits constructor logic from parent contracts.
|
|
95
|
+
/// @param name_ The name of the token.
|
|
96
|
+
/// @param symbol_ The symbol of the token.
|
|
97
|
+
/// @param newOwner_ The initial owner of the token, added to the allowlist.
|
|
98
|
+
/// @param lsp4TokenType_ The LSP4 token type (e.g., 0 for token).
|
|
99
|
+
/// @param isNonDivisible_ True if the token is non-divisible (e.g., for NDTs).
|
|
100
|
+
/// @param mintableParams Deployment configuration for minting feature (see above).
|
|
101
|
+
/// @param cappedParams Deployment configuration for capped balance and capped supply features (see above).
|
|
102
|
+
/// @param nonTransferableParams Deployment configuration for non-transferable feature (see above).
|
|
103
|
+
/// @param revokableParams Deployment configuration for revokable feature (see above).
|
|
104
|
+
function __LSP7CustomizableToken_init(
|
|
105
|
+
string calldata name_,
|
|
106
|
+
string calldata symbol_,
|
|
107
|
+
address newOwner_,
|
|
108
|
+
uint256 lsp4TokenType_,
|
|
109
|
+
bool isNonDivisible_,
|
|
110
|
+
LSP7MintableParams calldata mintableParams,
|
|
111
|
+
LSP7CappedParams calldata cappedParams,
|
|
112
|
+
LSP7NonTransferableParams calldata nonTransferableParams,
|
|
113
|
+
LSP7RevokableParams calldata revokableParams
|
|
114
|
+
) internal virtual onlyInitializing {
|
|
115
|
+
LSP7DigitalAssetInitAbstract._initialize(
|
|
116
|
+
name_,
|
|
117
|
+
symbol_,
|
|
118
|
+
newOwner_,
|
|
119
|
+
lsp4TokenType_,
|
|
120
|
+
isNonDivisible_
|
|
121
|
+
);
|
|
122
|
+
__AccessControlExtended_init_unchained();
|
|
123
|
+
__LSP7Mintable_init_unchained(mintableParams.isMintable);
|
|
124
|
+
__LSP7CappedSupply_init_unchained(cappedParams.tokenSupplyCap);
|
|
125
|
+
__LSP7CappedBalance_init_unchained(cappedParams.tokenBalanceCap);
|
|
126
|
+
__LSP7NonTransferable_init_unchained(
|
|
127
|
+
nonTransferableParams.transferLockStart,
|
|
128
|
+
nonTransferableParams.transferLockEnd
|
|
129
|
+
);
|
|
130
|
+
__LSP7Revokable_init_unchained(revokableParams.isRevokable);
|
|
131
|
+
|
|
132
|
+
if (mintableParams.initialMintAmount > 0) {
|
|
133
|
+
_initialMint({
|
|
134
|
+
to: newOwner_,
|
|
135
|
+
amount: mintableParams.initialMintAmount
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// @inheritdoc LSP7CappedSupplyInitAbstract
|
|
141
|
+
/// @notice Returns the token supply cap.
|
|
142
|
+
/// @dev If minting is enabled, returns the configured supply cap defining the maximum amount of tokens that can be minted.
|
|
143
|
+
/// If minting is disabled, returns the current total supply as the effective cap (no more tokens can be created).
|
|
144
|
+
function tokenSupplyCap() public view virtual override returns (uint256) {
|
|
145
|
+
return isMintable ? super.tokenSupplyCap() : totalSupply();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// @dev Required override to resolve multiple inheritance. Calls every parent {supportsInterface} functions
|
|
149
|
+
/// via `super` to aggregate the interface IDs supported across all inherited modules.
|
|
150
|
+
function supportsInterface(
|
|
151
|
+
bytes4 interfaceId
|
|
152
|
+
)
|
|
153
|
+
public
|
|
154
|
+
view
|
|
155
|
+
virtual
|
|
156
|
+
override(
|
|
157
|
+
LSP7DigitalAssetInitAbstract,
|
|
158
|
+
LSP7MintableInitAbstract,
|
|
159
|
+
LSP7CappedBalanceInitAbstract,
|
|
160
|
+
LSP7NonTransferableInitAbstract,
|
|
161
|
+
LSP7RevokableInitAbstract
|
|
162
|
+
)
|
|
163
|
+
returns (bool)
|
|
164
|
+
{
|
|
165
|
+
return super.supportsInterface(interfaceId);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// @dev Override to bypass the non transferable check when revokers revoke users' tokens.
|
|
169
|
+
function _nonTransferableCheck(
|
|
170
|
+
address from,
|
|
171
|
+
address to,
|
|
172
|
+
uint256 amount,
|
|
173
|
+
bool force,
|
|
174
|
+
bytes memory data
|
|
175
|
+
) internal virtual override {
|
|
176
|
+
if (_isRevocationBypass(to)) return;
|
|
177
|
+
super._nonTransferableCheck(from, to, amount, force, data);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/// @dev Override to bypass the token balance cap check when revokers revoke users' tokens.
|
|
181
|
+
function _tokenBalanceCapCheck(
|
|
182
|
+
address from,
|
|
183
|
+
address to,
|
|
184
|
+
uint256 amount,
|
|
185
|
+
bool force,
|
|
186
|
+
bytes memory data
|
|
187
|
+
) internal virtual override {
|
|
188
|
+
if (_isRevocationBypass(to)) return;
|
|
189
|
+
super._tokenBalanceCapCheck(from, to, amount, force, data);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/// @inheritdoc LSP7MintableInitAbstract
|
|
193
|
+
/// @dev Overridden function to allow minting only if:
|
|
194
|
+
/// - the minting feature is enabled, from {LSP7MintableInitAbstract}
|
|
195
|
+
/// - the total amount of tokens does not exceed the capped supply after minting, from {LSP7CappedSupplyInitAbstract}
|
|
196
|
+
function _mint(
|
|
197
|
+
address to,
|
|
198
|
+
uint256 amount,
|
|
199
|
+
bool force,
|
|
200
|
+
bytes memory data
|
|
201
|
+
)
|
|
202
|
+
internal
|
|
203
|
+
virtual
|
|
204
|
+
override(
|
|
205
|
+
LSP7DigitalAssetInitAbstract,
|
|
206
|
+
LSP7MintableInitAbstract,
|
|
207
|
+
LSP7CappedSupplyInitAbstract
|
|
208
|
+
)
|
|
209
|
+
{
|
|
210
|
+
require(isMintable, LSP7MintDisabled());
|
|
211
|
+
LSP7CappedSupplyInitAbstract._mint(to, amount, force, data);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/// @notice Hook called before a token transfer to enforce restrictions.
|
|
215
|
+
/// @dev Combines checks from {LSP7CappedBalanceInitAbstract} and {LSP7NonTransferableInitAbstract}.
|
|
216
|
+
/// - Bypasses {LSP7NonTransferableInitAbstract} checks for senders (`from`) holding the `NON_TRANSFERABLE_BYPASS_ROLE` role.
|
|
217
|
+
/// - Bypasses {LSP7CappedBalanceInitAbstract} checks for recipients (`to`) holding the `UNCAPPED_BALANCE_ROLE` role.
|
|
218
|
+
/// - Allows minting (from address(0)) and burning to address(0) regardless of restrictions.
|
|
219
|
+
/// @param from The address sending the tokens.
|
|
220
|
+
/// @param to The address receiving the tokens.
|
|
221
|
+
/// @param amount The amount of tokens being transferred.
|
|
222
|
+
/// @param force Whether to force the transfer.
|
|
223
|
+
/// @param data Additional data for the transfer.
|
|
224
|
+
function _beforeTokenTransfer(
|
|
225
|
+
address from,
|
|
226
|
+
address to,
|
|
227
|
+
uint256 amount,
|
|
228
|
+
bool force,
|
|
229
|
+
bytes memory data
|
|
230
|
+
)
|
|
231
|
+
internal
|
|
232
|
+
virtual
|
|
233
|
+
override(
|
|
234
|
+
LSP7DigitalAssetInitAbstract,
|
|
235
|
+
LSP7NonTransferableInitAbstract,
|
|
236
|
+
LSP7CappedBalanceInitAbstract
|
|
237
|
+
)
|
|
238
|
+
{
|
|
239
|
+
super._beforeTokenTransfer(from, to, amount, force, data);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/// @dev Required override to resolve multiple inheritance. Calls every parent {_transferOwnership} function
|
|
243
|
+
/// via `super` so that each inherited module updates its ownership-dependent state.
|
|
244
|
+
///
|
|
245
|
+
/// When contract ownership changes, this will:
|
|
246
|
+
/// - clear the admin role for: `MINTER_ROLE`, `REVOKER_ROLE`, `NON_TRANSFERABLE_BYPASS_ROLE`, `UNCAPPED_BALANCE_ROLE`
|
|
247
|
+
/// - clear the list of addresses holding the `REVOKER_ROLE`
|
|
248
|
+
function _transferOwnership(
|
|
249
|
+
address newOwner
|
|
250
|
+
)
|
|
251
|
+
internal
|
|
252
|
+
virtual
|
|
253
|
+
override(
|
|
254
|
+
OwnableUpgradeable,
|
|
255
|
+
LSP7MintableInitAbstract,
|
|
256
|
+
LSP7CappedBalanceInitAbstract,
|
|
257
|
+
LSP7NonTransferableInitAbstract,
|
|
258
|
+
LSP7RevokableInitAbstract
|
|
259
|
+
)
|
|
260
|
+
{
|
|
261
|
+
super._transferOwnership(newOwner);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/// @dev Mint initial tokens without enforcing check if the token contract is mintable or not.
|
|
265
|
+
/// Enforces the configured capped-supply value directly before bypassing the mintable check.
|
|
266
|
+
function _initialMint(address to, uint256 amount) private {
|
|
267
|
+
uint256 configuredTokenSupplyCap = LSP7CappedSupplyInitAbstract
|
|
268
|
+
.tokenSupplyCap();
|
|
269
|
+
|
|
270
|
+
bool exceedsSupplyCap = amount > configuredTokenSupplyCap;
|
|
271
|
+
|
|
272
|
+
require(
|
|
273
|
+
configuredTokenSupplyCap == 0 || !exceedsSupplyCap,
|
|
274
|
+
LSP7CappedSupplyCannotMintOverCap()
|
|
275
|
+
);
|
|
276
|
+
LSP7DigitalAssetInitAbstract._mint(to, amount, true, "");
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/// @dev Returns whether the current call is a legitimate revocation that should bypass the
|
|
280
|
+
/// {LSP7NonTransferableInitAbstract} and {LSP7CappedBalanceInitAbstract} restrictions when revoking tokens from a token holder.
|
|
281
|
+
///
|
|
282
|
+
/// Returns `true` only when all of the following conditions are met:
|
|
283
|
+
/// - the function being called is {revoke}.
|
|
284
|
+
/// - the revoking feature is enabled.
|
|
285
|
+
/// - the caller (`msg.sender`) holds the `REVOKER_ROLE`.
|
|
286
|
+
/// - the recipient (`to`) is either the contract `owner()` or a revoker (an address holding the `REVOKER_ROLE`).
|
|
287
|
+
function _isRevocationBypass(address to) private view returns (bool) {
|
|
288
|
+
return
|
|
289
|
+
msg.sig == this.revoke.selector &&
|
|
290
|
+
isRevokable() &&
|
|
291
|
+
hasRole(REVOKER_ROLE, msg.sender) &&
|
|
292
|
+
(to == owner() || hasRole(REVOKER_ROLE, to));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
|
|
3
|
-
pragma solidity ^0.8.4;
|
|
4
|
-
|
|
5
|
-
// interfaces
|
|
6
|
-
import {ILSP7Mintable} from "./ILSP7Mintable.sol";
|
|
2
|
+
pragma solidity ^0.8.27;
|
|
7
3
|
|
|
8
4
|
// modules
|
|
9
5
|
import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol";
|
|
6
|
+
import {
|
|
7
|
+
LSP7MintableAbstract
|
|
8
|
+
} from "../extensions/LSP7Mintable/LSP7MintableAbstract.sol";
|
|
9
|
+
import {
|
|
10
|
+
AccessControlExtendedAbstract
|
|
11
|
+
} from "../extensions/AccessControlExtended/AccessControlExtendedAbstract.sol";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* @title LSP7DigitalAsset deployable preset contract with a public {mint} function callable
|
|
14
|
+
* @title LSP7DigitalAsset deployable preset contract with a public {mint} function callable by addresses holding `MINTER_ROLE`.
|
|
13
15
|
*/
|
|
14
|
-
contract LSP7Mintable is
|
|
16
|
+
contract LSP7Mintable is LSP7MintableAbstract {
|
|
15
17
|
/**
|
|
16
|
-
* @notice Deploying a `LSP7Mintable` token contract
|
|
17
|
-
*
|
|
18
|
-
*
|
|
18
|
+
* @notice Deploying a `LSP7Mintable` token contract.
|
|
19
|
+
* @dev Set the token to be mintable to allow minting more tokens after deployment.
|
|
19
20
|
* @param name_ The name of the token.
|
|
20
21
|
* @param symbol_ The symbol of the token.
|
|
21
22
|
* @param newOwner_ The owner of the token contract.
|
|
22
23
|
* @param lsp4TokenType_ The type of token this digital asset contract represents (`0` = Token, `1` = NFT, `2` = Collection).
|
|
23
|
-
* @param isNonDivisible_ Specify if the LSP7 token is
|
|
24
|
+
* @param isNonDivisible_ Specify if the LSP7 token is divisible (decimals = 18) or non-divisible (decimals = 0).
|
|
24
25
|
*/
|
|
25
26
|
constructor(
|
|
26
27
|
string memory name_,
|
|
@@ -36,17 +37,7 @@ contract LSP7Mintable is LSP7DigitalAsset, ILSP7Mintable {
|
|
|
36
37
|
lsp4TokenType_,
|
|
37
38
|
isNonDivisible_
|
|
38
39
|
)
|
|
40
|
+
AccessControlExtendedAbstract()
|
|
41
|
+
LSP7MintableAbstract(true)
|
|
39
42
|
{}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @dev Public {_mint} function only callable by the {owner}.
|
|
43
|
-
*/
|
|
44
|
-
function mint(
|
|
45
|
-
address to,
|
|
46
|
-
uint256 amount,
|
|
47
|
-
bool force,
|
|
48
|
-
bytes memory data
|
|
49
|
-
) public virtual override onlyOwner {
|
|
50
|
-
_mint(to, amount, force, data);
|
|
51
|
-
}
|
|
52
43
|
}
|