@lukso/lsp-smart-contracts 0.7.0 → 0.8.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 (164) hide show
  1. package/CONTRIBUTING.md +31 -0
  2. package/README.md +73 -20
  3. package/artifacts/Create2Factory.json +2 -2
  4. package/artifacts/LSP0ERC725Account.json +194 -15
  5. package/artifacts/LSP0ERC725AccountInit.json +194 -15
  6. package/artifacts/LSP11BasicSocialRecovery.json +493 -0
  7. package/artifacts/LSP11BasicSocialRecoveryInit.json +513 -0
  8. package/artifacts/LSP16UniversalFactory.json +236 -0
  9. package/artifacts/LSP1UniversalReceiverDelegateUP.json +134 -15
  10. package/artifacts/LSP1UniversalReceiverDelegateVault.json +80 -15
  11. package/artifacts/LSP4Compatibility.json +16 -0
  12. package/artifacts/LSP4DigitalAssetMetadata.json +16 -0
  13. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +16 -0
  14. package/artifacts/LSP6KeyManager.json +177 -33
  15. package/artifacts/LSP6KeyManagerInit.json +177 -33
  16. package/artifacts/LSP7CappedSupply.json +21 -5
  17. package/artifacts/LSP7CappedSupplyInitAbstract.json +21 -5
  18. package/artifacts/LSP7CompatibleERC20.json +21 -5
  19. package/artifacts/LSP7CompatibleERC20InitAbstract.json +23 -7
  20. package/artifacts/LSP7CompatibleERC20Mintable.json +24 -8
  21. package/artifacts/LSP7CompatibleERC20MintableInit.json +24 -8
  22. package/artifacts/LSP7DigitalAsset.json +21 -5
  23. package/artifacts/LSP7DigitalAssetInitAbstract.json +21 -5
  24. package/artifacts/LSP7Mintable.json +24 -8
  25. package/artifacts/LSP7MintableInit.json +24 -8
  26. package/artifacts/LSP8CappedSupply.json +22 -6
  27. package/artifacts/LSP8CappedSupplyInitAbstract.json +22 -6
  28. package/artifacts/LSP8CompatibleERC721.json +23 -7
  29. package/artifacts/LSP8CompatibleERC721InitAbstract.json +25 -9
  30. package/artifacts/LSP8CompatibleERC721Mintable.json +26 -10
  31. package/artifacts/LSP8CompatibleERC721MintableInit.json +26 -10
  32. package/artifacts/LSP8IdentifiableDigitalAsset.json +22 -6
  33. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +22 -6
  34. package/artifacts/LSP8Mintable.json +25 -9
  35. package/artifacts/LSP8MintableInit.json +25 -9
  36. package/artifacts/LSP9Vault.json +202 -17
  37. package/artifacts/LSP9VaultInit.json +202 -17
  38. package/artifacts/UniversalProfile.json +194 -15
  39. package/artifacts/UniversalProfileInit.json +194 -15
  40. package/artifacts/UniversalReceiverAddressStore.json +3 -3
  41. package/constants.js +377 -115
  42. package/contracts/Custom/EIP191Signer.sol +12 -0
  43. package/contracts/Factories/Create2Factory.sol +1 -3
  44. package/contracts/LSP0ERC725Account/LSP0Constants.sol +13 -2
  45. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +2 -1
  46. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +261 -63
  47. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +2 -2
  48. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +2 -1
  49. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
  50. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +214 -0
  51. package/contracts/LSP11BasicSocialRecovery/ILSP11BasicSocialRecovery.sol +177 -0
  52. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol +23 -0
  53. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +258 -0
  54. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +26 -0
  55. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInitAbstract.sol +19 -0
  56. package/contracts/LSP11BasicSocialRecovery/LSP11Constants.sol +6 -0
  57. package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +60 -0
  58. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +53 -0
  59. package/contracts/LSP14Ownable2Step/LSP14Constants.sol +15 -0
  60. package/contracts/LSP14Ownable2Step/LSP14Errors.sol +12 -0
  61. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +212 -0
  62. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +246 -0
  63. package/contracts/LSP17ContractExtension/LSP17Constants.sol +17 -0
  64. package/contracts/LSP17ContractExtension/LSP17Errors.sol +7 -0
  65. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +104 -0
  66. package/contracts/LSP17ContractExtension/LSP17Extension.sol +45 -0
  67. package/contracts/LSP17ContractExtension/LSP17Utils.sol +20 -0
  68. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +5 -5
  69. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +5 -3
  70. package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +21 -0
  71. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +157 -37
  72. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +64 -31
  73. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +53 -40
  74. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +45 -23
  75. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
  76. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  77. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +1 -1
  78. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
  79. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +2 -2
  80. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +2 -2
  81. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +3 -3
  82. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
  83. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +102 -114
  84. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +25 -7
  85. package/contracts/LSP6KeyManager/LSP6Constants.sol +43 -38
  86. package/contracts/LSP6KeyManager/LSP6Errors.sol +90 -21
  87. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +2 -1
  88. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +772 -364
  89. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +1 -1
  90. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +3 -2
  91. package/contracts/LSP6KeyManager/LSP6Utils.sol +125 -34
  92. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +8 -8
  93. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +6 -6
  94. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +1 -1
  95. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +38 -34
  96. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +1 -1
  97. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +28 -1
  98. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +1 -1
  99. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +24 -0
  100. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +28 -8
  101. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +28 -11
  102. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +87 -20
  103. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +97 -19
  104. package/contracts/LSP7DigitalAsset/presets/ILSP7Mintable.sol +3 -3
  105. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +3 -4
  106. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +2 -2
  107. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +3 -3
  108. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +3 -5
  109. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +2 -2
  110. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +3 -3
  111. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +7 -7
  112. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +7 -7
  113. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +40 -2
  114. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +2 -2
  115. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +53 -50
  116. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +1 -1
  117. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +5 -2
  118. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +20 -0
  119. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +27 -7
  120. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +27 -10
  121. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +236 -30
  122. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +240 -30
  123. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +32 -4
  124. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +35 -8
  125. package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -3
  126. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +3 -4
  127. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +3 -3
  128. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +3 -3
  129. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +3 -4
  130. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +2 -2
  131. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +3 -3
  132. package/contracts/LSP9Vault/LSP9Constants.sol +10 -10
  133. package/contracts/LSP9Vault/LSP9Errors.sol +8 -0
  134. package/contracts/LSP9Vault/LSP9Vault.sol +6 -4
  135. package/contracts/LSP9Vault/LSP9VaultCore.sol +289 -126
  136. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -2
  137. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +4 -3
  138. package/contracts/Legacy/Registries/AddressRegistry.sol +1 -1
  139. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +1 -1
  140. package/contracts/Legacy/UniversalReceiverAddressStore.sol +4 -14
  141. package/contracts/UniversalProfile.sol +2 -2
  142. package/contracts/UniversalProfileInit.sol +2 -2
  143. package/contracts/UniversalProfileInitAbstract.sol +1 -1
  144. package/contracts/Utils/GasLib.sol +1 -1
  145. package/package.json +17 -9
  146. package/artifacts/UniversalFactory.json +0 -127
  147. package/contracts/Custom/ClaimOwnership.sol +0 -96
  148. package/contracts/Custom/ERC165Checker.sol +0 -130
  149. package/contracts/Custom/IClaimOwnership.sol +0 -12
  150. package/contracts/Factories/UniversalFactory.sol +0 -159
  151. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +0 -24
  152. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +0 -82
  153. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +0 -73
  154. package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +0 -9
  155. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +0 -17
  156. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +0 -57
  157. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +0 -111
  158. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +0 -17
  159. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +0 -17
  160. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +0 -58
  161. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleConstants.sol +0 -6
  162. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +0 -211
  163. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +0 -50
  164. package/contracts/Utils/UtilsLib.sol +0 -31
