@lukso/lsp-smart-contracts 0.8.0 → 0.9.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 +8 -0
- package/README.md +34 -21
- package/artifacts/LSP0ERC725Account.json +51 -5
- package/artifacts/LSP0ERC725AccountInit.json +51 -5
- package/artifacts/LSP11BasicSocialRecovery.json +2 -2
- package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
- package/artifacts/LSP16UniversalFactory.json +31 -2
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +19 -35
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +13 -13
- package/artifacts/LSP4Compatibility.json +7 -2
- package/artifacts/LSP4DigitalAssetMetadata.json +7 -2
- package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +7 -2
- package/artifacts/LSP6KeyManager.json +91 -6
- package/artifacts/LSP6KeyManagerInit.json +103 -18
- package/artifacts/LSP7CappedSupply.json +12 -2
- package/artifacts/LSP7CappedSupplyInitAbstract.json +12 -2
- package/artifacts/LSP7CompatibleERC20.json +12 -2
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +12 -2
- package/artifacts/LSP7CompatibleERC20Mintable.json +14 -4
- package/artifacts/LSP7CompatibleERC20MintableInit.json +14 -4
- package/artifacts/LSP7DigitalAsset.json +12 -2
- package/artifacts/LSP7DigitalAssetInitAbstract.json +12 -2
- package/artifacts/LSP7Mintable.json +14 -4
- package/artifacts/LSP7MintableInit.json +14 -4
- package/artifacts/LSP8CappedSupply.json +12 -2
- package/artifacts/LSP8CappedSupplyInitAbstract.json +12 -2
- package/artifacts/LSP8CompatibleERC721.json +12 -2
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +12 -2
- package/artifacts/LSP8CompatibleERC721Mintable.json +14 -4
- package/artifacts/LSP8CompatibleERC721MintableInit.json +14 -4
- package/artifacts/LSP8IdentifiableDigitalAsset.json +12 -2
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +12 -2
- package/artifacts/LSP8Mintable.json +14 -4
- package/artifacts/LSP8MintableInit.json +14 -4
- package/artifacts/LSP9Vault.json +29 -5
- package/artifacts/LSP9VaultInit.json +29 -5
- package/artifacts/UniversalProfile.json +51 -5
- package/artifacts/UniversalProfileInit.json +51 -5
- package/common/constants.d.ts +461 -0
- package/common/constants.js +789 -0
- package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +27 -0
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +353 -145
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0Utils.sol +50 -0
- package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +48 -54
- package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +5 -6
- package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +27 -4
- package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +36 -77
- package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +8 -8
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +50 -57
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +18 -8
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +12 -0
- package/contracts/LSP20CallVerification/ILSP20CallVerification.sol +30 -0
- package/contracts/LSP20CallVerification/LSP20CallVerification.sol +74 -0
- package/contracts/LSP20CallVerification/LSP20Errors.sol +15 -0
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +7 -7
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +50 -56
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6Constants.sol +8 -2
- package/contracts/LSP6KeyManager/LSP6Errors.sol +18 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +126 -745
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +407 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6OwnershipModule.sol +25 -0
- package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +633 -0
- package/contracts/LSP6KeyManager/LSP6Utils.sol +60 -15
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +14 -23
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +5 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +19 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +1 -3
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +1 -3
- package/contracts/LSP9Vault/ILSP9Vault.sol +19 -0
- package/contracts/LSP9Vault/LSP9Constants.sol +1 -1
- package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
- package/contracts/LSP9Vault/LSP9VaultCore.sol +166 -83
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
- package/module/constants.d.ts +461 -0
- package/module/constants.js +786 -0
- package/package.json +30 -6
- package/constants.js +0 -856
|
@@ -12,7 +12,6 @@ import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
|
12
12
|
import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
13
13
|
|
|
14
14
|
// libraries
|
|
15
|
-
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
16
15
|
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
17
16
|
import {LSP1Utils} from "../LSP1Utils.sol";
|
|
18
17
|
import {LSP2Utils} from "../../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
@@ -43,7 +42,6 @@ import "../LSP1Errors.sol";
|
|
|
43
42
|
*/
|
|
44
43
|
contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
|
|
45
44
|
using ERC165Checker for address;
|
|
46
|
-
using Address for address;
|
|
47
45
|
|
|
48
46
|
/**
|
|
49
47
|
* @inheritdoc ILSP1UniversalReceiver
|
|
@@ -69,32 +67,27 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
|
|
|
69
67
|
// solhint-disable avoid-tx-origin
|
|
70
68
|
if (notifier == tx.origin) revert CannotRegisterEOAsAsAssets(notifier);
|
|
71
69
|
|
|
72
|
-
(address keyManager, bool ownerIsKeyManager) = _validateCallerViaKeyManager();
|
|
73
|
-
if (!ownerIsKeyManager) return "LSP1: account owner is not a LSP6KeyManager";
|
|
74
|
-
|
|
75
70
|
// if the contract being transferred doesn't support LSP9, do not register it as a received vault
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
if (
|
|
72
|
+
mapPrefix == _LSP10_VAULTS_MAP_KEY_PREFIX &&
|
|
73
|
+
notifier.code.length > 0 &&
|
|
74
|
+
!notifier.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP9)
|
|
75
|
+
) {
|
|
76
|
+
return "LSP1: not an LSP9Vault ownership transfer";
|
|
81
77
|
}
|
|
82
78
|
|
|
83
79
|
bytes32 notifierMapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(notifier));
|
|
84
80
|
bytes memory notifierMapValue = IERC725Y(msg.sender).getData(notifierMapKey);
|
|
81
|
+
bool isMapValueSet = bytes20(notifierMapValue) != bytes20(0);
|
|
85
82
|
|
|
86
83
|
if (isReceiving) {
|
|
87
|
-
|
|
88
|
-
if (bytes12(notifierMapValue) != bytes12(0))
|
|
89
|
-
return "LSP1: asset received is already registered";
|
|
84
|
+
if (isMapValueSet) return "LSP1: asset received is already registered";
|
|
90
85
|
|
|
91
|
-
|
|
86
|
+
return _whenReceiving(typeId, notifier, notifierMapKey, interfaceID);
|
|
92
87
|
} else {
|
|
93
|
-
|
|
94
|
-
if (bytes12(notifierMapValue) == bytes12(0))
|
|
95
|
-
return "LSP1: asset sent is not registered";
|
|
88
|
+
if (!isMapValueSet) return "LSP1: asset sent is not registered";
|
|
96
89
|
|
|
97
|
-
|
|
90
|
+
return _whenSending(typeId, notifier, notifierMapKey, notifierMapValue);
|
|
98
91
|
}
|
|
99
92
|
}
|
|
100
93
|
|
|
@@ -108,25 +101,36 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
|
|
|
108
101
|
function _whenReceiving(
|
|
109
102
|
bytes32 typeId,
|
|
110
103
|
address notifier,
|
|
111
|
-
address keyManager,
|
|
112
104
|
bytes32 notifierMapKey,
|
|
113
105
|
bytes4 interfaceID
|
|
114
|
-
) internal virtual returns (bytes memory
|
|
106
|
+
) internal virtual returns (bytes memory) {
|
|
107
|
+
bytes32[] memory dataKeys;
|
|
108
|
+
bytes[] memory dataValues;
|
|
109
|
+
|
|
115
110
|
// if it's a token transfer (LSP7/LSP8)
|
|
116
111
|
if (typeId != _TYPEID_LSP9_OwnershipTransferred_RecipientNotification) {
|
|
117
112
|
// if the amount sent is 0, then do not update the keys
|
|
118
113
|
uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
|
|
119
114
|
if (balance == 0) return "LSP1: balance not updated";
|
|
120
115
|
|
|
121
|
-
(
|
|
122
|
-
|
|
116
|
+
(dataKeys, dataValues) = LSP5Utils.generateReceivedAssetKeys(
|
|
117
|
+
msg.sender,
|
|
118
|
+
notifier,
|
|
119
|
+
notifierMapKey,
|
|
120
|
+
interfaceID
|
|
121
|
+
);
|
|
123
122
|
|
|
124
|
-
|
|
123
|
+
IERC725Y(msg.sender).setData(dataKeys, dataValues);
|
|
124
|
+
return "";
|
|
125
125
|
} else {
|
|
126
|
-
(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
(dataKeys, dataValues) = LSP10Utils.generateReceivedVaultKeys(
|
|
127
|
+
msg.sender,
|
|
128
|
+
notifier,
|
|
129
|
+
notifierMapKey
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
IERC725Y(msg.sender).setData(dataKeys, dataValues);
|
|
133
|
+
return "";
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
|
|
@@ -138,46 +142,35 @@ contract LSP1UniversalReceiverDelegateUP is ERC165, ILSP1UniversalReceiver {
|
|
|
138
142
|
function _whenSending(
|
|
139
143
|
bytes32 typeId,
|
|
140
144
|
address notifier,
|
|
141
|
-
address keyManager,
|
|
142
145
|
bytes32 notifierMapKey,
|
|
143
146
|
bytes memory notifierMapValue
|
|
144
|
-
) internal virtual returns (bytes memory
|
|
147
|
+
) internal virtual returns (bytes memory) {
|
|
148
|
+
bytes32[] memory dataKeys;
|
|
149
|
+
bytes[] memory dataValues;
|
|
150
|
+
|
|
145
151
|
// if it's a token transfer (LSP7/LSP8)
|
|
146
152
|
if (typeId != _TYPEID_LSP9_OwnershipTransferred_SenderNotification) {
|
|
147
153
|
// if the amount sent is not the full balance, then do not update the keys
|
|
148
154
|
uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
|
|
149
155
|
if (balance != 0) return "LSP1: full balance is not sent";
|
|
150
156
|
|
|
151
|
-
(
|
|
152
|
-
|
|
157
|
+
(dataKeys, dataValues) = LSP5Utils.generateSentAssetKeys(
|
|
158
|
+
msg.sender,
|
|
159
|
+
notifierMapKey,
|
|
160
|
+
notifierMapValue
|
|
161
|
+
);
|
|
153
162
|
|
|
154
|
-
|
|
163
|
+
IERC725Y(msg.sender).setData(dataKeys, dataValues);
|
|
164
|
+
return "";
|
|
155
165
|
} else {
|
|
156
|
-
(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
* @dev Check if the caller is owned by an LSP6KeyManager and linked to
|
|
165
|
-
* the owner returned
|
|
166
|
-
*/
|
|
167
|
-
function _validateCallerViaKeyManager()
|
|
168
|
-
internal
|
|
169
|
-
view
|
|
170
|
-
virtual
|
|
171
|
-
returns (address accountOwner, bool ownerIsKeyManager)
|
|
172
|
-
{
|
|
173
|
-
accountOwner = ERC725Y(msg.sender).owner();
|
|
174
|
-
if (accountOwner.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP6))
|
|
175
|
-
ownerIsKeyManager = true;
|
|
176
|
-
|
|
177
|
-
if (ownerIsKeyManager) {
|
|
178
|
-
address target = ILSP6KeyManager(accountOwner).target();
|
|
179
|
-
// check if the caller is the same account controlled by the keyManager
|
|
180
|
-
if (target != msg.sender) revert CallerNotLSP6LinkedTarget(msg.sender, target);
|
|
166
|
+
(dataKeys, dataValues) = LSP10Utils.generateSentVaultKeys(
|
|
167
|
+
msg.sender,
|
|
168
|
+
notifierMapKey,
|
|
169
|
+
notifierMapValue
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
IERC725Y(msg.sender).setData(dataKeys, dataValues);
|
|
173
|
+
return "";
|
|
181
174
|
}
|
|
182
175
|
}
|
|
183
176
|
|
|
@@ -57,31 +57,41 @@ contract LSP1UniversalReceiverDelegateVault is ERC165, ILSP1UniversalReceiver {
|
|
|
57
57
|
bytes32 notifierMapKey = LSP2Utils.generateMappingKey(mapPrefix, bytes20(notifier));
|
|
58
58
|
bytes memory notifierMapValue = IERC725Y(msg.sender).getData(notifierMapKey);
|
|
59
59
|
|
|
60
|
+
bytes32[] memory dataKeys;
|
|
61
|
+
bytes[] memory dataValues;
|
|
62
|
+
|
|
60
63
|
if (isReceiving) {
|
|
61
64
|
// if the map value is already set, then do nothing
|
|
62
|
-
if (
|
|
65
|
+
if (bytes20(notifierMapValue) != bytes20(0))
|
|
63
66
|
return "URD: asset received is already registered";
|
|
64
67
|
|
|
65
68
|
// if the amount sent is 0, then do not update the keys
|
|
66
69
|
uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
|
|
67
70
|
if (balance == 0) return "LSP1: balance not updated";
|
|
68
71
|
|
|
69
|
-
(
|
|
70
|
-
|
|
72
|
+
(dataKeys, dataValues) = LSP5Utils.generateReceivedAssetKeys(
|
|
73
|
+
msg.sender,
|
|
74
|
+
notifier,
|
|
75
|
+
notifierMapKey,
|
|
76
|
+
interfaceID
|
|
77
|
+
);
|
|
71
78
|
|
|
72
|
-
IERC725Y(msg.sender).setData(
|
|
79
|
+
IERC725Y(msg.sender).setData(dataKeys, dataValues);
|
|
73
80
|
} else {
|
|
74
81
|
// if there is no map value for the asset to remove, then do nothing
|
|
75
|
-
if (
|
|
82
|
+
if (bytes20(notifierMapValue) == bytes20(0))
|
|
76
83
|
return "LSP1: asset sent is not registered";
|
|
77
84
|
// if it's a token transfer (LSP7/LSP8)
|
|
78
85
|
uint256 balance = ILSP7DigitalAsset(notifier).balanceOf(msg.sender);
|
|
79
86
|
if (balance != 0) return "LSP1: full balance is not sent";
|
|
80
87
|
|
|
81
|
-
(
|
|
82
|
-
|
|
88
|
+
(dataKeys, dataValues) = LSP5Utils.generateSentAssetKeys(
|
|
89
|
+
msg.sender,
|
|
90
|
+
notifierMapKey,
|
|
91
|
+
notifierMapValue
|
|
92
|
+
);
|
|
83
93
|
|
|
84
|
-
IERC725Y(msg.sender).setData(
|
|
94
|
+
IERC725Y(msg.sender).setData(dataKeys, dataValues);
|
|
85
95
|
}
|
|
86
96
|
}
|
|
87
97
|
|
|
@@ -3,9 +3,11 @@ pragma solidity ^0.8.4;
|
|
|
3
3
|
|
|
4
4
|
// libraries
|
|
5
5
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
6
|
+
import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
|
|
6
7
|
|
|
7
8
|
// constants
|
|
8
9
|
import "./ILSP1UniversalReceiver.sol";
|
|
10
|
+
import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
|
|
9
11
|
import "../LSP0ERC725Account/LSP0Constants.sol";
|
|
10
12
|
import "../LSP5ReceivedAssets/LSP5Constants.sol";
|
|
11
13
|
import "../LSP7DigitalAsset/LSP7Constants.sol";
|
|
@@ -15,6 +17,16 @@ import "../LSP14Ownable2Step/LSP14Constants.sol";
|
|
|
15
17
|
import "../LSP10ReceivedVaults/LSP10Constants.sol";
|
|
16
18
|
|
|
17
19
|
library LSP1Utils {
|
|
20
|
+
function tryNotifyUniversalReceiver(
|
|
21
|
+
address lsp1Implementation,
|
|
22
|
+
bytes32 typeId,
|
|
23
|
+
bytes memory data
|
|
24
|
+
) internal {
|
|
25
|
+
if (ERC165Checker.supportsERC165InterfaceUnchecked(lsp1Implementation, _INTERFACEID_LSP1)) {
|
|
26
|
+
ILSP1UniversalReceiver(lsp1Implementation).universalReceiver(typeId, data);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
function callUniversalReceiverWithCallerInfos(
|
|
19
31
|
address universalReceiverDelegate,
|
|
20
32
|
bytes32 typeId,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @dev Interface to be inherited for contract supporting LSP20-CallVerification
|
|
6
|
+
*/
|
|
7
|
+
interface ILSP20CallVerification {
|
|
8
|
+
/**
|
|
9
|
+
* @return magicValue MUST return the first 3 bytes of `lsp20VerifyCall(address,uint256,bytes)` function selector if the call to
|
|
10
|
+
* the function is allowed, concatened with a byte that determines if the lsp20VerifyCallResult function should
|
|
11
|
+
* be called after the original function call. The byte that invoke the lsp20VerifyCallResult function is strictly `0x01`.
|
|
12
|
+
*
|
|
13
|
+
* @param caller The address who called the function on the msg.sender
|
|
14
|
+
* @param value The value sent by the caller to the function called on the msg.sender
|
|
15
|
+
* @param receivedCalldata The receivedCalldata sent by the caller to the msg.sender
|
|
16
|
+
*/
|
|
17
|
+
function lsp20VerifyCall(
|
|
18
|
+
address caller,
|
|
19
|
+
uint256 value,
|
|
20
|
+
bytes memory receivedCalldata
|
|
21
|
+
) external returns (bytes4 magicValue);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @return MUST return the lsp20VerifyCallResult function selector if the call to the function is allowed
|
|
25
|
+
*
|
|
26
|
+
* @param callHash The keccak256 of the parameters of {lsp20VerifyCall} concatenated
|
|
27
|
+
* @param result The value result of the function called on the msg.sender
|
|
28
|
+
*/
|
|
29
|
+
function lsp20VerifyCallResult(bytes32 callHash, bytes memory result) external returns (bytes4);
|
|
30
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
// interfaces
|
|
5
|
+
|
|
6
|
+
import {ILSP20CallVerification as ILSP20} from "./ILSP20CallVerification.sol";
|
|
7
|
+
|
|
8
|
+
// errors
|
|
9
|
+
import "./LSP20Errors.sol";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @title Implementation of contract calling the verification functions according to LSP20CallVerification
|
|
13
|
+
* @dev Module to be inherited used to verify the execution of functions according to a verifier address.
|
|
14
|
+
* Verification can happen before or after execution based on a magicValue.
|
|
15
|
+
*/
|
|
16
|
+
abstract contract LSP20CallVerification {
|
|
17
|
+
/**
|
|
18
|
+
* @dev Calls {lsp20VerifyCall} function on the logicVerifier.
|
|
19
|
+
* Reverts in case the value returned does not match the magic value (lsp20VerifyCall selector)
|
|
20
|
+
* Returns whether a verification after the execution should happen based on the last byte of the magicValue
|
|
21
|
+
*/
|
|
22
|
+
function _verifyCall(address logicVerifier) internal virtual returns (bool verifyAfter) {
|
|
23
|
+
(bool success, bytes memory returnedData) = logicVerifier.call(
|
|
24
|
+
abi.encodeWithSelector(ILSP20.lsp20VerifyCall.selector, msg.sender, msg.value, msg.data)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (!success) _revert(false, returnedData);
|
|
28
|
+
|
|
29
|
+
if (returnedData.length < 32) revert LSP20InvalidMagicValue(false, returnedData);
|
|
30
|
+
|
|
31
|
+
bytes32 magicValue = abi.decode(returnedData, (bytes32));
|
|
32
|
+
|
|
33
|
+
if (bytes3(magicValue) != bytes3(ILSP20.lsp20VerifyCall.selector))
|
|
34
|
+
revert LSP20InvalidMagicValue(false, returnedData);
|
|
35
|
+
|
|
36
|
+
return bytes1(magicValue[3]) == 0x01 ? true : false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @dev Calls {lsp20VerifyCallResult} function on the logicVerifier.
|
|
41
|
+
* Reverts in case the value returned does not match the magic value (lsp20VerifyCallResult selector)
|
|
42
|
+
*/
|
|
43
|
+
function _verifyCallResult(address logicVerifier, bytes memory callResult) internal virtual {
|
|
44
|
+
(bool success, bytes memory returnedData) = logicVerifier.call(
|
|
45
|
+
abi.encodeWithSelector(
|
|
46
|
+
ILSP20.lsp20VerifyCallResult.selector,
|
|
47
|
+
keccak256(abi.encodePacked(msg.sender, msg.value, msg.data)),
|
|
48
|
+
callResult
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (!success) _revert(true, returnedData);
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
returnedData.length < 32 ||
|
|
56
|
+
bytes4(abi.decode(returnedData, (bytes32))) != ILSP20.lsp20VerifyCallResult.selector
|
|
57
|
+
) revert LSP20InvalidMagicValue(true, returnedData);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function _revert(bool postCall, bytes memory returnedData) internal pure {
|
|
61
|
+
// Look for revert reason and bubble it up if present
|
|
62
|
+
if (returnedData.length > 0) {
|
|
63
|
+
// The easiest way to bubble the revert reason is using memory via assembly
|
|
64
|
+
// solhint-disable no-inline-assembly
|
|
65
|
+
/// @solidity memory-safe-assembly
|
|
66
|
+
assembly {
|
|
67
|
+
let returndata_size := mload(returnedData)
|
|
68
|
+
revert(add(32, returnedData), returndata_size)
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
revert LSP20CallingVerifierFailed(postCall);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.4;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @dev reverts when the call to the owner fail with no revert reason
|
|
6
|
+
* @param postCall True if the execution call was done, False otherwise
|
|
7
|
+
*/
|
|
8
|
+
error LSP20CallingVerifierFailed(bool postCall);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @dev reverts when the call to the owner does not return the magic value
|
|
12
|
+
* @param postCall True if the execution call was done, False otherwise
|
|
13
|
+
* @param postCall The data returned by the call to the logic verifier
|
|
14
|
+
*/
|
|
15
|
+
error LSP20InvalidMagicValue(bool postCall, bytes returnedData);
|
|
@@ -270,13 +270,13 @@ library LSP2Utils {
|
|
|
270
270
|
/**
|
|
271
271
|
* Pointer will always land on these values:
|
|
272
272
|
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
273
|
+
* ↓↓↓↓
|
|
274
|
+
* 0003 a00000
|
|
275
|
+
* 0005 fff83a0011
|
|
276
|
+
* 0020 aa0000000000000000000000000000000000000000000000000000000000cafe
|
|
277
|
+
* 0012 bb000000000000000000000000000000beef
|
|
278
|
+
* 0019 cc00000000000000000000000000000000000000000000deed
|
|
279
|
+
* ↑↑↑↑
|
|
280
280
|
*
|
|
281
281
|
* The pointer can only land on the length of the following bytes value.
|
|
282
282
|
*/
|
|
@@ -14,25 +14,25 @@ import "../LSP7DigitalAsset/LSP7Constants.sol";
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @dev reverts when the value stored under the 'LSP5ReceivedAssets[]' data key is not valid.
|
|
17
|
-
* The value stored under this data key should be exactly
|
|
17
|
+
* The value stored under this data key should be exactly 16 bytes long.
|
|
18
18
|
*
|
|
19
19
|
* Only possible valid values are:
|
|
20
|
-
* - any valid
|
|
21
|
-
* i.e.
|
|
22
|
-
* i.e.
|
|
20
|
+
* - any valid uint128 values
|
|
21
|
+
* i.e. 0x00000000000000000000000000000000 (zero), empty array, no assets received.
|
|
22
|
+
* i.e. 0x00000000000000000000000000000005 (non-zero), 5 array elements, 5 assets received.
|
|
23
23
|
*
|
|
24
24
|
* - 0x (nothing stored under this data key, equivalent to empty array)
|
|
25
25
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* @param invalidValueLength the invalid number of bytes stored under the LSP5ReceivedAssets[] data key (MUST be
|
|
26
|
+
* @param invalidValueStored the invalid value stored under the LSP5ReceivedAssets[] data key
|
|
27
|
+
* @param invalidValueLength the invalid number of bytes stored under the LSP5ReceivedAssets[] data key (MUST be exactly 16 bytes long)
|
|
28
28
|
*/
|
|
29
|
-
error InvalidLSP5ReceivedAssetsArrayLength(bytes
|
|
29
|
+
error InvalidLSP5ReceivedAssetsArrayLength(bytes invalidValueStored, uint256 invalidValueLength);
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* @dev reverts when the
|
|
33
|
-
* @param
|
|
32
|
+
* @dev reverts when the `LSP5ReceivedAssets[]` array reaches its maximum limit (max(uint128))
|
|
33
|
+
* @param notRegisteredAsset the address of the asset that could not be registered
|
|
34
34
|
*/
|
|
35
|
-
error
|
|
35
|
+
error MaxLSP5ReceivedAssetsCountReached(address notRegisteredAsset);
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* @dev reverts when the received assets index is superior to uint128
|
|
@@ -68,44 +68,32 @@ library LSP5Utils {
|
|
|
68
68
|
IERC725Y account = IERC725Y(receiver);
|
|
69
69
|
bytes memory encodedArrayLength = getLSP5ReceivedAssetsCount(account);
|
|
70
70
|
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
keys[2] = assetMapKey;
|
|
80
|
-
values[2] = bytes.concat(interfaceID, bytes8(0));
|
|
81
|
-
|
|
82
|
-
// If the storage is already initiated
|
|
83
|
-
} else if (encodedArrayLength.length == 32) {
|
|
84
|
-
uint256 oldArrayLength = uint256(bytes32(encodedArrayLength));
|
|
71
|
+
// CHECK it's either the first asset received,
|
|
72
|
+
// or the storage is already set with a valid `uint128` value
|
|
73
|
+
if (encodedArrayLength.length != 0 && encodedArrayLength.length != 16) {
|
|
74
|
+
revert InvalidLSP5ReceivedAssetsArrayLength({
|
|
75
|
+
invalidValueStored: encodedArrayLength,
|
|
76
|
+
invalidValueLength: encodedArrayLength.length
|
|
77
|
+
});
|
|
78
|
+
}
|
|
85
79
|
|
|
86
|
-
|
|
87
|
-
revert ReceivedAssetsIndexSuperiorToUint64(oldArrayLength);
|
|
88
|
-
}
|
|
80
|
+
uint128 oldArrayLength = uint128(bytes16(encodedArrayLength));
|
|
89
81
|
|
|
90
|
-
|
|
82
|
+
if (oldArrayLength == type(uint128).max) {
|
|
83
|
+
revert MaxLSP5ReceivedAssetsCountReached({notRegisteredAsset: asset});
|
|
84
|
+
}
|
|
91
85
|
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
|
|
87
|
+
values[0] = bytes.concat(bytes16(oldArrayLength + 1));
|
|
94
88
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
89
|
+
keys[1] = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
90
|
+
_LSP5_RECEIVED_ASSETS_ARRAY_KEY,
|
|
91
|
+
oldArrayLength
|
|
92
|
+
);
|
|
93
|
+
values[1] = bytes.concat(bytes20(asset));
|
|
100
94
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
} else {
|
|
104
|
-
revert InvalidLSP5ReceivedAssetsArrayLength(
|
|
105
|
-
encodedArrayLength,
|
|
106
|
-
encodedArrayLength.length
|
|
107
|
-
);
|
|
108
|
-
}
|
|
95
|
+
keys[2] = assetMapKey;
|
|
96
|
+
values[2] = bytes.concat(interfaceID, bytes16(oldArrayLength));
|
|
109
97
|
}
|
|
110
98
|
|
|
111
99
|
/**
|
|
@@ -121,12 +109,20 @@ library LSP5Utils {
|
|
|
121
109
|
bytes memory assetInterfaceIdAndIndex
|
|
122
110
|
) internal view returns (bytes32[] memory keys, bytes[] memory values) {
|
|
123
111
|
IERC725Y account = IERC725Y(sender);
|
|
112
|
+
bytes memory lsp5ReceivedAssetsCountValue = getLSP5ReceivedAssetsCount(account);
|
|
113
|
+
|
|
114
|
+
if (lsp5ReceivedAssetsCountValue.length != 16) {
|
|
115
|
+
revert InvalidLSP5ReceivedAssetsArrayLength({
|
|
116
|
+
invalidValueStored: lsp5ReceivedAssetsCountValue,
|
|
117
|
+
invalidValueLength: lsp5ReceivedAssetsCountValue.length
|
|
118
|
+
});
|
|
119
|
+
}
|
|
124
120
|
|
|
125
121
|
// Updating the number of the received assets
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
uint128 oldArrayLength = uint128(bytes16(lsp5ReceivedAssetsCountValue));
|
|
123
|
+
uint128 newArrayLength = oldArrayLength - 1;
|
|
128
124
|
|
|
129
|
-
|
|
125
|
+
uint128 index = extractIndexFromMap(assetInterfaceIdAndIndex);
|
|
130
126
|
bytes32 assetInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
131
127
|
_LSP5_RECEIVED_ASSETS_ARRAY_KEY,
|
|
132
128
|
index
|
|
@@ -143,7 +139,7 @@ library LSP5Utils {
|
|
|
143
139
|
values = new bytes[](3);
|
|
144
140
|
|
|
145
141
|
keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
|
|
146
|
-
values[0] = bytes.concat(
|
|
142
|
+
values[0] = bytes.concat(bytes16(newArrayLength));
|
|
147
143
|
|
|
148
144
|
keys[1] = assetInArrayKey;
|
|
149
145
|
values[1] = "";
|
|
@@ -166,7 +162,7 @@ library LSP5Utils {
|
|
|
166
162
|
values = new bytes[](5);
|
|
167
163
|
|
|
168
164
|
keys[0] = _LSP5_RECEIVED_ASSETS_ARRAY_KEY;
|
|
169
|
-
values[0] = bytes.concat(
|
|
165
|
+
values[0] = bytes.concat(bytes16(newArrayLength));
|
|
170
166
|
|
|
171
167
|
keys[1] = assetMapKey;
|
|
172
168
|
values[1] = "";
|
|
@@ -175,13 +171,11 @@ library LSP5Utils {
|
|
|
175
171
|
revert ReceivedAssetsIndexSuperiorToUint128(newArrayLength);
|
|
176
172
|
}
|
|
177
173
|
|
|
178
|
-
uint128 newArrayLength128 = uint128(newArrayLength);
|
|
179
|
-
|
|
180
174
|
// Generate all data Keys/values of the last element in Array to swap
|
|
181
175
|
// with data Keys/values of the asset to remove
|
|
182
176
|
bytes32 lastAssetInArrayKey = LSP2Utils.generateArrayElementKeyAtIndex(
|
|
183
177
|
_LSP5_RECEIVED_ASSETS_ARRAY_KEY,
|
|
184
|
-
|
|
178
|
+
newArrayLength
|
|
185
179
|
);
|
|
186
180
|
|
|
187
181
|
bytes20 lastAssetInArrayAddress = bytes20(account.getData(lastAssetInArrayKey));
|
|
@@ -201,7 +195,7 @@ library LSP5Utils {
|
|
|
201
195
|
values[3] = "";
|
|
202
196
|
|
|
203
197
|
keys[4] = lastAssetInArrayMapKey;
|
|
204
|
-
values[4] = bytes.concat(interfaceID,
|
|
198
|
+
values[4] = bytes.concat(interfaceID, bytes16(index));
|
|
205
199
|
}
|
|
206
200
|
}
|
|
207
201
|
|
|
@@ -210,10 +204,10 @@ library LSP5Utils {
|
|
|
210
204
|
}
|
|
211
205
|
|
|
212
206
|
/**
|
|
213
|
-
* @dev returns the index from
|
|
207
|
+
* @dev returns the index from the LSP5ReceivedAssetMap
|
|
214
208
|
*/
|
|
215
|
-
function extractIndexFromMap(bytes memory mapValue) internal pure returns (
|
|
216
|
-
bytes memory val = BytesLib.slice(mapValue, 4,
|
|
217
|
-
return BytesLib.
|
|
209
|
+
function extractIndexFromMap(bytes memory mapValue) internal pure returns (uint128) {
|
|
210
|
+
bytes memory val = BytesLib.slice(mapValue, 4, 16);
|
|
211
|
+
return BytesLib.toUint128(val, 0);
|
|
218
212
|
}
|
|
219
213
|
}
|
|
@@ -11,7 +11,7 @@ interface ILSP6KeyManager is
|
|
|
11
11
|
IERC1271
|
|
12
12
|
/* is ERC165 */
|
|
13
13
|
{
|
|
14
|
-
event
|
|
14
|
+
event VerifiedCall(address indexed signer, uint256 indexed value, bytes4 indexed selector);
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @notice returns the address of the account linked to this KeyManager
|
|
@@ -33,8 +33,8 @@ bytes10 constant _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDCALLS_PREFIX = 0x4b80742de2b
|
|
|
33
33
|
// - AddressPermissions:AllowedERC725YDataKeys:...
|
|
34
34
|
// - AddressPermissions:AllowedCalls
|
|
35
35
|
bytes32 constant _PERMISSION_CHANGEOWNER = 0x0000000000000000000000000000000000000000000000000000000000000001;
|
|
36
|
-
bytes32 constant _PERMISSION_ADDCONTROLLER
|
|
37
|
-
bytes32 constant
|
|
36
|
+
bytes32 constant _PERMISSION_ADDCONTROLLER = 0x0000000000000000000000000000000000000000000000000000000000000002;
|
|
37
|
+
bytes32 constant _PERMISSION_EDITPERMISSIONS = 0x0000000000000000000000000000000000000000000000000000000000000004;
|
|
38
38
|
bytes32 constant _PERMISSION_ADDEXTENSIONS = 0x0000000000000000000000000000000000000000000000000000000000000008;
|
|
39
39
|
bytes32 constant _PERMISSION_CHANGEEXTENSIONS = 0x0000000000000000000000000000000000000000000000000000000000000010;
|
|
40
40
|
bytes32 constant _PERMISSION_ADDUNIVERSALRECEIVERDELEGATE = 0x0000000000000000000000000000000000000000000000000000000000000020;
|
|
@@ -63,3 +63,9 @@ bytes4 constant _LSP6_EXECUTE_SELECTOR = 0x09c5eabe;
|
|
|
63
63
|
bytes4 constant _LSP6_EXECUTE_BATCH_SELECTOR = 0xbf3e1f7b;
|
|
64
64
|
bytes4 constant _LSP6_EXECUTE_RELAYCALL_SELECTOR = 0x902d5fa0;
|
|
65
65
|
bytes4 constant _LSP6_EXECUTE_RELAYCALL_BATCH_SELECTOR = 0xbd68663a;
|
|
66
|
+
|
|
67
|
+
// AllowedCalls types
|
|
68
|
+
bytes4 constant _ALLOWEDCALLS_VALUE = 0x00000001; // 0000 0001 TRANSFER VALUE
|
|
69
|
+
bytes4 constant _ALLOWEDCALLS_WRITE = 0x00000002; // 0000 0010 CALL
|
|
70
|
+
bytes4 constant _ALLOWEDCALLS_READ = 0x00000004; // 0000 0100 STATIC CALL
|
|
71
|
+
bytes4 constant _ALLOWEDCALLS_EXECUTE = 0x00000008; // 0000 1000 DELEGATE CALL
|
|
@@ -88,8 +88,9 @@ error NoCallsAllowed(address from);
|
|
|
88
88
|
/**
|
|
89
89
|
* @dev reverts when `value` is not encoded properly using the CompactBytesArray
|
|
90
90
|
* @param value the value to check for an CompactBytesArray
|
|
91
|
+
* @param context a brief description of where the error occured
|
|
91
92
|
*/
|
|
92
|
-
error InvalidEncodedAllowedERC725YDataKeys(bytes value);
|
|
93
|
+
error InvalidEncodedAllowedERC725YDataKeys(bytes value, string context);
|
|
93
94
|
|
|
94
95
|
/**
|
|
95
96
|
* @dev a `from` address is not allowed to have 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff
|
|
@@ -141,3 +142,19 @@ error DelegateCallDisallowedViaKeyManager();
|
|
|
141
142
|
* @dev reverts when the payload is invalid.
|
|
142
143
|
*/
|
|
143
144
|
error InvalidPayload(bytes payload);
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @dev reverts when the caller is not the linked target
|
|
148
|
+
* @param caller The address calling lsp20 related functions
|
|
149
|
+
*/
|
|
150
|
+
error CallerIsNotTheTarget(address caller);
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @dev reverts when sending value to the `setData(..)` functions
|
|
154
|
+
*/
|
|
155
|
+
error CannotSendValueToSetData();
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @dev reverts when calling the KeyManager through execute(..)
|
|
159
|
+
*/
|
|
160
|
+
error CallingKeyManagerNotAllowed();
|