@lukso/lsp-smart-contracts 0.4.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 (109) hide show
  1. package/CONTRIBUTING.md +18 -0
  2. package/LICENSE +201 -0
  3. package/README.md +75 -0
  4. package/artifacts/Create2Factory.json +107 -0
  5. package/artifacts/LSP1UniversalReceiverDelegateUP.json +64 -0
  6. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +66 -0
  7. package/artifacts/LSP1UniversalReceiverDelegateVault.json +64 -0
  8. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +66 -0
  9. package/artifacts/LSP6KeyManager.json +222 -0
  10. package/artifacts/LSP6KeyManagerInit.json +224 -0
  11. package/artifacts/LSP7CappedSupply.json +404 -0
  12. package/artifacts/LSP7CappedSupplyInit.json +481 -0
  13. package/artifacts/LSP7CompatibilityForERC20.json +495 -0
  14. package/artifacts/LSP7DigitalAsset.json +417 -0
  15. package/artifacts/LSP7DigitalAssetInit.json +455 -0
  16. package/artifacts/LSP7Mintable.json +445 -0
  17. package/artifacts/LSP7MintableInit.json +483 -0
  18. package/artifacts/LSP8CappedSupply.json +459 -0
  19. package/artifacts/LSP8CappedSupplyInit.json +508 -0
  20. package/artifacts/LSP8CompatibilityForERC721.json +711 -0
  21. package/artifacts/LSP8IdentifiableDigitalAsset.json +467 -0
  22. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +482 -0
  23. package/artifacts/LSP8Mintable.json +495 -0
  24. package/artifacts/LSP8MintableInit.json +510 -0
  25. package/artifacts/UniversalProfile.json +373 -0
  26. package/artifacts/UniversalProfileInit.json +375 -0
  27. package/constants.ts +350 -0
  28. package/contracts/Factories/Create2Factory.sol +92 -0
  29. package/contracts/LSP0ERC725Account/LSP0Constants.sol +14 -0
  30. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +23 -0
  31. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +119 -0
  32. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +20 -0
  33. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +33 -0
  34. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +37 -0
  35. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +22 -0
  36. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +17 -0
  37. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +189 -0
  38. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +26 -0
  39. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +52 -0
  40. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +26 -0
  41. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +28 -0
  42. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +114 -0
  43. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +23 -0
  44. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +41 -0
  45. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +23 -0
  46. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +25 -0
  47. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +23 -0
  48. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +47 -0
  49. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +19 -0
  50. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +36 -0
  51. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +30 -0
  52. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +41 -0
  53. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +52 -0
  54. package/contracts/LSP6KeyManager/LSP6Constants.sol +28 -0
  55. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +21 -0
  56. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +444 -0
  57. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +19 -0
  58. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +26 -0
  59. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +186 -0
  60. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +12 -0
  61. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +35 -0
  62. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +394 -0
  63. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +29 -0
  64. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +44 -0
  65. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +17 -0
  66. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +47 -0
  67. package/contracts/LSP7DigitalAsset/extensions/ILSP7Mintable.sol +32 -0
  68. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +45 -0
  69. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +55 -0
  70. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +24 -0
  71. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +50 -0
  72. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +76 -0
  73. package/contracts/LSP7DigitalAsset/extensions/LSP7Mintable.sol +41 -0
  74. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableCore.sol +26 -0
  75. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInit.sol +26 -0
  76. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +47 -0
  77. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +223 -0
  78. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +18 -0
  79. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +35 -0
  80. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +470 -0
  81. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +29 -0
  82. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +41 -0
  83. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +17 -0
  84. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +108 -0
  85. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Mintable.sol +32 -0
  86. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +53 -0
  87. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +56 -0
  88. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +24 -0
  89. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +55 -0
  90. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityConstants.sol +6 -0
  91. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +252 -0
  92. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Mintable.sol +36 -0
  93. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableCore.sol +29 -0
  94. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInit.sol +24 -0
  95. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +44 -0
  96. package/contracts/LSP9Vault/LSP9Constants.sol +12 -0
  97. package/contracts/LSP9Vault/LSP9Vault.sol +56 -0
  98. package/contracts/LSP9Vault/LSP9VaultCore.sol +174 -0
  99. package/contracts/LSP9Vault/LSP9VaultInit.sol +19 -0
  100. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +60 -0
  101. package/contracts/UniversalProfile.sol +37 -0
  102. package/contracts/UniversalProfileCore.sol +56 -0
  103. package/contracts/UniversalProfileInit.sol +19 -0
  104. package/contracts/UniversalProfileInitAbstract.sol +48 -0
  105. package/contracts/Utils/ERC725Utils.sol +169 -0
  106. package/contracts/Utils/LSP2Utils.sol +127 -0
  107. package/contracts/Utils/LSP6Utils.sol +77 -0
  108. package/contracts/Utils/UtilsLib.sol +23 -0
  109. package/package.json +84 -0
