@lukso/lsp-smart-contracts 0.12.0-rc.0 → 0.12.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 (135) hide show
  1. package/artifacts/LSP0ERC725Account.json +18 -24
  2. package/artifacts/LSP0ERC725AccountInit.json +18 -24
  3. package/artifacts/LSP1UniversalReceiverDelegateUP.json +15 -2
  4. package/artifacts/LSP1UniversalReceiverDelegateVault.json +15 -2
  5. package/artifacts/LSP6KeyManager.json +25 -2
  6. package/artifacts/LSP6KeyManagerInit.json +25 -2
  7. package/artifacts/LSP7CappedSupply.json +35 -0
  8. package/artifacts/LSP7CappedSupplyInitAbstract.json +35 -0
  9. package/artifacts/LSP7CompatibleERC20.json +35 -0
  10. package/artifacts/LSP7CompatibleERC20InitAbstract.json +35 -0
  11. package/artifacts/LSP7CompatibleERC20Mintable.json +37 -2
  12. package/artifacts/LSP7CompatibleERC20MintableInit.json +37 -2
  13. package/artifacts/LSP7DigitalAsset.json +35 -0
  14. package/artifacts/LSP7DigitalAssetInitAbstract.json +35 -0
  15. package/artifacts/LSP7Mintable.json +37 -2
  16. package/artifacts/LSP7MintableInit.json +37 -2
  17. package/artifacts/LSP8CappedSupply.json +24 -0
  18. package/artifacts/LSP8CappedSupplyInitAbstract.json +24 -0
  19. package/artifacts/LSP8CompatibleERC721.json +24 -0
  20. package/artifacts/LSP8CompatibleERC721InitAbstract.json +24 -0
  21. package/artifacts/LSP8CompatibleERC721Mintable.json +26 -2
  22. package/artifacts/LSP8CompatibleERC721MintableInit.json +26 -2
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +24 -0
  24. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +24 -0
  25. package/artifacts/LSP8Mintable.json +26 -2
  26. package/artifacts/LSP8MintableInit.json +26 -2
  27. package/artifacts/LSP9Vault.json +15 -21
  28. package/artifacts/LSP9VaultInit.json +15 -21
  29. package/artifacts/UniversalProfile.json +18 -24
  30. package/artifacts/UniversalProfileInit.json +18 -24
  31. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +0 -8
  32. package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -0
  33. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +12 -2
  34. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +75 -30
  35. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
  36. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +11 -2
  37. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +12 -8
  38. package/contracts/LSP17ContractExtension/LSP17Extension.sol +2 -1
  39. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +30 -7
  40. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +16 -7
  41. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +3 -2
  42. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +43 -49
  43. package/contracts/LSP20CallVerification/LSP20Errors.sol +2 -2
  44. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +42 -2
  45. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +3 -3
  46. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +60 -0
  47. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
  48. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +7 -5
  49. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +122 -176
  50. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +7 -5
  51. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  52. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +8 -1
  53. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +7 -1
  54. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -0
  55. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +8 -5
  56. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +6 -5
  57. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +41 -74
  58. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +6 -5
  59. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +10 -7
  60. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +10 -7
  61. package/contracts/LSP9Vault/ILSP9Vault.sol +0 -8
  62. package/contracts/LSP9Vault/LSP9Constants.sol +5 -0
  63. package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
  64. package/contracts/LSP9Vault/LSP9VaultCore.sol +63 -27
  65. package/contracts/LSP9Vault/LSP9VaultInit.sol +1 -1
  66. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
  67. package/contracts/UniversalProfile.sol +1 -1
  68. package/contracts/UniversalProfileInit.sol +1 -1
  69. package/contracts/UniversalProfileInitAbstract.sol +1 -1
  70. package/contracts/Version.sol +16 -0
  71. package/devdocs/LSP0ERC725Account.json +14 -8
  72. package/devdocs/LSP0ERC725AccountInit.json +14 -8
  73. package/devdocs/LSP1UniversalReceiverDelegateUP.json +6 -0
  74. package/devdocs/LSP1UniversalReceiverDelegateVault.json +6 -0
  75. package/devdocs/LSP6KeyManager.json +16 -0
  76. package/devdocs/LSP6KeyManagerInit.json +16 -0
  77. package/devdocs/LSP7CappedSupply.json +16 -10
  78. package/devdocs/LSP7CappedSupplyInitAbstract.json +16 -10
  79. package/devdocs/LSP7CompatibleERC20.json +16 -10
  80. package/devdocs/LSP7CompatibleERC20InitAbstract.json +16 -10
  81. package/devdocs/LSP7CompatibleERC20Mintable.json +16 -10
  82. package/devdocs/LSP7CompatibleERC20MintableInit.json +16 -10
  83. package/devdocs/LSP7DigitalAsset.json +16 -10
  84. package/devdocs/LSP7DigitalAssetInitAbstract.json +16 -10
  85. package/devdocs/LSP7Mintable.json +16 -10
  86. package/devdocs/LSP7MintableInit.json +16 -10
  87. package/devdocs/LSP8CappedSupply.json +9 -2
  88. package/devdocs/LSP8CappedSupplyInitAbstract.json +9 -2
  89. package/devdocs/LSP8CompatibleERC721.json +9 -2
  90. package/devdocs/LSP8CompatibleERC721InitAbstract.json +9 -2
  91. package/devdocs/LSP8CompatibleERC721Mintable.json +9 -2
  92. package/devdocs/LSP8CompatibleERC721MintableInit.json +9 -2
  93. package/devdocs/LSP8IdentifiableDigitalAsset.json +9 -2
  94. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +9 -2
  95. package/devdocs/LSP8Mintable.json +9 -2
  96. package/devdocs/LSP8MintableInit.json +9 -2
  97. package/devdocs/LSP9Vault.json +12 -6
  98. package/devdocs/LSP9VaultInit.json +12 -6
  99. package/devdocs/UniversalProfile.json +14 -8
  100. package/devdocs/UniversalProfileInit.json +14 -8
  101. package/dist/constants.cjs.js +1211 -454
  102. package/dist/constants.d.ts +1277 -374
  103. package/dist/constants.es.js +1211 -454
  104. package/package.json +1 -3
  105. package/userdocs/LSP0ERC725Account.json +3 -3
  106. package/userdocs/LSP0ERC725AccountInit.json +3 -3
  107. package/userdocs/LSP1UniversalReceiverDelegateUP.json +3 -0
  108. package/userdocs/LSP1UniversalReceiverDelegateVault.json +3 -0
  109. package/userdocs/LSP6KeyManager.json +3 -0
  110. package/userdocs/LSP6KeyManagerInit.json +3 -0
  111. package/userdocs/LSP7CappedSupply.json +3 -0
  112. package/userdocs/LSP7CappedSupplyInitAbstract.json +3 -0
  113. package/userdocs/LSP7CompatibleERC20.json +3 -0
  114. package/userdocs/LSP7CompatibleERC20InitAbstract.json +3 -0
  115. package/userdocs/LSP7CompatibleERC20Mintable.json +3 -0
  116. package/userdocs/LSP7CompatibleERC20MintableInit.json +3 -0
  117. package/userdocs/LSP7DigitalAsset.json +3 -0
  118. package/userdocs/LSP7DigitalAssetInitAbstract.json +3 -0
  119. package/userdocs/LSP7Mintable.json +3 -0
  120. package/userdocs/LSP7MintableInit.json +3 -0
  121. package/userdocs/LSP8CappedSupply.json +3 -0
  122. package/userdocs/LSP8CappedSupplyInitAbstract.json +3 -0
  123. package/userdocs/LSP8CompatibleERC721.json +3 -0
  124. package/userdocs/LSP8CompatibleERC721InitAbstract.json +3 -0
  125. package/userdocs/LSP8CompatibleERC721Mintable.json +3 -0
  126. package/userdocs/LSP8CompatibleERC721MintableInit.json +3 -0
  127. package/userdocs/LSP8IdentifiableDigitalAsset.json +3 -0
  128. package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +3 -0
  129. package/userdocs/LSP8Mintable.json +3 -0
  130. package/userdocs/LSP8MintableInit.json +3 -0
  131. package/userdocs/LSP9Vault.json +3 -3
  132. package/userdocs/LSP9VaultInit.json +3 -3
  133. package/userdocs/UniversalProfile.json +3 -3
  134. package/userdocs/UniversalProfileInit.json +3 -3
  135. package/CONTRIBUTING.md +0 -188
