@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.
- package/README.md +11 -2
- package/artifacts/LSP0ERC725Account.json +26 -20
- package/artifacts/LSP0ERC725AccountInit.json +26 -20
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +7 -2
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +7 -2
- package/artifacts/LSP4Compatibility.json +9 -9
- package/artifacts/LSP4DigitalAssetMetadata.json +9 -9
- package/artifacts/LSP4DigitalAssetMetadataInit.json +9 -9
- package/artifacts/LSP6KeyManager.json +2 -2
- package/artifacts/LSP6KeyManagerInit.json +2 -2
- package/artifacts/LSP7CappedSupply.json +9 -9
- package/artifacts/LSP7CappedSupplyInit.json +9 -9
- package/artifacts/LSP7CompatibilityForERC20.json +11 -11
- package/artifacts/LSP7CompatibilityForERC20Init.json +11 -11
- package/artifacts/LSP7DigitalAsset.json +11 -11
- package/artifacts/LSP7DigitalAssetInit.json +11 -11
- package/artifacts/LSP7Mintable.json +11 -11
- package/artifacts/LSP7MintableInit.json +11 -11
- package/artifacts/LSP8CappedSupply.json +9 -9
- package/artifacts/LSP8CappedSupplyInit.json +9 -9
- package/artifacts/LSP8CompatibilityForERC721.json +11 -11
- package/artifacts/LSP8CompatibilityForERC721Init.json +11 -11
- package/artifacts/LSP8IdentifiableDigitalAsset.json +11 -11
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +11 -11
- package/artifacts/LSP8Mintable.json +11 -11
- package/artifacts/LSP8MintableInit.json +11 -11
- package/artifacts/LSP9Vault.json +22 -16
- package/artifacts/LSP9VaultInit.json +22 -16
- package/artifacts/UniversalProfile.json +26 -20
- package/artifacts/UniversalProfileInit.json +26 -20
- package/artifacts/UniversalReceiverAddressStore.json +7 -2
- package/constants.js +159 -11
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +5 -4
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +3 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
- package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +1 -1
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +24 -15
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +1 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +22 -15
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +1 -0
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +5 -4
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +1 -1
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +125 -77
- package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
- package/contracts/LSP9Vault/LSP9VaultCore.sol +5 -4
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +2 -1
- 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
|
-
|
|
47
|
-
emit ValueReceived(
|
|
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(
|
|
158
|
+
.universalReceiverDelegate(msg.sender, msg.value, _typeId, _data);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
|
-
emit UniversalReceiver(
|
|
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
|
|
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
|
|
19
|
+
address caller,
|
|
20
|
+
uint256 value,
|
|
19
21
|
bytes32 typeId,
|
|
20
22
|
bytes memory data
|
|
21
23
|
) external returns (bytes memory result);
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
58
|
+
arrayLengthKey,
|
|
53
59
|
mapKey,
|
|
54
|
-
|
|
60
|
+
caller,
|
|
55
61
|
interfaceID,
|
|
56
62
|
keyManager
|
|
57
63
|
);
|
|
58
|
-
} else
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
77
|
+
arrayLengthKey,
|
|
69
78
|
mapPrefix,
|
|
70
79
|
mapKey,
|
|
71
80
|
mapValue,
|
|
@@ -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
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
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
|
-
(
|
|
33
|
-
|
|
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(
|
|
39
|
+
bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
|
|
36
40
|
bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
|
|
37
41
|
|
|
38
|
-
if (
|
|
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
|
-
|
|
48
|
+
arrayLengthKey,
|
|
45
49
|
mapKey,
|
|
46
|
-
|
|
50
|
+
caller,
|
|
47
51
|
interfaceID
|
|
48
52
|
);
|
|
53
|
+
|
|
49
54
|
IERC725Y(msg.sender).setData(keys, values);
|
|
50
|
-
} else
|
|
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
|
-
|
|
54
|
-
// if the amount sent is not the full balance, then do
|
|
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
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
45
|
+
isReceiving = typeId == _TYPEID_LSP9_VAULTRECIPIENT ? true : false;
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
48
|
}
|
|
@@ -15,139 +15,187 @@ import {_TYPEID_LSP7_TOKENSSENDER} from "../LSP7DigitalAsset/LSP7Constants.sol";
|
|
|
15
15
|
|
|
16
16
|
library LSP5Utils {
|
|
17
17
|
/**
|
|
18
|
-
* @dev
|
|
19
|
-
*
|
|
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
|
|
23
|
-
bytes32
|
|
24
|
-
bytes32
|
|
25
|
-
address
|
|
26
|
-
bytes4
|
|
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
|
|
42
|
+
bytes memory encodedArrayLength = account.getData(arrayLengthKey);
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
49
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, 0);
|
|
50
|
+
values[1] = UtilsLib.addressToBytes(caller);
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
keys[2] = mapKey;
|
|
53
|
+
values[2] = bytes.concat(interfaceID, bytes8(0));
|
|
40
54
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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[
|
|
48
|
-
|
|
60
|
+
keys[0] = arrayLengthKey;
|
|
49
61
|
values[0] = UtilsLib.uint256ToBytes(newArrayLength);
|
|
50
|
-
|
|
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
|
|
56
|
-
*
|
|
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
|
|
60
|
-
bytes32
|
|
61
|
-
bytes12
|
|
62
|
-
bytes32
|
|
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
|
-
|
|
66
|
-
|
|
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] =
|
|
110
|
+
keys[0] = arrayLengthKey;
|
|
79
111
|
values[0] = UtilsLib.uint256ToBytes(newLength);
|
|
80
112
|
|
|
81
|
-
keys[1] =
|
|
113
|
+
keys[1] = mapKeyToRemove;
|
|
82
114
|
values[1] = "";
|
|
83
115
|
|
|
84
|
-
keys[2] =
|
|
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] =
|
|
133
|
+
keys[0] = arrayLengthKey;
|
|
91
134
|
values[0] = UtilsLib.uint256ToBytes(newLength);
|
|
92
135
|
|
|
93
|
-
keys[1] =
|
|
136
|
+
keys[1] = mapKeyToRemove;
|
|
94
137
|
values[1] = "";
|
|
95
138
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
bytes memory
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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] =
|
|
113
|
-
values[4] = bytes.concat(
|
|
160
|
+
keys[4] = lastArrayElementMapKey;
|
|
161
|
+
values[4] = bytes.concat(interfaceID, bytes8(index));
|
|
114
162
|
}
|
|
115
163
|
}
|
|
116
164
|
|
|
117
165
|
function addMapAndArrayKeyViaKeyManager(
|
|
118
|
-
IERC725Y
|
|
119
|
-
bytes32
|
|
120
|
-
bytes32
|
|
121
|
-
address
|
|
122
|
-
bytes4
|
|
123
|
-
address
|
|
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
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
173
|
+
(bytes32[] memory keys, bytes[] memory values) = addMapAndArrayKey(
|
|
174
|
+
account,
|
|
175
|
+
arrayLengthKey,
|
|
176
|
+
mapKey,
|
|
177
|
+
caller,
|
|
178
|
+
interfaceID
|
|
131
179
|
);
|
|
132
|
-
result = LSP6Utils.setDataViaKeyManager(
|
|
180
|
+
result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
|
|
133
181
|
}
|
|
134
182
|
|
|
135
183
|
function removeMapAndArrayKeyViaKeyManager(
|
|
136
|
-
IERC725Y
|
|
137
|
-
bytes32
|
|
138
|
-
bytes12
|
|
139
|
-
bytes32
|
|
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
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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,
|
|
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
|
-
// ---
|
|
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
|
-
|
|
61
|
-
emit ValueReceived(
|
|
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(
|
|
169
|
+
.universalReceiverDelegate(msg.sender, msg.value, _typeId, _data);
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
|
-
emit UniversalReceiver(
|
|
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 =
|
|
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.
|
|
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.
|
|
59
|
+
"@erc725/smart-contracts": "^3.1.1",
|
|
60
60
|
"@openzeppelin/contracts": "^4.6.0",
|
|
61
61
|
"solidity-bytes-utils": "0.8.0"
|
|
62
62
|
},
|