@@ -1,117 +1,189 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
6
- import {
7
- ILSP1UniversalReceiverDelegate
8
- } from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
9
6
 
10
7
  // libraries
11
8
  import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
12
9
  import {GasLib} from "../Utils/GasLib.sol";
13
- import {ERC165Checker} from "../Custom/ERC165Checker.sol";
10
+
11
+ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
12
+ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
13
+ import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
14
+ import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
14
15
 
15
16
  // modules
16
17
  import {ERC725XCore, IERC725X} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
17
18
  import {ERC725YCore, IERC725Y} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
18
19
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
19
- import {ClaimOwnership} from "../Custom/ClaimOwnership.sol";
20
+ import {LSP14Ownable2Step} from "../LSP14Ownable2Step/LSP14Ownable2Step.sol";
21
+ import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol";
20
22
 
21
23
  // constants
22
- import {_INTERFACEID_CLAIM_OWNERSHIP} from "../Custom/IClaimOwnership.sol";
23
-
24
+ import "@erc725/smart-contracts/contracts/errors.sol";
24
25
  import {
25
- OPERATION_CALL,
26
- OPERATION_STATICCALL,
27
- OPERATION_CREATE,
28
- OPERATION_CREATE2
26
+ OPERATION_0_CALL,
27
+ OPERATION_1_CREATE,
28
+ OPERATION_2_CREATE2,
29
+ OPERATION_3_STATICCALL
29
30
  } from "@erc725/smart-contracts/contracts/constants.sol";
