@lukso/lsp-smart-contracts 0.6.0 → 0.6.1

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 (47) hide show
  1. package/README.md +11 -2
  2. package/artifacts/LSP0ERC725Account.json +26 -20
  3. package/artifacts/LSP0ERC725AccountInit.json +26 -20
  4. package/artifacts/LSP1UniversalReceiverDelegateUP.json +7 -2
  5. package/artifacts/LSP1UniversalReceiverDelegateVault.json +7 -2
  6. package/artifacts/LSP4Compatibility.json +9 -9
  7. package/artifacts/LSP4DigitalAssetMetadata.json +9 -9
  8. package/artifacts/LSP4DigitalAssetMetadataInit.json +9 -9
  9. package/artifacts/LSP6KeyManager.json +2 -2
  10. package/artifacts/LSP6KeyManagerInit.json +2 -2
  11. package/artifacts/LSP7CappedSupply.json +9 -9
  12. package/artifacts/LSP7CappedSupplyInit.json +9 -9
  13. package/artifacts/LSP7CompatibilityForERC20.json +11 -11
  14. package/artifacts/LSP7CompatibilityForERC20Init.json +11 -11
  15. package/artifacts/LSP7DigitalAsset.json +11 -11
  16. package/artifacts/LSP7DigitalAssetInit.json +11 -11
  17. package/artifacts/LSP7Mintable.json +11 -11
  18. package/artifacts/LSP7MintableInit.json +11 -11
  19. package/artifacts/LSP8CappedSupply.json +9 -9
  20. package/artifacts/LSP8CappedSupplyInit.json +9 -9
  21. package/artifacts/LSP8CompatibilityForERC721.json +11 -11
  22. package/artifacts/LSP8CompatibilityForERC721Init.json +11 -11
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +11 -11
  24. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +11 -11
  25. package/artifacts/LSP8Mintable.json +11 -11
  26. package/artifacts/LSP8MintableInit.json +11 -11
  27. package/artifacts/LSP9Vault.json +22 -16
  28. package/artifacts/LSP9VaultInit.json +22 -16
  29. package/artifacts/UniversalProfile.json +26 -20
  30. package/artifacts/UniversalProfileInit.json +26 -20
  31. package/artifacts/UniversalReceiverAddressStore.json +7 -2
  32. package/constants.js +159 -11
  33. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +5 -4
  34. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +3 -0
  35. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
  36. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +1 -1
  37. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +24 -15
  38. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +1 -0
  39. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +22 -15
  40. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +1 -0
  41. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +5 -4
  42. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +1 -1
  43. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +125 -77
  44. package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
  45. package/contracts/LSP9Vault/LSP9VaultCore.sol +5 -4
  46. package/contracts/Legacy/UniversalReceiverAddressStore.sol +2 -1
  47. package/package.json +2 -2
@@ -43,8 +43,8 @@ abstract contract LSP0ERC725AccountCore is
43
43
  /**
44
44
  * @dev Emits an event when receiving native tokens
45
45
  */
46
- receive() external payable {
47
- emit ValueReceived(_msgSender(), msg.value);
46
+ fallback() external payable {
47
+ if (msg.value > 0) emit ValueReceived(msg.sender, msg.value);
48
48
  }
49
49
 
50
50
  // TODO to be discussed
@@ -138,6 +138,7 @@ abstract contract LSP0ERC725AccountCore is
138
138
  */
139
139
  function universalReceiver(bytes32 _typeId, bytes calldata _data)
140
140
  external
141
+ payable
141
142
  virtual
142
143
  override
143
144
  returns (bytes memory returnValue)
@@ -154,9 +155,9 @@ abstract contract LSP0ERC725AccountCore is
154
155
  )
155
156
  ) {
156
157
  returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
157
- .universalReceiverDelegate(_msgSender(), _typeId, _data);
158
+ .universalReceiverDelegate(msg.sender, msg.value, _typeId, _data);
158
159
  }
159
160
  }
160
- emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
161
+ emit UniversalReceiver(msg.sender, msg.value, _typeId, returnValue, _data);
161
162
  }
