@lukso/lsp-smart-contracts 0.9.0 → 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 (173) hide show
  1. package/README.md +15 -7
  2. package/artifacts/LSP0ERC725Account.json +62 -68
  3. package/artifacts/LSP0ERC725AccountInit.json +62 -68
  4. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  5. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  6. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
  7. package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
  8. package/artifacts/LSP4Compatibility.json +32 -38
  9. package/artifacts/LSP4DigitalAssetMetadata.json +32 -38
  10. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +32 -38
  11. package/artifacts/LSP6KeyManager.json +29 -15
  12. package/artifacts/LSP6KeyManagerInit.json +29 -15
  13. package/artifacts/LSP7CappedSupply.json +71 -36
  14. package/artifacts/LSP7CappedSupplyInitAbstract.json +71 -36
  15. package/artifacts/LSP7CompatibleERC20.json +71 -36
  16. package/artifacts/LSP7CompatibleERC20InitAbstract.json +71 -36
  17. package/artifacts/LSP7CompatibleERC20Mintable.json +73 -38
  18. package/artifacts/LSP7CompatibleERC20MintableInit.json +73 -38
  19. package/artifacts/LSP7DigitalAsset.json +71 -36
  20. package/artifacts/LSP7DigitalAssetInitAbstract.json +71 -36
  21. package/artifacts/LSP7Mintable.json +73 -38
  22. package/artifacts/LSP7MintableInit.json +73 -38
  23. package/artifacts/LSP8CappedSupply.json +32 -38
  24. package/artifacts/LSP8CappedSupplyInitAbstract.json +32 -38
  25. package/artifacts/LSP8CompatibleERC721.json +35 -41
  26. package/artifacts/LSP8CompatibleERC721InitAbstract.json +35 -41
  27. package/artifacts/LSP8CompatibleERC721Mintable.json +37 -43
  28. package/artifacts/LSP8CompatibleERC721MintableInit.json +37 -43
  29. package/artifacts/LSP8IdentifiableDigitalAsset.json +32 -38
  30. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +32 -38
  31. package/artifacts/LSP8Mintable.json +34 -40
  32. package/artifacts/LSP8MintableInit.json +34 -40
  33. package/artifacts/LSP9Vault.json +61 -67
  34. package/artifacts/LSP9VaultInit.json +61 -67
  35. package/artifacts/UniversalProfile.json +62 -68
  36. package/artifacts/UniversalProfileInit.json +62 -68
  37. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +45 -10
  38. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  39. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +36 -6
  40. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +361 -124
  41. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +30 -4
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +37 -3
  43. package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -1
  44. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +30 -15
  45. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +0 -1
  46. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +0 -1
  47. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +5 -7
  48. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -5
  49. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +0 -4
  50. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +91 -34
  51. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +27 -8
  52. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +18 -9
  53. package/contracts/LSP20CallVerification/LSP20Constants.sol +17 -0
  54. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +26 -12
  55. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +0 -1
  56. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +32 -16
  57. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +11 -2
  58. package/contracts/LSP6KeyManager/LSP6Constants.sol +5 -5
  59. package/contracts/LSP6KeyManager/LSP6Errors.sol +10 -6
  60. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +140 -68
  61. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
  62. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +30 -38
  63. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +153 -60
  64. package/contracts/LSP6KeyManager/LSP6Utils.sol +1 -5
  65. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +67 -13
  66. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  67. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -2
  68. package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +24 -0
  69. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -2
  70. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +1 -2
  71. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +3 -5
  72. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +3 -5
  73. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +15 -12
  74. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +1 -1
  75. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +1 -2
  76. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +1 -2
  77. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +5 -5
  78. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +6 -6
  79. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +2 -2
  80. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +2 -2
  81. package/contracts/LSP9Vault/ILSP9Vault.sol +9 -1
  82. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  83. package/contracts/LSP9Vault/LSP9Vault.sol +0 -6
  84. package/contracts/LSP9Vault/LSP9VaultCore.sol +17 -15
  85. package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -1
  86. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +8 -5
  87. package/contracts/UniversalProfileInitAbstract.sol +5 -0
  88. package/devdocs/Create2Factory.json +16 -0
  89. package/devdocs/LSP0ERC725Account.json +200 -0
  90. package/devdocs/LSP0ERC725AccountInit.json +203 -0
  91. package/devdocs/LSP11BasicSocialRecovery.json +146 -0
  92. package/devdocs/LSP11BasicSocialRecoveryInit.json +146 -0
  93. package/devdocs/LSP16UniversalFactory.json +51 -0
  94. package/devdocs/LSP1UniversalReceiverDelegateUP.json +80 -0
  95. package/devdocs/LSP1UniversalReceiverDelegateVault.json +62 -0
  96. package/devdocs/LSP4Compatibility.json +79 -0
  97. package/devdocs/LSP4DigitalAssetMetadata.json +84 -0
  98. package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +77 -0
  99. package/devdocs/LSP6KeyManager.json +257 -0
  100. package/devdocs/LSP6KeyManagerInit.json +260 -0
  101. package/devdocs/LSP7CappedSupply.json +211 -0
  102. package/devdocs/LSP7CappedSupplyInitAbstract.json +206 -0
  103. package/devdocs/LSP7CompatibleERC20.json +225 -0
  104. package/devdocs/LSP7CompatibleERC20InitAbstract.json +218 -0
  105. package/devdocs/LSP7CompatibleERC20Mintable.json +217 -0
  106. package/devdocs/LSP7CompatibleERC20MintableInit.json +227 -0
  107. package/devdocs/LSP7DigitalAsset.json +210 -0
  108. package/devdocs/LSP7DigitalAssetInitAbstract.json +202 -0
  109. package/devdocs/LSP7Mintable.json +219 -0
  110. package/devdocs/LSP7MintableInit.json +220 -0
  111. package/devdocs/LSP8CappedSupply.json +232 -0
  112. package/devdocs/LSP8CappedSupplyInitAbstract.json +227 -0
  113. package/devdocs/LSP8CompatibleERC721.json +298 -0
  114. package/devdocs/LSP8CompatibleERC721InitAbstract.json +291 -0
  115. package/devdocs/LSP8CompatibleERC721Mintable.json +290 -0
  116. package/devdocs/LSP8CompatibleERC721MintableInit.json +300 -0
  117. package/devdocs/LSP8IdentifiableDigitalAsset.json +230 -0
  118. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +223 -0
  119. package/devdocs/LSP8Mintable.json +242 -0
  120. package/devdocs/LSP8MintableInit.json +245 -0
  121. package/devdocs/LSP9Vault.json +171 -0
  122. package/devdocs/LSP9VaultInit.json +175 -0
  123. package/devdocs/UniversalProfile.json +199 -0
  124. package/devdocs/UniversalProfileInit.json +202 -0
  125. package/devdocs/UniversalReceiverAddressStore.json +9 -0
  126. package/dist/constants.cjs.js +31569 -0
  127. package/dist/constants.d.ts +31681 -0
  128. package/dist/constants.es.js +31550 -0
  129. package/package.json +69 -52
  130. package/userdocs/Create2Factory.json +5 -0
  131. package/userdocs/LSP0ERC725Account.json +47 -0
  132. package/userdocs/LSP0ERC725AccountInit.json +47 -0
  133. package/userdocs/LSP11BasicSocialRecovery.json +29 -0
  134. package/userdocs/LSP11BasicSocialRecoveryInit.json +29 -0
  135. package/userdocs/LSP16UniversalFactory.json +5 -0
  136. package/userdocs/LSP1UniversalReceiverDelegateUP.json +10 -0
  137. package/userdocs/LSP1UniversalReceiverDelegateVault.json +10 -0
  138. package/userdocs/LSP4Compatibility.json +20 -0
  139. package/userdocs/LSP4DigitalAssetMetadata.json +23 -0
  140. package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +20 -0
  141. package/userdocs/LSP6KeyManager.json +18 -0
  142. package/userdocs/LSP6KeyManagerInit.json +18 -0
  143. package/userdocs/LSP7CappedSupply.json +29 -0
  144. package/userdocs/LSP7CappedSupplyInitAbstract.json +26 -0
  145. package/userdocs/LSP7CompatibleERC20.json +35 -0
  146. package/userdocs/LSP7CompatibleERC20InitAbstract.json +32 -0
  147. package/userdocs/LSP7CompatibleERC20Mintable.json +32 -0
  148. package/userdocs/LSP7CompatibleERC20MintableInit.json +35 -0
  149. package/userdocs/LSP7DigitalAsset.json +29 -0
  150. package/userdocs/LSP7DigitalAssetInitAbstract.json +26 -0
  151. package/userdocs/LSP7Mintable.json +29 -0
  152. package/userdocs/LSP7MintableInit.json +29 -0
  153. package/userdocs/LSP8CappedSupply.json +23 -0
  154. package/userdocs/LSP8CappedSupplyInitAbstract.json +20 -0
  155. package/userdocs/LSP8CompatibleERC721.json +29 -0
  156. package/userdocs/LSP8CompatibleERC721InitAbstract.json +26 -0
  157. package/userdocs/LSP8CompatibleERC721Mintable.json +26 -0
  158. package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -0
  159. package/userdocs/LSP8IdentifiableDigitalAsset.json +23 -0
  160. package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +20 -0
  161. package/userdocs/LSP8Mintable.json +23 -0
  162. package/userdocs/LSP8MintableInit.json +23 -0
  163. package/userdocs/LSP9Vault.json +38 -0
  164. package/userdocs/LSP9VaultInit.json +38 -0
  165. package/userdocs/UniversalProfile.json +50 -0
  166. package/userdocs/UniversalProfileInit.json +50 -0
  167. package/userdocs/UniversalReceiverAddressStore.json +5 -0
  168. package/CONTRIBUTING.md +0 -57
  169. package/common/constants.d.ts +0 -461
  170. package/common/constants.js +0 -789
  171. package/contracts/Utils/GasLib.sol +0 -17
  172. package/module/constants.d.ts +0 -461
  173. package/module/constants.js +0 -786
