@lukso/lsp-smart-contracts 0.5.0 → 0.6.2
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 +38 -9
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +398 -0
- package/artifacts/LSP0ERC725AccountInit.json +444 -0
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +21 -5
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +21 -5
- package/artifacts/LSP4Compatibility.json +195 -0
- package/artifacts/LSP4DigitalAssetMetadata.json +179 -0
- package/artifacts/LSP4DigitalAssetMetadataInit.json +241 -0
- package/artifacts/LSP6KeyManager.json +110 -35
- package/artifacts/LSP6KeyManagerInit.json +123 -30
- package/artifacts/LSP7CappedSupply.json +146 -11
- package/artifacts/LSP7CappedSupplyInit.json +167 -57
- package/artifacts/LSP7CompatibleERC20.json +714 -0
- package/artifacts/LSP7CompatibleERC20Init.json +760 -0
- package/artifacts/LSP7CompatibleERC20Mintable.json +742 -0
- package/artifacts/LSP7CompatibleERC20MintableInit.json +783 -0
- package/artifacts/LSP7DigitalAsset.json +138 -13
- package/artifacts/LSP7DigitalAssetInit.json +167 -34
- package/artifacts/LSP7Mintable.json +139 -14
- package/artifacts/LSP7MintableInit.json +168 -35
- package/artifacts/LSP8CappedSupply.json +147 -11
- package/artifacts/LSP8CappedSupplyInit.json +176 -37
- package/artifacts/LSP8CompatibleERC721.json +842 -0
- package/artifacts/LSP8CompatibleERC721Init.json +883 -0
- package/artifacts/LSP8CompatibleERC721Mintable.json +881 -0
- package/artifacts/LSP8CompatibleERC721MintableInit.json +922 -0
- package/artifacts/LSP8IdentifiableDigitalAsset.json +139 -13
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +176 -19
- package/artifacts/LSP8Mintable.json +151 -14
- package/artifacts/LSP8MintableInit.json +188 -20
- package/artifacts/LSP9Vault.json +374 -0
- package/artifacts/LSP9VaultInit.json +420 -0
- package/artifacts/UniversalFactory.json +127 -0
- package/artifacts/UniversalProfile.json +89 -32
- package/artifacts/UniversalProfileInit.json +133 -32
- package/artifacts/UniversalReceiverAddressStore.json +209 -0
- package/constants.js +535 -0
- package/contracts/Custom/ClaimOwnership.sol +34 -0
- package/contracts/Custom/ERC165Checker.sol +130 -0
- package/contracts/Custom/IClaimOwnership.sol +10 -0
- package/contracts/Factories/Create2Factory.sol +3 -13
- package/contracts/Factories/UniversalFactory.sol +164 -0
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -9
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +7 -9
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +108 -55
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +11 -4
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +6 -21
- package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +10 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +3 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
- package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +3 -9
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +67 -184
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +58 -6
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +51 -89
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +46 -6
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +62 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +9 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +201 -0
- package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +5 -14
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +22 -8
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +26 -20
- package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +16 -0
- package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +231 -0
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +28 -25
- package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -25
- package/contracts/LSP6KeyManager/LSP6Errors.sol +66 -0
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +7 -6
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +465 -378
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +13 -5
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +9 -15
- package/contracts/LSP6KeyManager/LSP6Utils.sol +107 -0
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +27 -9
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +73 -95
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +19 -9
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +27 -23
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/{ILSP7CompatibilityForERC20.sol → ILSP7CompatibleERC20.sol} +7 -9
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +8 -7
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +10 -15
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +67 -0
- package/contracts/LSP7DigitalAsset/extensions/{LSP7CompatibilityForERC20Core.sol → LSP7CompatibleERC20Core.sol} +36 -50
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +29 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +67 -0
- package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +22 -0
- package/contracts/LSP7DigitalAsset/{extensions/LSP7CompatibilityForERC20Init.sol → presets/LSP7CompatibleERC20MintableInit.sol} +6 -5
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +27 -0
- package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7Mintable.sol +4 -3
- package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableCore.sol +5 -5
- package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableInit.sol +11 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +34 -0
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -16
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +6 -3
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +22 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +23 -10
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +103 -136
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +17 -11
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +26 -21
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{ILSP8CompatibilityForERC721.sol → ILSP8CompatibleERC721.sol} +4 -12
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +9 -15
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +14 -12
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +3 -8
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +13 -20
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityConstants.sol → LSP8CompatibleConstants.sol} +0 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +101 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Core.sol → LSP8CompatibleERC721Core.sol} +38 -95
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/{LSP8CompatibilityForERC721Init.sol → LSP8CompatibleERC721Init.sol} +4 -6
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +93 -0
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +22 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +23 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +27 -0
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8Mintable.sol +4 -3
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableCore.sol +5 -8
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableInit.sol +11 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +37 -0
- package/contracts/LSP9Vault/LSP9Constants.sol +14 -5
- package/contracts/LSP9Vault/LSP9Vault.sol +20 -38
- package/contracts/LSP9Vault/LSP9VaultCore.sol +123 -92
- package/contracts/LSP9Vault/LSP9VaultInit.sol +12 -4
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +20 -46
- package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
- package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +62 -0
- package/contracts/UniversalProfile.sol +11 -7
- package/contracts/UniversalProfileInit.sol +12 -4
- package/contracts/UniversalProfileInitAbstract.sol +12 -20
- package/contracts/Utils/UtilsLib.sol +21 -13
- package/package.json +23 -9
- package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
- package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
- package/artifacts/LSP7CompatibilityForERC20.json +0 -571
- package/artifacts/LSP8CompatibilityForERC721.json +0 -716
- package/constants.ts +0 -356
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +0 -52
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +0 -26
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +0 -28
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +0 -41
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +0 -23
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +0 -25
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +0 -56
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +0 -55
- package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +0 -47
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +0 -92
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +0 -90
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
- package/contracts/Utils/ERC725Utils.sol +0 -169
- package/contracts/Utils/LSP2Utils.sol +0 -127
- package/contracts/Utils/LSP6Utils.sol +0 -63
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
6
|
+
|
|
7
|
+
// libraries
|
|
8
|
+
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
9
|
+
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
10
|
+
import {LSP6Utils} from "../LSP6KeyManager/LSP6Utils.sol";
|
|
11
|
+
import {UtilsLib} from "../Utils/UtilsLib.sol";
|
|
12
|
+
|
|
13
|
+
// constants
|
|
14
|
+
import {_TYPEID_LSP7_TOKENSSENDER} from "../LSP7DigitalAsset/LSP7Constants.sol";
|
|
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
|
+
*/
|
|
39
|
+
library LSP5Utils {
|
|
40
|
+
/**
|
|
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
|
|
48
|
+
*/
|
|
49
|
+
function addMapAndArrayKey(
|
|
50
|
+
IERC725Y account,
|
|
51
|
+
bytes32 arrayLengthKey,
|
|
52
|
+
bytes32 mapKey,
|
|
53
|
+
address caller,
|
|
54
|
+
bytes4 interfaceID
|
|
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
|
+
*/
|
|
62
|
+
keys = new bytes32[](3);
|
|
63
|
+
values = new bytes[](3);
|
|
64
|
+
|
|
65
|
+
bytes memory encodedArrayLength = account.getData(arrayLengthKey);
|
|
66
|
+
|
|
67
|
+
// If it's the first asset to receive
|
|
68
|
+
if (encodedArrayLength.length == 0) {
|
|
69
|
+
keys[0] = arrayLengthKey;
|
|
70
|
+
values[0] = UtilsLib.uint256ToBytes(1);
|
|
71
|
+
|
|
72
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, 0);
|
|
73
|
+
values[1] = UtilsLib.addressToBytes(caller);
|
|
74
|
+
|
|
75
|
+
keys[2] = mapKey;
|
|
76
|
+
values[2] = bytes.concat(interfaceID, bytes8(0));
|
|
77
|
+
|
|
78
|
+
// If the storage is already initiated
|
|
79
|
+
} else if (encodedArrayLength.length == 32) {
|
|
80
|
+
uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
|
|
81
|
+
uint256 newArrayLength = arrayLength + 1;
|
|
82
|
+
|
|
83
|
+
keys[0] = arrayLengthKey;
|
|
84
|
+
values[0] = UtilsLib.uint256ToBytes(newArrayLength);
|
|
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
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
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
|
|
107
|
+
*/
|
|
108
|
+
function removeMapAndArrayKey(
|
|
109
|
+
IERC725Y account,
|
|
110
|
+
bytes32 arrayLengthKey,
|
|
111
|
+
bytes12 mapKeyPrefix,
|
|
112
|
+
bytes32 mapKeyToRemove,
|
|
113
|
+
bytes memory mapValue
|
|
114
|
+
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
115
|
+
// Updating the number of the received assets/vaults
|
|
116
|
+
bytes memory encodedArrayLength = account.getData(arrayLengthKey);
|
|
117
|
+
uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
|
|
118
|
+
uint256 newLength = arrayLength - 1;
|
|
119
|
+
|
|
120
|
+
uint64 index = extractIndexFromMap(mapValue);
|
|
121
|
+
bytes32 arrayElementKeyToRemove = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
122
|
+
arrayLengthKey,
|
|
123
|
+
index
|
|
124
|
+
);
|
|
125
|
+
|
|
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
|
+
*/
|
|
133
|
+
keys = new bytes32[](3);
|
|
134
|
+
values = new bytes[](3);
|
|
135
|
+
|
|
136
|
+
keys[0] = arrayLengthKey;
|
|
137
|
+
values[0] = UtilsLib.uint256ToBytes(newLength);
|
|
138
|
+
|
|
139
|
+
keys[1] = mapKeyToRemove;
|
|
140
|
+
values[1] = "";
|
|
141
|
+
|
|
142
|
+
keys[2] = arrayElementKeyToRemove;
|
|
143
|
+
values[2] = "";
|
|
144
|
+
|
|
145
|
+
// Swapping last element in ArrayKey with the elemnt in ArrayKey to remove || {Swap and pop} method;
|
|
146
|
+
// check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
|
|
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
|
+
*/
|
|
156
|
+
keys = new bytes32[](5);
|
|
157
|
+
values = new bytes[](5);
|
|
158
|
+
|
|
159
|
+
keys[0] = arrayLengthKey;
|
|
160
|
+
values[0] = UtilsLib.uint256ToBytes(newLength);
|
|
161
|
+
|
|
162
|
+
keys[1] = mapKeyToRemove;
|
|
163
|
+
values[1] = "";
|
|
164
|
+
|
|
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;
|
|
184
|
+
values[3] = "";
|
|
185
|
+
|
|
186
|
+
keys[4] = lastArrayElementMapKey;
|
|
187
|
+
values[4] = bytes.concat(interfaceID, bytes8(index));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function addMapAndArrayKeyViaKeyManager(
|
|
192
|
+
IERC725Y account,
|
|
193
|
+
bytes32 arrayLengthKey,
|
|
194
|
+
bytes32 mapKey,
|
|
195
|
+
address caller,
|
|
196
|
+
bytes4 interfaceID,
|
|
197
|
+
address keyManager
|
|
198
|
+
) internal returns (bytes memory result) {
|
|
199
|
+
(bytes32[] memory keys, bytes[] memory values) = addMapAndArrayKey(
|
|
200
|
+
account,
|
|
201
|
+
arrayLengthKey,
|
|
202
|
+
mapKey,
|
|
203
|
+
caller,
|
|
204
|
+
interfaceID
|
|
205
|
+
);
|
|
206
|
+
result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function removeMapAndArrayKeyViaKeyManager(
|
|
210
|
+
IERC725Y account,
|
|
211
|
+
bytes32 arrayLengthKey,
|
|
212
|
+
bytes12 mapKeyPrefix,
|
|
213
|
+
bytes32 mapKeyToRemove,
|
|
214
|
+
bytes memory mapValue,
|
|
215
|
+
address keyManager
|
|
216
|
+
) internal returns (bytes memory result) {
|
|
217
|
+
(bytes32[] memory keys, bytes[] memory values) = removeMapAndArrayKey(
|
|
218
|
+
account,
|
|
219
|
+
arrayLengthKey,
|
|
220
|
+
mapKeyPrefix,
|
|
221
|
+
mapKeyToRemove,
|
|
222
|
+
mapValue
|
|
223
|
+
);
|
|
224
|
+
result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint64) {
|
|
228
|
+
bytes memory val = BytesLib.slice(mapValue, 4, 8);
|
|
229
|
+
return BytesLib.toUint64(val, 0);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
5
|
-
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
5
|
+
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @dev Contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage
|
|
@@ -11,42 +11,45 @@ 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
|
-
* @notice
|
|
17
|
+
* @notice returns the address of the account linked to this KeyManager
|
|
18
|
+
* @dev this can be a contract that implements
|
|
19
|
+
* - ERC725X only
|
|
20
|
+
* - ERC725Y only
|
|
21
|
+
* - any ERC725 based contract (so implementing both ERC725X and ERC725Y)
|
|
22
|
+
*
|
|
23
|
+
* @return the address of the linked account
|
|
24
|
+
*/
|
|
25
|
+
function target() external view returns (address);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @notice get latest nonce for `from` for channel ID: `channelId`
|
|
18
29
|
* @dev use channel ID = 0 for sequential nonces, any other number for out-of-order execution (= execution in parallel)
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
30
|
+
* @param from caller address
|
|
31
|
+
* @param channelId channel id
|
|
21
32
|
*/
|
|
22
|
-
function getNonce(address
|
|
23
|
-
external
|
|
24
|
-
view
|
|
25
|
-
returns (uint256);
|
|
33
|
+
function getNonce(address from, uint256 channelId) external view returns (uint256);
|
|
26
34
|
|
|
27
35
|
/**
|
|
28
|
-
* @notice execute the following payload on the ERC725Account: `
|
|
36
|
+
* @notice execute the following payload on the ERC725Account: `_calldata`
|
|
29
37
|
* @dev the ERC725Account will return some data on successful call, or revert on failure
|
|
30
|
-
* @param
|
|
31
|
-
* @return
|
|
38
|
+
* @param payload the payload to execute. Obtained in web3 via encodeABI()
|
|
39
|
+
* @return the data being returned by the ERC725 Account
|
|
32
40
|
*/
|
|
33
|
-
function execute(bytes calldata
|
|
34
|
-
external
|
|
35
|
-
payable
|
|
36
|
-
returns (bytes memory);
|
|
41
|
+
function execute(bytes calldata payload) external payable returns (bytes memory);
|
|
37
42
|
|
|
38
43
|
/**
|
|
39
44
|
* @dev allows anybody to execute given they have a signed message from an executor
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
43
|
-
* @
|
|
44
|
-
* @return result_ the data being returned by the ERC725 Account
|
|
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
|
|
45
49
|
*/
|
|
46
50
|
function executeRelayCall(
|
|
47
|
-
|
|
48
|
-
uint256
|
|
49
|
-
bytes calldata
|
|
50
|
-
bytes memory _signature
|
|
51
|
+
bytes memory signature,
|
|
52
|
+
uint256 nonce,
|
|
53
|
+
bytes calldata payload
|
|
51
54
|
) external payable returns (bytes memory);
|
|
52
55
|
}
|
|
@@ -2,28 +2,64 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
// --- ERC165 interface ids
|
|
5
|
-
bytes4 constant _INTERFACEID_LSP6 =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
5
|
+
bytes4 constant _INTERFACEID_LSP6 = 0xc403d48f;
|
|
6
|
+
|
|
7
|
+
// --- ERC725Y Keys
|
|
8
|
+
|
|
9
|
+
// PERMISSIONS KEYS
|
|
10
|
+
|
|
11
|
+
// keccak256('AddressPermissions[]')
|
|
12
|
+
bytes32 constant _LSP6KEY_ADDRESSPERMISSIONS_ARRAY = 0xdf30dba06db6a30e65354d9a64c609861f089545ca58c6b4dbe31a5f338cb0e3;
|
|
13
|
+
|
|
14
|
+
// AddressPermissions[index]
|
|
15
|
+
bytes16 constant _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX = 0xdf30dba06db6a30e65354d9a64c60986;
|
|
16
|
+
|
|
17
|
+
// AddressPermissions:...
|
|
18
|
+
bytes6 constant _LSP6KEY_ADDRESSPERMISSIONS_PREFIX = 0x4b80742de2bf;
|
|
19
|
+
|
|
20
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('Permissions')) + bytes2(0)
|
|
21
|
+
bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX = 0x4b80742de2bf82acb3630000; // AddressPermissions:Permissions:<address> --> bytes32
|
|
22
|
+
|
|
23
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedAddresses')) + bytes2(0)
|
|
24
|
+
bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX = 0x4b80742de2bfc6dd6b3c0000; // AddressPermissions:AllowedAddresses:<address> --> address[]
|
|
25
|
+
|
|
26
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedFunctions')) + bytes2(0)
|
|
27
|
+
bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDFUNCTIONS_PREFIX = 0x4b80742de2bf8efea1e80000; // AddressPermissions:AllowedFunctions:<address> --> bytes4[]
|
|
28
|
+
|
|
29
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedStandards')) + bytes2(0)
|
|
30
|
+
bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDSTANDARDS_PREFIX = 0x4b80742de2bf3efa94a30000; // AddressPermissions:AllowedStandards:<address> --> bytes4[]
|
|
31
|
+
|
|
32
|
+
// bytes6(keccak256('AddressPermissions')) + bytes4(keccak256('AllowedERC725YKeys')) + bytes2(0)
|
|
33
|
+
bytes12 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX = 0x4b80742de2bf90b8b4850000; // AddressPermissions:AllowedERC725YKeys:<address> --> bytes32[]
|
|
34
|
+
|
|
35
|
+
// DEFAULT PERMISSIONS VALUES
|
|
36
|
+
bytes32 constant _PERMISSION_CHANGEOWNER = 0x0000000000000000000000000000000000000000000000000000000000000001;
|
|
37
|
+
bytes32 constant _PERMISSION_CHANGEPERMISSIONS = 0x0000000000000000000000000000000000000000000000000000000000000002;
|
|
38
|
+
bytes32 constant _PERMISSION_ADDPERMISSIONS = 0x0000000000000000000000000000000000000000000000000000000000000004;
|
|
39
|
+
bytes32 constant _PERMISSION_SETDATA = 0x0000000000000000000000000000000000000000000000000000000000000008;
|
|
40
|
+
bytes32 constant _PERMISSION_CALL = 0x0000000000000000000000000000000000000000000000000000000000000010;
|
|
41
|
+
bytes32 constant _PERMISSION_STATICCALL = 0x0000000000000000000000000000000000000000000000000000000000000020;
|
|
42
|
+
bytes32 constant _PERMISSION_DELEGATECALL = 0x0000000000000000000000000000000000000000000000000000000000000040;
|
|
43
|
+
bytes32 constant _PERMISSION_DEPLOY = 0x0000000000000000000000000000000000000000000000000000000000000080;
|
|
44
|
+
bytes32 constant _PERMISSION_TRANSFERVALUE = 0x0000000000000000000000000000000000000000000000000000000000000100;
|
|
45
|
+
bytes32 constant _PERMISSION_SIGN = 0x0000000000000000000000000000000000000000000000000000000000000200;
|
|
46
|
+
|
|
47
|
+
// SUPER PERMISSIONS
|
|
48
|
+
// -----
|
|
49
|
+
// allow to not check for AddressPermissions:AllowedERC725YKeys:...
|
|
50
|
+
bytes32 constant _PERMISSION_SUPER_SETDATA = 0x0000000000000000000000000000000000000000000000000000000000000400;
|
|
51
|
+
|
|
52
|
+
// allow to not check for:
|
|
53
|
+
// - AddressPermissions:AllowedAddress:...
|
|
54
|
+
// - AddressPermissions:AllowedStandards:...
|
|
55
|
+
// - AddressPermissions:AllowedFunctions:...
|
|
56
|
+
bytes32 constant _PERMISSION_SUPER_TRANSFERVALUE = 0x0000000000000000000000000000000000000000000000000000000000000800;
|
|
57
|
+
bytes32 constant _PERMISSION_SUPER_CALL = 0x0000000000000000000000000000000000000000000000000000000000001000;
|
|
58
|
+
bytes32 constant _PERMISSION_SUPER_STATICCALL = 0x0000000000000000000000000000000000000000000000000000000000002000;
|
|
59
|
+
bytes32 constant _PERMISSION_SUPER_DELEGATECALL = 0x0000000000000000000000000000000000000000000000000000000000004000;
|
|
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[])"));
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @dev reverts when address `from` does not have any permissions set
|
|
6
|
+
* on the account linked to this Key Manager
|
|
7
|
+
* @param from the address that does not have permissions
|
|
8
|
+
*/
|
|
9
|
+
error NoPermissionsSet(address from);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @dev reverts when address `from` is not authorised to perform `permission` on the linked account
|
|
13
|
+
* @param permission permission required
|
|
14
|
+
* @param from address not-authorised
|
|
15
|
+
*/
|
|
16
|
+
error NotAuthorised(address from, string permission);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @dev reverts when address `from` is not authorised to interact with `disallowedAddress` via the linked account
|
|
20
|
+
* @param from address making the request
|
|
21
|
+
* @param disallowedAddress address that `from` is not authorised to call
|
|
22
|
+
*/
|
|
23
|
+
error NotAllowedAddress(address from, address disallowedAddress);
|
|
24
|
+
|
|
25
|
+
/**
|
|
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
|
|
36
|
+
* @param from address making the request
|
|
37
|
+
* @param disallowedFunction bytes4 function selector that `from` is not authorised to run
|
|
38
|
+
*/
|
|
39
|
+
error NotAllowedFunction(address from, bytes4 disallowedFunction);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @dev reverts when address `from` is not authorised to set the key `disallowedKey` on the linked account
|
|
43
|
+
* @param from address making the request
|
|
44
|
+
* @param disallowedKey a bytes32 key that `from` is not authorised to set on the ERC725Y storage
|
|
45
|
+
*/
|
|
46
|
+
error NotAllowedERC725YKey(address from, bytes32 disallowedKey);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @dev reverts when the address provided as a target (= account) linked to this KeyManager is invalid
|
|
50
|
+
* e.g. address(0)
|
|
51
|
+
*/
|
|
52
|
+
error InvalidLSP6Target();
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @dev reverts when the `signer` address retrieved from the `signature` has an invalid nonce: `invalidNonce`.
|
|
56
|
+
* @param signer the address of the signer
|
|
57
|
+
* @param invalidNonce the nonce retrieved for the `signer` address
|
|
58
|
+
* @param signature the signature used to retrieve the `signer` address
|
|
59
|
+
*/
|
|
60
|
+
error InvalidRelayNonce(address signer, uint256 invalidNonce, bytes signature);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @dev reverts when trying to run an invalid function on the linked target account via the Key Manager.
|
|
64
|
+
* @param invalidFunction the bytes4 selector of the invalid function
|
|
65
|
+
*/
|
|
66
|
+
error InvalidERC725Function(bytes4 invalidFunction);
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
pragma solidity ^0.8.6;
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
|
-
import "./LSP6KeyManagerCore.sol";
|
|
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
|
|
9
|
-
* @author Fabian Vogelsteller
|
|
10
|
+
* @author Fabian Vogelsteller <frozeman>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
|
|
10
11
|
* @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below
|
|
11
12
|
*/
|
|
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
|
-
|
|
19
|
-
|
|
18
|
+
constructor(address target_) {
|
|
19
|
+
if (target_ == address(0)) revert InvalidLSP6Target();
|
|
20
|
+
target = target_;
|
|
20
21
|
}
|
|
21
22
|
}
|