@lukso/lsp-smart-contracts 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -10
- package/artifacts/Create2Factory.json +2 -2
- package/artifacts/LSP0ERC725Account.json +36 -3
- package/artifacts/LSP0ERC725AccountInit.json +36 -29
- package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
- package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -2
- package/artifacts/LSP4Compatibility.json +6 -0
- package/artifacts/LSP4DigitalAssetMetadata.json +6 -0
- package/artifacts/{LSP4DigitalAssetMetadataInit.json → LSP4DigitalAssetMetadataInitAbstract.json} +8 -51
- package/artifacts/LSP6KeyManager.json +13 -2
- package/artifacts/LSP6KeyManagerInit.json +13 -2
- package/artifacts/LSP7CappedSupply.json +37 -26
- package/artifacts/{LSP7CappedSupplyInit.json → LSP7CappedSupplyInitAbstract.json} +39 -67
- package/artifacts/LSP7CompatibleERC20.json +39 -49
- package/artifacts/LSP7CompatibleERC20InitAbstract.json +717 -0
- package/artifacts/LSP7CompatibleERC20Mintable.json +39 -28
- package/artifacts/LSP7CompatibleERC20MintableInit.json +44 -54
- package/artifacts/LSP7DigitalAsset.json +39 -54
- package/artifacts/LSP7DigitalAssetInitAbstract.json +540 -0
- package/artifacts/LSP7Mintable.json +40 -29
- package/artifacts/LSP7MintableInit.json +40 -55
- package/artifacts/LSP8CappedSupply.json +43 -0
- package/artifacts/{LSP8CappedSupplyInit.json → LSP8CappedSupplyInitAbstract.json} +45 -41
- package/artifacts/LSP8CompatibleERC721.json +88 -23
- package/artifacts/LSP8CompatibleERC721InitAbstract.json +920 -0
- package/artifacts/LSP8CompatibleERC721Mintable.json +88 -2
- package/artifacts/LSP8CompatibleERC721MintableInit.json +93 -28
- package/artifacts/LSP8IdentifiableDigitalAsset.json +45 -23
- package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +628 -0
- package/artifacts/LSP8Mintable.json +45 -2
- package/artifacts/LSP8MintableInit.json +45 -28
- package/artifacts/LSP9Vault.json +36 -3
- package/artifacts/LSP9VaultInit.json +36 -29
- package/artifacts/UniversalFactory.json +2 -2
- package/artifacts/UniversalProfile.json +36 -3
- package/artifacts/UniversalProfileInit.json +36 -29
- package/artifacts/UniversalReceiverAddressStore.json +2 -2
- package/constants.js +73 -14
- package/contracts/Custom/ClaimOwnership.sol +67 -5
- package/contracts/Custom/ERC165Checker.sol +1 -1
- package/contracts/Custom/IClaimOwnership.sol +3 -1
- package/contracts/Factories/UniversalFactory.sol +7 -12
- package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +20 -18
- package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +1 -1
- package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +2 -2
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +1 -4
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +2 -8
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +1 -4
- package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +2 -2
- package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +1 -1
- package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +92 -6
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +15 -6
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +15 -6
- package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +2 -2
- package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +3 -3
- package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6Constants.sol +16 -21
- package/contracts/LSP6KeyManager/LSP6Errors.sol +8 -0
- package/contracts/LSP6KeyManager/LSP6KeyManager.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +103 -84
- package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +1 -1
- package/contracts/LSP6KeyManager/LSP6Utils.sol +2 -1
- package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +18 -5
- package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
- package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +4 -4
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +33 -24
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +2 -2
- package/contracts/LSP7DigitalAsset/LSP7Errors.sol +2 -0
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +1 -1
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Core.sol +5 -6
- package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +7 -0
- package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +9 -7
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +3 -3
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +8 -7
- package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +3 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +4 -4
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +6 -0
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +31 -30
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +15 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Enumerable.sol +17 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +1 -1
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Core.sol +51 -27
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +21 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableCore.sol +50 -0
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +24 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +7 -0
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +6 -4
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +5 -4
- package/contracts/LSP9Vault/LSP9Constants.sol +4 -1
- package/contracts/LSP9Vault/LSP9VaultCore.sol +117 -46
- package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +1 -1
- package/contracts/Legacy/UniversalReceiverAddressStore.sol +1 -0
- package/contracts/Utils/GasLib.sol +17 -0
- package/package.json +27 -30
- package/artifacts/LSP7CompatibleERC20Init.json +0 -760
- package/artifacts/LSP7DigitalAssetInit.json +0 -588
- package/artifacts/LSP8CompatibleERC721Init.json +0 -883
- package/artifacts/LSP8IdentifiableDigitalAssetInit.json +0 -639
- package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +0 -26
- package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +0 -39
- package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +0 -19
- package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20Init.sol +0 -29
- package/contracts/LSP7DigitalAsset/presets/LSP7MintableCore.sol +0 -26
- package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +0 -35
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +0 -19
- package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721Init.sol +0 -25
- package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableCore.sol +0 -26
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
pragma solidity ^0.8.
|
|
2
|
+
pragma solidity ^0.8.5;
|
|
3
3
|
|
|
4
4
|
// interfaces
|
|
5
5
|
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
|
|
@@ -13,6 +13,7 @@ import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
|
|
|
13
13
|
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
|
|
14
14
|
|
|
15
15
|
// libraries
|
|
16
|
+
import {GasLib} from "../Utils/GasLib.sol";
|
|
16
17
|
import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
|
|
17
18
|
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
18
19
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
@@ -26,11 +27,15 @@ import {InvalidABIEncodedArray} from "../LSP2ERC725YJSONSchema/LSP2Errors.sol";
|
|
|
26
27
|
|
|
27
28
|
// constants
|
|
28
29
|
import {
|
|
30
|
+
// ERC725X
|
|
29
31
|
OPERATION_CALL,
|
|
30
32
|
OPERATION_CREATE,
|
|
31
33
|
OPERATION_CREATE2,
|
|
32
34
|
OPERATION_STATICCALL,
|
|
33
|
-
OPERATION_DELEGATECALL
|
|
35
|
+
OPERATION_DELEGATECALL,
|
|
36
|
+
// ERC725Y
|
|
37
|
+
SETDATA_SELECTOR,
|
|
38
|
+
SETDATA_ARRAY_SELECTOR
|
|
34
39
|
} from "@erc725/smart-contracts/contracts/constants.sol";
|
|
35
40
|
import {
|
|
36
41
|
_INTERFACEID_ERC1271,
|
|
@@ -51,7 +56,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
51
56
|
using ECDSA for bytes32;
|
|
52
57
|
using ERC165Checker for address;
|
|
53
58
|
|
|
54
|
-
address public
|
|
59
|
+
address public target;
|
|
55
60
|
mapping(address => mapping(uint256 => uint256)) internal _nonceStore;
|
|
56
61
|
|
|
57
62
|
/**
|
|
@@ -67,7 +72,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
67
72
|
/**
|
|
68
73
|
* @inheritdoc ILSP6KeyManager
|
|
69
74
|
*/
|
|
70
|
-
function getNonce(address from, uint256 channelId) public view
|
|
75
|
+
function getNonce(address from, uint256 channelId) public view returns (uint256) {
|
|
71
76
|
uint128 nonceId = uint128(_nonceStore[from][channelId]);
|
|
72
77
|
return (uint256(channelId) << 128) | nonceId;
|
|
73
78
|
}
|
|
@@ -78,7 +83,6 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
78
83
|
function isValidSignature(bytes32 dataHash, bytes memory signature)
|
|
79
84
|
public
|
|
80
85
|
view
|
|
81
|
-
override
|
|
82
86
|
returns (bytes4 magicValue)
|
|
83
87
|
{
|
|
84
88
|
address recoveredAddress = dataHash.recover(signature);
|
|
@@ -93,22 +97,10 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
93
97
|
/**
|
|
94
98
|
* @inheritdoc ILSP6KeyManager
|
|
95
99
|
*/
|
|
96
|
-
function execute(bytes calldata payload) public payable
|
|
100
|
+
function execute(bytes calldata payload) public payable returns (bytes memory) {
|
|
97
101
|
_verifyPermissions(msg.sender, payload);
|
|
98
102
|
|
|
99
|
-
|
|
100
|
-
(bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
|
|
101
|
-
payload
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
bytes memory result = Address.verifyCallResult(
|
|
105
|
-
success,
|
|
106
|
-
returnData,
|
|
107
|
-
"LSP6: Unknow Error occured when calling the linked target contract"
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
emit Executed(msg.value, bytes4(payload));
|
|
111
|
-
return result.length != 0 ? abi.decode(result, (bytes)) : result;
|
|
103
|
+
return _executePayload(payload);
|
|
112
104
|
}
|
|
113
105
|
|
|
114
106
|
/**
|
|
@@ -118,7 +110,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
118
110
|
bytes memory signature,
|
|
119
111
|
uint256 nonce,
|
|
120
112
|
bytes calldata payload
|
|
121
|
-
) public payable
|
|
113
|
+
) public payable returns (bytes memory) {
|
|
122
114
|
bytes memory blob = abi.encodePacked(
|
|
123
115
|
block.chainid,
|
|
124
116
|
address(this), // needs to be signed for this keyManager
|
|
@@ -137,20 +129,31 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
137
129
|
|
|
138
130
|
_verifyPermissions(signer, payload);
|
|
139
131
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
payload
|
|
143
|
-
);
|
|
132
|
+
return _executePayload(payload);
|
|
133
|
+
}
|
|
144
134
|
|
|
135
|
+
/**
|
|
136
|
+
* @notice execute the received payload (obtained via `execute(...)` and `executeRelayCall(...)`)
|
|
137
|
+
*
|
|
138
|
+
* @param payload the payload to execute
|
|
139
|
+
* @return bytes the result from calling the target with `_payload`
|
|
140
|
+
*/
|
|
141
|
+
function _executePayload(bytes calldata payload) internal returns (bytes memory) {
|
|
142
|
+
|
|
143
|
+
// solhint-disable avoid-low-level-calls
|
|
144
|
+
(bool success, bytes memory returnData) = target.call{value: msg.value, gas: gasleft()}(
|
|
145
|
+
payload
|
|
146
|
+
);
|
|
145
147
|
bytes memory result = Address.verifyCallResult(
|
|
146
148
|
success,
|
|
147
149
|
returnData,
|
|
148
|
-
"LSP6:
|
|
150
|
+
"LSP6: Unknown Error occured when calling the linked target contract"
|
|
149
151
|
);
|
|
150
152
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
emit Executed(msg.value, bytes4(payload));
|
|
154
|
+
return result.length != 0 ? abi.decode(result, (bytes)) : result;
|
|
155
|
+
|
|
156
|
+
}
|
|
154
157
|
|
|
155
158
|
/**
|
|
156
159
|
* @notice verify the nonce `_idx` for `_from` (obtained via `getNonce(...)`)
|
|
@@ -180,22 +183,24 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
180
183
|
|
|
181
184
|
if (permissions == bytes32(0)) revert NoPermissionsSet(from);
|
|
182
185
|
|
|
183
|
-
if (erc725Function ==
|
|
186
|
+
if (erc725Function == SETDATA_SELECTOR) {
|
|
184
187
|
(bytes32 inputKey, bytes memory inputValue) = abi.decode(payload[4:], (bytes32, bytes));
|
|
185
188
|
|
|
186
|
-
if (
|
|
189
|
+
if (bytes16(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
|
|
190
|
+
// CHECK if key = AddressPermissions[] or AddressPermissions[index]
|
|
191
|
+
_verifyCanSetPermissionsArray(inputKey, inputValue, from, permissions);
|
|
192
|
+
|
|
193
|
+
} else if (bytes6(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX) {
|
|
187
194
|
// CHECK for permission keys
|
|
188
|
-
bytes6(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX ||
|
|
189
|
-
bytes16(inputKey) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX
|
|
190
|
-
) {
|
|
191
195
|
_verifyCanSetPermissions(inputKey, inputValue, from, permissions);
|
|
196
|
+
|
|
192
197
|
} else {
|
|
193
198
|
bytes32[] memory wrappedInputKey = new bytes32[](1);
|
|
194
199
|
wrappedInputKey[0] = inputKey;
|
|
195
200
|
|
|
196
201
|
_verifyCanSetData(from, permissions, wrappedInputKey);
|
|
197
202
|
}
|
|
198
|
-
} else if (erc725Function ==
|
|
203
|
+
} else if (erc725Function == SETDATA_ARRAY_SELECTOR) {
|
|
199
204
|
(bytes32[] memory inputKeys, bytes[] memory inputValues) = abi.decode(
|
|
200
205
|
payload[4:],
|
|
201
206
|
(bytes32[], bytes[])
|
|
@@ -204,19 +209,22 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
204
209
|
bool isSettingERC725YKeys = false;
|
|
205
210
|
|
|
206
211
|
// loop through each ERC725Y data keys
|
|
207
|
-
for (uint256 ii = 0; ii < inputKeys.length; ii
|
|
212
|
+
for (uint256 ii = 0; ii < inputKeys.length; ii = GasLib.uncheckedIncrement(ii)) {
|
|
208
213
|
bytes32 key = inputKeys[ii];
|
|
209
214
|
bytes memory value = inputValues[ii];
|
|
210
215
|
|
|
211
|
-
if (
|
|
212
|
-
// CHECK
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
if (bytes16(key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
|
|
217
|
+
// CHECK if key = AddressPermissions[] or AddressPermissions[index]
|
|
218
|
+
_verifyCanSetPermissionsArray(key, value, from, permissions);
|
|
219
|
+
|
|
220
|
+
// "nullify" permission keys to not check them against allowed ERC725Y keys
|
|
221
|
+
inputKeys[ii] = bytes32(0);
|
|
222
|
+
|
|
223
|
+
} else if (bytes6(key) == _LSP6KEY_ADDRESSPERMISSIONS_PREFIX) {
|
|
224
|
+
// CHECK for permissions keys
|
|
216
225
|
_verifyCanSetPermissions(key, value, from, permissions);
|
|
217
226
|
|
|
218
|
-
// "nullify" permission keys
|
|
219
|
-
// to not check them against allowed ERC725Y keys
|
|
227
|
+
// "nullify" permission keys to not check them against allowed ERC725Y keys
|
|
220
228
|
inputKeys[ii] = bytes32(0);
|
|
221
229
|
} else {
|
|
222
230
|
// if the key is any other bytes32 key
|
|
@@ -265,22 +273,12 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
265
273
|
bytes memory value,
|
|
266
274
|
address from,
|
|
267
275
|
bytes32 permissions
|
|
268
|
-
) internal view {
|
|
276
|
+
) internal view virtual {
|
|
269
277
|
// prettier-ignore
|
|
270
278
|
if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX) {
|
|
271
|
-
|
|
279
|
+
|
|
272
280
|
// key = AddressPermissions:Permissions:<address>
|
|
273
281
|
_verifyCanSetBytes32Permissions(key, from, permissions);
|
|
274
|
-
|
|
275
|
-
} else if (key == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
|
|
276
|
-
|
|
277
|
-
// key = AddressPermissions[]
|
|
278
|
-
_verifyCanSetPermissionsArray(key, value, from, permissions);
|
|
279
|
-
|
|
280
|
-
} else if (bytes16(key) == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY_PREFIX) {
|
|
281
|
-
|
|
282
|
-
// key = AddressPermissions[index]
|
|
283
|
-
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
284
282
|
|
|
285
283
|
} else if (bytes12(key) == _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX) {
|
|
286
284
|
|
|
@@ -347,7 +345,24 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
347
345
|
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
348
346
|
|
|
349
347
|
}
|
|
350
|
-
|
|
348
|
+
} else {
|
|
349
|
+
/**
|
|
350
|
+
* if bytes6(key) != bytes6(keccak256("AddressPermissions"))
|
|
351
|
+
* this is not a standard permission key according to LSP6
|
|
352
|
+
* so we revert execution
|
|
353
|
+
*
|
|
354
|
+
* @dev to implement custom permissions keys, consider overriding
|
|
355
|
+
* this function and implement specific checks
|
|
356
|
+
*
|
|
357
|
+
* // AddressPermissions:MyCustomPermissions:<address>
|
|
358
|
+
* bytes12 CUSTOM_PERMISSION_PREFIX = 0x4b80742de2bf9e659ba40000
|
|
359
|
+
*
|
|
360
|
+
* if (bytes12(key) == CUSTOM_PERMISSION_PREFIX) {
|
|
361
|
+
* // custom logic
|
|
362
|
+
* }
|
|
363
|
+
* super._verifyCanSetPermissions(...)
|
|
364
|
+
*/
|
|
365
|
+
revert NotRecognisedPermissionKey(key);
|
|
351
366
|
}
|
|
352
367
|
}
|
|
353
368
|
|
|
@@ -374,14 +389,22 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
374
389
|
address from,
|
|
375
390
|
bytes32 permissions
|
|
376
391
|
) internal view {
|
|
377
|
-
|
|
378
|
-
|
|
392
|
+
// key = AddressPermissions[] -> array length
|
|
393
|
+
if (key == _LSP6KEY_ADDRESSPERMISSIONS_ARRAY) {
|
|
394
|
+
uint256 arrayLength = uint256(bytes32(ERC725Y(target).getData(key)));
|
|
395
|
+
uint256 newLength = uint256(bytes32(value));
|
|
379
396
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
397
|
+
if (newLength > arrayLength) {
|
|
398
|
+
_requirePermissions(from, permissions, _PERMISSION_ADDPERMISSIONS);
|
|
399
|
+
} else {
|
|
400
|
+
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return;
|
|
384
404
|
}
|
|
405
|
+
|
|
406
|
+
// key = AddressPermissions[index] -> array index
|
|
407
|
+
_requirePermissions(from, permissions, _PERMISSION_CHANGEPERMISSIONS);
|
|
385
408
|
}
|
|
386
409
|
|
|
387
410
|
function _verifyAllowedERC725YKeys(address from, bytes32[] memory inputKeys) internal view {
|
|
@@ -401,12 +424,12 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
401
424
|
bytes32 mask;
|
|
402
425
|
|
|
403
426
|
// loop through each allowed ERC725Y key retrieved from storage
|
|
404
|
-
for (uint256 ii = 0; ii < allowedERC725YKeys.length; ii
|
|
427
|
+
for (uint256 ii = 0; ii < allowedERC725YKeys.length; ii = GasLib.uncheckedIncrement(ii)) {
|
|
405
428
|
// required to know which part of the input key to compare against the allowed key
|
|
406
429
|
zeroBytesCount = _countTrailingZeroBytes(allowedERC725YKeys[ii]);
|
|
407
430
|
|
|
408
431
|
// loop through each keys given as input
|
|
409
|
-
for (uint256 jj = 0; jj < inputKeys.length; jj
|
|
432
|
+
for (uint256 jj = 0; jj < inputKeys.length; jj = GasLib.uncheckedIncrement(jj)) {
|
|
410
433
|
// skip permissions keys that have been previously checked and "nulled"
|
|
411
434
|
if (inputKeys[jj] == bytes32(0)) continue;
|
|
412
435
|
|
|
@@ -430,7 +453,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
430
453
|
}
|
|
431
454
|
}
|
|
432
455
|
|
|
433
|
-
for (uint256 ii = 0; ii < inputKeys.length; ii
|
|
456
|
+
for (uint256 ii = 0; ii < inputKeys.length; ii = GasLib.uncheckedIncrement(ii)) {
|
|
434
457
|
if (inputKeys[ii] != bytes32(0)) revert NotAllowedERC725YKey(from, inputKeys[ii]);
|
|
435
458
|
}
|
|
436
459
|
}
|
|
@@ -450,7 +473,6 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
450
473
|
uint256 operationType = uint256(bytes32(payload[4:36]));
|
|
451
474
|
require(operationType < 5, "LSP6KeyManager: invalid operation type");
|
|
452
475
|
|
|
453
|
-
// TODO: if re-enable delegatecall, add check to ensure owner() + initialized() are not overriden after delegatecall
|
|
454
476
|
require(
|
|
455
477
|
operationType != OPERATION_DELEGATECALL,
|
|
456
478
|
"LSP6KeyManager: operation DELEGATECALL is currently disallowed"
|
|
@@ -467,16 +489,14 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
467
489
|
? false
|
|
468
490
|
: permissions.hasPermission(_extractSuperPermissionFromOperation(operationType));
|
|
469
491
|
|
|
470
|
-
if (isCallDataPresent) {
|
|
471
|
-
|
|
472
|
-
hasSuperOperation || _requirePermissions(from, permissions, _extractPermissionFromOperation(operationType));
|
|
492
|
+
if (isCallDataPresent && !hasSuperOperation) {
|
|
493
|
+
_requirePermissions(from, permissions, _extractPermissionFromOperation(operationType));
|
|
473
494
|
}
|
|
474
495
|
|
|
475
496
|
bool hasSuperTransferValue = permissions.hasPermission(_PERMISSION_SUPER_TRANSFERVALUE);
|
|
476
497
|
|
|
477
|
-
if (value
|
|
478
|
-
|
|
479
|
-
hasSuperTransferValue || _requirePermissions(from, permissions, _PERMISSION_TRANSFERVALUE);
|
|
498
|
+
if (value != 0 && !hasSuperTransferValue) {
|
|
499
|
+
_requirePermissions(from, permissions, _PERMISSION_TRANSFERVALUE);
|
|
480
500
|
}
|
|
481
501
|
|
|
482
502
|
// Skip on contract creation (CREATE or CREATE2)
|
|
@@ -486,7 +506,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
486
506
|
if (hasSuperOperation && isCallDataPresent && value == 0) return;
|
|
487
507
|
|
|
488
508
|
// Skip if caller has SUPER permission for value transfers
|
|
489
|
-
if (hasSuperTransferValue && !isCallDataPresent && value
|
|
509
|
+
if (hasSuperTransferValue && !isCallDataPresent && value != 0) return;
|
|
490
510
|
|
|
491
511
|
// Skip if both SUPER permissions are present
|
|
492
512
|
if (hasSuperOperation && hasSuperTransferValue) return;
|
|
@@ -495,7 +515,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
495
515
|
address to = address(bytes20(payload[48:68]));
|
|
496
516
|
_verifyAllowedAddress(from, to);
|
|
497
517
|
|
|
498
|
-
if (to.code.length
|
|
518
|
+
if (to.code.length != 0) {
|
|
499
519
|
// CHECK for ALLOWED STANDARDS
|
|
500
520
|
_verifyAllowedStandard(from, to);
|
|
501
521
|
|
|
@@ -551,7 +571,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
551
571
|
|
|
552
572
|
address[] memory allowedAddressesList = abi.decode(allowedAddresses, (address[]));
|
|
553
573
|
|
|
554
|
-
for (uint256 ii = 0; ii < allowedAddressesList.length; ii
|
|
574
|
+
for (uint256 ii = 0; ii < allowedAddressesList.length; ii = GasLib.uncheckedIncrement(ii)) {
|
|
555
575
|
if (to == allowedAddressesList[ii]) return;
|
|
556
576
|
}
|
|
557
577
|
revert NotAllowedAddress(from, to);
|
|
@@ -576,7 +596,7 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
576
596
|
|
|
577
597
|
bytes4[] memory allowedStandardsList = abi.decode(allowedStandards, (bytes4[]));
|
|
578
598
|
|
|
579
|
-
for (uint256 ii = 0; ii < allowedStandardsList.length; ii
|
|
599
|
+
for (uint256 ii = 0; ii < allowedStandardsList.length; ii = GasLib.uncheckedIncrement(ii)) {
|
|
580
600
|
if (to.supportsERC165Interface(allowedStandardsList[ii])) return;
|
|
581
601
|
}
|
|
582
602
|
revert NotAllowedStandard(from, to);
|
|
@@ -602,27 +622,27 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
602
622
|
|
|
603
623
|
bytes4[] memory allowedFunctionsList = abi.decode(allowedFunctions, (bytes4[]));
|
|
604
624
|
|
|
605
|
-
for (uint256 ii = 0; ii < allowedFunctionsList.length; ii
|
|
625
|
+
for (uint256 ii = 0; ii < allowedFunctionsList.length; ii = GasLib.uncheckedIncrement(ii)) {
|
|
606
626
|
if (functionSelector == allowedFunctionsList[ii]) return;
|
|
607
627
|
}
|
|
608
628
|
revert NotAllowedFunction(from, functionSelector);
|
|
609
629
|
}
|
|
610
630
|
|
|
611
|
-
function _countTrailingZeroBytes(bytes32
|
|
612
|
-
uint256
|
|
631
|
+
function _countTrailingZeroBytes(bytes32 dataKey) internal pure returns (uint256) {
|
|
632
|
+
uint256 nByte = 32;
|
|
613
633
|
|
|
614
|
-
// CHECK each bytes of the key, starting from the end (right to left)
|
|
615
|
-
// skip each empty bytes `0x00`
|
|
616
|
-
while (
|
|
634
|
+
// CHECK each bytes of the data key, starting from the end (right to left)
|
|
635
|
+
// skip each empty bytes `0x00` until we find the first non-empty byte
|
|
636
|
+
while (nByte > 0 && dataKey[nByte - 1] == 0x00) nByte--;
|
|
617
637
|
|
|
618
|
-
return 32 -
|
|
638
|
+
return 32 - nByte;
|
|
619
639
|
}
|
|
620
640
|
|
|
621
641
|
function _requirePermissions(
|
|
622
642
|
address from,
|
|
623
643
|
bytes32 addressPermissions,
|
|
624
644
|
bytes32 permissionRequired
|
|
625
|
-
) internal pure
|
|
645
|
+
) internal pure {
|
|
626
646
|
if (!addressPermissions.hasPermission(permissionRequired)) {
|
|
627
647
|
string memory permissionErrorString = _getPermissionErrorString(permissionRequired);
|
|
628
648
|
revert NotAuthorised(from, permissionErrorString);
|
|
@@ -641,7 +661,6 @@ abstract contract LSP6KeyManagerCore is ERC165, ILSP6KeyManager {
|
|
|
641
661
|
if (permission == _PERMISSION_CALL) return "CALL";
|
|
642
662
|
if (permission == _PERMISSION_STATICCALL) return "STATICCALL";
|
|
643
663
|
if (permission == _PERMISSION_DELEGATECALL) return "DELEGATECALL";
|
|
644
|
-
// TODO: add support to display CREATE or CREATE2 in the revert error
|
|
645
664
|
if (permission == _PERMISSION_DEPLOY) return "DEPLOY";
|
|
646
665
|
if (permission == _PERMISSION_TRANSFERVALUE) return "TRANSFERVALUE";
|
|
647
666
|
if (permission == _PERMISSION_SIGN) return "SIGN";
|
|
@@ -9,6 +9,7 @@ import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
|
|
|
9
9
|
import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
|
|
10
10
|
|
|
11
11
|
// constants
|
|
12
|
+
import {SETDATA_ARRAY_SELECTOR} from "@erc725/smart-contracts/contracts/constants.sol";
|
|
12
13
|
import "../LSP6KeyManager/LSP6Constants.sol";
|
|
13
14
|
|
|
14
15
|
library LSP6Utils {
|
|
@@ -101,7 +102,7 @@ library LSP6Utils {
|
|
|
101
102
|
bytes32[] memory keys,
|
|
102
103
|
bytes[] memory values
|
|
103
104
|
) internal returns (bytes memory result) {
|
|
104
|
-
bytes memory payload = abi.encodeWithSelector(
|
|
105
|
+
bytes memory payload = abi.encodeWithSelector(SETDATA_ARRAY_SELECTOR, keys, values);
|
|
105
106
|
result = ILSP6KeyManager(keyManagerAddress).execute(payload);
|
|
106
107
|
}
|
|
107
108
|
}
|
|
@@ -7,7 +7,7 @@ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
|
|
7
7
|
import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @
|
|
10
|
+
* @title interface of the LSP7 - Digital Asset standard.
|
|
11
11
|
*/
|
|
12
12
|
interface ILSP7DigitalAsset is IERC165, IERC725Y {
|
|
13
13
|
// --- Events
|
|
@@ -60,7 +60,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
|
|
|
60
60
|
* no way affects any of the arithmetic of the contract, including
|
|
61
61
|
* {balanceOf} and {transfer}.
|
|
62
62
|
*/
|
|
63
|
-
function decimals() external view returns (
|
|
63
|
+
function decimals() external view returns (uint8);
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* @dev Returns the number of existing tokens.
|
|
@@ -84,7 +84,17 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
|
|
|
84
84
|
* @param amount The amount of tokens operator has access to.
|
|
85
85
|
* @dev Sets `amount` as the amount of tokens `operator` address has access to from callers tokens.
|
|
86
86
|
*
|
|
87
|
-
*
|
|
87
|
+
* To avoid front-running and Allowance Double-Spend Exploit when
|
|
88
|
+
* increasing or decreasing the authorized amount of an operator,
|
|
89
|
+
* it is advised to:
|
|
90
|
+
* 1. call {revokeOperator} first, and
|
|
91
|
+
* 2. then re-call {authorizeOperator} with the new amount
|
|
92
|
+
*
|
|
93
|
+
* for more information, see:
|
|
94
|
+
* https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/
|
|
95
|
+
*
|
|
96
|
+
*
|
|
97
|
+
* See {authorizedAmountFor}.
|
|
88
98
|
*
|
|
89
99
|
* Requirements
|
|
90
100
|
*
|
|
@@ -98,7 +108,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
|
|
|
98
108
|
* @param operator The address to revoke as an operator.
|
|
99
109
|
* @dev Removes `operator` address as an operator of callers tokens.
|
|
100
110
|
*
|
|
101
|
-
* See {
|
|
111
|
+
* See {authorizedAmountFor}.
|
|
102
112
|
*
|
|
103
113
|
* Requirements
|
|
104
114
|
*
|
|
@@ -116,7 +126,10 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
|
|
|
116
126
|
* Operators can send and burn tokens on behalf of their owners. The tokenOwner is their own
|
|
117
127
|
* operator.
|
|
118
128
|
*/
|
|
119
|
-
function
|
|
129
|
+
function authorizedAmountFor(address operator, address tokenOwner)
|
|
130
|
+
external
|
|
131
|
+
view
|
|
132
|
+
returns (uint256);
|
|
120
133
|
|
|
121
134
|
// --- Transfer functionality
|
|
122
135
|
|
|
@@ -21,21 +21,21 @@ import {_INTERFACEID_LSP7} from "./LSP7Constants.sol";
|
|
|
21
21
|
* A supply mechanism has to be added in a derived contract using {_mint}
|
|
22
22
|
* For a generic mechanism, see {LSP7Mintable}.
|
|
23
23
|
*/
|
|
24
|
-
contract LSP7DigitalAsset is LSP4DigitalAssetMetadata, LSP7DigitalAssetCore {
|
|
24
|
+
abstract contract LSP7DigitalAsset is LSP4DigitalAssetMetadata, LSP7DigitalAssetCore {
|
|
25
25
|
/**
|
|
26
26
|
* @notice Sets the token-Metadata
|
|
27
27
|
* @param name_ The name of the token
|
|
28
28
|
* @param symbol_ The symbol of the token
|
|
29
29
|
* @param newOwner_ The owner of the the token-Metadata
|
|
30
|
-
* @param
|
|
30
|
+
* @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token
|
|
31
31
|
*/
|
|
32
32
|
constructor(
|
|
33
33
|
string memory name_,
|
|
34
34
|
string memory symbol_,
|
|
35
35
|
address newOwner_,
|
|
36
|
-
bool
|
|
36
|
+
bool isNonDivisible_
|
|
37
37
|
) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {
|
|
38
|
-
|
|
38
|
+
_isNonDivisible = isNonDivisible_;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|