@lukso/lsp-smart-contracts 0.5.0 → 0.6.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 (138) hide show
  1. package/README.md +29 -9
  2. package/artifacts/LSP0ERC725Account.json +392 -0
  3. package/artifacts/LSP0ERC725AccountInit.json +433 -0
  4. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -7
  5. package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -7
  6. package/artifacts/LSP4Compatibility.json +195 -0
  7. package/artifacts/LSP4DigitalAssetMetadata.json +169 -0
  8. package/artifacts/LSP4DigitalAssetMetadataInit.json +231 -0
  9. package/artifacts/LSP6KeyManager.json +34 -28
  10. package/artifacts/LSP6KeyManagerInit.json +42 -23
  11. package/artifacts/LSP7CappedSupply.json +133 -8
  12. package/artifacts/LSP7CappedSupplyInit.json +160 -32
  13. package/artifacts/LSP7CompatibilityForERC20.json +125 -10
  14. package/artifacts/LSP7CompatibilityForERC20Init.json +727 -0
  15. package/artifacts/LSP7DigitalAsset.json +125 -10
  16. package/artifacts/LSP7DigitalAssetInit.json +149 -31
  17. package/artifacts/LSP7Mintable.json +126 -11
  18. package/artifacts/LSP7MintableInit.json +150 -32
  19. package/artifacts/LSP8CappedSupply.json +134 -8
  20. package/artifacts/LSP8CappedSupplyInit.json +169 -17
  21. package/artifacts/LSP8CompatibilityForERC721.json +126 -10
  22. package/artifacts/LSP8CompatibilityForERC721Init.json +873 -0
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +126 -10
  24. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +158 -16
  25. package/artifacts/LSP8Mintable.json +138 -11
  26. package/artifacts/LSP8MintableInit.json +170 -17
  27. package/artifacts/LSP9Vault.json +368 -0
  28. package/artifacts/LSP9VaultInit.json +409 -0
  29. package/artifacts/UniversalFactory.json +127 -0
  30. package/artifacts/UniversalProfile.json +65 -14
  31. package/artifacts/UniversalProfileInit.json +104 -14
  32. package/artifacts/UniversalReceiverAddressStore.json +204 -0
  33. package/constants.js +352 -0
  34. package/contracts/Custom/ClaimOwnership.sol +31 -0
  35. package/contracts/Custom/ERC165Checker.sol +130 -0
  36. package/contracts/Custom/IClaimOwnership.sol +10 -0
  37. package/contracts/Factories/UniversalFactory.sol +155 -0
  38. package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -9
  39. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +6 -8
  40. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +89 -46
  41. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +5 -5
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +6 -21
  43. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +10 -0
  44. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +2 -8
  45. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +59 -185
  46. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +48 -6
  47. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +45 -92
  48. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +39 -6
  49. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +47 -0
  50. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +205 -0
  51. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
  52. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  53. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +5 -14
  54. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
  55. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +11 -8
  56. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
  57. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +14 -20
  58. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
  59. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +157 -0
  60. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +21 -18
  61. package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -25
  62. package/contracts/LSP6KeyManager/LSP6Errors.sol +37 -0
  63. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -4
  64. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +429 -332
  65. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +6 -5
  66. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +7 -15
  67. package/contracts/LSP6KeyManager/LSP6Utils.sol +111 -0
  68. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
  69. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
  70. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +23 -9
  71. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +70 -94
  72. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +8 -9
  73. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +25 -23
  74. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
  75. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
  76. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +2 -4
  77. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +8 -7
  78. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
  79. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
  80. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +9 -17
  81. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +33 -21
  82. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Core.sol +20 -39
  83. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol +3 -3
  84. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +39 -28
  85. package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
  86. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7Mintable.sol +4 -3
  87. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableCore.sol +5 -5
  88. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableInit.sol +3 -2
  89. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +34 -0
  90. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -16
  91. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +6 -3
  92. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +22 -0
  93. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +23 -10
  94. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +102 -135
  95. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +8 -11
  96. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +24 -21
  97. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
  98. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +3 -11
  99. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +9 -15
  100. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +14 -12
  101. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +3 -8
  102. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +11 -20
  103. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +41 -33
  104. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Core.sol +27 -84
  105. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol +4 -6
  106. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +40 -41
  107. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
  108. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8Mintable.sol +4 -3
  109. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableCore.sol +5 -8
  110. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableInit.sol +4 -3
  111. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +35 -0
  112. package/contracts/LSP9Vault/LSP9Constants.sol +13 -4
  113. package/contracts/LSP9Vault/LSP9Vault.sol +15 -37
  114. package/contracts/LSP9Vault/LSP9VaultCore.sol +101 -82
  115. package/contracts/LSP9Vault/LSP9VaultInit.sol +5 -4
  116. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +15 -45
  117. package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
  118. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
  119. package/contracts/Legacy/UniversalReceiverAddressStore.sol +59 -0
  120. package/contracts/UniversalProfile.sol +10 -5
  121. package/contracts/UniversalProfileInit.sol +5 -4
  122. package/contracts/UniversalProfileInitAbstract.sol +14 -20
  123. package/contracts/Utils/UtilsLib.sol +47 -11
  124. package/package.json +23 -9
  125. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
  126. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
  127. package/constants.ts +0 -356
  128. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +0 -52
  129. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +0 -26
  130. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +0 -28
  131. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +0 -41
  132. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +0 -23
  133. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +0 -25
  134. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +0 -47
  135. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
  136. package/contracts/Utils/ERC725Utils.sol +0 -169
  137. package/contracts/Utils/LSP2Utils.sol +0 -127
  138. package/contracts/Utils/LSP6Utils.sol +0 -63