30
31
  import {
31
32
  _INTERFACEID_LSP1,
32
- _INTERFACEID_LSP1_DELEGATE,
33
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
33
34
  _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
34
35
  } from "../LSP1UniversalReceiver/LSP1Constants.sol";
36
+
37
+ import {_LSP6KEY_ADDRESSPERMISSIONS_PREFIX} from "../LSP6KeyManager/LSP6Constants.sol";
35
38
  import {
36
39
  _INTERFACEID_LSP9,
37
- _TYPEID_LSP9_VAULTRECIPIENT,
38
- _TYPEID_LSP9_VAULTSENDER,
39
- _TYPEID_LSP9_VAULTPENDINGOWNER
40
+ _TYPEID_LSP9_OwnershipTransferStarted,
41
+ _TYPEID_LSP9_OwnershipTransferred_SenderNotification,
42
+ _TYPEID_LSP9_OwnershipTransferred_RecipientNotification
40
43
  } from "./LSP9Constants.sol";
44
+ import {_INTERFACEID_LSP14} from "../LSP14Ownable2Step/LSP14Constants.sol";
45
+ import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.sol";
46
+
47
+ // errors
48
+ import "./LSP9Errors.sol";
41
49
 
42
50
  /**
43
51
  * @title Core Implementation of LSP9Vault built on top of ERC725, LSP1UniversalReceiver
44
52
  * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
45
53
  * @dev Could be owned by a UniversalProfile and able to register received asset with UniversalReceiverDelegateVault
46
54
  */
