@lukso/lsp-smart-contracts 0.4.3 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -9
- package/artifacts/LSP0ERC725Account.json +398 -0
- package/artifacts/LSP0ERC725AccountInit.json +439 -0
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +7 -7
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +7 -7
- package/artifacts/LSP4Compatibility.json +195 -0
- package/artifacts/LSP4DigitalAssetMetadata.json +169 -0
- package/artifacts/LSP4DigitalAssetMetadataInit.json +231 -0
- package/artifacts/LSP6KeyManager.json +50 -28
- package/artifacts/LSP6KeyManagerInit.json +58 -23
- package/artifacts/LSP7CappedSupply.json +136 -11
- package/artifacts/LSP7CappedSupplyInit.json +163 -35
- package/artifacts/LSP7CompatibilityForERC20.json +204 -13
- package/artifacts/LSP7CompatibilityForERC20Init.json +727 -0
- package/artifacts/LSP7DigitalAsset.json +128 -13
- package/artifacts/LSP7DigitalAssetInit.json +152 -34
- package/artifacts/LSP7Mintable.json +129 -14
- package/artifacts/LSP7MintableInit.json +153 -35
- package/artifacts/LSP8CappedSupply.json +137 -11
- package/artifacts/LSP8CappedSupplyInit.json +172 -20
- package/artifacts/LSP8CompatibilityForERC721.json +138 -17
- package/artifacts/LSP8CompatibilityForERC721Init.json +873 -0
- package/artifacts/LSP8IdentifiableDigitalAsset.json +129 -13
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +161 -19
- package/artifacts/LSP8Mintable.json +141 -14
- package/artifacts/LSP8MintableInit.json +173 -20
- package/artifacts/LSP9Vault.json +374 -0
- package/artifacts/LSP9VaultInit.json +415 -0
- package/artifacts/UniversalFactory.json +127 -0
- package/artifacts/UniversalProfile.json +78 -53
- package/artifacts/UniversalProfileInit.json +117 -53
- package/artifacts/UniversalReceiverAddressStore.json +209 -0
- package/constants.js +500 -0
- package/contracts/Custom/ClaimOwnership.sol +31 -0
- package/contracts/Custom/ERC165Checker.sol +130 -0
- package/contracts/Custom/IClaimOwnership.sol +10 -0
- package/contracts/Factories/UniversalFactory.sol +155 -0
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -9
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +6 -8
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +92 -48
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +5 -5
- 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 +61 -165
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +49 -6
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +50 -90
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +40 -6
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +48 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +205 -0
- package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +6 -15
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +11 -8
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +14 -20
- package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +205 -0
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +21 -18
- package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -24
- package/contracts/LSP6KeyManager/LSP6Errors.sol +37 -0
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -4
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +475 -260
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +6 -5
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +7 -15
- package/contracts/LSP6KeyManager/LSP6Utils.sol +111 -0
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +22 -8
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +70 -96
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +8 -9
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +23 -21
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +22 -6
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +7 -6
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +9 -17
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +37 -45
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Core.sol +107 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol +22 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +66 -0
- package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
- 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 +3 -2
- 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 +21 -8
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +102 -135
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +8 -11
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +22 -19
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +17 -22
- 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 +9 -18
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +37 -189
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Core.sol +187 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol +25 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +89 -0
- package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
- 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 +4 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +35 -0
- package/contracts/LSP9Vault/LSP9Constants.sol +14 -5
- package/contracts/LSP9Vault/LSP9Vault.sol +15 -37
- package/contracts/LSP9Vault/LSP9VaultCore.sol +105 -85
- package/contracts/LSP9Vault/LSP9VaultInit.sol +5 -4
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +15 -45
- package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
- package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +60 -0
- package/contracts/UniversalProfile.sol +11 -20
- package/contracts/UniversalProfileInit.sol +5 -4
- package/contracts/UniversalProfileInitAbstract.sol +14 -35
- package/contracts/Utils/UtilsLib.sol +47 -11
- package/package.json +23 -9
- package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
- package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
- package/constants.ts +0 -350
- 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/LSP7MintableInitAbstract.sol +0 -47
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
- package/contracts/UniversalProfileCore.sol +0 -56
- package/contracts/Utils/ERC725Utils.sol +0 -169
- package/contracts/Utils/LSP2Utils.sol +0 -127
- package/contracts/Utils/LSP6Utils.sol +0 -77
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// libraries
|
|
5
|
+
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
6
|
+
import {UtilsLib} from "../Utils/UtilsLib.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title ERC725 Utility library to encode key types
|
|
10
|
+
* @author Jean Cavallera (CJ-42)
|
|
11
|
+
* @dev based on LSP2 - ERC725Y JSON Schema
|
|
12
|
+
* https://github.com/lukso-network/LIPs/blob/master/LSPs/LSP-2-ERC725YJSONSchema.md
|
|
13
|
+
*/
|
|
14
|
+
library LSP2Utils {
|
|
15
|
+
using BytesLib for bytes;
|
|
16
|
+
|
|
17
|
+
/* solhint-disable no-inline-assembly */
|
|
18
|
+
|
|
19
|
+
function generateBytes32Key(bytes memory _rawKey) internal pure returns (bytes32 key) {
|
|
20
|
+
// solhint-disable-next-line
|
|
21
|
+
assembly {
|
|
22
|
+
key := mload(add(_rawKey, 32))
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function generateSingletonKey(string memory _keyName) internal pure returns (bytes32) {
|
|
27
|
+
return keccak256(bytes(_keyName));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function generateArrayKey(string memory _keyName) internal pure returns (bytes32) {
|
|
31
|
+
bytes memory keyName = bytes(_keyName);
|
|
32
|
+
|
|
33
|
+
// prettier-ignore
|
|
34
|
+
require(
|
|
35
|
+
keyName[keyName.length - 2] == 0x5b && // "[" in utf8 encoded
|
|
36
|
+
keyName[keyName.length - 1] == 0x5d, // "]" in utf8
|
|
37
|
+
"Missing empty square brackets \"[]\" at the end of the key name"
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return keccak256(keyName);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function generateArrayElementKeyAtIndex(bytes32 _arrayKey, uint256 _index)
|
|
44
|
+
internal
|
|
45
|
+
pure
|
|
46
|
+
returns (bytes32)
|
|
47
|
+
{
|
|
48
|
+
bytes memory elementInArray = UtilsLib.concatTwoBytes16(
|
|
49
|
+
bytes16(_arrayKey),
|
|
50
|
+
bytes16(uint128(_index))
|
|
51
|
+
);
|
|
52
|
+
return generateBytes32Key(elementInArray);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function generateMappingKey(string memory _firstWord, string memory _lastWord)
|
|
56
|
+
internal
|
|
57
|
+
pure
|
|
58
|
+
returns (bytes32)
|
|
59
|
+
{
|
|
60
|
+
bytes32 firstWordHash = keccak256(bytes(_firstWord));
|
|
61
|
+
bytes32 lastWordHash = keccak256(bytes(_lastWord));
|
|
62
|
+
|
|
63
|
+
bytes memory temporaryBytes = abi.encodePacked(
|
|
64
|
+
bytes10(firstWordHash),
|
|
65
|
+
bytes2(0),
|
|
66
|
+
bytes20(lastWordHash)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return generateBytes32Key(temporaryBytes);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function generateMappingKey(string memory _firstWord, address _address)
|
|
73
|
+
internal
|
|
74
|
+
pure
|
|
75
|
+
returns (bytes32)
|
|
76
|
+
{
|
|
77
|
+
bytes32 firstWordHash = keccak256(bytes(_firstWord));
|
|
78
|
+
|
|
79
|
+
bytes memory temporaryBytes = abi.encodePacked(bytes10(firstWordHash), bytes2(0), _address);
|
|
80
|
+
|
|
81
|
+
return generateBytes32Key(temporaryBytes);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function generateMappingKey(bytes12 _keyPrefix, bytes20 _bytes20)
|
|
85
|
+
internal
|
|
86
|
+
pure
|
|
87
|
+
returns (bytes32)
|
|
88
|
+
{
|
|
89
|
+
bytes memory generatedKey = bytes.concat(_keyPrefix, _bytes20);
|
|
90
|
+
return generateBytes32Key(generatedKey);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function generateMappingWithGroupingKey(
|
|
94
|
+
string memory _firstWord,
|
|
95
|
+
string memory _secondWord,
|
|
96
|
+
address _address
|
|
97
|
+
) internal pure returns (bytes32) {
|
|
98
|
+
bytes32 firstWordHash = keccak256(bytes(_firstWord));
|
|
99
|
+
bytes32 secondWordHash = keccak256(bytes(_secondWord));
|
|
100
|
+
|
|
101
|
+
bytes memory temporaryBytes = abi.encodePacked(
|
|
102
|
+
bytes6(firstWordHash),
|
|
103
|
+
bytes4(secondWordHash),
|
|
104
|
+
bytes2(0),
|
|
105
|
+
_address
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return generateBytes32Key(temporaryBytes);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function generateMappingWithGroupingKey(bytes12 _keyPrefix, bytes20 _bytes20)
|
|
112
|
+
internal
|
|
113
|
+
pure
|
|
114
|
+
returns (bytes32)
|
|
115
|
+
{
|
|
116
|
+
bytes memory generatedKey = bytes.concat(_keyPrefix, _bytes20);
|
|
117
|
+
return generateBytes32Key(generatedKey);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function generateJSONURLValue(
|
|
121
|
+
string memory _hashFunction,
|
|
122
|
+
string memory _json,
|
|
123
|
+
string memory _url
|
|
124
|
+
) internal pure returns (bytes memory key_) {
|
|
125
|
+
bytes32 hashFunctionDigest = keccak256(bytes(_hashFunction));
|
|
126
|
+
bytes32 jsonDigest = keccak256(bytes(_json));
|
|
127
|
+
|
|
128
|
+
key_ = abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, _url);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function generateASSETURLValue(
|
|
132
|
+
string memory _hashFunction,
|
|
133
|
+
string memory _assetBytes,
|
|
134
|
+
string memory _url
|
|
135
|
+
) internal pure returns (bytes memory key_) {
|
|
136
|
+
bytes32 hashFunctionDigest = keccak256(bytes(_hashFunction));
|
|
137
|
+
bytes32 jsonDigest = keccak256(bytes(_assetBytes));
|
|
138
|
+
|
|
139
|
+
key_ = abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, _url);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function isEncodedArray(bytes memory _data) internal pure returns (bool) {
|
|
143
|
+
uint256 nbOfBytes = _data.length;
|
|
144
|
+
|
|
145
|
+
// 1) there must be at least 32 bytes to store the offset
|
|
146
|
+
if (nbOfBytes < 32) return false;
|
|
147
|
+
|
|
148
|
+
// 2) there must be at least the same number of bytes specified by
|
|
149
|
+
// the offset value (otherwise, the offset points to nowhere)
|
|
150
|
+
uint256 offset = uint256(bytes32(_data));
|
|
151
|
+
if (nbOfBytes < offset) return false;
|
|
152
|
+
|
|
153
|
+
// 3) there must be at least 32 x length bytes after offset
|
|
154
|
+
uint256 arrayLength = _data.toUint256(offset);
|
|
155
|
+
|
|
156
|
+
// 32 bytes word (= offset)
|
|
157
|
+
// + 32 bytes word (= array length)
|
|
158
|
+
// + remaining bytes that make each element of the array
|
|
159
|
+
if (nbOfBytes < (offset + 32 + (arrayLength * 32))) return false;
|
|
160
|
+
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function isEncodedArrayOfAddresses(bytes memory _data) internal pure returns (bool) {
|
|
165
|
+
if (!isEncodedArray(_data)) return false;
|
|
166
|
+
|
|
167
|
+
uint256 offset = uint256(bytes32(_data));
|
|
168
|
+
uint256 arrayLength = _data.toUint256(offset);
|
|
169
|
+
|
|
170
|
+
uint256 pointer = offset + 32;
|
|
171
|
+
|
|
172
|
+
for (uint256 ii = 0; ii < arrayLength; ii++) {
|
|
173
|
+
bytes32 key = _data.toBytes32(pointer);
|
|
174
|
+
|
|
175
|
+
// check that the leading bytes are zero bytes "00"
|
|
176
|
+
// NB: address type is padded on the left (unlike bytes20 type that is padded on the right)
|
|
177
|
+
if (bytes12(key) != bytes12(0)) return false;
|
|
178
|
+
|
|
179
|
+
// increment the pointer
|
|
180
|
+
pointer += 32;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function isBytes4EncodedArray(bytes memory _data) internal pure returns (bool) {
|
|
187
|
+
if (!isEncodedArray(_data)) return false;
|
|
188
|
+
|
|
189
|
+
uint256 offset = uint256(bytes32(_data));
|
|
190
|
+
uint256 arrayLength = _data.toUint256(offset);
|
|
191
|
+
uint256 pointer = offset + 32;
|
|
192
|
+
|
|
193
|
+
for (uint256 ii = 0; ii < arrayLength; ii++) {
|
|
194
|
+
bytes32 key = _data.toBytes32(pointer);
|
|
195
|
+
|
|
196
|
+
// check that the trailing bytes are zero bytes "00"
|
|
197
|
+
if (uint224(uint256(key)) != 0) return false;
|
|
198
|
+
|
|
199
|
+
// increment the pointer
|
|
200
|
+
pointer += 32;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// bytes10(keccak256('SupportedStandard')) + bytes2(0) + bytes20(keccak256('LSP3UniversalProfile'))
|
|
5
|
+
bytes32 constant _LSP3_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38;
|
|
6
|
+
|
|
7
|
+
// bytes4(keccak256('LSP3UniversalProfile'))
|
|
8
|
+
bytes constant _LSP3_SUPPORTED_STANDARDS_VALUE = hex"abe425d6";
|
|
9
|
+
|
|
10
|
+
// bytes32(keccak256("LSP3Profile"))
|
|
11
|
+
bytes32 constant _LSP3_PROFILE_KEY = 0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
pragma solidity ^0.8.0;
|
|
4
4
|
|
|
5
5
|
// interfaces
|
|
6
|
-
import "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
6
|
+
import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @dev LSP4 extension, for compatibility with clients & tools that expect ERC20/721.
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
// modules
|
|
5
|
-
import "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
|
-
|
|
7
4
|
// interfaces
|
|
8
|
-
import "./ILSP4Compatibility.sol";
|
|
5
|
+
import {ILSP4Compatibility} from "./ILSP4Compatibility.sol";
|
|
9
6
|
|
|
10
|
-
//
|
|
11
|
-
import "
|
|
7
|
+
// modules
|
|
8
|
+
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
|
|
12
9
|
|
|
13
10
|
// constants
|
|
14
11
|
import "./LSP4Constants.sol";
|
|
@@ -18,7 +15,7 @@ import "./LSP4Constants.sol";
|
|
|
18
15
|
* @author Matthew Stevens
|
|
19
16
|
* @dev LSP4 extension, for compatibility with clients & tools that expect ERC20/721.
|
|
20
17
|
*/
|
|
21
|
-
abstract contract LSP4Compatibility is
|
|
18
|
+
abstract contract LSP4Compatibility is ILSP4Compatibility, ERC725YCore {
|
|
22
19
|
// --- Token queries
|
|
23
20
|
|
|
24
21
|
/**
|
|
@@ -26,10 +23,7 @@ abstract contract LSP4Compatibility is ERC725Y, ILSP4Compatibility {
|
|
|
26
23
|
* @return The name of the token
|
|
27
24
|
*/
|
|
28
25
|
function name() public view virtual override returns (string memory) {
|
|
29
|
-
bytes memory data =
|
|
30
|
-
this,
|
|
31
|
-
_LSP4_METADATA_TOKEN_NAME_KEY
|
|
32
|
-
);
|
|
26
|
+
bytes memory data = _getData(_LSP4_TOKEN_NAME_KEY);
|
|
33
27
|
return string(data);
|
|
34
28
|
}
|
|
35
29
|
|
|
@@ -38,10 +32,7 @@ abstract contract LSP4Compatibility is ERC725Y, ILSP4Compatibility {
|
|
|
38
32
|
* @return The symbol of the token
|
|
39
33
|
*/
|
|
40
34
|
function symbol() public view virtual override returns (string memory) {
|
|
41
|
-
bytes memory data =
|
|
42
|
-
this,
|
|
43
|
-
_LSP4_METADATA_TOKEN_SYMBOL_KEY
|
|
44
|
-
);
|
|
35
|
+
bytes memory data = _getData(_LSP4_TOKEN_SYMBOL_KEY);
|
|
45
36
|
return string(data);
|
|
46
37
|
}
|
|
47
38
|
}
|
|
@@ -3,17 +3,23 @@ pragma solidity ^0.8.0;
|
|
|
3
3
|
|
|
4
4
|
// --- ERC725Y entries
|
|
5
5
|
|
|
6
|
-
//
|
|
7
|
-
bytes32 constant _LSP4_SUPPORTED_STANDARDS_KEY =
|
|
6
|
+
// bytes10(keccak256('SupportedStandard')) + bytes2(0) + bytes20(keccak256('LSP4DigitalAsset'))
|
|
7
|
+
bytes32 constant _LSP4_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b60000a4d96624a38f7ac2d8d9a604ecf07c12c77e480c;
|
|
8
8
|
|
|
9
9
|
// bytes4(keccak256('LSP4DigitalAsset'))
|
|
10
10
|
bytes constant _LSP4_SUPPORTED_STANDARDS_VALUE = hex"a4d96624";
|
|
11
11
|
|
|
12
12
|
// keccak256('LSP4TokenName')
|
|
13
|
-
bytes32 constant
|
|
13
|
+
bytes32 constant _LSP4_TOKEN_NAME_KEY = 0xdeba1e292f8ba88238e10ab3c7f88bd4be4fac56cad5194b6ecceaf653468af1;
|
|
14
14
|
|
|
15
15
|
// keccak256('LSP4TokenSymbol')
|
|
16
|
-
bytes32 constant
|
|
16
|
+
bytes32 constant _LSP4_TOKEN_SYMBOL_KEY = 0x2f0a68ab07768e01943a599e73362a0e17a63a72e94dd2e384d2c1d4db932756;
|
|
17
|
+
|
|
18
|
+
// keccak256('LSP4Creators[]')
|
|
19
|
+
bytes32 constant _LSP4_CREATORS_ARRAY_KEY = 0x114bd03b3a46d48759680d81ebb2b414fda7d030a7105a851867accf1c2352e7;
|
|
20
|
+
|
|
21
|
+
// bytes10(keccak256('LSP4CreatorsMap')) + bytes2(0)
|
|
22
|
+
bytes12 constant _LSP4_CREATORS_MAP_KEY_PREFIX = 0x6de85eaf5d982b4e5da00000;
|
|
17
23
|
|
|
18
24
|
// keccak256('LSP4Metadata')
|
|
19
25
|
bytes32 constant _LSP4_METADATA_KEY = 0x9afb95cacc9f95858ec44aa8c3b685511002e30ae54415823f406128b85b238e;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
|
-
import "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
5
|
+
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
6
|
|
|
7
7
|
// constants
|
|
8
8
|
import "./LSP4Constants.sol";
|
|
@@ -24,13 +24,16 @@ abstract contract LSP4DigitalAssetMetadata is ERC725Y {
|
|
|
24
24
|
string memory symbol_,
|
|
25
25
|
address newOwner_
|
|
26
26
|
) ERC725Y(newOwner_) {
|
|
27
|
-
// SupportedStandards:LSP4DigitalAsset
|
|
28
|
-
_setData(
|
|
29
|
-
_LSP4_SUPPORTED_STANDARDS_KEY,
|
|
30
|
-
_LSP4_SUPPORTED_STANDARDS_VALUE
|
|
31
|
-
);
|
|
27
|
+
// set key SupportedStandards:LSP4DigitalAsset
|
|
28
|
+
super._setData(_LSP4_SUPPORTED_STANDARDS_KEY, _LSP4_SUPPORTED_STANDARDS_VALUE);
|
|
32
29
|
|
|
33
|
-
_setData(
|
|
34
|
-
_setData(
|
|
30
|
+
super._setData(_LSP4_TOKEN_NAME_KEY, bytes(name_));
|
|
31
|
+
super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _setData(bytes32 key, bytes memory value) internal virtual override {
|
|
35
|
+
require(key != _LSP4_TOKEN_NAME_KEY, "LSP4: cannot edit Token Name after deployment");
|
|
36
|
+
require(key != _LSP4_TOKEN_SYMBOL_KEY, "LSP4: cannot edit Token Symbol after deployment");
|
|
37
|
+
super._setData(key, value);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
import "./
|
|
6
|
-
import "./LSP4DigitalAssetMetadataInitAbstract.sol";
|
|
4
|
+
// modules
|
|
5
|
+
import {LSP4DigitalAssetMetadataInitAbstract} from "./LSP4DigitalAssetMetadataInitAbstract.sol";
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* @title LSP4DigitalAssetMetadata
|
|
10
9
|
* @author Matthew Stevens
|
|
11
10
|
* @dev Deployable Proxy Implementation of a LSP8 compliant contract.
|
|
12
11
|
*/
|
|
13
|
-
abstract contract LSP4DigitalAssetMetadataInit is
|
|
14
|
-
LSP4DigitalAssetMetadataInitAbstract
|
|
15
|
-
{
|
|
12
|
+
abstract contract LSP4DigitalAssetMetadataInit is LSP4DigitalAssetMetadataInitAbstract {
|
|
16
13
|
/**
|
|
17
|
-
* @
|
|
14
|
+
* @notice Sets the name, symbol of the token and the owner, and sets the SupportedStandards:LSP4DigitalAsset key
|
|
15
|
+
* @param name_ The name of the token
|
|
16
|
+
* @param symbol_ The symbol of the token
|
|
17
|
+
* @param newOwner_ The owner of the token contract
|
|
18
18
|
*/
|
|
19
19
|
function initialize(
|
|
20
20
|
string memory name_,
|
|
21
21
|
string memory symbol_,
|
|
22
22
|
address newOwner_
|
|
23
|
-
) public virtual
|
|
24
|
-
LSP4DigitalAssetMetadataInitAbstract.
|
|
25
|
-
name_,
|
|
26
|
-
symbol_,
|
|
27
|
-
newOwner_
|
|
28
|
-
);
|
|
23
|
+
) public virtual initializer {
|
|
24
|
+
LSP4DigitalAssetMetadataInitAbstract._initialize(name_, symbol_, newOwner_);
|
|
29
25
|
}
|
|
30
26
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
|
-
import "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";
|
|
5
|
+
import {ERC725YInitAbstract, ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";
|
|
6
6
|
|
|
7
7
|
// constants
|
|
8
8
|
import "./LSP4Constants.sol";
|
|
@@ -12,30 +12,24 @@ import "./LSP4Constants.sol";
|
|
|
12
12
|
* @author Matthew Stevens
|
|
13
13
|
* @dev Inheritable Proxy Implementation of a LSP8 compliant contract.
|
|
14
14
|
*/
|
|
15
|
-
abstract contract LSP4DigitalAssetMetadataInitAbstract is
|
|
16
|
-
|
|
17
|
-
ERC725YInitAbstract
|
|
18
|
-
{
|
|
19
|
-
/**
|
|
20
|
-
* @notice Sets the name, symbol of the token and the owner, and sets the SupportedStandards:LSP4DigitalAsset key
|
|
21
|
-
* @param name_ The name of the token
|
|
22
|
-
* @param symbol_ The symbol of the token
|
|
23
|
-
* @param newOwner_ The owner of the token contract
|
|
24
|
-
*/
|
|
25
|
-
function initialize(
|
|
15
|
+
abstract contract LSP4DigitalAssetMetadataInitAbstract is ERC725YInitAbstract {
|
|
16
|
+
function _initialize(
|
|
26
17
|
string memory name_,
|
|
27
18
|
string memory symbol_,
|
|
28
19
|
address newOwner_
|
|
29
|
-
)
|
|
30
|
-
ERC725YInitAbstract.
|
|
20
|
+
) internal virtual onlyInitializing {
|
|
21
|
+
ERC725YInitAbstract._initialize(newOwner_);
|
|
31
22
|
|
|
32
23
|
// set SupportedStandards:LSP4DigitalAsset
|
|
33
|
-
_setData(
|
|
34
|
-
_LSP4_SUPPORTED_STANDARDS_KEY,
|
|
35
|
-
_LSP4_SUPPORTED_STANDARDS_VALUE
|
|
36
|
-
);
|
|
24
|
+
super._setData(_LSP4_SUPPORTED_STANDARDS_KEY, _LSP4_SUPPORTED_STANDARDS_VALUE);
|
|
37
25
|
|
|
38
|
-
_setData(
|
|
39
|
-
_setData(
|
|
26
|
+
super._setData(_LSP4_TOKEN_NAME_KEY, bytes(name_));
|
|
27
|
+
super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _setData(bytes32 key, bytes memory value) internal virtual override {
|
|
31
|
+
require(key != _LSP4_TOKEN_NAME_KEY, "LSP4: cannot edit Token Name after deployment");
|
|
32
|
+
require(key != _LSP4_TOKEN_SYMBOL_KEY, "LSP4: cannot edit Token Symbol after deployment");
|
|
33
|
+
super._setData(key, value);
|
|
40
34
|
}
|
|
41
35
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// --- ERC725Y Keys
|
|
5
|
+
|
|
6
|
+
// keccak256('LSP5ReceivedAssets[]')
|
|
7
|
+
bytes32 constant _LSP5_RECEIVED_ASSETS_ARRAY_KEY = 0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b;
|
|
8
|
+
|
|
9
|
+
// bytes10(keccak256('LSP5ReceivedAssetsMap')) + bytes2(0)
|
|
10
|
+
bytes12 constant _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX = 0x812c4334633eb816c80d0000;
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
library LSP5Utils {
|
|
17
|
+
/**
|
|
18
|
+
* @dev Generating the data keys/values to be set on the account after receiving assets/vaults
|
|
19
|
+
*
|
|
20
|
+
* @param account The account where the Keys should be added
|
|
21
|
+
* @param arrayLengthKey The arrayLengthKey containing the number of the received assets/vaults
|
|
22
|
+
* @param mapKey The mapKey containing the interfaceID and the index of the asset in the `element in arrayKey`
|
|
23
|
+
* @param caller The address of the asset/vault received
|
|
24
|
+
* @param interfaceID The interfaceID of the asset/vault received
|
|
25
|
+
*/
|
|
26
|
+
function addMapAndArrayKey(
|
|
27
|
+
IERC725Y account,
|
|
28
|
+
bytes32 arrayLengthKey,
|
|
29
|
+
bytes32 mapKey,
|
|
30
|
+
address caller,
|
|
31
|
+
bytes4 interfaceID
|
|
32
|
+
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
33
|
+
/**
|
|
34
|
+
* We will be setting 3 keys:
|
|
35
|
+
* - Keys[0]: The arrayLengthKey containing the number of the received assets/vaults
|
|
36
|
+
* - Keys[1]: The element in arrayKey containing the address of each received asset/vault for a specific index
|
|
37
|
+
* - Keys[2]: The mapKey containing the interfaceID and the index of the asset in the `element in arrayKey`
|
|
38
|
+
*/
|
|
39
|
+
keys = new bytes32[](3);
|
|
40
|
+
values = new bytes[](3);
|
|
41
|
+
|
|
42
|
+
bytes memory encodedArrayLength = account.getData(arrayLengthKey);
|
|
43
|
+
|
|
44
|
+
// If it's the first asset to receive
|
|
45
|
+
if (encodedArrayLength.length == 0) {
|
|
46
|
+
keys[0] = arrayLengthKey;
|
|
47
|
+
values[0] = UtilsLib.uint256ToBytes(1);
|
|
48
|
+
|
|
49
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, 0);
|
|
50
|
+
values[1] = UtilsLib.addressToBytes(caller);
|
|
51
|
+
|
|
52
|
+
keys[2] = mapKey;
|
|
53
|
+
values[2] = bytes.concat(interfaceID, bytes8(0));
|
|
54
|
+
|
|
55
|
+
// If the storage is already initiated
|
|
56
|
+
} else if (encodedArrayLength.length == 32) {
|
|
57
|
+
uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
|
|
58
|
+
uint256 newArrayLength = arrayLength + 1;
|
|
59
|
+
|
|
60
|
+
keys[0] = arrayLengthKey;
|
|
61
|
+
values[0] = UtilsLib.uint256ToBytes(newArrayLength);
|
|
62
|
+
|
|
63
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(arrayLengthKey, newArrayLength - 1);
|
|
64
|
+
values[1] = UtilsLib.addressToBytes(caller);
|
|
65
|
+
|
|
66
|
+
keys[2] = mapKey;
|
|
67
|
+
values[2] = bytes.concat(interfaceID, bytes8(uint64(arrayLength)));
|
|
68
|
+
} else {
|
|
69
|
+
revert("Invalid length of the LSP5ReceivedAssets[] Key");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @dev Generating the data keys/values to be removed/changed on the account after sending assets/vaults
|
|
75
|
+
*
|
|
76
|
+
* @param account The account where the Keys should be added
|
|
77
|
+
* @param arrayLengthKey The arrayLengthKey containing the number of the received assets/vaults
|
|
78
|
+
* @param mapKeyPrefix The mapKey prefix relative to LSP5ReceivedAssetsMap or LSP10VaultsMap Keys
|
|
79
|
+
* @param mapKeyToRemove The mapKey of the asset sent
|
|
80
|
+
* @param mapValue The mapValue of the asset/vault sent
|
|
81
|
+
*/
|
|
82
|
+
function removeMapAndArrayKey(
|
|
83
|
+
IERC725Y account,
|
|
84
|
+
bytes32 arrayLengthKey,
|
|
85
|
+
bytes12 mapKeyPrefix,
|
|
86
|
+
bytes32 mapKeyToRemove,
|
|
87
|
+
bytes memory mapValue
|
|
88
|
+
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
89
|
+
// Updating the number of the received assets/vaults
|
|
90
|
+
bytes memory encodedArrayLength = account.getData(arrayLengthKey);
|
|
91
|
+
uint256 arrayLength = abi.decode(encodedArrayLength, (uint256));
|
|
92
|
+
uint256 newLength = arrayLength - 1;
|
|
93
|
+
|
|
94
|
+
uint64 index = extractIndexFromMap(mapValue);
|
|
95
|
+
bytes32 arrayElementKeyToRemove = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
96
|
+
arrayLengthKey,
|
|
97
|
+
index
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (index == (arrayLength - 1)) {
|
|
101
|
+
/**
|
|
102
|
+
* We will be updating/removing 3 keys:
|
|
103
|
+
* - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets/vaults
|
|
104
|
+
* - Keys[1]: [Remove] The element in arrayKey (Remove the address of the asset sent)
|
|
105
|
+
* - Keys[2]: [Remove] The mapKey (Remove the interfaceId and the index of the asset sent)
|
|
106
|
+
*/
|
|
107
|
+
keys = new bytes32[](3);
|
|
108
|
+
values = new bytes[](3);
|
|
109
|
+
|
|
110
|
+
keys[0] = arrayLengthKey;
|
|
111
|
+
values[0] = UtilsLib.uint256ToBytes(newLength);
|
|
112
|
+
|
|
113
|
+
keys[1] = mapKeyToRemove;
|
|
114
|
+
values[1] = "";
|
|
115
|
+
|
|
116
|
+
keys[2] = arrayElementKeyToRemove;
|
|
117
|
+
values[2] = "";
|
|
118
|
+
|
|
119
|
+
// Swapping last element in ArrayKey with the elemnt in ArrayKey to remove || {Swap and pop} method;
|
|
120
|
+
// check https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/EnumerableSet.sol#L80
|
|
121
|
+
} else {
|
|
122
|
+
/**
|
|
123
|
+
* We will be updating/removing 5 keys:
|
|
124
|
+
* - Keys[0]: [Update] The arrayLengthKey to contain the new number of the received assets/vaults
|
|
125
|
+
* - Keys[1]: [Remove] The mapKey of the asset to remove (Remove the interfaceId and the index of the asset sent)
|
|
126
|
+
* - Keys[2]: [Update] The element in arrayKey to remove (Swap with the address of the last element in Array)
|
|
127
|
+
* - Keys[3]: [Remove] The last element in arrayKey (Remove (pop) the address of the last element as it's already swapped)
|
|
128
|
+
* - Keys[4]: [Update] The mapKey of the last element in array (Update the new index and the interfaceID)
|
|
129
|
+
*/
|
|
130
|
+
keys = new bytes32[](5);
|
|
131
|
+
values = new bytes[](5);
|
|
132
|
+
|
|
133
|
+
keys[0] = arrayLengthKey;
|
|
134
|
+
values[0] = UtilsLib.uint256ToBytes(newLength);
|
|
135
|
+
|
|
136
|
+
keys[1] = mapKeyToRemove;
|
|
137
|
+
values[1] = "";
|
|
138
|
+
|
|
139
|
+
// Generate all data Keys/values of the last element in Array to swap
|
|
140
|
+
// with data Keys/values of the asset to remove
|
|
141
|
+
bytes32 lastArrayElementKey = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
142
|
+
arrayLengthKey,
|
|
143
|
+
newLength
|
|
144
|
+
);
|
|
145
|
+
bytes memory lastArrayElementValue = account.getData(lastArrayElementKey);
|
|
146
|
+
|
|
147
|
+
bytes32 lastArrayElementMapKey = LSP2Utils.generateMappingKey(
|
|
148
|
+
mapKeyPrefix,
|
|
149
|
+
bytes20(lastArrayElementValue)
|
|
150
|
+
);
|
|
151
|
+
bytes memory lastArrayElementMapValue = account.getData(lastArrayElementMapKey);
|
|
152
|
+
bytes memory interfaceID = BytesLib.slice(lastArrayElementMapValue, 0, 4);
|
|
153
|
+
|
|
154
|
+
keys[2] = arrayElementKeyToRemove;
|
|
155
|
+
values[2] = lastArrayElementValue;
|
|
156
|
+
|
|
157
|
+
keys[3] = lastArrayElementKey;
|
|
158
|
+
values[3] = "";
|
|
159
|
+
|
|
160
|
+
keys[4] = lastArrayElementMapKey;
|
|
161
|
+
values[4] = bytes.concat(interfaceID, bytes8(index));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function addMapAndArrayKeyViaKeyManager(
|
|
166
|
+
IERC725Y account,
|
|
167
|
+
bytes32 arrayLengthKey,
|
|
168
|
+
bytes32 mapKey,
|
|
169
|
+
address caller,
|
|
170
|
+
bytes4 interfaceID,
|
|
171
|
+
address keyManager
|
|
172
|
+
) internal returns (bytes memory result) {
|
|
173
|
+
(bytes32[] memory keys, bytes[] memory values) = addMapAndArrayKey(
|
|
174
|
+
account,
|
|
175
|
+
arrayLengthKey,
|
|
176
|
+
mapKey,
|
|
177
|
+
caller,
|
|
178
|
+
interfaceID
|
|
179
|
+
);
|
|
180
|
+
result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function removeMapAndArrayKeyViaKeyManager(
|
|
184
|
+
IERC725Y account,
|
|
185
|
+
bytes32 arrayLengthKey,
|
|
186
|
+
bytes12 mapKeyPrefix,
|
|
187
|
+
bytes32 mapKeyToRemove,
|
|
188
|
+
bytes memory mapValue,
|
|
189
|
+
address keyManager
|
|
190
|
+
) internal returns (bytes memory result) {
|
|
191
|
+
(bytes32[] memory keys, bytes[] memory values) = removeMapAndArrayKey(
|
|
192
|
+
account,
|
|
193
|
+
arrayLengthKey,
|
|
194
|
+
mapKeyPrefix,
|
|
195
|
+
mapKeyToRemove,
|
|
196
|
+
mapValue
|
|
197
|
+
);
|
|
198
|
+
result = LSP6Utils.setDataViaKeyManager(keyManager, keys, values);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint64) {
|
|
202
|
+
bytes memory val = BytesLib.slice(mapValue, 4, 8);
|
|
203
|
+
return BytesLib.toUint64(val, 0);
|
|
204
|
+
}
|
|
205
|
+
}
|