162
163
  }
@@ -9,12 +9,14 @@ interface ILSP1UniversalReceiver {
9
9
  /**
10
10
  * @notice Emitted when the universalReceiver function is succesfully executed
11
11
  * @param from The address calling the universalReceiver function
12
+ * @param value The amount sent to the universalReceiver function
12
13
  * @param typeId The hash of a specific standard or a hook
13
14
  * @param returnedValue The return value of universalReceiver function
14
15
  * @param receivedData The arbitrary data passed to universalReceiver function
15
16
  */
16
17
  event UniversalReceiver(
17
18
  address indexed from,
19
+ uint256 value,
18
20
  bytes32 indexed typeId,
19
21
  bytes indexed returnedValue,
20
22
  bytes receivedData
@@ -33,5 +35,6 @@ interface ILSP1UniversalReceiver {
33
35
  */
34
36
  function universalReceiver(bytes32 typeId, bytes calldata data)
35
37
  external
38
+ payable
36
39
  returns (bytes memory);
37
40
  }
@@ -9,13 +9,15 @@ pragma solidity ^0.8.0;
9
9
  interface ILSP1UniversalReceiverDelegate {
10
10
  /**
11
11
  * @dev Get called by the universalReceiver function, can be customized to have a specific logic
12
- * @param sender The address calling the universalReceiver function
12
+ * @param caller The address calling the universalReceiver function
13
+ * @param value The amount sent to the universalReceiver function
13
14
  * @param typeId The hash of a specific standard or a hook
14
15
  * @param data The arbitrary data received with the call
15
16
  * @return result Any useful data could be returned
16
17
  */
17
18
  function universalReceiverDelegate(
18
- address sender,
19
+ address caller,
20
+ uint256 value,
19
21
  bytes32 typeId,
20
22
  bytes memory data
21
23
  ) external returns (bytes memory result);
@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
3
3
 
4
4
  // --- ERC165 interface ids
5
5
  bytes4 constant _INTERFACEID_LSP1 = 0x6bb56a14;
6
- bytes4 constant _INTERFACEID_LSP1_DELEGATE = 0xc2d7bcc1;
6
+ bytes4 constant _INTERFACEID_LSP1_DELEGATE = 0xa245bbda;
7
7
 
8
8
  // --- ERC725Y Keys
9
9
 
@@ -24,12 +24,12 @@ import {_TYPEID_LSP9_VAULTSENDER} from "../../../LSP9Vault/LSP9Constants.sol";
24
24
  * @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
25
25
  */
26
26
  abstract contract TokenAndVaultHandling {
27
- // internal functions
28
- function _tokenAndVaultHandling(address sender, bytes32 typeId)
27
+ function _tokenAndVaultHandling(address caller, bytes32 typeId)
29
28
  internal
30
29
  returns (bytes memory result)
31
30
  {
32
- if (sender.code.length == 0) return "";
31
+ // avoid EOAs spamming the storage
32
+ if (caller.code.length == 0) return "";
33
33
 
34
34
  address keyManager = ERC725Y(msg.sender).owner();
35
35
  if (!ERC165Checker.supportsERC165Interface(keyManager, _INTERFACEID_LSP6)) return "";
@@ -38,34 +38,43 @@ abstract contract TokenAndVaultHandling {
38
38
 
39
39
  // check if the caller is the same account controlled by the keyManager
40
40
  if (msg.sender != target) return "";
41
- (bool senderHook, bytes32 arrayKey, bytes12 mapPrefix, bytes4 interfaceID) = LSP1Utils
42
- .getTransferDetails(typeId);
43
41
 
44
- bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(sender));
42
+ (
43
+ bool isReceiving,
44
+ bytes32 arrayLengthKey,
45
+ bytes12 mapPrefix,
46
+ bytes4 interfaceID
47
+ ) = LSP1Utils.getTransferDetails(typeId);
48
+
49
+ bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
45
50
  bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
46
51
 
47
- if (!senderHook) {
48
- // if the map is already set, then do nothing
52
+ if (isReceiving) {
53
+ // if the map value is already set, then do nothing
49
54
  if (bytes12(mapValue) != bytes12(0)) return "";
55
+
50
56
  result = LSP5Utils.addMapAndArrayKeyViaKeyManager(
51
57
  IERC725Y(msg.sender),
52
- arrayKey,
58
+ arrayLengthKey,
53
59
  mapKey,
54
- sender,
60
+ caller,
55
61
  interfaceID,
56
62
  keyManager
57
63
  );
58
- } else if (senderHook) {
59
- // if there is no map for the asset to remove, then do nothing
64
+ } else {
65
+ // if there is no map value for the asset to remove, then do nothing
60
66
  if (bytes12(mapValue) == bytes12(0)) return "";
67
+
68
+ // if it's a token transfer (LSP7/LSP8)
61
69
  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
70
+ // if the amount sent is not the full balance, then do not remove the keys
71
+ uint256 balance = ILSP7DigitalAsset(caller).balanceOf(msg.sender);
64
72
  if (balance != 0) return "";
65
73
  }
74
+
66
75
  result = LSP5Utils.removeMapAndArrayKeyViaKeyManager(
67
76
  IERC725Y(msg.sender),
68
- arrayKey,
77
+ arrayLengthKey,
69
78
  mapPrefix,
70
79
  mapKey,
71
80
  mapValue,
@@ -36,6 +36,7 @@ contract LSP1UniversalReceiverDelegateUP is
36
36
  */
37
37
  function universalReceiverDelegate(
38
38
  address sender,
39
+ uint256 value,
39
40
  bytes32 typeId,
40
41
  bytes memory data // solhint-disable no-unused-vars
41
42
  ) public virtual override returns (bytes memory result) {
@@ -23,44 +23,51 @@ import "../../../LSP9Vault/LSP9Constants.sol";
23
23
  * @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
24
24
  */
25
25
  abstract contract TokenHandling {
26
- // internal functions
27
- function _tokenHandling(address sender, bytes32 typeId) internal returns (bytes memory result) {
28
- if (sender.code.length == 0) return "";
26
+ function _tokenHandling(address caller, bytes32 typeId) internal returns (bytes memory result) {
27
+ // avoid EOAs spamming the storage
28
+ if (caller.code.length == 0) return "";
29
29
 
30
30
  if (!ERC165Checker.supportsERC165Interface(msg.sender, _INTERFACEID_LSP9)) return "";
31
31
 
32
- (bool senderHook, bytes32 arrayKey, bytes12 mapPrefix, bytes4 interfaceID) = LSP1Utils
33
- .getTransferDetails(typeId);
32
+ (
33
+ bool isReceiving,
34
+ bytes32 arrayLengthKey,
35
+ bytes12 mapPrefix,
36
+ bytes4 interfaceID
37
+ ) = LSP1Utils.getTransferDetails(typeId);
34
38
 
35
- bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(sender));
39
+ bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
36
40
  bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
37
41
 
38
- if (!senderHook) {
39
- // if the map is already set, then do nothing
42
+ if (isReceiving) {
43
+ // if the map value is already set, then do nothing
40
44
  if (bytes12(mapValue) != bytes12(0)) return "";
41
45
 
42
46
  (bytes32[] memory keys, bytes[] memory values) = LSP5Utils.addMapAndArrayKey(
43
47
  IERC725Y(msg.sender),
44
- arrayKey,
48
+ arrayLengthKey,
45
49
  mapKey,
46
- sender,
50
+ caller,
47
51
  interfaceID
48
52
  );
53
+
49
54
  IERC725Y(msg.sender).setData(keys, values);
50
- } else if (senderHook) {
51
- // if there is no map for the asset to remove, then do nothing
55
+ } else {
56
+ // if there is no map value for the asset to remove, then do nothing
52
57
  if (bytes12(mapValue) == bytes12(0)) return "";
53
- uint256 balance = ILSP7DigitalAsset(sender).balanceOf(msg.sender);
54
- // if the amount sent is not the full balance, then do nothing
58
+
59
+ // if the amount sent is not the full balance, then do not remove the keys
60
+ uint256 balance = ILSP7DigitalAsset(caller).balanceOf(msg.sender);
55
61
  if (balance != 0) return "";
56
62
 
57
63
  (bytes32[] memory keys, bytes[] memory values) = LSP5Utils.removeMapAndArrayKey(
58
64
  IERC725Y(msg.sender),
59
- arrayKey,
65
+ arrayLengthKey,
60
66
  mapPrefix,
61
67
  mapKey,
62
68
  mapValue
63
69
  );
70
+
64
71
  IERC725Y(msg.sender).setData(keys, values);
65
72
  }
66
73
  }
@@ -32,6 +32,7 @@ contract LSP1UniversalReceiverDelegateVault is
32
32
  */
33
33
  function universalReceiverDelegate(
34
34
  address sender,
35
+ uint256 value,
35
36
  bytes32 typeId,
36
37
  bytes memory data // solhint-disable no-unused-vars
37
38
  ) public virtual override returns (bytes memory result) {
@@ -5,7 +5,7 @@ pragma solidity ^0.8.0;
5
5
  import {_LSP5_RECEIVED_ASSETS_ARRAY_KEY, _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX} from "../LSP5ReceivedAssets/LSP5Constants.sol";
6
6
  import {_INTERFACEID_LSP7, _TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "../LSP7DigitalAsset/LSP7Constants.sol";
7
7
  import {_INTERFACEID_LSP8, _TYPEID_LSP8_TOKENSRECIPIENT, _TYPEID_LSP8_TOKENSSENDER} from "../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
8
- import {_INTERFACEID_LSP9, _TYPEID_LSP9_VAULTSENDER} from "../LSP9Vault/LSP9Constants.sol";
8
+ import {_INTERFACEID_LSP9, _TYPEID_LSP9_VAULTRECIPIENT} from "../LSP9Vault/LSP9Constants.sol";
9
9
  import {_LSP10_VAULTS_ARRAY_KEY, _LSP10_VAULTS_MAP_KEY_PREFIX} from "../LSP10ReceivedVaults/LSP10Constants.sol";
10
10
 
11
11
  library LSP1Utils {
@@ -16,7 +16,7 @@ library LSP1Utils {
16
16
  internal
17
17
  pure
18
18
  returns (
19
- bool senderHook,
19
+ bool isReceiving,
20
20
  bytes32 arrayKey,
21
21
  bytes12 mapPrefix,
22
22
  bytes4 interfaceId
@@ -34,14 +34,15 @@ library LSP1Utils {
34
34
  typeId == _TYPEID_LSP7_TOKENSRECIPIENT
35
35
  ? _INTERFACEID_LSP7
36
36
  : _INTERFACEID_LSP8;
37
- senderHook = typeId == _TYPEID_LSP7_TOKENSSENDER || typeId == _TYPEID_LSP8_TOKENSSENDER
37
+ isReceiving = typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
38
+ typeId == _TYPEID_LSP8_TOKENSRECIPIENT
38
39
  ? true
39
40
  : false;
40
41
  } else {
41
42
  arrayKey = _LSP10_VAULTS_ARRAY_KEY;
42
43
  mapPrefix = _LSP10_VAULTS_MAP_KEY_PREFIX;
43
44
  interfaceId = _INTERFACEID_LSP9;
44
- senderHook = typeId == _TYPEID_LSP9_VAULTSENDER ? true : false;
45
+ isReceiving = typeId == _TYPEID_LSP9_VAULTRECIPIENT ? true : false;
45
46
  }
46
47
  }
47
48
  }
@@ -40,7 +40,7 @@ library LSP2Utils {
40
40
  return keccak256(keyName);
41
41
  }
42
42
 
43
- function generateArrayKeyAtIndex(bytes32 _arrayKey, uint256 _index)
43
+ function generateArrayElementKeyAtIndex(bytes32 _arrayKey, uint256 _index)
44
44
  internal
45
45
  pure
46
46
  returns (bytes32)
@@ -15,139 +15,187 @@ import {_TYPEID_LSP7_TOKENSSENDER} from "../LSP7DigitalAsset/LSP7Constants.sol";
15
15
 
16
16
  library LSP5Utils {
17
17
  /**
18
- * @dev Initiates Map and ArrayKey and sets the length of the Array to `1` if it's not set before,
19
- * If it's already set, it decodes the arrayLength, increment it and adds Map and ArrayKey
18
+ * @dev Generating the data keys/values to be set on the account after receiving assets/vaults
19
+ *
20
+ * @param account The account where the Keys should be added
21
+ * @param arrayLengthKey The arrayLengthKey containing the number of the received assets/vaults
22
+ * @param mapKey The mapKey containing the interfaceID and the index of the asset in the `element in arrayKey`
23
+ * @param caller The address of the asset/vault received
24
+ * @param interfaceID The interfaceID of the asset/vault received
20
25
  */
21
26
  function addMapAndArrayKey(
22
- IERC725Y _account,
23
- bytes32 _arrayKey,
24
- bytes32 _mapKey,
25
- address _sender,
26
- bytes4 _appendix
27
+ IERC725Y account,
28
+ bytes32 arrayLengthKey,
29
+ bytes32 mapKey,
30
+ address caller,
31
+ bytes4 interfaceID
27
32
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
33
+ /**
34
+ * We will be setting 3 keys:
35
+ * - Keys[0]: The arrayLengthKey containing the number of the received assets/vaults
36
+ * - Keys[1]: The element in arrayKey containing the address of each received asset/vault for a specific index
37
+ * - Keys[2]: The mapKey containing the interfaceID and the index of the asset in the `element in arrayKey`
38
+ */
28
39
  keys = new bytes32[](3);
29
40
  values = new bytes[](3);
30
41
 
31
- bytes memory rawArrayLength = _account.getData(_arrayKey);
42
+ bytes memory encodedArrayLength = account.getData(arrayLengthKey);
32
43
 
33
- keys[0] = _arrayKey;
34
- keys[2] = _mapKey;
44
+ // If it's the first asset to receive
45
+ if (encodedArrayLength.length == 0) {
46
+ keys[0] = arrayLengthKey;
47
+ values[0] = UtilsLib.uint256ToBytes(1);
35
48
 
36
- values[1] = UtilsLib.addressToBytes(_sender);
49
+ keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, 0);
50
+ values[1] = UtilsLib.addressToBytes(caller);
37
51
 
38
- if (rawArrayLength.length != 32) {
39
- keys[1] = LSP2Utils.generateArrayKeyAtIndex(_arrayKey, 0);
52
+ keys[2] = mapKey;
53
+ values[2] = bytes.concat(interfaceID, bytes8(0));
40
54
 
41
- values[0] = UtilsLib.uint256ToBytes(1);
42
- values[2] = bytes.concat(_appendix, bytes8(0));
43
- } else if (rawArrayLength.length == 32) {
44
- uint256 arrayLength = abi.decode(rawArrayLength, (uint256));
55
+ // If the storage is already initiated
56
+ } else if (encodedArrayLength.length == 32) {
57
+ uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
45
58
  uint256 newArrayLength = arrayLength + 1;
46
59
 
47
- keys[1] = LSP2Utils.generateArrayKeyAtIndex(_arrayKey, newArrayLength - 1);
48
-
60
+ keys[0] = arrayLengthKey;
49
61
  values[0] = UtilsLib.uint256ToBytes(newArrayLength);
50
- values[2] = bytes.concat(_appendix, bytes8(uint64(arrayLength)));
62
+
63
+ keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, newArrayLength - 1);
64
+ values[1] = UtilsLib.addressToBytes(caller);
65
+
66
+ keys[2] = mapKey;
67
+ values[2] = bytes.concat(interfaceID, bytes8(uint64(arrayLength)));
68
+ } else {
69
+ revert("Invalid length of the LSP5ReceivedAssets[] Key");
51
70
  }
52
71
  }
53
72
 
54
73
  /**
55
- * @dev Decrements the arrayLength, removes the Map, swaps the arrayKey that need to be removed with
56
- * the last `arrayKey` in the array and removes the last arrayKey with updating all modified entries
74
+ * @dev Generating the data keys/values to be removed/changed on the account after sending assets/vaults
75
+ *
76
+ * @param account The account where the Keys should be added
77
+ * @param arrayLengthKey The arrayLengthKey containing the number of the received assets/vaults
78
+ * @param mapKeyPrefix The mapKey prefix relative to LSP5ReceivedAssetsMap or LSP10VaultsMap Keys
79
+ * @param mapKeyToRemove The mapKey of the asset sent
80
+ * @param mapValue The mapValue of the asset/vault sent
57
81
  */
58
82
  function removeMapAndArrayKey(
59
- IERC725Y _account,
60
- bytes32 _arrayKey,
61
- bytes12 mapPrefix,
62
- bytes32 _mapKeyToRemove,
83
+ IERC725Y account,
84
+ bytes32 arrayLengthKey,
85
+ bytes12 mapKeyPrefix,
86
+ bytes32 mapKeyToRemove,
63
87
  bytes memory mapValue
64
88
  ) internal view returns (bytes32[] memory keys, bytes[] memory values) {
65
- uint64 index = extractIndexFromMap(mapValue);
66
- bytes32 arrayKeyToRemove = LSP2Utils.generateArrayKeyAtIndex(_arrayKey, index);
67
-
68
- bytes memory rawArrayLength = _account.getData(_arrayKey);
69
-
70
- uint256 arrayLength = abi.decode(rawArrayLength, (uint256));
71
-
89
+ // Updating the number of the received assets/vaults
90
+ bytes memory encodedArrayLength = account.getData(arrayLengthKey);
91
+ uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
72
92
  uint256 newLength = arrayLength - 1;
73
93
 
94
+ uint64 index = extractIndexFromMap(mapValue);
95
+ bytes32 arrayElementKeyToRemove = LSP2Utils.generateArrayElementKeyAtIndex(
96
+ arrayLengthKey,
97
+ index
98
+ );
99
+
74
100
  if (index == (arrayLength - 1)) {
101
+ /**
102
+ * We will be updating/removing 3 keys:
103
+ * - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets/vaults
104
+ * - Keys[1]: [Remove] The element in arrayKey (Remove the address of the asset sent)
105
+ * - Keys[2]: [Remove] The mapKey (Remove the interfaceId and the index of the asset sent)
106
+ */
75
107
  keys = new bytes32[](3);
76
108
  values = new bytes[](3);
77
109
 
78
- keys[0] = _arrayKey;
110
+ keys[0] = arrayLengthKey;
79
111
  values[0] = UtilsLib.uint256ToBytes(newLength);
80
112
 
81
- keys[1] = _mapKeyToRemove;
113
+ keys[1] = mapKeyToRemove;
82
114
  values[1] = "";
83
115
 
84
- keys[2] = arrayKeyToRemove;
116
+ keys[2] = arrayElementKeyToRemove;
85
117
  values[2] = "";
118
+
119
+ // Swapping last element in ArrayKey with the elemnt in ArrayKey to remove || {Swap and pop} method;
120
+ // check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
86
121
  } else {
122
+ /**
123
+ * We will be updating/removing 5 keys:
124
+ * - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets/vaults
125
+ * - Keys[1]: [Remove] The mapKey of the asset to remove (Remove the interfaceId and the index of the asset sent)
126
+ * - Keys[2]: [Update] The element in arrayKey to remove (Swap with the address of the last element in Array)
127
+ * - Keys[3]: [Remove] The last element in arrayKey (Remove (pop) the address of the last element as it's already swapped)
128
+ * - Keys[4]: [Update] The mapKey of the last element in array (Update the new index and the interfaceID)
129
+ */
87
130
  keys = new bytes32[](5);
88
131
  values = new bytes[](5);
89
132
 
90
- keys[0] = _arrayKey;
133
+ keys[0] = arrayLengthKey;
91
134
  values[0] = UtilsLib.uint256ToBytes(newLength);
92
135
 
93
- keys[1] = _mapKeyToRemove;
136
+ keys[1] = mapKeyToRemove;
94
137
  values[1] = "";
95
138
 
96
- bytes32 lastKey = LSP2Utils.generateArrayKeyAtIndex(_arrayKey, newLength);
97
-
98
- bytes memory lastKeyValue = _account.getData(lastKey);
99
-
100
- bytes32 mapOfLastkey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(lastKeyValue));
101
-
102
- bytes memory mapValueOfLastkey = _account.getData(mapOfLastkey);
103
-
104
- bytes memory appendix = BytesLib.slice(mapValueOfLastkey, 0, 4);
105
-
106
- keys[2] = arrayKeyToRemove;
107
- values[2] = lastKeyValue;
108
-
109
- keys[3] = lastKey;
139
+ // Generate all data Keys/values of the last element in Array to swap
140
+ // with data Keys/values of the asset to remove
141
+ bytes32 lastArrayElementKey = LSP2Utils.generateArrayElementKeyAtIndex(
142
+ arrayLengthKey,
143
+ newLength
144
+ );
145
+ bytes memory lastArrayElementValue = account.getData(lastArrayElementKey);
146
+
147
+ bytes32 lastArrayElementMapKey = LSP2Utils.generateMappingKey(
148
+ mapKeyPrefix,
149
+ bytes20(lastArrayElementValue)
150
+ );
151
+ bytes memory lastArrayElementMapValue = account.getData(lastArrayElementMapKey);
152
+ bytes memory interfaceID = BytesLib.slice(lastArrayElementMapValue, 0, 4);
153
+
154
+ keys[2] = arrayElementKeyToRemove;
155
+ values[2] = lastArrayElementValue;
156
+
157
+ keys[3] = lastArrayElementKey;
110
158
  values[3] = "";
111
159
 
112
- keys[4] = mapOfLastkey;
113
- values[4] = bytes.concat(appendix, bytes8(index));
160
+ keys[4] = lastArrayElementMapKey;
161
+ values[4] = bytes.concat(interfaceID, bytes8(index));
114
162
  }
115
163
  }
116
164
 
117
165
  function addMapAndArrayKeyViaKeyManager(
118
- IERC725Y _account,
119
- bytes32 _arrayKey,
120
- bytes32 _mapKey,
121
- address _sender,
122
- bytes4 _appendix,
123
- address _keyManager
166
+ IERC725Y account,
167
+ bytes32 arrayLengthKey,
168
+ bytes32 mapKey,
169
+ address caller,
170
+ bytes4 interfaceID,
171
+ address keyManager
124
172
  ) internal returns (bytes memory result) {
125
- (bytes32[] memory _keys, bytes[] memory _values) = addMapAndArrayKey(
126
- _account,
127
- _arrayKey,
128
- _mapKey,
129
- _sender,
130
- _appendix
173
+ (bytes32[] memory keys, bytes[] memory values) = addMapAndArrayKey(
174
+ account,
175
+ arrayLengthKey,
176
+ mapKey,
177
+ caller,
178
+ interfaceID
131
179
  );
132
- result = LSP6Utils.setDataViaKeyManager(_keyManager, _keys, _values);
180
+ result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
133
181
  }
134
182
 
135
183
  function removeMapAndArrayKeyViaKeyManager(
136
- IERC725Y _account,
137
- bytes32 _arrayKey,
138
- bytes12 mapPrefix,
139
- bytes32 _mapKeyToRemove,
184
+ IERC725Y account,
185
+ bytes32 arrayLengthKey,
186
+ bytes12 mapKeyPrefix,
187
+ bytes32 mapKeyToRemove,
140
188
  bytes memory mapValue,
141
189
  address keyManager
142
190
  ) internal returns (bytes memory result) {
143
- (bytes32[] memory _keys, bytes[] memory _values) = removeMapAndArrayKey(
144
- _account,
145
- _arrayKey,
146
- mapPrefix,
147
- _mapKeyToRemove,
191
+ (bytes32[] memory keys, bytes[] memory values) = removeMapAndArrayKey(
192
+ account,
193
+ arrayLengthKey,
194
+ mapKeyPrefix,
195
+ mapKeyToRemove,
148
196
  mapValue
149
197
  );
150
- result = LSP6Utils.setDataViaKeyManager(keyManager, _keys, _values);
198
+ result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
151
199
  }
152
200
 
153
201
  function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint64) {
@@ -12,7 +12,7 @@ bytes32 constant _LSP9_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b600007c033
12
12
  // bytes4(keccak256('LSP9Vault'))
13
13
  bytes constant _LSP9_SUPPORTED_STANDARDS_VALUE = hex"7c0334a1";
14
14
 
15
- // --- Token Hooks
15
+ // --- Vault Hooks
16
16
 
17
17
  // keccak256("LSP9VaultSender")
18
18
  bytes32 constant _TYPEID_LSP9_VAULTSENDER = 0x3ca9f769340018257ac15b3a00e502e8fb730d66086f774210f84d0205af31e7;
@@ -57,8 +57,8 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ClaimOwnership, ILSP1Univers
57
57
  /**
58
58
  * @dev Emits an event when receiving native tokens
59
59
  */
60
- receive() external payable {
61
- emit ValueReceived(_msgSender(), msg.value);
60
+ fallback() external payable {
61
+ if (msg.value > 0) emit ValueReceived(msg.sender, msg.value);
62
62
  }
63
63
 
64
64
  // ERC165
@@ -149,6 +149,7 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ClaimOwnership, ILSP1Univers
149
149
  */
150
150
  function universalReceiver(bytes32 _typeId, bytes calldata _data)
151
151
  external
152
+ payable
152
153
  virtual
153
154
  override
154
155
  returns (bytes memory returnValue)
@@ -165,10 +166,10 @@ contract LSP9VaultCore is ERC725XCore, ERC725YCore, ClaimOwnership, ILSP1Univers
165
166
  )
166
167
  ) {
167
168
  returnValue = ILSP1UniversalReceiverDelegate(universalReceiverDelegate)
168
- .universalReceiverDelegate(_msgSender(), _typeId, _data);
169
+ .universalReceiverDelegate(msg.sender, msg.value, _typeId, _data);
169
170
  }
170
171
  }
171
- emit UniversalReceiver(_msgSender(), _typeId, returnValue, _data);
172
+ emit UniversalReceiver(msg.sender, msg.value, _typeId, returnValue, _data);
172
173
  }
173
174
 
174
175
  // internal functions
@@ -18,7 +18,7 @@ contract UniversalReceiverAddressStore is
18
18
  {
19
19
  using EnumerableSet for EnumerableSet.AddressSet;
20
20
 
21
- bytes4 internal constant _INTERFACE_ID_LSP1DELEGATE = 0xc2d7bcc1;
21
+ bytes4 internal constant _INTERFACE_ID_LSP1DELEGATE = 0xa245bbda;
22
22
 
23
23
  bytes32 internal constant _TOKENS_RECIPIENT_INTERFACE_HASH =
24
24
  0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b; // keccak256("ERC777TokensRecipient")
@@ -40,6 +40,7 @@ contract UniversalReceiverAddressStore is
40
40
 
41
41
  function universalReceiverDelegate(
42
42
  address sender,
43
+ uint256 value,
43
44
  bytes32 typeId,
44
45
  bytes memory
45
46
  ) external override onlyAccount returns (bytes memory) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukso/lsp-smart-contracts",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "The reference implementation for universal profiles smart contracts",
5
5
  "directories": {
6
6
  "test": "test"
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "homepage": "https://github.com/lukso-network/lsp-smart-contracts#readme",
58
58
  "dependencies": {
59
- "@erc725/smart-contracts": "^3.1.0",
59
+ "@erc725/smart-contracts": "^3.1.1",
60
60
  "@openzeppelin/contracts": "^4.6.0",
61
61
  "solidity-bytes-utils": "0.8.0"
62
62
  },