@lukso/lsp-smart-contracts 0.8.2 → 0.10.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 (179) hide show
  1. package/README.md +29 -8
  2. package/artifacts/LSP0ERC725Account.json +90 -50
  3. package/artifacts/LSP0ERC725AccountInit.json +90 -50
  4. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  5. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  6. package/artifacts/LSP16UniversalFactory.json +31 -2
  7. package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
  8. package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
  9. package/artifacts/LSP4Compatibility.json +39 -40
  10. package/artifacts/LSP4DigitalAssetMetadata.json +39 -40
  11. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +39 -40
  12. package/artifacts/LSP6KeyManager.json +107 -8
  13. package/artifacts/LSP6KeyManagerInit.json +119 -20
  14. package/artifacts/LSP7CappedSupply.json +78 -38
  15. package/artifacts/LSP7CappedSupplyInitAbstract.json +78 -38
  16. package/artifacts/LSP7CompatibleERC20.json +78 -38
  17. package/artifacts/LSP7CompatibleERC20InitAbstract.json +78 -38
  18. package/artifacts/LSP7CompatibleERC20Mintable.json +80 -40
  19. package/artifacts/LSP7CompatibleERC20MintableInit.json +80 -40
  20. package/artifacts/LSP7DigitalAsset.json +78 -38
  21. package/artifacts/LSP7DigitalAssetInitAbstract.json +78 -38
  22. package/artifacts/LSP7Mintable.json +80 -40
  23. package/artifacts/LSP7MintableInit.json +80 -40
  24. package/artifacts/LSP8CappedSupply.json +39 -40
  25. package/artifacts/LSP8CappedSupplyInitAbstract.json +39 -40
  26. package/artifacts/LSP8CompatibleERC721.json +42 -43
  27. package/artifacts/LSP8CompatibleERC721InitAbstract.json +42 -43
  28. package/artifacts/LSP8CompatibleERC721Mintable.json +44 -45
  29. package/artifacts/LSP8CompatibleERC721MintableInit.json +44 -45
  30. package/artifacts/LSP8IdentifiableDigitalAsset.json +39 -40
  31. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +39 -40
  32. package/artifacts/LSP8Mintable.json +41 -42
  33. package/artifacts/LSP8MintableInit.json +41 -42
  34. package/artifacts/LSP9Vault.json +73 -55
  35. package/artifacts/LSP9VaultInit.json +73 -55
  36. package/artifacts/UniversalProfile.json +90 -50
  37. package/artifacts/UniversalProfileInit.json +90 -50
  38. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +62 -0
  39. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  40. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +36 -6
  41. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +605 -219
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +31 -5
  43. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +37 -3
  44. package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -1
  45. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +71 -60
  46. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -7
  47. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +0 -1
  48. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
  49. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +41 -84
  50. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
  51. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -5
  52. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +0 -4
  53. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +129 -77
  54. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +45 -16
  55. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
  56. package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
  57. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +83 -0
  58. package/contracts/LSP20CallVerification/LSP20Constants.sol +17 -0
  59. package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
  60. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +26 -12
  61. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +0 -1
  62. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +76 -66
  63. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +12 -3
  64. package/contracts/LSP6KeyManager/LSP6Constants.sol +9 -3
  65. package/contracts/LSP6KeyManager/LSP6Errors.sol +22 -1
  66. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +172 -29
  67. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
  68. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +270 -100
  69. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +187 -67
  70. package/contracts/LSP6KeyManager/LSP6Utils.sol +31 -20
  71. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +79 -30
  72. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  73. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -2
  74. package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +24 -0
  75. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -2
  76. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +1 -2
  77. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +3 -5
  78. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +3 -5
  79. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +27 -29
  80. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +1 -1
  81. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +1 -2
  82. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +1 -2
  83. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +5 -5
  84. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +6 -6
  85. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +2 -2
  86. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +2 -2
  87. package/contracts/LSP9Vault/ILSP9Vault.sol +27 -0
  88. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  89. package/contracts/LSP9Vault/LSP9Vault.sol +11 -8
  90. package/contracts/LSP9Vault/LSP9VaultCore.sol +96 -71
  91. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -1
  92. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +19 -7
  93. package/contracts/UniversalProfileInitAbstract.sol +5 -0
  94. package/devdocs/Create2Factory.json +16 -0
  95. package/devdocs/LSP0ERC725Account.json +200 -0
  96. package/devdocs/LSP0ERC725AccountInit.json +203 -0
  97. package/devdocs/LSP11BasicSocialRecovery.json +146 -0
  98. package/devdocs/LSP11BasicSocialRecoveryInit.json +146 -0
  99. package/devdocs/LSP16UniversalFactory.json +51 -0
  100. package/devdocs/LSP1UniversalReceiverDelegateUP.json +80 -0
  101. package/devdocs/LSP1UniversalReceiverDelegateVault.json +62 -0
  102. package/devdocs/LSP4Compatibility.json +79 -0
  103. package/devdocs/LSP4DigitalAssetMetadata.json +84 -0
  104. package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +77 -0
  105. package/devdocs/LSP6KeyManager.json +257 -0
  106. package/devdocs/LSP6KeyManagerInit.json +260 -0
  107. package/devdocs/LSP7CappedSupply.json +211 -0
  108. package/devdocs/LSP7CappedSupplyInitAbstract.json +206 -0
  109. package/devdocs/LSP7CompatibleERC20.json +225 -0
  110. package/devdocs/LSP7CompatibleERC20InitAbstract.json +218 -0
  111. package/devdocs/LSP7CompatibleERC20Mintable.json +217 -0
  112. package/devdocs/LSP7CompatibleERC20MintableInit.json +227 -0
  113. package/devdocs/LSP7DigitalAsset.json +210 -0
  114. package/devdocs/LSP7DigitalAssetInitAbstract.json +202 -0
  115. package/devdocs/LSP7Mintable.json +219 -0
  116. package/devdocs/LSP7MintableInit.json +220 -0
  117. package/devdocs/LSP8CappedSupply.json +232 -0
  118. package/devdocs/LSP8CappedSupplyInitAbstract.json +227 -0
  119. package/devdocs/LSP8CompatibleERC721.json +298 -0
  120. package/devdocs/LSP8CompatibleERC721InitAbstract.json +291 -0
  121. package/devdocs/LSP8CompatibleERC721Mintable.json +290 -0
  122. package/devdocs/LSP8CompatibleERC721MintableInit.json +300 -0
  123. package/devdocs/LSP8IdentifiableDigitalAsset.json +230 -0
  124. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +223 -0
  125. package/devdocs/LSP8Mintable.json +242 -0
  126. package/devdocs/LSP8MintableInit.json +245 -0
  127. package/devdocs/LSP9Vault.json +171 -0
  128. package/devdocs/LSP9VaultInit.json +175 -0
  129. package/devdocs/UniversalProfile.json +199 -0
  130. package/devdocs/UniversalProfileInit.json +202 -0
  131. package/devdocs/UniversalReceiverAddressStore.json +9 -0
  132. package/dist/constants.cjs.js +31569 -0
  133. package/dist/constants.d.ts +31681 -0
  134. package/dist/constants.es.js +31550 -0
  135. package/package.json +70 -52
  136. package/userdocs/Create2Factory.json +5 -0
  137. package/userdocs/LSP0ERC725Account.json +47 -0
  138. package/userdocs/LSP0ERC725AccountInit.json +47 -0
  139. package/userdocs/LSP11BasicSocialRecovery.json +29 -0
  140. package/userdocs/LSP11BasicSocialRecoveryInit.json +29 -0
  141. package/userdocs/LSP16UniversalFactory.json +5 -0
  142. package/userdocs/LSP1UniversalReceiverDelegateUP.json +10 -0
  143. package/userdocs/LSP1UniversalReceiverDelegateVault.json +10 -0
  144. package/userdocs/LSP4Compatibility.json +20 -0
  145. package/userdocs/LSP4DigitalAssetMetadata.json +23 -0
  146. package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +20 -0
  147. package/userdocs/LSP6KeyManager.json +18 -0
  148. package/userdocs/LSP6KeyManagerInit.json +18 -0
  149. package/userdocs/LSP7CappedSupply.json +29 -0
  150. package/userdocs/LSP7CappedSupplyInitAbstract.json +26 -0
  151. package/userdocs/LSP7CompatibleERC20.json +35 -0
  152. package/userdocs/LSP7CompatibleERC20InitAbstract.json +32 -0
  153. package/userdocs/LSP7CompatibleERC20Mintable.json +32 -0
  154. package/userdocs/LSP7CompatibleERC20MintableInit.json +35 -0
  155. package/userdocs/LSP7DigitalAsset.json +29 -0
  156. package/userdocs/LSP7DigitalAssetInitAbstract.json +26 -0
  157. package/userdocs/LSP7Mintable.json +29 -0
  158. package/userdocs/LSP7MintableInit.json +29 -0
  159. package/userdocs/LSP8CappedSupply.json +23 -0
  160. package/userdocs/LSP8CappedSupplyInitAbstract.json +20 -0
  161. package/userdocs/LSP8CompatibleERC721.json +29 -0
  162. package/userdocs/LSP8CompatibleERC721InitAbstract.json +26 -0
  163. package/userdocs/LSP8CompatibleERC721Mintable.json +26 -0
  164. package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -0
  165. package/userdocs/LSP8IdentifiableDigitalAsset.json +23 -0
  166. package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +20 -0
  167. package/userdocs/LSP8Mintable.json +23 -0
  168. package/userdocs/LSP8MintableInit.json +23 -0
  169. package/userdocs/LSP9Vault.json +38 -0
  170. package/userdocs/LSP9VaultInit.json +38 -0
  171. package/userdocs/UniversalProfile.json +50 -0
  172. package/userdocs/UniversalProfileInit.json +50 -0
  173. package/userdocs/UniversalReceiverAddressStore.json +5 -0
  174. package/CONTRIBUTING.md +0 -57
  175. package/common/constants.d.ts +0 -738
  176. package/common/constants.js +0 -785
  177. package/contracts/Utils/GasLib.sol +0 -17
  178. package/module/constants.d.ts +0 -738
  179. package/module/constants.js +0 -782