@@ -5,9 +5,35 @@ pragma solidity ^0.8.4;
5
5
  import {LSP0ERC725AccountInitAbstract} from "./LSP0ERC725AccountInitAbstract.sol";
6
6
 
7
7
  /**
8
- * @title Deployable Proxy Implementation of ERC725Account
9
- * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
10
- * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
8
+ * @title Deployable Proxy Implementation of LSP0-ERC725Account Standard
9
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-0-ERC725Account.md
10
+ *
11
+ * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42)
12
+ * @dev A smart contract account including basic functionalities such as:
13
+ *
14
+ * - Detecting supported standards using ERC165
15
+ * https://eips.ethereum.org/EIPS/eip-165
16
+ *
17
+ * - Executing several operation on other addresses including creating contracts using ERC725X
18
+ * https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md
19
+ *
20
+ * - Storing data in a generic way using ERC725Y
21
+ * https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md
22
+ *
23
+ * - Validating signatures using ERC1271
24
+ * https://eips.ethereum.org/EIPS/eip-1271
25
+ *
26
+ * - Receiving notification and react on them using LSP1
27
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-1-UniversalReceiver.md
28
+ *
29
+ * - Secure ownership management using LSP14
30
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-14-Ownable2Step.md
31
+ *
32
+ * - Extending the account with new functions and interfaceIds of future standards using LSP17
33
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-17-ContractExtension.md
34
+ *
35
+ * - Verifying calls on the owner to allow unified and standard interaction with the account using LSP20
36
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-20-CallVerification.md
11
37
  */