47
- contract LSP9VaultCore is ERC725XCore, ERC725YCore, ClaimOwnership, ILSP1UniversalReceiver {
55
+ contract LSP9VaultCore is
56
+ ERC725XCore,
57
+ ERC725YCore,
58
+ LSP14Ownable2Step,
59
+ LSP17Extendable,
60
+ ILSP1UniversalReceiver
61
+ {
62
+ using ERC165Checker for address;
63
+ using LSP1Utils for address;
64
+
65
+ address private _reentrantDelegate;
66
+
48
67
  /**
49
68
  * @notice Emitted when receiving native tokens
50
69
  * @param sender The address of the sender
51
- * @param value The amount of value sent
70
+ * @param value The amount of native tokens received
52
71
  */
53
72
  event ValueReceived(address indexed sender, uint256 indexed value);
54
73
 
55
- // modifiers
74
+ /**
75
+ * @dev Emits an event when receiving native tokens
76
+ *
77
+ * Executed when receiving native tokens with empty calldata.
78
+ */
79
+ receive() external payable virtual {
80
+ if (msg.value > 0) emit ValueReceived(msg.sender, msg.value);
81
+ }
56
82
 
57
83
  /**
58
- * @dev Modifier restricting the call to the owner of the contract and the UniversalReceiverDelegate
84
+ * @dev Returns the extension stored under the `_LSP17_EXTENSION_PREFIX` data key
85
+ * mapped to the functionSelector provided.
86
+ *
87
+ * If no extension is stored, returns the address(0)
59
88
  */
60
- modifier onlyAllowed() {
61
- if (msg.sender != owner()) {
62
- address universalReceiverAddress = address(
63
- bytes20(_getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY))
64
- );
65
- require(
66
- ERC165Checker.supportsERC165Interface(msg.sender, _INTERFACEID_LSP1_DELEGATE) &&
67
- msg.sender == universalReceiverAddress,
68
- "Only Owner or Universal Receiver Delegate allowed"
69
- );
70
- }
71
- _;
89
+ function _getExtension(bytes4 functionSelector)
90
+ internal
91
+ view
92
+ virtual
93
+ override
94
+ returns (address)
95
+ {
96
+ bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
97
+ _LSP17_EXTENSION_PREFIX,
98
+ functionSelector
99
+ );
100
+
101
+ // Check if there is an extension for the function selector provided
102
+ address extension = address(bytes20(_getData(mappedExtensionDataKey)));
103
+
104
+ return extension;
72
105
  }
73
106
 
74
- // public functions
107
+ // solhint-disable no-complex-fallback
75
108
 
76
109
  /**
77
110
  * @dev Emits an event when receiving native tokens
111
+ *
112
+ * Forwards the call to an extension (address) stored under a _LSP17_FALLBACK_EXTENSIONS_HANDLER_ appended
113
+ * to a function selector. If there is no extension stored under the data key, return.
114
+ *
115
+ * The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
116
+ * Returns the return value on success and revert in case of failure.
117
+ *
118
+ * If the msg.data is shorter than 4 bytes or the first 4 bytes are 0s
119
+ * do not check for an extension and return
120
+ *
121
+ * Executed when:
122
+ * - the first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
123
+ * - receiving native tokens with some calldata.
78
124
  */
79
125
  fallback() external payable virtual {
80
126
  if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
127
+ if (msg.data.length < 4 || msg.sig == bytes4(0)) return;
128
+ _fallbackLSP17Extendable();
81
129
  }
82
130
 
83
- // ERC725
131
+ /**
132
+ * @dev Returns true if this contract implements the interface defined by
133
+ * `interfaceId`.
134
+ *
135
+ * If the contract doesn't support the `interfaceId`, it forwards the call to the
136
+ * `supportsInterface` extension according to LSP17, and checks if the extension
137
+ * implements the interface defined by `interfaceId`.
138
+ */
139
+ function supportsInterface(bytes4 interfaceId)
140
+ public
141
+ view
142
+ virtual
143
+ override(ERC725XCore, ERC725YCore, LSP17Extendable)
144
+ returns (bool)
145
+ {
146
+ return
147
+ interfaceId == _INTERFACEID_LSP9 ||
148
+ interfaceId == _INTERFACEID_LSP1 ||
149
+ interfaceId == _INTERFACEID_LSP14 ||
150
+ super.supportsInterface(interfaceId) ||
151
+ _supportsInterfaceInERC165Extension(interfaceId);
152
+ }
84
153
 
85
154
  /**
86
155
  * @inheritdoc IERC725X
87
- * @param operation The operation to execute: CALL = 0 CREATE = 1 CREATE2 = 2 STATICCALL = 3
156
+ * @param operationType The operation to execute: CALL = 0 CREATE = 1 CREATE2 = 2 STATICCALL = 3
88
157
  * @dev Executes any other smart contract.
89
158
  * SHOULD only be callable by the owner of the contract set via ERC173
90
159
  *
91
160
  * Emits a {Executed} event, when a call is executed under `operationType` 0 and 3
92
161
  * Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2
162
+ * Emits a {ValueReceived} event, when receives native token
93
163
  */
94
164
  function execute(
95
- uint256 operation,
96
- address to,
165
+ uint256 operationType,
166
+ address target,
97
167
  uint256 value,
98
168
  bytes memory data
99
169
  ) public payable virtual override onlyOwner returns (bytes memory) {
100
- require(address(this).balance >= value, "ERC725X: insufficient balance");
101
-
102
- // CALL
103
- if (operation == OPERATION_CALL) return _executeCall(to, value, data);
104
-
105
- // Deploy with CREATE
106
- if (operation == OPERATION_CREATE) return _deployCreate(to, value, data);
107
-
108
- // Deploy with CREATE2
109
- if (operation == OPERATION_CREATE2) return _deployCreate2(to, value, data);
110
-
111
- // STATICCALL
112
- if (operation == OPERATION_STATICCALL) return _executeStaticCall(to, value, data);
170
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
171
+ return _execute(operationType, target, value, data);
172
+ }
113
173
 
114
- revert("ERC725X: Unknown operation type");
174
+ /**
175
+ * @inheritdoc ERC725XCore
176
+ *
177
+ * @dev Emits a {ValueReceived} event when receiving native tokens.
178
+ */
179
+ function execute(
180
+ uint256[] memory operationsType,
181
+ address[] memory targets,
182
+ uint256[] memory values,
183
+ bytes[] memory datas
184
+ ) public payable virtual override onlyOwner returns (bytes[] memory) {
185
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
186
+ return _execute(operationsType, targets, values, datas);
115
187
  }
116
188
 
117
189
  /**
@@ -122,7 +194,17 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ClaimOwnership, ILSP1Univers
122
194
  *
123
195
  * Emits a {DataChanged} event.
124
196
  */
125
- function setData(bytes32 dataKey, bytes memory dataValue) public virtual override onlyAllowed {
197
+ function setData(bytes32 dataKey, bytes memory dataValue) public virtual override {
198
+ bool isURD = _validateAndIdentifyCaller();
199
+ if (isURD) {
200
+ if (
201
+ bytes12(dataKey) == _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX ||
202
+ bytes6(dataKey) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX ||
203
+ bytes12(dataKey) == _LSP17_EXTENSION_PREFIX
204
+ ) {
205
+ revert LSP1DelegateNotAllowedToSetDataKey(dataKey);
206
+ }
207
+ }
126
208
  _setData(dataKey, dataValue);
127
209
  }
128
210
 
@@ -134,110 +216,133 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ClaimOwnership, ILSP1Univers
134
216
  *
135
217
  * Emits a {DataChanged} event.
136
218
  */
137
- function setData(bytes32[] memory dataKeys, bytes[] memory dataValues)
138
- public
139
- virtual
140
- override
141
- onlyAllowed
142
- {
143
- require(dataKeys.length == dataValues.length, "Keys length not equal to values length");
219
+ function setData(bytes32[] memory dataKeys, bytes[] memory dataValues) public virtual override {
220
+ bool isURD = _validateAndIdentifyCaller();
221
+ if (dataKeys.length != dataValues.length) {
222
+ revert ERC725Y_DataKeysValuesLengthMismatch(dataKeys.length, dataValues.length);
223
+ }
224
+
144
225
  for (uint256 i = 0; i < dataKeys.length; i = GasLib.uncheckedIncrement(i)) {
226
+ if (isURD) {
227
+ if (
228
+ bytes12(dataKeys[i]) == _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX ||
229
+ bytes6(dataKeys[i]) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX ||
230
+ bytes12(dataKeys[i]) == _LSP17_EXTENSION_PREFIX
231
+ ) {
232
+ revert LSP1DelegateNotAllowedToSetDataKey(dataKeys[i]);
233
+ }
234
+ }
145
235
  _setData(dataKeys[i], dataValues[i]);
146
236
  }
147
237
  }
148
238
 
149
- // LSP1
239
+ /**
240
+ * @dev Modifier restricting the call to the owner of the contract and the UniversalReceiverDelegate
241
+ */
242
+ function _validateAndIdentifyCaller() internal view returns (bool isURD) {
243
+ if (msg.sender != owner()) {
244
+ require(
245
+ msg.sender == _reentrantDelegate,
246
+ "Only Owner or reentered Universal Receiver Delegate allowed"
247
+ );
248
+ isURD = true;
249
+ }
250
+ }
150
251
 
151
252
  /**
152
253
  * @notice Triggers the UniversalReceiver event when this function gets executed successfully.
153
- * @dev Forwards the call to the UniversalReceiverDelegate if set.
254
+ * Forwards the call to the addresses stored in the ERC725Y storage under the LSP1UniversalReceiverDelegate
255
+ * Key and the typeId Key (param) respectively. The call will be discarded if no addresses are set.
256
+ *
154
257
  * @param typeId The type of call received.
155
- * @param data The data received.
258
+ * @param receivedData The data received.
259
+ * @return returnedValues The ABI encoded return value of the LSP1UniversalReceiverDelegate call
260
+ * and the LSP1TypeIdDelegate call.
156
261
  */
157
- function universalReceiver(bytes32 typeId, bytes calldata data)
262
+ function universalReceiver(bytes32 typeId, bytes calldata receivedData)
158
263
  public
159
264
  payable
160
265
  virtual
161
- returns (bytes memory returnValue)
266
+ returns (bytes memory returnedValues)
162
267
  {
268
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
163
269
  bytes memory lsp1DelegateValue = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
270
+ bytes memory resultDefaultDelegate;
164
271
 
165
272
  if (lsp1DelegateValue.length >= 20) {
166
273
  address universalReceiverDelegate = address(bytes20(lsp1DelegateValue));
167
274
 
168
- if (
169
- ERC165Checker.supportsERC165Interface(
170
- universalReceiverDelegate,
171
- _INTERFACEID_LSP1_DELEGATE
172
- )
173
- ) {
174
- returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
175
- .universalReceiverDelegate(msg.sender, msg.value, typeId, data);
275
+ if (universalReceiverDelegate.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
276
+ _reentrantDelegate = universalReceiverDelegate;
277
+ resultDefaultDelegate = universalReceiverDelegate
278
+ .callUniversalReceiverWithCallerInfos(
279
+ typeId,
280
+ receivedData,
281
+ msg.sender,
282
+ msg.value
283
+ );
176
284
  }
177
285
  }
178
- emit UniversalReceiver(msg.sender, msg.value, typeId, returnValue, data);
179
- }
180
286
 
181
- // ERC173 - Modified ClaimOwnership
287
+ bytes32 lsp1typeIdDelegateKey = LSP2Utils.generateMappingKey(
288
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
289
+ bytes20(typeId)
290
+ );
291
+
292
+ bytes memory lsp1TypeIdDelegateValue = _getData(lsp1typeIdDelegateKey);
293
+ bytes memory resultTypeIdDelegate;
294
+
295
+ if (lsp1TypeIdDelegateValue.length >= 20) {
296
+ address universalReceiverDelegate = address(bytes20(lsp1TypeIdDelegateValue));
297
+
298
+ if (universalReceiverDelegate.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
299
+ _reentrantDelegate = universalReceiverDelegate;
300
+ resultTypeIdDelegate = universalReceiverDelegate
301
+ .callUniversalReceiverWithCallerInfos(
302
+ typeId,
303
+ receivedData,
304
+ msg.sender,
305
+ msg.value
306
+ );
307
+ }
308
+ }
309
+
310
+ delete _reentrantDelegate;
311
+ returnedValues = abi.encode(resultDefaultDelegate, resultTypeIdDelegate);
312
+ emit UniversalReceiver(msg.sender, msg.value, typeId, receivedData, returnedValues);
313
+ }
182
314
 
183
315
  /**
184
316
  * @dev Sets the pending owner and notify the pending owner
317
+ *
318
+ * @param _newOwner The address nofied and set as `pendingOwner`
185
319
  */
186
- function transferOwnership(address newOwner)
320
+ function transferOwnership(address _newOwner)
187
321
  public
188
322
  virtual
189
- override(ClaimOwnership, OwnableUnset)
323
+ override(LSP14Ownable2Step, OwnableUnset)
190
324
  onlyOwner
191
325
  {
192
- ClaimOwnership._transferOwnership(newOwner);
193
- _notifyVaultPendingOwner(newOwner);
194
- }
195
-
196
- /**
197
- * @dev Transfer the ownership and notify the previous and the new owner.
198
- */
199
- function claimOwnership() public virtual override {
200
- address previousOwner = owner();
201
-
202
- _claimOwnership();
203
-
204
- _notifyVaultSender(previousOwner);
205
- _notifyVaultReceiver(msg.sender);
326
+ LSP14Ownable2Step._transferOwnership(_newOwner);
206
327
  }
207
328
 
208
329
  /**
209
330
  * @dev Renounce ownership of the contract in a 2-step process
210
331
  */
211
- function renounceOwnership() public virtual override(ClaimOwnership, OwnableUnset) onlyOwner {
212
- ClaimOwnership._renounceOwnership();
213
- }
214
-
215
- // ERC165
216
-
217
- /**
218
- * @dev See {IERC165-supportsInterface}.
219
- */
220
- function supportsInterface(bytes4 interfaceId)
332
+ function renounceOwnership()
221
333
  public
222
- view
223
334
  virtual
224
- override(ERC725XCore, ERC725YCore)
225
- returns (bool)
335
+ override(LSP14Ownable2Step, OwnableUnset)
336
+ onlyOwner
226
337
  {
227
- return
228
- interfaceId == _INTERFACEID_LSP9 ||
229
- interfaceId == _INTERFACEID_LSP1 ||
230
- interfaceId == _INTERFACEID_CLAIM_OWNERSHIP ||
231
- super.supportsInterface(interfaceId);
338
+ LSP14Ownable2Step._renounceOwnership();
232
339
  }
233
340
 
234
- // internal functions
235
-
236
341
  /**
237
342
  * @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
238
343
  */
239
344
  function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
240
- store[dataKey] = dataValue;
345
+ _store[dataKey] = dataValue;
241
346
  emit DataChanged(
242
347
  dataKey,
243
348
  dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
@@ -245,31 +350,89 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ClaimOwnership, ILSP1Univers
245
350
  }
246
351
 
247
352
  /**
248
- * @dev Calls the universalReceiver function of the vault sender if supports LSP1 InterfaceId
353
+ * @dev disable operation type DELEGATECALL (4).
354
+ * NB: providing operation type DELEGATECALL (4) as argument will result
355
+ * in custom error ERC725X_UnknownOperationType(4)
249
356
  */
250
- function _notifyVaultSender(address sender) internal virtual {
251
- if (ERC165Checker.supportsERC165Interface(sender, _INTERFACEID_LSP1)) {
252
- ILSP1UniversalReceiver(sender).universalReceiver(_TYPEID_LSP9_VAULTSENDER, "");
357
+ function _execute(
358
+ uint256 operationType,
359
+ address target,
360
+ uint256 value,
361
+ bytes memory data
362
+ ) internal virtual override returns (bytes memory) {
363
+ // CALL
364
+ if (operationType == OPERATION_0_CALL) {
365
+ return _executeCall(target, value, data);
366
+ }
367
+
368
+ // Deploy with CREATE
369
+ if (operationType == uint256(OPERATION_1_CREATE)) {
370
+ if (target != address(0)) revert ERC725X_CreateOperationsRequireEmptyRecipientAddress();
371
+ return _deployCreate(value, data);
372
+ }
373
+
374
+ // Deploy with CREATE2
375
+ if (operationType == uint256(OPERATION_2_CREATE2)) {
376
+ if (target != address(0)) revert ERC725X_CreateOperationsRequireEmptyRecipientAddress();
377
+ return _deployCreate2(value, data);
378
+ }
379
+
380
+ // STATICCALL
381
+ if (operationType == uint256(OPERATION_3_STATICCALL)) {
382
+ if (value != 0) revert ERC725X_MsgValueDisallowedInStaticCall();
383
+ return _executeStaticCall(target, data);
384
+ }
385
+
386
+ revert ERC725X_UnknownOperationType(operationType);
387
+ }
388
+
389
+ // --- LSP14 URD Hooks
390
+
391
+ /**
392
+ * @dev Calls the universalReceiver function of the sender when ownerhsip transfer starts
393
+ * if supports LSP1 InterfaceId
394
+ */
395
+ function _notifyLSP1SenderOnOwnershipTransferStart(address notifiedContract, bytes memory data)
396
+ internal
397
+ virtual
398
+ override
399
+ {
400
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
401
+ ILSP1UniversalReceiver(notifiedContract).universalReceiver(
402
+ _TYPEID_LSP9_OwnershipTransferStarted,
403
+ data
404
+ );
253
405
  }
254
406
  }
255
407
 
256
408
  /**
257
- * @dev Calls the universalReceiver function of the vault owner if supports LSP1 InterfaceId
409
+ * @dev Calls the universalReceiver function of the sender when ownerhsip transfer is complete
410
+ * if supports LSP1 InterfaceId
258
411
  */
259
- function _notifyVaultReceiver(address receiver) internal virtual {
260
- if (ERC165Checker.supportsERC165Interface(receiver, _INTERFACEID_LSP1)) {
261
- ILSP1UniversalReceiver(receiver).universalReceiver(_TYPEID_LSP9_VAULTRECIPIENT, "");
412
+ function _notifyLSP1SenderOnOwnershipTransferCompletion(
413
+ address notifiedContract,
414
+ bytes memory data
415
+ ) internal virtual override {
416
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
417
+ ILSP1UniversalReceiver(notifiedContract).universalReceiver(
418
+ _TYPEID_LSP9_OwnershipTransferred_SenderNotification,
419
+ data
420
+ );
262
421
  }
263
422
  }
264
423
 
265
424
  /**
266
- * @dev Calls the universalReceiver function of the pending owner if supports LSP1 InterfaceId
425
+ * @dev Calls the universalReceiver function of the recipient when ownerhsip transfer is complete
426
+ * if supports LSP1 InterfaceId
267
427
  */
268
- function _notifyVaultPendingOwner(address newPendingOwner) internal virtual {
269
- if (ERC165Checker.supportsERC165Interface(newPendingOwner, _INTERFACEID_LSP1)) {
270
- ILSP1UniversalReceiver(newPendingOwner).universalReceiver(
271
- _TYPEID_LSP9_VAULTPENDINGOWNER,
272
- ""
428
+ function _notifyLSP1RecipientOnOwnershipTransferCompletion(
429
+ address notifiedContract,
430
+ bytes memory data
431
+ ) internal virtual override {
432
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
433
+ ILSP1UniversalReceiver(notifiedContract).universalReceiver(
434
+ _TYPEID_LSP9_OwnershipTransferred_RecipientNotification,
435
+ data
273
436
  );
274
437
  }
275
438
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // modules
5
5
  import {LSP9VaultInitAbstract} from "./LSP9VaultInitAbstract.sol";
@@ -21,7 +21,7 @@ contract LSP9VaultInit is LSP9VaultInitAbstract {
21
21
  * @notice Sets the owner of the contract and sets the SupportedStandards:LSP9Vault key
22
22
  * @param newOwner the owner of the contract
23
23
  */
24
- function initialize(address newOwner) public virtual initializer {
24
+ function initialize(address newOwner) external payable virtual initializer {
25
25
  LSP9VaultInitAbstract._initialize(newOwner);
26
26
  }
27
27
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
@@ -7,7 +7,7 @@ import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.so
7
7
  // modules
8
8
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
9
9
  import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
10
- import {LSP9VaultCore, ClaimOwnership} from "./LSP9VaultCore.sol";
10
+ import {LSP9VaultCore} from "./LSP9VaultCore.sol";
11
11
 
12
12
  // constants
13
13
  import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
@@ -24,11 +24,12 @@ import {
24
24
  */
25
25
  abstract contract LSP9VaultInitAbstract is Initializable, LSP9VaultCore {
26
26
  function _initialize(address newOwner) internal virtual onlyInitializing {
27
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
27
28
  OwnableUnset._setOwner(newOwner);
28
29
 
29
30
  // set key SupportedStandards:LSP9Vault
30
31
  _setData(_LSP9_SUPPORTED_STANDARDS_KEY, _LSP9_SUPPORTED_STANDARDS_VALUE);
31
32
 
32
- _notifyVaultReceiver(newOwner);
33
+ _notifyLSP1RecipientOnOwnershipTransferCompletion(newOwner, "");
33
34
  }
34
35
  }
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // libraries
5
5
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // libraries
5
5
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
@@ -1,10 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
3
-
4
- // interfaces
5
- import {
6
- ILSP1UniversalReceiverDelegate
7
- } from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
2
+ pragma solidity ^0.8.4;
8
3
 
9
4
  // libraries
10
5
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
@@ -13,11 +8,7 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
13
8
  import {ERC165Storage} from "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
14
9
  import {AddressRegistry} from "./Registries/AddressRegistry.sol";
15
10
 
16
- contract UniversalReceiverAddressStore is
17
- ERC165Storage,
18
- ILSP1UniversalReceiverDelegate,
19
- AddressRegistry
20
- {
11
+ contract UniversalReceiverAddressStore is ERC165Storage, AddressRegistry {
21
12
  using EnumerableSet for EnumerableSet.AddressSet;
22
13
 
23
14
  bytes4 internal constant _INTERFACE_ID_LSP1DELEGATE = 0xa245bbda;
@@ -40,13 +31,12 @@ contract UniversalReceiverAddressStore is
40
31
  return _addressStore.remove(_address);
41
32
  }
42
33
 
43
- // solhint-disable no-unused-vars
44
34
  function universalReceiverDelegate(
45
35
  address sender,
46
- uint256 value,
36
+ uint256, /* value */
47
37
  bytes32 typeId,
48
38
  bytes memory
49
- ) external override onlyAccount returns (bytes memory) {
39
+ ) external onlyAccount returns (bytes memory) {
50
40
  // require(typeId == _TOKENS_RECIPIENT_INTERFACE_HASH, 'UniversalReceiverDelegate: Type not supported');
51
41
 
52
42
  // store tokens only if received, DO NOT revert on _TOKENS_SENDER_INTERFACE_HASH
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // modules
5
5
  import {LSP0ERC725Account} from "./LSP0ERC725Account/LSP0ERC725Account.sol";
@@ -20,7 +20,7 @@ contract UniversalProfile is LSP0ERC725Account {
20
20
  * @notice Sets the owner of the contract and sets the SupportedStandards:LSP3UniversalProfile key
21
21
  * @param newOwner the owner of the contract
22
22
  */
23
- constructor(address newOwner) LSP0ERC725Account(newOwner) payable {
23
+ constructor(address newOwner) payable LSP0ERC725Account(newOwner) {
24
24
  // set key SupportedStandards:LSP3UniversalProfile
25
25
  _setData(_LSP3_SUPPORTED_STANDARDS_KEY, _LSP3_SUPPORTED_STANDARDS_VALUE);
26
26
  }