@@ -3,6 +3,7 @@ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
+ import {ILSP0ERC725Account} from "./ILSP0ERC725Account.sol";
6
7
  import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
8
 
8
9
  // libraries
@@ -19,10 +20,10 @@ import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
19
20
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
20
21
  import {LSP14Ownable2Step} from "../LSP14Ownable2Step/LSP14Ownable2Step.sol";
21
22
  import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol";
23
+ import {LSP20CallVerification} from "../LSP20CallVerification/LSP20CallVerification.sol";
22
24
 
23
25
  // constants
24
26
  import "@erc725/smart-contracts/contracts/constants.sol";
25
- import "@erc725/smart-contracts/contracts/errors.sol";
26
27
  import {
27
28
  _INTERFACEID_LSP0,
28
29
  _INTERFACEID_ERC1271,
@@ -40,254 +41,387 @@ import {
40
41
  import {_INTERFACEID_LSP14} from "../LSP14Ownable2Step/LSP14Constants.sol";
41
42
 
42
43
  import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.sol";
44
+ import {_INTERFACEID_LSP20_CALL_VERIFICATION} from "../LSP20CallVerification/LSP20Constants.sol";
43
45
 
44
46
  // errors
45
- import "../LSP17ContractExtension/LSP17Errors.sol";
47
+ import {ERC725Y_DataKeysValuesLengthMismatch} from "@erc725/smart-contracts/contracts/errors.sol";
48
+ import {NoExtensionFoundForFunctionSelector} from "../LSP17ContractExtension/LSP17Errors.sol";
46
49
 
47
50
  /**
48
- * @title Core Implementation of ERC725Account
49
- * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
50
- * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
51
+ * @title The Core Implementation of LSP0-ERC725Account Standard
52
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-0-ERC725Account.md
53
+ *
54
+ * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42)
55
+ * @dev A smart contract account including basic functionalities such as:
56
+ *
57
+ * - Detecting supported standards using ERC165
58
+ * https://eips.ethereum.org/EIPS/eip-165
59
+ *
60
+ * - Executing several operation on other addresses including creating contracts using ERC725X
61
+ * https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md
62
+ *
63
+ * - Storing data in a generic way using ERC725Y
64
+ * https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md
65
+ *
66
+ * - Validating signatures using ERC1271
67
+ * https://eips.ethereum.org/EIPS/eip-1271
68
+ *
69
+ * - Receiving notification and react on them using LSP1
70
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-1-UniversalReceiver.md
71
+ *
72
+ * - Secure ownership management using LSP14
73
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-14-Ownable2Step.md
74
+ *
75
+ * - Extending the account with new functions and interfaceIds of future standards using LSP17
76
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-17-ContractExtension.md
77
+ *
78
+ * - Verifying calls on the owner to allow unified and standard interaction with the account using LSP20
79
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-20-CallVerification.md
51
80
  */
52
81
  abstract contract LSP0ERC725AccountCore is
53
82
  ERC725XCore,
54
83
  ERC725YCore,
84
+ IERC1271,
85
+ ILSP0ERC725Account,
86
+ ILSP1UniversalReceiver,
55
87
  LSP14Ownable2Step,
56
88
  LSP17Extendable,
57
- IERC1271,
58
- ILSP1UniversalReceiver
89
+ LSP20CallVerification
59
90
  {
60
91
  using ERC165Checker for address;
61
92
  using LSP1Utils for address;
62
93
  using Address for address;
63
94
 
64
95
  /**
65
- * @notice Emitted when receiving native tokens
66
- * @param sender The address of the sender
67
- * @param value The amount of native tokens received
68
- */
69
- event ValueReceived(address indexed sender, uint256 indexed value);
70
-
71
- /**
72
- * @dev Emits an event when receiving native tokens
96
+ * @dev Emits a `ValueReceived` event when receiving native tokens.
73
97
  *
74
98
  * Executed:
75
99
  * - when receiving some native tokens without any additional data.
76
100
  * - on empty calls to the contract.
77
101
  */
78
102
  receive() external payable virtual {
79
- if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
103
+ if (msg.value != 0) {
104
+ emit ValueReceived(msg.sender, msg.value);
105
+ }
80
106
  }
81
107
 
82
108
  // solhint-disable no-complex-fallback
83
109
 
84
110
  /**
85
- * @dev Emits an event when receiving native tokens
111
+ * @notice Achieves the goal of {LSP17-ContractExtension} standard by extending the contract to
112
+ * handle calls of functions that do not exist natively, forwarding the function call to the
113
+ * extension address mapped to the function being called.
86
114
  *
87
- * Forwards the call to an extension contract (address). This address can be retrieved from
88
- * the ERC725Y data key-value store using the data key below (function selector appended to the prefix):
89
- *_LSP17_FALLBACK_EXTENSIONS_HANDLER_ + <function-selector>
90
- * If there is no extension stored under the data key, return.
115
+ * @dev This function:
116
+ * - Emits a {ValueReceived} event when receiving native tokens
91
117
  *
92
- * The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
93
- * Returns the return value on success and revert in case of failure.
118
+ * - Returns if the data sent to this function is of length less than 4 bytes (not a function selector)
94
119
  *
95
- * If the msg.data is shorter than 4 bytes do not check for an extension and return
120
+ * - If the data is equal or longer than 4 bytes, the ERC725Y storage is queried with the following data key:
121
+ * {_LSP17_EXTENSION_PREFIX + <bytes4 (msg.sig)>} (Check {LSP2-ERC725YJSONSchema} for encoding the data key)
122
+ *
123
+ * - If there is no address stored under the following data key, revert with {NoExtensionFoundForFunctionSelector(bytes4)}
124
+ * The data key relative to bytes4(0) is an exception, where no reverts occurs if there is no extension address stored under
125
+ *
126
+ * This exception is made to allow users to send random data (graffiti) to the account and to be able to react on it.
127
+ *
128
+ * - If there is an address, forward the {msg.data} to the extension using the CALL opcode,
129
+ * appending 52 bytes (20 bytes of {msg.sender} and 32 bytes of {msg.value}).
130
+ * Return what the calls returns, or revert if the call failed
96
131
  *
97
132
  * Executed when:
98
- * - the first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
99
- * - receiving native tokens with some calldata.
133
+ * - sending data of length less than 4 bytes to the contract.
134
+ * - the first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
135
+ * - receiving native tokens with some calldata.
100
136
  */
101
137
  fallback() external payable virtual {
102
- if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
103
- if (msg.data.length < 4) return;
138
+ if (msg.value != 0) {
139
+ emit ValueReceived(msg.sender, msg.value);
140
+ }
141
+
142
+ if (msg.data.length < 4) {
143
+ return;
144
+ }
104
145
 
105
146
  _fallbackLSP17Extendable();
106
147
  }
107
148
 
108
149
  /**
109
- * @dev Forwards the call to an extension mapped to a function selector. If no extension address
110
- * is mapped to the function selector (address(0)), then revert.
150
+ * @dev Allows a caller to batch different function calls in one call.
151
+ * Perform a delegatecall on self, to call different functions with preserving the context
152
+ * It is not possible to send value along the functions call due to the use of delegatecall.
111
153
  *
112
- * The bytes4(0) msg.sig is an exception, the function won't revert if there is no extension found
113
- * mapped to bytes4(0), but will execute the call to the extension in case it existed.
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
- * Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
119
- * called before other codes in fallback().
120
- *
121
- * Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
154
+ * @param data An array of ABI encoded function calls to be called on the contract.
155
+ * @return results An array of values returned by the executed functions.
122
156
  */
123
- function _fallbackLSP17Extendable() internal virtual override {
124
- // If there is a function selector
125
- address extension = _getExtension(msg.sig);
157
+ function batchCalls(bytes[] calldata data) public returns (bytes[] memory results) {
158
+ results = new bytes[](data.length);
159
+ for (uint256 i; i < data.length; ) {
160
+ (bool success, bytes memory result) = address(this).delegatecall(data[i]);
161
+
162
+ if (!success) {
163
+ // Look for revert reason and bubble it up if present
164
+ if (result.length > 0) {
165
+ // The easiest way to bubble the revert reason is using memory via assembly
166
+ // solhint-disable no-inline-assembly
167
+ /// @solidity memory-safe-assembly
168
+ assembly {
169
+ let returndata_size := mload(result)
170
+ revert(add(32, result), returndata_size)
171
+ }
172
+ } else {
173
+ revert("LSP0: batchCalls reverted");
174
+ }
175
+ }
126
176
 
127
- // if no extension was found for bytes4(0) return don't revert
128
- if (msg.sig == bytes4(0) && extension == address(0)) return;
177
+ results[i] = result;
129
178
 
130
- // if no extension was found, revert
131
- if (extension == address(0)) revert NoExtensionFoundForFunctionSelector(msg.sig);
179
+ unchecked {
180
+ ++i;
181
+ }
182
+ }
183
+ }
132
184
 
133
- // solhint-disable no-inline-assembly
134
- // if the extension was found, call the extension with the msg.data
135
- // appended with bytes20(address) and bytes32(msg.value)
136
- assembly {
137
- calldatacopy(0, 0, calldatasize())
185
+ /**
186
+ * @dev Executes any call on other addresses.
187
+ *
188
+ * @param operationType The operation to execute: CALL = 0 CREATE = 1 CREATE2 = 2 STATICCALL = 3 DELEGATECALL = 4
189
+ * @param target The address (smart contract/EOA) to interact with, `target` will be unused if a contract is created (operation 1 and 2)
190
+ * @param value The amount of native tokens to transfer (in Wei).
191
+ * @param data The call data to execute on `target`, or the bytecode of the contract to deploy
192
+ *
193
+ * Requirements:
194
+ *
195
+ * - if a `value` is provided, the contract MUST have at least this amount in its balance to execute successfully.
196
+ * - if the operation type is {STATICCALL} or {DELEGATECALL}, `value` SHOULD be 0.
197
+ * - `target` SHOULD be address(0) when deploying a contract.
198
+ * - MUST pass when called by the owner or by an authorised address that pass the verification check performed
199
+ * on the owner accordinng to LSP20 - CallVerification specification
200
+ *
201
+ * Emits a {Executed} event, when a call is executed under `operationType` 0, 3 and 4
202
+ * Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2
203
+ * Emits a {ValueReceived} event when receiving native tokens.
204
+ */
205
+ function execute(
206
+ uint256 operationType,
207
+ address target,
208
+ uint256 value,
209
+ bytes memory data
210
+ ) public payable virtual override returns (bytes memory) {
211
+ if (msg.value != 0) {
212
+ emit ValueReceived(msg.sender, msg.value);
213
+ }
138
214
 
139
- // The msg.sender address is shifted to the left by 12 bytes to remove the padding
140
- // Then the address without padding is stored right after the calldata
141
- mstore(calldatasize(), shl(96, caller()))
215
+ address _owner = owner();
142
216
 
143
- // The msg.value is stored right after the calldata + msg.sender
144
- mstore(add(calldatasize(), 20), callvalue())
217
+ // If the caller is the owner perform execute directly
218
+ if (msg.sender == _owner) {
219
+ return ERC725XCore._execute(operationType, target, value, data);
220
+ }
145
221
 
146
- // Add 52 bytes for the msg.sender and msg.value appended at the end of the calldata
147
- let success := call(gas(), extension, 0, 0, add(calldatasize(), 52), 0, 0)
222
+ // If the caller is not the owner, call {lsp20VerifyCall} on the owner
223
+ // Depending on the magicValue returned, a second call is done after execution
224
+ bool verifyAfter = LSP20CallVerification._verifyCall(_owner);
148
225
 
149
- // Copy the returned data
150
- returndatacopy(0, 0, returndatasize())
226
+ // Perform the execution
227
+ bytes memory result = ERC725XCore._execute(operationType, target, value, data);
151
228
 
152
- switch success
153
- // call returns 0 on failed calls
154
- case 0 {
155
- revert(0, returndatasize())
156
- }
157
- default {
158
- return(0, returndatasize())
159
- }
229
+ // if verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
230
+ if (verifyAfter) {
231
+ LSP20CallVerification._verifyCallResult(_owner, abi.encode(result));
160
232
  }
233
+
234
+ return result;
161
235
  }
162
236
 
163
237
  /**
164
- * @dev Returns the extension stored under the `_LSP17_EXTENSION_PREFIX` data key
165
- * mapped to the functionSelector provided.
238
+ * @dev Generic batch executor function that executes any call on other addresses
166
239
  *
167
- * If no extension is stored, returns the address(0)
240
+ * @param operationsType The list of operations type used: CALL = 0; CREATE = 1; CREATE2 = 2; STATICCALL = 3; DELEGATECALL = 4
241
+ * @param targets The list of addresses to call. `targets` will be unused if a contract is created (operation types 1 and 2).
242
+ * @param values The list of native token amounts to transfer (in Wei)
243
+ * @param datas The list of call data to execute on `targets`, or the creation bytecode of the contracts to deploy
244
+ *
245
+ * Requirements:
246
+ *
247
+ * - The length of the parameters provided MUST be equal
248
+ * - if a `value` is provided, the contract MUST have at least this amount in its balance to execute successfully.
249
+ * - if the operation type is {STATICCALL} or {DELEGATECALL}, `value` SHOULD be 0.
250
+ * - `target` SHOULD be address(0) when deploying a contract.
251
+ * - MUST pass when called by the owner or by an authorised address that pass the verification check performed
252
+ * on the owner accordinng to LSP20 - CallVerification specification
253
+ *
254
+ * Emits a {Executed} event, when a call is executed under `operationType` 0, 3 and 4 (each iteration)
255
+ * Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2 (each iteration)
256
+ * Emits a {ValueReceived} event when receiving native tokens.
168
257
  */
169
- function _getExtension(bytes4 functionSelector)
170
- internal
171
- view
172
- virtual
173
- override
174
- returns (address)
175
- {
176
- bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
177
- _LSP17_EXTENSION_PREFIX,
178
- functionSelector
179
- );
258
+ function executeBatch(
259
+ uint256[] memory operationsType,
260
+ address[] memory targets,
261
+ uint256[] memory values,
262
+ bytes[] memory datas
263
+ ) public payable virtual override returns (bytes[] memory) {
264
+ if (msg.value != 0) {
265
+ emit ValueReceived(msg.sender, msg.value);
266
+ }
180
267
 
181
- // Check if there is an extension for the function selector provided
182
- address extension = address(bytes20(_getData(mappedExtensionDataKey)));
268
+ address _owner = owner();
183
269
 
184
- return extension;
270
+ // If the caller is the owner perform execute directly
271
+ if (msg.sender == _owner) {
272
+ return ERC725XCore._executeBatch(operationsType, targets, values, datas);
273
+ }
274
+
275
+ // If the caller is not the owner, call {lsp20VerifyCall} on the owner
276
+ // Depending on the magicValue returned, a second call is done after execution
277
+ bool verifyAfter = LSP20CallVerification._verifyCall(_owner);
278
+
279
+ // Perform the execution
280
+ bytes[] memory results = ERC725XCore._executeBatch(operationsType, targets, values, datas);
281
+
282
+ // if verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
283
+ if (verifyAfter) {
284
+ LSP20CallVerification._verifyCallResult(_owner, abi.encode(results));
285
+ }
286
+
287
+ return results;
185
288
  }
186
289
 
187
290
  /**
188
- * @dev Returns true if this contract implements the interface defined by
189
- * `interfaceId`.
291
+ * @dev Sets singular data for a given `dataKey`
190
292
  *
191
- * If the contract doesn't support the `interfaceId`, it forwards the call to the
192
- * `supportsInterface` extension according to LSP17, and checks if the extension
193
- * implements the interface defined by `interfaceId`.
293
+ * @param dataKey The key to retrieve stored value
294
+ * @param dataValue The value to set
295
+ *
296
+ * Requirements:
297
+ *
298
+ * - MUST pass when called by the owner or by an authorised address that pass the verification check performed
299
+ * on the owner accordinng to LSP20 - CallVerification specification
300
+ *
301
+ * Emits a {ValueReceived} event when receiving native tokens.
302
+ * Emits a {DataChanged} event.
194
303
  */
195
- function supportsInterface(bytes4 interfaceId)
196
- public
197
- view
198
- virtual
199
- override(ERC725XCore, ERC725YCore, LSP17Extendable)
200
- returns (bool)
201
- {
202
- return
203
- interfaceId == _INTERFACEID_ERC1271 ||
204
- interfaceId == _INTERFACEID_LSP0 ||
205
- interfaceId == _INTERFACEID_LSP1 ||
206
- interfaceId == _INTERFACEID_LSP14 ||
207
- super.supportsInterface(interfaceId) ||
208
- _supportsInterfaceInERC165Extension(interfaceId);
304
+ function setData(bytes32 dataKey, bytes memory dataValue) public payable virtual override {
305
+ if (msg.value != 0) {
306
+ emit ValueReceived(msg.sender, msg.value);
307
+ }
308
+
309
+ address _owner = owner();
310
+
311
+ // If the caller is the owner perform setData directly
312
+ if (msg.sender == _owner) {
313
+ return _setData(dataKey, dataValue);
314
+ }
315
+
316
+ // If the caller is not the owner, call {lsp20VerifyCall} on the owner
317
+ // Depending on the magicValue returned, a second call is done after setting data
318
+ bool verifyAfter = _verifyCall(_owner);
319
+
320
+ _setData(dataKey, dataValue);
321
+
322
+ // If verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
323
+ // The setData function does not return, second parameter of {_verifyCallResult} will be empty
324
+ if (verifyAfter) {
325
+ _verifyCallResult(_owner, "");
326
+ }
209
327
  }
210
328
 
211
329
  /**
212
- * @notice Checks if an owner signed `_data`.
213
- * ERC1271 interface.
330
+ * @dev Sets array of data for multiple given `dataKeys`
331
+ *
332
+ * @param dataKeys The array of data keys for values to set
333
+ * @param dataValues The array of values to set
334
+ *
335
+ * Requirements:
214
336
  *
215
- * @param dataHash hash of the data signed//Arbitrary length data signed on the behalf of address(this)
216
- * @param signature owner's signature(s) of the data
337
+ * - MUST pass when called by the owner or by an authorised address that pass the verification check performed
338
+ * on the owner accordinng to LSP20 - CallVerification specification
339
+ *
340
+ * Emits a {ValueReceived} event when receiving native tokens.
341
+ * Emits a {DataChanged} event. (on each iteration of setting data)
217
342
  */
218
- function isValidSignature(bytes32 dataHash, bytes memory signature)
343
+ function setDataBatch(bytes32[] memory dataKeys, bytes[] memory dataValues)
219
344
  public
220
- view
345
+ payable
221
346
  virtual
222
- returns (bytes4 magicValue)
347
+ override
223
348
  {
349
+ if (msg.value != 0) {
350
+ emit ValueReceived(msg.sender, msg.value);
351
+ }
352
+
353
+ if (dataKeys.length != dataValues.length) {
354
+ revert ERC725Y_DataKeysValuesLengthMismatch();
355
+ }
356
+
224
357
  address _owner = owner();
225
358
 
226
- // If owner is a contract
227
- if (_owner.code.length > 0) {
228
- (bool success, bytes memory result) = _owner.staticcall(
229
- abi.encodeWithSelector(IERC1271.isValidSignature.selector, dataHash, signature)
230
- );
359
+ // If the caller is the owner perform setData directly
360
+ if (msg.sender == _owner) {
361
+ for (uint256 i = 0; i < dataKeys.length; ) {
362
+ _setData(dataKeys[i], dataValues[i]);
231
363
 
232
- bool isValid = (success &&
233
- result.length == 32 &&
234
- abi.decode(result, (bytes32)) == bytes32(_ERC1271_MAGICVALUE));
364
+ unchecked {
365
+ ++i;
366
+ }
367
+ }
235
368
 
236
- return isValid ? _ERC1271_MAGICVALUE : _ERC1271_FAILVALUE;
369
+ return;
237
370
  }
238
- // If owner is an EOA
239
- else {
240
- return
241
- _owner == ECDSA.recover(dataHash, signature)
242
- ? _ERC1271_MAGICVALUE
243
- : _ERC1271_FAILVALUE;
371
+
372
+ // If the caller is not the owner, call {lsp20VerifyCall} on the owner
373
+ // Depending on the magicValue returned, a second call is done after setting data
374
+ bool verifyAfter = _verifyCall(_owner);
375
+
376
+ for (uint256 i = 0; i < dataKeys.length; ) {
377
+ _setData(dataKeys[i], dataValues[i]);
378
+
379
+ unchecked {
380
+ ++i;
381
+ }
244
382
  }
245
- }
246
383
 
247
- /**
248
- * @param operationType The operation to execute: CALL = 0 CREATE = 1 CREATE2 = 2 STATICCALL = 3 DELEGATECALL = 4
249
- * @param target The smart contract or address to interact with, `to` will be unused if a contract is created (operation 1 and 2)
250
- * @param value The amount of native tokens to transfer (in Wei).
251
- * @param data The call data, or the bytecode of the contract to deploy
252
- * @dev Executes any other smart contract.
253
- * SHOULD only be callable by the owner of the contract set via ERC173
254
- *
255
- * Emits a {Executed} event, when a call is executed under `operationType` 0, 3 and 4
256
- * Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2
257
- * Emits a {ValueReceived} event, when receives native token
258
- */
259
- function execute(
260
- uint256 operationType,
261
- address target,
262
- uint256 value,
263
- bytes memory data
264
- ) public payable virtual override onlyOwner returns (bytes memory) {
265
- if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
266
- return _execute(operationType, target, value, data);
384
+ // If verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
385
+ // The setData function does not return, second parameter of {_verifyCallResult} will be empty
386
+ if (verifyAfter) {
387
+ _verifyCallResult(_owner, "");
388
+ }
267
389
  }
268
390
 
269
391
  /**
270
- * @inheritdoc ERC725XCore
392
+ * @notice Achieves the goal of LSP1-UniversalReceiver by allowing the account to be notified about incoming/outgoing
393
+ * transactions and enabling reactions to these actions.
271
394
  *
272
- * @dev Emits a {ValueReceived} event when receiving native tokens.
273
- */
274
- function execute(
275
- uint256[] memory operationsType,
276
- address[] memory targets,
277
- uint256[] memory values,
278
- bytes[] memory datas
279
- ) public payable virtual override onlyOwner returns (bytes[] memory) {
280
- if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
281
- return _execute(operationsType, targets, values, datas);
282
- }
283
-
284
- /**
285
- * @notice Triggers the UniversalReceiver event when this function gets executed successfully.
286
- * Forwards the call to the addresses stored in the ERC725Y storage under the LSP1UniversalReceiverDelegate
287
- * Key and the typeId Key (param) respectively. The call will be discarded if no addresses were set.
395
+ * The reaction is achieved by having two external contracts (UniversalReceiverDelegates) that react on the whole transaction
396
+ * and on the specific typeId, respectively.
397
+ *
398
+ * The notification is achieved by emitting a {UniversalReceiver} event on the call with the function parameters, call options, and the
399
+ * response of the UniversalReceiverDelegates (URD) contract.
400
+ *
401
+ * @dev The function performs the following steps:
402
+ *
403
+ * - Emits {ValueReceived} when receiving native tokens.
404
+ *
405
+ * - Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY}.
406
+ * - If there is an address stored under the data key, check if this address supports the LSP1 interfaceId.
407
+ *
408
+ * - If yes, call this address with the typeId and data (params), along with additional calldata consisting
409
+ * of 20 bytes of {msg.sender} and 32 bytes of {msg.value}. If not, continue the execution of the function.
410
+ *
411
+ *
412
+ * - Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY + <bytes32 typeId>}.
413
+ * (Check {LSP2-ERC725YJSONSchema} for encoding the data key)
414
+ *
415
+ * - If there is an address stored under the data key, check if this address supports the LSP1 interfaceId.
416
+ *
417
+ * - If yes, call this address with the typeId and data (params), along with additional calldata consisting
418
+ * of 20 bytes of {msg.sender} and 32 bytes of {msg.value}. If not, continue the execution of the function.
419
+ *
420
+ * - Emits a {UniversalReceiver} event.
288
421
  *
289
422
  * @param typeId The type of call received.
290
423
  * @param receivedData The data received.
424
+ *
291
425
  * @return returnedValues The ABI encoded return value of the LSP1UniversalReceiverDelegate call
292
426
  * and the LSP1TypeIdDelegate call.
293
427
  */
@@ -297,14 +431,20 @@ abstract contract LSP0ERC725AccountCore is
297
431
  virtual
298
432
  returns (bytes memory returnedValues)
299
433
  {
300
- if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
434
+ if (msg.value != 0) {
435
+ emit ValueReceived(msg.sender, msg.value);
436
+ }
437
+
438
+ // Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY}
301
439
  bytes memory lsp1DelegateValue = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
302
440
  bytes memory resultDefaultDelegate;
303
441
 
304
442
  if (lsp1DelegateValue.length >= 20) {
305
443
  address universalReceiverDelegate = address(bytes20(lsp1DelegateValue));
306
444
 
445
+ // Checking LSP1 InterfaceId support
307
446
  if (universalReceiverDelegate.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
447
+ // calling {universalReceiver} function on URD appending the caller and the value sent
308
448
  resultDefaultDelegate = universalReceiverDelegate
309
449
  .callUniversalReceiverWithCallerInfos(
310
450
  typeId,
@@ -315,18 +455,22 @@ abstract contract LSP0ERC725AccountCore is
315
455
  }
316
456
  }
317
457
 
458
+ // Generate the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY + <bytes32 typeId>}
318
459
  bytes32 lsp1typeIdDelegateKey = LSP2Utils.generateMappingKey(
319
460
  _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
320
461
  bytes20(typeId)
321
462
  );
322
463
 
464
+ // Query the ERC725Y storage with the data key {_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY + <bytes32 typeId>}
323
465
  bytes memory lsp1TypeIdDelegateValue = _getData(lsp1typeIdDelegateKey);
324
466
  bytes memory resultTypeIdDelegate;
325
467
 
326
468
  if (lsp1TypeIdDelegateValue.length >= 20) {
327
469
  address universalReceiverDelegate = address(bytes20(lsp1TypeIdDelegateValue));
328
470
 
471
+ // Checking LSP1 InterfaceId support
329
472
  if (universalReceiverDelegate.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
473
+ // calling {universalReceiver} function on URD appending the caller and the value sent
330
474
  resultTypeIdDelegate = universalReceiverDelegate
331
475
  .callUniversalReceiverWithCallerInfos(
332
476
  typeId,
@@ -342,90 +486,332 @@ abstract contract LSP0ERC725AccountCore is
342
486
  }
343
487
 
344
488
  /**
345
- * @dev Sets the pending owner and notifies the pending owner
489
+ * @notice Achieves the goal of LSP14Ownable2Step by implementing a 2-step ownership transfer process.
490
+ *
491
+ * @dev Sets the pending owner address as an address that should call {acceptOwnership} in order to complete
492
+ * the ownership transfer of the account.
493
+ *
494
+ * Notifies the pending owner via LSP1Standard by calling {universalReceiver} on the pending owner if it's
495
+ * an address that supports LSP1.
496
+ *
497
+ * @param _pendingOwner The address of the new pending owner.
346
498
  *
347
- * @param _newOwner The address nofied and set as `pendingOwner`
499
+ * Requirements:
500
+ *
501
+ * - MUST pass when called by the owner or by an authorized address that passes the verification check performed
502
+ * on the owner according to LSP20 - CallVerification specification.
503
+ *
504
+ * - When notifying the new owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferStarted').
505
+ *
506
+ * - pending owner cannot accept ownership in the same tx via the LSP1 hook.
348
507
  */
349
- function transferOwnership(address _newOwner)
508
+ function transferOwnership(address _pendingOwner)
350
509
  public
351
510
  virtual
352
511
  override(LSP14Ownable2Step, OwnableUnset)
353
- onlyOwner
354
512
  {
355
- LSP14Ownable2Step._transferOwnership(_newOwner);
513
+ address currentOwner = owner();
514
+
515
+ // If the caller is the owner perform transferOwnership directly
516
+ if (msg.sender == currentOwner) {
517
+ // set the pending owner
518
+ LSP14Ownable2Step._transferOwnership(_pendingOwner);
519
+ emit OwnershipTransferStarted(currentOwner, _pendingOwner);
520
+
521
+ // notify the pending owner through LSP1
522
+ _pendingOwner.tryNotifyUniversalReceiver(_TYPEID_LSP0_OwnershipTransferStarted, "");
523
+
524
+ // Require that the owner didn't change after the LSP1 Call
525
+ // (Pending owner didn't automate the acceptOwnership call through LSP1)
526
+ require(
527
+ currentOwner == owner(),
528
+ "LSP14: newOwner MUST accept ownership in a separate transaction"
529
+ );
530
+ } else {
531
+ // If the caller is not the owner, call {lsp20VerifyCall} on the owner
532
+ // Depending on the magicValue returned, a second call is done after transferring ownership
533
+ bool verifyAfter = _verifyCall(currentOwner);
534
+
535
+ // Set the pending owner if the call is allowed
536
+ LSP14Ownable2Step._transferOwnership(_pendingOwner);
537
+ emit OwnershipTransferStarted(currentOwner, _pendingOwner);
538
+
539
+ // notify the pending owner through LSP1
540
+ _pendingOwner.tryNotifyUniversalReceiver(_TYPEID_LSP0_OwnershipTransferStarted, "");
541
+
542
+ // Require that the owner didn't change after the LSP1 Call
543
+ // (Pending owner didn't automate the acceptOwnership call through LSP1)
544
+ require(
545
+ currentOwner == owner(),
546
+ "LSP14: newOwner MUST accept ownership in a separate transaction"
547
+ );
548
+
549
+ // If verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
550
+ // The transferOwnership function does not return, second parameter of {_verifyCallResult} will be empty
551
+ if (verifyAfter) {
552
+ _verifyCallResult(currentOwner, "");
553
+ }
554
+ }
356
555
  }
357
556
 
358
557
  /**
359
- * @dev Renounce ownership of the contract in a 2-step process
558
+ * @notice Achieves the goal of LSP14Ownable2Step by implementing a 2-step ownership transfer process.
559
+ *
560
+ * @dev Transfer ownership of the contract from the current `owner()` to the `pendingOwner()`.
561
+ *
562
+ * Once this function is called:
563
+ * - the current `owner()` will loose access to the functions restricted to the `owner()` only.
564
+ * - the `pendingOwner()` will gain access to the functions restricted to the `owner()` only.
565
+ *
566
+ * Requirements:
567
+ * - MUST be called by the pendingOwner.
568
+ * - When notifying the previous owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferred_SenderNotification').
569
+ * - When notifying the new owner via LSP1, the typeId used MUST be keccak256('LSP0OwnershipTransferred_RecipientNotification').
360
570
  */
361
- function renounceOwnership()
362
- public
363
- virtual
364
- override(LSP14Ownable2Step, OwnableUnset)
365
- onlyOwner
366
- {
367
- LSP14Ownable2Step._renounceOwnership();
571
+ function acceptOwnership() public virtual override {
572
+ address previousOwner = owner();
573
+
574
+ _acceptOwnership();
575
+
576
+ // notify the previous owner if supports LSP1
577
+ previousOwner.tryNotifyUniversalReceiver(
578
+ _TYPEID_LSP0_OwnershipTransferred_SenderNotification,
579
+ ""
580
+ );
581
+
582
+ // notify the pending owner if supports LSP1
583
+ msg.sender.tryNotifyUniversalReceiver(
584
+ _TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
585
+ ""
586
+ );
368
587
  }
369
588
 
370
589
  /**
371
- * @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
590
+ * @notice Achieves the goal of LSP14Ownable2Step by implementing a 2-step ownership renouncing process.
591
+ *
592
+ * @dev Renounce ownership of the contract in a 2-step process.
593
+ *
594
+ * 1. the first call will initiate the process of renouncing ownership.
595
+ * 2. the second is used as a confirmation and will leave the contract without an owner.
596
+ *
597
+ * MUST pass when called by the owner or by an authorised address that pass the verification check performed
598
+ * on the owner accordinng to LSP20 - CallVerification specification
599
+ *
600
+ * WARNING: once ownership of the contract has been renounced, any functions
601
+ * that are restricted to be called by the owner will be permanently inaccessible,
602
+ * making these functions not callable anymore and unusable.
372
603
  */
373
- function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
374
- _store[dataKey] = dataValue;
375
- emit DataChanged(
376
- dataKey,
377
- dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
378
- );
604
+ function renounceOwnership() public virtual override(LSP14Ownable2Step, OwnableUnset) {
605
+ address _owner = owner();
606
+
607
+ // If the caller is the owner perform renounceOwnership directly
608
+ if (msg.sender == _owner) {
609
+ return LSP14Ownable2Step._renounceOwnership();
610
+ }
611
+
612
+ // If the caller is not the owner, call {lsp20VerifyCall} on the owner
613
+ // Depending on the magicValue returned, a second call is done after transferring ownership
614
+ bool verifyAfter = _verifyCall(_owner);
615
+
616
+ // set the pending owner
617
+ LSP14Ownable2Step._renounceOwnership();
618
+
619
+ // If verifyAfter is true, Call {lsp20VerifyCallResult} on the owner
620
+ // The transferOwnership function does not return, second parameter of {_verifyCallResult} will be empty
621
+ if (verifyAfter) {
622
+ _verifyCallResult(_owner, "");
623
+ }
379
624
  }
380
625
 
381
- // --- LSP14 URD Hooks
626
+ /**
627
+ * @notice Achieves the goal of ERC165 to detect supported interfaces and LSP17 by
628
+ * checking if the interfaceId being queried is supported on another linked extension.
629
+ *
630
+ * @dev Returns true if this contract implements the interface defined by
631
+ * `interfaceId`.
632
+ *
633
+ * If the contract doesn't support the `interfaceId`, it forwards the call to the
634
+ * `supportsInterface` extension according to LSP17, and checks if the extension
635
+ * implements the interface defined by `interfaceId`.
636
+ */
637
+ function supportsInterface(bytes4 interfaceId)
638
+ public
639
+ view
640
+ virtual
641
+ override(ERC725XCore, ERC725YCore, LSP17Extendable)
642
+ returns (bool)
643
+ {
644
+ return
645
+ interfaceId == _INTERFACEID_ERC1271 ||
646
+ interfaceId == _INTERFACEID_LSP0 ||
647
+ interfaceId == _INTERFACEID_LSP1 ||
648
+ interfaceId == _INTERFACEID_LSP14 ||
649
+ interfaceId == _INTERFACEID_LSP20_CALL_VERIFICATION ||
650
+ super.supportsInterface(interfaceId) ||
651
+ LSP17Extendable._supportsInterfaceInERC165Extension(interfaceId);
652
+ }
382
653
 
383
654
  /**
384
- * @dev Calls the universalReceiver function of the sender when ownerhsip transfer starts
385
- * if supports LSP1 InterfaceId
655
+ * @notice Achieves the goal of EIP-1271 by validating signatures of smart contracts
656
+ * according to their own logic.
657
+ *
658
+ * @param dataHash The hash of the data to be validated.
659
+ * @param signature A signature that can validate the previous parameter (Hash).
660
+ *
661
+ * @dev Handles two cases:
662
+ *
663
+ * - If the owner is an EOA, recovers an address from the hash and the signature provided:
664
+ *
665
+ * - Returns the magicValue if the address recovered is the same as the owner, indicating
666
+ * that it was a valid signature.
667
+ *
668
+ * - If the address is different, it returns the fail value indicating that the signature is not valid.
669
+ *
670
+ * - If the owner is a smart contract, it forwards the call of {isValidSignature} to the owner contract:
671
+ *
672
+ * - If the contract fails or returns the fail value, the {isValidSignature} on the account returns the
673
+ * fail value, indicating that the signature is not valid.
674
+ *
675
+ * - If the {isValidSignature} on the owner returned the magicValue, the {isValidSignature} on the account
676
+ * returns the magicValue, indicating that it's a valid signature.
677
+ *
678
+ * @return magicValue A bytes4 value that indicates if the signature is valid or not.
386
679
  */
387
- function _notifyLSP1SenderOnOwnershipTransferStart(address notifiedContract, bytes memory data)
388
- internal
680
+ function isValidSignature(bytes32 dataHash, bytes memory signature)
681
+ public
682
+ view
389
683
  virtual
390
- override
684
+ returns (bytes4 magicValue)
391
685
  {
392
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
393
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
394
- _TYPEID_LSP0_OwnershipTransferStarted,
395
- data
686
+ address _owner = owner();
687
+
688
+ // If owner is a contract
689
+ if (_owner.code.length > 0) {
690
+ (bool success, bytes memory result) = _owner.staticcall(
691
+ abi.encodeWithSelector(IERC1271.isValidSignature.selector, dataHash, signature)
396
692
  );
693
+
694
+ bool isValid = (success &&
695
+ result.length == 32 &&
696
+ abi.decode(result, (bytes32)) == bytes32(_ERC1271_MAGICVALUE));
697
+
698
+ return isValid ? _ERC1271_MAGICVALUE : _ERC1271_FAILVALUE;
699
+ }
700
+ // If owner is an EOA
701
+ else {
702
+ // if isValidSignature fail, the error is catched in returnedError
703
+ (address recoveredAddress, ECDSA.RecoverError returnedError) = ECDSA.tryRecover(
704
+ dataHash,
705
+ signature
706
+ );
707
+
708
+ // if recovering throws an error, return the fail value
709
+ if (returnedError != ECDSA.RecoverError.NoError) return _ERC1271_FAILVALUE;
710
+
711
+ // if recovering is successful and the recovered address matches the owner's address,
712
+ // return the ERC1271 magic value. Otherwise, return the ERC1271 fail value
713
+ // matches the address of the owner, otherwise return fail value
714
+ return recoveredAddress == _owner ? _ERC1271_MAGICVALUE : _ERC1271_FAILVALUE;
397
715
  }
398
716
  }
399
717
 
718
+ // Internal functions
719
+
400
720
  /**
401
- * @dev Calls the universalReceiver function of the sender when ownerhsip transfer is complete
402
- * if supports LSP1 InterfaceId
721
+ * @dev Forwards the call to an extension mapped to a function selector.
722
+ *
723
+ * Calls {_getExtension} to get the address of the extension mapped to the function selector being
724
+ * called on the account. If there is no extension, the address(0) will be returned.
725
+ *
726
+ * Reverts if there is no extension for the function being called, except for the bytes4(0) function
727
+ * selector, which passes even if there is no extension for it.
728
+ *
729
+ * If there is an extension for the function selector being called, it calls the extension with the
730
+ * CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
731
+ * 32 bytes of the {msg.value}
732
+ *
733
+ * Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
734
+ * called before other codes in fallback().
735
+ *
736
+ * Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
403
737
  */
404
- function _notifyLSP1SenderOnOwnershipTransferCompletion(
405
- address notifiedContract,
406
- bytes memory data
407
- ) internal virtual override {
408
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
409
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
410
- _TYPEID_LSP0_OwnershipTransferred_SenderNotification,
411
- data
412
- );
738
+ function _fallbackLSP17Extendable() internal virtual override {
739
+ // If there is a function selector
740
+ address extension = _getExtension(msg.sig);
741
+
742
+ // if no extension was found for bytes4(0) return don't revert
743
+ if (msg.sig == bytes4(0) && extension == address(0)) return;
744
+
745
+ // if no extension was found for other function selectors, revert
746
+ if (extension == address(0)) revert NoExtensionFoundForFunctionSelector(msg.sig);
747
+
748
+ // solhint-disable no-inline-assembly
749
+ // if the extension was found, call the extension with the msg.data
750
+ // appended with bytes20(address) and bytes32(msg.value)
751
+ assembly {
752
+ calldatacopy(0, 0, calldatasize())
753
+
754
+ // The msg.sender address is shifted to the left by 12 bytes to remove the padding
755
+ // Then the address without padding is stored right after the calldata
756
+ mstore(calldatasize(), shl(96, caller()))
757
+
758
+ // The msg.value is stored right after the calldata + msg.sender
759
+ mstore(add(calldatasize(), 20), callvalue())
760
+
761
+ // Add 52 bytes for the msg.sender and msg.value appended at the end of the calldata
762
+ let success := call(gas(), extension, 0, 0, add(calldatasize(), 52), 0, 0)
763
+
764
+ // Copy the returned data
765
+ returndatacopy(0, 0, returndatasize())
766
+
767
+ switch success
768
+ // call returns 0 on failed calls
769
+ case 0 {
770
+ revert(0, returndatasize())
771
+ }
772
+ default {
773
+ return(0, returndatasize())
774
+ }
413
775
  }
414
776
  }
415
777
 
416
778
  /**
417
- * @dev Calls the universalReceiver function of the recipient when ownerhsip transfer is complete
418
- * if supports LSP1 InterfaceId
779
+ * @dev Returns the extension address stored under the following data key:
780
+ * {_LSP17_EXTENSION_PREFIX + <bytes4>} (Check {LSP2-ERC725YJSONSchema} for encoding the data key)
781
+ *
782
+ * If no extension is stored, returns the address(0)
419
783
  */
420
- function _notifyLSP1RecipientOnOwnershipTransferCompletion(
421
- address notifiedContract,
422
- bytes memory data
423
- ) internal virtual override {
424
- if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
425
- ILSP1UniversalReceiver(notifiedContract).universalReceiver(
426
- _TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
427
- data
428
- );
429
- }
784
+ function _getExtension(bytes4 functionSelector)
785
+ internal
786
+ view
787
+ virtual
788
+ override
789
+ returns (address)
790
+ {
791
+ // Generate the data key relevant for the functionSelector being called
792
+ bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
793
+ _LSP17_EXTENSION_PREFIX,
794
+ functionSelector
795
+ );
796
+
797
+ // Check if there is an extension stored under the generated data key
798
+ address extension = address(bytes20(ERC725YCore._getData(mappedExtensionDataKey)));
799
+
800
+ return extension;
801
+ }
802
+
803
+ /**
804
+ * @dev This function overrides the {ERC725YCore} internal {_setData} function to optimize gas usage by
805
+ * emitting the {DataChanged} event with only the first 256 bytes of {dataValue}.
806
+ *
807
+ * @param dataKey The key to store the data value under.
808
+ * @param dataValue The data value to be stored.
809
+ */
810
+ function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
811
+ ERC725YCore._store[dataKey] = dataValue;
812
+ emit DataChanged(
813
+ dataKey,
814
+ dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
815
+ );
430
816
  }
431
817
  }