@lukso/lsp-smart-contracts 0.6.2 → 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 (175) hide show
  1. package/CONTRIBUTING.md +31 -0
  2. package/README.md +73 -28
  3. package/artifacts/Create2Factory.json +2 -2
  4. package/artifacts/LSP0ERC725Account.json +227 -15
  5. package/artifacts/LSP0ERC725AccountInit.json +227 -41
  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 +22 -0
  12. package/artifacts/LSP4DigitalAssetMetadata.json +22 -0
  13. package/artifacts/{LSP4DigitalAssetMetadataInit.json → LSP4DigitalAssetMetadataInitAbstract.json} +24 -51
  14. package/artifacts/LSP6KeyManager.json +188 -33
  15. package/artifacts/LSP6KeyManagerInit.json +188 -33
  16. package/artifacts/LSP7CappedSupply.json +58 -31
  17. package/artifacts/{LSP7CappedSupplyInit.json → LSP7CappedSupplyInitAbstract.json} +60 -72
  18. package/artifacts/LSP7CompatibleERC20.json +52 -46
  19. package/artifacts/LSP7CompatibleERC20InitAbstract.json +733 -0
  20. package/artifacts/LSP7CompatibleERC20Mintable.json +61 -34
  21. package/artifacts/LSP7CompatibleERC20MintableInit.json +66 -60
  22. package/artifacts/LSP7DigitalAsset.json +52 -51
  23. package/artifacts/LSP7DigitalAssetInitAbstract.json +556 -0
  24. package/artifacts/LSP7Mintable.json +62 -35
  25. package/artifacts/LSP7MintableInit.json +62 -61
  26. package/artifacts/LSP8CappedSupply.json +64 -5
  27. package/artifacts/LSP8CappedSupplyInitAbstract.json +667 -0
  28. package/artifacts/LSP8CompatibleERC721.json +102 -21
  29. package/artifacts/LSP8CompatibleERC721InitAbstract.json +936 -0
  30. package/artifacts/LSP8CompatibleERC721Mintable.json +111 -9
  31. package/artifacts/LSP8CompatibleERC721MintableInit.json +116 -35
  32. package/artifacts/LSP8IdentifiableDigitalAsset.json +58 -20
  33. package/artifacts/{LSP8CappedSupplyInit.json → LSP8IdentifiableDigitalAssetInitAbstract.json} +62 -65
  34. package/artifacts/LSP8Mintable.json +67 -8
  35. package/artifacts/LSP8MintableInit.json +67 -34
  36. package/artifacts/LSP9Vault.json +235 -17
  37. package/artifacts/LSP9VaultInit.json +235 -43
  38. package/artifacts/UniversalProfile.json +227 -15
  39. package/artifacts/UniversalProfileInit.json +227 -41
  40. package/artifacts/UniversalReceiverAddressStore.json +3 -3
  41. package/constants.js +416 -95
  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 +274 -74
  47. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +2 -2
  48. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +3 -2
  49. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +4 -4
  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 +156 -42
  72. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +64 -31
  73. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +54 -41
  74. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +136 -28
  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 +16 -7
  80. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +16 -7
  81. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +3 -3
  82. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +4 -4
  83. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +103 -115
  84. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +26 -8
  85. package/contracts/LSP6KeyManager/LSP6Constants.sol +45 -45
  86. package/contracts/LSP6KeyManager/LSP6Errors.sol +97 -20
  87. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -2
  88. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +786 -359
  89. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +2 -2
  90. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +4 -3
  91. package/contracts/LSP6KeyManager/LSP6Utils.sol +127 -35
  92. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +26 -13
  93. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +6 -6
  94. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +5 -5
  95. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +65 -52
  96. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +3 -3
  97. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +30 -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 +9 -2
  107. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +3 -3
  108. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +12 -12
  109. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +5 -5
  110. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +11 -10
  111. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +10 -8
  112. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +11 -11
  113. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +45 -1
  114. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +3 -3
  115. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +75 -71
  116. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +1 -1
  117. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +20 -3
  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 +49 -0
  124. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +51 -0
  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 +9 -2
  128. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +3 -3
  129. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +9 -8
  130. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +2 -2
  131. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +8 -7
  132. package/contracts/LSP9Vault/LSP9Constants.sol +11 -8
  133. package/contracts/LSP9Vault/LSP9Errors.sol +8 -0
  134. package/contracts/LSP9Vault/LSP9Vault.sol +6 -4
  135. package/contracts/LSP9Vault/LSP9VaultCore.sol +324 -90
  136. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -2
  137. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +5 -4
  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 -13
  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 +17 -0
  145. package/package.json +37 -32
  146. package/artifacts/LSP7CompatibleERC20Init.json +0 -760
  147. package/artifacts/LSP7DigitalAssetInit.json +0 -588
  148. package/artifacts/LSP8CompatibleERC721Init.json +0 -883
  149. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +0 -639
  150. package/artifacts/UniversalFactory.json +0 -127
  151. package/contracts/Custom/ClaimOwnership.sol +0 -34
  152. package/contracts/Custom/ERC165Checker.sol +0 -130
  153. package/contracts/Custom/IClaimOwnership.sol +0 -10
  154. package/contracts/Factories/UniversalFactory.sol +0 -164
  155. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +0 -24
  156. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +0 -85
  157. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +0 -76
  158. package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +0 -9
  159. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +0 -26
  160. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +0 -39
  161. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +0 -17
  162. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +0 -57
  163. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +0 -19
  164. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +0 -112
  165. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +0 -29
  166. package/contracts/LSP7DigitalAsset/presets/LSP7MintableCore.sol +0 -26
  167. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +0 -35
  168. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +0 -17
  169. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +0 -58
  170. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +0 -19
  171. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleConstants.sol +0 -6
  172. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +0 -187
  173. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Init.sol +0 -25
  174. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableCore.sol +0 -26
  175. package/contracts/Utils/UtilsLib.sol +0 -31
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.5;
3
+
4
+ library EIP191Signer {
5
+ function toDataWithIntendedValidator(address validator, bytes memory dataToSign)
6
+ internal
7
+ pure
8
+ returns (bytes32)
9
+ {
10
+ return keccak256(abi.encodePacked("\x19\x00", validator, dataToSign));
11
+ }
12
+ }
@@ -1,7 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
- /* solhint-disable */
5
4
  // DO NOT TOUCH
