@lukso/lsp-smart-contracts 0.6.2 → 0.7.0

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 (112) hide show
  1. package/README.md +2 -10
  2. package/artifacts/Create2Factory.json +2 -2
  3. package/artifacts/LSP0ERC725Account.json +36 -3
  4. package/artifacts/LSP0ERC725AccountInit.json +36 -29
  5. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
  6. package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
  7. package/artifacts/LSP4Compatibility.json +6 -0
  8. package/artifacts/LSP4DigitalAssetMetadata.json +6 -0
  9. package/artifacts/{LSP4DigitalAssetMetadataInit.json → LSP4DigitalAssetMetadataInitAbstract.json} +8 -51
  10. package/artifacts/LSP6KeyManager.json +13 -2
  11. package/artifacts/LSP6KeyManagerInit.json +13 -2
  12. package/artifacts/LSP7CappedSupply.json +37 -26
  13. package/artifacts/{LSP7CappedSupplyInit.json → LSP7CappedSupplyInitAbstract.json} +39 -67
  14. package/artifacts/LSP7CompatibleERC20.json +39 -49
  15. package/artifacts/LSP7CompatibleERC20InitAbstract.json +717 -0
  16. package/artifacts/LSP7CompatibleERC20Mintable.json +39 -28
  17. package/artifacts/LSP7CompatibleERC20MintableInit.json +44 -54
  18. package/artifacts/LSP7DigitalAsset.json +39 -54
  19. package/artifacts/LSP7DigitalAssetInitAbstract.json +540 -0
  20. package/artifacts/LSP7Mintable.json +40 -29
  21. package/artifacts/LSP7MintableInit.json +40 -55
  22. package/artifacts/LSP8CappedSupply.json +43 -0
  23. package/artifacts/{LSP8CappedSupplyInit.json → LSP8CappedSupplyInitAbstract.json} +45 -41
  24. package/artifacts/LSP8CompatibleERC721.json +88 -23
  25. package/artifacts/LSP8CompatibleERC721InitAbstract.json +920 -0
  26. package/artifacts/LSP8CompatibleERC721Mintable.json +88 -2
  27. package/artifacts/LSP8CompatibleERC721MintableInit.json +93 -28
  28. package/artifacts/LSP8IdentifiableDigitalAsset.json +45 -23
  29. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +628 -0
  30. package/artifacts/LSP8Mintable.json +45 -2
  31. package/artifacts/LSP8MintableInit.json +45 -28
  32. package/artifacts/LSP9Vault.json +36 -3
  33. package/artifacts/LSP9VaultInit.json +36 -29
  34. package/artifacts/UniversalFactory.json +2 -2
  35. package/artifacts/UniversalProfile.json +36 -3
  36. package/artifacts/UniversalProfileInit.json +36 -29
  37. package/artifacts/UniversalReceiverAddressStore.json +2 -2
  38. package/constants.js +73 -14
  39. package/contracts/Custom/ClaimOwnership.sol +67 -5
  40. package/contracts/Custom/ERC165Checker.sol +1 -1
  41. package/contracts/Custom/IClaimOwnership.sol +3 -1
  42. package/contracts/Factories/UniversalFactory.sol +7 -12
  43. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  44. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +20 -18
  45. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +1 -1
  46. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
  47. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +1 -4
  48. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +2 -8
  49. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +1 -4
  50. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +2 -2
  51. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +1 -1
  52. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +92 -6
  53. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +15 -6
  54. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +15 -6
  55. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
  56. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +3 -3
  57. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +1 -1
  58. package/contracts/LSP6KeyManager/LSP6Constants.sol +16 -21
  59. package/contracts/LSP6KeyManager/LSP6Errors.sol +8 -0
  60. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +1 -1
  61. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +103 -84
  62. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +1 -1
  63. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +1 -1
  64. package/contracts/LSP6KeyManager/LSP6Utils.sol +2 -1
  65. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +18 -5
  66. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
  67. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +4 -4
  68. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +33 -24
  69. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +2 -2
  70. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +2 -0
  71. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +1 -1
  72. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +1 -1
  73. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +5 -6
  74. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +7 -0
  75. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +9 -7
  76. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +3 -3
  77. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +8 -7
  78. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +3 -1
  79. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +4 -4
  80. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +6 -0
  81. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +1 -1
  82. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +31 -30
  83. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +15 -1
  84. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +17 -0
  85. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +1 -1
  86. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +1 -1
  87. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +51 -27
  88. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +21 -0
  89. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +50 -0
  90. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +24 -0
  91. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +7 -0
  92. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +6 -4
  93. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +5 -4
  94. package/contracts/LSP9Vault/LSP9Constants.sol +4 -1
  95. package/contracts/LSP9Vault/LSP9VaultCore.sol +117 -46
  96. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +1 -1
  97. package/contracts/Legacy/UniversalReceiverAddressStore.sol +1 -0
  98. package/contracts/Utils/GasLib.sol +17 -0
  99. package/package.json +27 -30
  100. package/artifacts/LSP7CompatibleERC20Init.json +0 -760
  101. package/artifacts/LSP7DigitalAssetInit.json +0 -588
  102. package/artifacts/LSP8CompatibleERC721Init.json +0 -883
  103. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +0 -639
  104. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +0 -26
  105. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +0 -39
  106. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +0 -19
  107. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +0 -29
  108. package/contracts/LSP7DigitalAsset/presets/LSP7MintableCore.sol +0 -26
  109. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +0 -35
  110. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +0 -19
  111. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Init.sol +0 -25
  112. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableCore.sol +0 -26