@@ -0,0 +1,35 @@
1
+ // SPDX-License-Identifier: CC0-1.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // constants
5
+ import "./LSP7Constants.sol";
6
+ import "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
7
+
8
+ // modules
9
+ import "./LSP7DigitalAssetCore.sol";
10
+ import "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol";
11
+ import "@erc725/smart-contracts/contracts/ERC725Y.sol";
12
+
13
+ /**
14
+ * @title LSP7DigitalAsset contract
15
+ * @author Matthew Stevens
16
+ * @dev Implementation of a LSP7 compliant contract.
17
+ */
18
+ contract LSP7DigitalAsset is LSP4DigitalAssetMetadata, LSP7DigitalAssetCore {
19
+ /**
20
+ * @notice Sets the token-Metadata and register LSP7InterfaceId
21
+ * @param name_ The name of the token
22
+ * @param symbol_ The symbol of the token
23
+ * @param newOwner_ The owner of the the token-Metadata
24
+ * @param isNFT_ Specify if the LSP7 token is a fungible or non-fungible token
25
+ */
26
+ constructor(
27
+ string memory name_,
28
+ string memory symbol_,
29
+ address newOwner_,
30
+ bool isNFT_
31
+ ) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {
32
+ _isNFT = isNFT_;
33
+ _registerInterface(_INTERFACEID_LSP7);
34
+ }
35
+ }
@@ -0,0 +1,394 @@
1
+ // SPDX-License-Identifier: CC0-1.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // constants
5
+ import "./LSP7Constants.sol";
6
+ import "../LSP1UniversalReceiver/LSP1Constants.sol";
7
+ import "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
8
+
9
+ // interfaces
10
+ import "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
11
+ import "./ILSP7DigitalAsset.sol";
12
+
13
+ // modules
14
+ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
15
+ import "@openzeppelin/contracts/utils/Address.sol";
16
+ import "@openzeppelin/contracts/utils/Context.sol";
17
+ import "@erc725/smart-contracts/contracts/ERC725Y.sol";
18
+
19
+ // library
20
+ import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
21
+
22
+ /**
23
+ * @title LSP7DigitalAsset contract
24
+ * @author Matthew Stevens
25
+ * @dev Core Implementation of a LSP7 compliant contract.
26
+ */
27
+ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
28
+ using EnumerableSet for EnumerableSet.AddressSet;
29
+ using EnumerableSet for EnumerableSet.Bytes32Set;
30
+ using Address for address;
31
+
32
+ // --- Storage
33
+
34
+ bool internal _isNFT;
35
+
36
+ uint256 internal _existingTokens;
37
+
38
+ // Mapping from `tokenOwner` to an `amount` of tokens
39
+ mapping(address => uint256) internal _tokenOwnerBalances;
40
+
41
+ // Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
42
+ mapping(address => mapping(address => uint256))
43
+ internal _operatorAuthorizedAmount;
44
+
45
+ // --- Token queries
46
+
47
+ /**
48
+ * @inheritdoc ILSP7DigitalAsset
49
+ */
50
+ function decimals() public view override returns (uint256) {
51
+ return _isNFT ? 0 : 18;
52
+ }
53
+
54
+ /**
55
+ * @inheritdoc ILSP7DigitalAsset
56
+ */
57
+ function totalSupply() public view override returns (uint256) {
58
+ return _existingTokens;
59
+ }
60
+
61
+ // --- Token owner queries
62
+
63
+ /**
64
+ * @inheritdoc ILSP7DigitalAsset
65
+ */
66
+ function balanceOf(address tokenOwner)
67
+ public
68
+ view
69
+ override
70
+ returns (uint256)
71
+ {
72
+ return _tokenOwnerBalances[tokenOwner];
73
+ }
74
+
75
+ // --- Operator functionality
76
+
77
+ /**
78
+ * @inheritdoc ILSP7DigitalAsset
79
+ */
80
+ function authorizeOperator(address operator, uint256 amount)
81
+ public
82
+ virtual
83
+ override
84
+ {
85
+ _updateOperator(_msgSender(), operator, amount);
86
+ }
87
+
88
+ /**
89
+ * @inheritdoc ILSP7DigitalAsset
90
+ */
91
+ function revokeOperator(address operator) public virtual override {
92
+ _updateOperator(_msgSender(), operator, 0);
93
+ }
94
+
95
+ /**
96
+ * @inheritdoc ILSP7DigitalAsset
97
+ */
98
+ function isOperatorFor(address operator, address tokenOwner)
99
+ public
100
+ view
101
+ virtual
102
+ override
103
+ returns (uint256)
104
+ {
105
+ if (tokenOwner == operator) {
106
+ return _tokenOwnerBalances[tokenOwner];
107
+ } else {
108
+ return _operatorAuthorizedAmount[tokenOwner][operator];
109
+ }
110
+ }
111
+
112
+ // --- Transfer functionality
113
+
114
+ /**
115
+ * @inheritdoc ILSP7DigitalAsset
116
+ */
117
+ function transfer(
118
+ address from,
119
+ address to,
120
+ uint256 amount,
121
+ bool force,
122
+ bytes memory data
123
+ ) public virtual override {
124
+ address operator = _msgSender();
125
+ if (operator != from) {
126
+ uint256 operatorAmount = _operatorAuthorizedAmount[from][operator];
127
+ require(
128
+ operatorAmount >= amount,
129
+ "LSP7: transfer amount exceeds operator authorized amount"
130
+ );
131
+ _updateOperator(
132
+ from,
133
+ operator,
134
+ _operatorAuthorizedAmount[from][operator] - amount
135
+ );
136
+ }
137
+
138
+ _transfer(from, to, amount, force, data);
139
+ }
140
+
141
+ /**
142
+ * @inheritdoc ILSP7DigitalAsset
143
+ */
144
+ function transferBatch(
145
+ address[] memory from,
146
+ address[] memory to,
147
+ uint256[] memory amount,
148
+ bool force,
149
+ bytes[] memory data
150
+ ) external virtual override {
151
+ require(
152
+ from.length == to.length &&
153
+ from.length == amount.length &&
154
+ from.length == data.length,
155
+ "LSP7: transferBatch list length mismatch"
156
+ );
157
+
158
+ for (uint256 i = 0; i < from.length; i++) {
159
+ // using the public transfer function to handle updates to operator authorized amounts
160
+ transfer(from[i], to[i], amount[i], force, data[i]);
161
+ }
162
+ }
163
+
164
+ /**
165
+ * @dev Changes token `amount` the `operator` has access to from `tokenOwner` tokens. If the
166
+ * amount is zero then the operator is being revoked, otherwise the operator amount is being
167
+ * modified.
168
+ *
169
+ * See {isOperatorFor}.
170
+ *
171
+ * Emits either {AuthorizedOperator} or {RevokedOperator} event.
172
+ *
173
+ * Requirements
174
+ *
175
+ * - `operator` cannot be calling address.
176
+ * - `operator` cannot be the zero address.
177
+ */
178
+ function _updateOperator(
179
+ address tokenOwner,
180
+ address operator,
181
+ uint256 amount
182
+ ) internal virtual {
183
+ require(
184
+ operator != tokenOwner,
185
+ "LSP7: updating operator failed, can not use token owner as operator"
186
+ );
187
+ require(
188
+ operator != address(0),
189
+ "LSP7: updating operator failed, operator can not be zero address"
190
+ );
191
+ require(
192
+ tokenOwner != address(0),
193
+ "LSP7: updating operator failed, can not set operator for zero address"
194
+ );
195
+
196
+ _operatorAuthorizedAmount[tokenOwner][operator] = amount;
197
+
198
+ if (amount > 0) {
199
+ emit AuthorizedOperator(operator, tokenOwner, amount);
200
+ } else {
201
+ emit RevokedOperator(operator, tokenOwner);
202
+ }
203
+ }
204
+
205
+ /**
206
+ * @dev Mints `amount` tokens and transfers it to `to`.
207
+ *
208
+ * Requirements:
209
+ *
210
+ * - `to` cannot be the zero address.
211
+ *
212
+ * Emits a {Transfer} event.
213
+ */
214
+ function _mint(
215
+ address to,
216
+ uint256 amount,
217
+ bool force,
218
+ bytes memory data
219
+ ) internal virtual {
220
+ require(to != address(0), "LSP7: mint to the zero address not allowed");
221
+
222
+ address operator = _msgSender();
223
+
224
+ _beforeTokenTransfer(address(0), to, amount);
225
+
226
+ _tokenOwnerBalances[to] += amount;
227
+
228
+ emit Transfer(operator, address(0), to, amount, force, data);
229
+
230
+ _notifyTokenReceiver(address(0), to, amount, force, data);
231
+ }
232
+
233
+ /**
234
+ * @dev Destroys `amount` tokens.
235
+ *
236
+ * Requirements:
237
+ *
238
+ * - `from` cannot be the zero address.
239
+ * - `from` must have at least `amount` tokens.
240
+ * - If the caller is not `from`, it must be an operator for `from` with access to at least
241
+ * `amount` tokens.
242
+ *
243
+ * Emits a {Transfer} event.
244
+ */
245
+ function _burn(
246
+ address from,
247
+ uint256 amount,
248
+ bytes memory data
249
+ ) internal virtual {
250
+ require(from != address(0), "LSP7: burn from the zero address");
251
+ require(
252
+ _tokenOwnerBalances[from] >= amount,
253
+ "LSP7: burn amount exceeds tokenOwner balance"
254
+ );
255
+
256
+ address operator = _msgSender();
257
+ if (operator != from) {
258
+ require(
259
+ _operatorAuthorizedAmount[from][operator] >= amount,
260
+ "LSP7: burn amount exceeds operator authorized amount"
261
+ );
262
+ _operatorAuthorizedAmount[from][operator] -= amount;
263
+ }
264
+
265
+ _notifyTokenSender(from, address(0), amount, data);
266
+
267
+ _beforeTokenTransfer(from, address(0), amount);
268
+
269
+ _tokenOwnerBalances[from] -= amount;
270
+
271
+ emit Transfer(operator, from, address(0), amount, false, data);
272
+ }
273
+
274
+ /**
275
+ * @dev Transfers `amount` tokens from `from` to `to`.
276
+ *
277
+ * Requirements:
278
+ *
279
+ * - `to` cannot be the zero address.
280
+ * - `from` cannot be the zero address.
281
+ * - `from` must have at least `amount` tokens.
282
+ * - If the caller is not `from`, it must be an operator for `from` with access to at least
283
+ * `amount` tokens.
284
+ *
285
+ * Emits a {Transfer} event.
286
+ */
287
+ function _transfer(
288
+ address from,
289
+ address to,
290
+ uint256 amount,
291
+ bool force,
292
+ bytes memory data
293
+ ) internal virtual {
294
+ require(from != address(0), "LSP7: transfer from the zero address");
295
+ require(to != address(0), "LSP7: transfer to the zero address");
296
+ require(
297
+ _tokenOwnerBalances[from] >= amount,
298
+ "LSP7: transfer amount exceeds tokenOwner balance"
299
+ );
300
+
301
+ address operator = _msgSender();
302
+
303
+ _notifyTokenSender(from, to, amount, data);
304
+
305
+ _beforeTokenTransfer(from, to, amount);
306
+
307
+ _tokenOwnerBalances[from] -= amount;
308
+ _tokenOwnerBalances[to] += amount;
309
+
310
+ emit Transfer(operator, from, to, amount, force, data);
311
+
312
+ _notifyTokenReceiver(from, to, amount, force, data);
313
+ }
314
+
315
+ /**
316
+ * @dev Hook that is called before any token transfer. This includes minting
317
+ * and burning.
318
+ *
319
+ * Calling conditions:
320
+ *
321
+ * - When `from` and `to` are both non-zero, ``from``'s `amount` tokens will be
322
+ * transferred to `to`.
323
+ * - When `from` is zero, `amount` tokens will be minted for `to`.
324
+ * - When `to` is zero, ``from``'s `amount` tokens will be burned.
325
+ */
326
+ function _beforeTokenTransfer(
327
+ address from,
328
+ address to,
329
+ uint256 amount
330
+ ) internal virtual {
331
+ // tokens being minted
332
+ if (from == address(0)) {
333
+ _existingTokens += amount;
334
+ }
335
+
336
+ // tokens being burned
337
+ if (to == address(0)) {
338
+ _existingTokens -= amount;
339
+ }
340
+ }
341
+
342
+ /**
343
+ * @dev An attempt is made to notify the token sender about the `amount` tokens changing owners using
344
+ * LSP1 interface.
345
+ */
346
+ function _notifyTokenSender(
347
+ address from,
348
+ address to,
349
+ uint256 amount,
350
+ bytes memory data
351
+ ) internal virtual {
352
+ if (
353
+ ERC165Checker.supportsERC165(from) &&
354
+ ERC165Checker.supportsInterface(from, _INTERFACEID_LSP1)
355
+ ) {
356
+ bytes memory packedData = abi.encodePacked(from, to, amount, data);
357
+ ILSP1UniversalReceiver(from).universalReceiver(
358
+ _TYPEID_LSP7_TOKENSSENDER,
359
+ packedData
360
+ );
361
+ }
362
+ }
363
+
364
+ /**
365
+ * @dev An attempt is made to notify the token receiver about the `amount` tokens changing owners
366
+ * using LSP1 interface. When force is FALSE the token receiver MUST support LSP1.
367
+ *
368
+ * The receiver may revert when the token being sent is not wanted.
369
+ */
370
+ function _notifyTokenReceiver(
371
+ address from,
372
+ address to,
373
+ uint256 amount,
374
+ bool force,
375
+ bytes memory data
376
+ ) internal virtual {
377
+ if (
378
+ ERC165Checker.supportsERC165(to) &&
379
+ ERC165Checker.supportsInterface(to, _INTERFACEID_LSP1)
380
+ ) {
381
+ bytes memory packedData = abi.encodePacked(from, to, amount, data);
382
+ ILSP1UniversalReceiver(to).universalReceiver(
383
+ _TYPEID_LSP7_TOKENSRECIPIENT,
384
+ packedData
385
+ );
386
+ } else if (!force) {
387
+ if (to.isContract()) {
388
+ revert("LSP7: token receiver contract missing LSP1 interface");
389
+ } else {
390
+ revert("LSP7: token receiver is EOA");
391
+ }
392
+ }
393
+ }
394
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: CC0-1.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "./LSP7DigitalAssetInitAbstract.sol";
6
+
7
+ /**
8
+ * @title LSP7DigitalAsset contract
9
+ * @author Matthew Stevens
10
+ * @dev Proxy Implementation of a LSP7 compliant contract.
11
+ */
12
+ contract LSP7DigitalAssetInit is LSP7DigitalAssetInitAbstract {
13
+ /**
14
+ * @inheritdoc LSP7DigitalAssetInitAbstract
15
+ */
16
+ function initialize(
17
+ string memory name_,
18
+ string memory symbol_,
19
+ address newOwner_,
20
+ bool isNFT_
21
+ ) public virtual override initializer {
22
+ LSP7DigitalAssetInitAbstract.initialize(
23
+ name_,
24
+ symbol_,
25
+ newOwner_,
26
+ isNFT_
27
+ );
28
+ }
29
+ }
@@ -0,0 +1,44 @@
1
+ // SPDX-License-Identifier: CC0-1.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // constants
5
+ import "./LSP7Constants.sol";
6
+ import "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
7
+
8
+ // modules
9
+ import "./LSP7DigitalAssetCore.sol";
10
+ import "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol";
11
+
12
+ /**
13
+ * @title LSP7DigitalAsset contract
14
+ * @author Matthew Stevens
15
+ * @dev Proxy Implementation of a LSP7 compliant contract.
16
+ */
17
+ abstract contract LSP7DigitalAssetInitAbstract is
18
+ Initializable,
19
+ LSP4DigitalAssetMetadataInitAbstract,
20
+ LSP7DigitalAssetCore
21
+ {
22
+ /**
23
+ * @notice Sets the token-Metadata and register LSP7InterfaceId
24
+ * @param name_ The name of the token
25
+ * @param symbol_ The symbol of the token
26
+ * @param newOwner_ The owner of the the token-Metadata
27
+ * @param isNFT_ Specify if the LSP7 token is a fungible or non-fungible token
28
+ */
29
+ function initialize(
30
+ string memory name_,
31
+ string memory symbol_,
32
+ address newOwner_,
33
+ bool isNFT_
34
+ ) public virtual onlyInitializing {
35
+ _isNFT = isNFT_;
36
+ LSP4DigitalAssetMetadataInitAbstract.initialize(
37
+ name_,
38
+ symbol_,
39
+ newOwner_
40
+ );
41
+
42
+ _registerInterface(_INTERFACEID_LSP7);
43
+ }
44
+ }
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // interfaces
6
+ import "../ILSP7DigitalAsset.sol";
7
+
8
+ /**
9
+ * @dev LSP7 extension, adds token supply cap.
10
+ */
11
+ interface ILSP7CappedSupply is ILSP7DigitalAsset {
12
+ /**
13
+ * @dev Returns the number of tokens that can be minted
14
+ * @return The number of tokens that can be minted
15
+ */
16
+ function tokenSupplyCap() external view returns (uint256);
17
+ }
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // interfaces
6
+ import "../ILSP7DigitalAsset.sol";
7
+
8
+ /**
9
+ * @dev LSP8 extension, for compatibility for clients / tools that expect ERC20.
10
+ */
11
+ interface ILSP7CompatibilityForERC20 is ILSP7DigitalAsset {
12
+ /*
13
+ * @dev Compatible with ERC20 tranfer
14
+ * @param to The receiving address
15
+ * @param amount The amount of tokens to transfer
16
+ */
17
+ function transfer(address to, uint256 amount) external;
18
+
19
+ /*
20
+ * @dev Compatible with ERC20 tranferFrom
21
+ * @param from The sending address
22
+ * @param to The receiving address
23
+ * @param amount The amount of tokens to transfer
24
+ */
25
+ function transferFrom(
26
+ address from,
27
+ address to,
28
+ uint256 amount
29
+ ) external;
30
+
31
+ /*
32
+ * @dev Compatible with ERC20 approve
33
+ * @param operator The address to approve for `amount`
34
+ * @param amount The amount to approve
35
+ */
36
+ function approve(address operator, uint256 amount) external;
37
+
38
+ /*
39
+ * @dev Compatible with ERC20 allowance
40
+ * @param tokenOwner The address of the token owner
41
+ * @param operator The address approved by the `tokenOwner`
42
+ * @return The amount `operator` is approved by `tokenOwner`
43
+ */
44
+ function allowance(address tokenOwner, address operator)
45
+ external
46
+ returns (uint256);
47
+ }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // interfaces
6
+ import "../ILSP7DigitalAsset.sol";
7
+
8
+ /**
9
+ * @dev LSP7 extension, Mintable version.
10
+ */
11
+ interface ILSP7Mintable is ILSP7DigitalAsset {
12
+ /**
13
+ * @param to The address to mint tokens
14
+ * @param amount The amount to mint
15
+ * @param force When set to TRUE, to may be any address but
16
+ * when set to FALSE to must be a contract that supports LSP1 UniversalReceiver
17
+ * @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
18
+ * @dev Mints `amount` tokens and transfers it to `to`.
19
+ *
20
+ * Requirements:
21
+ *
22
+ * - `to` cannot be the zero address.
23
+ *
24
+ * Emits a {Transfer} event.
25
+ */
26
+ function mint(
27
+ address to,
28
+ uint256 amount,
29
+ bool force,
30
+ bytes memory data
31
+ ) external;
32
+ }
@@ -0,0 +1,45 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // modules
6
+ import "./LSP7CappedSupplyCore.sol";
7
+ import "../LSP7DigitalAsset.sol";
8
+
9
+ /**
10
+ * @dev LSP7 extension, adds token supply cap.
11
+ */
12
+ abstract contract LSP7CappedSupply is LSP7DigitalAsset, LSP7CappedSupplyCore {
13
+ /**
14
+ * @notice Sets the token max supply
15
+ * @param tokenSupplyCap_ The Token max supply
16
+ */
17
+ constructor(uint256 tokenSupplyCap_) {
18
+ require(
19
+ tokenSupplyCap_ > 0,
20
+ "LSP7CappedSupply: tokenSupplyCap is zero"
21
+ );
22
+ _tokenSupplyCap = tokenSupplyCap_;
23
+ }
24
+
25
+ // --- Overrides
26
+
27
+ /**
28
+ * @dev Mints `amount` tokens and transfers it to `to`.
29
+ *
30
+ * Requirements:
31
+ *
32
+ * - `tokenSupplyCap() - totalSupply()` must be greater than zero.
33
+ * - `to` cannot be the zero address.
34
+ *
35
+ * Emits a {Transfer} event.
36
+ */
37
+ function _mint(
38
+ address to,
39
+ uint256 amount,
40
+ bool force,
41
+ bytes memory data
42
+ ) internal virtual override(LSP7DigitalAssetCore, LSP7CappedSupplyCore) {
43
+ super._mint(to, amount, force, data);
44
+ }
45
+ }
@@ -0,0 +1,55 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // modules
6
+ import "../LSP7DigitalAssetCore.sol";
7
+
8
+ // interfaces
9
+ import "./ILSP7CappedSupply.sol";
10
+
11
+ /**
12
+ * @dev LSP7 extension, adds token supply cap.
13
+ */
14
+ abstract contract LSP7CappedSupplyCore is
15
+ ILSP7CappedSupply,
16
+ LSP7DigitalAssetCore
17
+ {
18
+ // --- Storage
19
+
20
+ uint256 internal _tokenSupplyCap;
21
+
22
+ // --- Token queries
23
+
24
+ /**
25
+ * @inheritdoc ILSP7CappedSupply
26
+ */
27
+ function tokenSupplyCap() public view virtual override returns (uint256) {
28
+ return _tokenSupplyCap;
29
+ }
30
+
31
+ // --- Transfer functionality
32
+
33
+ /**
34
+ * @dev Mints `amount` and transfers it to `to`.
35
+ *
36
+ * Requirements:
37
+ *
38
+ * - `tokenSupplyCap() - totalSupply()` must be greater than zero.
39
+ * - `to` cannot be the zero address.
40
+ *
41
+ * Emits a {Transfer} event.
42
+ */
43
+ function _mint(
44
+ address to,
45
+ uint256 amount,
46
+ bool force,
47
+ bytes memory data
48
+ ) internal virtual override {
49
+ require(
50
+ totalSupply() + amount <= tokenSupplyCap(),
51
+ "LSP7CappedSupply: tokenSupplyCap reached"
52
+ );
53
+ super._mint(to, amount, force, data);
54
+ }
55
+ }