6
5
  // --------------------
7
6
  // bytecode
@@ -14,7 +13,6 @@ pragma solidity ^0.8.0;
14
13
  // cost 0.0801
15
14
  // RAW Tx:
16
15
  // 0xf9059380852e90edd0008306f2cc8080b90540608060405234801561001057600080fd5b50610520806100206000396000f3fe6080604052600436106100345760003560e01c8063481286e61461003957806378065306146100be578063cdcb760a14610163575b600080fd5b34801561004557600080fd5b5061007c6004803603604081101561005c57600080fd5b810190808035906020019092919080359060200190929190505050610268565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b3480156100ca57600080fd5b50610121600480360360608110156100e157600080fd5b810190808035906020019092919080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061027d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102266004803603604081101561017957600080fd5b8101908080359060200190929190803590602001906401000000008111156101a057600080fd5b8201836020820111156101b257600080fd5b803590602001918460018302840111640100000000831117156101d457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610346565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600061027583833061027d565b905092915050565b60008060ff60f81b83868660405160200180857effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191681526001018473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1660601b81526014018381526020018281526020019450505050506040516020818303038152906040528051906020012090508060001c9150509392505050565b60008060003490506000845114156103c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260208152602001807f437265617465323a2062797465636f6465206c656e677468206973207a65726f81525060200191505060405180910390fd5b8484516020860183f59150600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415610474576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260198152602001807f437265617465323a204661696c6564206f6e206465706c6f790000000000000081525060200191505060405180910390fd5b7fc16bb3dbd36917c7aa3e76b988c2cd35e74bb230a02fef61e7376d8b4bfaea778286604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390a181925050509291505056fea26469706673582212208e45d684157bfc10076a3d284f8c3899cd5ecf31abade0a086223e0886a8a68164736f6c634300060100331ba01234123412341234123412341234123412341234123412341234123412341234a01234123412341234123412341234123412341234123412341234123412341234
17
- /* solhint-enable */
18
16
 
