@lukso/lsp-smart-contracts 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -12
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +66 -27
- package/artifacts/LSP0ERC725AccountInit.json +71 -53
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +23 -2
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +23 -2
- package/artifacts/LSP4Compatibility.json +15 -9
- package/artifacts/LSP4DigitalAssetMetadata.json +25 -9
- package/artifacts/{LSP4DigitalAssetMetadataInit.json → LSP4DigitalAssetMetadataInitAbstract.json} +27 -60
- package/artifacts/LSP6KeyManager.json +93 -13
- package/artifacts/LSP6KeyManagerInit.json +98 -13
- package/artifacts/LSP7CappedSupply.json +56 -35
- package/artifacts/{LSP7CappedSupplyInit.json → LSP7CappedSupplyInitAbstract.json} +58 -104
- package/artifacts/LSP7CompatibleERC20.json +704 -0
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +717 -0
- package/artifacts/LSP7CompatibleERC20Mintable.json +753 -0
- package/artifacts/LSP7CompatibleERC20MintableInit.json +773 -0
- package/artifacts/LSP7DigitalAsset.json +56 -61
- package/artifacts/LSP7DigitalAssetInitAbstract.json +540 -0
- package/artifacts/LSP7Mintable.json +59 -38
- package/artifacts/LSP7MintableInit.json +64 -64
- package/artifacts/LSP8CappedSupply.json +62 -9
- package/artifacts/{LSP8CappedSupplyInit.json → LSP8CappedSupplyInitAbstract.json} +64 -73
- package/artifacts/LSP8CompatibleERC721.json +907 -0
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +920 -0
- package/artifacts/LSP8CompatibleERC721Mintable.json +967 -0
- package/artifacts/LSP8CompatibleERC721MintableInit.json +987 -0
- package/artifacts/LSP8IdentifiableDigitalAsset.json +62 -30
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +628 -0
- package/artifacts/LSP8Mintable.json +64 -11
- package/artifacts/LSP8MintableInit.json +69 -37
- package/artifacts/LSP9Vault.json +63 -24
- package/artifacts/LSP9VaultInit.json +68 -50
- package/artifacts/UniversalFactory.json +2 -2
- package/artifacts/UniversalProfile.json +66 -27
- package/artifacts/UniversalProfileInit.json +71 -53
- package/artifacts/UniversalReceiverAddressStore.json +7 -2
- package/constants.js +273 -31
- package/contracts/Custom/ClaimOwnership.sol +74 -9
- package/contracts/Custom/ERC165Checker.sol +1 -1
- package/contracts/Custom/IClaimOwnership.sol +3 -1
- package/contracts/Factories/Create2Factory.sol +3 -13
- package/contracts/Factories/UniversalFactory.sol +20 -16
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +3 -3
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +49 -37
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +10 -3
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +3 -3
- package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
- 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 +22 -16
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +14 -10
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +35 -29
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +10 -3
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +24 -9
- package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +9 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +157 -75
- package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +24 -4
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +26 -5
- package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +16 -0
- package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +151 -77
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +16 -16
- package/contracts/LSP6KeyManager/LSP6Constants.sol +16 -21
- package/contracts/LSP6KeyManager/LSP6Errors.sol +42 -5
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +6 -4
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +293 -284
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +11 -4
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +5 -3
- package/contracts/LSP6KeyManager/LSP6Utils.sol +24 -27
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +18 -5
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +8 -4
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +35 -24
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +5 -3
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +2 -0
- package/contracts/LSP7DigitalAsset/extensions/{ILSP7CompatibilityForERC20.sol → ILSP7CompatibleERC20.sol} +6 -6
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +5 -2
- package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20.sol → LSP7CompatibleERC20.sol} +6 -7
- package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20Core.sol → LSP7CompatibleERC20Core.sol} +23 -19
- package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20InitAbstract.sol → LSP7CompatibleERC20InitAbstract.sol} +11 -10
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +22 -0
- package/contracts/{LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol → LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol} +12 -7
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +27 -0
- package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +9 -7
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +11 -4
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +8 -7
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +4 -4
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +6 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +31 -30
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{ILSP8CompatibilityForERC721.sol → ILSP8CompatibleERC721.sol} +16 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +17 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +4 -2
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityConstants.sol → LSP8CompatibleConstants.sol} +0 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721.sol → LSP8CompatibleERC721.sol} +12 -11
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Core.sol → LSP8CompatibleERC721Core.sol} +61 -37
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721InitAbstract.sol → LSP8CompatibleERC721InitAbstract.sol} +13 -9
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +21 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +50 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +24 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +22 -0
- package/contracts/{LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol → LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol} +12 -4
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +27 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +6 -4
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +7 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +8 -5
- package/contracts/LSP9Vault/LSP9Constants.sol +6 -3
- package/contracts/LSP9Vault/LSP9Vault.sol +9 -5
- package/contracts/LSP9Vault/LSP9VaultCore.sol +152 -69
- package/contracts/LSP9Vault/LSP9VaultInit.sol +10 -3
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +9 -5
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +6 -2
- package/contracts/UniversalProfile.sol +3 -4
- package/contracts/UniversalProfileInit.sol +10 -3
- package/contracts/UniversalProfileInitAbstract.sol +3 -5
- package/contracts/Utils/GasLib.sol +17 -0
- package/contracts/Utils/UtilsLib.sol +6 -34
- package/package.json +27 -30
- package/artifacts/LSP7CompatibilityForERC20.json +0 -686
- package/artifacts/LSP7CompatibilityForERC20Init.json +0 -727
- package/artifacts/LSP7DigitalAssetInit.json +0 -573
- package/artifacts/LSP8CompatibilityForERC721.json +0 -832
- package/artifacts/LSP8CompatibilityForERC721Init.json +0 -873
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +0 -624
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +0 -26
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +0 -28
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +0 -19
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableCore.sol +0 -26
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +0 -26
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +0 -19
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableCore.sol +0 -26
|
@@ -13,141 +13,215 @@ import {UtilsLib} from "../Utils/UtilsLib.sol";
|
|
|
13
13
|
// constants
|
|
14
14
|
import {_TYPEID_LSP7_TOKENSSENDER} from "../LSP7DigitalAsset/LSP7Constants.sol";
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @dev reverts when the value stored under the 'LSP5ReceivedAssets[]' data key is not valid.
|
|
18
|
+
* The value stored under this data key should be exactly 32 bytes long.
|
|
19
|
+
*
|
|
20
|
+
* Only possible valid values are:
|
|
21
|
+
* - any valid uint256 values
|
|
22
|
+
* i.e. 0x0000000000000000000000000000000000000000000000000000000000000000 (zero), meaning empty array, no assets received.
|
|
23
|
+
* i.e. 0x0000000000000000000000000000000000000000000000000000000000000005 (non-zero), meaning 5 array elements, 5 assets received.
|
|
24
|
+
*
|
|
25
|
+
* - 0x (nothing stored under this data key, equivalent to empty array)
|
|
26
|
+
*
|
|
27
|
+
* @param invalidValue the invalid value stored under the LSP5ReceivedAssets[] data key
|
|
28
|
+
* @param invalidValueLength the invalid number of bytes stored under the LSP5ReceivedAssets[] data key (MUST be 32)
|
|
29
|
+
*/
|
|
30
|
+
error InvalidLSP5ReceivedAssetsArrayLength(bytes invalidValue, uint256 invalidValueLength);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @title LSP5Utils
|
|
34
|
+
* @author Yamen Merhi <YamenMerhi>, Jean Cavallera <CJ42>
|
|
35
|
+
* @dev LSP5Utils is a library of functions that are used to register and manage assets received by an ERC725Y smart contract
|
|
36
|
+
* based on the LSP5 - Received Assets standard
|
|
37
|
+
* https://github.com/lukso-network/LIPs/blob/main/LSPs/LSP-5-ReceivedAssets.md
|
|
38
|
+
*/
|
|
16
39
|
library LSP5Utils {
|
|
17
40
|
/**
|
|
18
|
-
* @dev
|
|
19
|
-
*
|
|
41
|
+
* @dev Generating the data keys/values to be set on the account after receiving assets/vaults
|
|
42
|
+
*
|
|
43
|
+
* @param account The account where the Keys should be added
|
|
44
|
+
* @param arrayLengthKey The arrayLengthKey containing the number of the received assets/vaults
|
|
45
|
+
* @param mapKey The mapKey containing the interfaceID and the index of the asset in the `element in arrayKey`
|
|
46
|
+
* @param caller The address of the asset/vault received
|
|
47
|
+
* @param interfaceID The interfaceID of the asset/vault received
|
|
20
48
|
*/
|
|
21
49
|
function addMapAndArrayKey(
|
|
22
|
-
IERC725Y
|
|
23
|
-
bytes32
|
|
24
|
-
bytes32
|
|
25
|
-
address
|
|
26
|
-
bytes4
|
|
50
|
+
IERC725Y account,
|
|
51
|
+
bytes32 arrayLengthKey,
|
|
52
|
+
bytes32 mapKey,
|
|
53
|
+
address caller,
|
|
54
|
+
bytes4 interfaceID
|
|
27
55
|
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
56
|
+
/**
|
|
57
|
+
* We will be setting 3 keys:
|
|
58
|
+
* - Keys[0]: The arrayLengthKey containing the number of the received assets/vaults
|
|
59
|
+
* - Keys[1]: The element in arrayKey containing the address of each received asset/vault for a specific index
|
|
60
|
+
* - Keys[2]: The mapKey containing the interfaceID and the index of the asset in the `element in arrayKey`
|
|
61
|
+
*/
|
|
28
62
|
keys = new bytes32[](3);
|
|
29
63
|
values = new bytes[](3);
|
|
30
64
|
|
|
31
|
-
bytes memory
|
|
65
|
+
bytes memory encodedArrayLength = account.getData(arrayLengthKey);
|
|
32
66
|
|
|
33
|
-
|
|
34
|
-
|
|
67
|
+
// If it's the first asset to receive
|
|
68
|
+
if (encodedArrayLength.length == 0) {
|
|
69
|
+
keys[0] = arrayLengthKey;
|
|
70
|
+
values[0] = UtilsLib.uint256ToBytes(1);
|
|
35
71
|
|
|
36
|
-
|
|
72
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, 0);
|
|
73
|
+
values[1] = UtilsLib.addressToBytes(caller);
|
|
37
74
|
|
|
38
|
-
|
|
39
|
-
|
|
75
|
+
keys[2] = mapKey;
|
|
76
|
+
values[2] = bytes.concat(interfaceID, bytes8(0));
|
|
40
77
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
uint256 arrayLength = abi.decode(rawArrayLength, (uint256));
|
|
78
|
+
// If the storage is already initiated
|
|
79
|
+
} else if (encodedArrayLength.length == 32) {
|
|
80
|
+
uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
|
|
45
81
|
uint256 newArrayLength = arrayLength + 1;
|
|
46
82
|
|
|
47
|
-
keys[
|
|
48
|
-
|
|
83
|
+
keys[0] = arrayLengthKey;
|
|
49
84
|
values[0] = UtilsLib.uint256ToBytes(newArrayLength);
|
|
50
|
-
|
|
85
|
+
|
|
86
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, newArrayLength - 1);
|
|
87
|
+
values[1] = UtilsLib.addressToBytes(caller);
|
|
88
|
+
|
|
89
|
+
keys[2] = mapKey;
|
|
90
|
+
values[2] = bytes.concat(interfaceID, bytes8(uint64(arrayLength)));
|
|
91
|
+
} else {
|
|
92
|
+
revert InvalidLSP5ReceivedAssetsArrayLength(
|
|
93
|
+
encodedArrayLength,
|
|
94
|
+
encodedArrayLength.length
|
|
95
|
+
);
|
|
51
96
|
}
|
|
52
97
|
}
|
|
53
98
|
|
|
54
99
|
/**
|
|
55
|
-
* @dev
|
|
56
|
-
*
|
|
100
|
+
* @dev Generating the data keys/values to be removed/changed on the account after sending assets/vaults
|
|
101
|
+
*
|
|
102
|
+
* @param account The account where the Keys should be added
|
|
103
|
+
* @param arrayLengthKey The arrayLengthKey containing the number of the received assets/vaults
|
|
104
|
+
* @param mapKeyPrefix The mapKey prefix relative to LSP5ReceivedAssetsMap or LSP10VaultsMap Keys
|
|
105
|
+
* @param mapKeyToRemove The mapKey of the asset sent
|
|
106
|
+
* @param mapValue The mapValue of the asset/vault sent
|
|
57
107
|
*/
|
|
58
108
|
function removeMapAndArrayKey(
|
|
59
|
-
IERC725Y
|
|
60
|
-
bytes32
|
|
61
|
-
|
|
62
|
-
bytes32
|
|
109
|
+
IERC725Y account,
|
|
110
|
+
bytes32 arrayLengthKey,
|
|
111
|
+
bytes10 mapKeyPrefix,
|
|
112
|
+
bytes32 mapKeyToRemove,
|
|
63
113
|
bytes memory mapValue
|
|
64
114
|
) 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
|
-
|
|
115
|
+
// Updating the number of the received assets/vaults
|
|
116
|
+
bytes memory encodedArrayLength = account.getData(arrayLengthKey);
|
|
117
|
+
uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
|
|
72
118
|
uint256 newLength = arrayLength - 1;
|
|
73
119
|
|
|
120
|
+
uint64 index = extractIndexFromMap(mapValue);
|
|
121
|
+
bytes32 arrayElementKeyToRemove = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
122
|
+
arrayLengthKey,
|
|
123
|
+
index
|
|
124
|
+
);
|
|
125
|
+
|
|
74
126
|
if (index == (arrayLength - 1)) {
|
|
127
|
+
/**
|
|
128
|
+
* We will be updating/removing 3 keys:
|
|
129
|
+
* - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets/vaults
|
|
130
|
+
* - Keys[1]: [Remove] The element in arrayKey (Remove the address of the asset sent)
|
|
131
|
+
* - Keys[2]: [Remove] The mapKey (Remove the interfaceId and the index of the asset sent)
|
|
132
|
+
*/
|
|
75
133
|
keys = new bytes32[](3);
|
|
76
134
|
values = new bytes[](3);
|
|
77
135
|
|
|
78
|
-
keys[0] =
|
|
136
|
+
keys[0] = arrayLengthKey;
|
|
79
137
|
values[0] = UtilsLib.uint256ToBytes(newLength);
|
|
80
138
|
|
|
81
|
-
keys[1] =
|
|
139
|
+
keys[1] = mapKeyToRemove;
|
|
82
140
|
values[1] = "";
|
|
83
141
|
|
|
84
|
-
keys[2] =
|
|
142
|
+
keys[2] = arrayElementKeyToRemove;
|
|
85
143
|
values[2] = "";
|
|
144
|
+
|
|
145
|
+
// Swapping last element in ArrayKey with the element in ArrayKey to remove || {Swap and pop} method;
|
|
146
|
+
// check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
|
|
86
147
|
} else {
|
|
148
|
+
/**
|
|
149
|
+
* We will be updating/removing 5 keys:
|
|
150
|
+
* - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets/vaults
|
|
151
|
+
* - Keys[1]: [Remove] The mapKey of the asset to remove (Remove the interfaceId and the index of the asset sent)
|
|
152
|
+
* - Keys[2]: [Update] The element in arrayKey to remove (Swap with the address of the last element in Array)
|
|
153
|
+
* - Keys[3]: [Remove] The last element in arrayKey (Remove (pop) the address of the last element as it's already swapped)
|
|
154
|
+
* - Keys[4]: [Update] The mapKey of the last element in array (Update the new index and the interfaceID)
|
|
155
|
+
*/
|
|
87
156
|
keys = new bytes32[](5);
|
|
88
157
|
values = new bytes[](5);
|
|
89
158
|
|
|
90
|
-
keys[0] =
|
|
159
|
+
keys[0] = arrayLengthKey;
|
|
91
160
|
values[0] = UtilsLib.uint256ToBytes(newLength);
|
|
92
161
|
|
|
93
|
-
keys[1] =
|
|
162
|
+
keys[1] = mapKeyToRemove;
|
|
94
163
|
values[1] = "";
|
|
95
164
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
bytes memory
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
165
|
+
// Generate all data Keys/values of the last element in Array to swap
|
|
166
|
+
// with data Keys/values of the asset to remove
|
|
167
|
+
bytes32 lastArrayElementKey = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
168
|
+
arrayLengthKey,
|
|
169
|
+
newLength
|
|
170
|
+
);
|
|
171
|
+
bytes memory lastArrayElementValue = account.getData(lastArrayElementKey);
|
|
172
|
+
|
|
173
|
+
bytes32 lastArrayElementMapKey = LSP2Utils.generateMappingKey(
|
|
174
|
+
mapKeyPrefix,
|
|
175
|
+
bytes20(lastArrayElementValue)
|
|
176
|
+
);
|
|
177
|
+
bytes memory lastArrayElementMapValue = account.getData(lastArrayElementMapKey);
|
|
178
|
+
bytes memory interfaceID = BytesLib.slice(lastArrayElementMapValue, 0, 4);
|
|
179
|
+
|
|
180
|
+
keys[2] = arrayElementKeyToRemove;
|
|
181
|
+
values[2] = lastArrayElementValue;
|
|
182
|
+
|
|
183
|
+
keys[3] = lastArrayElementKey;
|
|
110
184
|
values[3] = "";
|
|
111
185
|
|
|
112
|
-
keys[4] =
|
|
113
|
-
values[4] = bytes.concat(
|
|
186
|
+
keys[4] = lastArrayElementMapKey;
|
|
187
|
+
values[4] = bytes.concat(interfaceID, bytes8(index));
|
|
114
188
|
}
|
|
115
189
|
}
|
|
116
190
|
|
|
117
191
|
function addMapAndArrayKeyViaKeyManager(
|
|
118
|
-
IERC725Y
|
|
119
|
-
bytes32
|
|
120
|
-
bytes32
|
|
121
|
-
address
|
|
122
|
-
bytes4
|
|
123
|
-
address
|
|
192
|
+
IERC725Y account,
|
|
193
|
+
bytes32 arrayLengthKey,
|
|
194
|
+
bytes32 mapKey,
|
|
195
|
+
address caller,
|
|
196
|
+
bytes4 interfaceID,
|
|
197
|
+
address keyManager
|
|
124
198
|
) internal returns (bytes memory result) {
|
|
125
|
-
(bytes32[] memory
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
199
|
+
(bytes32[] memory keys, bytes[] memory values) = addMapAndArrayKey(
|
|
200
|
+
account,
|
|
201
|
+
arrayLengthKey,
|
|
202
|
+
mapKey,
|
|
203
|
+
caller,
|
|
204
|
+
interfaceID
|
|
131
205
|
);
|
|
132
|
-
result = LSP6Utils.setDataViaKeyManager(
|
|
206
|
+
result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
|
|
133
207
|
}
|
|
134
208
|
|
|
135
209
|
function removeMapAndArrayKeyViaKeyManager(
|
|
136
|
-
IERC725Y
|
|
137
|
-
bytes32
|
|
138
|
-
|
|
139
|
-
bytes32
|
|
210
|
+
IERC725Y account,
|
|
211
|
+
bytes32 arrayLengthKey,
|
|
212
|
+
bytes10 mapKeyPrefix,
|
|
213
|
+
bytes32 mapKeyToRemove,
|
|
140
214
|
bytes memory mapValue,
|
|
141
215
|
address keyManager
|
|
142
216
|
) internal returns (bytes memory result) {
|
|
143
|
-
(bytes32[] memory
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
217
|
+
(bytes32[] memory keys, bytes[] memory values) = removeMapAndArrayKey(
|
|
218
|
+
account,
|
|
219
|
+
arrayLengthKey,
|
|
220
|
+
mapKeyPrefix,
|
|
221
|
+
mapKeyToRemove,
|
|
148
222
|
mapValue
|
|
149
223
|
);
|
|
150
|
-
result = LSP6Utils.setDataViaKeyManager(keyManager,
|
|
224
|
+
result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
|
|
151
225
|
}
|
|
152
226
|
|
|
153
227
|
function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint64) {
|
|
@@ -11,7 +11,7 @@ interface ILSP6KeyManager is
|
|
|
11
11
|
IERC1271
|
|
12
12
|
/* is ERC165 */
|
|
13
13
|
{
|
|
14
|
-
event Executed(uint256 indexed
|
|
14
|
+
event Executed(uint256 indexed value, bytes4 selector);
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @notice returns the address of the account linked to this KeyManager
|
|
@@ -25,31 +25,31 @@ interface ILSP6KeyManager is
|
|
|
25
25
|
function target() external view returns (address);
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* @notice get latest nonce for `
|
|
28
|
+
* @notice get latest nonce for `from` for channel ID: `channelId`
|
|
29
29
|
* @dev use channel ID = 0 for sequential nonces, any other number for out-of-order execution (= execution in parallel)
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
30
|
+
* @param from caller address
|
|
31
|
+
* @param channelId channel id
|
|
32
32
|
*/
|
|
33
|
-
function getNonce(address
|
|
33
|
+
function getNonce(address from, uint256 channelId) external view returns (uint256);
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* @notice execute the following payload on the ERC725Account: `
|
|
36
|
+
* @notice execute the following payload on the ERC725Account: `payload`
|
|
37
37
|
* @dev the ERC725Account will return some data on successful call, or revert on failure
|
|
38
|
-
* @param
|
|
39
|
-
* @return
|
|
38
|
+
* @param payload the payload to execute. Obtained in web3 via encodeABI()
|
|
39
|
+
* @return the data being returned by the ERC725 Account
|
|
40
40
|
*/
|
|
41
|
-
function execute(bytes calldata
|
|
41
|
+
function execute(bytes calldata payload) external payable returns (bytes memory);
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* @dev allows anybody to execute given they have a signed message from an executor
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @param
|
|
48
|
-
* @return
|
|
45
|
+
* @param signature bytes32 ethereum signature
|
|
46
|
+
* @param nonce the address' nonce (in a specific `_channel`), obtained via `getNonce(...)`. Used to prevent replay attack
|
|
47
|
+
* @param payload obtained via encodeABI() in web3
|
|
48
|
+
* @return the data being returned by the ERC725 Account
|
|
49
49
|
*/
|
|
50
50
|
function executeRelayCall(
|
|
51
|
-
bytes memory
|
|
52
|
-
uint256
|
|
53
|
-
bytes calldata
|
|
51
|
+
bytes memory signature,
|
|
52
|
+
uint256 nonce,
|
|
53
|
+
bytes calldata payload
|
|
54
54
|
) external payable returns (bytes memory);
|
|
55
55
|
}
|
|
@@ -17,20 +17,20 @@ bytes16 constant _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX = 0xdf30dba06db6a30e65
|
|
|
17
17
|
// AddressPermissions:...
|
|
18
18
|
bytes6 constant _LSP6KEY_ADDRESSPERMISSIONS_PREFIX = 0x4b80742de2bf;
|
|
19
19
|
|
|
20
|
-
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('Permissions'))
|
|
21
|
-
|
|
20
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('Permissions'))
|
|
21
|
+
bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX = 0x4b80742de2bf82acb363; // AddressPermissions:Permissions:<address> --> bytes32
|
|
22
22
|
|
|
23
|
-
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedAddresses'))
|
|
24
|
-
|
|
23
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedAddresses'))
|
|
24
|
+
bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX = 0x4b80742de2bfc6dd6b3c; // AddressPermissions:AllowedAddresses:<address> --> address[]
|
|
25
25
|
|
|
26
|
-
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedFunctions'))
|
|
27
|
-
|
|
26
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedFunctions'))
|
|
27
|
+
bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDFUNCTIONS_PREFIX = 0x4b80742de2bf8efea1e8; // AddressPermissions:AllowedFunctions:<address> --> bytes4[]
|
|
28
28
|
|
|
29
|
-
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedStandards'))
|
|
30
|
-
|
|
29
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedStandards'))
|
|
30
|
+
bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDSTANDARDS_PREFIX = 0x4b80742de2bf3efa94a3; // AddressPermissions:AllowedStandards:<address> --> bytes4[]
|
|
31
31
|
|
|
32
|
-
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedERC725YKeys'))
|
|
33
|
-
|
|
32
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedERC725YKeys'))
|
|
33
|
+
bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX = 0x4b80742de2bf90b8b485; // AddressPermissions:AllowedERC725YKeys:<address> --> bytes32[]
|
|
34
34
|
|
|
35
35
|
// DEFAULT PERMISSIONS VALUES
|
|
36
36
|
bytes32 constant _PERMISSION_CHANGEOWNER = 0x0000000000000000000000000000000000000000000000000000000000000001;
|
|
@@ -43,23 +43,18 @@ bytes32 constant _PERMISSION_DELEGATECALL = 0x0000000000000000000000000000
|
|
|
43
43
|
bytes32 constant _PERMISSION_DEPLOY = 0x0000000000000000000000000000000000000000000000000000000000000080;
|
|
44
44
|
bytes32 constant _PERMISSION_TRANSFERVALUE = 0x0000000000000000000000000000000000000000000000000000000000000100;
|
|
45
45
|
bytes32 constant _PERMISSION_SIGN = 0x0000000000000000000000000000000000000000000000000000000000000200;
|
|
46
|
+
bytes32 constant _PERMISSION_ENCRYPT = 0x0000000000000000000000000000000000000000000000000000000000000400;
|
|
46
47
|
|
|
47
48
|
// SUPER PERMISSIONS
|
|
48
49
|
// -----
|
|
49
50
|
// allow to not check for AddressPermissions:AllowedERC725YKeys:...
|
|
50
|
-
bytes32 constant _PERMISSION_SUPER_SETDATA =
|
|
51
|
+
bytes32 constant _PERMISSION_SUPER_SETDATA = 0x0000000000000000000000000000000000000000000000000000000000000800;
|
|
51
52
|
|
|
52
53
|
// allow to not check for:
|
|
53
54
|
// - AddressPermissions:AllowedAddress:...
|
|
54
55
|
// - AddressPermissions:AllowedStandards:...
|
|
55
56
|
// - AddressPermissions:AllowedFunctions:...
|
|
56
|
-
bytes32 constant _PERMISSION_SUPER_TRANSFERVALUE =
|
|
57
|
-
bytes32 constant _PERMISSION_SUPER_CALL
|
|
58
|
-
bytes32 constant _PERMISSION_SUPER_STATICCALL
|
|
59
|
-
bytes32 constant _PERMISSION_SUPER_DELEGATECALL
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
/// @dev see IERC725Y interface
|
|
63
|
-
/// https://github.com/ERC725Alliance/ERC725/blob/main/implementations/contracts/interfaces/IERC725Y.sol
|
|
64
|
-
bytes4 constant setDataSingleSelector = bytes4(keccak256("setData(bytes32,bytes)"));
|
|
65
|
-
bytes4 constant setDataMultipleSelector = bytes4(keccak256("setData(bytes32[],bytes[])"));
|
|
57
|
+
bytes32 constant _PERMISSION_SUPER_TRANSFERVALUE = 0x0000000000000000000000000000000000000000000000000000000000001000;
|
|
58
|
+
bytes32 constant _PERMISSION_SUPER_CALL = 0x0000000000000000000000000000000000000000000000000000000000002000;
|
|
59
|
+
bytes32 constant _PERMISSION_SUPER_STATICCALL = 0x0000000000000000000000000000000000000000000000000000000000004000;
|
|
60
|
+
bytes32 constant _PERMISSION_SUPER_DELEGATECALL = 0x0000000000000000000000000000000000000000000000000000000000008000;
|
|
@@ -2,36 +2,73 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* @dev
|
|
5
|
+
* @dev reverts when address `from` does not have any permissions set
|
|
6
6
|
* on the account linked to this Key Manager
|
|
7
7
|
* @param from the address that does not have permissions
|
|
8
8
|
*/
|
|
9
9
|
error NoPermissionsSet(address from);
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* @dev address `from` is not authorised to `permission`
|
|
12
|
+
* @dev reverts when address `from` is not authorised to perform `permission` on the linked account
|
|
13
13
|
* @param permission permission required
|
|
14
14
|
* @param from address not-authorised
|
|
15
15
|
*/
|
|
16
16
|
error NotAuthorised(address from, string permission);
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @dev address `from` is not authorised to interact with `disallowedAddress` via account
|
|
19
|
+
* @dev reverts when address `from` is not authorised to interact with `disallowedAddress` via the linked account
|
|
20
20
|
* @param from address making the request
|
|
21
21
|
* @param disallowedAddress address that `from` is not authorised to call
|
|
22
22
|
*/
|
|
23
23
|
error NotAllowedAddress(address from, address disallowedAddress);
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* @dev address `from` is
|
|
26
|
+
* @dev reverts when address `from` is restricted to interact only with smart contracts implementing specific standard interface(s)
|
|
27
|
+
* and try to call an address `addressNotImplementingAllowedStandard` that does not implement one of this restricted standard interfaces.
|
|
28
|
+
* @param from address making the request
|
|
29
|
+
* @param addressNotImplementingAllowedStandard the address of the smart contract that `from` is trying to interact with,
|
|
30
|
+
* and that does not implement an allowed interface.
|
|
31
|
+
*/
|
|
32
|
+
error NotAllowedStandard(address from, address addressNotImplementingAllowedStandard);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @dev reverts when address `from` is not authorised to run `disallowedFunction` via the linked account
|
|
27
36
|
* @param from address making the request
|
|
28
37
|
* @param disallowedFunction bytes4 function selector that `from` is not authorised to run
|
|
29
38
|
*/
|
|
30
39
|
error NotAllowedFunction(address from, bytes4 disallowedFunction);
|
|
31
40
|
|
|
32
41
|
/**
|
|
33
|
-
* @dev address `from` is not authorised to set the key `disallowedKey` on the account
|
|
42
|
+
* @dev reverts when address `from` is not authorised to set the key `disallowedKey` on the linked account
|
|
34
43
|
* @param from address making the request
|
|
35
44
|
* @param disallowedKey a bytes32 key that `from` is not authorised to set on the ERC725Y storage
|
|
36
45
|
*/
|
|
37
46
|
error NotAllowedERC725YKey(address from, bytes32 disallowedKey);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @dev reverts when `dataKey` is a bytes32 that does not adhere to any of the
|
|
50
|
+
* permission data keys specified by the LSP6 standard
|
|
51
|
+
*
|
|
52
|
+
* @param dataKey the dataKey that does not match with any of the standard LSP6 permission data keys
|
|
53
|
+
*/
|
|
54
|
+
error NotRecognisedPermissionKey(bytes32 dataKey);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @dev reverts when the address provided as a target (= account) linked to this KeyManager is invalid
|
|
58
|
+
* e.g. address(0)
|
|
59
|
+
*/
|
|
60
|
+
error InvalidLSP6Target();
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @dev reverts when the `signer` address retrieved from the `signature` has an invalid nonce: `invalidNonce`.
|
|
64
|
+
* @param signer the address of the signer
|
|
65
|
+
* @param invalidNonce the nonce retrieved for the `signer` address
|
|
66
|
+
* @param signature the signature used to retrieve the `signer` address
|
|
67
|
+
*/
|
|
68
|
+
error InvalidRelayNonce(address signer, uint256 invalidNonce, bytes signature);
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @dev reverts when trying to run an invalid function on the linked target account via the Key Manager.
|
|
72
|
+
* @param invalidFunction the bytes4 selector of the invalid function
|
|
73
|
+
*/
|
|
74
|
+
error InvalidERC725Function(bytes4 invalidFunction);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.5;
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
5
|
import {LSP6KeyManagerCore} from "./LSP6KeyManagerCore.sol";
|
|
6
|
+
import {InvalidLSP6Target} from "./LSP6Errors.sol";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @title Implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage
|
|
@@ -12,9 +13,10 @@ import {LSP6KeyManagerCore} from "./LSP6KeyManagerCore.sol";
|
|
|
12
13
|
contract LSP6KeyManager is LSP6KeyManagerCore {
|
|
13
14
|
/**
|
|
14
15
|
* @notice Initiate the account with the address of the ERC725Account contract and sets LSP6KeyManager InterfaceId
|
|
15
|
-
* @param
|
|
16
|
+
* @param target_ The address of the ER725Account to control
|
|
16
17
|
*/
|
|
17
|
-
constructor(address
|
|
18
|
-
|
|
18
|
+
constructor(address target_) {
|
|
19
|
+
if (target_ == address(0)) revert InvalidLSP6Target();
|
|
20
|
+
target = target_;
|
|
19
21
|
}
|
|
20
22
|
}
|