@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
|
@@ -1,189 +1,85 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
-
// modules
|
|
5
|
-
import "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
|
-
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
7
|
-
|
|
8
4
|
// interfaces
|
|
9
|
-
import "
|
|
10
|
-
import "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
|
|
5
|
+
import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
6
|
+
import {ILSP7DigitalAsset} from "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
|
|
7
|
+
import {ILSP6KeyManager} from "../../../LSP6KeyManager/ILSP6KeyManager.sol";
|
|
11
8
|
|
|
12
9
|
// libraries
|
|
13
|
-
import "../../../
|
|
10
|
+
import {ERC165Checker} from "../../../Custom/ERC165Checker.sol";
|
|
11
|
+
import {LSP1Utils} from "../../LSP1Utils.sol";
|
|
12
|
+
import {LSP2Utils} from "../../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
13
|
+
import {LSP5Utils} from "../../../LSP5ReceivedAssets/LSP5Utils.sol";
|
|
14
|
+
|
|
15
|
+
// modules
|
|
16
|
+
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
17
|
+
import {LSP6KeyManager} from "../../../LSP6KeyManager/LSP6KeyManager.sol";
|
|
14
18
|
|
|
15
19
|
// constants
|
|
16
|
-
import "
|
|
17
|
-
import "../../../
|
|
18
|
-
import "../../../LSP7DigitalAsset/LSP7Constants.sol";
|
|
19
|
-
import "../../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
20
|
-
import "../../../LSP9Vault/LSP9Constants.sol";
|
|
20
|
+
import {_INTERFACEID_LSP6} from "../../../LSP6KeyManager/LSP6Constants.sol";
|
|
21
|
+
import {_TYPEID_LSP9_VAULTSENDER} from "../../../LSP9Vault/LSP9Constants.sol";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
|
|
24
25
|
*/
|
|
25
|
-
abstract contract
|
|
26
|
-
|
|
26
|
+
abstract contract TokenAndVaultHandling {
|
|
27
|
+
function _tokenAndVaultHandling(address caller, bytes32 typeId)
|
|
28
|
+
internal
|
|
29
|
+
returns (bytes memory result)
|
|
30
|
+
{
|
|
31
|
+
// avoid EOAs spamming the storage
|
|
32
|
+
if (caller.code.length == 0) return "";
|
|
27
33
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
bytes32 typeId,
|
|
31
|
-
bytes memory data
|
|
32
|
-
) internal returns (bytes memory result) {
|
|
33
|
-
address keyManagerAddress = ERC725Y(msg.sender).owner();
|
|
34
|
-
if (
|
|
35
|
-
ERC165Checker.supportsInterface(
|
|
36
|
-
keyManagerAddress,
|
|
37
|
-
_INTERFACEID_LSP6
|
|
38
|
-
)
|
|
39
|
-
) {
|
|
40
|
-
(
|
|
41
|
-
bytes32 arrayKey,
|
|
42
|
-
bytes32 mapHash,
|
|
43
|
-
bytes4 interfaceID
|
|
44
|
-
) = _getTransferData(typeId);
|
|
45
|
-
bytes32 mapKey = ERC725Utils.generateMapKey(
|
|
46
|
-
mapHash,
|
|
47
|
-
abi.encodePacked(sender)
|
|
48
|
-
);
|
|
49
|
-
bytes memory mapValue = IERC725Y(msg.sender).getDataSingle(mapKey);
|
|
34
|
+
address keyManager = ERC725Y(msg.sender).owner();
|
|
35
|
+
if (!ERC165Checker.supportsERC165Interface(keyManager, _INTERFACEID_LSP6)) return "";
|
|
50
36
|
|
|
51
|
-
|
|
52
|
-
typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
53
|
-
typeId == _TYPEID_LSP8_TOKENSRECIPIENT ||
|
|
54
|
-
typeId == _TYPEID_LSP9_VAULTRECIPIENT
|
|
55
|
-
) {
|
|
56
|
-
if (bytes12(mapValue) == bytes12(0)) {
|
|
57
|
-
(bytes32[] memory keys, bytes[] memory values) = ERC725Utils
|
|
58
|
-
.addMapAndArrayKey(
|
|
59
|
-
IERC725Y(msg.sender),
|
|
60
|
-
arrayKey,
|
|
61
|
-
mapKey,
|
|
62
|
-
sender,
|
|
63
|
-
interfaceID
|
|
64
|
-
);
|
|
37
|
+
address target = ILSP6KeyManager(keyManager).target();
|
|
65
38
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
keys,
|
|
69
|
-
values
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
} else if (
|
|
73
|
-
typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
74
|
-
typeId == _TYPEID_LSP8_TOKENSSENDER ||
|
|
75
|
-
typeId == _TYPEID_LSP9_VAULTSENDER
|
|
76
|
-
) {
|
|
77
|
-
if (bytes12(mapValue) != bytes12(0)) {
|
|
78
|
-
if (typeId == _TYPEID_LSP9_VAULTSENDER) {
|
|
79
|
-
(
|
|
80
|
-
bytes32[] memory keys,
|
|
81
|
-
bytes[] memory values
|
|
82
|
-
) = ERC725Utils.removeMapAndArrayKey(
|
|
83
|
-
IERC725Y(msg.sender),
|
|
84
|
-
arrayKey,
|
|
85
|
-
mapHash,
|
|
86
|
-
mapKey
|
|
87
|
-
);
|
|
39
|
+
// check if the caller is the same account controlled by the keyManager
|
|
40
|
+
if (msg.sender != target) return "";
|
|
88
41
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
96
|
-
typeId == _TYPEID_LSP8_TOKENSSENDER
|
|
97
|
-
) {
|
|
98
|
-
uint256 balance = ILSP7DigitalAsset(sender).balanceOf(
|
|
99
|
-
msg.sender
|
|
100
|
-
);
|
|
101
|
-
if ((balance - _tokenAmount(typeId, data)) == 0) {
|
|
102
|
-
(
|
|
103
|
-
bytes32[] memory keys,
|
|
104
|
-
bytes[] memory values
|
|
105
|
-
) = ERC725Utils.removeMapAndArrayKey(
|
|
106
|
-
IERC725Y(msg.sender),
|
|
107
|
-
arrayKey,
|
|
108
|
-
mapHash,
|
|
109
|
-
mapKey
|
|
110
|
-
);
|
|
42
|
+
(
|
|
43
|
+
bool isReceiving,
|
|
44
|
+
bytes32 arrayLengthKey,
|
|
45
|
+
bytes12 mapPrefix,
|
|
46
|
+
bytes4 interfaceID
|
|
47
|
+
) = LSP1Utils.getTransferDetails(typeId);
|
|
111
48
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
keys,
|
|
115
|
-
values
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
49
|
+
bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
|
|
50
|
+
bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
|
|
123
51
|
|
|
124
|
-
|
|
52
|
+
if (isReceiving) {
|
|
53
|
+
// if the map value is already set, then do nothing
|
|
54
|
+
if (bytes12(mapValue) != bytes12(0)) return "";
|
|
125
55
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
_typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
138
|
-
_typeId == _TYPEID_LSP8_TOKENSSENDER ||
|
|
139
|
-
_typeId == _TYPEID_LSP8_TOKENSRECIPIENT
|
|
140
|
-
) {
|
|
141
|
-
_arrayKey = _ARRAYKEY_LSP5;
|
|
142
|
-
_mapHash = _MAPHASH_LSP5;
|
|
143
|
-
if (
|
|
144
|
-
_typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
145
|
-
_typeId == _TYPEID_LSP7_TOKENSRECIPIENT
|
|
146
|
-
) {
|
|
147
|
-
_interfaceID = _INTERFACEID_LSP7;
|
|
148
|
-
} else {
|
|
149
|
-
_interfaceID = _INTERFACEID_LSP8;
|
|
150
|
-
}
|
|
151
|
-
} else if (
|
|
152
|
-
_typeId == _TYPEID_LSP9_VAULTSENDER ||
|
|
153
|
-
_typeId == _TYPEID_LSP9_VAULTRECIPIENT
|
|
154
|
-
) {
|
|
155
|
-
_arrayKey = _ARRAYKEY_LSP10;
|
|
156
|
-
_mapHash = _MAPHASH_LSP10;
|
|
157
|
-
_interfaceID = _INTERFACEID_LSP9;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function _executeViaKeyManager(
|
|
162
|
-
ILSP6KeyManager _keyManagerAdd,
|
|
163
|
-
bytes32[] memory _keys,
|
|
164
|
-
bytes[] memory _values
|
|
165
|
-
) private returns (bytes memory result) {
|
|
166
|
-
bytes memory payload = abi.encodeWithSelector(
|
|
167
|
-
IERC725Y.setData.selector,
|
|
168
|
-
_keys,
|
|
169
|
-
_values
|
|
170
|
-
);
|
|
171
|
-
result = ILSP6KeyManager(_keyManagerAdd).execute(payload);
|
|
172
|
-
}
|
|
56
|
+
result = LSP5Utils.addMapAndArrayKeyViaKeyManager(
|
|
57
|
+
IERC725Y(msg.sender),
|
|
58
|
+
arrayLengthKey,
|
|
59
|
+
mapKey,
|
|
60
|
+
caller,
|
|
61
|
+
interfaceID,
|
|
62
|
+
keyManager
|
|
63
|
+
);
|
|
64
|
+
} else {
|
|
65
|
+
// if there is no map value for the asset to remove, then do nothing
|
|
66
|
+
if (bytes12(mapValue) == bytes12(0)) return "";
|
|
173
67
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (_typeId == _TYPEID_LSP7_TOKENSSENDER) {
|
|
180
|
-
/* solhint-disable */
|
|
181
|
-
assembly {
|
|
182
|
-
amount := mload(add(add(_data, 0x20), 0x28))
|
|
68
|
+
// if it's a token transfer (LSP7/LSP8)
|
|
69
|
+
if (typeId != _TYPEID_LSP9_VAULTSENDER) {
|
|
70
|
+
// if the amount sent is not the full balance, then do not remove the keys
|
|
71
|
+
uint256 balance = ILSP7DigitalAsset(caller).balanceOf(msg.sender);
|
|
72
|
+
if (balance != 0) return "";
|
|
183
73
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
74
|
+
|
|
75
|
+
result = LSP5Utils.removeMapAndArrayKeyViaKeyManager(
|
|
76
|
+
IERC725Y(msg.sender),
|
|
77
|
+
arrayLengthKey,
|
|
78
|
+
mapPrefix,
|
|
79
|
+
mapKey,
|
|
80
|
+
mapValue,
|
|
81
|
+
keyManager
|
|
82
|
+
);
|
|
187
83
|
}
|
|
188
84
|
}
|
|
189
85
|
}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
// interfaces
|
|
5
|
+
import {ILSP1UniversalReceiverDelegate} from "../ILSP1UniversalReceiverDelegate.sol";
|
|
6
|
+
|
|
4
7
|
// modules
|
|
5
|
-
import "
|
|
8
|
+
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
9
|
+
import {TokenAndVaultHandling} from "./Handling/TokenAndVaultHandling.sol";
|
|
10
|
+
|
|
11
|
+
// constants
|
|
12
|
+
import {_INTERFACEID_LSP1_DELEGATE} from "../LSP1Constants.sol";
|
|
13
|
+
import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "../../LSP7DigitalAsset/LSP7Constants.sol";
|
|
14
|
+
import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
15
|
+
import {_TYPEID_LSP9_VAULTSENDER, _TYPEID_LSP9_VAULTRECIPIENT} from "../../LSP9Vault/LSP9Constants.sol";
|
|
6
16
|
|
|
7
17
|
/**
|
|
8
|
-
* @title Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
|
|
18
|
+
* @title Core Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
|
|
9
19
|
* the LSP5-ReceivedAsset and LSP10-ReceivedVaults standard and removing the sent vaults and assets.
|
|
10
20
|
*
|
|
11
21
|
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
@@ -15,12 +25,45 @@ import "./LSP1UniversalReceiverDelegateUPCore.sol";
|
|
|
15
25
|
*
|
|
16
26
|
*/
|
|
17
27
|
contract LSP1UniversalReceiverDelegateUP is
|
|
18
|
-
|
|
28
|
+
ERC165,
|
|
29
|
+
ILSP1UniversalReceiverDelegate,
|
|
30
|
+
TokenAndVaultHandling
|
|
19
31
|
{
|
|
20
32
|
/**
|
|
21
|
-
* @
|
|
33
|
+
* @inheritdoc ILSP1UniversalReceiverDelegate
|
|
34
|
+
* @dev Allows to register arrayKeys and Map of incoming vaults and assets and removing them after being sent
|
|
35
|
+
* @return result the return value of keyManager's execute function
|
|
36
|
+
*/
|
|
37
|
+
function universalReceiverDelegate(
|
|
38
|
+
address sender,
|
|
39
|
+
uint256 value,
|
|
40
|
+
bytes32 typeId,
|
|
41
|
+
bytes memory data // solhint-disable no-unused-vars
|
|
42
|
+
) public virtual override returns (bytes memory result) {
|
|
43
|
+
if (
|
|
44
|
+
typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
45
|
+
typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
46
|
+
typeId == _TYPEID_LSP8_TOKENSSENDER ||
|
|
47
|
+
typeId == _TYPEID_LSP8_TOKENSRECIPIENT ||
|
|
48
|
+
typeId == _TYPEID_LSP9_VAULTSENDER ||
|
|
49
|
+
typeId == _TYPEID_LSP9_VAULTRECIPIENT
|
|
50
|
+
) {
|
|
51
|
+
result = _tokenAndVaultHandling(sender, typeId);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* @TODO
|
|
55
|
+
else if() {
|
|
56
|
+
result = FollowerHandling(sender, typeId, data);
|
|
57
|
+
}
|
|
58
|
+
*/
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// --- Overrides
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @inheritdoc ERC165
|
|
22
65
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
66
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
67
|
+
return interfaceId == _INTERFACEID_LSP1_DELEGATE || super.supportsInterface(interfaceId);
|
|
25
68
|
}
|
|
26
69
|
}
|
|
@@ -1,114 +1,74 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
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 "
|
|
5
|
+
import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
6
|
+
import {ILSP7DigitalAsset} from "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
|
|
9
7
|
|
|
10
8
|
// libraries
|
|
11
|
-
import "../../../
|
|
9
|
+
import {ERC165Checker} from "../../../Custom/ERC165Checker.sol";
|
|
10
|
+
import {LSP1Utils} from "../../LSP1Utils.sol";
|
|
11
|
+
import {LSP2Utils} from "../../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
12
|
+
import {LSP5Utils} from "../../../LSP5ReceivedAssets/LSP5Utils.sol";
|
|
13
|
+
|
|
14
|
+
// modules
|
|
15
|
+
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
16
|
+
import {LSP6KeyManager} from "../../../LSP6KeyManager/LSP6KeyManager.sol";
|
|
12
17
|
|
|
13
18
|
// constants
|
|
14
19
|
import "../../LSP1Constants.sol";
|
|
15
|
-
import "../../../LSP7DigitalAsset/LSP7Constants.sol";
|
|
16
|
-
import "../../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
17
20
|
import "../../../LSP9Vault/LSP9Constants.sol";
|
|
18
21
|
|
|
19
22
|
/**
|
|
20
|
-
* @dev Function logic to add and remove the MapAndArrayKey of incoming assets
|
|
23
|
+
* @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
|
|
21
24
|
*/
|
|
22
|
-
abstract contract
|
|
23
|
-
|
|
25
|
+
abstract contract TokenHandling {
|
|
26
|
+
function _tokenHandling(address caller, bytes32 typeId) internal returns (bytes memory result) {
|
|
27
|
+
// avoid EOAs spamming the storage
|
|
28
|
+
if (caller.code.length == 0) return "";
|
|
29
|
+
|
|
30
|
+
if (!ERC165Checker.supportsERC165Interface(msg.sender, _INTERFACEID_LSP9)) return "";
|
|
24
31
|
|
|
25
|
-
function _tokenHandling(
|
|
26
|
-
address sender,
|
|
27
|
-
bytes32 typeId,
|
|
28
|
-
bytes memory data
|
|
29
|
-
) internal returns (bytes memory) {
|
|
30
32
|
(
|
|
31
|
-
|
|
32
|
-
bytes32
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
mapHash,
|
|
37
|
-
abi.encodePacked(sender)
|
|
38
|
-
);
|
|
39
|
-
IERC725Y vault = IERC725Y(msg.sender);
|
|
40
|
-
bytes memory mapValue = vault.getDataSingle(mapKey);
|
|
33
|
+
bool isReceiving,
|
|
34
|
+
bytes32 arrayLengthKey,
|
|
35
|
+
bytes12 mapPrefix,
|
|
36
|
+
bytes4 interfaceID
|
|
37
|
+
) = LSP1Utils.getTransferDetails(typeId);
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
typeId == _TYPEID_LSP8_TOKENSRECIPIENT
|
|
45
|
-
) {
|
|
46
|
-
if (bytes12(mapValue) == bytes12(0)) {
|
|
47
|
-
(bytes32[] memory keys, bytes[] memory values) = ERC725Utils
|
|
48
|
-
.addMapAndArrayKey(
|
|
49
|
-
vault,
|
|
50
|
-
arrayKey,
|
|
51
|
-
mapKey,
|
|
52
|
-
sender,
|
|
53
|
-
interfaceId
|
|
54
|
-
);
|
|
39
|
+
bytes32 mapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(caller));
|
|
40
|
+
bytes memory mapValue = IERC725Y(msg.sender).getData(mapKey);
|
|
55
41
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
60
|
-
typeId == _TYPEID_LSP8_TOKENSSENDER
|
|
61
|
-
) {
|
|
62
|
-
if (bytes12(mapValue) != bytes12(0)) {
|
|
63
|
-
uint256 balance = ILSP7DigitalAsset(sender).balanceOf(
|
|
64
|
-
msg.sender
|
|
65
|
-
);
|
|
66
|
-
if ((balance - _tokenAmount(typeId, data)) == 0) {
|
|
67
|
-
(bytes32[] memory keys, bytes[] memory values) = ERC725Utils
|
|
68
|
-
.removeMapAndArrayKey(vault, arrayKey, mapHash, mapKey);
|
|
42
|
+
if (isReceiving) {
|
|
43
|
+
// if the map value is already set, then do nothing
|
|
44
|
+
if (bytes12(mapValue) != bytes12(0)) return "";
|
|
69
45
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
46
|
+
(bytes32[] memory keys, bytes[] memory values) = LSP5Utils.addMapAndArrayKey(
|
|
47
|
+
IERC725Y(msg.sender),
|
|
48
|
+
arrayLengthKey,
|
|
49
|
+
mapKey,
|
|
50
|
+
caller,
|
|
51
|
+
interfaceID
|
|
52
|
+
);
|
|
75
53
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
function _getTransferData(bytes32 _typeId)
|
|
79
|
-
private
|
|
80
|
-
pure
|
|
81
|
-
returns (
|
|
82
|
-
bytes32 arrayKey,
|
|
83
|
-
bytes32 mapHash,
|
|
84
|
-
bytes4 interfaceID
|
|
85
|
-
)
|
|
86
|
-
{
|
|
87
|
-
arrayKey = _ARRAYKEY_LSP5;
|
|
88
|
-
mapHash = _MAPHASH_LSP5;
|
|
89
|
-
if (
|
|
90
|
-
_typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
91
|
-
_typeId == _TYPEID_LSP7_TOKENSRECIPIENT
|
|
92
|
-
) {
|
|
93
|
-
interfaceID = _INTERFACEID_LSP7;
|
|
54
|
+
IERC725Y(msg.sender).setData(keys, values);
|
|
94
55
|
} else {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
56
|
+
// if there is no map value for the asset to remove, then do nothing
|
|
57
|
+
if (bytes12(mapValue) == bytes12(0)) return "";
|
|
98
58
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
59
|
+
// if the amount sent is not the full balance, then do not remove the keys
|
|
60
|
+
uint256 balance = ILSP7DigitalAsset(caller).balanceOf(msg.sender);
|
|
61
|
+
if (balance != 0) return "";
|
|
62
|
+
|
|
63
|
+
(bytes32[] memory keys, bytes[] memory values) = LSP5Utils.removeMapAndArrayKey(
|
|
64
|
+
IERC725Y(msg.sender),
|
|
65
|
+
arrayLengthKey,
|
|
66
|
+
mapPrefix,
|
|
67
|
+
mapKey,
|
|
68
|
+
mapValue
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
IERC725Y(msg.sender).setData(keys, values);
|
|
112
72
|
}
|
|
113
73
|
}
|
|
114
74
|
}
|
|
@@ -1,23 +1,57 @@
|
|
|
1
1
|
// SPDX-License-Identifier: CC0-1.0
|
|
2
2
|
pragma solidity ^0.8.0;
|
|
3
3
|
|
|
4
|
+
// interfaces
|
|
5
|
+
import {ILSP1UniversalReceiverDelegate} from "../ILSP1UniversalReceiverDelegate.sol";
|
|
6
|
+
|
|
4
7
|
// modules
|
|
5
|
-
import "
|
|
8
|
+
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
9
|
+
import {TokenHandling} from "./Handling/TokenHandling.sol";
|
|
10
|
+
|
|
11
|
+
// constants
|
|
12
|
+
import {_INTERFACEID_LSP1_DELEGATE} from "../LSP1Constants.sol";
|
|
13
|
+
import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "../../LSP7DigitalAsset/LSP7Constants.sol";
|
|
14
|
+
import {_TYPEID_LSP8_TOKENSSENDER, _TYPEID_LSP8_TOKENSRECIPIENT} from "../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
6
15
|
|
|
7
16
|
/**
|
|
8
|
-
* @title Implementation of contract writing the received LSP7 and LSP8 assets into your Vault using
|
|
17
|
+
* @title Core Implementation of contract writing the received LSP7 and LSP8 assets into your Vault using
|
|
9
18
|
* the LSP5-ReceivedAsset standard and removing the sent assets.
|
|
10
19
|
*
|
|
11
20
|
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
12
21
|
* @dev Delegate contract of the initial universal receiver
|
|
13
22
|
*/
|
|
14
23
|
contract LSP1UniversalReceiverDelegateVault is
|
|
15
|
-
|
|
24
|
+
ERC165,
|
|
25
|
+
ILSP1UniversalReceiverDelegate,
|
|
26
|
+
TokenHandling
|
|
16
27
|
{
|
|
17
28
|
/**
|
|
18
|
-
* @
|
|
29
|
+
* @inheritdoc ILSP1UniversalReceiverDelegate
|
|
30
|
+
* @dev allows to register arrayKeys and Map of incoming assets and remove after being sent
|
|
31
|
+
* @return result The return value
|
|
32
|
+
*/
|
|
33
|
+
function universalReceiverDelegate(
|
|
34
|
+
address sender,
|
|
35
|
+
uint256 value,
|
|
36
|
+
bytes32 typeId,
|
|
37
|
+
bytes memory data // solhint-disable no-unused-vars
|
|
38
|
+
) public virtual override returns (bytes memory result) {
|
|
39
|
+
if (
|
|
40
|
+
typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
41
|
+
typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
42
|
+
typeId == _TYPEID_LSP8_TOKENSSENDER ||
|
|
43
|
+
typeId == _TYPEID_LSP8_TOKENSRECIPIENT
|
|
44
|
+
) {
|
|
45
|
+
result = _tokenHandling(sender, typeId);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// --- Overrides
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @inheritdoc ERC165
|
|
19
53
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
54
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
|
55
|
+
return interfaceId == _INTERFACEID_LSP1_DELEGATE || super.supportsInterface(interfaceId);
|
|
22
56
|
}
|
|
23
57
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// constants
|
|
5
|
+
import {_LSP5_RECEIVED_ASSETS_ARRAY_KEY, _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX} from "../LSP5ReceivedAssets/LSP5Constants.sol";
|
|
6
|
+
import {_INTERFACEID_LSP7, _TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "../LSP7DigitalAsset/LSP7Constants.sol";
|
|
7
|
+
import {_INTERFACEID_LSP8, _TYPEID_LSP8_TOKENSRECIPIENT, _TYPEID_LSP8_TOKENSSENDER} from "../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
8
|
+
import {_INTERFACEID_LSP9, _TYPEID_LSP9_VAULTRECIPIENT} from "../LSP9Vault/LSP9Constants.sol";
|
|
9
|
+
import {_LSP10_VAULTS_ARRAY_KEY, _LSP10_VAULTS_MAP_KEY_PREFIX} from "../LSP10ReceivedVaults/LSP10Constants.sol";
|
|
10
|
+
|
|
11
|
+
library LSP1Utils {
|
|
12
|
+
/**
|
|
13
|
+
* @dev Gets all the transfer details depending on the `typeId`
|
|
14
|
+
*/
|
|
15
|
+
function getTransferDetails(bytes32 typeId)
|
|
16
|
+
internal
|
|
17
|
+
pure
|
|
18
|
+
returns (
|
|
19
|
+
bool isReceiving,
|
|
20
|
+
bytes32 arrayKey,
|
|
21
|
+
bytes12 mapPrefix,
|
|
22
|
+
bytes4 interfaceId
|
|
23
|
+
)
|
|
24
|
+
{
|
|
25
|
+
if (
|
|
26
|
+
typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
27
|
+
typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
28
|
+
typeId == _TYPEID_LSP8_TOKENSRECIPIENT ||
|
|
29
|
+
typeId == _TYPEID_LSP8_TOKENSSENDER
|
|
30
|
+
) {
|
|
31
|
+
arrayKey = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
|
|
32
|
+
mapPrefix = _LSP5_RECEIVED_ASSETS_MAP_KEY_PREFIX;
|
|
33
|
+
interfaceId = typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
34
|
+
typeId == _TYPEID_LSP7_TOKENSRECIPIENT
|
|
35
|
+
? _INTERFACEID_LSP7
|
|
36
|
+
: _INTERFACEID_LSP8;
|
|
37
|
+
isReceiving = typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
38
|
+
typeId == _TYPEID_LSP8_TOKENSRECIPIENT
|
|
39
|
+
? true
|
|
40
|
+
: false;
|
|
41
|
+
} else {
|
|
42
|
+
arrayKey = _LSP10_VAULTS_ARRAY_KEY;
|
|
43
|
+
mapPrefix = _LSP10_VAULTS_MAP_KEY_PREFIX;
|
|
44
|
+
interfaceId = _INTERFACEID_LSP9;
|
|
45
|
+
isReceiving = typeId == _TYPEID_LSP9_VAULTRECIPIENT ? true : false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|