@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
|
@@ -16,142 +16,206 @@ library LSP2Utils {
|
|
|
16
16
|
|
|
17
17
|
/* solhint-disable no-inline-assembly */
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return keccak256(bytes(_keyName));
|
|
19
|
+
/**
|
|
20
|
+
* @dev Generates a data key of keyType Singleton
|
|
21
|
+
* @param keyName The string to hash to generate a Singleton data key
|
|
22
|
+
* @return a bytes32 dataKey
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
function generateSingletonKey(string memory keyName) internal pure returns (bytes32) {
|
|
26
|
+
return keccak256(bytes(keyName));
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
/**
|
|
30
|
+
* @dev Generates a data key of keyType Array by hashing `keyName`.
|
|
31
|
+
* @param keyName The string that will be used to generate an data key of keyType Array
|
|
32
|
+
*/
|
|
33
|
+
function generateArrayKey(string memory keyName) internal pure returns (bytes32) {
|
|
34
|
+
bytes memory dataKey = bytes(keyName);
|
|
32
35
|
|
|
33
|
-
// prettier-ignore
|
|
34
36
|
require(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"Missing empty square brackets
|
|
37
|
+
dataKey[dataKey.length - 2] == 0x5b && // "[" in utf8 encoded
|
|
38
|
+
dataKey[dataKey.length - 1] == 0x5d, // "]" in utf8
|
|
39
|
+
"Missing empty square brackets '[]' at the end of the key name"
|
|
38
40
|
);
|
|
39
41
|
|
|
40
|
-
return keccak256(
|
|
42
|
+
return keccak256(dataKey);
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @dev Generates a Array index data key by concatenating the first 16 bytes of `arrayKey`
|
|
47
|
+
* and `index` transformed from uint256 to bytes16 (uint256 -> uint128 -> bytes16)
|
|
48
|
+
* @param arrayKey The key from which we're getting the first half of the Array index data key from
|
|
49
|
+
* @param index Used to generate the second half of the Array index data key
|
|
50
|
+
*/
|
|
51
|
+
function generateArrayElementKeyAtIndex(bytes32 arrayKey, uint256 index)
|
|
44
52
|
internal
|
|
45
53
|
pure
|
|
46
54
|
returns (bytes32)
|
|
47
55
|
{
|
|
48
56
|
bytes memory elementInArray = UtilsLib.concatTwoBytes16(
|
|
49
|
-
bytes16(
|
|
50
|
-
bytes16(uint128(
|
|
57
|
+
bytes16(arrayKey),
|
|
58
|
+
bytes16(uint128(index))
|
|
51
59
|
);
|
|
52
|
-
return
|
|
60
|
+
return bytes32(elementInArray);
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
|
|
63
|
+
/**
|
|
64
|
+
* @dev @dev Generates a data key of keyType Mapping by hashing two strings:
|
|
65
|
+
* <bytes10(keccak256(firstWord))>:<bytes2(0)>:<bytes20(keccak256(firstWord))>
|
|
66
|
+
* @param firstWord Used to generate a hash and its first 10 bytes
|
|
67
|
+
* are used for the first part of the data key of keyType Mapping
|
|
68
|
+
* @param lastWord Used to generate a hash and its first 20 bytes
|
|
69
|
+
* are used for the last part of the data key of keyType Mapping
|
|
70
|
+
*/
|
|
71
|
+
function generateMappingKey(string memory firstWord, string memory lastWord)
|
|
56
72
|
internal
|
|
57
73
|
pure
|
|
58
74
|
returns (bytes32)
|
|
59
75
|
{
|
|
60
|
-
bytes32 firstWordHash = keccak256(bytes(
|
|
61
|
-
bytes32 lastWordHash = keccak256(bytes(
|
|
76
|
+
bytes32 firstWordHash = keccak256(bytes(firstWord));
|
|
77
|
+
bytes32 lastWordHash = keccak256(bytes(lastWord));
|
|
62
78
|
|
|
63
|
-
bytes memory temporaryBytes =
|
|
79
|
+
bytes memory temporaryBytes = bytes.concat(
|
|
64
80
|
bytes10(firstWordHash),
|
|
65
81
|
bytes2(0),
|
|
66
82
|
bytes20(lastWordHash)
|
|
67
83
|
);
|
|
68
84
|
|
|
69
|
-
return
|
|
85
|
+
return bytes32(temporaryBytes);
|
|
70
86
|
}
|
|
71
87
|
|
|
72
|
-
|
|
88
|
+
/**
|
|
89
|
+
* @dev Generates a data key of keyType Mapping by hashing a string and concatenating it with an address:
|
|
90
|
+
* <bytes10(keccak256(firstWord))>:<bytes2(0)>:<bytes20(addr)>
|
|
91
|
+
* @param firstWord Used to generate a hash and its first 10 bytes
|
|
92
|
+
* are used for the first part of the data key of keyType Mapping
|
|
93
|
+
* @param addr used for the last part of the data key of keyType Mapping
|
|
94
|
+
*/
|
|
95
|
+
function generateMappingKey(string memory firstWord, address addr)
|
|
73
96
|
internal
|
|
74
97
|
pure
|
|
75
98
|
returns (bytes32)
|
|
76
99
|
{
|
|
77
|
-
bytes32 firstWordHash = keccak256(bytes(
|
|
100
|
+
bytes32 firstWordHash = keccak256(bytes(firstWord));
|
|
78
101
|
|
|
79
|
-
bytes memory temporaryBytes =
|
|
102
|
+
bytes memory temporaryBytes = bytes.concat(
|
|
103
|
+
bytes10(firstWordHash),
|
|
104
|
+
bytes2(0),
|
|
105
|
+
bytes20(addr)
|
|
106
|
+
);
|
|
80
107
|
|
|
81
|
-
return
|
|
108
|
+
return bytes32(temporaryBytes);
|
|
82
109
|
}
|
|
83
110
|
|
|
84
|
-
|
|
111
|
+
/**
|
|
112
|
+
* @dev Generate a data key of keyType Mapping
|
|
113
|
+
* <bytes10keyPrefix>:<bytes2(0)>:<bytes20Value>
|
|
114
|
+
* @param keyPrefix First part of the data key of keyType Mapping
|
|
115
|
+
* @param bytes20Value Second part of the data key of keyType Mapping
|
|
116
|
+
*/
|
|
117
|
+
function generateMappingKey(bytes10 keyPrefix, bytes20 bytes20Value)
|
|
85
118
|
internal
|
|
86
119
|
pure
|
|
87
120
|
returns (bytes32)
|
|
88
121
|
{
|
|
89
|
-
bytes memory generatedKey = bytes.concat(
|
|
90
|
-
return
|
|
122
|
+
bytes memory generatedKey = bytes.concat(keyPrefix, bytes2(0), bytes20Value);
|
|
123
|
+
return bytes32(generatedKey);
|
|
91
124
|
}
|
|
92
125
|
|
|
126
|
+
/**
|
|
127
|
+
* @dev Generate a data key of keyType MappingWithGrouping by using two strings and an address
|
|
128
|
+
* <bytes6(keccak256(firstWord))>:<bytes4(keccak256(secondWord))>:<bytes2(0)>:<bytes20(addr)>
|
|
129
|
+
* @param firstWord Used to generate a hash and its first 6 bytes
|
|
130
|
+
* are used for the first part of the data key of keyType MappingWithGrouping
|
|
131
|
+
* @param secondWord Used to generate a hash and its first 4 bytes
|
|
132
|
+
* are used for the second part of the data key of keyType MappingWithGrouping
|
|
133
|
+
* @param addr Used for the last part of the data key of keyType MappingWithGrouping
|
|
134
|
+
*/
|
|
93
135
|
function generateMappingWithGroupingKey(
|
|
94
|
-
string memory
|
|
95
|
-
string memory
|
|
96
|
-
address
|
|
136
|
+
string memory firstWord,
|
|
137
|
+
string memory secondWord,
|
|
138
|
+
address addr
|
|
97
139
|
) internal pure returns (bytes32) {
|
|
98
|
-
bytes32 firstWordHash = keccak256(bytes(
|
|
99
|
-
bytes32 secondWordHash = keccak256(bytes(
|
|
140
|
+
bytes32 firstWordHash = keccak256(bytes(firstWord));
|
|
141
|
+
bytes32 secondWordHash = keccak256(bytes(secondWord));
|
|
100
142
|
|
|
101
|
-
bytes memory temporaryBytes =
|
|
143
|
+
bytes memory temporaryBytes = bytes.concat(
|
|
102
144
|
bytes6(firstWordHash),
|
|
103
145
|
bytes4(secondWordHash),
|
|
104
146
|
bytes2(0),
|
|
105
|
-
|
|
147
|
+
bytes20(addr)
|
|
106
148
|
);
|
|
107
149
|
|
|
108
|
-
return
|
|
150
|
+
return bytes32(temporaryBytes);
|
|
109
151
|
}
|
|
110
152
|
|
|
111
|
-
|
|
153
|
+
/**
|
|
154
|
+
* @dev Generate a data key of keyType MappingWithGrouping
|
|
155
|
+
* <bytes10keyPrefix>:<bytes2(0)>:<bytes20Value>
|
|
156
|
+
* @param keyPrefix Used for the first part of the data key of keyType MappingWithGrouping
|
|
157
|
+
* @param bytes20Value Used for the first last of the data key of keyType MappingWithGrouping
|
|
158
|
+
*/
|
|
159
|
+
function generateMappingWithGroupingKey(bytes10 keyPrefix, bytes20 bytes20Value)
|
|
112
160
|
internal
|
|
113
161
|
pure
|
|
114
162
|
returns (bytes32)
|
|
115
163
|
{
|
|
116
|
-
bytes memory generatedKey = bytes.concat(
|
|
117
|
-
return
|
|
164
|
+
bytes memory generatedKey = bytes.concat(keyPrefix, bytes2(0), bytes20Value);
|
|
165
|
+
return bytes32(generatedKey);
|
|
118
166
|
}
|
|
119
167
|
|
|
168
|
+
/**
|
|
169
|
+
* @dev Generate a JSONURL valueContent
|
|
170
|
+
* @param hashFunction The function used to hash the JSON file
|
|
171
|
+
* @param json Bytes value of the JSON file
|
|
172
|
+
* @param url The URL where the JSON file is hosted
|
|
173
|
+
*/
|
|
120
174
|
function generateJSONURLValue(
|
|
121
|
-
string memory
|
|
122
|
-
string memory
|
|
123
|
-
string memory
|
|
124
|
-
) internal pure returns (bytes memory
|
|
125
|
-
bytes32 hashFunctionDigest = keccak256(bytes(
|
|
126
|
-
bytes32 jsonDigest = keccak256(bytes(
|
|
127
|
-
|
|
128
|
-
|
|
175
|
+
string memory hashFunction,
|
|
176
|
+
string memory json,
|
|
177
|
+
string memory url
|
|
178
|
+
) internal pure returns (bytes memory key) {
|
|
179
|
+
bytes32 hashFunctionDigest = keccak256(bytes(hashFunction));
|
|
180
|
+
bytes32 jsonDigest = keccak256(bytes(json));
|
|
181
|
+
|
|
182
|
+
key = abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, url);
|
|
129
183
|
}
|
|
130
184
|
|
|
185
|
+
/**
|
|
186
|
+
* @dev Generate a ASSETURL valueContent
|
|
187
|
+
* @param hashFunction The function used to hash the JSON file
|
|
188
|
+
* @param assetBytes Bytes value of the JSON file
|
|
189
|
+
* @param url The URL where the JSON file is hosted
|
|
190
|
+
*/
|
|
131
191
|
function generateASSETURLValue(
|
|
132
|
-
string memory
|
|
133
|
-
string memory
|
|
134
|
-
string memory
|
|
135
|
-
) internal pure returns (bytes memory
|
|
136
|
-
bytes32 hashFunctionDigest = keccak256(bytes(
|
|
137
|
-
bytes32 jsonDigest = keccak256(bytes(
|
|
138
|
-
|
|
139
|
-
|
|
192
|
+
string memory hashFunction,
|
|
193
|
+
string memory assetBytes,
|
|
194
|
+
string memory url
|
|
195
|
+
) internal pure returns (bytes memory key) {
|
|
196
|
+
bytes32 hashFunctionDigest = keccak256(bytes(hashFunction));
|
|
197
|
+
bytes32 jsonDigest = keccak256(bytes(assetBytes));
|
|
198
|
+
|
|
199
|
+
key = abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, url);
|
|
140
200
|
}
|
|
141
201
|
|
|
142
|
-
|
|
143
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Verifing if `data` is an encoded array
|
|
204
|
+
* @param data The value that is to be verified
|
|
205
|
+
*/
|
|
206
|
+
function isEncodedArray(bytes memory data) internal pure returns (bool) {
|
|
207
|
+
uint256 nbOfBytes = data.length;
|
|
144
208
|
|
|
145
209
|
// 1) there must be at least 32 bytes to store the offset
|
|
146
210
|
if (nbOfBytes < 32) return false;
|
|
147
211
|
|
|
148
212
|
// 2) there must be at least the same number of bytes specified by
|
|
149
213
|
// the offset value (otherwise, the offset points to nowhere)
|
|
150
|
-
uint256 offset = uint256(bytes32(
|
|
214
|
+
uint256 offset = uint256(bytes32(data));
|
|
151
215
|
if (nbOfBytes < offset) return false;
|
|
152
216
|
|
|
153
217
|
// 3) there must be at least 32 x length bytes after offset
|
|
154
|
-
uint256 arrayLength =
|
|
218
|
+
uint256 arrayLength = data.toUint256(offset);
|
|
155
219
|
|
|
156
220
|
// 32 bytes word (= offset)
|
|
157
221
|
// + 32 bytes word (= array length)
|
|
@@ -161,16 +225,20 @@ library LSP2Utils {
|
|
|
161
225
|
return true;
|
|
162
226
|
}
|
|
163
227
|
|
|
164
|
-
|
|
165
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Verifing if `data` is an encoded array of addresses (address[])
|
|
230
|
+
* @param data The value that is to be verified
|
|
231
|
+
*/
|
|
232
|
+
function isEncodedArrayOfAddresses(bytes memory data) internal pure returns (bool) {
|
|
233
|
+
if (!isEncodedArray(data)) return false;
|
|
166
234
|
|
|
167
|
-
uint256 offset = uint256(bytes32(
|
|
168
|
-
uint256 arrayLength =
|
|
235
|
+
uint256 offset = uint256(bytes32(data));
|
|
236
|
+
uint256 arrayLength = data.toUint256(offset);
|
|
169
237
|
|
|
170
238
|
uint256 pointer = offset + 32;
|
|
171
239
|
|
|
172
|
-
for (uint256 ii = 0; ii < arrayLength; ii
|
|
173
|
-
bytes32 key =
|
|
240
|
+
for (uint256 ii = 0; ii < arrayLength; ii = uncheckedIncrement(ii)) {
|
|
241
|
+
bytes32 key = data.toBytes32(pointer);
|
|
174
242
|
|
|
175
243
|
// check that the leading bytes are zero bytes "00"
|
|
176
244
|
// NB: address type is padded on the left (unlike bytes20 type that is padded on the right)
|
|
@@ -183,15 +251,19 @@ library LSP2Utils {
|
|
|
183
251
|
return true;
|
|
184
252
|
}
|
|
185
253
|
|
|
186
|
-
|
|
187
|
-
|
|
254
|
+
/**
|
|
255
|
+
* @dev verify that `data` is an array of bytes4 (bytes4[]) encoded according to the Solidity ABI specs.
|
|
256
|
+
* @param data The value that is to be verified
|
|
257
|
+
*/
|
|
258
|
+
function isBytes4EncodedArray(bytes memory data) internal pure returns (bool) {
|
|
259
|
+
if (!isEncodedArray(data)) return false;
|
|
188
260
|
|
|
189
|
-
uint256 offset = uint256(bytes32(
|
|
190
|
-
uint256 arrayLength =
|
|
261
|
+
uint256 offset = uint256(bytes32(data));
|
|
262
|
+
uint256 arrayLength = data.toUint256(offset);
|
|
191
263
|
uint256 pointer = offset + 32;
|
|
192
264
|
|
|
193
|
-
for (uint256 ii = 0; ii < arrayLength; ii
|
|
194
|
-
bytes32 key =
|
|
265
|
+
for (uint256 ii = 0; ii < arrayLength; ii = uncheckedIncrement(ii)) {
|
|
266
|
+
bytes32 key = data.toBytes32(pointer);
|
|
195
267
|
|
|
196
268
|
// check that the trailing bytes are zero bytes "00"
|
|
197
269
|
if (uint224(uint256(key)) != 0) return false;
|
|
@@ -202,4 +274,14 @@ library LSP2Utils {
|
|
|
202
274
|
|
|
203
275
|
return true;
|
|
204
276
|
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @dev Will return unchecked incremented uint256
|
|
280
|
+
* can be used to save gas when iterating over loops
|
|
281
|
+
*/
|
|
282
|
+
function uncheckedIncrement(uint256 i) internal pure returns (uint256) {
|
|
283
|
+
unchecked {
|
|
284
|
+
return i + 1;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
205
287
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
// bytes10(keccak256('
|
|
4
|
+
// bytes10(keccak256('SupportedStandards')) + bytes2(0) + bytes20(keccak256('LSP3UniversalProfile'))
|
|
5
5
|
bytes32 constant _LSP3_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38;
|
|
6
6
|
|
|
7
7
|
// bytes4(keccak256('LSP3UniversalProfile'))
|
|
@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
|
|
|
3
3
|
|
|
4
4
|
// --- ERC725Y entries
|
|
5
5
|
|
|
6
|
-
// bytes10(keccak256('
|
|
6
|
+
// bytes10(keccak256('SupportedStandards')) + bytes2(0) + bytes20(keccak256('LSP4DigitalAsset'))
|
|
7
7
|
bytes32 constant _LSP4_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b60000a4d96624a38f7ac2d8d9a604ecf07c12c77e480c;
|
|
8
8
|
|
|
9
9
|
// bytes4(keccak256('LSP4DigitalAsset'))
|
|
@@ -4,9 +4,15 @@ pragma solidity ^0.8.0;
|
|
|
4
4
|
// modules
|
|
5
5
|
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
6
|
|
|
7
|
+
// libraries
|
|
8
|
+
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
9
|
+
|
|
7
10
|
// constants
|
|
8
11
|
import "./LSP4Constants.sol";
|
|
9
12
|
|
|
13
|
+
// errors
|
|
14
|
+
import {LSP4TokenNameNotEditable, LSP4TokenSymbolNotEditable} from "./LSP4Errors.sol";
|
|
15
|
+
|
|
10
16
|
/**
|
|
11
17
|
* @title LSP4DigitalAssetMetadata
|
|
12
18
|
* @author Matthew Stevens
|
|
@@ -31,9 +37,23 @@ abstract contract LSP4DigitalAssetMetadata is ERC725Y {
|
|
|
31
37
|
super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
/**
|
|
41
|
+
* @dev The ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
|
|
42
|
+
* via this function once the digital asset contract has been deployed.
|
|
43
|
+
*
|
|
44
|
+
* @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
|
|
45
|
+
*/
|
|
46
|
+
function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
|
|
47
|
+
if (dataKey == _LSP4_TOKEN_NAME_KEY) {
|
|
48
|
+
revert LSP4TokenNameNotEditable();
|
|
49
|
+
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
|
|
50
|
+
revert LSP4TokenSymbolNotEditable();
|
|
51
|
+
} else {
|
|
52
|
+
store[dataKey] = dataValue;
|
|
53
|
+
emit DataChanged(
|
|
54
|
+
dataKey,
|
|
55
|
+
dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
38
58
|
}
|
|
39
59
|
}
|
|
@@ -2,11 +2,18 @@
|
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
|
-
import {ERC725YInitAbstract
|
|
5
|
+
import {ERC725YInitAbstract} from "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";
|
|
6
|
+
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
|
|
7
|
+
|
|
8
|
+
// libraries
|
|
9
|
+
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
6
10
|
|
|
7
11
|
// constants
|
|
8
12
|
import "./LSP4Constants.sol";
|
|
9
13
|
|
|
14
|
+
// errors
|
|
15
|
+
import {LSP4TokenNameNotEditable, LSP4TokenSymbolNotEditable} from "./LSP4Errors.sol";
|
|
16
|
+
|
|
10
17
|
/**
|
|
11
18
|
* @title LSP4DigitalAssetMetadata
|
|
12
19
|
* @author Matthew Stevens
|
|
@@ -27,9 +34,23 @@ abstract contract LSP4DigitalAssetMetadataInitAbstract is ERC725YInitAbstract {
|
|
|
27
34
|
super._setData(_LSP4_TOKEN_SYMBOL_KEY, bytes(symbol_));
|
|
28
35
|
}
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @dev the ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
|
|
39
|
+
* via this function once the digital asset contract has been deployed.
|
|
40
|
+
*
|
|
41
|
+
* @dev SAVE GAS by emitting the DataChanged event with only the first 256 bytes of dataValue
|
|
42
|
+
*/
|
|
43
|
+
function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
|
|
44
|
+
if (dataKey == _LSP4_TOKEN_NAME_KEY) {
|
|
45
|
+
revert LSP4TokenNameNotEditable();
|
|
46
|
+
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
|
|
47
|
+
revert LSP4TokenSymbolNotEditable();
|
|
48
|
+
} else {
|
|
49
|
+
store[dataKey] = dataValue;
|
|
50
|
+
emit DataChanged(
|
|
51
|
+
dataKey,
|
|
52
|
+
dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
34
55
|
}
|
|
35
56
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @dev Reverts when trying to edit the data key `LSP4TokenName` after the digital asset contract has been deployed.
|
|
6
|
+
* The `LSP4TokenName` data key is located inside the ERC725Y key-value store of the digital asset contract.
|
|
7
|
+
* It can be set only once inside the constructor/initializer when the digital asset contract is being deployed.
|
|
8
|
+
*/
|
|
9
|
+
error LSP4TokenNameNotEditable();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @dev Reverts when trying to edit the data key `LSP4TokenSymbol` after the digital asset contract has been deployed.
|
|
13
|
+
* The `LSP4TokenSymbol` data key is located inside the ERC725Y key-value store of the digital asset contract.
|
|
14
|
+
* It can be set only once inside the constructor/initializer when the digital asset contract is being deployed.
|
|
15
|
+
*/
|
|
16
|
+
error LSP4TokenSymbolNotEditable();
|
|
@@ -6,5 +6,5 @@ pragma solidity ^0.8.0;
|
|
|
6
6
|
// keccak256('LSP5ReceivedAssets[]')
|
|
7
7
|
bytes32 constant _LSP5_RECEIVED_ASSETS_ARRAY_KEY = 0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b;
|
|
8
8
|
|
|
9
|
-
// bytes10(keccak256('LSP5ReceivedAssetsMap'))
|
|
10
|
-
|
|
9
|
+
// bytes10(keccak256('LSP5ReceivedAssetsMap'))
|
|
10
|
+
bytes10 constant _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX = 0x812c4334633eb816c80d;
|