19
17
  /**
20
18
  * @title contract to deploy contracts with precomputed addresses, using create2 opcode
@@ -1,10 +1,21 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
4
  // --- ERC165 interface ids
5
- bytes4 constant _INTERFACEID_LSP0 = 0x9a3bfe88;
5
+ bytes4 constant _INTERFACEID_LSP0 = 0x66767497;
6
6
  bytes4 constant _INTERFACEID_ERC1271 = 0x1626ba7e;
7
7
 
8
8
  // ERC1271 - Standard Signature Validation
9
9
  bytes4 constant _ERC1271_MAGICVALUE = 0x1626ba7e;
10
10
  bytes4 constant _ERC1271_FAILVALUE = 0xffffffff;
11
+
12
+ // Ownerhsip Transfer Type IDs
13
+
14
+ // keccak256('LSP0OwnershipTransferStarted')
15
+ bytes32 constant _TYPEID_LSP0_OwnershipTransferStarted = 0xe17117c9d2665d1dbeb479ed8058bbebde3c50ac50e2e65619f60006caac6926;
16
+
17
+ // keccak256('LSP0OwnershipTransferred_SenderNotification')
18
+ bytes32 constant _TYPEID_LSP0_OwnershipTransferred_SenderNotification = 0xa4e59c931d14f7c8a7a35027f92ee40b5f2886b9fdcdb78f30bc5ecce5a2f814;
19
+
20
+ // keccak256('LSP0OwnershipTransferred_RecipientNotification')
21
+ bytes32 constant _TYPEID_LSP0_OwnershipTransferred_RecipientNotification = 0xceca317f109c43507871523e82dc2a3cc64dfa18f12da0b6db14f6e23f995538;
@@ -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 {LSP0ERC725AccountCore} from "./LSP0ERC725AccountCore.sol";
@@ -16,6 +16,7 @@ contract LSP0ERC725Account is LSP0ERC725AccountCore {
16
16
  * @param newOwner the owner of the contract
17
17
  */
18
18
  constructor(address newOwner) payable {
19
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
19
20
  OwnableUnset._setOwner(newOwner);
20
21
  }
21
22
  }