@@ -1,14 +1,10 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- // >> INTERFACES
5
-
6
- bytes4 constant _INTERFACE_ID_ERC725ACCOUNT = 0x63cb749b;
7
-
8
- bytes4 constant _INTERFACE_ID_ERC1271 = 0x1626ba7e;
9
-
10
- // >> OTHER
4
+ // --- ERC165 interface ids
5
+ bytes4 constant _INTERFACEID_LSP0 = 0x9a3bfe88;
6
+ bytes4 constant _INTERFACEID_ERC1271 = 0x1626ba7e;
11
7
 
12
8
  // ERC1271 - Standard Signature Validation
13
- bytes4 constant _ERC1271MAGICVALUE = 0x1626ba7e;
14
- bytes4 constant _ERC1271FAILVALUE = 0xffffffff;
9
+ bytes4 constant _ERC1271_MAGICVALUE = 0x1626ba7e;
10
+ bytes4 constant _ERC1271_FAILVALUE = 0xffffffff;
@@ -2,22 +2,20 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./LSP0ERC725AccountCore.sol";
6
- import "@erc725/smart-contracts/contracts/ERC725.sol";
5
+ import {LSP0ERC725AccountCore} from "./LSP0ERC725AccountCore.sol";
6
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
7
7
 
8
8
  /**
9
9
  * @title Implementation of ERC725Account
10
10
  * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
11
11
  * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
12
12
  */
