@lukso/lsp-smart-contracts 0.9.0 → 0.10.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 +29 -7
- package/artifacts/LSP0ERC725Account.json +63 -69
- package/artifacts/LSP0ERC725AccountInit.json +63 -69
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP16UniversalFactory.json +27 -21
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
- package/artifacts/LSP4Compatibility.json +32 -38
- package/artifacts/LSP4DigitalAssetMetadata.json +32 -38
- package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +32 -38
- package/artifacts/LSP6KeyManager.json +29 -15
- package/artifacts/LSP6KeyManagerInit.json +29 -15
- package/artifacts/LSP7CappedSupply.json +71 -36
- package/artifacts/LSP7CappedSupplyInitAbstract.json +71 -36
- package/artifacts/LSP7CompatibleERC20.json +71 -36
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +71 -36
- package/artifacts/LSP7CompatibleERC20Mintable.json +73 -38
- package/artifacts/LSP7CompatibleERC20MintableInit.json +73 -38
- package/artifacts/LSP7DigitalAsset.json +71 -36
- package/artifacts/LSP7DigitalAssetInitAbstract.json +71 -36
- package/artifacts/LSP7Mintable.json +73 -38
- package/artifacts/LSP7MintableInit.json +73 -38
- package/artifacts/LSP8CappedSupply.json +32 -38
- package/artifacts/LSP8CappedSupplyInitAbstract.json +32 -38
- package/artifacts/LSP8CompatibleERC721.json +35 -41
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +35 -41
- package/artifacts/LSP8CompatibleERC721Mintable.json +37 -43
- package/artifacts/LSP8CompatibleERC721MintableInit.json +37 -43
- package/artifacts/LSP8IdentifiableDigitalAsset.json +32 -38
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +32 -38
- package/artifacts/LSP8Mintable.json +34 -40
- package/artifacts/LSP8MintableInit.json +34 -40
- package/artifacts/LSP9Vault.json +61 -67
- package/artifacts/LSP9VaultInit.json +61 -67
- package/artifacts/UniversalProfile.json +63 -69
- package/artifacts/UniversalProfileInit.json +63 -69
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +45 -10
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +43 -8
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +361 -124
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +44 -8
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +45 -6
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -1
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +30 -15
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +0 -1
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +0 -1
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +5 -7
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +262 -115
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +10 -5
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +0 -4
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +91 -34
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +27 -8
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +18 -9
- package/contracts/LSP20CallVerification/LSP20Constants.sol +17 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +26 -12
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +0 -1
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +32 -16
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +11 -2
- package/contracts/LSP6KeyManager/LSP6Constants.sol +5 -5
- package/contracts/LSP6KeyManager/LSP6Errors.sol +10 -6
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +140 -68
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +30 -38
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +153 -60
- package/contracts/LSP6KeyManager/LSP6Utils.sol +1 -5
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +67 -13
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +24 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +1 -2
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +3 -5
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +3 -5
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +15 -12
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +1 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +1 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +5 -5
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +6 -6
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +2 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +2 -2
- package/contracts/LSP9Vault/ILSP9Vault.sol +9 -1
- package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
- package/contracts/LSP9Vault/LSP9Vault.sol +0 -6
- package/contracts/LSP9Vault/LSP9VaultCore.sol +17 -15
- package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -1
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +8 -5
- package/contracts/UniversalProfile.sol +10 -4
- package/contracts/UniversalProfileInit.sol +15 -5
- package/contracts/UniversalProfileInitAbstract.sol +7 -3
- package/devdocs/Create2Factory.json +16 -0
- package/devdocs/LSP0ERC725Account.json +200 -0
- package/devdocs/LSP0ERC725AccountInit.json +203 -0
- package/devdocs/LSP11BasicSocialRecovery.json +146 -0
- package/devdocs/LSP11BasicSocialRecoveryInit.json +146 -0
- package/devdocs/LSP16UniversalFactory.json +116 -0
- package/devdocs/LSP1UniversalReceiverDelegateUP.json +80 -0
- package/devdocs/LSP1UniversalReceiverDelegateVault.json +62 -0
- package/devdocs/LSP4Compatibility.json +79 -0
- package/devdocs/LSP4DigitalAssetMetadata.json +84 -0
- package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +77 -0
- package/devdocs/LSP6KeyManager.json +257 -0
- package/devdocs/LSP6KeyManagerInit.json +260 -0
- package/devdocs/LSP7CappedSupply.json +211 -0
- package/devdocs/LSP7CappedSupplyInitAbstract.json +206 -0
- package/devdocs/LSP7CompatibleERC20.json +225 -0
- package/devdocs/LSP7CompatibleERC20InitAbstract.json +218 -0
- package/devdocs/LSP7CompatibleERC20Mintable.json +217 -0
- package/devdocs/LSP7CompatibleERC20MintableInit.json +227 -0
- package/devdocs/LSP7DigitalAsset.json +210 -0
- package/devdocs/LSP7DigitalAssetInitAbstract.json +202 -0
- package/devdocs/LSP7Mintable.json +219 -0
- package/devdocs/LSP7MintableInit.json +220 -0
- package/devdocs/LSP8CappedSupply.json +232 -0
- package/devdocs/LSP8CappedSupplyInitAbstract.json +227 -0
- package/devdocs/LSP8CompatibleERC721.json +298 -0
- package/devdocs/LSP8CompatibleERC721InitAbstract.json +291 -0
- package/devdocs/LSP8CompatibleERC721Mintable.json +290 -0
- package/devdocs/LSP8CompatibleERC721MintableInit.json +300 -0
- package/devdocs/LSP8IdentifiableDigitalAsset.json +230 -0
- package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +223 -0
- package/devdocs/LSP8Mintable.json +242 -0
- package/devdocs/LSP8MintableInit.json +245 -0
- package/devdocs/LSP9Vault.json +171 -0
- package/devdocs/LSP9VaultInit.json +175 -0
- package/devdocs/UniversalProfile.json +200 -0
- package/devdocs/UniversalProfileInit.json +203 -0
- package/devdocs/UniversalReceiverAddressStore.json +9 -0
- package/dist/constants.cjs.js +31657 -0
- package/dist/constants.d.ts +31759 -0
- package/dist/constants.es.js +31638 -0
- package/package.json +71 -53
- package/userdocs/Create2Factory.json +5 -0
- package/userdocs/LSP0ERC725Account.json +50 -0
- package/userdocs/LSP0ERC725AccountInit.json +53 -0
- package/userdocs/LSP11BasicSocialRecovery.json +29 -0
- package/userdocs/LSP11BasicSocialRecoveryInit.json +29 -0
- package/userdocs/LSP16UniversalFactory.json +5 -0
- package/userdocs/LSP1UniversalReceiverDelegateUP.json +10 -0
- package/userdocs/LSP1UniversalReceiverDelegateVault.json +10 -0
- package/userdocs/LSP4Compatibility.json +20 -0
- package/userdocs/LSP4DigitalAssetMetadata.json +23 -0
- package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +20 -0
- package/userdocs/LSP6KeyManager.json +18 -0
- package/userdocs/LSP6KeyManagerInit.json +18 -0
- package/userdocs/LSP7CappedSupply.json +29 -0
- package/userdocs/LSP7CappedSupplyInitAbstract.json +26 -0
- package/userdocs/LSP7CompatibleERC20.json +35 -0
- package/userdocs/LSP7CompatibleERC20InitAbstract.json +32 -0
- package/userdocs/LSP7CompatibleERC20Mintable.json +32 -0
- package/userdocs/LSP7CompatibleERC20MintableInit.json +35 -0
- package/userdocs/LSP7DigitalAsset.json +29 -0
- package/userdocs/LSP7DigitalAssetInitAbstract.json +26 -0
- package/userdocs/LSP7Mintable.json +29 -0
- package/userdocs/LSP7MintableInit.json +29 -0
- package/userdocs/LSP8CappedSupply.json +23 -0
- package/userdocs/LSP8CappedSupplyInitAbstract.json +20 -0
- package/userdocs/LSP8CompatibleERC721.json +29 -0
- package/userdocs/LSP8CompatibleERC721InitAbstract.json +26 -0
- package/userdocs/LSP8CompatibleERC721Mintable.json +26 -0
- package/userdocs/LSP8CompatibleERC721MintableInit.json +29 -0
- package/userdocs/LSP8IdentifiableDigitalAsset.json +23 -0
- package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +20 -0
- package/userdocs/LSP8Mintable.json +23 -0
- package/userdocs/LSP8MintableInit.json +23 -0
- package/userdocs/LSP9Vault.json +38 -0
- package/userdocs/LSP9VaultInit.json +38 -0
- package/userdocs/UniversalProfile.json +50 -0
- package/userdocs/UniversalProfileInit.json +53 -0
- package/userdocs/UniversalReceiverAddressStore.json +5 -0
- package/CONTRIBUTING.md +0 -57
- package/common/constants.d.ts +0 -461
- package/common/constants.js +0 -789
- package/contracts/Utils/GasLib.sol +0 -17
- package/module/constants.d.ts +0 -461
- package/module/constants.js +0 -786
|
@@ -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
|
|
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
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
|
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
|
-
//
|
|
113
|
-
|
|
114
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
201
|
+
arrayIndex
|
|
161
202
|
);
|
|
162
203
|
|
|
163
|
-
|
|
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
|
-
|
|
218
|
+
arrayIndex
|
|
170
219
|
);
|
|
171
220
|
|
|
172
|
-
|
|
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
|
}
|
|
@@ -8,10 +8,8 @@ import {ILSP7DigitalAsset} from "../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
|
|
|
8
8
|
|
|
9
9
|
// modules
|
|
10
10
|
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
11
|
-
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
12
11
|
|
|
13
12
|
// libraries
|
|
14
|
-
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
15
13
|
import {LSP1Utils} from "../LSP1Utils.sol";
|
|
16
14
|
import {LSP2Utils} from "../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
17
15
|
import {LSP5Utils} from "../../LSP5ReceivedAssets/LSP5Utils.sol";
|
|
@@ -65,9 +63,13 @@ contract LSP1UniversalReceiverDelegateVault is ERC165, ILSP1UniversalReceiver {
|
|
|
65
63
|
if (bytes20(notifierMapValue) != bytes20(0))
|
|
66
64
|
return "URD: asset received is already registered";
|
|
67
65
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
if (
|
|
66
|
+
// CHECK balance only when the Token contract is already deployed,
|
|
67
|
+
// not when tokens are being transferred on deployment through the `constructor`
|
|
68
|
+
if (notifier.code.length > 0) {
|
|
69
|
+
// if the amount sent is 0, then do not update the keys
|
|
70
|
+
uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
|
|
71
|
+
if (balance == 0) return "LSP1: balance not updated";
|
|
72
|
+
}
|
|
71
73
|
|
|
72
74
|
(dataKeys, dataValues) = LSP5Utils.generateReceivedAssetKeys(
|
|
73
75
|
msg.sender,
|
|
@@ -76,22 +78,39 @@ contract LSP1UniversalReceiverDelegateVault is ERC165, ILSP1UniversalReceiver {
|
|
|
76
78
|
interfaceID
|
|
77
79
|
);
|
|
78
80
|
|
|
79
|
-
IERC725Y(msg.sender).
|
|
81
|
+
IERC725Y(msg.sender).setDataBatch(dataKeys, dataValues);
|
|
80
82
|
} else {
|
|
81
83
|
// if there is no map value for the asset to remove, then do nothing
|
|
82
84
|
if (bytes20(notifierMapValue) == bytes20(0))
|
|
83
85
|
return "LSP1: asset sent is not registered";
|
|
86
|
+
|
|
84
87
|
// if it's a token transfer (LSP7/LSP8)
|
|
85
88
|
uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
|
|
86
89
|
if (balance != 0) return "LSP1: full balance is not sent";
|
|
87
90
|
|
|
91
|
+
// if the value under the `LSP5ReceivedAssetsMap:<asset-address>`
|
|
92
|
+
// is not a valid tuple as `(bytes4,uint128)`
|
|
93
|
+
if (notifierMapValue.length < 20) return "LSP1: asset data corrupted";
|
|
94
|
+
|
|
95
|
+
// Identify where the asset is located in the `LSP5ReceivedAssets[]` Array
|
|
96
|
+
// by extracting the index from the tuple value `(bytes4,uint128)`
|
|
97
|
+
// fetched under the LSP5ReceivedAssetsMap/LSP10VaultsMap data key
|
|
98
|
+
uint128 assetIndex = uint128(uint160(bytes20(notifierMapValue)));
|
|
99
|
+
|
|
88
100
|
(dataKeys, dataValues) = LSP5Utils.generateSentAssetKeys(
|
|
89
101
|
msg.sender,
|
|
90
102
|
notifierMapKey,
|
|
91
|
-
|
|
103
|
+
assetIndex
|
|
92
104
|
);
|
|
93
105
|
|
|
94
|
-
|
|
106
|
+
/**
|
|
107
|
+
* `generateSentAssetKeys(...)` returns empty arrays in the following cases:
|
|
108
|
+
* - the index returned from the data key `notifierMapKey` is bigger than
|
|
109
|
+
* the length of the `LSP5ReceivedAssets[]`, meaning, index is out of bounds.
|
|
110
|
+
*/
|
|
111
|
+
if (dataKeys.length == 0 && dataValues.length == 0) return "LSP1: asset data corrupted";
|
|
112
|
+
|
|
113
|
+
IERC725Y(msg.sender).setDataBatch(dataKeys, dataValues);
|
|
95
114
|
}
|
|
96
115
|
}
|
|
97
116
|
|
|
@@ -24,11 +24,9 @@ abstract contract LSP20CallVerification {
|
|
|
24
24
|
abi.encodeWithSelector(ILSP20.lsp20VerifyCall.selector, msg.sender, msg.value, msg.data)
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
_validateCall(false, success, returnedData);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
bytes32 magicValue = abi.decode(returnedData, (bytes32));
|
|
29
|
+
bytes4 magicValue = abi.decode(returnedData, (bytes4));
|
|
32
30
|
|
|
33
31
|
if (bytes3(magicValue) != bytes3(ILSP20.lsp20VerifyCall.selector))
|
|
34
32
|
revert LSP20InvalidMagicValue(false, returnedData);
|
|
@@ -49,12 +47,23 @@ abstract contract LSP20CallVerification {
|
|
|
49
47
|
)
|
|
50
48
|
);
|
|
51
49
|
|
|
52
|
-
|
|
50
|
+
_validateCall(true, success, returnedData);
|
|
51
|
+
|
|
52
|
+
if (abi.decode(returnedData, (bytes4)) != ILSP20.lsp20VerifyCallResult.selector)
|
|
53
|
+
revert LSP20InvalidMagicValue(true, returnedData);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function _validateCall(
|
|
57
|
+
bool postCall,
|
|
58
|
+
bool success,
|
|
59
|
+
bytes memory returnedData
|
|
60
|
+
) internal pure {
|
|
61
|
+
if (!success) _revert(postCall, returnedData);
|
|
53
62
|
|
|
54
|
-
if
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
// check if the returned data contains at least 32 bytes, potentially an abi encoded bytes4 value
|
|
64
|
+
// check if the returned data has in the first 32 bytes an abi encoded bytes4 value
|
|
65
|
+
if (returnedData.length < 32 || bytes28(bytes32(returnedData) << 32) != bytes28(0))
|
|
66
|
+
revert LSP20InvalidMagicValue(postCall, returnedData);
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
function _revert(bool postCall, bytes memory returnedData) internal pure {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
// bytes4(keccak256("LSP20CallVerification"))
|
|
5
|
+
bytes4 constant _INTERFACEID_LSP20_CALL_VERIFICATION = 0x1a0eb6a5;
|
|
6
|
+
|
|
7
|
+
// `lsp20VerifyCall(address,uint256,bytes)` selector XOR `lsp20VerifyCallResult(bytes32,bytes)` selector
|
|
8
|
+
bytes4 constant _INTERFACEID_LSP20_CALL_VERIFIER = 0x480c0ec2;
|
|
9
|
+
|
|
10
|
+
// bytes4(bytes.concat(bytes3(ILSP20.lsp20VerifyCall.selector), hex"01"))
|
|
11
|
+
bytes4 constant _LSP20_VERIFY_CALL_MAGIC_VALUE_WITH_POST_VERIFICATION = 0x9bf04b01;
|
|
12
|
+
|
|
13
|
+
// bytes4(bytes.concat(bytes3(ILSP20.lsp20VerifyCall.selector), hex"00"))
|
|
14
|
+
bytes4 constant _LSP20_VERIFY_CALL_MAGIC_VALUE_WITHOUT_POST_VERIFICATION = 0x9bf04b00;
|
|
15
|
+
|
|
16
|
+
// bytes4(ILSP20.lsp20VerifyCallResult.selector)
|
|
17
|
+
bytes4 constant _LSP20_VERIFY_CALL_RESULT_MAGIC_VALUE = 0xd3fc45d3;
|
|
@@ -144,6 +144,22 @@ library LSP2Utils {
|
|
|
144
144
|
return bytes32(temporaryBytes);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
/**
|
|
148
|
+
* @dev Generate a data key of keyType MappingWithGrouping
|
|
149
|
+
* <bytes6keyPrefix>:<bytes4mapPrefix>:<bytes2(0)>:<subMapKey>
|
|
150
|
+
* @param keyPrefix the first part of the data key of keyType MappingWithGrouping
|
|
151
|
+
* @param mapPrefix Used for the second part (bytes4) of the data key of keyType MappingWithGrouping
|
|
152
|
+
* @param subMapKey Used for the last part (bytes20) of the data key of keyType MappingWithGrouping
|
|
153
|
+
*/
|
|
154
|
+
function generateMappingWithGroupingKey(
|
|
155
|
+
bytes6 keyPrefix,
|
|
156
|
+
bytes4 mapPrefix,
|
|
157
|
+
bytes20 subMapKey
|
|
158
|
+
) internal pure returns (bytes32) {
|
|
159
|
+
bytes memory generatedKey = bytes.concat(keyPrefix, mapPrefix, bytes2(0), subMapKey);
|
|
160
|
+
return bytes32(generatedKey);
|
|
161
|
+
}
|
|
162
|
+
|
|
147
163
|
/**
|
|
148
164
|
* @dev Generate a data key of keyType MappingWithGrouping
|
|
149
165
|
* <bytes10keyPrefix>:<bytes2(0)>:<bytes20Value>
|
|
@@ -225,7 +241,7 @@ library LSP2Utils {
|
|
|
225
241
|
|
|
226
242
|
uint256 pointer = offset + 32;
|
|
227
243
|
|
|
228
|
-
for (uint256 ii = 0; ii < arrayLength;
|
|
244
|
+
for (uint256 ii = 0; ii < arrayLength; ) {
|
|
229
245
|
bytes32 key = data.toBytes32(pointer);
|
|
230
246
|
|
|
231
247
|
// check that the leading bytes are zero bytes "00"
|
|
@@ -234,6 +250,10 @@ library LSP2Utils {
|
|
|
234
250
|
|
|
235
251
|
// increment the pointer
|
|
236
252
|
pointer += 32;
|
|
253
|
+
|
|
254
|
+
unchecked {
|
|
255
|
+
++ii;
|
|
256
|
+
}
|
|
237
257
|
}
|
|
238
258
|
|
|
239
259
|
return true;
|
|
@@ -250,7 +270,7 @@ library LSP2Utils {
|
|
|
250
270
|
uint256 arrayLength = data.toUint256(offset);
|
|
251
271
|
uint256 pointer = offset + 32;
|
|
252
272
|
|
|
253
|
-
for (uint256 ii = 0; ii < arrayLength;
|
|
273
|
+
for (uint256 ii = 0; ii < arrayLength; ) {
|
|
254
274
|
bytes32 key = data.toBytes32(pointer);
|
|
255
275
|
|
|
256
276
|
// check that the trailing bytes are zero bytes "00"
|
|
@@ -258,6 +278,10 @@ library LSP2Utils {
|
|
|
258
278
|
|
|
259
279
|
// increment the pointer
|
|
260
280
|
pointer += 32;
|
|
281
|
+
|
|
282
|
+
unchecked {
|
|
283
|
+
++ii;
|
|
284
|
+
}
|
|
261
285
|
}
|
|
262
286
|
|
|
263
287
|
return true;
|
|
@@ -296,14 +320,4 @@ library LSP2Utils {
|
|
|
296
320
|
if (pointer == compactBytesArray.length) return true;
|
|
297
321
|
return false;
|
|
298
322
|
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* @dev Will return unchecked incremented uint256
|
|
302
|
-
* can be used to save gas when iterating over loops
|
|
303
|
-
*/
|
|
304
|
-
function uncheckedIncrement(uint256 i) internal pure returns (uint256) {
|
|
305
|
-
unchecked {
|
|
306
|
-
return i + 1;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
323
|
}
|
|
@@ -3,7 +3,6 @@ pragma solidity ^0.8.4;
|
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
5
|
import {ERC725YInitAbstract} from "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";
|
|
6
|
-
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
|
|
7
6
|
|
|
8
7
|
// libraries
|
|
9
8
|
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
@@ -83,15 +83,19 @@ library LSP5Utils {
|
|
|
83
83
|
revert MaxLSP5ReceivedAssetsCountReached({notRegisteredAsset: asset});
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// store the number of received assets incremented by 1
|
|
86
87
|
keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
|
|
87
88
|
values[0] = bytes.concat(bytes16(oldArrayLength + 1));
|
|
88
89
|
|
|
90
|
+
// store the address of the asset under the element key in the array
|
|
89
91
|
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
90
92
|
_LSP5_RECEIVED_ASSETS_ARRAY_KEY,
|
|
91
93
|
oldArrayLength
|
|
92
94
|
);
|
|
93
95
|
values[1] = bytes.concat(bytes20(asset));
|
|
94
96
|
|
|
97
|
+
// store the interfaceId and the location in the array of the asset
|
|
98
|
+
// under the LSP5ReceivedAssetMap key
|
|
95
99
|
keys[2] = assetMapKey;
|
|
96
100
|
values[2] = bytes.concat(interfaceID, bytes16(oldArrayLength));
|
|
97
101
|
}
|
|
@@ -101,12 +105,12 @@ library LSP5Utils {
|
|
|
101
105
|
* @param sender The address sending the asset and where the Keys should be updated
|
|
102
106
|
* @param assetMapKey The map key of the asset being received containing the interfaceId of the
|
|
103
107
|
* asset and the index in the array
|
|
104
|
-
* @param
|
|
108
|
+
* @param assetIndex The index in the LSP5ReceivedAssets[] array
|
|
105
109
|
*/
|
|
106
110
|
function generateSentAssetKeys(
|
|
107
111
|
address sender,
|
|
108
112
|
bytes32 assetMapKey,
|
|
109
|
-
|
|
113
|
+
uint128 assetIndex
|
|
110
114
|
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
111
115
|
IERC725Y account = IERC725Y(sender);
|
|
112
116
|
bytes memory lsp5ReceivedAssetsCountValue = getLSP5ReceivedAssetsCount(account);
|
|
@@ -118,17 +122,19 @@ library LSP5Utils {
|
|
|
118
122
|
});
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
// Updating the number of the received assets
|
|
122
125
|
uint128 oldArrayLength = uint128(bytes16(lsp5ReceivedAssetsCountValue));
|
|
126
|
+
|
|
127
|
+
// Updating the number of the received assets (decrementing by 1
|
|
123
128
|
uint128 newArrayLength = oldArrayLength - 1;
|
|
124
129
|
|
|
125
|
-
|
|
130
|
+
// Generate the element key in the array of the asset
|
|
126
131
|
bytes32 assetInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
127
132
|
_LSP5_RECEIVED_ASSETS_ARRAY_KEY,
|
|
128
|
-
|
|
133
|
+
assetIndex
|
|
129
134
|
);
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
// If the asset to remove is the last element in the array
|
|
137
|
+
if (assetIndex == newArrayLength) {
|
|
132
138
|
/**
|
|
133
139
|
* We will be updating/removing 3 keys:
|
|
134
140
|
* - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets
|
|
@@ -138,18 +144,21 @@ library LSP5Utils {
|
|
|
138
144
|
keys = new bytes32[](3);
|
|
139
145
|
values = new bytes[](3);
|
|
140
146
|
|
|
147
|
+
// store the number of received assets decremented by 1
|
|
141
148
|
keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
|
|
142
149
|
values[0] = bytes.concat(bytes16(newArrayLength));
|
|
143
150
|
|
|
151
|
+
// remove the address of the asset from the element key
|
|
144
152
|
keys[1] = assetInArrayKey;
|
|
145
153
|
values[1] = "";
|
|
146
154
|
|
|
155
|
+
// remove the interfaceId and the location in the array of the asset
|
|
147
156
|
keys[2] = assetMapKey;
|
|
148
157
|
values[2] = "";
|
|
149
158
|
|
|
150
159
|
// Swapping last element in ArrayKey with the element in ArrayKey to remove || {Swap and pop} method;
|
|
151
160
|
// check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
|
|
152
|
-
} else {
|
|
161
|
+
} else if (assetIndex < newArrayLength) {
|
|
153
162
|
/**
|
|
154
163
|
* We will be updating/removing 5 keys:
|
|
155
164
|
* - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets
|
|
@@ -161,9 +170,11 @@ library LSP5Utils {
|
|
|
161
170
|
keys = new bytes32[](5);
|
|
162
171
|
values = new bytes[](5);
|
|
163
172
|
|
|
173
|
+
// store the number of received assets decremented by 1
|
|
164
174
|
keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
|
|
165
175
|
values[0] = bytes.concat(bytes16(newArrayLength));
|
|
166
176
|
|
|
177
|
+
// remove the interfaceId and the location in the array of the asset
|
|
167
178
|
keys[1] = assetMapKey;
|
|
168
179
|
values[1] = "";
|
|
169
180
|
|
|
@@ -173,41 +184,46 @@ library LSP5Utils {
|
|
|
173
184
|
|
|
174
185
|
// Generate all data Keys/values of the last element in Array to swap
|
|
175
186
|
// with data Keys/values of the asset to remove
|
|
187
|
+
|
|
188
|
+
// Generate the element key of the last asset in the array
|
|
176
189
|
bytes32 lastAssetInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
177
190
|
_LSP5_RECEIVED_ASSETS_ARRAY_KEY,
|
|
178
191
|
newArrayLength
|
|
179
192
|
);
|
|
180
193
|
|
|
194
|
+
// Get the address of the asset from the element key of the last asset in the array
|
|
181
195
|
bytes20 lastAssetInArrayAddress = bytes20(account.getData(lastAssetInArrayKey));
|
|
182
196
|
|
|
197
|
+
// Generate the map key of the last asset in the array
|
|
183
198
|
bytes32 lastAssetInArrayMapKey = LSP2Utils.generateMappingKey(
|
|
184
199
|
_LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX,
|
|
185
200
|
lastAssetInArrayAddress
|
|
186
201
|
);
|
|
187
202
|
|
|
203
|
+
// Get the interfaceId and the location in the array of the last asset
|
|
188
204
|
bytes memory lastAssetInterfaceIdAndIndex = account.getData(lastAssetInArrayMapKey);
|
|
189
205
|
bytes memory interfaceID = BytesLib.slice(lastAssetInterfaceIdAndIndex, 0, 4);
|
|
190
206
|
|
|
207
|
+
// Set the address of the last asset instead of the asset to be sent
|
|
208
|
+
// under the element data key in the array
|
|
191
209
|
keys[2] = assetInArrayKey;
|
|
192
210
|
values[2] = bytes.concat(lastAssetInArrayAddress);
|
|
193
211
|
|
|
212
|
+
// Remove the address swapped from the last element data key in the array
|
|
194
213
|
keys[3] = lastAssetInArrayKey;
|
|
195
214
|
values[3] = "";
|
|
196
215
|
|
|
216
|
+
// Update the index and the interfaceId of the address swapped (last element in the array)
|
|
217
|
+
// to point to the new location in the LSP5ReceivedAssets array
|
|
197
218
|
keys[4] = lastAssetInArrayMapKey;
|
|
198
|
-
values[4] = bytes.concat(interfaceID, bytes16(
|
|
219
|
+
values[4] = bytes.concat(interfaceID, bytes16(assetIndex));
|
|
220
|
+
} else {
|
|
221
|
+
// If index is bigger than the array length, out of bounds
|
|
222
|
+
return (keys, values);
|
|
199
223
|
}
|
|
200
224
|
}
|
|
201
225
|
|
|
202
226
|
function getLSP5ReceivedAssetsCount(IERC725Y account) internal view returns (bytes memory) {
|
|
203
227
|
return account.getData(_LSP5_RECEIVED_ASSETS_ARRAY_KEY);
|
|
204
228
|
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @dev returns the index from the LSP5ReceivedAssetMap
|
|
208
|
-
*/
|
|
209
|
-
function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint128) {
|
|
210
|
-
bytes memory val = BytesLib.slice(mapValue, 4, 16);
|
|
211
|
-
return BytesLib.toUint128(val, 0);
|
|
212
|
-
}
|
|
213
229
|
}
|
|
@@ -11,6 +11,12 @@ interface ILSP6KeyManager is
|
|
|
11
11
|
IERC1271
|
|
12
12
|
/* is ERC165 */
|
|
13
13
|
{
|
|
14
|
+
/**
|
|
15
|
+
* @dev Emitted when a calldata payload that includes `selector` and `value` as msg.value was verified for `signer`
|
|
16
|
+
* @param signer the address of the controller that executed the calldata payload.
|
|
17
|
+
* @param value the amount of native token to be transferred in the calldata payload.
|
|
18
|
+
* @param selector the bytes4 function of the function to run in the calldata payload.
|
|
19
|
+
*/
|
|
14
20
|
event VerifiedCall(address indexed signer, uint256 indexed value, bytes4 indexed selector);
|
|
15
21
|
|
|
16
22
|
/**
|
|
@@ -43,7 +49,7 @@ interface ILSP6KeyManager is
|
|
|
43
49
|
/**
|
|
44
50
|
* @dev batch `execute(bytes)`
|
|
45
51
|
*/
|
|
46
|
-
function
|
|
52
|
+
function executeBatch(uint256[] calldata values, bytes[] calldata payloads)
|
|
47
53
|
external
|
|
48
54
|
payable
|
|
49
55
|
returns (bytes[] memory);
|
|
@@ -52,21 +58,24 @@ interface ILSP6KeyManager is
|
|
|
52
58
|
* @dev allows anybody to execute given they have a signed message from an executor
|
|
53
59
|
* @param signature bytes32 ethereum signature
|
|
54
60
|
* @param nonce the address' nonce (in a specific `_channel`), obtained via `getNonce(...)`. Used to prevent replay attack
|
|
61
|
+
* @param validityTimestamps two `uint128` timestamps concatenated, the first timestamp determines from when the payload can be executed, the second timestamp delimits the end of the validity of the payload. If `validityTimestamps` is 0, the checks regardin the timestamps are skipped
|
|
55
62
|
* @param payload obtained via encodeABI() in web3
|
|
56
63
|
* @return the data being returned by the ERC725 Account
|
|
57
64
|
*/
|
|
58
65
|
function executeRelayCall(
|
|
59
66
|
bytes calldata signature,
|
|
60
67
|
uint256 nonce,
|
|
68
|
+
uint256 validityTimestamps,
|
|
61
69
|
bytes calldata payload
|
|
62
70
|
) external payable returns (bytes memory);
|
|
63
71
|
|
|
64
72
|
/**
|
|
65
73
|
* @dev batch `executeRelayCall(...)`
|
|
66
74
|
*/
|
|
67
|
-
function
|
|
75
|
+
function executeRelayCallBatch(
|
|
68
76
|
bytes[] calldata signatures,
|
|
69
77
|
uint256[] calldata nonces,
|
|
78
|
+
uint256[] calldata validityTimestamps,
|
|
70
79
|
uint256[] calldata values,
|
|
71
80
|
bytes[] calldata payloads
|
|
72
81
|
) external payable returns (bytes[] memory);
|