@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
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.6;
2
+ pragma solidity ^0.8.5;
3
3
 
4
4
  // interfaces
5
5
  import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
@@ -13,6 +13,7 @@ import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
13
13
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
14
14
 
15
15
  // libraries
16
+ import {GasLib} from "../Utils/GasLib.sol";
16
17
  import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
17
18
  import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
18
19
  import {Address} from "@openzeppelin/contracts/utils/Address.sol";
@@ -26,11 +27,15 @@ import {InvalidABIEncodedArray} from "../LSP2ERC725YJSONSchema/LSP2Errors.sol";
26
27
 
27
28
  // constants
28
29
  import {
30
+ // ERC725X
29
31
  OPERATION_CALL,
30
32
  OPERATION_CREATE,
31
33
  OPERATION_CREATE2,
32
34
  OPERATION_STATICCALL,
33
- OPERATION_DELEGATECALL
35
+ OPERATION_DELEGATECALL,
36
+ // ERC725Y
37
+ SETDATA_SELECTOR,
38
+ SETDATA_ARRAY_SELECTOR
34
39
  } from "@erc725/smart-contracts/contracts/constants.sol";
35
40
  import {
36
41
  _INTERFACEID_ERC1271,
@@ -51,7 +56,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
51
56
  using ECDSA for bytes32;
52
57
  using ERC165Checker for address;
53
58
 
54
- address public override target;
59
+ address public target;
55
60
  mapping(address => mapping(uint256 => uint256)) internal _nonceStore;
56
61
 
57
62
  /**
@@ -67,7 +72,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
67
72
  /**
68
73
  * @inheritdoc ILSP6KeyManager
69
74
  */
70
- function getNonce(address from, uint256 channelId) public view override returns (uint256) {
75
+ function getNonce(address from, uint256 channelId) public view returns (uint256) {
71
76
  uint128 nonceId = uint128(_nonceStore[from][channelId]);
72
77
  return (uint256(channelId) << 128) | nonceId;
73
78
  }
@@ -78,7 +83,6 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
78
83
  function isValidSignature(bytes32 dataHash, bytes memory signature)
79
84
  public
80
85
  view
81
- override
82
86
  returns (bytes4 magicValue)
83
87
  {
84
88
  address recoveredAddress = dataHash.recover(signature);
@@ -93,22 +97,10 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
93
97
  /**
94
98
  * @inheritdoc ILSP6KeyManager
95
99
  */
96
- function execute(bytes calldata payload) public payable override returns (bytes memory) {
100
+ function execute(bytes calldata payload) public payable returns (bytes memory) {
97
101
  _verifyPermissions(msg.sender, payload);
98
102
 
99
- // solhint-disable avoid-low-level-calls
100
- (bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
101
- payload
102
- );
103
-
104
- bytes memory result = Address.verifyCallResult(
105
- success,
106
- returnData,
107
- "LSP6: Unknow Error occured when calling the linked target contract"
108
- );
109
-
110
- emit Executed(msg.value, bytes4(payload));
111
- return result.length != 0 ? abi.decode(result, (bytes)) : result;
103
+ return _executePayload(payload);
112
104
  }
113
105
 
114
106
  /**
@@ -118,7 +110,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
118
110
  bytes memory signature,
119
111
  uint256 nonce,
120
112
  bytes calldata payload
121
- ) public payable override returns (bytes memory) {
113
+ ) public payable returns (bytes memory) {
122
114
  bytes memory blob = abi.encodePacked(
123
115
  block.chainid,
124
116
  address(this), // needs to be signed for this keyManager
@@ -137,20 +129,31 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
137
129
 
138
130
  _verifyPermissions(signer, payload);
139
131
 
140
- // solhint-disable avoid-low-level-calls
141
- (bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
142
- payload
143
- );
132
+ return _executePayload(payload);
133
+ }
144
134
 
135
+ /**
136
+ * @notice execute the received payload (obtained via `execute(...)` and `executeRelayCall(...)`)
137
+ *
138
+ * @param payload the payload to execute
139
+ * @return bytes the result from calling the target with `_payload`
140
+ */
141
+ function _executePayload(bytes calldata payload) internal returns (bytes memory) {
142
+
143
+ // solhint-disable avoid-low-level-calls
144
+ (bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
145
+ payload
146
+ );
145
147
  bytes memory result = Address.verifyCallResult(
146
148
  success,
147
149
  returnData,
148
- "LSP6: Unknow Error occured when calling the linked target contract"
150
+ "LSP6: Unknown Error occured when calling the linked target contract"
149
151
  );
150
152
 
151
- emit Executed(msg.value, bytes4(payload));
152
- return result.length != 0 ? abi.decode(result, (bytes)) : result;
153
- }
153
+ emit Executed(msg.value, bytes4(payload));
154
+ return result.length != 0 ? abi.decode(result, (bytes)) : result;
155
+
156
+ }
154
157
 
155
158
  /**
156
159
  * @notice verify the nonce `_idx` for `_from` (obtained via `getNonce(...)`)
@@ -180,22 +183,24 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
180
183
 
181
184
  if (permissions == bytes32(0)) revert NoPermissionsSet(from);
182
185
 
183
- if (erc725Function == setDataSingleSelector) {
186
+ if (erc725Function == SETDATA_SELECTOR) {
184
187
  (bytes32 inputKey, bytes memory inputValue) = abi.decode(payload[4:], (bytes32, bytes));
185
188
 
186
- if (
189
+ if (bytes16(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
190
+ // CHECK if key = AddressPermissions[] or AddressPermissions[index]
191
+ _verifyCanSetPermissionsArray(inputKey, inputValue, from, permissions);
192
+
193
+ } else if (bytes6(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX) {
187
194
  // CHECK for permission keys
188
- bytes6(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX ||
189
- bytes16(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX
190
- ) {
191
195
  _verifyCanSetPermissions(inputKey, inputValue, from, permissions);
196
+
192
197
  } else {
193
198
  bytes32[] memory wrappedInputKey = new bytes32[](1);
194
199
  wrappedInputKey[0] = inputKey;
195
200
 
196
201
  _verifyCanSetData(from, permissions, wrappedInputKey);
197
202
  }
198
- } else if (erc725Function == setDataMultipleSelector) {
203
+ } else if (erc725Function == SETDATA_ARRAY_SELECTOR) {
199
204
  (bytes32[] memory inputKeys, bytes[] memory inputValues) = abi.decode(
200
205
  payload[4:],
201
206
  (bytes32[], bytes[])
@@ -204,19 +209,22 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
204
209
  bool isSettingERC725YKeys = false;
205
210
 
206
211
  // loop through each ERC725Y data keys
207
- for (uint256 ii = 0; ii < inputKeys.length; ii++) {
212
+ for (uint256 ii = 0; ii < inputKeys.length; ii = GasLib.uncheckedIncrement(ii)) {
208
213
  bytes32 key = inputKeys[ii];
209
214
  bytes memory value = inputValues[ii];
210
215
 
211
- if (
212
- // CHECK for permission keys
213
- bytes6(key) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX ||
214
- bytes16(key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX
215
- ) {
216
+ if (bytes16(key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
217
+ // CHECK if key = AddressPermissions[] or AddressPermissions[index]
218
+ _verifyCanSetPermissionsArray(key, value, from, permissions);
219
+
220
+ // "nullify" permission keys to not check them against allowed ERC725Y keys
221
+ inputKeys[ii] = bytes32(0);
222
+
223
+ } else if (bytes6(key) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX) {
224
+ // CHECK for permissions keys
216
225
  _verifyCanSetPermissions(key, value, from, permissions);
217
226
 
218
- // "nullify" permission keys
219
- // to not check them against allowed ERC725Y keys
227
+ // "nullify" permission keys to not check them against allowed ERC725Y keys
220
228
  inputKeys[ii] = bytes32(0);
221
229
  } else {
222
230
  // if the key is any other bytes32 key
@@ -265,22 +273,12 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
265
273
  bytes memory value,
266
274
  address from,
267
275
  bytes32 permissions
268
- ) internal view {
276
+ ) internal view virtual {
269
277
  // prettier-ignore
270
278
  if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX) {
271
-
279
+
272
280
  // key = AddressPermissions:Permissions:<address>
273
281
  _verifyCanSetBytes32Permissions(key, from, permissions);
274
-
275
- } else if (key == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
276
-
277
- // key = AddressPermissions[]
278
- _verifyCanSetPermissionsArray(key, value, from, permissions);
279
-
280
- } else if (bytes16(key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
281
-
282
- // key = AddressPermissions[index]
283
- _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
284
282
 
285
283
  } else if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX) {
286
284
 
@@ -347,7 +345,24 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
347
345
  _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
348
346
 
349
347
  }
350
-
348
+ } else {
349
+ /**
350
+ * if bytes6(key) != bytes6(keccak256("AddressPermissions"))
351
+ * this is not a standard permission key according to LSP6
352
+ * so we revert execution
353
+ *
354
+ * @dev to implement custom permissions keys, consider overriding
355
+ * this function and implement specific checks
356
+ *
357
+ * // AddressPermissions:MyCustomPermissions:<address>
358
+ * bytes12 CUSTOM_PERMISSION_PREFIX = 0x4b80742de2bf9e659ba40000
359
+ *
360
+ * if (bytes12(key) == CUSTOM_PERMISSION_PREFIX) {
361
+ * // custom logic
362
+ * }
363
+ * super._verifyCanSetPermissions(...)
364
+ */
365
+ revert NotRecognisedPermissionKey(key);
351
366
  }
352
367
  }
353
368
 
@@ -374,14 +389,22 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
374
389
  address from,
375
390
  bytes32 permissions
376
391
  ) internal view {
377
- uint256 arrayLength = uint256(bytes32(ERC725Y(target).getData(key)));
378
- uint256 newLength = uint256(bytes32(value));
392
+ // key = AddressPermissions[] -> array length
393
+ if (key == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
394
+ uint256 arrayLength = uint256(bytes32(ERC725Y(target).getData(key)));
395
+ uint256 newLength = uint256(bytes32(value));
379
396
 
380
- if (newLength > arrayLength) {
381
- _requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
382
- } else {
383
- _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
397
+ if (newLength > arrayLength) {
398
+ _requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
399
+ } else {
400
+ _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
401
+ }
402
+
403
+ return;
384
404
  }
405
+
406
+ // key = AddressPermissions[index] -> array index
407
+ _requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
385
408
  }
386
409
 
387
410
  function _verifyAllowedERC725YKeys(address from, bytes32[] memory inputKeys) internal view {
@@ -401,12 +424,12 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
401
424
  bytes32 mask;
402
425
 
403
426
  // loop through each allowed ERC725Y key retrieved from storage
404
- for (uint256 ii = 0; ii < allowedERC725YKeys.length; ii++) {
427
+ for (uint256 ii = 0; ii < allowedERC725YKeys.length; ii = GasLib.uncheckedIncrement(ii)) {
405
428
  // required to know which part of the input key to compare against the allowed key
406
429
  zeroBytesCount = _countTrailingZeroBytes(allowedERC725YKeys[ii]);
407
430
 
408
431
  // loop through each keys given as input
409
- for (uint256 jj = 0; jj < inputKeys.length; jj++) {
432
+ for (uint256 jj = 0; jj < inputKeys.length; jj = GasLib.uncheckedIncrement(jj)) {
410
433
  // skip permissions keys that have been previously checked and "nulled"
411
434
  if (inputKeys[jj] == bytes32(0)) continue;
412
435
 
@@ -430,7 +453,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
430
453
  }
431
454
  }
432
455
 
433
- for (uint256 ii = 0; ii < inputKeys.length; ii++) {
456
+ for (uint256 ii = 0; ii < inputKeys.length; ii = GasLib.uncheckedIncrement(ii)) {
434
457
  if (inputKeys[ii] != bytes32(0)) revert NotAllowedERC725YKey(from, inputKeys[ii]);
435
458
  }
436
459
  }
@@ -450,7 +473,6 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
450
473
  uint256 operationType = uint256(bytes32(payload[4:36]));
451
474
  require(operationType < 5, "LSP6KeyManager: invalid operation type");
452
475
 
453
- // TODO: if re-enable delegatecall, add check to ensure owner() + initialized() are not overriden after delegatecall
454
476
  require(
455
477
  operationType != OPERATION_DELEGATECALL,
456
478
  "LSP6KeyManager: operation DELEGATECALL is currently disallowed"
@@ -467,16 +489,14 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
467
489
  ? false
468
490
  : permissions.hasPermission(_extractSuperPermissionFromOperation(operationType));
469
491
 
470
- if (isCallDataPresent) {
471
- // prettier-ignore
472
- hasSuperOperation || _requirePermissions(from, permissions, _extractPermissionFromOperation(operationType));
492
+ if (isCallDataPresent && !hasSuperOperation) {
493
+ _requirePermissions(from, permissions, _extractPermissionFromOperation(operationType));
473
494
  }
474
495
 
475
496
  bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
476
497
 
477
- if (value > 0) {
478
- // prettier-ignore
479
- hasSuperTransferValue || _requirePermissions(from, permissions, _PERMISSION_TRANSFERVALUE);
498
+ if (value != 0 && !hasSuperTransferValue) {
499
+ _requirePermissions(from, permissions, _PERMISSION_TRANSFERVALUE);
480
500
  }
481
501
 
482
502
  // Skip on contract creation (CREATE or CREATE2)
@@ -486,7 +506,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
486
506
  if (hasSuperOperation && isCallDataPresent && value == 0) return;
487
507
 
488
508
  // Skip if caller has SUPER permission for value transfers
489
- if (hasSuperTransferValue && !isCallDataPresent && value > 0) return;
509
+ if (hasSuperTransferValue && !isCallDataPresent && value != 0) return;
490
510
 
491
511
  // Skip if both SUPER permissions are present
492
512
  if (hasSuperOperation && hasSuperTransferValue) return;
@@ -495,7 +515,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
495
515
  address to = address(bytes20(payload[48:68]));
496
516
  _verifyAllowedAddress(from, to);
497
517
 
498
- if (to.code.length > 0) {
518
+ if (to.code.length != 0) {
499
519
  // CHECK for ALLOWED STANDARDS
500
520
  _verifyAllowedStandard(from, to);
501
521
 
@@ -551,7 +571,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
551
571
 
552
572
  address[] memory allowedAddressesList = abi.decode(allowedAddresses, (address[]));
553
573
 
554
- for (uint256 ii = 0; ii < allowedAddressesList.length; ii++) {
574
+ for (uint256 ii = 0; ii < allowedAddressesList.length; ii = GasLib.uncheckedIncrement(ii)) {
555
575
  if (to == allowedAddressesList[ii]) return;
556
576
  }
557
577
  revert NotAllowedAddress(from, to);
@@ -576,7 +596,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
576
596
 
577
597
  bytes4[] memory allowedStandardsList = abi.decode(allowedStandards, (bytes4[]));
578
598
 
579
- for (uint256 ii = 0; ii < allowedStandardsList.length; ii++) {
599
+ for (uint256 ii = 0; ii < allowedStandardsList.length; ii = GasLib.uncheckedIncrement(ii)) {
580
600
  if (to.supportsERC165Interface(allowedStandardsList[ii])) return;
581
601
  }
582
602
  revert NotAllowedStandard(from, to);
@@ -602,27 +622,27 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
602
622
 
603
623
  bytes4[] memory allowedFunctionsList = abi.decode(allowedFunctions, (bytes4[]));
604
624
 
605
- for (uint256 ii = 0; ii < allowedFunctionsList.length; ii++) {
625
+ for (uint256 ii = 0; ii < allowedFunctionsList.length; ii = GasLib.uncheckedIncrement(ii)) {
606
626
  if (functionSelector == allowedFunctionsList[ii]) return;
607
627
  }
608
628
  revert NotAllowedFunction(from, functionSelector);
609
629
  }
610
630
 
611
- function _countTrailingZeroBytes(bytes32 key) internal pure returns (uint256) {
612
- uint256 index = 31;
631
+ function _countTrailingZeroBytes(bytes32 dataKey) internal pure returns (uint256) {
632
+ uint256 nByte = 32;
613
633
 
614
- // CHECK each bytes of the key, starting from the end (right to left)
615
- // skip each empty bytes `0x00` to find the first non-empty byte
616
- while (key[index] == 0x00 && index != 0) index--;
634
+ // CHECK each bytes of the data key, starting from the end (right to left)
635
+ // skip each empty bytes `0x00` until we find the first non-empty byte
636
+ while (nByte > 0 && dataKey[nByte - 1] == 0x00) nByte--;
617
637
 
618
- return 32 - (index + 1);
638
+ return 32 - nByte;
619
639
  }
620
640
 
621
641
  function _requirePermissions(
622
642
  address from,
623
643
  bytes32 addressPermissions,
624
644
  bytes32 permissionRequired
625
- ) internal pure returns (bool) {
645
+ ) internal pure {
626
646
  if (!addressPermissions.hasPermission(permissionRequired)) {
627
647
  string memory permissionErrorString = _getPermissionErrorString(permissionRequired);
628
648
  revert NotAuthorised(from, permissionErrorString);
@@ -641,7 +661,6 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
641
661
  if (permission == _PERMISSION_CALL) return "CALL";
642
662
  if (permission == _PERMISSION_STATICCALL) return "STATICCALL";
643
663
  if (permission == _PERMISSION_DELEGATECALL) return "DELEGATECALL";
644
- // TODO: add support to display CREATE or CREATE2 in the revert error
645
664
  if (permission == _PERMISSION_DEPLOY) return "DEPLOY";
646
665
  if (permission == _PERMISSION_TRANSFERVALUE) return "TRANSFERVALUE";
647
666
  if (permission == _PERMISSION_SIGN) return "SIGN";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.6;
2
+ pragma solidity ^0.8.5;
3
3
 
4
4
  // modules
5
5
  import {LSP6KeyManagerInitAbstract} from "./LSP6KeyManagerInitAbstract.sol";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.6;
2
+ pragma solidity ^0.8.5;
3
3
 
4
4
  // modules
5
5
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
@@ -9,6 +9,7 @@ import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
9
9
  import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
10
10
 
11
11
  // constants
12
+ import {SETDATA_ARRAY_SELECTOR} from "@erc725/smart-contracts/contracts/constants.sol";
12
13
  import "../LSP6KeyManager/LSP6Constants.sol";
13
14
 
14
15
  library LSP6Utils {
@@ -101,7 +102,7 @@ library LSP6Utils {
101
102
  bytes32[] memory keys,
102
103
  bytes[] memory values
103
104
  ) internal returns (bytes memory result) {
104
- bytes memory payload = abi.encodeWithSelector(hex"14a6e293", keys, values);
105
+ bytes memory payload = abi.encodeWithSelector(SETDATA_ARRAY_SELECTOR, keys, values);
105
106
  result = ILSP6KeyManager(keyManagerAddress).execute(payload);
106
107
  }
107
108
  }
@@ -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 LSP7 - Digital Asset standard.
11
11
  */
12
12
  interface ILSP7DigitalAsset is IERC165, IERC725Y {
13
13
  // --- Events
@@ -60,7 +60,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
60
60
  * no way affects any of the arithmetic of the contract, including
61
61
  * {balanceOf} and {transfer}.
62
62
  */
63
- function decimals() external view returns (uint256);
63
+ function decimals() external view returns (uint8);
64
64
 
65
65
  /**
66
66
  * @dev Returns the number of existing tokens.
@@ -84,7 +84,17 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
84
84
  * @param amount The amount of tokens operator has access to.
85
85
  * @dev Sets `amount` as the amount of tokens `operator` address has access to from callers tokens.
86
86
  *
87
- * See {isOperatorFor}.
87
+ * To avoid front-running and Allowance Double-Spend Exploit when
88
+ * increasing or decreasing the authorized amount of an operator,
89
+ * it is advised to:
90
+ * 1. call {revokeOperator} first, and
91
+ * 2. then re-call {authorizeOperator} with the new amount
92
+ *
93
+ * for more information, see:
94
+ * https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/
95
+ *
96
+ *
97
+ * See {authorizedAmountFor}.
88
98
  *
89
99
  * Requirements
90
100
  *
@@ -98,7 +108,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
98
108
  * @param operator The address to revoke as an operator.
99
109
  * @dev Removes `operator` address as an operator of callers tokens.
100
110
  *
101
- * See {isOperatorFor}.
111
+ * See {authorizedAmountFor}.
102
112
  *
103
113
  * Requirements
104
114
  *
@@ -116,7 +126,10 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
116
126
  * Operators can send and burn tokens on behalf of their owners. The tokenOwner is their own
117
127
  * operator.
118
128
  */
119
- function isOperatorFor(address operator, address tokenOwner) external view returns (uint256);
129
+ function authorizedAmountFor(address operator, address tokenOwner)
130
+ external
131
+ view
132
+ returns (uint256);
120
133
 
121
134
  // --- Transfer functionality
122
135
 
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // --- ERC165 interface ids
5
- bytes4 constant _INTERFACEID_LSP7 = 0xe33f65c3;
5
+ bytes4 constant _INTERFACEID_LSP7 = 0x5fcaac27;
6
6
 
7
7
  // --- Token Hooks
8
8
 
@@ -21,21 +21,21 @@ import {_INTERFACEID_LSP7} from "./LSP7Constants.sol";
21
21
  * A supply mechanism has to be added in a derived contract using {_mint}
22
22
  * For a generic mechanism, see {LSP7Mintable}.
23
23
  */
24
- contract LSP7DigitalAsset is LSP4DigitalAssetMetadata, LSP7DigitalAssetCore {
24
+ abstract contract LSP7DigitalAsset is LSP4DigitalAssetMetadata, LSP7DigitalAssetCore {
25
25
  /**
26
26
  * @notice Sets the token-Metadata
27
27
  * @param name_ The name of the token
28
28
  * @param symbol_ The symbol of the token
29
29
  * @param newOwner_ The owner of the the token-Metadata
30
- * @param isNFT_ Specify if the LSP7 token is a fungible or non-fungible token
30
+ * @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token
31
31
  */
32
32
  constructor(
33
33
  string memory name_,
34
34
  string memory symbol_,
35
35
  address newOwner_,
36
- bool isNFT_
36
+ bool isNonDivisible_
37
37
  ) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {
38
- _isNFT = isNFT_;
38
+ _isNonDivisible = isNonDivisible_;
39
39
  }
40
40
 
41
41
  /**