@@ -1,35 +1,45 @@
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 {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
6
  import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
- import {
8
- ILSP1UniversalReceiverDelegate
9
- } from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
10
7
 
11
8
  // libraries
9
+ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
12
10
  import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
13
- import {ERC165Checker} from "../Custom/ERC165Checker.sol";
11
+ import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
12
+ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
13
+ import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
14
+ import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
14
15
 
15
16
  // modules
16
17
  import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
17
18
  import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.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
24
+ import "@erc725/smart-contracts/contracts/constants.sol";
25
+ import "@erc725/smart-contracts/contracts/errors.sol";
22
26
  import {
23
27
  _INTERFACEID_LSP0,
24
28
  _INTERFACEID_ERC1271,
25
- _ERC1271_FAILVALUE
29
+ _ERC1271_MAGICVALUE,
30
+ _ERC1271_FAILVALUE,
31
+ _TYPEID_LSP0_OwnershipTransferStarted,
32
+ _TYPEID_LSP0_OwnershipTransferred_SenderNotification,
33
+ _TYPEID_LSP0_OwnershipTransferred_RecipientNotification
26
34
  } from "../LSP0ERC725Account/LSP0Constants.sol";
27
35
  import {
28
36
  _INTERFACEID_LSP1,
29
- _INTERFACEID_LSP1_DELEGATE,
37
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
30
38
  _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
31
39
  } from "../LSP1UniversalReceiver/LSP1Constants.sol";
32
- import {_INTERFACEID_CLAIM_OWNERSHIP} from "../Custom/IClaimOwnership.sol";
40
+ import {_INTERFACEID_LSP14} from "../LSP14Ownable2Step/LSP14Constants.sol";
41
+
42
+ import {_LSP17_EXTENSION_PREFIX} from "../LSP17ContractExtension/LSP17Constants.sol";
33
43
 
34
44
  /**
35
45
  * @title Core Implementation of ERC725Account
@@ -39,75 +49,106 @@ import {_INTERFACEID_CLAIM_OWNERSHIP} from "../Custom/IClaimOwnership.sol";
39
49
  abstract contract LSP0ERC725AccountCore is
40
50
  ERC725XCore,
41
51
  ERC725YCore,
42
- ClaimOwnership,
52
+ LSP14Ownable2Step,
53
+ LSP17Extendable,
43
54
  IERC1271,
44
55
  ILSP1UniversalReceiver
45
56
  {
57
+ using ERC165Checker for address;
58
+ using LSP1Utils for address;
59
+ using Address for address;
60
+
46
61
  /**
47
62
  * @notice Emitted when receiving native tokens
48
63
  * @param sender The address of the sender
49
- * @param value The amount of value sent
64
+ * @param value The amount of native tokens received
50
65
  */
51
66
  event ValueReceived(address indexed sender, uint256 indexed value);
52
67
 
53
68
  /**
54
69
  * @dev Emits an event when receiving native tokens
70
+ *
71
+ * Executed when receiving native tokens with empty calldata.
55
72
  */
56
- fallback() external payable virtual {
57
- if (msg.value > 0) emit ValueReceived(msg.sender, msg.value);
73
+ receive() external payable virtual {
74
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
58
75
  }
59
76
 
60
- // TODO to be discussed
61
- // function fallback()
62
- // public
63
- // {
64
- // address to = owner();
65
- // assembly {
66
- // calldatacopy(0, 0, calldatasize())
67
- // let result := staticcall(gas(), to, 0, calldatasize(), 0, 0)
68
- // returndatacopy(0, 0, returndatasize())
69
- // switch result
70
- // case 0 { revert (0, returndatasize()) }
71
- // default { return (0, returndatasize()) }
72
- // }
73
- // }
74
-
75
- // ERC165
76
-
77
77
  /**
78
- * @dev See {IERC165-supportsInterface}.
78
+ * @dev Returns the extension stored under the `_LSP17_EXTENSION_PREFIX` data key
79
+ * mapped to the functionSelector provided.
80
+ *
81
+ * If no extension is stored, returns the address(0)
79
82
  */
80
- function supportsInterface(bytes4 interfaceId)
81
- public
83
+ function _getExtension(bytes4 functionSelector)
84
+ internal
82
85
  view
83
86
  virtual
84
- override(ERC725XCore, ERC725YCore)
85
- returns (bool)
87
+ override
88
+ returns (address)
86
89
  {
87
- return
88
- interfaceId == _INTERFACEID_ERC1271 ||
89
- interfaceId == _INTERFACEID_LSP0 ||
90
- interfaceId == _INTERFACEID_LSP1 ||
91
- interfaceId == _INTERFACEID_CLAIM_OWNERSHIP ||
92
- super.supportsInterface(interfaceId);
90
+ bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
91
+ _LSP17_EXTENSION_PREFIX,
92
+ functionSelector
93
+ );
94
+
95
+ // Check if there is an extension for the function selector provided
96
+ address extension = address(bytes20(_getData(mappedExtensionDataKey)));
97
+
98
+ return extension;
93
99
  }
94
100
 
95
- // ERC173 - Modified ClaimOwnership
101
+ // solhint-disable no-complex-fallback
96
102
 
97
103
  /**
98
- * @dev Sets the pending owner
104
+ * @dev Emits an event when receiving native tokens
105
+ *
106
+ * Forwards the call to an extension contract (address). This address can be retrieved from
107
+ * the ERC725Y data key-value store using the data key below (function selector appended to the prefix):
108
+ *_LSP17_FALLBACK_EXTENSIONS_HANDLER_ + <function-selector>
109
+ * If there is no extension stored under the data key, return.
110
+ *
111
+ * The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
112
+ * Returns the return value on success and revert in case of failure.
113
+ *
114
+ * If the msg.data is shorter than 4 bytes or the first 4 bytes are 0s
115
+ * do not check for an extension and return
116
+ *
117
+ * Executed when:
118
+ * - the first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
119
+ * - receiving native tokens with some calldata.
99
120
  */
100
- function transferOwnership(address _newOwner)
121
+ fallback() external payable virtual {
122
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
123
+ if (msg.data.length < 4 || msg.sig == bytes4(0)) return;
124
+
125
+ _fallbackLSP17Extendable();
126
+ }
127
+
128
+ /**
129
+ * @dev Returns true if this contract implements the interface defined by
130
+ * `interfaceId`.
131
+ *
132
+ * If the contract doesn't support the `interfaceId`, it forwards the call to the
133
+ * `supportsInterface` extension according to LSP17, and checks if the extension
134
+ * implements the interface defined by `interfaceId`.
135
+ */
136
+ function supportsInterface(bytes4 interfaceId)
101
137
  public
138
+ view
102
139
  virtual
103
- override(ClaimOwnership, OwnableUnset)
104
- onlyOwner
140
+ override(ERC725XCore, ERC725YCore, LSP17Extendable)
141
+ returns (bool)
105
142
  {
106
- ClaimOwnership._transferOwnership(_newOwner);
143
+ return
144
+ interfaceId == _INTERFACEID_ERC1271 ||
145
+ interfaceId == _INTERFACEID_LSP0 ||
146
+ interfaceId == _INTERFACEID_LSP1 ||
147
+ interfaceId == _INTERFACEID_LSP14 ||
148
+ super.supportsInterface(interfaceId) ||
149
+ _supportsInterfaceInERC165Extension(interfaceId);
107
150
  }
108
151
 
109
- // ERC1271
110
-
111
152
  /**
112
153
  * @notice Checks if an owner signed `_data`.
113
154
  * ERC1271 interface.
@@ -118,55 +159,214 @@ abstract contract LSP0ERC725AccountCore is
118
159
  function isValidSignature(bytes32 dataHash, bytes memory signature)
119
160
  public
120
161
  view
121
- override
162
+ virtual
122
163
  returns (bytes4 magicValue)
123
164
  {
124
165
  address _owner = owner();
125
- // if OWNER is a contract
126
- if (_owner.code.length != 0) {
127
- return
128
- ERC165Checker.supportsERC165Interface(_owner, _INTERFACEID_ERC1271)
129
- ? IERC1271(_owner).isValidSignature(dataHash, signature)
130
- : _ERC1271_FAILVALUE;
131
- // if OWNER is a key
132
- } else {
166
+
167
+ // If owner is a contract
168
+ if (_owner.code.length > 0) {
169
+ (bool success, bytes memory result) = _owner.staticcall(
170
+ abi.encodeWithSelector(IERC1271.isValidSignature.selector, dataHash, signature)
171
+ );
172
+
173
+ bool isValid = (success &&
174
+ result.length == 32 &&
175
+ abi.decode(result, (bytes32)) == bytes32(_ERC1271_MAGICVALUE));
176
+
177
+ return isValid ? _ERC1271_MAGICVALUE : _ERC1271_FAILVALUE;
178
+ }
179
+ // If owner is an EOA
180
+ else {
133
181
  return
134
182
  _owner == ECDSA.recover(dataHash, signature)
135
- ? _INTERFACEID_ERC1271
183
+ ? _ERC1271_MAGICVALUE
136
184
  : _ERC1271_FAILVALUE;
137
185
  }
138
186
  }
139
187
 
140
- // LSP1
188
+ /**
189
+ * @param operationType The operation to execute: CALL = 0 CREATE = 1 CREATE2 = 2 STATICCALL = 3 DELEGATECALL = 4
190
+ * @param target The smart contract or address to interact with, `to` will be unused if a contract is created (operation 1 and 2)
191
+ * @param value The amount of native tokens to transfer (in Wei).
192
+ * @param data The call data, or the bytecode of the contract to deploy
193
+ * @dev Executes any other smart contract.
194
+ * SHOULD only be callable by the owner of the contract set via ERC173
195
+ *
196
+ * Emits a {Executed} event, when a call is executed under `operationType` 0, 3 and 4
197
+ * Emits a {ContractCreated} event, when a contract is created under `operationType` 1 and 2
198
+ * Emits a {ValueReceived} event, when receives native token
199
+ */
200
+ function execute(
201
+ uint256 operationType,
202
+ address target,
203
+ uint256 value,
204
+ bytes memory data
205
+ ) public payable virtual override onlyOwner returns (bytes memory) {
206
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
207
+ return _execute(operationType, target, value, data);
208
+ }
209
+
210
+ /**
211
+ * @inheritdoc ERC725XCore
212
+ *
213
+ * @dev Emits a {ValueReceived} event when receiving native tokens.
214
+ */
215
+ function execute(
216
+ uint256[] memory operationsType,
217
+ address[] memory targets,
218
+ uint256[] memory values,
219
+ bytes[] memory datas
220
+ ) public payable virtual override onlyOwner returns (bytes[] memory) {
221
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
222
+ return _execute(operationsType, targets, values, datas);
223
+ }
141
224
 
142
225
  /**
143
226
  * @notice Triggers the UniversalReceiver event when this function gets executed successfully.
144
- * @dev Forwards the call to the UniversalReceiverDelegate if set.
227
+ * Forwards the call to the addresses stored in the ERC725Y storage under the LSP1UniversalReceiverDelegate
228
+ * Key and the typeId Key (param) respectively. The call will be discarded if no addresses were set.
229
+ *
145
230
  * @param typeId The type of call received.
146
- * @param data The data received.
231
+ * @param receivedData The data received.
232
+ * @return returnedValues The ABI encoded return value of the LSP1UniversalReceiverDelegate call
233
+ * and the LSP1TypeIdDelegate call.
147
234
  */
148
- function universalReceiver(bytes32 typeId, bytes calldata data)
235
+ function universalReceiver(bytes32 typeId, bytes calldata receivedData)
149
236
  public
150
237
  payable
151
238
  virtual
152
- override
153
- returns (bytes memory returnValue)
239
+ returns (bytes memory returnedValues)
154
240
  {
241
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
155
242
  bytes memory lsp1DelegateValue = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
243
+ bytes memory resultDefaultDelegate;
156
244
 
157
245
  if (lsp1DelegateValue.length >= 20) {
158
246
  address universalReceiverDelegate = address(bytes20(lsp1DelegateValue));
159
247
 
160
- if (
161
- ERC165Checker.supportsERC165Interface(
162
- universalReceiverDelegate,
163
- _INTERFACEID_LSP1_DELEGATE
164
- )
165
- ) {
166
- returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
167
- .universalReceiverDelegate(msg.sender, msg.value, typeId, data);
248
+ if (universalReceiverDelegate.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
249
+ resultDefaultDelegate = universalReceiverDelegate
250
+ .callUniversalReceiverWithCallerInfos(
251
+ typeId,
252
+ receivedData,
253
+ msg.sender,
254
+ msg.value
255
+ );
256
+ }
257
+ }
258
+
259
+ bytes32 lsp1typeIdDelegateKey = LSP2Utils.generateMappingKey(
260
+ _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
261
+ bytes20(typeId)
262
+ );
263
+
264
+ bytes memory lsp1TypeIdDelegateValue = _getData(lsp1typeIdDelegateKey);
265
+ bytes memory resultTypeIdDelegate;
266
+
267
+ if (lsp1TypeIdDelegateValue.length >= 20) {
268
+ address universalReceiverDelegate = address(bytes20(lsp1TypeIdDelegateValue));
269
+
270
+ if (universalReceiverDelegate.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
271
+ resultTypeIdDelegate = universalReceiverDelegate
272
+ .callUniversalReceiverWithCallerInfos(
273
+ typeId,
274
+ receivedData,
275
+ msg.sender,
276
+ msg.value
277
+ );
168
278
  }
169
279
  }
170
- emit UniversalReceiver(msg.sender, msg.value, typeId, returnValue, data);
280
+
281
+ returnedValues = abi.encode(resultDefaultDelegate, resultTypeIdDelegate);
282
+ emit UniversalReceiver(msg.sender, msg.value, typeId, receivedData, returnedValues);
283
+ }
284
+
285
+ /**
286
+ * @dev Sets the pending owner and notifies the pending owner
287
+ *
288
+ * @param _newOwner The address nofied and set as `pendingOwner`
289
+ */
290
+ function transferOwnership(address _newOwner)
291
+ public
292
+ virtual
293
+ override(LSP14Ownable2Step, OwnableUnset)
294
+ onlyOwner
295
+ {
296
+ LSP14Ownable2Step._transferOwnership(_newOwner);
297
+ }
298
+
299
+ /**
300
+ * @dev Renounce ownership of the contract in a 2-step process
301
+ */
302
+ function renounceOwnership()
303
+ public
304
+ virtual
305
+ override(LSP14Ownable2Step, OwnableUnset)
306
+ onlyOwner
307
+ {
308
+ LSP14Ownable2Step._renounceOwnership();
309
+ }
310
+
311
+ /**
312
+ * @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
313
+ */
314
+ function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
315
+ _store[dataKey] = dataValue;
316
+ emit DataChanged(
317
+ dataKey,
318
+ dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
319
+ );
320
+ }
321
+
322
+ // --- LSP14 URD Hooks
323
+
324
+ /**
325
+ * @dev Calls the universalReceiver function of the sender when ownerhsip transfer starts
326
+ * if supports LSP1 InterfaceId
327
+ */
328
+ function _notifyLSP1SenderOnOwnershipTransferStart(address notifiedContract, bytes memory data)
329
+ internal
330
+ virtual
331
+ override
332
+ {
333
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
334
+ ILSP1UniversalReceiver(notifiedContract).universalReceiver(
335
+ _TYPEID_LSP0_OwnershipTransferStarted,
336
+ data
337
+ );
338
+ }
339
+ }
340
+
341
+ /**
342
+ * @dev Calls the universalReceiver function of the sender when ownerhsip transfer is complete
343
+ * if supports LSP1 InterfaceId
344
+ */
345
+ function _notifyLSP1SenderOnOwnershipTransferCompletion(
346
+ address notifiedContract,
347
+ bytes memory data
348
+ ) internal virtual override {
349
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
350
+ ILSP1UniversalReceiver(notifiedContract).universalReceiver(
351
+ _TYPEID_LSP0_OwnershipTransferred_SenderNotification,
352
+ data
353
+ );
354
+ }
355
+ }
356
+
357
+ /**
358
+ * @dev Calls the universalReceiver function of the recipient when ownerhsip transfer is complete
359
+ * if supports LSP1 InterfaceId
360
+ */
361
+ function _notifyLSP1RecipientOnOwnershipTransferCompletion(
362
+ address notifiedContract,
363
+ bytes memory data
364
+ ) internal virtual override {
365
+ if (ERC165Checker.supportsERC165InterfaceUnchecked(notifiedContract, _INTERFACEID_LSP1)) {
366
+ ILSP1UniversalReceiver(notifiedContract).universalReceiver(
367
+ _TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
368
+ data
369
+ );
370
+ }
171
371
  }