13
- contract LSP0ERC725Account is LSP0ERC725AccountCore, ERC725 {
13
+ contract LSP0ERC725Account is LSP0ERC725AccountCore {
14
14
  /**
15
- * @notice Sets the owner of the contract and register ERC725Account, ERC1271 and LSP1UniversalReceiver interfacesId
15
+ * @notice Sets the owner of the contract
16
16
  * @param _newOwner the owner of the contract
17
17
  */
18
- constructor(address _newOwner) ERC725(_newOwner) {
19
- _registerInterface(_INTERFACE_ID_ERC725ACCOUNT);
20
- _registerInterface(_INTERFACE_ID_ERC1271);
21
- _registerInterface(_INTERFACEID_LSP1);
18
+ constructor(address _newOwner) {
19
+ OwnableUnset._setOwner(_newOwner);
22
20
  }
23
21
  }
@@ -2,23 +2,24 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // interfaces
5
- import "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
- import "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
- import "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
8
-
9
- // modules
10
-
11
- import "@erc725/smart-contracts/contracts/ERC725YCore.sol";
12
- import "@erc725/smart-contracts/contracts/ERC725XCore.sol";
5
+ import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
6
+ import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
+ import {ILSP1UniversalReceiverDelegate} from "../LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol";
13
8
 
14
9
  // libraries
15
- import "../Utils/UtilsLib.sol";
16
- import "../Utils/ERC725Utils.sol";
17
- import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
10
+ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
11
+ import {ERC165Checker} from "../Custom/ERC165Checker.sol";
12
+
13
+ // modules
14
+ import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
15
+ import {ERC725XCore} from "@erc725/smart-contracts/contracts/ERC725XCore.sol";
16
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
17
+ import {ClaimOwnership} from "../Custom/ClaimOwnership.sol";
18
18
 
19
19
  // constants
20
- import "../LSP1UniversalReceiver/LSP1Constants.sol";
21
- import "../LSP0ERC725Account/LSP0Constants.sol";
20
+ import {_INTERFACEID_LSP0, _INTERFACEID_ERC1271, _ERC1271_FAILVALUE} from "../LSP0ERC725Account/LSP0Constants.sol";
21
+ import {_INTERFACEID_LSP1, _INTERFACEID_LSP1_DELEGATE, _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY} from "../LSP1UniversalReceiver/LSP1Constants.sol";
22
+ import {_INTERFACEID_CLAIM_OWNERSHIP} from "../Custom/IClaimOwnership.sol";
22
23
 
23
24
  /**
24
25
  * @title Core Implementation of ERC725Account
@@ -26,15 +27,22 @@ import "../LSP0ERC725Account/LSP0Constants.sol";
26
27
  * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
27
28
  */
28
29
  abstract contract LSP0ERC725AccountCore is
29
- IERC1271,
30
- ILSP1UniversalReceiver,
31
30
  ERC725XCore,
32
- ERC725YCore
31
+ ERC725YCore,
32
+ ClaimOwnership,
33
+ IERC1271,
34
+ ILSP1UniversalReceiver
33
35
  {
34
- using ERC725Utils for IERC725Y;
35
-
36
+ /**
37
+ * @notice Emitted when receiving native tokens
38
+ * @param sender The address of the sender
39
+ * @param value The amount of value sent
40
+ */
36
41
  event ValueReceived(address indexed sender, uint256 indexed value);
37
42
 
43
+ /**
44
+ * @dev Emits an event when receiving native tokens
45
+ */
38
46
  receive() external payable {
39
47
  emit ValueReceived(_msgSender(), msg.value);
40
48
  }
@@ -54,6 +62,42 @@ abstract contract LSP0ERC725AccountCore is
54
62
  // }
55
63
  // }
56
64
 
65
+ // ERC165
66
+
67
+ /**
68
+ * @dev See {IERC165-supportsInterface}.
69
+ */
70
+ function supportsInterface(bytes4 interfaceId)
71
+ public
72
+ view
73
+ virtual
74
+ override(ERC725XCore, ERC725YCore)
75
+ returns (bool)
76
+ {
77
+ return
78
+ interfaceId == _INTERFACEID_ERC1271 ||
79
+ interfaceId == _INTERFACEID_LSP0 ||
80
+ interfaceId == _INTERFACEID_LSP1 ||
81
+ interfaceId == _INTERFACEID_CLAIM_OWNERSHIP ||
82
+ super.supportsInterface(interfaceId);
83
+ }
84
+
85
+ // ERC173 - Modified ClaimOwnership
86
+
87
+ /**
88
+ * @dev Sets the pending owner
89
+ */
90
+ function transferOwnership(address _newOwner)
91
+ public
92
+ virtual
93
+ override(ClaimOwnership, OwnableUnset)
94
+ onlyOwner
95
+ {
96
+ ClaimOwnership._transferOwnership(_newOwner);
97
+ }
98
+
99
+ // ERC1271
100
+
57
101
  /**
58
102
  * @notice Checks if an owner signed `_data`.
59
103
  * ERC1271 interface.
@@ -68,52 +112,51 @@ abstract contract LSP0ERC725AccountCore is
68
112
  returns (bytes4 magicValue)
69
113
  {
70
114
  // prettier-ignore
115
+ address _owner = owner();
71
116
  // if OWNER is a contract
72
- if (UtilsLib.isContract(owner())) {
73
- return
74
- supportsInterface(_INTERFACE_ID_ERC1271)
75
- ? IERC1271(owner()).isValidSignature(_hash, _signature)
76
- : _ERC1271FAILVALUE;
77
- // if OWNER is a key
117
+ if (_owner.code.length != 0) {
118
+ return
119
+ ERC165Checker.supportsERC165Interface(_owner, _INTERFACEID_ERC1271)
120
+ ? IERC1271(_owner).isValidSignature(_hash, _signature)
121
+ : _ERC1271_FAILVALUE;
122
+ // if OWNER is a key
78
123
  } else {
79
- return
80
- owner() == ECDSA.recover(_hash, _signature)
81
- ? _INTERFACE_ID_ERC1271
82
- : _ERC1271FAILVALUE;
124
+ return
125
+ _owner == ECDSA.recover(_hash, _signature)
126
+ ? _INTERFACEID_ERC1271
127
+ : _ERC1271_FAILVALUE;
83
128
  }
84
129
  }
85
130
 
131
+ // LSP1
132
+
133
+ /**
134
+ * @notice Triggers the UniversalReceiver event when this function gets executed successfully.
135
+ * @dev Forwards the call to the UniversalReceiverDelegate if set.
136
+ * @param _typeId The type of call received.
137
+ * @param _data The data received.
138
+ */
86
139
  function universalReceiver(bytes32 _typeId, bytes calldata _data)
87
140
  external
88
141
  virtual
89
142
  override
90
143
  returns (bytes memory returnValue)
91
144
  {
92
- bytes memory receiverData = IERC725Y(this).getDataSingle(
93
- _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
94
- );
95
- returnValue = "";
96
-
97
- // call external contract
98
- if (receiverData.length == 20) {
99
- address universalReceiverAddress = BytesLib.toAddress(
100
- receiverData,
101
- 0
102
- );
145
+ bytes memory data = _getData(_LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY);
146
+
147
+ if (data.length >= 20) {
148
+ address universalReceiverDelegate = address(bytes20(data));
103
149
 
104
150
  if (
105
- ERC165(universalReceiverAddress).supportsInterface(
151
+ ERC165Checker.supportsERC165Interface(
152
+ universalReceiverDelegate,
106
153
  _INTERFACEID_LSP1_DELEGATE
107
154
  )
108
155
  ) {
109
- returnValue = ILSP1UniversalReceiverDelegate(
110
- universalReceiverAddress
111
- ).universalReceiverDelegate(_msgSender(), _typeId, _data);
156
+ returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
157
+ .universalReceiverDelegate(_msgSender(), _typeId, _data);
112
158
  }
113
159
  }
114
-
115
160
  emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
116
-
117
- return returnValue;
118
161
  }
119
162
  }
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./LSP0ERC725AccountInitAbstract.sol";
5
+ import {LSP0ERC725AccountInitAbstract} from "./LSP0ERC725AccountInitAbstract.sol";
6
6
 
7
7
  /**
8
8
  * @title Deployable Proxy Implementation of ERC725Account
@@ -11,10 +11,10 @@ import "./LSP0ERC725AccountInitAbstract.sol";
11
11
  */
12
12
  contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
13
13
  /**
14
- * @inheritdoc LSP0ERC725AccountInitAbstract
14
+ * @notice Sets the owner of the contract
15
+ * @param _newOwner the owner of the contract
15
16
  */
16
-
17
- function initialize(address _newOwner) public virtual override initializer {
18
- LSP0ERC725AccountInitAbstract.initialize(_newOwner);
17
+ function initialize(address _newOwner) public virtual initializer {
18
+ LSP0ERC725AccountInitAbstract._initialize(_newOwner);
19
19
  }
20
20
  }
@@ -2,32 +2,17 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "@erc725/smart-contracts/contracts/ERC725InitAbstract.sol";
6
- import "./LSP0ERC725AccountCore.sol";
5
+ import {LSP0ERC725AccountCore} from "./LSP0ERC725AccountCore.sol";
6
+ import {Initializable} from "@erc725/smart-contracts/contracts/custom/Initializable.sol";
7
+ import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
7
8
 
8
9
  /**
9
10
  * @title Inheritable Proxy Implementation of ERC725Account
10
11
  * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
11
12
  * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
12
13
  */
13
- abstract contract LSP0ERC725AccountInitAbstract is
14
- LSP0ERC725AccountCore,
15
- ERC725InitAbstract
16
- {
17
- /**
18
- * @notice Sets the owner of the contract and register ERC725Account, ERC1271 and LSP1UniversalReceiver interfacesId
19
- * @param _newOwner the owner of the contract
20
- */
21
- function initialize(address _newOwner)
22
- public
23
- virtual
24
- override
25
- onlyInitializing
26
- {
27
- ERC725InitAbstract.initialize(_newOwner);
28
-
29
- _registerInterface(_INTERFACE_ID_ERC725ACCOUNT);
30
- _registerInterface(_INTERFACE_ID_ERC1271);
31
- _registerInterface(_INTERFACEID_LSP1);
14
+ abstract contract LSP0ERC725AccountInitAbstract is Initializable, LSP0ERC725AccountCore {
15
+ function _initialize(address _newOwner) internal virtual onlyInitializing {
16
+ OwnableUnset._setOwner(_newOwner);
32
17
  }
33
18
  }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // --- ERC725Y Keys
5
+
6
+ // keccak256('LSP10Vaults[]')
7
+ bytes32 constant _LSP10_VAULTS_ARRAY_KEY = 0x55482936e01da86729a45d2b87a6b1d3bc582bea0ec00e38bdb340e3af6f9f06;
8
+
9
+ // bytes10(keccak256('LSP10VaultsMap')) + bytes2(0)
10
+ bytes12 constant _LSP10_VAULTS_MAP_KEY_PREFIX = 0x192448c3c0f88c7f238c0000;
@@ -6,12 +6,6 @@ bytes4 constant _INTERFACEID_LSP1 = 0x6bb56a14;
6
6
  bytes4 constant _INTERFACEID_LSP1_DELEGATE = 0xc2d7bcc1;
7
7
 
8
8
  // --- ERC725Y Keys
9
- bytes32 constant _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY = 0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47; // keccak256("LSP1UniversalReceiverDelegate")
10
9
 
11
- bytes32 constant _ARRAYKEY_LSP5 = 0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b; // keccak256("LSP5ReceivedAssets[]")
12
-
13
- bytes32 constant _MAPHASH_LSP5 = 0x812c4334633eb816c80deebfa5fb7d2509eb438ca1b6418106442cb5ccc62f6c; // keccak256("LSP5ReceivedAssetsMap")
14
-
15
- bytes32 constant _ARRAYKEY_LSP10 = 0x55482936e01da86729a45d2b87a6b1d3bc582bea0ec00e38bdb340e3af6f9f06; // keccak256("LSP10Vaults[]")
16
-
17
- bytes32 constant _MAPHASH_LSP10 = 0x192448c3c0f88c7f238c7f70449c270032f9752568e88cc8936ce3a2cb18e3ec; // keccak256("LSP10VaultsMap")
10
+ // keccak256('LSP1UniversalReceiverDelegate')
11
+ bytes32 constant _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY = 0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47;
@@ -1,202 +1,76 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- // modules
5
- import "@erc725/smart-contracts/contracts/ERC725Y.sol";
6
- import "../../../LSP6KeyManager/LSP6KeyManager.sol";
7
- import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
8
-
9
4
  // interfaces
10
- import "../../../LSP6KeyManager/ILSP6KeyManager.sol";
11
- import "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
5
+ import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
6
+ import {ILSP7DigitalAsset} from "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
7
+ import {ILSP6KeyManager} from "../../../LSP6KeyManager/ILSP6KeyManager.sol";
12
8
 
13
9
  // libraries
14
- import "../../../Utils/ERC725Utils.sol";
10
+ import {ERC165Checker} from "../../../Custom/ERC165Checker.sol";
11
+ import {LSP1Utils} from "../../LSP1Utils.sol";
12
+ import {LSP2Utils} from "../../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
13
+ import {LSP5Utils} from "../../../LSP5ReceivedAssets/LSP5Utils.sol";
14
+
15
+ // modules
16
+ import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
17
+ import {LSP6KeyManager} from "../../../LSP6KeyManager/LSP6KeyManager.sol";
15
18
 
16
19
  // constants
17
- import "../../LSP1Constants.sol";
18
- import "../../../LSP6KeyManager/LSP6Constants.sol";
19
- import "../../../LSP7DigitalAsset/LSP7Constants.sol";
20
- import "../../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
21
- import "../../../LSP9Vault/LSP9Constants.sol";
20
+ import {_INTERFACEID_LSP6} from "../../../LSP6KeyManager/LSP6Constants.sol";
21
+ import {_TYPEID_LSP9_VAULTSENDER} from "../../../LSP9Vault/LSP9Constants.sol";
22
22
 
23
23
  /**
24
24
  * @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
25
25
  */
26
- abstract contract TokenAndVaultHandlingContract {
27
- using ERC725Utils for IERC725Y;
28
-
29
- function _tokenAndVaultHandling(
30
- address sender,
31
- bytes32 typeId,
32
- bytes memory data
33
- ) internal returns (bytes memory result) {
34
- address keyManagerAddress = ERC725Y(msg.sender).owner();
35
- _profileChecker(keyManagerAddress);
36
-
37
- if (
38
- ERC165Checker.supportsInterface(
39
- keyManagerAddress,
40
- _INTERFACEID_LSP6
41
- )
42
- ) {
43
- (
44
- bytes32 arrayKey,
45
- bytes32 mapHash,
46
- bytes4 interfaceID
47
- ) = _getTransferData(typeId);
48
- bytes32 mapKey = ERC725Utils.generateMapKey(
49
- mapHash,
50
- abi.encodePacked(sender)
51
- );
52
- bytes memory mapValue = IERC725Y(msg.sender).getDataSingle(mapKey);
53
-
54
- if (
55
- typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
56
- typeId == _TYPEID_LSP8_TOKENSRECIPIENT ||
57
- typeId == _TYPEID_LSP9_VAULTRECIPIENT
58
- ) {
59
- if (bytes12(mapValue) == bytes12(0)) {
60
- (bytes32[] memory keys, bytes[] memory values) = ERC725Utils
61
- .addMapAndArrayKey(
62
- IERC725Y(msg.sender),
63
- arrayKey,
64
- mapKey,
65
- sender,
66
- interfaceID
67
- );
68
-
69
- result = _executeViaKeyManager(
70
- ILSP6KeyManager(keyManagerAddress),
71
- keys,
72
- values
73
- );
74
- }
75
- } else if (
76
- typeId == _TYPEID_LSP7_TOKENSSENDER ||
77
- typeId == _TYPEID_LSP8_TOKENSSENDER ||
78
- typeId == _TYPEID_LSP9_VAULTSENDER
79
- ) {
80
- if (bytes12(mapValue) != bytes12(0)) {
81
- if (typeId == _TYPEID_LSP9_VAULTSENDER) {
82
- (
83
- bytes32[] memory keys,
84
- bytes[] memory values
85
- ) = ERC725Utils.removeMapAndArrayKey(
86
- IERC725Y(msg.sender),
87
- arrayKey,
88
- mapHash,
89
- mapKey
90
- );
91
-
92
- result = _executeViaKeyManager(
93
- ILSP6KeyManager(keyManagerAddress),
94
- keys,
95
- values
96
- );
97
- } else if (
98
- typeId == _TYPEID_LSP7_TOKENSSENDER ||
99
- typeId == _TYPEID_LSP8_TOKENSSENDER
100
- ) {
101
- uint256 balance = ILSP7DigitalAsset(sender).balanceOf(
102
- msg.sender
103
- );
104
- if ((balance - _tokenAmount(typeId, data)) == 0) {
105
- (
106
- bytes32[] memory keys,
107
- bytes[] memory values
108
- ) = ERC725Utils.removeMapAndArrayKey(
109
- IERC725Y(msg.sender),
110
- arrayKey,
111
- mapHash,
112
- mapKey
113
- );
114
-
115
- result = _executeViaKeyManager(
116
- ILSP6KeyManager(keyManagerAddress),
117
- keys,
118
- values
119
- );
120
- }
121
- }
122
- }
123
- }
124
- }
125
- }
126
-
127
- // helper functions
128
-
129
- function _getTransferData(bytes32 _typeId)
130
- private
131
- pure
132
- returns (
133
- bytes32 _arrayKey,
134
- bytes32 _mapHash,
135
- bytes4 _interfaceID
136
- )
26
+ abstract contract TokenAndVaultHandling {
27
+ // internal functions
28
+ function _tokenAndVaultHandling(address sender, bytes32 typeId)
29
+ internal
30
+ returns (bytes memory result)
137
31
  {
138
- if (
139
- _typeId == _TYPEID_LSP7_TOKENSSENDER ||
140
- _typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
141
- _typeId == _TYPEID_LSP8_TOKENSSENDER ||
142
- _typeId == _TYPEID_LSP8_TOKENSRECIPIENT
143
- ) {
144
- _arrayKey = _ARRAYKEY_LSP5;
145
- _mapHash = _MAPHASH_LSP5;
146
- if (
147
- _typeId == _TYPEID_LSP7_TOKENSSENDER ||
148
- _typeId == _TYPEID_LSP7_TOKENSRECIPIENT
149
- ) {
150
- _interfaceID = _INTERFACEID_LSP7;
151
- } else {
152
- _interfaceID = _INTERFACEID_LSP8;
153
- }
154
- } else if (
155
- _typeId == _TYPEID_LSP9_VAULTSENDER ||
156
- _typeId == _TYPEID_LSP9_VAULTRECIPIENT
157
- ) {
158
- _arrayKey = _ARRAYKEY_LSP10;
159
- _mapHash = _MAPHASH_LSP10;
160
- _interfaceID = _INTERFACEID_LSP9;
161
- }
162
- }
163
-
164
- function _executeViaKeyManager(
165
- ILSP6KeyManager _keyManagerAdd,
166
- bytes32[] memory _keys,
167
- bytes[] memory _values
168
- ) private returns (bytes memory result) {
169
- bytes memory payload = abi.encodeWithSelector(
170
- IERC725Y.setData.selector,
171
- _keys,
172
- _values
173
- );
174
- result = ILSP6KeyManager(_keyManagerAdd).execute(payload);
175
- }
176
-
177
- function _tokenAmount(bytes32 _typeId, bytes memory _data)
178
- private
179
- pure
180
- returns (uint256 amount)
181
- {
182
- if (_typeId == _TYPEID_LSP7_TOKENSSENDER) {
183
- /* solhint-disable */
184
- assembly {
185
- amount := mload(add(add(_data, 0x20), 0x28))
32
+ if (sender.code.length == 0) return "";
33
+
34
+ address keyManager = ERC725Y(msg.sender).owner();
35
+ if (!ERC165Checker.supportsERC165Interface(keyManager, _INTERFACEID_LSP6)) return "";
36
+
37
+ address target = ILSP6KeyManager(keyManager).target();
38
+
39
+ // check if the caller is the same account controlled by the keyManager
40
+ if (msg.sender != target) return "";
41
+ (bool senderHook, bytes32 arrayKey, bytes12 mapPrefix, bytes4 interfaceID) = LSP1Utils
42
+ .getTransferDetails(typeId);
43
+
44
+ bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(sender));
45
+ bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
46
+
47
+ if (!senderHook) {
48
+ // if the map is already set, then do nothing
49
+ if (bytes12(mapValue) != bytes12(0)) return "";
50
+ result = LSP5Utils.addMapAndArrayKeyViaKeyManager(
51
+ IERC725Y(msg.sender),
52
+ arrayKey,
53
+ mapKey,
54
+ sender,
55
+ interfaceID,
56
+ keyManager
57
+ );
58
+ } else if (senderHook) {
59
+ // if there is no map for the asset to remove, then do nothing
60
+ if (bytes12(mapValue) == bytes12(0)) return "";
61
+ if (typeId != _TYPEID_LSP9_VAULTSENDER) {
62
+ uint256 balance = ILSP7DigitalAsset(sender).balanceOf(msg.sender);
63
+ // if the amount sent is not the full balance, then do nothing
64
+ if (balance != 0) return "";
186
65
  }
187
- /* solhint-enable */
188
- } else {
189
- amount = 1;
66
+ result = LSP5Utils.removeMapAndArrayKeyViaKeyManager(
67
+ IERC725Y(msg.sender),
68
+ arrayKey,
69
+ mapPrefix,
70
+ mapKey,
71
+ mapValue,
72
+ keyManager
73
+ );
190
74
  }
191
75
  }
192
-
193
- function _profileChecker(address keyManagerAddress) private {
194
- address profileAddress = address(
195
- LSP6KeyManager(keyManagerAddress).account()
196
- );
197
- require(
198
- profileAddress == msg.sender,
199
- "Security: The called Key Manager belongs to a different account"
200
- );
201
- }
202
76
  }
@@ -1,11 +1,21 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
+ // interfaces
5
+ import {ILSP1UniversalReceiverDelegate} from "../ILSP1UniversalReceiverDelegate.sol";
6
+
4
7
  // modules
5
- import "./LSP1UniversalReceiverDelegateUPCore.sol";
8
+ import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
9
+ import {TokenAndVaultHandling} from "./Handling/TokenAndVaultHandling.sol";
10
+
11
+ // constants
12
+ import {_INTERFACEID_LSP1_DELEGATE} from "../LSP1Constants.sol";
13
+ import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "../../LSP7DigitalAsset/LSP7Constants.sol";
14
+ import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
15
+ import {_TYPEID_LSP9_VAULTSENDER, _TYPEID_LSP9_VAULTRECIPIENT} from "../../LSP9Vault/LSP9Constants.sol";
6
16
 
7
17
  /**
8
- * @title Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
18
+ * @title Core Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
9
19
  * the LSP5-ReceivedAsset and LSP10-ReceivedVaults standard and removing the sent vaults and assets.
10
20
  *
11
21
  * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
@@ -15,12 +25,44 @@ import "./LSP1UniversalReceiverDelegateUPCore.sol";
15
25
  *
16
26
  */
17
27
  contract LSP1UniversalReceiverDelegateUP is
18
- LSP1UniversalReceiverDelegateUPCore
28
+ ERC165,
29
+ ILSP1UniversalReceiverDelegate,
30
+ TokenAndVaultHandling
19
31
  {
20
32
  /**
21
- * @notice Register the LSP1UniversalReceiverDelegate InterfaceId
33
+ * @inheritdoc ILSP1UniversalReceiverDelegate
34
+ * @dev Allows to register arrayKeys and Map of incoming vaults and assets and removing them after being sent
35
+ * @return result the return value of keyManager's execute function
36
+ */
37
+ function universalReceiverDelegate(
38
+ address sender,
39
+ bytes32 typeId,
40
+ bytes memory data // solhint-disable no-unused-vars
41
+ ) public virtual override returns (bytes memory result) {
42
+ if (
43
+ typeId == _TYPEID_LSP7_TOKENSSENDER ||
44
+ typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
45
+ typeId == _TYPEID_LSP8_TOKENSSENDER ||
46
+ typeId == _TYPEID_LSP8_TOKENSRECIPIENT ||
47
+ typeId == _TYPEID_LSP9_VAULTSENDER ||
48
+ typeId == _TYPEID_LSP9_VAULTRECIPIENT
49
+ ) {
50
+ result = _tokenAndVaultHandling(sender, typeId);
51
+ }
52
+
53
+ /* @TODO
54
+ else if() {
55
+ result = FollowerHandling(sender, typeId, data);
56
+ }
57
+ */
58
+ }
59
+
60
+ // --- Overrides
61
+
62
+ /**
63
+ * @inheritdoc ERC165
22
64
  */
23
- constructor() {
24
- _registerInterface(_INTERFACEID_LSP1_DELEGATE);
65
+ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
66
+ return interfaceId == _INTERFACEID_LSP1_DELEGATE || super.supportsInterface(interfaceId);
25
67
  }
26
68
  }