12
38
  contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
13
39
  /**
@@ -18,7 +44,7 @@ contract LSP0ERC725AccountInit is LSP0ERC725AccountInitAbstract {
18
44
  }
19
45
 
20
46
  /**
21
- * @notice Sets the owner of the contract
47
+ * @dev Sets the owner of the contract
22
48
  * @param newOwner the owner of the contract
23
49
  */
24
50
  function initialize(address newOwner) external payable virtual initializer {
@@ -7,11 +7,45 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
7
7
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
8
8
 
9
9
  /**
10
- * @title Inheritable Proxy Implementation of ERC725Account
11
- * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
12
- * @dev Bundles ERC725X and ERC725Y, ERC1271 and LSP1UniversalReceiver and allows receiving native tokens
10
+ * @title Inheritable Proxy Implementation of LSP0-ERC725Account Standard
11
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-0-ERC725Account.md
12
+ *
13
+ * @author Fabian Vogelsteller <fabian@lukso.network>, Jean Cavallera (CJ42)
14
+ * @dev A smart contract account including basic functionalities such as:
15
+ *
16
+ * - Detecting supported standards using ERC165
17
+ * https://eips.ethereum.org/EIPS/eip-165
18
+ *
19
+ * - Executing several operation on other addresses including creating contracts using ERC725X
20
+ * https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md
21
+ *
22
+ * - Storing data in a generic way using ERC725Y
23
+ * https://github.com/ERC725Alliance/ERC725/blob/develop/docs/ERC-725.md
24
+ *
25
+ * - Validating signatures using ERC1271
26
+ * https://eips.ethereum.org/EIPS/eip-1271
27
+ *
28
+ * - Receiving notification and react on them using LSP1
29
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-1-UniversalReceiver.md
30
+ *
31
+ * - Secure ownership management using LSP14
32
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-14-Ownable2Step.md
33
+ *
34
+ * - Extending the account with new functions and interfaceIds of future standards using LSP17
35
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-17-ContractExtension.md
36
+ *
37
+ * - Verifying calls on the owner to allow unified and standard interaction with the account using LSP20
38
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-20-CallVerification.md
13
39
  */
14
40
  abstract contract LSP0ERC725AccountInitAbstract is Initializable, LSP0ERC725AccountCore {
41
+ /**
42
+ * @notice Initializing the contract owner to: `newOwner`
43
+ * @dev Sets the owner of the contract. ERC725X & ERC725Y parent contracts
44
+ * are not initialised as they don't have non-zero initial state.
45
+ * If you decide to add non-zero initial state to any of those
46
+ * contracts, you MUST initialize them here
47
+ * @param newOwner the owner of the contract
48
+ */
15
49
  function _initialize(address newOwner) internal virtual onlyInitializing {
16
50
  if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
17
51
  OwnableUnset._setOwner(newOwner);
@@ -6,7 +6,6 @@ import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
6
6
 
7
7
  // constants
8
8
  import {
9
- _INTERFACEID_LSP1,
10
9
  _LSP1_UNIVERSAL_RECEIVER_DELEGATE_PREFIX,
11
10
  _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY
12
11
  } from "../LSP1UniversalReceiver/LSP1Constants.sol";
@@ -83,12 +83,16 @@ library LSP10Utils {
83
83
 
84
84
  uint128 newArrayLength = oldArrayLength + 1;
85
85
 
86
+ // store the number of received vaults incremented by 1
86
87
  keys[0] = _LSP10_VAULTS_ARRAY_KEY;
87
88
  values[0] = bytes.concat(bytes16(newArrayLength));
88
89
 
90
+ // store the address of the vault under the element key in the array
89
91
  keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(_LSP10_VAULTS_ARRAY_KEY, oldArrayLength);
90
92
  values[1] = bytes.concat(bytes20(vault));
91
93
 
94
+ // store the interfaceId and the location in the array of the asset
95
+ // under the LSP5ReceivedAssetMap key
92
96
  keys[2] = vaultMapKey;
93
97
  values[2] = bytes.concat(_INTERFACEID_LSP9, bytes16(oldArrayLength));
94
98
  }
@@ -98,12 +102,12 @@ library LSP10Utils {
98
102
  * @param sender The address sending the vault and where the Keys should be updated
99
103
  * @param vaultMapKey The map key of the vault being sent containing the interfaceId of the
100
104
  * vault and the index in the array
101
- * @param vaultInterfaceIdAndIndex The value of the map key of the vault being sent
105
+ * @param vaultIndex The index where the vault address is stored under `LSP10Vaults[]` Array
102
106
  */
103
107
  function generateSentVaultKeys(
104
108
  address sender,
105
109
  bytes32 vaultMapKey,
106
- bytes memory vaultInterfaceIdAndIndex
110
+ uint128 vaultIndex
107
111
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
108
112
  IERC725Y account = IERC725Y(sender);
109
113
  bytes memory lsp10VaultsCountValue = getLSP10ReceivedVaultsCount(account);
@@ -122,15 +126,17 @@ library LSP10Utils {
122
126
  revert VaultIndexSuperiorToUint128(oldArrayLength);
123
127
  }
124
128
 
129
+ // Updating the number of the received vaults (decrementing by 1
125
130
  uint128 newArrayLength = oldArrayLength - 1;
126
131
 
127
- uint128 index = extractIndexFromMap(vaultInterfaceIdAndIndex);
132
+ // Generate the element key in the array of the vault
128
133
  bytes32 vaultInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
129
134
  _LSP10_VAULTS_ARRAY_KEY,
130
- index
135
+ vaultIndex
131
136
  );
132
137
 
133
- if (index == newArrayLength) {
138
+ // If the asset to remove is the last element in the array
139
+ if (vaultIndex == newArrayLength) {
134
140
  /**
135
141
  * We will be updating/removing 3 keys:
136
142
  * - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received vaults
@@ -140,18 +146,21 @@ library LSP10Utils {
140
146
  keys = new bytes32[](3);
141
147
  values = new bytes[](3);
142
148
 
149
+ // store the number of received vaults decremented by 1
143
150
  keys[0] = _LSP10_VAULTS_ARRAY_KEY;
144
151
  values[0] = bytes.concat(bytes16(newArrayLength));
145
152
 
153
+ // remove the address of the vault from the element key
146
154
  keys[1] = vaultInArrayKey;
147
155
  values[1] = "";
148
156
 
157
+ // remove the interfaceId and the location in the array of the vault
149
158
  keys[2] = vaultMapKey;
150
159
  values[2] = "";
151
160
 
152
161
  // Swapping last element in ArrayKey with the element in ArrayKey to remove || {Swap and pop} method;
153
162
  // check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
154
- } else {
163
+ } else if (vaultIndex < newArrayLength) {
155
164
  /**
156
165
  * We will be updating/removing 5 keys:
157
166
  * - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received vaults
@@ -163,46 +172,52 @@ library LSP10Utils {
163
172
  keys = new bytes32[](5);
164
173
  values = new bytes[](5);
165
174
 
175
+ // store the number of received vaults decremented by 1
166
176
  keys[0] = _LSP10_VAULTS_ARRAY_KEY;
167
177
  values[0] = bytes.concat(bytes16(newArrayLength));
168
178
 
179
+ // remove the interfaceId and the location in the array of the vault
169
180
  keys[1] = vaultMapKey;
170
181
  values[1] = "";
171
182
 
172
183
  // Generate all data Keys/values of the last element in Array to swap
173
184
  // with data Keys/values of the vault to remove
185
+
186
+ // Generate the element key of the last vault in the array
174
187
  bytes32 lastVaultInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
175
188
  _LSP10_VAULTS_ARRAY_KEY,
176
189
  newArrayLength
177
190
  );
178
191
 
192
+ // Get the address of the vault from the element key of the last vault in the array
179
193
  bytes20 lastVaultInArrayAddress = bytes20(account.getData(lastVaultInArrayKey));
180
194
 
195
+ // Generate the map key of the last vault in the array
181
196
  bytes32 lastVaultInArrayMapKey = LSP2Utils.generateMappingKey(
182
197
  _LSP10_VAULTS_MAP_KEY_PREFIX,
183
198
  lastVaultInArrayAddress
184
199
  );
185
200
 
201
+ // Set the address of the last vault instead of the asset to be sent
202
+ // under the element data key in the array
186
203
  keys[2] = vaultInArrayKey;
187
204
  values[2] = bytes.concat(lastVaultInArrayAddress);
188
205
 
206
+ // Remove the address swapped (last vault in the array) from the last element data key in the array
189
207
  keys[3] = lastVaultInArrayKey;
190
208
  values[3] = "";
191
209
 
210
+ // Update the index and the interfaceId of the address swapped (last vault in the array)
211
+ // to point to the new location in the LSP10Vaults array
192
212
  keys[4] = lastVaultInArrayMapKey;
193
- values[4] = bytes.concat(_INTERFACEID_LSP9, bytes16(index));
213
+ values[4] = bytes.concat(_INTERFACEID_LSP9, bytes16(vaultIndex));
214
+ } else {
215
+ // If index is bigger than the array length, out of bounds
216
+ return (keys, values);
194
217
  }
195
218
  }
196
219
 
197
220
  function getLSP10ReceivedVaultsCount(IERC725Y account) internal view returns (bytes memory) {
198
221
  return account.getData(_LSP10_VAULTS_ARRAY_KEY);
199
222
  }
200
-
201
- /**
202
- * @dev returns the index from the LSP10VaultMap
203
- */
204
- function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint128) {
205
- bytes memory val = BytesLib.slice(mapValue, 4, 16);
206
- return BytesLib.toUint128(val, 0);
207
- }
208
223
  }
@@ -12,7 +12,6 @@ import {ERC725} from "@erc725/smart-contracts/contracts/ERC725.sol";
12
12
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
13
13
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
14
14
  import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
15
- import {LSP6KeyManager} from "../LSP6KeyManager/LSP6KeyManager.sol";
16
15
 
17
16
  // constants
18
17
  import {ALL_REGULAR_PERMISSIONS} from "../LSP6KeyManager/LSP6Constants.sol";
@@ -2,7 +2,6 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
6
5
  import {LSP11BasicSocialRecoveryInitAbstract} from "./LSP11BasicSocialRecoveryInitAbstract.sol";
7
6
 
8
7
  /**
@@ -3,11 +3,9 @@ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {ILSP14Ownable2Step} from "./ILSP14Ownable2Step.sol";
6
- import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
7
6
 
8
7
  // modules
9
8
  import {OwnableUnset} from "@erc725/smart-contracts/contracts/custom/OwnableUnset.sol";
10
- import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
11
9
 
12
10
  // libraries
13
11
  import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
@@ -21,7 +19,6 @@ import {
21
19
  _TYPEID_LSP14_OwnershipTransferred_SenderNotification,
22
20
  _TYPEID_LSP14_OwnershipTransferred_RecipientNotification
23
21
  } from "./LSP14Constants.sol";
24
- import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
25
22
 
26
23
  /**
27
24
  * @title LSP14Ownable2Step
@@ -37,12 +34,12 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
37
34
  * @dev The number of block that MUST pass before one is able to
38
35
  * confirm renouncing ownership
39
36
  */
40
- uint256 public constant RENOUNCE_OWNERSHIP_CONFIRMATION_DELAY = 100;
37
+ uint256 public constant RENOUNCE_OWNERSHIP_CONFIRMATION_DELAY = 200;
41
38
 
42
39
  /**
43
40
  * @dev The number of blocks during which one can renounce ownership
44
41
  */
45
- uint256 public constant RENOUNCE_OWNERSHIP_CONFIRMATION_PERIOD = 100;
42
+ uint256 public constant RENOUNCE_OWNERSHIP_CONFIRMATION_PERIOD = 200;
46
43
 
47
44
  /**
48
45
  * @dev The block number saved when initiating the process of renouncing ownerhsip
@@ -152,7 +149,9 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
152
149
  uint256 confirmationPeriodEnd = confirmationPeriodStart +
153
150
  RENOUNCE_OWNERSHIP_CONFIRMATION_PERIOD;
154
151
 
155
- if (currentBlock > confirmationPeriodEnd) {
152
+ // On the creation of a new network, `currentBlock` will be smaller than `confirmationPeriodEnd`,
153
+ // `_renounceOwnershipStartedAt == 0` will indicate that a renounceOwnership call is happening for the first time
154
+ if (currentBlock > confirmationPeriodEnd || _renounceOwnershipStartedAt == 0) {
156
155
  _renounceOwnershipStartedAt = currentBlock;
157
156
  delete _pendingOwner;
158
157
  emit RenounceOwnershipStarted();
@@ -165,7 +164,6 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
165
164
 
166
165
  _setOwner(address(0));
167
166
  delete _renounceOwnershipStartedAt;
168
- delete _pendingOwner;
169
167
  emit OwnershipRenounced();
170
168
  }
171
169
  }
@@ -54,13 +54,18 @@ abstract contract LSP17Extendable is ERC165 {
54
54
  function _getExtension(bytes4 functionSelector) internal view virtual returns (address);
55
55
 
56
56
  /**
57
- * @dev Forwards the call to an extension mapped to a function selector. If no extension address
58
- * is mapped to the function selector (address(0)), then revert.
57
+ * @dev Forwards the call to an extension mapped to a function selector.
59
58
  *
60
- * The call to the extension is appended with bytes20 (msg.sender) and bytes32 (msg.value).
61
- * Returns the return value on success and revert in case of failure.
59
+ * Calls {_getExtension} to get the address of the extension mapped to the function selector being
60
+ * called on the account. If there is no extension, the address(0) will be returned.
62
61
  *
63
- * As the function uses assembly {return()/revert()} to terminate the call, it cannot be
62
+ * Reverts if there is no extension for the function being called.
63
+ *
64
+ * If there is an extension for the function selector being called, it calls the extension with the
65
+ * CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
66
+ * 32 bytes of the {msg.value}
67
+ *
68
+ * Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
64
69
  * called before other codes in fallback().
65
70
  *
66
71
  * Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
@@ -27,10 +27,6 @@ interface ILSP1UniversalReceiver {
27
27
  * @param data The arbitrary data received with the call
28
28
  * @dev Emits an event when it's succesfully executed
29
29
  *
30
- * Call the universalReceiverDelegate function in the UniversalReceiverDelegate (URD) contract, if the address of the URD
31
- * was set as a value for the `_UniversalReceiverKey` in the account key/value value store of the same contract implementing
32
- * the universalReceiver function and if the URD contract has the LSP1UniversalReceiverDelegate Interface Id registred using ERC165
33
- *
34
30
  * Emits a {UniversalReceiver} event
35
31
  */
36
32
  function universalReceiver(bytes32 typeId, bytes calldata data)
@@ -4,18 +4,15 @@ pragma solidity ^0.8.4;
4
4
  // interfaces
5
5
  import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
6
6
  import {ILSP1UniversalReceiver} from "../ILSP1UniversalReceiver.sol";
7
- import {ILSP6KeyManager} from "../../LSP6KeyManager/ILSP6KeyManager.sol";
8
7
  import {ILSP7DigitalAsset} from "../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
9
8
 
10
9
  // modules
11
10
  import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
12
- import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
13
11
 
14
12
  // libraries
15
13
  import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
16
14
  import {LSP1Utils} from "../LSP1Utils.sol";
17
15
  import {LSP2Utils} from "../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
18
- import {LSP6Utils} from "../../LSP6KeyManager/LSP6Utils.sol";
19
16
  import {LSP5Utils} from "../../LSP5ReceivedAssets/LSP5Utils.sol";
20
17
  import {LSP10Utils} from "../../LSP10ReceivedVaults/LSP10Utils.sol";
21
18
 
@@ -31,22 +28,48 @@ import "../../LSP14Ownable2Step/LSP14Constants.sol";
31
28
  import "../LSP1Errors.sol";
32
29
 
33
30
  /**
34
- * @title Core Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
35
- * the LSP5-ReceivedAsset and LSP10-ReceivedVaults standard and removing the sent vaults and assets.
36
- *
31
+ * @title Implementation of a UniversalReceiverDelegate for LSP0ERC725Account
37
32
  * @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
38
- * @dev Delegate contract of the initial universal receiver
33
+ * @dev This UniversalReceiverDelegate follows the {LSP1-UniversalReceiver} standards and is designed
34
+ * for LSP0ERC725Account contracts.
35
+ *
36
+ * @dev Handles two cases:
37
+ * - Registers the address of received assets (exclusively LSP7 and LSP8) and vaults (exclusively LSP9) according
38
+ * to {LSP5-ReceivedAssets} and {LSP10-ReceivedVaults} respectively
39
+ *
40
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-5-ReceivedAssets.md
41
+ * https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-10-ReceivedVaults.md
42
+ *
43
+ * - Removes the address of registered assets and vaults when the full balance is sent from the LSP0ERC725Account contract
39
44
  *
40
- * Owner of the UniversalProfile MUST be a KeyManager that allows (this) address to setData on the UniversalProfile
45
+ * Requirements:
46
+ * - The contract should be able to setData the LSP5 and LSP10 data Keys according to the logic of the owner
47
+ * of the LSP0ERC725Account.
41
48
  *
49
+ * For example, for contracts that are owned by an LSP6KeyManager, this contract should be granted
50
+ * the SUPER/SETDATA and REENTRANCY Permission.
51
+ *
52
+ * Assets and Vaults that are compliant with this version of the UniversalReceiverDelegate are:
53
+ *
54
+ * - LSP7-DigitalAsset: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-7-DigitalAsset.md
55
+ * - LSP8-IdentifiableDigitalAsset: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-8-IdentifiableDigitalAsset.md
56
+ * - LSP9-Vault: https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-9-Vault.md
42
57
  */
43
58
  contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
44
59
  using ERC165Checker for address;
45
60
 
46
61
  /**
47
- * @inheritdoc ILSP1UniversalReceiver
48
- * @dev Allows to register arrayKeys and Map of incoming vaults and assets and removing them after being sent
49
- * @return result the return value of keyManager's execute function
62
+ * @dev Handles two cases:
63
+ * - Registers the address of received assets (exclusively LSP7 and LSP8) and vaults (exclusively LSP9) according
64
+ * to {LSP5-ReceivedAssets} and {LSP10-ReceivedVaults} respectively
65
+ *
66
+ * - Removes the address of registered assets and vaults when the full balance is sent from the LSP0ERC725Account contract
67
+ *
68
+ * Requirements:
69
+ * - The contract should be able to setData the LSP5 and LSP10 data Keys according to the logic of the owner
70
+ * of the LSP0ERC725Account.
71
+ *
72
+ * - Cannot accept native tokens
50
73
  */
51
74
  function universalReceiver(
52
75
  bytes32 typeId,
@@ -54,40 +77,52 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
54
77
  ) public payable virtual returns (bytes memory result) {
55
78
  if (msg.value != 0) revert NativeTokensNotAccepted();
56
79
 
57
- // This contract acts like a UniversalReceiverDelegate of a UP where we append the
80
+ // This contract acts like a UniversalReceiverDelegate of an LSP0ERC725Account where we append the
58
81
  // address and the value, sent to the universalReceiver function of the LSP0, to the msg.data
59
82
  // Check https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-0-ERC725Account.md#universalreceiver
60
83
  address notifier = address(bytes20(msg.data[msg.data.length - 52:]));
61
84
 
85
+ // Get the supposed mapPrefix and interfaceId based on the typeID
62
86
  (bool invalid, bytes10 mapPrefix, bytes4 interfaceID, bool isReceiving) = LSP1Utils
63
87
  .getTransferDetails(typeId);
64
88
 
89
+ // If it's a typeId different than LSP7/LSP8/LSP9 typeIds
65
90
  if (invalid) return "LSP1: typeId out of scope";
66
91
 
92
+ // The notifier is supposed to be either the LSP7 or LSP8 or LSP9 contract
93
+ // If it's EOA we revert to avoid registering the EOA as asset or vault (spam protection)
67
94
  // solhint-disable avoid-tx-origin
68
95
  if (notifier == tx.origin) revert CannotRegisterEOAsAsAssets(notifier);
69
96
 
70
- // if the contract being transferred doesn't support LSP9, do not register it as a received vault
71
- if (
72
- mapPrefix == _LSP10_VAULTS_MAP_KEY_PREFIX &&
73
- notifier.code.length > 0 &&
74
- !notifier.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP9)
75
- ) {
76
- return "LSP1: not an LSP9Vault ownership transfer";
77
- }
78
-
97
+ // Generate the LSP5ReceivedAssetsMap/LSP10VaultsMap based on the prefix and the notifier
79
98
  bytes32 notifierMapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(notifier));
99
+
100
+ // Query the ERC725Y storage of the LSP0-ERC725Account
80
101
  bytes memory notifierMapValue = IERC725Y(msg.sender).getData(notifierMapKey);
102
+
81
103
  bool isMapValueSet = bytes20(notifierMapValue) != bytes20(0);
82
104
 
83
105
  if (isReceiving) {
106
+ // If the mapValue is set, we assume that all other data keys relevant to the asset/vault
107
+ // are registered in the account, we don't need to re register the asset being received
84
108
  if (isMapValueSet) return "LSP1: asset received is already registered";
85
109
 
86
110
  return _whenReceiving(typeId, notifier, notifierMapKey, interfaceID);
87
111
  } else {
112
+ // If the mapValue is not set, we assume that all other data keys relevant to the asset/vault
113
+ // are not registered in the account, we cannot remove non-existing data keys for the asset being sent
88
114
  if (!isMapValueSet) return "LSP1: asset sent is not registered";
89
115
 
90
- return _whenSending(typeId, notifier, notifierMapKey, notifierMapValue);
116
+ // if the value under the `LSP5ReceivedAssetsMap:<asset-address>` or `LSP10VaultsMap:<vault-address>`
117
+ // is not a valid tuple as `(bytes4,uint128)`
118
+ if (notifierMapValue.length < 20) return "LSP1: asset data corrupted";
119
+
120
+ // Identify where the asset/vault is located in the `LSP5ReceivedAssets[]` / `LSP10Vaults[]` Array
121
+ // by extracting the index from the tuple value `(bytes4,uint128)`
122
+ // fetched under the `LSP5ReceivedAssetsMap` / `LSP10VaultsMap` data key
123
+ uint128 arrayIndex = uint128(uint160(bytes20(notifierMapValue)));
124
+
125
+ return _whenSending(typeId, notifier, notifierMapKey, arrayIndex);
91
126
  }
92
127
  }
93
128
 
@@ -96,7 +131,7 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
96
131
  /**
97
132
  * @dev To avoid stack too deep error
98
133
  * Generate the keys/values of the asset/vault received to set and set them
99
- * on the Key Manager depending on the type of the transfer (asset/vault)
134
+ * on the account depending on the type of the transfer (asset/vault)
100
135
  */
101
136
  function _whenReceiving(
102
137
  bytes32 typeId,
@@ -109,9 +144,13 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
109
144
 
110
145
  // if it's a token transfer (LSP7/LSP8)
111
146
  if (typeId != _TYPEID_LSP9_OwnershipTransferred_RecipientNotification) {
112
- // if the amount sent is 0, then do not update the keys
113
- uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
114
- if (balance == 0) return "LSP1: balance not updated";
147
+ // CHECK balance only when the Token contract is already deployed,
148
+ // not when tokens are being transferred on deployment through the `constructor`
149
+ if (notifier.code.length > 0) {
150
+ // if the amount sent is 0, then do not update the keys
151
+ uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
152
+ if (balance == 0) return "LSP1: balance not updated";
153
+ }
115
154
 
116
155
  (dataKeys, dataValues) = LSP5Utils.generateReceivedAssetKeys(
117
156
  msg.sender,
@@ -120,7 +159,8 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
120
159
  interfaceID
121
160
  );
122
161
 
123
- IERC725Y(msg.sender).setData(dataKeys, dataValues);
162
+ // Set the LSP5 generated data keys on the account
163
+ IERC725Y(msg.sender).setDataBatch(dataKeys, dataValues);
124
164
  return "";
125
165
  } else {
126
166
  (dataKeys, dataValues) = LSP10Utils.generateReceivedVaultKeys(
@@ -129,7 +169,8 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
129
169
  notifierMapKey
130
170
  );
131
171
 
132
- IERC725Y(msg.sender).setData(dataKeys, dataValues);
172
+ // Set the LSP10 generated data keys on the account
173
+ IERC725Y(msg.sender).setDataBatch(dataKeys, dataValues);
133
174
  return "";
134
175
  }
135
176
  }
@@ -137,13 +178,13 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
137
178
  /**
138
179
  * @dev To avoid stack too deep error
139
180
  * Generate the keys/values of the asset/vault sent to set and set them
140
- * on the Key Manager depending on the type of the transfer (asset/vault)
181
+ * on the account depending on the type of the transfer (asset/vault)
141
182
  */
142
183
  function _whenSending(
143
184
  bytes32 typeId,
144
185
  address notifier,
145
186
  bytes32 notifierMapKey,
146
- bytes memory notifierMapValue
187
+ uint128 arrayIndex
147
188
  ) internal virtual returns (bytes memory) {
148
189
  bytes32[] memory dataKeys;
149
190
  bytes[] memory dataValues;
@@ -157,19 +198,35 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
157
198
  (dataKeys, dataValues) = LSP5Utils.generateSentAssetKeys(
158
199
  msg.sender,
159
200
  notifierMapKey,
160
- notifierMapValue
201
+ arrayIndex
161
202
  );
162
203
 
163
- IERC725Y(msg.sender).setData(dataKeys, dataValues);
204
+ /**
205
+ * `generateSentAssetKeys(...)` returns empty arrays in the following cases:
206
+ * - the index returned from the data key `notifierMapKey` is bigger than
207
+ * the length of the `LSP5ReceivedAssets[]`, meaning, index is out of bounds.
208
+ */
209
+ if (dataKeys.length == 0 && dataValues.length == 0) return "LSP1: asset data corrupted";
210
+
211
+ // Set the LSP5 generated data keys on the account
212
+ IERC725Y(msg.sender).setDataBatch(dataKeys, dataValues);
164
213
  return "";
165
214
  } else {
166
215
  (dataKeys, dataValues) = LSP10Utils.generateSentVaultKeys(
167
216
  msg.sender,
168
217
  notifierMapKey,
169
- notifierMapValue
218
+ arrayIndex
170
219
  );
171
220
 
172
- IERC725Y(msg.sender).setData(dataKeys, dataValues);
221
+ /**
222
+ * `generateSentAssetKeys(...)` returns empty arrays in the following cases:
223
+ * - the index returned from the data key `notifierMapKey` is bigger than
224
+ * the length of the `LSP10Vaults[]`, meaning, index is out of bounds.
225
+ */
226
+ if (dataKeys.length == 0 && dataValues.length == 0) return "LSP1: asset data corrupted";
227
+
228
+ // Set the LSP10 generated data keys on the account
229
+ IERC725Y(msg.sender).setDataBatch(dataKeys, dataValues);
173
230
  return "";
174
231
  }
175
232
  }