@lukso/lsp-smart-contracts 0.6.2 → 0.8.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/CONTRIBUTING.md +31 -0
- package/README.md +73 -28
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +227 -15
- package/artifacts/LSP0ERC725AccountInit.json +227 -41
- package/artifacts/LSP11BasicSocialRecovery.json +493 -0
- package/artifacts/LSP11BasicSocialRecoveryInit.json +513 -0
- package/artifacts/LSP16UniversalFactory.json +236 -0
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +134 -15
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +80 -15
- package/artifacts/LSP4Compatibility.json +22 -0
- package/artifacts/LSP4DigitalAssetMetadata.json +22 -0
- package/artifacts/{LSP4DigitalAssetMetadataInit.json → LSP4DigitalAssetMetadataInitAbstract.json} +24 -51
- package/artifacts/LSP6KeyManager.json +188 -33
- package/artifacts/LSP6KeyManagerInit.json +188 -33
- package/artifacts/LSP7CappedSupply.json +58 -31
- package/artifacts/{LSP7CappedSupplyInit.json → LSP7CappedSupplyInitAbstract.json} +60 -72
- package/artifacts/LSP7CompatibleERC20.json +52 -46
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +733 -0
- package/artifacts/LSP7CompatibleERC20Mintable.json +61 -34
- package/artifacts/LSP7CompatibleERC20MintableInit.json +66 -60
- package/artifacts/LSP7DigitalAsset.json +52 -51
- package/artifacts/LSP7DigitalAssetInitAbstract.json +556 -0
- package/artifacts/LSP7Mintable.json +62 -35
- package/artifacts/LSP7MintableInit.json +62 -61
- package/artifacts/LSP8CappedSupply.json +64 -5
- package/artifacts/LSP8CappedSupplyInitAbstract.json +667 -0
- package/artifacts/LSP8CompatibleERC721.json +102 -21
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +936 -0
- package/artifacts/LSP8CompatibleERC721Mintable.json +111 -9
- package/artifacts/LSP8CompatibleERC721MintableInit.json +116 -35
- package/artifacts/LSP8IdentifiableDigitalAsset.json +58 -20
- package/artifacts/{LSP8CappedSupplyInit.json → LSP8IdentifiableDigitalAssetInitAbstract.json} +62 -65
- package/artifacts/LSP8Mintable.json +67 -8
- package/artifacts/LSP8MintableInit.json +67 -34
- package/artifacts/LSP9Vault.json +235 -17
- package/artifacts/LSP9VaultInit.json +235 -43
- package/artifacts/UniversalProfile.json +227 -15
- package/artifacts/UniversalProfileInit.json +227 -41
- package/artifacts/UniversalReceiverAddressStore.json +3 -3
- package/constants.js +416 -95
- package/contracts/Custom/EIP191Signer.sol +12 -0
- package/contracts/Factories/Create2Factory.sol +1 -3
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +13 -2
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +2 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +274 -74
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +2 -2
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +3 -2
- package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +4 -4
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +214 -0
- package/contracts/LSP11BasicSocialRecovery/ILSP11BasicSocialRecovery.sol +177 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecovery.sol +23 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +258 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInit.sol +26 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryInitAbstract.sol +19 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11Constants.sol +6 -0
- package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +60 -0
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +53 -0
- package/contracts/LSP14Ownable2Step/LSP14Constants.sol +15 -0
- package/contracts/LSP14Ownable2Step/LSP14Errors.sol +12 -0
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +212 -0
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +246 -0
- package/contracts/LSP17ContractExtension/LSP17Constants.sol +17 -0
- package/contracts/LSP17ContractExtension/LSP17Errors.sol +7 -0
- package/contracts/LSP17ContractExtension/LSP17Extendable.sol +104 -0
- package/contracts/LSP17ContractExtension/LSP17Extension.sol +45 -0
- package/contracts/LSP17ContractExtension/LSP17Utils.sol +20 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +5 -5
- package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +5 -3
- package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +21 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +156 -42
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +64 -31
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +54 -41
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +136 -28
- package/contracts/LSP3UniversalProfile/LSP3Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +16 -7
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +16 -7
- package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +3 -3
- package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +4 -4
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +103 -115
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +26 -8
- package/contracts/LSP6KeyManager/LSP6Constants.sol +45 -45
- package/contracts/LSP6KeyManager/LSP6Errors.sol +97 -20
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -2
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +786 -359
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +2 -2
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +4 -3
- package/contracts/LSP6KeyManager/LSP6Utils.sol +127 -35
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +26 -13
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +6 -6
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +5 -5
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +65 -52
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +3 -3
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +30 -1
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +24 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +28 -8
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +28 -11
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +87 -20
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +97 -19
- package/contracts/LSP7DigitalAsset/presets/ILSP7Mintable.sol +3 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +3 -4
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +9 -2
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +3 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +12 -12
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +5 -5
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +11 -10
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +10 -8
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +11 -11
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +45 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +75 -71
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +20 -3
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +20 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +27 -7
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +27 -10
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +236 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +240 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +49 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +51 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +3 -4
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +9 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +3 -3
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +9 -8
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +2 -2
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +8 -7
- package/contracts/LSP9Vault/LSP9Constants.sol +11 -8
- package/contracts/LSP9Vault/LSP9Errors.sol +8 -0
- package/contracts/LSP9Vault/LSP9Vault.sol +6 -4
- package/contracts/LSP9Vault/LSP9VaultCore.sol +324 -90
- package/contracts/LSP9Vault/LSP9VaultInit.sol +2 -2
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +5 -4
- package/contracts/Legacy/Registries/AddressRegistry.sol +1 -1
- package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +1 -1
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +4 -13
- package/contracts/UniversalProfile.sol +2 -2
- package/contracts/UniversalProfileInit.sol +2 -2
- package/contracts/UniversalProfileInitAbstract.sol +1 -1
- package/contracts/Utils/GasLib.sol +17 -0
- package/package.json +37 -32
- package/artifacts/LSP7CompatibleERC20Init.json +0 -760
- package/artifacts/LSP7DigitalAssetInit.json +0 -588
- package/artifacts/LSP8CompatibleERC721Init.json +0 -883
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +0 -639
- package/artifacts/UniversalFactory.json +0 -127
- package/contracts/Custom/ClaimOwnership.sol +0 -34
- package/contracts/Custom/ERC165Checker.sol +0 -130
- package/contracts/Custom/IClaimOwnership.sol +0 -10
- package/contracts/Factories/UniversalFactory.sol +0 -164
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +0 -24
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +0 -85
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +0 -76
- package/contracts/LSP2ERC725YJSONSchema/LSP2Errors.sol +0 -9
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +0 -26
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +0 -39
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +0 -17
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +0 -57
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +0 -19
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +0 -112
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +0 -29
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableCore.sol +0 -26
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +0 -35
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +0 -17
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +0 -58
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +0 -19
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleConstants.sol +0 -6
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +0 -187
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Init.sol +0 -25
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableCore.sol +0 -26
- package/contracts/Utils/UtilsLib.sol +0 -31
|
@@ -1,62 +1,75 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
// libraries
|
|
5
|
+
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
3
6
|
|
|
4
7
|
// constants
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from "../LSP7DigitalAsset/LSP7Constants.sol";
|
|
14
|
-
import {
|
|
15
|
-
_INTERFACEID_LSP8,
|
|
16
|
-
_TYPEID_LSP8_TOKENSRECIPIENT,
|
|
17
|
-
_TYPEID_LSP8_TOKENSSENDER
|
|
18
|
-
} from "../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
19
|
-
import {_INTERFACEID_LSP9, _TYPEID_LSP9_VAULTRECIPIENT} from "../LSP9Vault/LSP9Constants.sol";
|
|
20
|
-
import {
|
|
21
|
-
_LSP10_VAULTS_ARRAY_KEY,
|
|
22
|
-
_LSP10_VAULTS_MAP_KEY_PREFIX
|
|
23
|
-
} from "../LSP10ReceivedVaults/LSP10Constants.sol";
|
|
8
|
+
import "./ILSP1UniversalReceiver.sol";
|
|
9
|
+
import "../LSP0ERC725Account/LSP0Constants.sol";
|
|
10
|
+
import "../LSP5ReceivedAssets/LSP5Constants.sol";
|
|
11
|
+
import "../LSP7DigitalAsset/LSP7Constants.sol";
|
|
12
|
+
import "../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
13
|
+
import "../LSP9Vault/LSP9Constants.sol";
|
|
14
|
+
import "../LSP14Ownable2Step/LSP14Constants.sol";
|
|
15
|
+
import "../LSP10ReceivedVaults/LSP10Constants.sol";
|
|
24
16
|
|
|
25
17
|
library LSP1Utils {
|
|
18
|
+
function callUniversalReceiverWithCallerInfos(
|
|
19
|
+
address universalReceiverDelegate,
|
|
20
|
+
bytes32 typeId,
|
|
21
|
+
bytes calldata receivedData,
|
|
22
|
+
address msgSender,
|
|
23
|
+
uint256 msgValue
|
|
24
|
+
) internal returns (bytes memory) {
|
|
25
|
+
bytes memory callData = abi.encodePacked(
|
|
26
|
+
abi.encodeWithSelector(
|
|
27
|
+
ILSP1UniversalReceiver.universalReceiver.selector,
|
|
28
|
+
typeId,
|
|
29
|
+
receivedData
|
|
30
|
+
),
|
|
31
|
+
msgSender,
|
|
32
|
+
msgValue
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
(bool success, bytes memory result) = universalReceiverDelegate.call(callData);
|
|
36
|
+
Address.verifyCallResult(success, result, "Call to universalReceiver failed");
|
|
37
|
+
return result.length != 0 ? abi.decode(result, (bytes)) : result;
|
|
38
|
+
}
|
|
39
|
+
|
|
26
40
|
/**
|
|
27
41
|
* @dev Gets all the transfer details depending on the `typeId`
|
|
42
|
+
* @param typeId A unique identifier for a specific action
|
|
28
43
|
*/
|
|
29
44
|
function getTransferDetails(bytes32 typeId)
|
|
30
45
|
internal
|
|
31
46
|
pure
|
|
32
47
|
returns (
|
|
33
|
-
bool
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
bool invalid,
|
|
49
|
+
bytes10 mapPrefix,
|
|
50
|
+
bytes4 interfaceId,
|
|
51
|
+
bool isReceiving
|
|
37
52
|
)
|
|
38
53
|
{
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
typeId ==
|
|
43
|
-
|
|
44
|
-
) {
|
|
45
|
-
arrayKey = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
|
|
54
|
+
if (typeId == _TYPEID_LSP7_TOKENSSENDER || typeId == _TYPEID_LSP7_TOKENSRECIPIENT) {
|
|
55
|
+
mapPrefix = _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX;
|
|
56
|
+
interfaceId = _INTERFACEID_LSP7;
|
|
57
|
+
isReceiving = typeId == _TYPEID_LSP7_TOKENSRECIPIENT ? true : false;
|
|
58
|
+
} else if (typeId == _TYPEID_LSP8_TOKENSSENDER || typeId == _TYPEID_LSP8_TOKENSRECIPIENT) {
|
|
46
59
|
mapPrefix = _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX;
|
|
47
|
-
interfaceId =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
60
|
+
interfaceId = _INTERFACEID_LSP8;
|
|
61
|
+
isReceiving = typeId == _TYPEID_LSP8_TOKENSRECIPIENT ? true : false;
|
|
62
|
+
} else if (
|
|
63
|
+
typeId == _TYPEID_LSP9_OwnershipTransferred_SenderNotification ||
|
|
64
|
+
typeId == _TYPEID_LSP9_OwnershipTransferred_RecipientNotification
|
|
65
|
+
) {
|
|
66
|
+
mapPrefix = _LSP10_VAULTS_MAP_KEY_PREFIX;
|
|
67
|
+
interfaceId = _INTERFACEID_LSP9;
|
|
68
|
+
isReceiving = (typeId == _TYPEID_LSP9_OwnershipTransferred_RecipientNotification)
|
|
53
69
|
? true
|
|
54
70
|
: false;
|
|
55
71
|
} else {
|
|
56
|
-
|
|
57
|
-
mapPrefix = _LSP10_VAULTS_MAP_KEY_PREFIX;
|
|
58
|
-
interfaceId = _INTERFACEID_LSP9;
|
|
59
|
-
isReceiving = typeId == _TYPEID_LSP9_VAULTRECIPIENT ? true : false;
|
|
72
|
+
invalid = true;
|
|
60
73
|
}
|
|
61
74
|
}
|
|
62
75
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// libraries
|
|
5
5
|
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
6
|
-
import {UtilsLib} from "../Utils/UtilsLib.sol";
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* @title ERC725 Utility library to encode key types
|
|
@@ -14,15 +13,23 @@ import {UtilsLib} from "../Utils/UtilsLib.sol";
|
|
|
14
13
|
library LSP2Utils {
|
|
15
14
|
using BytesLib for bytes;
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @dev Generates a data key of keyType Singleton
|
|
18
|
+
* @param keyName The string to hash to generate a Singleton data key
|
|
19
|
+
* @return a bytes32 dataKey
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
19
22
|
function generateSingletonKey(string memory keyName) internal pure returns (bytes32) {
|
|
20
23
|
return keccak256(bytes(keyName));
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @dev Generates a data key of keyType Array by hashing `keyName`.
|
|
28
|
+
* @param keyName The string that will be used to generate an data key of keyType Array
|
|
29
|
+
*/
|
|
23
30
|
function generateArrayKey(string memory keyName) internal pure returns (bytes32) {
|
|
24
31
|
bytes memory dataKey = bytes(keyName);
|
|
25
|
-
|
|
32
|
+
require(dataKey.length >= 2, "MUST be longer than 2 characters");
|
|
26
33
|
require(
|
|
27
34
|
dataKey[dataKey.length - 2] == 0x5b && // "[" in utf8 encoded
|
|
28
35
|
dataKey[dataKey.length - 1] == 0x5d, // "]" in utf8
|
|
@@ -32,18 +39,29 @@ library LSP2Utils {
|
|
|
32
39
|
return keccak256(dataKey);
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @dev Generates a Array index data key by concatenating the first 16 bytes of `arrayKey`
|
|
44
|
+
* and `index` transformed from uint256 to bytes16 (uint256 -> uint128 -> bytes16)
|
|
45
|
+
* @param arrayKey The key from which we're getting the first half of the Array index data key from
|
|
46
|
+
* @param index Used to generate the second half of the Array index data key
|
|
47
|
+
*/
|
|
48
|
+
function generateArrayElementKeyAtIndex(bytes32 arrayKey, uint128 index)
|
|
36
49
|
internal
|
|
37
50
|
pure
|
|
38
51
|
returns (bytes32)
|
|
39
52
|
{
|
|
40
|
-
bytes memory elementInArray =
|
|
41
|
-
bytes16(arrayKey),
|
|
42
|
-
bytes16(uint128(index))
|
|
43
|
-
);
|
|
53
|
+
bytes memory elementInArray = bytes.concat(bytes16(arrayKey), bytes16(index));
|
|
44
54
|
return bytes32(elementInArray);
|
|
45
55
|
}
|
|
46
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @dev Generates a data key of keyType Mapping by hashing two strings:
|
|
59
|
+
* <bytes10(keccak256(firstWord))>:<bytes2(0)>:<bytes20(keccak256(firstWord))>
|
|
60
|
+
* @param firstWord Used to generate a hash and its first 10 bytes
|
|
61
|
+
* are used for the first part of the data key of keyType Mapping
|
|
62
|
+
* @param lastWord Used to generate a hash and its first 20 bytes
|
|
63
|
+
* are used for the last part of the data key of keyType Mapping
|
|
64
|
+
*/
|
|
47
65
|
function generateMappingKey(string memory firstWord, string memory lastWord)
|
|
48
66
|
internal
|
|
49
67
|
pure
|
|
@@ -61,6 +79,13 @@ library LSP2Utils {
|
|
|
61
79
|
return bytes32(temporaryBytes);
|
|
62
80
|
}
|
|
63
81
|
|
|
82
|
+
/**
|
|
83
|
+
* @dev Generates a data key of keyType Mapping by hashing a string and concatenating it with an address:
|
|
84
|
+
* <bytes10(keccak256(firstWord))>:<bytes2(0)>:<bytes20(addr)>
|
|
85
|
+
* @param firstWord Used to generate a hash and its first 10 bytes
|
|
86
|
+
* are used for the first part of the data key of keyType Mapping
|
|
87
|
+
* @param addr used for the last part of the data key of keyType Mapping
|
|
88
|
+
*/
|
|
64
89
|
function generateMappingKey(string memory firstWord, address addr)
|
|
65
90
|
internal
|
|
66
91
|
pure
|
|
@@ -77,15 +102,30 @@ library LSP2Utils {
|
|
|
77
102
|
return bytes32(temporaryBytes);
|
|
78
103
|
}
|
|
79
104
|
|
|
80
|
-
|
|
105
|
+
/**
|
|
106
|
+
* @dev Generate a data key of keyType Mapping
|
|
107
|
+
* <bytes10keyPrefix>:<bytes2(0)>:<bytes20Value>
|
|
108
|
+
* @param keyPrefix First part of the data key of keyType Mapping
|
|
109
|
+
* @param bytes20Value Second part of the data key of keyType Mapping
|
|
110
|
+
*/
|
|
111
|
+
function generateMappingKey(bytes10 keyPrefix, bytes20 bytes20Value)
|
|
81
112
|
internal
|
|
82
113
|
pure
|
|
83
114
|
returns (bytes32)
|
|
84
115
|
{
|
|
85
|
-
bytes memory generatedKey = bytes.concat(keyPrefix, bytes20Value);
|
|
116
|
+
bytes memory generatedKey = bytes.concat(keyPrefix, bytes2(0), bytes20Value);
|
|
86
117
|
return bytes32(generatedKey);
|
|
87
118
|
}
|
|
88
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @dev Generate a data key of keyType MappingWithGrouping by using two strings and an address
|
|
122
|
+
* <bytes6(keccak256(firstWord))>:<bytes4(keccak256(secondWord))>:<bytes2(0)>:<bytes20(addr)>
|
|
123
|
+
* @param firstWord Used to generate a hash and its first 6 bytes
|
|
124
|
+
* are used for the first part of the data key of keyType MappingWithGrouping
|
|
125
|
+
* @param secondWord Used to generate a hash and its first 4 bytes
|
|
126
|
+
* are used for the second part of the data key of keyType MappingWithGrouping
|
|
127
|
+
* @param addr Used for the last part of the data key of keyType MappingWithGrouping
|
|
128
|
+
*/
|
|
89
129
|
function generateMappingWithGroupingKey(
|
|
90
130
|
string memory firstWord,
|
|
91
131
|
string memory secondWord,
|
|
@@ -104,49 +144,65 @@ library LSP2Utils {
|
|
|
104
144
|
return bytes32(temporaryBytes);
|
|
105
145
|
}
|
|
106
146
|
|
|
107
|
-
|
|
147
|
+
/**
|
|
148
|
+
* @dev Generate a data key of keyType MappingWithGrouping
|
|
149
|
+
* <bytes10keyPrefix>:<bytes2(0)>:<bytes20Value>
|
|
150
|
+
* @param keyPrefix Used for the first part of the data key of keyType MappingWithGrouping
|
|
151
|
+
* @param bytes20Value Used for the first last of the data key of keyType MappingWithGrouping
|
|
152
|
+
*/
|
|
153
|
+
function generateMappingWithGroupingKey(bytes10 keyPrefix, bytes20 bytes20Value)
|
|
108
154
|
internal
|
|
109
155
|
pure
|
|
110
156
|
returns (bytes32)
|
|
111
157
|
{
|
|
112
|
-
bytes memory generatedKey = bytes.concat(keyPrefix, bytes20Value);
|
|
158
|
+
bytes memory generatedKey = bytes.concat(keyPrefix, bytes2(0), bytes20Value);
|
|
113
159
|
return bytes32(generatedKey);
|
|
114
160
|
}
|
|
115
161
|
|
|
162
|
+
/**
|
|
163
|
+
* @dev Generate a JSONURL valueContent
|
|
164
|
+
* @param hashFunction The function used to hash the JSON file
|
|
165
|
+
* @param json Bytes value of the JSON file
|
|
166
|
+
* @param url The URL where the JSON file is hosted
|
|
167
|
+
*/
|
|
116
168
|
function generateJSONURLValue(
|
|
117
169
|
string memory hashFunction,
|
|
118
170
|
string memory json,
|
|
119
171
|
string memory url
|
|
120
|
-
) internal pure returns (bytes memory
|
|
172
|
+
) internal pure returns (bytes memory) {
|
|
121
173
|
bytes32 hashFunctionDigest = keccak256(bytes(hashFunction));
|
|
122
174
|
bytes32 jsonDigest = keccak256(bytes(json));
|
|
123
175
|
|
|
124
|
-
|
|
176
|
+
return abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, url);
|
|
125
177
|
}
|
|
126
178
|
|
|
179
|
+
/**
|
|
180
|
+
* @dev Generate a ASSETURL valueContent
|
|
181
|
+
* @param hashFunction The function used to hash the JSON file
|
|
182
|
+
* @param assetBytes Bytes value of the JSON file
|
|
183
|
+
* @param url The URL where the JSON file is hosted
|
|
184
|
+
*/
|
|
127
185
|
function generateASSETURLValue(
|
|
128
186
|
string memory hashFunction,
|
|
129
187
|
string memory assetBytes,
|
|
130
188
|
string memory url
|
|
131
|
-
) internal pure returns (bytes memory
|
|
189
|
+
) internal pure returns (bytes memory) {
|
|
132
190
|
bytes32 hashFunctionDigest = keccak256(bytes(hashFunction));
|
|
133
191
|
bytes32 jsonDigest = keccak256(bytes(assetBytes));
|
|
134
192
|
|
|
135
|
-
|
|
193
|
+
return abi.encodePacked(bytes4(hashFunctionDigest), jsonDigest, url);
|
|
136
194
|
}
|
|
137
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Verifing if `data` is an encoded array
|
|
198
|
+
* @param data The value that is to be verified
|
|
199
|
+
*/
|
|
138
200
|
function isEncodedArray(bytes memory data) internal pure returns (bool) {
|
|
139
201
|
uint256 nbOfBytes = data.length;
|
|
140
202
|
|
|
141
|
-
//
|
|
142
|
-
if (nbOfBytes < 32) return false;
|
|
143
|
-
|
|
144
|
-
// 2) there must be at least the same number of bytes specified by
|
|
145
|
-
// the offset value (otherwise, the offset points to nowhere)
|
|
203
|
+
// there must be at least 32 x length bytes after offset
|
|
146
204
|
uint256 offset = uint256(bytes32(data));
|
|
147
|
-
if (nbOfBytes < offset) return false;
|
|
148
|
-
|
|
149
|
-
// 3) there must be at least 32 x length bytes after offset
|
|
205
|
+
if (nbOfBytes < offset + 32) return false;
|
|
150
206
|
uint256 arrayLength = data.toUint256(offset);
|
|
151
207
|
|
|
152
208
|
// 32 bytes word (= offset)
|
|
@@ -157,6 +213,10 @@ library LSP2Utils {
|
|
|
157
213
|
return true;
|
|
158
214
|
}
|
|
159
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Verifing if `data` is an encoded array of addresses (address[])
|
|
218
|
+
* @param data The value that is to be verified
|
|
219
|
+
*/
|
|
160
220
|
function isEncodedArrayOfAddresses(bytes memory data) internal pure returns (bool) {
|
|
161
221
|
if (!isEncodedArray(data)) return false;
|
|
162
222
|
|
|
@@ -165,7 +225,7 @@ library LSP2Utils {
|
|
|
165
225
|
|
|
166
226
|
uint256 pointer = offset + 32;
|
|
167
227
|
|
|
168
|
-
for (uint256 ii = 0; ii < arrayLength; ii
|
|
228
|
+
for (uint256 ii = 0; ii < arrayLength; ii = uncheckedIncrement(ii)) {
|
|
169
229
|
bytes32 key = data.toBytes32(pointer);
|
|
170
230
|
|
|
171
231
|
// check that the leading bytes are zero bytes "00"
|
|
@@ -179,6 +239,10 @@ library LSP2Utils {
|
|
|
179
239
|
return true;
|
|
180
240
|
}
|
|
181
241
|
|
|
242
|
+
/**
|
|
243
|
+
* @dev verify that `data` is an array of bytes4 (bytes4[]) encoded according to the Solidity ABI specs.
|
|
244
|
+
* @param data The value that is to be verified
|
|
245
|
+
*/
|
|
182
246
|
function isBytes4EncodedArray(bytes memory data) internal pure returns (bool) {
|
|
183
247
|
if (!isEncodedArray(data)) return false;
|
|
184
248
|
|
|
@@ -186,7 +250,7 @@ library LSP2Utils {
|
|
|
186
250
|
uint256 arrayLength = data.toUint256(offset);
|
|
187
251
|
uint256 pointer = offset + 32;
|
|
188
252
|
|
|
189
|
-
for (uint256 ii = 0; ii < arrayLength; ii
|
|
253
|
+
for (uint256 ii = 0; ii < arrayLength; ii = uncheckedIncrement(ii)) {
|
|
190
254
|
bytes32 key = data.toBytes32(pointer);
|
|
191
255
|
|
|
192
256
|
// check that the trailing bytes are zero bytes "00"
|
|
@@ -198,4 +262,48 @@ library LSP2Utils {
|
|
|
198
262
|
|
|
199
263
|
return true;
|
|
200
264
|
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @dev Verify the validity of the `compactBytesArray` according to LSP2
|
|
268
|
+
*/
|
|
269
|
+
function isCompactBytesArray(bytes memory compactBytesArray) internal pure returns (bool) {
|
|
270
|
+
/**
|
|
271
|
+
* Pointer will always land on these values:
|
|
272
|
+
*
|
|
273
|
+
* ↓↓
|
|
274
|
+
* 03 a00000
|
|
275
|
+
* 05 fff83a0011
|
|
276
|
+
* 20 aa0000000000000000000000000000000000000000000000000000000000cafe
|
|
277
|
+
* 12 bb000000000000000000000000000000beef
|
|
278
|
+
* 19 cc00000000000000000000000000000000000000000000deed
|
|
279
|
+
* ↑↑
|
|
280
|
+
*
|
|
281
|
+
* The pointer can only land on the length of the following bytes value.
|
|
282
|
+
*/
|
|
283
|
+
uint256 pointer;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Check each length byte and make sure that when you reach the last length byte.
|
|
287
|
+
* Make sure that the last length describes exactly the last bytes value and you do not get out of bounds.
|
|
288
|
+
*/
|
|
289
|
+
while (pointer < compactBytesArray.length) {
|
|
290
|
+
if (pointer + 1 >= compactBytesArray.length) return false;
|
|
291
|
+
uint256 elementLength = uint16(
|
|
292
|
+
bytes2(abi.encodePacked(compactBytesArray[pointer], compactBytesArray[pointer + 1]))
|
|
293
|
+
);
|
|
294
|
+
pointer += elementLength + 2;
|
|
295
|
+
}
|
|
296
|
+
if (pointer == compactBytesArray.length) return true;
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* @dev Will return unchecked incremented uint256
|
|
302
|
+
* can be used to save gas when iterating over loops
|
|
303
|
+
*/
|
|
304
|
+
function uncheckedIncrement(uint256 i) internal pure returns (uint256) {
|
|
305
|
+
unchecked {
|
|
306
|
+
return i + 1;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
201
309
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// bytes10(keccak256('SupportedStandards')) + bytes2(0) + bytes20(keccak256('LSP3UniversalProfile'))
|
|
5
5
|
bytes32 constant _LSP3_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b60000abe425d64acd861a49b8ddf5c0b6962110481f38;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
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
|
|
|
@@ -35,16 +38,22 @@ abstract contract LSP4DigitalAssetMetadata is ERC725Y {
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
|
-
* @dev
|
|
39
|
-
* once the digital asset contract has been deployed
|
|
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
|
|
40
45
|
*/
|
|
41
|
-
function _setData(bytes32
|
|
42
|
-
if (
|
|
46
|
+
function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
|
|
47
|
+
if (dataKey == _LSP4_TOKEN_NAME_KEY) {
|
|
43
48
|
revert LSP4TokenNameNotEditable();
|
|
44
|
-
} else if (
|
|
49
|
+
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
|
|
45
50
|
revert LSP4TokenSymbolNotEditable();
|
|
46
51
|
} else {
|
|
47
|
-
|
|
52
|
+
_store[dataKey] = dataValue;
|
|
53
|
+
emit DataChanged(
|
|
54
|
+
dataKey,
|
|
55
|
+
dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
|
|
56
|
+
);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
// modules
|
|
5
5
|
import {ERC725YInitAbstract} from "@erc725/smart-contracts/contracts/ERC725YInitAbstract.sol";
|
|
6
6
|
import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
|
|
7
7
|
|
|
8
|
+
// libraries
|
|
9
|
+
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
10
|
+
|
|
8
11
|
// constants
|
|
9
12
|
import "./LSP4Constants.sol";
|
|
10
13
|
|
|
@@ -32,16 +35,22 @@ abstract contract LSP4DigitalAssetMetadataInitAbstract is ERC725YInitAbstract {
|
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
|
-
* @dev the ERC725Y data keys `LSP4TokenName` and `LSP4TokenSymbol` cannot be changed
|
|
36
|
-
* once the digital asset contract has been deployed
|
|
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
|
|
37
42
|
*/
|
|
38
|
-
function _setData(bytes32
|
|
39
|
-
if (
|
|
43
|
+
function _setData(bytes32 dataKey, bytes memory dataValue) internal virtual override {
|
|
44
|
+
if (dataKey == _LSP4_TOKEN_NAME_KEY) {
|
|
40
45
|
revert LSP4TokenNameNotEditable();
|
|
41
|
-
} else if (
|
|
46
|
+
} else if (dataKey == _LSP4_TOKEN_SYMBOL_KEY) {
|
|
42
47
|
revert LSP4TokenSymbolNotEditable();
|
|
43
48
|
} else {
|
|
44
|
-
|
|
49
|
+
_store[dataKey] = dataValue;
|
|
50
|
+
emit DataChanged(
|
|
51
|
+
dataKey,
|
|
52
|
+
dataValue.length <= 256 ? dataValue : BytesLib.slice(dataValue, 0, 256)
|
|
53
|
+
);
|
|
45
54
|
}
|
|
46
55
|
}
|
|
47
56
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
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.
|
|
6
|
+
* The `LSP4TokenName` data key is located inside the ERC725Y Data key-value store of the digital asset contract.
|
|
7
7
|
* It can be set only once inside the constructor/initializer when the digital asset contract is being deployed.
|
|
8
8
|
*/
|
|
9
9
|
error LSP4TokenNameNotEditable();
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
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.
|
|
13
|
+
* The `LSP4TokenSymbol` data key is located inside the ERC725Y Data key-value store of the digital asset contract.
|
|
14
14
|
* It can be set only once inside the constructor/initializer when the digital asset contract is being deployed.
|
|
15
15
|
*/
|
|
16
16
|
error LSP4TokenSymbolNotEditable();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
3
|
|
|
4
|
-
// --- ERC725Y Keys
|
|
4
|
+
// --- ERC725Y Data Keys
|
|
5
5
|
|
|
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;
|