172
372
  }
@@ -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 {LSP0ERC725AccountInitAbstract} from "./LSP0ERC725AccountInitAbstract.sol";
@@ -21,7 +21,7 @@ contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
21
21
  * @notice Sets the owner of the contract
22
22
  * @param newOwner the owner of the contract
23
23
  */
24
- function initialize(address newOwner) public payable virtual initializer {
24
+ function initialize(address newOwner) external payable virtual initializer {
25
25
  LSP0ERC725AccountInitAbstract._initialize(newOwner);
26
26
  }
27
27
  }
@@ -1,9 +1,9 @@
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 {LSP0ERC725AccountCore} from "./LSP0ERC725AccountCore.sol";
6
- import {Initializable} from "@erc725/smart-contracts/contracts/custom/Initializable.sol";
6
+ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
7
7
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
8
8
 
9
9
  /**
@@ -13,6 +13,7 @@ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnse
13
13
  */
14
14
  abstract contract LSP0ERC725AccountInitAbstract is Initializable, LSP0ERC725AccountCore {
15
15
  function _initialize(address newOwner) internal virtual onlyInitializing {
16
+ if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
16
17
  OwnableUnset._setOwner(newOwner);
17
18
  }
18
19
  }
@@ -1,10 +1,10 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.0;
2
+ pragma solidity ^0.8.4;
3
3
 
4
- // --- ERC725Y Keys
4
+ // --- ERC725Y Data Keys
5
5
 
6
6
  // keccak256('LSP10Vaults[]')
7
7
  bytes32 constant _LSP10_VAULTS_ARRAY_KEY = 0x55482936e01da86729a45d2b87a6b1d3bc582bea0ec00e38bdb340e3af6f9f06;
8
8
 
9
- // bytes10(keccak256('LSP10VaultsMap')) + bytes2(0)
10
- bytes12 constant _LSP10_VAULTS_MAP_KEY_PREFIX = 0x192448c3c0f88c7f238c0000;
9
+ // bytes10(keccak256('LSP10VaultsMap'))
10
+ bytes10 constant _LSP10_VAULTS_MAP_KEY_PREFIX = 0x192448c3c0f88c7f238c;