@@ -23,6 +23,7 @@ import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
23
23
  import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
24
24
 
25
25
  // modules
26
+ import {Version} from "../Version.sol";
26
27
  import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
27
28
  import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
28
29
  import {
@@ -40,6 +41,7 @@ import {
40
41
  _INTERFACEID_ERC1271,
41
42
  _ERC1271_SUCCESSVALUE,
42
43
  _ERC1271_FAILVALUE,
44
+ _TYPEID_LSP0_VALUE_RECEIVED,
43
45
  _TYPEID_LSP0_OwnershipTransferStarted,
44
46
  _TYPEID_LSP0_OwnershipTransferred_SenderNotification,
45
47
  _TYPEID_LSP0_OwnershipTransferred_RecipientNotification
@@ -76,6 +78,7 @@ import {
76
78
  abstract contract LSP0ERC725AccountCore is
77
79
  ERC725XCore,
78
80
  ERC725YCore,
81
+ Version,
79
82
  IERC1271,
80
83
  ILSP0ERC725Account,
81
84
  ILSP1UniversalReceiver,
@@ -92,11 +95,11 @@ abstract contract LSP0ERC725AccountCore is
92
95
  * - When receiving some native tokens without any additional data.
93
96
  * - On empty calls to the contract.
94
97
  *
95
- * @custom:events {ValueReceived} event when receiving native tokens.
98
+ * @custom:events {UniversalReceiver} event when receiving native tokens.
96
99
  */
97
100
  receive() external payable virtual {
98
101
  if (msg.value != 0) {
99
- emit ValueReceived(msg.sender, msg.value);
102
+ universalReceiver(_TYPEID_LSP0_VALUE_RECEIVED, "");
100
103
  }
101
104
  }
102
105
 
@@ -119,17 +122,16 @@ abstract contract LSP0ERC725AccountCore is
119
122
  *
120
123
  * 2. If the data sent to this function is of length less than 4 bytes (not a function selector), return.
121
124
  *
122
- * @custom:events {ValueReceived} event when receiving native tokens.
125
+ * @custom:events {UniversalReceiver} event when receiving native tokens and extension function selector is not found or not payable.
123
126
  */
124
127
  // solhint-disable-next-line no-complex-fallback
125
128
  fallback(
126
129
  bytes calldata callData
127
130
  ) external payable virtual returns (bytes memory) {
128
- if (msg.value != 0) {
129
- emit ValueReceived(msg.sender, msg.value);
130
- }
131
-
132
131
  if (msg.data.length < 4) {
132
+ // if value is associated with the extension call, use the universalReceiver
133
+ if (msg.value != 0)
134
+ universalReceiver(_TYPEID_LSP0_VALUE_RECEIVED, callData);
133
135
  return "";
134
136
  }
135
137
 
@@ -185,7 +187,7 @@ abstract contract LSP0ERC725AccountCore is
185
187
  * @custom:events
186
188
  * - {Executed} event for each call that uses under `operationType`: `CALL` (0), `STATICCALL` (3) and `DELEGATECALL` (4).
187
189
  * - {ContractCreated} event, when a contract is created under `operationType`: `CREATE` (1) and `CREATE2` (2).
188
- * - {ValueReceived} event when receiving native tokens.
190
+ * - {UniversalReceiver} event when receiving native tokens.
189
191
  */
190
192
  function execute(
191
193
  uint256 operationType,
@@ -194,7 +196,13 @@ abstract contract LSP0ERC725AccountCore is
194
196
  bytes memory data
195
197
  ) public payable virtual override returns (bytes memory) {
196
198
  if (msg.value != 0) {
197
- emit ValueReceived(msg.sender, msg.value);
199
+ emit UniversalReceiver(
200
+ msg.sender,
201
+ msg.value,
202
+ _TYPEID_LSP0_VALUE_RECEIVED,
203
+ abi.encodePacked(msg.sig),
204
+ ""
205
+ );
198
206
  }
199
207
 
200
208
  address accountOwner = owner();
@@ -243,7 +251,7 @@ abstract contract LSP0ERC725AccountCore is
243
251
  * @custom:events
244
252
  * - {Executed} event for each call that uses under `operationType`: `CALL` (0), `STATICCALL` (3) and `DELEGATECALL` (4). (each iteration)
245
253
  * - {ContractCreated} event, when a contract is created under `operationType`: `CREATE` (1) and `CREATE2` (2) (each iteration)
246
- * - {ValueReceived} event when receiving native tokens.
254
+ * - {UniversalReceiver} event when receiving native tokens.
247
255
  */
248
256
  function executeBatch(
249
257
  uint256[] memory operationsType,
@@ -252,7 +260,13 @@ abstract contract LSP0ERC725AccountCore is
252
260
  bytes[] memory datas
253
261
  ) public payable virtual override returns (bytes[] memory) {
254
262
  if (msg.value != 0) {
255
- emit ValueReceived(msg.sender, msg.value);
263
+ emit UniversalReceiver(
264
+ msg.sender,
265
+ msg.value,
266
+ _TYPEID_LSP0_VALUE_RECEIVED,
267
+ abi.encodePacked(msg.sig),
268
+ ""
269
+ );
256
270
  }
257
271
 
258
272
  address accountOwner = owner();
@@ -297,7 +311,7 @@ abstract contract LSP0ERC725AccountCore is
297
311
  * @custom:requirements Can be only called by the {owner} or by an authorised address that pass the verification check performed on the owner.
298
312
  *
299
313
  * @custom:events
300
- * - {ValueReceived} event when receiving native tokens.
314
+ * - {UniversalReceiver} event when receiving native tokens.
301
315
  * - {DataChanged} event.
302
316
  */
303
317
  function setData(
@@ -305,7 +319,13 @@ abstract contract LSP0ERC725AccountCore is
305
319
  bytes memory dataValue
306
320
  ) public payable virtual override {
307
321
  if (msg.value != 0) {
308
- emit ValueReceived(msg.sender, msg.value);
322
+ emit UniversalReceiver(
323
+ msg.sender,
324
+ msg.value,
325
+ _TYPEID_LSP0_VALUE_RECEIVED,
326
+ abi.encodePacked(msg.sig),
327
+ ""
328
+ );
309
329
  }
310
330
 
311
331
  address accountOwner = owner();
@@ -334,7 +354,7 @@ abstract contract LSP0ERC725AccountCore is
334
354
  * @custom:requirements Can be only called by the {owner} or by an authorised address that pass the verification check performed on the owner.
335
355
  *
336
356
  * @custom:events
337
- * - {ValueReceived} event when receiving native tokens.
357
+ * - {UniversalReceiver} event when receiving native tokens.
338
358
  * - {DataChanged} event. (on each iteration of setting data)
339
359
  */
340
360
  function setDataBatch(
@@ -342,7 +362,13 @@ abstract contract LSP0ERC725AccountCore is
342
362
  bytes[] memory dataValues
343
363
  ) public payable virtual override {
344
364
  if (msg.value != 0) {
345
- emit ValueReceived(msg.sender, msg.value);
365
+ emit UniversalReceiver(
366
+ msg.sender,
367
+ msg.value,
368
+ _TYPEID_LSP0_VALUE_RECEIVED,
369
+ abi.encodePacked(msg.sig),
370
+ ""
371
+ );
346
372
  }
347
373
 
348
374
  if (dataKeys.length != dataValues.length) {
@@ -414,15 +440,15 @@ abstract contract LSP0ERC725AccountCore is
414
440
  * @return returnedValues The ABI encoded return value of the LSP1UniversalReceiverDelegate call and the LSP1TypeIdDelegate call.
415
441
  *
416
442
  * @custom:events
417
- * - {ValueReceived} when receiving native tokens.
443
+ * - {UniversalReceiver} when receiving native tokens.
418
444
  * - {UniversalReceiver} event with the function parameters, call options, and the response of the UniversalReceiverDelegates (URD) contract that was called.
419
445
  */
420
446
  function universalReceiver(
421
447
  bytes32 typeId,
422
- bytes calldata receivedData
448
+ bytes memory receivedData
423
449
  ) public payable virtual override returns (bytes memory returnedValues) {
424
- if (msg.value != 0) {
425
- emit ValueReceived(msg.sender, msg.value);
450
+ if (msg.value != 0 && (typeId != _TYPEID_LSP0_VALUE_RECEIVED)) {
451
+ universalReceiver(_TYPEID_LSP0_VALUE_RECEIVED, msg.data);
426
452
  }
427
453
 
428
454
  // Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY}
@@ -740,8 +766,9 @@ abstract contract LSP0ERC725AccountCore is
740
766
  /**
741
767
  * @dev Forwards the call to an extension mapped to a function selector.
742
768
  *
743
- * Calls {_getExtension} to get the address of the extension mapped to the function selector being
769
+ * Calls {_getExtensionAndForwardValue} to get the address of the extension mapped to the function selector being
744
770
  * called on the account. If there is no extension, the `address(0)` will be returned.
771
+ * Forwards the value sent with the call to the extension if the function selector is mapped to a payable extension.
745
772
  *
746
773
  * Reverts if there is no extension for the function being called, except for the `bytes4(0)` function selector, which passes even if there is no extension for it.
747
774
  *
@@ -761,7 +788,14 @@ abstract contract LSP0ERC725AccountCore is
761
788
  bytes calldata callData
762
789
  ) internal virtual override returns (bytes memory) {
763
790
  // If there is a function selector
764
- address extension = _getExtension(msg.sig);
791
+ (
792
+ address extension,
793
+ bool isForwardingValue
794
+ ) = _getExtensionAndForwardValue(msg.sig);
795
+
796
+ // if value is associated with the extension call and extension function selector is not payable, use the universalReceiver
797
+ if (msg.value != 0 && !isForwardingValue)
798
+ universalReceiver(_TYPEID_LSP0_VALUE_RECEIVED, callData);
765
799
 
766
800
  // if no extension was found for bytes4(0) return don't revert
767
801
  if (msg.sig == bytes4(0) && extension == address(0)) return "";
@@ -770,9 +804,9 @@ abstract contract LSP0ERC725AccountCore is
770
804
  if (extension == address(0))
771
805
  revert NoExtensionFoundForFunctionSelector(msg.sig);
772
806
 
773
- (bool success, bytes memory result) = extension.call(
774
- abi.encodePacked(callData, msg.sender, msg.value)
775
- );
807
+ (bool success, bytes memory result) = extension.call{
808
+ value: isForwardingValue ? msg.value : 0
809
+ }(abi.encodePacked(callData, msg.sender, msg.value));
776
810
 
777
811
  if (success) {
778
812
  return result;
@@ -791,21 +825,32 @@ abstract contract LSP0ERC725AccountCore is
791
825
  * - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
792
826
  * - If no extension is stored, returns the address(0).
793
827
  */
794
- function _getExtension(
828
+ function _getExtensionAndForwardValue(
795
829
  bytes4 functionSelector
796
- ) internal view virtual override returns (address) {
830
+ ) internal view virtual override returns (address, bool) {
797
831
  // Generate the data key relevant for the functionSelector being called
798
832
  bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
799
833
  _LSP17_EXTENSION_PREFIX,
800
834
  functionSelector
801
835
  );
802
836
 
803
- // Check if there is an extension stored under the generated data key
804
- address extension = address(
805
- bytes20(ERC725YCore._getData(mappedExtensionDataKey))
837
+ bytes memory extensionData = ERC725YCore._getData(
838
+ mappedExtensionDataKey
806
839
  );
807
840
 
808
- return extension;
841
+ // CHECK if the `extensionData` is 21 bytes long
842
+ // - 20 bytes = extension's address
843
+ // - 1 byte `0x01` as a boolean indicating if the contract should forward the value to the extension or not
844
+ if (extensionData.length == 21) {
845
+ // If the last byte is set to `0x01` (`true`)
846
+ // this indicates that the contract should forward the value to the extension
847
+ if (extensionData[20] == 0x01) {
848
+ // Return the address of the extension
849
+ return (address(bytes20(extensionData)), true);
850
+ }
851
+ }
852
+
853
+ return (address(bytes20(extensionData)), false);
809
854
  }
810
855
 
811
856
  /**
@@ -38,7 +38,7 @@ contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
38
38
  * @param initialOwner The owner of the contract.
39
39
  *
40
40
  * @custom:events
41
- * - {ValueReceived} event when funding the contract on deployment.
41
+ * - {UniversalReceiver} event when funding the contract on deployment.
42
42
  * - {OwnershipTransferred} event when `initialOwner` is set as the contract {owner}.
43
43
  */
44
44
  function initialize(
@@ -10,6 +10,9 @@ import {
10
10
  OwnableUnset
11
11
  } from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
12
12
 
13
+ // constants
14
+ import {_TYPEID_LSP0_VALUE_RECEIVED} from "./LSP0Constants.sol";
15
+
13
16
  /**
14
17
  * @title Inheritable Proxy Implementation of [LSP-0-ERC725Account] Standard.
15
18
  *
@@ -27,14 +30,20 @@ abstract contract LSP0ERC725AccountInitAbstract is
27
30
  * @custom:warning ERC725X & ERC725Y parent contracts are not initialised as they don't have non-zero initial state. If you decide to add non-zero initial state to any of those contracts, you must initialize them here.
28
31
  *
29
32
  * @custom:events
30
- * - {ValueReceived} event when funding the contract on deployment.
33
+ * - {UniversalReceiver} event when funding the contract on deployment.
31
34
  * - {OwnershipTransferred} event when `initialOwner` is set as the contract {owner}.
32
35
  */
33
36
  function _initialize(
34
37
  address initialOwner
35
38
  ) internal virtual onlyInitializing {
36
39
  if (msg.value != 0) {
37
- emit ValueReceived(msg.sender, msg.value);
40
+ emit UniversalReceiver(
41
+ msg.sender,
42
+ msg.value,
43
+ _TYPEID_LSP0_VALUE_RECEIVED,
44
+ "",
45
+ ""
46
+ );
38
47
  }
39
48
  OwnableUnset._setOwner(initialOwner);
40
49
  }
@@ -44,7 +44,7 @@ abstract contract LSP17Extendable is ERC165 {
44
44
  function _supportsInterfaceInERC165Extension(
45
45
  bytes4 interfaceId
46
46
  ) internal view virtual returns (bool) {
47
- address erc165Extension = _getExtension(
47
+ (address erc165Extension, ) = _getExtensionAndForwardValue(
48
48
  ERC165.supportsInterface.selector
49
49
  );
50
50
  if (erc165Extension == address(0)) return false;
@@ -62,15 +62,16 @@ abstract contract LSP17Extendable is ERC165 {
62
62
  * To be overrided.
63
63
  * Up to the implementor contract to return an extension based on a function selector
64
64
  */
65
- function _getExtension(
65
+ function _getExtensionAndForwardValue(
66
66
  bytes4 functionSelector
67
- ) internal view virtual returns (address);
67
+ ) internal view virtual returns (address, bool);
68
68
 
69
69
  /**
70
70
  * @dev Forwards the call to an extension mapped to a function selector.
71
71
  *
72
- * Calls {_getExtension} to get the address of the extension mapped to the function selector being
72
+ * Calls {_getExtensionAndForwardValue} to get the address of the extension mapped to the function selector being
73
73
  * called on the account. If there is no extension, the `address(0)` will be returned.
74
+ * Forwards the value if the extension is payable.
74
75
  *
75
76
  * Reverts if there is no extension for the function being called.
76
77
  *
@@ -90,15 +91,18 @@ abstract contract LSP17Extendable is ERC165 {
90
91
  bytes calldata callData
91
92
  ) internal virtual returns (bytes memory) {
92
93
  // If there is a function selector
93
- address extension = _getExtension(msg.sig);
94
+ (
95
+ address extension,
96
+ bool shouldForwardValue
97
+ ) = _getExtensionAndForwardValue(msg.sig);
94
98
 
95
99
  // if no extension was found, revert
96
100
  if (extension == address(0))
97
101
  revert NoExtensionFoundForFunctionSelector(msg.sig);
98
102
 
99
- (bool success, bytes memory result) = extension.call(
100
- abi.encodePacked(callData, msg.sender, msg.value)
101
- );
103
+ (bool success, bytes memory result) = extension.call{
104
+ value: shouldForwardValue ? msg.value : 0
105
+ }(abi.encodePacked(callData, msg.sender, msg.value));
102
106
 
103
107
  if (success) {
104
108
  return result;
@@ -2,6 +2,7 @@
2
2
  pragma solidity ^0.8.4;
3
3
 
4
4
  // modules
5
+ import {Version} from "../Version.sol";
5
6
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
6
7
 
7
8
  // constants
@@ -13,7 +14,7 @@ import {_INTERFACEID_LSP17_EXTENSION} from "./LSP17Constants.sol";
13
14
  * @dev Implementation of the extension logic according to LSP17ContractExtension.
14
15
  * This module can be inherited to provide context of the msg variable related to the extendable contract
15
16
  */
16
- abstract contract LSP17Extension is ERC165 {
17
+ abstract contract LSP17Extension is ERC165, Version {
17
18
  /**
18
19
  * @dev See {IERC165-supportsInterface}.
19
20
  */
@@ -11,6 +11,7 @@ import {
11
11
  import {ILSP7DigitalAsset} from "../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
12
12
 
13
13
  // modules
14
+ import {Version} from "../../Version.sol";
14
15
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
15
16
 
16
17
  // libraries
@@ -54,6 +55,7 @@ import {CannotRegisterEOAsAsAssets} from "../LSP1Errors.sol";
54
55
  */
55
56
  contract LSP1UniversalReceiverDelegateUP is
56
57
  ERC165,
58
+ Version,
57
59
  ILSP1UniversalReceiverDelegate
58
60
  {
59
61
  using ERC165Checker for address;
@@ -84,13 +86,6 @@ contract LSP1UniversalReceiverDelegateUP is
84
86
  bytes32 typeId,
85
87
  bytes memory /* data */
86
88
  ) public virtual override returns (bytes memory) {
87
- // The notifier is supposed to be either the LSP7 or LSP8 or LSP9 contract
88
- // If it's EOA we revert to avoid registering the EOA as asset or vault (spam protection)
89
- // solhint-disable-next-line avoid-tx-origin
90
- if (notifier == tx.origin) {
91
- revert CannotRegisterEOAsAsAssets(notifier);
92
- }
93
-
94
89
  if (typeId == _TYPEID_LSP7_TOKENSSENDER) {
95
90
  return _tokenSender(notifier);
96
91
  }
@@ -129,6 +124,13 @@ contract LSP1UniversalReceiverDelegateUP is
129
124
  * @param notifier The LSP7 or LSP8 token address.
130
125
  */
131
126
  function _tokenSender(address notifier) internal returns (bytes memory) {
127
+ // The notifier is supposed to be either the LSP7 or LSP8 or LSP9 contract
128
+ // If it's EOA we revert (spam protection)
129
+ // solhint-disable-next-line avoid-tx-origin
130
+ if (notifier == tx.origin) {
131
+ revert CannotRegisterEOAsAsAssets(notifier);
132
+ }
133
+
132
134
  // if the amount sent is not the full balance, then do not update the keys
133
135
  try ILSP7DigitalAsset(notifier).balanceOf(msg.sender) returns (
134
136
  uint256 balance
@@ -167,6 +169,13 @@ contract LSP1UniversalReceiverDelegateUP is
167
169
  address notifier,
168
170
  bytes4 interfaceId
169
171
  ) internal returns (bytes memory) {
172
+ // The notifier is supposed to be either the LSP7 or LSP8 or LSP9 contract
173
+ // If it's EOA we revert to avoid registering the EOA as asset or vault (spam protection)
174
+ // solhint-disable-next-line avoid-tx-origin
175
+ if (notifier == tx.origin) {
176
+ revert CannotRegisterEOAsAsAssets(notifier);
177
+ }
178
+
170
179
  // CHECK balance only when the Token contract is already deployed,
171
180
  // not when tokens are being transferred on deployment through the `constructor`
172
181
  if (notifier.code.length != 0) {
@@ -205,6 +214,13 @@ contract LSP1UniversalReceiverDelegateUP is
205
214
  * @param notifier The LSP9 vault address.
206
215
  */
207
216
  function _vaultSender(address notifier) internal returns (bytes memory) {
217
+ // The notifier is supposed to be either the LSP7 or LSP8 or LSP9 contract
218
+ // If it's EOA we revert (spam protection)
219
+ // solhint-disable-next-line avoid-tx-origin
220
+ if (notifier == tx.origin) {
221
+ revert CannotRegisterEOAsAsAssets(notifier);
222
+ }
223
+
208
224
  (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP10Utils
209
225
  .generateSentVaultKeys(msg.sender, notifier);
210
226
 
@@ -228,6 +244,13 @@ contract LSP1UniversalReceiverDelegateUP is
228
244
  * @param notifier The LSP9 vault address.
229
245
  */
230
246
  function _vaultRecipient(address notifier) internal returns (bytes memory) {
247
+ // The notifier is supposed to be either the LSP7 or LSP8 or LSP9 contract
248
+ // If it's EOA we revert to avoid registering the EOA as asset or vault (spam protection)
249
+ // solhint-disable-next-line avoid-tx-origin
250
+ if (notifier == tx.origin) {
251
+ revert CannotRegisterEOAsAsAssets(notifier);
252
+ }
253
+
231
254
  (bytes32[] memory dataKeys, bytes[] memory dataValues) = LSP10Utils
232
255
  .generateReceivedVaultKeys(msg.sender, notifier);
233
256
 
@@ -11,6 +11,7 @@ import {
11
11
  import {ILSP7DigitalAsset} from "../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
12
12
 
13
13
  // modules
14
+ import {Version} from "../../Version.sol";
14
15
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
15
16
 
16
17
  // libraries
@@ -44,6 +45,7 @@ import {CannotRegisterEOAsAsAssets} from "../LSP1Errors.sol";
44
45
  */
45
46
  contract LSP1UniversalReceiverDelegateVault is
46
47
  ERC165,
48
+ Version,
47
49
  ILSP1UniversalReceiverDelegate
48
50
  {
49
51
  /**
@@ -68,13 +70,6 @@ contract LSP1UniversalReceiverDelegateVault is
68
70
  bytes32 typeId,
69
71
  bytes memory /* data */
70
72
  ) public virtual override returns (bytes memory) {
71
- // The notifier is supposed to be either the LSP7 or LSP8 contract
72
- // If it's EOA we revert to avoid registering the EOA as asset (spam protection)
73
- // solhint-disable-next-line avoid-tx-origin
74
- if (notifier == tx.origin) {
75
- revert CannotRegisterEOAsAsAssets(notifier);
76
- }
77
-
78
73
  if (typeId == _TYPEID_LSP7_TOKENSSENDER) {
79
74
  return _tokenSender(notifier);
80
75
  }
@@ -105,6 +100,13 @@ contract LSP1UniversalReceiverDelegateVault is
105
100
  * @param notifier The LSP7 or LSP8 token address.
106
101
  */
107
102
  function _tokenSender(address notifier) internal returns (bytes memory) {
103
+ // The notifier is supposed to be either the LSP7 or LSP8 contract
104
+ // If it's EOA we revert to avoid registering the EOA as asset (spam protection)
105
+ // solhint-disable-next-line avoid-tx-origin
106
+ if (notifier == tx.origin) {
107
+ revert CannotRegisterEOAsAsAssets(notifier);
108
+ }
109
+
108
110
  // if the amount sent is not the full balance, then do not update the keys
109
111
  try ILSP7DigitalAsset(notifier).balanceOf(msg.sender) returns (
110
112
  uint256 balance
@@ -143,6 +145,13 @@ contract LSP1UniversalReceiverDelegateVault is
143
145
  address notifier,
144
146
  bytes4 interfaceId
145
147
  ) internal returns (bytes memory) {
148
+ // The notifier is supposed to be either the LSP7 or LSP8 contract
149
+ // If it's EOA we revert to avoid registering the EOA as asset (spam protection)
150
+ // solhint-disable-next-line avoid-tx-origin
151
+ if (notifier == tx.origin) {
152
+ revert CannotRegisterEOAsAsAssets(notifier);
153
+ }
154
+
146
155
  // CHECK balance only when the Token contract is already deployed,
147
156
  // not when tokens are being transferred on deployment through the `constructor`
148
157
  if (notifier.code.length != 0) {
@@ -25,6 +25,8 @@ import {
25
25
  * Based on LSP1 Universal Receiver standard.
26
26
  */
27
27
  library LSP1Utils {
28
+ using ERC165Checker for address;
29
+
28
30
  /**
29
31
  * @dev Notify a contract at `lsp1Implementation` address by calling its `universalReceiver` function if this contract
30
32
  * supports the LSP1 interface.
@@ -39,8 +41,7 @@ library LSP1Utils {
39
41
  bytes memory data
40
42
  ) internal {
41
43
  if (
42
- ERC165Checker.supportsERC165InterfaceUnchecked(
43
- lsp1Implementation,
44
+ lsp1Implementation.supportsERC165InterfaceUnchecked(
44
45
  _INTERFACEID_LSP1
45
46
  )
46
47
  ) {
@@ -20,48 +20,61 @@ import {
20
20
  abstract contract LSP20CallVerification {
21
21
  /**
22
22
  * @dev Calls {lsp20VerifyCall} function on the logicVerifier.
23
- * Reverts in case the value returned does not match the success value (lsp20VerifyCall selector)
24
- * Returns whether a verification after the execution should happen based on the last byte of the returnedStatus
23
+ *
24
+ * @custom:info
25
+ * - Reverts in case the value returned does not match the returned status (lsp20VerifyCall selector).
26
+ * - Returns whether a verification after the execution should happen based on the last byte of the `returnedStatus`.
27
+ * - Reverts with no reason if the data returned by `ILSP20(logicVerifier).lsp20VerifyCall(...)` cannot be decoded (_e.g:_ any other data type besides `bytes4`).
28
+ * See this link for more info: https://forum.soliditylang.org/t/call-for-feedback-the-future-of-try-catch-in-solidity/1497.
25
29
  */
26
30
  function _verifyCall(
27
31
  address logicVerifier
28
32
  ) internal virtual returns (bool verifyAfter) {
29
- if (logicVerifier.code.length == 0)
33
+ if (logicVerifier.code.length == 0) {
30
34
  revert LSP20EOACannotVerifyCall(logicVerifier);
35
+ }
31
36
 
32
- (bool success, bytes memory returnedData) = logicVerifier.call(
33
- abi.encodeWithSelector(
34
- ILSP20.lsp20VerifyCall.selector,
37
+ // Reverts with no reason if the returned data type is not a `bytes4` value
38
+ try
39
+ ILSP20(logicVerifier).lsp20VerifyCall(
35
40
  msg.sender,
36
41
  address(this),
37
42
  msg.sender,
38
43
  msg.value,
39
44
  msg.data
40
45
  )
41
- );
42
-
43
- _validateCall(false, success, returnedData);
44
-
45
- bytes4 returnedStatus = abi.decode(returnedData, (bytes4));
46
+ returns (bytes4 returnedStatus) {
47
+ if (
48
+ bytes3(returnedStatus) !=
49
+ bytes3(ILSP20.lsp20VerifyCall.selector)
50
+ ) {
51
+ revert LSP20CallVerificationFailed({
52
+ postCall: false,
53
+ returnedStatus: returnedStatus
54
+ });
55
+ }
46
56
 
47
- if (bytes3(returnedStatus) != bytes3(ILSP20.lsp20VerifyCall.selector)) {
48
- revert LSP20CallVerificationFailed(false, returnedData);
57
+ return returnedStatus[3] == 0x01;
58
+ } catch (bytes memory errorData) {
59
+ _revertWithLSP20DefaultError(false, errorData);
49
60
  }
50
-
51
- return returnedStatus[3] == 0x01;
52
61
  }
53
62
 
54
63
  /**
55
64
  * @dev Calls {lsp20VerifyCallResult} function on the logicVerifier.
56
- * Reverts in case the value returned does not match the success value (lsp20VerifyCallResult selector)
65
+ *
66
+ * @custom:info
67
+ * - Reverts in case the value returned does not match the returned status (lsp20VerifyCallResult selector).
68
+ * - Reverts with no reason if the data returned by `ILSP20(logicVerifier).lsp20VerifyCallResult(...)` cannot be decoded (_e.g:_ any other data type besides `bytes4`).
69
+ * See this link for more info: https://forum.soliditylang.org/t/call-for-feedback-the-future-of-try-catch-in-solidity/1497.
57
70
  */
58
71
  function _verifyCallResult(
59
72
  address logicVerifier,
60
73
  bytes memory callResult
61
74
  ) internal virtual {
62
- (bool success, bytes memory returnedData) = logicVerifier.call(
63
- abi.encodeWithSelector(
64
- ILSP20.lsp20VerifyCallResult.selector,
75
+ // Reverts with no reason if the returned data type is not a `bytes4` value
76
+ try
77
+ ILSP20(logicVerifier).lsp20VerifyCallResult(
65
78
  keccak256(
66
79
  abi.encodePacked(
67
80
  msg.sender,
@@ -73,37 +86,18 @@ abstract contract LSP20CallVerification {
73
86
  ),
74
87
  callResult
75
88
  )
76
- );
77
-
78
- _validateCall(true, success, returnedData);
79
-
80
- if (
81
- abi.decode(returnedData, (bytes4)) !=
82
- ILSP20.lsp20VerifyCallResult.selector
83
- )
84
- revert LSP20CallVerificationFailed({
85
- postCall: true,
86
- returnedData: returnedData
87
- });
88
- }
89
-
90
- function _validateCall(
91
- bool postCall,
92
- bool success,
93
- bytes memory returnedData
94
- ) internal pure virtual {
95
- if (!success) _revertWithLSP20DefaultError(postCall, returnedData);
89
+ returns (bytes4 returnedStatus) {
90
+ if (returnedStatus != ILSP20.lsp20VerifyCallResult.selector) {
91
+ revert LSP20CallVerificationFailed({
92
+ postCall: true,
93
+ returnedStatus: returnedStatus
94
+ });
95
+ }
96
96
 
97
- // check if the returned data contains at least 32 bytes, potentially an abi encoded bytes4 value
98
- // check if the returned data has in the first 32 bytes an abi encoded bytes4 value
99
- if (
100
- returnedData.length < 32 ||
101
- bytes28(bytes32(returnedData) << 32) != bytes28(0)
102
- )
103
- revert LSP20CallVerificationFailed({
104
- postCall: postCall,
105
- returnedData: returnedData
106
- });
97
+ return;
98
+ } catch (bytes memory errorData) {
99
+ _revertWithLSP20DefaultError(true, errorData);
100
+ }
107
101
  }
108
102
 
109
103
  function _revertWithLSP20DefaultError(
@@ -10,9 +10,9 @@ error LSP20CallingVerifierFailed(bool postCall);
10
10
  /**
11
11
  * @dev reverts when the call to the owner does not return the LSP20 success value
12
12
  * @param postCall True if the execution call was done, False otherwise
13
- * @param returnedData The data returned by the call to the logic verifier
13
+ * @param returnedStatus The bytes4 decoded data returned by the logic verifier.
14
14
  */
15
- error LSP20CallVerificationFailed(bool postCall, bytes returnedData);
15
+ error LSP20CallVerificationFailed(bool postCall, bytes4 returnedStatus);
16
16
 
17
17
  /**
18
18
  * @dev Reverts when the logic verifier is an Externally Owned Account (EOA) that cannot return the LSP20 success value.