@@ -6,12 +6,12 @@ import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalRec
6
6
  import {ILSP7DigitalAsset} from "./ILSP7DigitalAsset.sol";
7
7
 
8
8
  // libraries
9
+ import {GasLib} from "../Utils/GasLib.sol";
9
10
  import {ERC165Checker} from "../Custom/ERC165Checker.sol";
10
11
 
11
12
  // modules
12
13
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
13
- import {Address} from "@openzeppelin/contracts/utils/Address.sol";
14
- import {Context} from "@openzeppelin/contracts/utils/Context.sol";
14
+
15
15
  import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
16
16
 
17
17
  // errors
@@ -28,12 +28,10 @@ import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "./LSP7Con
28
28
  *
29
29
  * This contract implement the core logic of the functions for the {ILSP7DigitalAsset} interface.
30
30
  */
31
- abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
32
- using Address for address;
33
-
31
+ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
34
32
  // --- Storage
35
33
 
36
- bool internal _isNFT;
34
+ bool internal _isNonDivisible;
37
35
 
38
36
  uint256 internal _existingTokens;
39
37
 
@@ -48,14 +46,14 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
48
46
  /**
49
47
  * @inheritdoc ILSP7DigitalAsset
50
48
  */
51
- function decimals() public view override returns (uint256) {
52
- return _isNFT ? 0 : 18;
49
+ function decimals() public view returns (uint8) {
50
+ return _isNonDivisible ? 0 : 18;
53
51
  }
54
52
 
55
53
  /**
56
54
  * @inheritdoc ILSP7DigitalAsset
57
55
  */
58
- function totalSupply() public view override returns (uint256) {
56
+ function totalSupply() public view returns (uint256) {
59
57
  return _existingTokens;
60
58
  }
61
59
 
@@ -64,7 +62,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
64
62
  /**
65
63
  * @inheritdoc ILSP7DigitalAsset
66
64
  */
67
- function balanceOf(address tokenOwner) public view override returns (uint256) {
65
+ function balanceOf(address tokenOwner) public view returns (uint256) {
68
66
  return _tokenOwnerBalances[tokenOwner];
69
67
  }
70
68
 
@@ -72,26 +70,35 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
72
70
 
73
71
  /**
74
72
  * @inheritdoc ILSP7DigitalAsset
73
+ *
74
+ * @dev To avoid front-running and Allowance Double-Spend Exploit when
75
+ * increasing or decreasing the authorized amount of an operator,
76
+ * it is advised to:
77
+ * 1. call {revokeOperator} first, and
78
+ * 2. then re-call {authorizeOperator} with the new amount
79
+ *
80
+ * for more information, see:
81
+ * https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/
82
+ *
75
83
  */
76
- function authorizeOperator(address operator, uint256 amount) public virtual override {
77
- _updateOperator(_msgSender(), operator, amount);
84
+ function authorizeOperator(address operator, uint256 amount) public virtual {
85
+ _updateOperator(msg.sender, operator, amount);
78
86
  }
79
87
 
80
88
  /**
81
89
  * @inheritdoc ILSP7DigitalAsset
82
90
  */
83
- function revokeOperator(address operator) public virtual override {
84
- _updateOperator(_msgSender(), operator, 0);
91
+ function revokeOperator(address operator) public virtual {
92
+ _updateOperator(msg.sender, operator, 0);
85
93
  }
86
94
 
87
95
  /**
88
96
  * @inheritdoc ILSP7DigitalAsset
89
97
  */
90
- function isOperatorFor(address operator, address tokenOwner)
98
+ function authorizedAmountFor(address operator, address tokenOwner)
91
99
  public
92
100
  view
93
101
  virtual
94
- override
95
102
  returns (uint256)
96
103
  {
97
104
  if (tokenOwner == operator) {
@@ -112,8 +119,10 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
112
119
  uint256 amount,
113
120
  bool force,
114
121
  bytes memory data
115
- ) public virtual override {
116
- address operator = _msgSender();
122
+ ) public virtual {
123
+ if (from == to) revert LSP7CannotSendToSelf();
124
+
125
+ address operator = msg.sender;
117
126
  if (operator != from) {
118
127
  uint256 operatorAmount = _operatorAuthorizedAmount[from][operator];
119
128
  if (amount > operatorAmount) {
@@ -135,14 +144,14 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
135
144
  uint256[] memory amount,
136
145
  bool force,
137
146
  bytes[] memory data
138
- ) public virtual override {
147
+ ) public virtual {
139
148
  if (
140
149
  from.length != to.length || from.length != amount.length || from.length != data.length
141
150
  ) {
142
151
  revert LSP7InvalidTransferBatch();
143
152
  }
144
153
 
145
- for (uint256 i = 0; i < from.length; i++) {
154
+ for (uint256 i = 0; i < from.length; i = GasLib.uncheckedIncrement(i)) {
146
155
  // using the public transfer function to handle updates to operator authorized amounts
147
156
  transfer(from[i], to[i], amount[i], force, data[i]);
148
157
  }
@@ -153,7 +162,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
153
162
  * amount is zero then the operator is being revoked, otherwise the operator amount is being
154
163
  * modified.
155
164
  *
156
- * See {isOperatorFor}.
165
+ * See {authorizedAmountFor}.
157
166
  *
158
167
  * Emits either {AuthorizedOperator} or {RevokedOperator} event.
159
168
  *
@@ -203,7 +212,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
203
212
  revert LSP7CannotSendWithAddressZero();
204
213
  }
205
214
 
206
- address operator = _msgSender();
215
+ address operator = msg.sender;
207
216
 
208
217
  _beforeTokenTransfer(address(0), to, amount);
209
218
 
@@ -240,7 +249,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
240
249
  revert LSP7AmountExceedsBalance(balance, from, amount);
241
250
  }
242
251
 
243
- address operator = _msgSender();
252
+ address operator = msg.sender;
244
253
  if (operator != from) {
245
254
  uint256 authorizedAmount = _operatorAuthorizedAmount[from][operator];
246
255
  if (amount > authorizedAmount) {
@@ -287,7 +296,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
287
296
  revert LSP7AmountExceedsBalance(balance, from, amount);
288
297
  }
289
298
 
290
- address operator = _msgSender();
299
+ address operator = msg.sender;
291
300
 
292
301
  _beforeTokenTransfer(from, to, amount);
293
302
 
@@ -27,9 +27,9 @@ abstract contract LSP7DigitalAssetInitAbstract is
27
27
  string memory name_,
28
28
  string memory symbol_,
29
29
  address newOwner_,
30
- bool isNFT_
30
+ bool isNonDivisible_
31
31
  ) internal virtual onlyInitializing {
32
- _isNFT = isNFT_;
32
+ _isNonDivisible = isNonDivisible_;
33
33
  LSP4DigitalAssetMetadataInitAbstract._initialize(name_, symbol_, newOwner_);
34
34
  }
35
35
 
@@ -16,6 +16,8 @@ error LSP7CannotUseAddressZeroAsOperator();
16
16
 
17
17
  error LSP7CannotSendWithAddressZero();
18
18
 
19
+ error LSP7CannotSendToSelf();
20
+
19
21
  error LSP7InvalidTransferBatch();
20
22
 
21
23
  error LSP7NotifyTokenReceiverContractMissingLSP1Interface(address tokenReceiver);
@@ -26,7 +26,7 @@ abstract contract LSP7CappedSupplyCore is LSP7DigitalAssetCore, ILSP7CappedSuppl
26
26
  /**
27
27
  * @inheritdoc ILSP7CappedSupply
28
28
  */
29
- function tokenSupplyCap() public view virtual override returns (uint256) {
29
+ function tokenSupplyCap() public view virtual returns (uint256) {
30
30
  return _tokenSupplyCap;
31
31
  }
32
32
 
@@ -6,7 +6,7 @@ import {LSP7DigitalAsset, LSP4DigitalAssetMetadata, ERC725YCore} from "../LSP7Di
6
6
  import {LSP7DigitalAssetCore} from "../LSP7DigitalAssetCore.sol";
7
7
  import {LSP7CompatibleERC20Core} from "./LSP7CompatibleERC20Core.sol";
8
8
 
9
- contract LSP7CompatibleERC20 is LSP7DigitalAsset, LSP7CompatibleERC20Core {
9
+ abstract contract LSP7CompatibleERC20 is LSP7DigitalAsset, LSP7CompatibleERC20Core {
10
10
  /* solhint-disable no-empty-blocks */
11
11
  /**
12
12
  * @notice Sets the name, the symbol and the owner of the token
@@ -23,7 +23,7 @@ abstract contract LSP7CompatibleERC20Core is
23
23
  /**
24
24
  * @inheritdoc ILSP7CompatibleERC20
25
25
  */
26
- function approve(address operator, uint256 amount) public virtual override returns (bool) {
26
+ function approve(address operator, uint256 amount) public virtual returns (bool) {
27
27
  authorizeOperator(operator, amount);
28
28
  return true;
29
29
  }
@@ -35,10 +35,9 @@ abstract contract LSP7CompatibleERC20Core is
35
35
  public
36
36
  view
37
37
  virtual
38
- override
39
38
  returns (uint256)
40
39
  {
41
- return isOperatorFor(operator, tokenOwner);
40
+ return authorizedAmountFor(operator, tokenOwner);
42
41
  }
43
42
 
44
43
  /**
@@ -47,7 +46,7 @@ abstract contract LSP7CompatibleERC20Core is
47
46
  * Using force=true so that EOA and any contract may receive the tokens.
48
47
  */
49
48
  function transfer(address to, uint256 amount) public virtual override returns (bool) {
50
- transfer(_msgSender(), to, amount, true, "");
49
+ transfer(msg.sender, to, amount, true, "");
51
50
  return true;
52
51
  }
53
52
 
@@ -60,7 +59,7 @@ abstract contract LSP7CompatibleERC20Core is
60
59
  address from,
61
60
  address to,
62
61
  uint256 amount
63
- ) public virtual override returns (bool) {
62
+ ) public virtual returns (bool) {
64
63
  transfer(from, to, amount, true, "");
65
64
  return true;
66
65
  }
@@ -72,7 +71,7 @@ abstract contract LSP7CompatibleERC20Core is
72
71
  {
73
72
  super.authorizeOperator(operator, amount);
74
73
 
75
- emit Approval(_msgSender(), operator, amount);
74
+ emit Approval(msg.sender, operator, amount);
76
75
  }
77
76
 
78
77
  // --- Internals
@@ -7,6 +7,13 @@ import {
7
7
  } from "./LSP7CompatibleERC20MintableInitAbstract.sol";
8
8
 
9
9
  contract LSP7CompatibleERC20MintableInit is LSP7CompatibleERC20MintableInitAbstract {
10
+ /**
11
+ * @dev initialize (= lock) base implementation contract on deployment
12
+ */
13
+ constructor() {
14
+ _disableInitializers();
15
+ }
16
+
10
17
  /**
11
18
  * @notice Sets the name, the symbol and the owner of the token
12
19
  * @param name_ The name of the token
@@ -2,16 +2,18 @@
2
2
 
3
3
  pragma solidity ^0.8.0;
4
4
 
5
+ // interfaces
6
+ import {ILSP7Mintable} from "./ILSP7Mintable.sol";
7
+
5
8
  // modules
6
9
  import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol";
7
- import {LSP7MintableCore} from "./LSP7MintableCore.sol";
8
10
 
9
11
  /**
10
12
  * @title LSP7Mintable
11
13
  * @author Jean Cavallera, Yamen Merhi
12
14
  * @dev LSP7 extension, mintable.
13
15
  */
14
- contract LSP7Mintable is LSP7DigitalAsset, LSP7MintableCore {
16
+ contract LSP7Mintable is LSP7DigitalAsset, ILSP7Mintable {
15
17
  // solhint-disable no-empty-blocks
16
18
 
17
19
  /**
@@ -19,24 +21,24 @@ contract LSP7Mintable is LSP7DigitalAsset, LSP7MintableCore {
19
21
  * @param name_ The name of the token
20
22
  * @param symbol_ The symbol of the token
21
23
  * @param newOwner_ The owner of the the token-Metadata
22
- * @param isNFT_ Specify if the LSP7 token is a fungible or non-fungible token
24
+ * @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token
23
25
  */
24
26
  constructor(
25
27
  string memory name_,
26
28
  string memory symbol_,
27
29
  address newOwner_,
28
- bool isNFT_
29
- ) LSP7DigitalAsset(name_, symbol_, newOwner_, isNFT_) {}
30
+ bool isNonDivisible_
31
+ ) LSP7DigitalAsset(name_, symbol_, newOwner_, isNonDivisible_) {}
30
32
 
31
33
  /**
32
- * @inheritdoc LSP7MintableCore
34
+ * @inheritdoc ILSP7Mintable
33
35
  */
34
36
  function mint(
35
37
  address to,
36
38
  uint256 amount,
37
39
  bool force,
38
40
  bytes memory data
39
- ) public override onlyOwner {
41
+ ) public virtual onlyOwner {
40
42
  _mint(to, amount, force, data);
41
43
  }
42
44
  }
@@ -21,14 +21,14 @@ contract LSP7MintableInit is LSP7MintableInitAbstract {
21
21
  * @param name_ The name of the token
22
22
  * @param symbol_ The symbol of the token
23
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
24
+ * @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token
25
25
  */
26
26
  function initialize(
27
27
  string memory name_,
28
28
  string memory symbol_,
29
29
  address newOwner_,
30
- bool isNFT_
30
+ bool isNonDivisible_
31
31
  ) public virtual initializer {
32
- LSP7MintableInitAbstract._initialize(name_, symbol_, newOwner_, isNFT_);
32
+ LSP7MintableInitAbstract._initialize(name_, symbol_, newOwner_, isNonDivisible_);
33
33
  }
34
34
  }
@@ -2,33 +2,34 @@
2
2
 
3
3
  pragma solidity ^0.8.0;
4
4
 
5
+ // interfaces
6
+ import {ILSP7Mintable} from "./ILSP7Mintable.sol";
7
+
5
8
  // modules
6
- import {LSP7DigitalAssetInit} from "../LSP7DigitalAssetInit.sol";
7
9
  import {LSP7DigitalAssetInitAbstract} from "../LSP7DigitalAssetInitAbstract.sol";
8
- import {LSP7MintableCore} from "./LSP7MintableCore.sol";
9
10
 
10
11
  /**
11
12
  * @dev LSP7 extension, mintable.
12
13
  */
13
- abstract contract LSP7MintableInitAbstract is LSP7DigitalAssetInitAbstract, LSP7MintableCore {
14
+ abstract contract LSP7MintableInitAbstract is LSP7DigitalAssetInitAbstract, ILSP7Mintable {
14
15
  function _initialize(
15
16
  string memory name_,
16
17
  string memory symbol_,
17
18
  address newOwner_,
18
- bool isNFT_
19
+ bool isNonDivisible_
19
20
  ) internal virtual override onlyInitializing {
20
- LSP7DigitalAssetInitAbstract._initialize(name_, symbol_, newOwner_, isNFT_);
21
+ LSP7DigitalAssetInitAbstract._initialize(name_, symbol_, newOwner_, isNonDivisible_);
21
22
  }
22
23
 
23
24
  /**
24
- * @inheritdoc LSP7MintableCore
25
+ * @inheritdoc ILSP7Mintable
25
26
  */
26
27
  function mint(
27
28
  address to,
28
29
  uint256 amount,
29
30
  bool force,
30
31
  bytes memory data
31
- ) public override onlyOwner {
32
+ ) public virtual onlyOwner {
32
33
  _mint(to, amount, force, data);
33
34
  }
34
35
  }
@@ -7,7 +7,7 @@ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
7
7
  import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
8
8
 
9
9
  /**
10
- * @dev Required interface of a LSP8 compliant contract.
10
+ * @title interface of the LSP8 - Identifiable Digital Asset standard.
11
11
  */
12
12
  interface ILSP8IdentifiableDigitalAsset is IERC165, IERC725Y {
13
13
  // --- Events
@@ -168,6 +168,7 @@ interface ILSP8IdentifiableDigitalAsset is IERC165, IERC725Y {
168
168
  *
169
169
  * - `from` cannot be the zero address.
170
170
  * - `to` cannot be the zero address.
171
+ * - `from` and `to` cannot be the same address.
171
172
  * - `tokenId` token must be owned by `from`.
172
173
  * - If the caller is not `from`, it must be an operator of `tokenId`.
173
174
  *
@@ -197,6 +198,7 @@ interface ILSP8IdentifiableDigitalAsset is IERC165, IERC725Y {
197
198
  * - `from`, `to`, `tokenId` lists are the same length.
198
199
  * - no values in `from` can be the zero address.
199
200
  * - no values in `to` can be the zero address.
201
+ * - `from` and `to` cannot be the same address at the same index of each lists.
200
202
  * - each `tokenId` token must be owned by `from`.
201
203
  * - If the caller is not `from`, it must be an operator of each `tokenId`.
202
204
  *
@@ -6,11 +6,11 @@ bytes4 constant _INTERFACEID_LSP8 = 0x49399145;
6
6
 
7
7
  // --- ERC725Y Keys
8
8
 
9
- // bytes8('LSP8MetadataAddress') + bytes4(0)
10
- bytes12 constant _LSP8_METADATA_ADDRESS_KEY_PREFIX = 0x73dcc7c3c4096cdc00000000;
9
+ // bytes10(keccak256('LSP8MetadataAddress')) + bytes2(0)
10
+ bytes12 constant _LSP8_METADATA_ADDRESS_KEY_PREFIX = 0x73dcc7c3c4096cdc7f8a0000;
11
11
 
12
- // bytes8('LSP8MetadataJSON') + bytes4(0)
13
- bytes12 constant _LSP8_METADATA_JSON_KEY_PREFIX = 0x9a26b4060ae7f7d500000000;
12
+ // bytes10(keccak256('LSP8MetadataJSON')) + bytes2(0)
13
+ bytes12 constant _LSP8_METADATA_JSON_KEY_PREFIX = 0x9a26b4060ae7f7d5e3cd0000;
14
14
 
15
15
  // --- Token Hooks
16
16
 
@@ -9,10 +9,16 @@ error LSP8NotTokenOwner(address tokenOwner, bytes32 tokenId, address caller);
9
9
 
10
10
  error LSP8NotTokenOperator(bytes32 tokenId, address caller);
11
11
 
12
+ error LSP8OperatorAlreadyAuthorized(address operator, bytes32 tokenId);
13
+
12
14
  error LSP8CannotUseAddressZeroAsOperator();
13
15
 
14
16
  error LSP8CannotSendToAddressZero();
15
17
 
18
+ error LSP8CannotSendToSelf();
19
+
20
+ error LSP8NonExistingOperator(address _address, bytes32 tokenId);
21
+
16
22
  error LSP8TokenIdAlreadyMinted(bytes32 tokenId);
17
23
 
18
24
  error LSP8InvalidTransferBatch();
@@ -17,7 +17,7 @@ import {_INTERFACEID_LSP8} from "./LSP8Constants.sol";
17
17
  * @author Matthew Stevens
18
18
  * @dev Implementation of a LSP8 compliant contract.
19
19
  */
20
- contract LSP8IdentifiableDigitalAsset is
20
+ abstract contract LSP8IdentifiableDigitalAsset is
21
21
  LSP4DigitalAssetMetadata,
22
22
  LSP8IdentifiableDigitalAssetCore
23
23
  {
@@ -6,12 +6,12 @@ import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalRec
6
6
  import {ILSP8IdentifiableDigitalAsset} from "./ILSP8IdentifiableDigitalAsset.sol";
7
7
 
8
8
  // libraries
9
+ import {GasLib} from "../Utils/GasLib.sol";
9
10
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
10
11
  import {ERC165Checker} from "../Custom/ERC165Checker.sol";
11
12
 
12
13
  // modules
13
- import {Address} from "@openzeppelin/contracts/utils/Address.sol";
14
- import {Context} from "@openzeppelin/contracts/utils/Context.sol";
14
+
15
15
  import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
16
16
 
17
17
  // errors
@@ -19,7 +19,6 @@ import "./LSP8Errors.sol";
19
19
 
20
20
  // constants
21
21
  import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
22
- // import {} from "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
23
22
  import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "./LSP8Constants.sol";
24
23
 
25
24
  /**
@@ -27,10 +26,9 @@ import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "./LSP8Con
27
26
  * @author Matthew Stevens
28
27
  * @dev Core Implementation of a LSP8 compliant contract.
29
28
  */
30
- abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8IdentifiableDigitalAsset {
29
+ abstract contract LSP8IdentifiableDigitalAssetCore is ILSP8IdentifiableDigitalAsset {
31
30
  using EnumerableSet for EnumerableSet.AddressSet;
32
31
  using EnumerableSet for EnumerableSet.Bytes32Set;
33
- using Address for address;
34
32
 
35
33
  // --- Storage
36
34
 
@@ -45,12 +43,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
45
43
  // Mapping a `tokenId` to its authorized operator addresses.
46
44
  mapping(bytes32 => EnumerableSet.AddressSet) internal _operators;
47
45
 
46
+ mapping(address => EnumerableSet.Bytes32Set) internal _tokenIdsForOperator;
47
+
48
48
  // --- Token queries
49
49
 
50
50
  /**
51
51
  * @inheritdoc ILSP8IdentifiableDigitalAsset
52
52
  */
53
- function totalSupply() public view override returns (uint256) {
53
+ function totalSupply() public view returns (uint256) {
54
54
  return _existingTokens;
55
55
  }
56
56
 
@@ -59,14 +59,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
59
59
  /**
60
60
  * @inheritdoc ILSP8IdentifiableDigitalAsset
61
61
  */
62
- function balanceOf(address tokenOwner) public view override returns (uint256) {
62
+ function balanceOf(address tokenOwner) public view returns (uint256) {
63
63
  return _ownedTokens[tokenOwner].length();
64
64
  }
65
65
 
66
66
  /**
67
67
  * @inheritdoc ILSP8IdentifiableDigitalAsset
68
68
  */
69
- function tokenOwnerOf(bytes32 tokenId) public view override returns (address) {
69
+ function tokenOwnerOf(bytes32 tokenId) public view returns (address) {
70
70
  address tokenOwner = _tokenOwners[tokenId];
71
71
 
72
72
  if (tokenOwner == address(0)) {
@@ -79,7 +79,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
79
79
  /**
80
80
  * @inheritdoc ILSP8IdentifiableDigitalAsset
81
81
  */
82
- function tokenIdsOf(address tokenOwner) public view override returns (bytes32[] memory) {
82
+ function tokenIdsOf(address tokenOwner) public view returns (bytes32[] memory) {
83
83
  return _ownedTokens[tokenOwner].values();
84
84
  }
85
85
 
@@ -88,9 +88,9 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
88
88
  /**
89
89
  * @inheritdoc ILSP8IdentifiableDigitalAsset
90
90
  */
91
- function authorizeOperator(address operator, bytes32 tokenId) public virtual override {
91
+ function authorizeOperator(address operator, bytes32 tokenId) public virtual {
92
92
  address tokenOwner = tokenOwnerOf(tokenId);
93
- address caller = _msgSender();
93
+ address caller = msg.sender;
94
94
 
95
95
  if (tokenOwner != caller) {
96
96
  revert LSP8NotTokenOwner(tokenOwner, tokenId, caller);
@@ -105,7 +105,8 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
105
105
  return;
106
106
  }
107
107
 
108
- _operators[tokenId].add(operator);
108
+ bool isAdded = _operators[tokenId].add(operator);
109
+ if (!isAdded) revert LSP8OperatorAlreadyAuthorized(operator, tokenId);
109
110
 
110
111
  emit AuthorizedOperator(operator, tokenOwner, tokenId);
111
112
  }
@@ -113,9 +114,9 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
113
114
  /**
114
115
  * @inheritdoc ILSP8IdentifiableDigitalAsset
115
116
  */
116
- function revokeOperator(address operator, bytes32 tokenId) public virtual override {
117
+ function revokeOperator(address operator, bytes32 tokenId) public virtual {
117
118
  address tokenOwner = tokenOwnerOf(tokenId);
118
- address caller = _msgSender();
119
+ address caller = msg.sender;
119
120
 
120
121
  if (tokenOwner != caller) {
121
122
  revert LSP8NotTokenOwner(tokenOwner, tokenId, caller);
@@ -140,7 +141,6 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
140
141
  public
141
142
  view
142
143
  virtual
143
- override
144
144
  returns (bool)
145
145
  {
146
146
  _existsOrError(tokenId);
@@ -155,7 +155,6 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
155
155
  public
156
156
  view
157
157
  virtual
158
- override
159
158
  returns (address[] memory)
160
159
  {
161
160
  _existsOrError(tokenId);
@@ -185,8 +184,8 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
185
184
  bytes32 tokenId,
186
185
  bool force,
187
186
  bytes memory data
188
- ) public virtual override {
189
- address operator = _msgSender();
187
+ ) public virtual {
188
+ address operator = msg.sender;
190
189
 
191
190
  if (!_isOperatorOrOwner(operator, tokenId)) {
192
191
  revert LSP8NotTokenOperator(tokenId, operator);
@@ -204,14 +203,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
204
203
  bytes32[] memory tokenId,
205
204
  bool force,
206
205
  bytes[] memory data
207
- ) public virtual override {
206
+ ) public virtual {
208
207
  if (
209
208
  from.length != to.length || from.length != tokenId.length || from.length != data.length
210
209
  ) {
211
210
  revert LSP8InvalidTransferBatch();
212
211
  }
213
212
 
214
- for (uint256 i = 0; i < from.length; i++) {
213
+ for (uint256 i = 0; i < from.length; i = GasLib.uncheckedIncrement(i)) {
215
214
  transfer(from[i], to[i], tokenId[i], force, data[i]);
216
215
  }
217
216
  }
@@ -221,12 +220,13 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
221
220
  address tokenOwner,
222
221
  bytes32 tokenId
223
222
  ) internal virtual {
224
- _operators[tokenId].remove(operator);
223
+ bool isRemoved = _operators[tokenId].remove(operator);
224
+ if (!isRemoved) revert LSP8NonExistingOperator(operator, tokenId);
225
225
  emit RevokedOperator(operator, tokenOwner, tokenId);
226
226
  }
227
227
 
228
228
  function _clearOperators(address tokenOwner, bytes32 tokenId) internal virtual {
229
- // TODO: here is a good exmaple of why having multiple operators will be expensive.. we
229
+ // here is a good example of why having multiple operators will be expensive.. we
230
230
  // need to clear them on token transfer
231
231
  //
232
232
  // NOTE: this may cause a tx to fail if there is too many operators to clear, in which case
@@ -235,7 +235,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
235
235
  EnumerableSet.AddressSet storage operatorsForTokenId = _operators[tokenId];
236
236
 
237
237
  uint256 operatorListLength = operatorsForTokenId.length();
238
- for (uint256 i = 0; i < operatorListLength; i++) {
238
+ for (uint256 i = 0; i < operatorListLength; i = GasLib.uncheckedIncrement(i)) {
239
239
  // we are emptying the list, always remove from index 0
240
240
  address operator = operatorsForTokenId.at(0);
241
241
  _revokeOperator(operator, tokenOwner, tokenId);
@@ -285,7 +285,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
285
285
  revert LSP8TokenIdAlreadyMinted(tokenId);
286
286
  }
287
287
 
288
- address operator = _msgSender();
288
+ address operator = msg.sender;
289
289
 
290
290
  _beforeTokenTransfer(address(0), to, tokenId);
291
291
 
@@ -308,7 +308,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
308
308
  */
309
309
  function _burn(bytes32 tokenId, bytes memory data) internal virtual {
310
310
  address tokenOwner = tokenOwnerOf(tokenId);
311
- address operator = _msgSender();
311
+ address operator = msg.sender;
312
312
 
313
313
  _beforeTokenTransfer(tokenOwner, address(0), tokenId);
314
314
 
@@ -339,6 +339,10 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
339
339
  bool force,
340
340
  bytes memory data
341
341
  ) internal virtual {
342
+ if (from == to) {
343
+ revert LSP8CannotSendToSelf();
344
+ }
345
+
342
346
  address tokenOwner = tokenOwnerOf(tokenId);
343
347
  if (tokenOwner != from) {
344
348
  revert LSP8NotTokenOwner(tokenOwner, tokenId, from);
@@ -348,7 +352,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
348
352
  revert LSP8CannotSendToAddressZero();
349
353
  }
350
354
 
351
- address operator = _msgSender();
355
+ address operator = msg.sender;
352
356
 
353
357
  _beforeTokenTransfer(from, to, tokenId);
354
358
 
@@ -378,11 +382,8 @@ abstract contract LSP8IdentifiableDigitalAssetCore is Context, ILSP8Identifiable
378
382
  function _beforeTokenTransfer(
379
383
  address from,
380
384
  address to,
381
- bytes32 tokenId
385
+ bytes32 tokenId // solhint-disable no-unused-vars
382
386
  ) internal virtual {
383
- // silence compiler warning about unused variable
384
- tokenId;
385
-
386
387
  // token being minted
387
388
  if (from == address(0)) {
388
389
  _existingTokens += 1;