@lukso/lsp-smart-contracts 0.4.3
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 +18 -0
- package/LICENSE +201 -0
- package/README.md +75 -0
- package/artifacts/Create2Factory.json +107 -0
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +64 -0
- package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +66 -0
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +64 -0
- package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +66 -0
- package/artifacts/LSP6KeyManager.json +222 -0
- package/artifacts/LSP6KeyManagerInit.json +224 -0
- package/artifacts/LSP7CappedSupply.json +404 -0
- package/artifacts/LSP7CappedSupplyInit.json +481 -0
- package/artifacts/LSP7CompatibilityForERC20.json +495 -0
- package/artifacts/LSP7DigitalAsset.json +417 -0
- package/artifacts/LSP7DigitalAssetInit.json +455 -0
- package/artifacts/LSP7Mintable.json +445 -0
- package/artifacts/LSP7MintableInit.json +483 -0
- package/artifacts/LSP8CappedSupply.json +459 -0
- package/artifacts/LSP8CappedSupplyInit.json +508 -0
- package/artifacts/LSP8CompatibilityForERC721.json +711 -0
- package/artifacts/LSP8IdentifiableDigitalAsset.json +467 -0
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +482 -0
- package/artifacts/LSP8Mintable.json +495 -0
- package/artifacts/LSP8MintableInit.json +510 -0
- package/artifacts/UniversalProfile.json +373 -0
- package/artifacts/UniversalProfileInit.json +375 -0
- package/constants.ts +350 -0
- package/contracts/Factories/Create2Factory.sol +92 -0
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +14 -0
- package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +23 -0
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +119 -0
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +20 -0
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +33 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +37 -0
- package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +22 -0
- package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +17 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +189 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +26 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +52 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +26 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +28 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +114 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +23 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +41 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +23 -0
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +25 -0
- package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +23 -0
- package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +47 -0
- package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +19 -0
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +36 -0
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +30 -0
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +41 -0
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +52 -0
- package/contracts/LSP6KeyManager/LSP6Constants.sol +28 -0
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +21 -0
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +444 -0
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +19 -0
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +26 -0
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +186 -0
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +12 -0
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +35 -0
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +394 -0
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +29 -0
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +44 -0
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +17 -0
- package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +47 -0
- package/contracts/LSP7DigitalAsset/extensions/ILSP7Mintable.sol +32 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +45 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +55 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +24 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +50 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +76 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7Mintable.sol +41 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7MintableCore.sol +26 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInit.sol +26 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +47 -0
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +223 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +18 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +35 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +470 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +29 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +41 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +17 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +108 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Mintable.sol +32 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +53 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +56 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +24 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +55 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityConstants.sol +6 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +252 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Mintable.sol +36 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableCore.sol +29 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInit.sol +24 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +44 -0
- package/contracts/LSP9Vault/LSP9Constants.sol +12 -0
- package/contracts/LSP9Vault/LSP9Vault.sol +56 -0
- package/contracts/LSP9Vault/LSP9VaultCore.sol +174 -0
- package/contracts/LSP9Vault/LSP9VaultInit.sol +19 -0
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +60 -0
- package/contracts/UniversalProfile.sol +37 -0
- package/contracts/UniversalProfileCore.sol +56 -0
- package/contracts/UniversalProfileInit.sol +19 -0
- package/contracts/UniversalProfileInitAbstract.sol +48 -0
- package/contracts/Utils/ERC725Utils.sol +169 -0
- package/contracts/Utils/LSP2Utils.sol +127 -0
- package/contracts/Utils/LSP6Utils.sol +77 -0
- package/contracts/Utils/UtilsLib.sol +23 -0
- package/package.json +84 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title The interface for LSP1UniversalReceiver
|
|
6
|
+
* @dev LSP1UniversalReceiver allows to receive arbitrary messages and to be informed when assets are sent or received
|
|
7
|
+
*/
|
|
8
|
+
interface ILSP1UniversalReceiver {
|
|
9
|
+
/**
|
|
10
|
+
* @notice Emitted when the universalReceiver function is succesfully executed
|
|
11
|
+
* @param from The address calling the universalReceiver function
|
|
12
|
+
* @param typeId The hash of a specific standard or a hook
|
|
13
|
+
* @param returnedValue The return value of universalReceiver function
|
|
14
|
+
* @param receivedData The arbitrary data passed to universalReceiver function
|
|
15
|
+
*/
|
|
16
|
+
event UniversalReceiver(
|
|
17
|
+
address indexed from,
|
|
18
|
+
bytes32 indexed typeId,
|
|
19
|
+
bytes indexed returnedValue,
|
|
20
|
+
bytes receivedData
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param typeId The hash of a specific standard or a hook
|
|
25
|
+
* @param data The arbitrary data received with the call
|
|
26
|
+
* @dev Emits an event when it's succesfully executed
|
|
27
|
+
*
|
|
28
|
+
* Call the universalReceiverDelegate function in the UniversalReceiverDelegate (URD) contract, if the address of the URD
|
|
29
|
+
* was set as a value for the `_UniversalReceiverKey` in the account key/value value store of the same contract implementing
|
|
30
|
+
* the universalReceiver function and if the URD contract has the LSP1UniversalReceiverDelegate Interface Id registred using ERC165
|
|
31
|
+
*
|
|
32
|
+
* Emits a {UniversalReceiver} event
|
|
33
|
+
*/
|
|
34
|
+
function universalReceiver(bytes32 typeId, bytes calldata data)
|
|
35
|
+
external
|
|
36
|
+
returns (bytes memory);
|
|
37
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title The interface for LSP1UniversalReceiverDelegate
|
|
6
|
+
* @dev LSP1UniversalReceiverDelegate allows for an external universal receiver smart contract,
|
|
7
|
+
* that is the delegate of the initial universal receiver
|
|
8
|
+
*/
|
|
9
|
+
interface ILSP1UniversalReceiverDelegate {
|
|
10
|
+
/**
|
|
11
|
+
* @dev Get called by the universalReceiver function, can be customized to have a specific logic
|
|
12
|
+
* @param sender The address calling the universalReceiver function
|
|
13
|
+
* @param typeId The hash of a specific standard or a hook
|
|
14
|
+
* @param data The arbitrary data received with the call
|
|
15
|
+
* @return result Any useful data could be returned
|
|
16
|
+
*/
|
|
17
|
+
function universalReceiverDelegate(
|
|
18
|
+
address sender,
|
|
19
|
+
bytes32 typeId,
|
|
20
|
+
bytes memory data
|
|
21
|
+
) external returns (bytes memory result);
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// --- ERC165 interface ids
|
|
5
|
+
bytes4 constant _INTERFACEID_LSP1 = 0x6bb56a14;
|
|
6
|
+
bytes4 constant _INTERFACEID_LSP1_DELEGATE = 0xc2d7bcc1;
|
|
7
|
+
|
|
8
|
+
// --- ERC725Y Keys
|
|
9
|
+
bytes32 constant _LSP1_UNIVERSAL_RECEIVER_DELEGATE_KEY = 0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47; // keccak256("LSP1UniversalReceiverDelegate")
|
|
10
|
+
|
|
11
|
+
bytes32 constant _ARRAYKEY_LSP5 = 0x6460ee3c0aac563ccbf76d6e1d07bada78e3a9514e6382b736ed3f478ab7b90b; // keccak256("LSP5ReceivedAssets[]")
|
|
12
|
+
|
|
13
|
+
bytes32 constant _MAPHASH_LSP5 = 0x812c4334633eb816c80deebfa5fb7d2509eb438ca1b6418106442cb5ccc62f6c; // keccak256("LSP5ReceivedAssetsMap")
|
|
14
|
+
|
|
15
|
+
bytes32 constant _ARRAYKEY_LSP10 = 0x55482936e01da86729a45d2b87a6b1d3bc582bea0ec00e38bdb340e3af6f9f06; // keccak256("LSP10Vaults[]")
|
|
16
|
+
|
|
17
|
+
bytes32 constant _MAPHASH_LSP10 = 0x192448c3c0f88c7f238c7f70449c270032f9752568e88cc8936ce3a2cb18e3ec; // keccak256("LSP10VaultsMap")
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
|
+
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
7
|
+
|
|
8
|
+
// interfaces
|
|
9
|
+
import "../../../LSP6KeyManager/ILSP6KeyManager.sol";
|
|
10
|
+
import "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
|
|
11
|
+
|
|
12
|
+
// libraries
|
|
13
|
+
import "../../../Utils/ERC725Utils.sol";
|
|
14
|
+
|
|
15
|
+
// constants
|
|
16
|
+
import "../../LSP1Constants.sol";
|
|
17
|
+
import "../../../LSP6KeyManager/LSP6Constants.sol";
|
|
18
|
+
import "../../../LSP7DigitalAsset/LSP7Constants.sol";
|
|
19
|
+
import "../../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
20
|
+
import "../../../LSP9Vault/LSP9Constants.sol";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @dev Function logic to add and remove the MapAndArrayKey of incoming assets and vaults
|
|
24
|
+
*/
|
|
25
|
+
abstract contract TokenAndVaultHandlingContract {
|
|
26
|
+
using ERC725Utils for IERC725Y;
|
|
27
|
+
|
|
28
|
+
function _tokenAndVaultHandling(
|
|
29
|
+
address sender,
|
|
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);
|
|
50
|
+
|
|
51
|
+
if (
|
|
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
|
+
);
|
|
65
|
+
|
|
66
|
+
result = _executeViaKeyManager(
|
|
67
|
+
ILSP6KeyManager(keyManagerAddress),
|
|
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
|
+
);
|
|
88
|
+
|
|
89
|
+
result = _executeViaKeyManager(
|
|
90
|
+
ILSP6KeyManager(keyManagerAddress),
|
|
91
|
+
keys,
|
|
92
|
+
values
|
|
93
|
+
);
|
|
94
|
+
} else if (
|
|
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
|
+
);
|
|
111
|
+
|
|
112
|
+
result = _executeViaKeyManager(
|
|
113
|
+
ILSP6KeyManager(keyManagerAddress),
|
|
114
|
+
keys,
|
|
115
|
+
values
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// helper functions
|
|
125
|
+
|
|
126
|
+
function _getTransferData(bytes32 _typeId)
|
|
127
|
+
private
|
|
128
|
+
pure
|
|
129
|
+
returns (
|
|
130
|
+
bytes32 _arrayKey,
|
|
131
|
+
bytes32 _mapHash,
|
|
132
|
+
bytes4 _interfaceID
|
|
133
|
+
)
|
|
134
|
+
{
|
|
135
|
+
if (
|
|
136
|
+
_typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
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
|
+
}
|
|
173
|
+
|
|
174
|
+
function _tokenAmount(bytes32 _typeId, bytes memory _data)
|
|
175
|
+
private
|
|
176
|
+
pure
|
|
177
|
+
returns (uint256 amount)
|
|
178
|
+
{
|
|
179
|
+
if (_typeId == _TYPEID_LSP7_TOKENSSENDER) {
|
|
180
|
+
/* solhint-disable */
|
|
181
|
+
assembly {
|
|
182
|
+
amount := mload(add(add(_data, 0x20), 0x28))
|
|
183
|
+
}
|
|
184
|
+
/* solhint-enable */
|
|
185
|
+
} else {
|
|
186
|
+
amount = 1;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import "./LSP1UniversalReceiverDelegateUPCore.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
|
|
9
|
+
* the LSP5-ReceivedAsset and LSP10-ReceivedVaults standard and removing the sent vaults and assets.
|
|
10
|
+
*
|
|
11
|
+
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
12
|
+
* @dev Delegate contract of the initial universal receiver
|
|
13
|
+
*
|
|
14
|
+
* Owner of the UniversalProfile MUST be a KeyManager that allows (this) address to setData on the UniversalProfile
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
contract LSP1UniversalReceiverDelegateUP is
|
|
18
|
+
LSP1UniversalReceiverDelegateUPCore
|
|
19
|
+
{
|
|
20
|
+
/**
|
|
21
|
+
* @notice Register the LSP1UniversalReceiverDelegate InterfaceId
|
|
22
|
+
*/
|
|
23
|
+
constructor() {
|
|
24
|
+
_registerInterface(_INTERFACEID_LSP1_DELEGATE);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "./Handling/TokenAndVaultHandling.sol";
|
|
5
|
+
|
|
6
|
+
import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
|
|
7
|
+
|
|
8
|
+
import "../ILSP1UniversalReceiverDelegate.sol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @title Core Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
|
|
12
|
+
* the LSP5-ReceivedAsset and LSP10-ReceivedVaults standard and removing the sent vaults and assets.
|
|
13
|
+
*
|
|
14
|
+
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
15
|
+
* @dev Delegate contract of the initial universal receiver
|
|
16
|
+
*
|
|
17
|
+
* Owner of the UniversalProfile MUST be a KeyManager that allows (this) address to setData on the UniversalProfile
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
abstract contract LSP1UniversalReceiverDelegateUPCore is
|
|
21
|
+
ILSP1UniversalReceiverDelegate,
|
|
22
|
+
ERC165Storage,
|
|
23
|
+
TokenAndVaultHandlingContract
|
|
24
|
+
{
|
|
25
|
+
/**
|
|
26
|
+
* @inheritdoc ILSP1UniversalReceiverDelegate
|
|
27
|
+
* @dev Allows to register arrayKeys and Map of incoming vaults and assets and removing them after being sent
|
|
28
|
+
* @return result the return value of keyManager's execute function
|
|
29
|
+
*/
|
|
30
|
+
function universalReceiverDelegate(
|
|
31
|
+
address sender,
|
|
32
|
+
bytes32 typeId,
|
|
33
|
+
bytes memory data
|
|
34
|
+
) public override returns (bytes memory result) {
|
|
35
|
+
if (
|
|
36
|
+
typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
37
|
+
typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
38
|
+
typeId == _TYPEID_LSP8_TOKENSSENDER ||
|
|
39
|
+
typeId == _TYPEID_LSP8_TOKENSRECIPIENT ||
|
|
40
|
+
typeId == _TYPEID_LSP9_VAULTSENDER ||
|
|
41
|
+
typeId == _TYPEID_LSP9_VAULTRECIPIENT
|
|
42
|
+
) {
|
|
43
|
+
result = _tokenAndVaultHandling(sender, typeId, data);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* @TODO
|
|
47
|
+
else if() {
|
|
48
|
+
result = FollowerHandling(sender, typeId, data);
|
|
49
|
+
}
|
|
50
|
+
*/
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import "./LSP1UniversalReceiverDelegateUPInitAbstract.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title Deployable Proxy Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
|
|
9
|
+
* the LSP5-ReceivedAsset and LSP10-ReceivedVaults standard and removing the sent vaults and assets.
|
|
10
|
+
*
|
|
11
|
+
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
12
|
+
* @dev Delegate contract of the initial universal receiver
|
|
13
|
+
*
|
|
14
|
+
* Owner of the UniversalProfile MUST be a KeyManager that allows (this) address to setData on the UniversalProfile
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
contract LSP1UniversalReceiverDelegateUPInit is
|
|
18
|
+
LSP1UniversalReceiverDelegateUPInitAbstract
|
|
19
|
+
{
|
|
20
|
+
/**
|
|
21
|
+
* @inheritdoc LSP1UniversalReceiverDelegateUPInitAbstract
|
|
22
|
+
*/
|
|
23
|
+
function initialize() public virtual override initializer {
|
|
24
|
+
LSP1UniversalReceiverDelegateUPInitAbstract.initialize();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import "./LSP1UniversalReceiverDelegateUPCore.sol";
|
|
6
|
+
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title Inheritable Proxy Implementation of contract writing the received Vaults and LSP7, LSP8 assets into your ERC725Account using
|
|
10
|
+
* the LSP5-ReceivedAsset and LSP10-ReceivedVaults standard and removing the sent vaults and assets.
|
|
11
|
+
*
|
|
12
|
+
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
13
|
+
* @dev Delegate contract of the initial universal receiver
|
|
14
|
+
*
|
|
15
|
+
* Owner of the UniversalProfile MUST be a KeyManager that allows (this) address to setData on the UniversalProfile
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
abstract contract LSP1UniversalReceiverDelegateUPInitAbstract is
|
|
19
|
+
Initializable,
|
|
20
|
+
LSP1UniversalReceiverDelegateUPCore
|
|
21
|
+
{
|
|
22
|
+
/**
|
|
23
|
+
* @notice Register the LSP1UniversalReceiverDelegate InterfaceId
|
|
24
|
+
*/
|
|
25
|
+
function initialize() public virtual onlyInitializing {
|
|
26
|
+
_registerInterface(_INTERFACEID_LSP1_DELEGATE);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
6
|
+
|
|
7
|
+
// interfaces
|
|
8
|
+
import "../../../LSP7DigitalAsset/ILSP7DigitalAsset.sol";
|
|
9
|
+
|
|
10
|
+
// libraries
|
|
11
|
+
import "../../../Utils/ERC725Utils.sol";
|
|
12
|
+
|
|
13
|
+
// constants
|
|
14
|
+
import "../../LSP1Constants.sol";
|
|
15
|
+
import "../../../LSP7DigitalAsset/LSP7Constants.sol";
|
|
16
|
+
import "../../../LSP8IdentifiableDigitalAsset/LSP8Constants.sol";
|
|
17
|
+
import "../../../LSP9Vault/LSP9Constants.sol";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @dev Function logic to add and remove the MapAndArrayKey of incoming assets
|
|
21
|
+
*/
|
|
22
|
+
abstract contract TokenHandlingContract {
|
|
23
|
+
using ERC725Utils for IERC725Y;
|
|
24
|
+
|
|
25
|
+
function _tokenHandling(
|
|
26
|
+
address sender,
|
|
27
|
+
bytes32 typeId,
|
|
28
|
+
bytes memory data
|
|
29
|
+
) internal returns (bytes memory) {
|
|
30
|
+
(
|
|
31
|
+
bytes32 arrayKey,
|
|
32
|
+
bytes32 mapHash,
|
|
33
|
+
bytes4 interfaceId
|
|
34
|
+
) = _getTransferData(typeId);
|
|
35
|
+
bytes32 mapKey = ERC725Utils.generateMapKey(
|
|
36
|
+
mapHash,
|
|
37
|
+
abi.encodePacked(sender)
|
|
38
|
+
);
|
|
39
|
+
IERC725Y vault = IERC725Y(msg.sender);
|
|
40
|
+
bytes memory mapValue = vault.getDataSingle(mapKey);
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
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
|
+
);
|
|
55
|
+
|
|
56
|
+
vault.setData(keys, values);
|
|
57
|
+
}
|
|
58
|
+
} else if (
|
|
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);
|
|
69
|
+
|
|
70
|
+
vault.setData(keys, values);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// helper functions
|
|
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;
|
|
94
|
+
} else {
|
|
95
|
+
interfaceID = _INTERFACEID_LSP8;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function _tokenAmount(bytes32 _typeId, bytes memory _data)
|
|
100
|
+
private
|
|
101
|
+
pure
|
|
102
|
+
returns (uint256 amount)
|
|
103
|
+
{
|
|
104
|
+
if (_typeId == _TYPEID_LSP7_TOKENSSENDER) {
|
|
105
|
+
/* solhint-disable */
|
|
106
|
+
assembly {
|
|
107
|
+
amount := mload(add(add(_data, 0x20), 0x28))
|
|
108
|
+
}
|
|
109
|
+
/* solhint-enable */
|
|
110
|
+
} else {
|
|
111
|
+
amount = 1;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import "./LSP1UniversalReceiverDelegateVaultCore.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title Implementation of contract writing the received LSP7 and LSP8 assets into your Vault using
|
|
9
|
+
* the LSP5-ReceivedAsset standard and removing the sent assets.
|
|
10
|
+
*
|
|
11
|
+
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
12
|
+
* @dev Delegate contract of the initial universal receiver
|
|
13
|
+
*/
|
|
14
|
+
contract LSP1UniversalReceiverDelegateVault is
|
|
15
|
+
LSP1UniversalReceiverDelegateVaultCore
|
|
16
|
+
{
|
|
17
|
+
/**
|
|
18
|
+
* @notice Register the LSP1UniversalReceiverDelegate InterfaceId
|
|
19
|
+
*/
|
|
20
|
+
constructor() {
|
|
21
|
+
_registerInterface(_INTERFACEID_LSP1_DELEGATE);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "./Handling/TokenHandling.sol";
|
|
5
|
+
|
|
6
|
+
import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
|
|
7
|
+
|
|
8
|
+
import "../ILSP1UniversalReceiverDelegate.sol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @title Core Implementation of contract writing the received LSP7 and LSP8 assets into your Vault using
|
|
12
|
+
* the LSP5-ReceivedAsset standard and removing the sent assets.
|
|
13
|
+
*
|
|
14
|
+
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
15
|
+
* @dev Delegate contract of the initial universal receiver
|
|
16
|
+
*/
|
|
17
|
+
abstract contract LSP1UniversalReceiverDelegateVaultCore is
|
|
18
|
+
ILSP1UniversalReceiverDelegate,
|
|
19
|
+
ERC165Storage,
|
|
20
|
+
TokenHandlingContract
|
|
21
|
+
{
|
|
22
|
+
/**
|
|
23
|
+
* @inheritdoc ILSP1UniversalReceiverDelegate
|
|
24
|
+
* @dev allows to register arrayKeys and Map of incoming assets and remove after being sent
|
|
25
|
+
* @return result The return value
|
|
26
|
+
*/
|
|
27
|
+
function universalReceiverDelegate(
|
|
28
|
+
address sender,
|
|
29
|
+
bytes32 typeId,
|
|
30
|
+
bytes memory data
|
|
31
|
+
) public override returns (bytes memory result) {
|
|
32
|
+
if (
|
|
33
|
+
typeId == _TYPEID_LSP7_TOKENSSENDER ||
|
|
34
|
+
typeId == _TYPEID_LSP7_TOKENSRECIPIENT ||
|
|
35
|
+
typeId == _TYPEID_LSP8_TOKENSSENDER ||
|
|
36
|
+
typeId == _TYPEID_LSP8_TOKENSRECIPIENT
|
|
37
|
+
) {
|
|
38
|
+
result = _tokenHandling(sender, typeId, data);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import "./LSP1UniversalReceiverDelegateVaultInitAbstract.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @title Deployable Proxy Implementation of contract writing the received LSP7 and LSP8 assets into your Vault using
|
|
9
|
+
* the LSP5-ReceivedAsset standard and removing the sent assets.
|
|
10
|
+
*
|
|
11
|
+
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
12
|
+
* @dev Delegate contract of the initial universal receiver
|
|
13
|
+
*/
|
|
14
|
+
contract LSP1UniversalReceiverDelegateVaultInit is
|
|
15
|
+
LSP1UniversalReceiverDelegateVaultInitAbstract
|
|
16
|
+
{
|
|
17
|
+
/**
|
|
18
|
+
* @inheritdoc LSP1UniversalReceiverDelegateVaultInitAbstract
|
|
19
|
+
*/
|
|
20
|
+
function initialize() public virtual override initializer {
|
|
21
|
+
LSP1UniversalReceiverDelegateVaultInitAbstract.initialize();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-License-Identifier: CC0-1.0
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
// modules
|
|
5
|
+
import "./LSP1UniversalReceiverDelegateVaultCore.sol";
|
|
6
|
+
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title Inheritable Proxy Implementation of contract writing the received LSP7 and LSP8 assets into your Vault using
|
|
10
|
+
* the LSP5-ReceivedAsset standard and removing the sent assets.
|
|
11
|
+
*
|
|
12
|
+
* @author Fabian Vogelsteller, Yamen Merhi, Jean Cavallera
|
|
13
|
+
* @dev Delegate contract of the initial universal receiver
|
|
14
|
+
*/
|
|
15
|
+
abstract contract LSP1UniversalReceiverDelegateVaultInitAbstract is
|
|
16
|
+
Initializable,
|
|
17
|
+
LSP1UniversalReceiverDelegateVaultCore
|
|
18
|
+
{
|
|
19
|
+
/**
|
|
20
|
+
* @notice Register the LSP1UniversalReceiverDelegate InterfaceId
|
|
21
|
+
*/
|
|
22
|
+
function initialize() public virtual onlyInitializing {
|
|
23
|
+
_registerInterface(_INTERFACEID_LSP1_DELEGATE);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.0;
|
|
4
|
+
|
|
5
|
+
// interfaces
|
|
6
|
+
import "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @dev LSP4 extension, for compatibility with clients & tools that expect ERC20/721.
|
|
10
|
+
*/
|
|
11
|
+
interface ILSP4Compatibility is IERC725Y {
|
|
12
|
+
/**
|
|
13
|
+
* @dev Returns the name of the token.
|
|
14
|
+
* @return The name of the token
|
|
15
|
+
*/
|
|
16
|
+
function name() external view returns (string memory);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @dev Returns the symbol of the token, usually a shorter version of the name.
|
|
20
|
+
* @return The symbol of the token
|
|
21
|
+
*/
|
|
22
|
+
function symbol() external view returns (string memory);
|
|
23
|
+
}
|