@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,470 @@
1
+ // SPDX-License-Identifier: CC0-1.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "@openzeppelin/contracts/utils/Address.sol";
6
+ import "@openzeppelin/contracts/utils/Context.sol";
7
+ import "@erc725/smart-contracts/contracts/ERC725Y.sol";
8
+
9
+ // interfaces
10
+ import "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
11
+ import "./ILSP8IdentifiableDigitalAsset.sol";
12
+
13
+ // libraries
14
+ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
15
+ import "../Utils/ERC725Utils.sol";
16
+ import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
17
+
18
+ // constants
19
+ import "./LSP8Constants.sol";
20
+ import "../LSP1UniversalReceiver/LSP1Constants.sol";
21
+ import "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
22
+
23
+ /**
24
+ * @title LSP8IdentifiableDigitalAsset contract
25
+ * @author Matthew Stevens
26
+ * @dev Core Implementation of a LSP8 compliant contract.
27
+ */
28
+ abstract contract LSP8IdentifiableDigitalAssetCore is
29
+ Context,
30
+ ILSP8IdentifiableDigitalAsset
31
+ {
32
+ using EnumerableSet for EnumerableSet.AddressSet;
33
+ using EnumerableSet for EnumerableSet.Bytes32Set;
34
+ using Address for address;
35
+
36
+ // --- Storage
37
+
38
+ uint256 internal _existingTokens;
39
+
40
+ // Mapping from `tokenId` to `tokenOwner`
41
+ mapping(bytes32 => address) internal _tokenOwners;
42
+
43
+ // Mapping `tokenOwner` to owned tokenIds
44
+ mapping(address => EnumerableSet.Bytes32Set) internal _ownedTokens;
45
+
46
+ // Mapping a `tokenId` to its authorized operator addresses.
47
+ mapping(bytes32 => EnumerableSet.AddressSet) internal _operators;
48
+
49
+ // --- Token queries
50
+
51
+ /**
52
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
53
+ */
54
+ function totalSupply() public view override returns (uint256) {
55
+ return _existingTokens;
56
+ }
57
+
58
+ // --- Token owner queries
59
+
60
+ /**
61
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
62
+ */
63
+ function balanceOf(address tokenOwner)
64
+ public
65
+ view
66
+ override
67
+ returns (uint256)
68
+ {
69
+ return _ownedTokens[tokenOwner].length();
70
+ }
71
+
72
+ /**
73
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
74
+ */
75
+ function tokenOwnerOf(bytes32 tokenId)
76
+ public
77
+ view
78
+ override
79
+ returns (address)
80
+ {
81
+ address tokenOwner = _tokenOwners[tokenId];
82
+ require(
83
+ tokenOwner != address(0),
84
+ "LSP8: can not query non existent token"
85
+ );
86
+
87
+ return tokenOwner;
88
+ }
89
+
90
+ /**
91
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
92
+ */
93
+ function tokenIdsOf(address tokenOwner)
94
+ public
95
+ view
96
+ override
97
+ returns (bytes32[] memory)
98
+ {
99
+ require(
100
+ tokenOwner != address(0),
101
+ "LSP8: can not query token for zero address"
102
+ );
103
+
104
+ return _ownedTokens[tokenOwner].values();
105
+ }
106
+
107
+ // --- Operator functionality
108
+
109
+ /**
110
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
111
+ */
112
+ function authorizeOperator(address operator, bytes32 tokenId)
113
+ public
114
+ virtual
115
+ override
116
+ {
117
+ address tokenOwner = tokenOwnerOf(tokenId);
118
+ require(
119
+ tokenOwner == _msgSender(),
120
+ "LSP8: caller can not authorize operator for token id"
121
+ );
122
+
123
+ require(
124
+ tokenOwner != operator,
125
+ "LSP8: can not authorize token owner as operator"
126
+ );
127
+ require(operator != address(0), "LSP8: can not authorize zero address");
128
+
129
+ _operators[tokenId].add(operator);
130
+
131
+ emit AuthorizedOperator(operator, tokenOwner, tokenId);
132
+ }
133
+
134
+ /**
135
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
136
+ */
137
+ function revokeOperator(address operator, bytes32 tokenId)
138
+ public
139
+ virtual
140
+ override
141
+ {
142
+ address tokenOwner = tokenOwnerOf(tokenId);
143
+ require(
144
+ tokenOwner == _msgSender(),
145
+ "LSP8: caller can not revoke operator for token id"
146
+ );
147
+
148
+ require(
149
+ operator != tokenOwner,
150
+ "LSP8: can not revoke token owner as operator"
151
+ );
152
+ require(
153
+ operator != address(0),
154
+ "LSP8: can not revoke zero address as operator"
155
+ );
156
+
157
+ _revokeOperator(operator, tokenOwner, tokenId);
158
+ }
159
+
160
+ /**
161
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
162
+ */
163
+ function isOperatorFor(address operator, bytes32 tokenId)
164
+ public
165
+ view
166
+ virtual
167
+ override
168
+ returns (bool)
169
+ {
170
+ require(
171
+ _exists(tokenId),
172
+ "LSP8: can not query operator for non existent token"
173
+ );
174
+
175
+ return _isOperatorOrOwner(operator, tokenId);
176
+ }
177
+
178
+ /**
179
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
180
+ */
181
+ function getOperatorsOf(bytes32 tokenId)
182
+ public
183
+ view
184
+ virtual
185
+ override
186
+ returns (address[] memory)
187
+ {
188
+ require(
189
+ _exists(tokenId),
190
+ "LSP8: can not query operator for non existent token"
191
+ );
192
+
193
+ return _operators[tokenId].values();
194
+ }
195
+
196
+ function _isOperatorOrOwner(address caller, bytes32 tokenId)
197
+ internal
198
+ view
199
+ virtual
200
+ returns (bool)
201
+ {
202
+ address tokenOwner = tokenOwnerOf(tokenId);
203
+
204
+ return (caller == tokenOwner || _operators[tokenId].contains(caller));
205
+ }
206
+
207
+ // --- Transfer functionality
208
+
209
+ /**
210
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
211
+ */
212
+ function transfer(
213
+ address from,
214
+ address to,
215
+ bytes32 tokenId,
216
+ bool force,
217
+ bytes memory data
218
+ ) public virtual override {
219
+ require(
220
+ _isOperatorOrOwner(_msgSender(), tokenId),
221
+ "LSP8: can not transfer, caller is not the owner or operator of token"
222
+ );
223
+ _transfer(from, to, tokenId, force, data);
224
+ }
225
+
226
+ /**
227
+ * @inheritdoc ILSP8IdentifiableDigitalAsset
228
+ */
229
+ function transferBatch(
230
+ address[] memory from,
231
+ address[] memory to,
232
+ bytes32[] memory tokenId,
233
+ bool force,
234
+ bytes[] memory data
235
+ ) external virtual override {
236
+ require(
237
+ from.length == to.length &&
238
+ from.length == tokenId.length &&
239
+ from.length == data.length,
240
+ "LSP8: transferBatch list length mismatch"
241
+ );
242
+
243
+ for (uint256 i = 0; i < from.length; i++) {
244
+ transfer(from[i], to[i], tokenId[i], force, data[i]);
245
+ }
246
+ }
247
+
248
+ function _revokeOperator(
249
+ address operator,
250
+ address tokenOwner,
251
+ bytes32 tokenId
252
+ ) internal virtual {
253
+ _operators[tokenId].remove(operator);
254
+ emit RevokedOperator(operator, tokenOwner, tokenId);
255
+ }
256
+
257
+ function _clearOperators(address tokenOwner, bytes32 tokenId)
258
+ internal
259
+ virtual
260
+ {
261
+ // TODO: here is a good exmaple of why having multiple operators will be expensive.. we
262
+ // need to clear them on token transfer
263
+ //
264
+ // NOTE: this may cause a tx to fail if there is too many operators to clear, in which case
265
+ // the tokenOwner needs to call `revokeOperator` until there is less operators to clear and
266
+ // the desired `transfer` or `burn` call can succeed.
267
+ EnumerableSet.AddressSet storage operatorsForTokenId = _operators[
268
+ tokenId
269
+ ];
270
+
271
+ uint256 operatorListLength = operatorsForTokenId.length();
272
+ for (uint256 i = 0; i < operatorListLength; i++) {
273
+ // we are emptying the list, always remove from index 0
274
+ address operator = operatorsForTokenId.at(0);
275
+ _revokeOperator(operator, tokenOwner, tokenId);
276
+ }
277
+ }
278
+
279
+ /**
280
+ * @dev Returns whether `tokenId` exists.
281
+ *
282
+ * Tokens start existing when they are minted (`_mint`), and stop existing when they are burned
283
+ * (`_burn`).
284
+ */
285
+ function _exists(bytes32 tokenId) internal view virtual returns (bool) {
286
+ return _tokenOwners[tokenId] != address(0);
287
+ }
288
+
289
+ /**
290
+ * @dev Mints `tokenId` and transfers it to `to`.
291
+ *
292
+ * Requirements:
293
+ *
294
+ * - `tokenId` must not exist.
295
+ * - `to` cannot be the zero address.
296
+ *
297
+ * Emits a {Transfer} event.
298
+ */
299
+ function _mint(
300
+ address to,
301
+ bytes32 tokenId,
302
+ bool force,
303
+ bytes memory data
304
+ ) internal virtual {
305
+ require(to != address(0), "LSP8: can not mint to zero address");
306
+ require(!_exists(tokenId), "LSP8: tokenId already minted");
307
+
308
+ address operator = _msgSender();
309
+
310
+ _beforeTokenTransfer(address(0), to, tokenId);
311
+
312
+ _ownedTokens[to].add(tokenId);
313
+ _tokenOwners[tokenId] = to;
314
+
315
+ emit Transfer(operator, address(0), to, tokenId, force, data);
316
+
317
+ _notifyTokenReceiver(address(0), to, tokenId, force, data);
318
+ }
319
+
320
+ /**
321
+ * @dev Destroys `tokenId`.
322
+ * The approval is cleared when the token is burned.
323
+ *
324
+ * Requirements:
325
+ *
326
+ * - `tokenId` must exist.
327
+ *
328
+ * Emits a {Transfer} event.
329
+ */
330
+ function _burn(bytes32 tokenId, bytes memory data) internal virtual {
331
+ address tokenOwner = tokenOwnerOf(tokenId);
332
+ address operator = _msgSender();
333
+
334
+ _notifyTokenSender(tokenOwner, address(0), tokenId, data);
335
+
336
+ _beforeTokenTransfer(tokenOwner, address(0), tokenId);
337
+
338
+ // Clear operators
339
+ _clearOperators(tokenOwner, tokenId);
340
+
341
+ _ownedTokens[tokenOwner].remove(tokenId);
342
+ delete _tokenOwners[tokenId];
343
+
344
+ emit Transfer(operator, tokenOwner, address(0), tokenId, false, data);
345
+ }
346
+
347
+ /**
348
+ * @dev Transfers `tokenId` from `from` to `to`.
349
+ *
350
+ * Requirements:
351
+ *
352
+ * - `to` cannot be the zero address.
353
+ * - `tokenId` token must be owned by `from`.
354
+ *
355
+ * Emits a {Transfer} event.
356
+ */
357
+ function _transfer(
358
+ address from,
359
+ address to,
360
+ bytes32 tokenId,
361
+ bool force,
362
+ bytes memory data
363
+ ) internal virtual {
364
+ require(
365
+ tokenOwnerOf(tokenId) == from,
366
+ "LSP8: transfer of tokenId from incorrect owner"
367
+ );
368
+ require(to != address(0), "LSP8: can not transfer to zero address");
369
+
370
+ address operator = _msgSender();
371
+
372
+ _notifyTokenSender(from, to, tokenId, data);
373
+
374
+ _beforeTokenTransfer(from, to, tokenId);
375
+
376
+ // Clear operators from the previous owner
377
+ _clearOperators(from, tokenId);
378
+
379
+ _ownedTokens[from].remove(tokenId);
380
+ _ownedTokens[to].add(tokenId);
381
+ _tokenOwners[tokenId] = to;
382
+
383
+ emit Transfer(operator, from, to, tokenId, force, data);
384
+
385
+ _notifyTokenReceiver(from, to, tokenId, force, data);
386
+ }
387
+
388
+ /**
389
+ * @dev Hook that is called before any token transfer. This includes minting
390
+ * and burning.
391
+ *
392
+ * Calling conditions:
393
+ *
394
+ * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
395
+ * transferred to `to`.
396
+ * - When `from` is zero, `tokenId` will be minted for `to`.
397
+ * - When `to` is zero, ``from``'s `tokenId` will be burned.
398
+ */
399
+ function _beforeTokenTransfer(
400
+ address from,
401
+ address to,
402
+ bytes32 tokenId
403
+ ) internal virtual {
404
+ // silence compiler warning about unused variable
405
+ tokenId;
406
+
407
+ // token being minted
408
+ if (from == address(0)) {
409
+ _existingTokens += 1;
410
+ }
411
+
412
+ // token being burned
413
+ if (to == address(0)) {
414
+ _existingTokens -= 1;
415
+ }
416
+ }
417
+
418
+ /**
419
+ * @dev An attempt is made to notify the token sender about the `tokenId` changing owners using
420
+ * LSP1 interface.
421
+ */
422
+ function _notifyTokenSender(
423
+ address from,
424
+ address to,
425
+ bytes32 tokenId,
426
+ bytes memory data
427
+ ) internal virtual {
428
+ if (
429
+ ERC165Checker.supportsERC165(from) &&
430
+ ERC165Checker.supportsInterface(from, _INTERFACEID_LSP1)
431
+ ) {
432
+ bytes memory packedData = abi.encodePacked(from, to, tokenId, data);
433
+ ILSP1UniversalReceiver(from).universalReceiver(
434
+ _TYPEID_LSP8_TOKENSSENDER,
435
+ packedData
436
+ );
437
+ }
438
+ }
439
+
440
+ /**
441
+ * @dev An attempt is made to notify the token receiver about the `tokenId` changing owners
442
+ * using LSP1 interface. When force is FALSE the token receiver MUST support LSP1.
443
+ *
444
+ * The receiver may revert when the token being sent is not wanted.
445
+ */
446
+ function _notifyTokenReceiver(
447
+ address from,
448
+ address to,
449
+ bytes32 tokenId,
450
+ bool force,
451
+ bytes memory data
452
+ ) internal virtual {
453
+ if (
454
+ ERC165Checker.supportsERC165(to) &&
455
+ ERC165Checker.supportsInterface(to, _INTERFACEID_LSP1)
456
+ ) {
457
+ bytes memory packedData = abi.encodePacked(from, to, tokenId, data);
458
+ ILSP1UniversalReceiver(to).universalReceiver(
459
+ _TYPEID_LSP8_TOKENSRECIPIENT,
460
+ packedData
461
+ );
462
+ } else if (!force) {
463
+ if (to.isContract()) {
464
+ revert("LSP8: token receiver contract missing LSP1 interface");
465
+ } else {
466
+ revert("LSP8: token receiver is EOA");
467
+ }
468
+ }
469
+ }
470
+ }
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: CC0-1.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "./LSP8IdentifiableDigitalAssetInitAbstract.sol";
6
+
7
+ /**
8
+ * @title LSP8IdentifiableDigitalAsset contract
9
+ * @author Matthew Stevens
10
+ * @dev Proxy Implementation of a LSP8 compliant contract.
11
+ */
12
+ contract LSP8IdentifiableDigitalAssetInit is
13
+ LSP8IdentifiableDigitalAssetInitAbstract
14
+ {
15
+ /**
16
+ * @inheritdoc LSP8IdentifiableDigitalAssetInitAbstract
17
+ */
18
+ function initialize(
19
+ string memory name_,
20
+ string memory symbol_,
21
+ address newOwner_
22
+ ) public virtual override initializer {
23
+ LSP8IdentifiableDigitalAssetInitAbstract.initialize(
24
+ name_,
25
+ symbol_,
26
+ newOwner_
27
+ );
28
+ }
29
+ }
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: CC0-1.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // modules
5
+ import "./LSP8IdentifiableDigitalAssetCore.sol";
6
+ import "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol";
7
+
8
+ // constants
9
+ import "./LSP8Constants.sol";
10
+ import "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
11
+
12
+ /**
13
+ * @title LSP8IdentifiableDigitalAsset contract
14
+ * @author Matthew Stevens
15
+ * @dev Proxy Implementation of a LSP8 compliant contract.
16
+ */
17
+ abstract contract LSP8IdentifiableDigitalAssetInitAbstract is
18
+ Initializable,
19
+ LSP4DigitalAssetMetadataInitAbstract,
20
+ LSP8IdentifiableDigitalAssetCore
21
+ {
22
+ /**
23
+ * @notice Sets the token-Metadata and register LSP8InterfaceId
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
+ */
28
+ function initialize(
29
+ string memory name_,
30
+ string memory symbol_,
31
+ address newOwner_
32
+ ) public virtual override onlyInitializing {
33
+ LSP4DigitalAssetMetadataInitAbstract.initialize(
34
+ name_,
35
+ symbol_,
36
+ newOwner_
37
+ );
38
+
39
+ _registerInterface(_INTERFACEID_LSP8);
40
+ }
41
+ }
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // interfaces
6
+ import "../ILSP8IdentifiableDigitalAsset.sol";
7
+
8
+ /**
9
+ * @dev LSP8 extension, adds token supply cap.
10
+ */
11
+ interface ILSP8CappedSupply is ILSP8IdentifiableDigitalAsset {
12
+ /**
13
+ * @dev Returns the number of tokens that can be minted.
14
+ * @return The token max supply
15
+ */
16
+ function tokenSupplyCap() external view returns (uint256);
17
+ }
@@ -0,0 +1,108 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // interfaces
6
+ import "../ILSP8IdentifiableDigitalAsset.sol";
7
+
8
+ /**
9
+ * @dev LSP8 extension, for compatibility for clients / tools that expect ERC721.
10
+ */
11
+ interface ILSP8CompatibilityForERC721 is ILSP8IdentifiableDigitalAsset {
12
+ /**
13
+ * @dev To provide compatibility with indexing ERC721 events
14
+ * @param from The sending address
15
+ * @param to The receiving address
16
+ * @param tokenId The tokenId to transfer
17
+ */
18
+ event Transfer(
19
+ address indexed from,
20
+ address indexed to,
21
+ uint256 indexed tokenId
22
+ );
23
+
24
+ /**
25
+ * @dev To provide compatibility with indexing ERC721 events.
26
+ * @param owner The address of the owner of the `tokenId`
27
+ * @param approved The address set as operator
28
+ * @param tokenId The approved tokenId
29
+ */
30
+ event Approval(
31
+ address indexed owner,
32
+ address indexed approved,
33
+ uint256 indexed tokenId
34
+ );
35
+
36
+ /**
37
+ * @dev Compatible with ERC721 tranferFrom.
38
+ * @param from The sending address
39
+ * @param to The receiving address
40
+ * @param tokenId The tokenId to transfer
41
+ */
42
+ function transferFrom(
43
+ address from,
44
+ address to,
45
+ uint256 tokenId
46
+ ) external;
47
+
48
+ /**
49
+ * @dev Compatible with ERC721 tranferFrom.
50
+ * @param from The sending address
51
+ * @param to The receiving address
52
+ * @param tokenId The tokenId to transfer
53
+ */
54
+ function safeTransferFrom(
55
+ address from,
56
+ address to,
57
+ uint256 tokenId
58
+ ) external;
59
+
60
+ /**
61
+ * @dev Compatible with ERC721 safeTransferFrom.
62
+ * @param from The sending address
63
+ * @param to The receiving address
64
+ * @param tokenId The tokenId to transfer
65
+ * @param data The data to be sent with the transfer
66
+ */
67
+ function safeTransferFrom(
68
+ address from,
69
+ address to,
70
+ uint256 tokenId,
71
+ bytes memory data
72
+ ) external;
73
+
74
+ /**
75
+ * @dev Compatible with ERC721 ownerOf.
76
+ * @param tokenId The tokenId to query
77
+ * @return The owner of the tokenId
78
+ */
79
+ function ownerOf(uint256 tokenId) external returns (address);
80
+
81
+ /**
82
+ * @dev Compatible with ERC721 approve.
83
+ * @param operator The address to approve for `amount`
84
+ * @param tokenId The tokenId to approve
85
+ */
86
+ function approve(address operator, uint256 tokenId) external;
87
+
88
+ /**
89
+ * @dev Compatible with ERC721 getApproved.
90
+ * @param tokenId The tokenId to query
91
+ * @return The address of the operator for `tokenId`
92
+ */
93
+ function getApproved(uint256 tokenId) external returns (address);
94
+
95
+ /*
96
+ * @dev Compatible with ERC721 tokenURI.
97
+ * @param tokenId The tokenId to query.
98
+ * @return True if all tokenId are approved, false otherwise.
99
+ */
100
+ function isApprovedForAll(uint256 tokenId) external returns (bool);
101
+
102
+ /*
103
+ * @dev Compatible with ERC721Metadata tokenURI.
104
+ * @param tokenId The tokenId to query.
105
+ * @return The token URI
106
+ */
107
+ function tokenURI(uint256 tokenId) external returns (string memory);
108
+ }
@@ -0,0 +1,32 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // interfaces
6
+ import "../ILSP8IdentifiableDigitalAsset.sol";
7
+
8
+ /**
9
+ * @dev LSP8 extension, mintable.
10
+ */
11
+ interface ILSP8Mintable is ILSP8IdentifiableDigitalAsset {
12
+ /**
13
+ * @param to The address to mint tokens
14
+ * @param tokenId The tokenId 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
+ bytes32 tokenId,
29
+ bool force,
30
+ bytes memory data
31
+ ) external;
32
+ }