@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.
Files changed (109) hide show
  1. package/CONTRIBUTING.md +18 -0
  2. package/LICENSE +201 -0
  3. package/README.md +75 -0
  4. package/artifacts/Create2Factory.json +107 -0
  5. package/artifacts/LSP1UniversalReceiverDelegateUP.json +64 -0
  6. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +66 -0
  7. package/artifacts/LSP1UniversalReceiverDelegateVault.json +64 -0
  8. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +66 -0
  9. package/artifacts/LSP6KeyManager.json +222 -0
  10. package/artifacts/LSP6KeyManagerInit.json +224 -0
  11. package/artifacts/LSP7CappedSupply.json +404 -0
  12. package/artifacts/LSP7CappedSupplyInit.json +481 -0
  13. package/artifacts/LSP7CompatibilityForERC20.json +495 -0
  14. package/artifacts/LSP7DigitalAsset.json +417 -0
  15. package/artifacts/LSP7DigitalAssetInit.json +455 -0
  16. package/artifacts/LSP7Mintable.json +445 -0
  17. package/artifacts/LSP7MintableInit.json +483 -0
  18. package/artifacts/LSP8CappedSupply.json +459 -0
  19. package/artifacts/LSP8CappedSupplyInit.json +508 -0
  20. package/artifacts/LSP8CompatibilityForERC721.json +711 -0
  21. package/artifacts/LSP8IdentifiableDigitalAsset.json +467 -0
  22. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +482 -0
  23. package/artifacts/LSP8Mintable.json +495 -0
  24. package/artifacts/LSP8MintableInit.json +510 -0
  25. package/artifacts/UniversalProfile.json +373 -0
  26. package/artifacts/UniversalProfileInit.json +375 -0
  27. package/constants.ts +350 -0
  28. package/contracts/Factories/Create2Factory.sol +92 -0
  29. package/contracts/LSP0ERC725Account/LSP0Constants.sol +14 -0
  30. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +23 -0
  31. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +119 -0
  32. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +20 -0
  33. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +33 -0
  34. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +37 -0
  35. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +22 -0
  36. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +17 -0
  37. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +189 -0
  38. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +26 -0
  39. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +52 -0
  40. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +26 -0
  41. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +28 -0
  42. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +114 -0
  43. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +23 -0
  44. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +41 -0
  45. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +23 -0
  46. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +25 -0
  47. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +23 -0
  48. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +47 -0
  49. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +19 -0
  50. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +36 -0
  51. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +30 -0
  52. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +41 -0
  53. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +52 -0
  54. package/contracts/LSP6KeyManager/LSP6Constants.sol +28 -0
  55. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +21 -0
  56. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +444 -0
  57. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +19 -0
  58. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +26 -0
  59. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +186 -0
  60. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +12 -0
  61. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +35 -0
  62. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +394 -0
  63. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +29 -0
  64. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +44 -0
  65. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +17 -0
  66. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +47 -0
  67. package/contracts/LSP7DigitalAsset/extensions/ILSP7Mintable.sol +32 -0
  68. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +45 -0
  69. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +55 -0
  70. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +24 -0
  71. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +50 -0
  72. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +76 -0
  73. package/contracts/LSP7DigitalAsset/extensions/LSP7Mintable.sol +41 -0
  74. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableCore.sol +26 -0
  75. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInit.sol +26 -0
  76. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +47 -0
  77. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +223 -0
  78. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +18 -0
  79. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +35 -0
  80. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +470 -0
  81. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +29 -0
  82. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +41 -0
  83. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +17 -0
  84. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +108 -0
  85. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8Mintable.sol +32 -0
  86. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +53 -0
  87. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +56 -0
  88. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +24 -0
  89. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +55 -0
  90. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityConstants.sol +6 -0
  91. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +252 -0
  92. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Mintable.sol +36 -0
  93. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableCore.sol +29 -0
  94. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInit.sol +24 -0
  95. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +44 -0
  96. package/contracts/LSP9Vault/LSP9Constants.sol +12 -0
  97. package/contracts/LSP9Vault/LSP9Vault.sol +56 -0
  98. package/contracts/LSP9Vault/LSP9VaultCore.sol +174 -0
  99. package/contracts/LSP9Vault/LSP9VaultInit.sol +19 -0
  100. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +60 -0
  101. package/contracts/UniversalProfile.sol +37 -0
  102. package/contracts/UniversalProfileCore.sol +56 -0
  103. package/contracts/UniversalProfileInit.sol +19 -0
  104. package/contracts/UniversalProfileInitAbstract.sol +48 -0
  105. package/contracts/Utils/ERC725Utils.sol +169 -0
  106. package/contracts/Utils/LSP2Utils.sol +127 -0
  107. package/contracts/Utils/LSP6Utils.sol +77 -0
  108. package/contracts/Utils/UtilsLib.sol +23 -0
  109. package/package.json +84 -0
@@ -0,0 +1,444 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.6;
3
+
4
+ // modules
5
+ import "@erc725/smart-contracts/contracts/ERC725Y.sol";
6
+ import "@erc725/smart-contracts/contracts/ERC725.sol";
7
+ import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
8
+
9
+ // interfaces
10
+ import "./ILSP6KeyManager.sol";
11
+
12
+ // libraries
13
+ import "../Utils/LSP6Utils.sol";
14
+
15
+ import "../Utils/ERC725Utils.sol";
16
+ import "@openzeppelin/contracts/utils/Address.sol";
17
+ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
18
+ import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
19
+
20
+ // constants
21
+ import "./LSP6Constants.sol";
22
+ import "../LSP0ERC725Account/LSP0Constants.sol";
23
+ import "@erc725/smart-contracts/contracts/constants.sol";
24
+
25
+ /**
26
+ * @dev address `from` is not authorised to `permission`
27
+ * @param permission permission required
28
+ * @param from address not-authorised
29
+ */
30
+ error NotAuthorised(address from, string permission);
31
+
32
+ /**
33
+ * @dev address `from` is not authorised to interact with `disallowedAddress` via account
34
+ * @param from address making the request
35
+ * @param disallowedAddress address that `from` is not authorised to call
36
+ */
37
+ error NotAllowedAddress(address from, address disallowedAddress);
38
+
39
+ /**
40
+ * @dev address `from` is not authorised to run `disallowedFunction` via account
41
+ * @param from address making the request
42
+ * @param disallowedFunction bytes4 function selector that `from` is not authorised to run
43
+ */
44
+ error NotAllowedFunction(address from, bytes4 disallowedFunction);
45
+
46
+ /**
47
+ * @title Core implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage
48
+ * @author Fabian Vogelsteller, Jean Cavallera
49
+ * @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below
50
+ */
51
+ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
52
+ using ERC725Utils for ERC725Y;
53
+ using LSP6Utils for ERC725;
54
+ using Address for address;
55
+ using ECDSA for bytes32;
56
+ using ERC165Checker for address;
57
+
58
+ ERC725 public account;
59
+ mapping(address => mapping(uint256 => uint256)) internal _nonceStore;
60
+
61
+ /**
62
+ * @dev See {IERC165-supportsInterface}.
63
+ */
64
+ function supportsInterface(bytes4 interfaceId)
65
+ public
66
+ view
67
+ virtual
68
+ override(ERC165Storage)
69
+ returns (bool)
70
+ {
71
+ return
72
+ interfaceId == _INTERFACE_ID_ERC1271 ||
73
+ super.supportsInterface(interfaceId);
74
+ }
75
+
76
+ /**
77
+ * @inheritdoc ILSP6KeyManager
78
+ */
79
+ function getNonce(address _from, uint256 _channel)
80
+ public
81
+ view
82
+ override
83
+ returns (uint256)
84
+ {
85
+ uint128 nonceId = uint128(_nonceStore[_from][_channel]);
86
+ return (uint256(_channel) << 128) | nonceId;
87
+ }
88
+
89
+ /**
90
+ * @inheritdoc IERC1271
91
+ */
92
+ function isValidSignature(bytes32 _hash, bytes memory _signature)
93
+ public
94
+ view
95
+ override
96
+ returns (bytes4 magicValue)
97
+ {
98
+ address recoveredAddress = ECDSA.recover(_hash, _signature);
99
+ return
100
+ (_PERMISSION_SIGN & account.getPermissionsFor(recoveredAddress)) ==
101
+ _PERMISSION_SIGN
102
+ ? _INTERFACE_ID_ERC1271
103
+ : _ERC1271FAILVALUE;
104
+ }
105
+
106
+ /**
107
+ * @inheritdoc ILSP6KeyManager
108
+ */
109
+ function execute(bytes calldata _data)
110
+ external
111
+ payable
112
+ override
113
+ returns (bytes memory)
114
+ {
115
+ _verifyPermissions(msg.sender, _data);
116
+
117
+ // solhint-disable avoid-low-level-calls
118
+ (bool success, bytes memory result_) = address(account).call{
119
+ value: msg.value,
120
+ gas: gasleft()
121
+ }(_data);
122
+
123
+ if (!success) {
124
+ // solhint-disable reason-string
125
+ if (result_.length < 68) revert();
126
+
127
+ // solhint-disable no-inline-assembly
128
+ assembly {
129
+ result_ := add(result_, 0x04)
130
+ }
131
+ revert(abi.decode(result_, (string)));
132
+ }
133
+
134
+ emit Executed(msg.value, _data);
135
+ return result_.length > 0 ? abi.decode(result_, (bytes)) : result_;
136
+ }
137
+
138
+ /**
139
+ * @inheritdoc ILSP6KeyManager
140
+ */
141
+ function executeRelayCall(
142
+ address _signedFor,
143
+ uint256 _nonce,
144
+ bytes calldata _data,
145
+ bytes memory _signature
146
+ ) external payable override returns (bytes memory) {
147
+ require(
148
+ _signedFor == address(this),
149
+ "executeRelayCall: Message not signed for this keyManager"
150
+ );
151
+
152
+ bytes memory blob = abi.encodePacked(
153
+ address(this), // needs to be signed for this keyManager
154
+ _nonce,
155
+ _data
156
+ );
157
+
158
+ address signer = keccak256(blob).toEthSignedMessageHash().recover(
159
+ _signature
160
+ );
161
+
162
+ require(
163
+ _isValidNonce(signer, _nonce),
164
+ "executeRelayCall: Invalid nonce"
165
+ );
166
+
167
+ // increase nonce after successful verification
168
+ _nonceStore[signer][_nonce >> 128]++;
169
+
170
+ _verifyPermissions(signer, _data);
171
+
172
+ // solhint-disable avoid-low-level-calls
173
+ (bool success, bytes memory result_) = address(account).call{
174
+ value: 0,
175
+ gas: gasleft()
176
+ }(_data);
177
+
178
+ if (!success) {
179
+ // solhint-disable reason-string
180
+ if (result_.length < 68) revert();
181
+
182
+ // solhint-disable no-inline-assembly
183
+ assembly {
184
+ result_ := add(result_, 0x04)
185
+ }
186
+ revert(abi.decode(result_, (string)));
187
+ }
188
+
189
+ emit Executed(msg.value, _data);
190
+ return result_.length > 0 ? abi.decode(result_, (bytes)) : result_;
191
+ }
192
+
193
+ /**
194
+ * @notice verify the nonce `_idx` for `_from` (obtained via `getNonce(...)`)
195
+ * @dev "idx" is a 256bits (unsigned) integer, where:
196
+ * - the 128 leftmost bits = channelId
197
+ * and - the 128 rightmost bits = nonce within the channel
198
+ * @param _from caller address
199
+ * @param _idx (channel id + nonce within the channel)
200
+ */
201
+ function _isValidNonce(address _from, uint256 _idx)
202
+ internal
203
+ view
204
+ returns (bool)
205
+ {
206
+ // idx % (1 << 128) = nonce
207
+ // (idx >> 128) = channel
208
+ // equivalent to: return (nonce == _nonceStore[_from][channel]
209
+ return (_idx % (1 << 128)) == (_nonceStore[_from][_idx >> 128]);
210
+ }
211
+
212
+ /**
213
+ * @dev verify the permissions of the _from address that want to interact with the `account`
214
+ * @param _from the address making the request
215
+ * @param _data the payload that will be run on `account`
216
+ */
217
+ function _verifyPermissions(address _from, bytes calldata _data)
218
+ internal
219
+ view
220
+ {
221
+ bytes4 erc725Function = bytes4(_data[:4]);
222
+
223
+ if (erc725Function == account.setData.selector) {
224
+ _verifyCanSetData(_from, _data);
225
+ } else if (erc725Function == account.execute.selector) {
226
+ _verifyCanExecute(_from, _data);
227
+
228
+ address to = address(bytes20(_data[48:68]));
229
+ _verifyAllowedAddress(_from, to);
230
+
231
+ if (to.isContract()) {
232
+ _verifyAllowedStandard(_from, to);
233
+
234
+ if (_data.length >= 168) {
235
+ // extract bytes4 function selector from payload
236
+ _verifyAllowedFunction(_from, bytes4(_data[164:168]));
237
+ }
238
+ }
239
+ } else if (erc725Function == account.transferOwnership.selector) {
240
+ bytes32 permissions = account.getPermissionsFor(_from);
241
+
242
+ _hasPermission(_PERMISSION_CHANGEOWNER, permissions) ||
243
+ _notAuthorised(_from, "TRANSFEROWNERSHIP");
244
+ } else {
245
+ revert("_verifyPermissions: unknown ERC725 selector");
246
+ }
247
+ }
248
+
249
+ /**
250
+ * @dev verify if `_from` has the required permissions to set some keys
251
+ * on the linked ERC725Account
252
+ * @param _from the address who want to set the keys
253
+ * @param _data the ABI encoded payload `account.setData(keys, values)`
254
+ * containing a list of keys-value pairs
255
+ */
256
+ function _verifyCanSetData(address _from, bytes calldata _data)
257
+ internal
258
+ view
259
+ {
260
+ bytes32 permissions = account.getPermissionsFor(_from);
261
+
262
+ uint256 keyCount = uint256(bytes32(_data[68:100]));
263
+ uint256 pointer = 100;
264
+
265
+ // loop through the keys
266
+ for (uint256 ii = 0; ii < keyCount; ii++) {
267
+ bytes32 key = bytes32(_data[pointer:pointer + 32]);
268
+
269
+ // check if the key is related to setting permissions
270
+ if (bytes8(key) == _SET_PERMISSIONS) {
271
+ bool isNewAddress = bytes32(
272
+ ERC725Y(account).getDataSingle(key)
273
+ ) == bytes32(0);
274
+
275
+ if (isNewAddress) {
276
+ _hasPermission(_PERMISSION_ADDPERMISSIONS, permissions) ||
277
+ _notAuthorised(_from, "ADDPERMISSIONS");
278
+ } else {
279
+ // prettier-ignore
280
+ _hasPermission(_PERMISSION_CHANGEPERMISSIONS, permissions) ||
281
+ _notAuthorised(_from, "CHANGEPERMISSIONS");
282
+ }
283
+ } else {
284
+ _hasPermission(_PERMISSION_SETDATA, permissions) ||
285
+ _notAuthorised(_from, "SETDATA");
286
+ }
287
+
288
+ pointer += 32; // move calldata pointer
289
+ }
290
+ }
291
+
292
+ /**
293
+ * @dev verify if `_from` has the required permissions to make an external call
294
+ * via the linked ERC725Account
295
+ * @param _from the address who want to run the execute function on the ERC725Account
296
+ * @param _data the ABI encoded payload `account.execute(...)`
297
+ */
298
+ function _verifyCanExecute(address _from, bytes calldata _data)
299
+ internal
300
+ view
301
+ {
302
+ bytes32 permissions = account.getPermissionsFor(_from);
303
+
304
+ uint256 operationType = uint256(bytes32(_data[4:36]));
305
+ uint256 value = uint256(bytes32(_data[68:100]));
306
+
307
+ require(
308
+ operationType != 4,
309
+ "_verifyCanExecute: operation 4 `DELEGATECALL` not supported"
310
+ );
311
+
312
+ (
313
+ bytes32 permissionRequired,
314
+ string memory operationName
315
+ ) = _extractPermissionFromOperation(operationType);
316
+
317
+ _hasPermission(permissionRequired, permissions) ||
318
+ _notAuthorised(_from, operationName);
319
+
320
+ if (
321
+ (value > 0) &&
322
+ !_hasPermission(_PERMISSION_TRANSFERVALUE, permissions)
323
+ ) _notAuthorised(_from, "TRANSFERVALUE");
324
+ }
325
+
326
+ /**
327
+ * @dev verify if `_from` is authorised to use the linked ERC725Account
328
+ * to interact with address `_to`
329
+ * @param _from the caller address
330
+ * @param _to the address to interact with
331
+ */
332
+ function _verifyAllowedAddress(address _from, address _to) internal view {
333
+ bytes memory allowedAddresses = account.getAllowedAddressesFor(_from);
334
+
335
+ // whitelist any address if nothing in the list
336
+ if (allowedAddresses.length == 0) return;
337
+
338
+ address[] memory allowedAddressesList = abi.decode(
339
+ allowedAddresses,
340
+ (address[])
341
+ );
342
+
343
+ for (uint256 ii = 0; ii < allowedAddressesList.length; ii++) {
344
+ if (_to == allowedAddressesList[ii]) return;
345
+ }
346
+ revert NotAllowedAddress(_from, _to);
347
+ }
348
+
349
+ function _verifyAllowedStandard(address _from, address to) internal view {
350
+ bytes memory allowedStandards = account.getAllowedStandardsFor(_from);
351
+
352
+ // whitelist any standard interface if nothing in the list
353
+ if (allowedStandards.length == 0) return;
354
+
355
+ bytes4[] memory allowedStandardsList = abi.decode(
356
+ allowedStandards,
357
+ (bytes4[])
358
+ );
359
+
360
+ for (uint256 ii = 0; ii < allowedStandardsList.length; ii++) {
361
+ if (to.supportsInterface(allowedStandardsList[ii])) return;
362
+ }
363
+ revert("Not Allowed Standards");
364
+ }
365
+
366
+ /**
367
+ * @dev verify if `_from` is authorised to use the linked ERC725Account
368
+ * to run a specific function `_functionSelector` at a target contract
369
+ * @param _from the caller address
370
+ * @param _functionSelector the bytes4 function selector of the function to run
371
+ * at the target contract
372
+ */
373
+ function _verifyAllowedFunction(address _from, bytes4 _functionSelector)
374
+ internal
375
+ view
376
+ {
377
+ bytes memory allowedFunctions = account.getAllowedFunctionsFor(_from);
378
+
379
+ // whitelist any function if nothing in the list
380
+ if (allowedFunctions.length == 0) return;
381
+
382
+ bytes4[] memory allowedFunctionsList = abi.decode(
383
+ allowedFunctions,
384
+ (bytes4[])
385
+ );
386
+
387
+ for (uint256 ii = 0; ii < allowedFunctionsList.length; ii++) {
388
+ if (_functionSelector == allowedFunctionsList[ii]) return;
389
+ }
390
+ revert NotAllowedFunction(_from, _functionSelector);
391
+ }
392
+
393
+ /**
394
+ * @dev compare the permissions `_addressPermission` of an address with `_requiredPermission`
395
+ * @param _requiredPermission the permission required
396
+ * @param _addressPermission the permission of address that we want to check
397
+ * @return true if address has enough permissions, false otherwise
398
+ */
399
+ function _hasPermission(
400
+ bytes32 _requiredPermission,
401
+ bytes32 _addressPermission
402
+ ) internal pure returns (bool) {
403
+ return
404
+ (_requiredPermission & _addressPermission) == _requiredPermission
405
+ ? true
406
+ : false;
407
+ }
408
+
409
+ /**
410
+ * @dev extract the required permission + a descriptive string, based on the `_operationType`
411
+ * being run via ERC725Account.execute(...)
412
+ * @param _operationType 0 = CALL, 1 = CREATE, 2 = CREATE2, etc... See ERC725X docs for more infos.
413
+ * @return bytes32 the permission associated with the `_operationType`
414
+ * @return string the opcode associated with `_operationType`
415
+ */
416
+ function _extractPermissionFromOperation(uint256 _operationType)
417
+ internal
418
+ pure
419
+ returns (bytes32, string memory)
420
+ {
421
+ require(
422
+ _operationType < 5,
423
+ "_extractPermissionFromOperation: invalid operation type"
424
+ );
425
+
426
+ if (_operationType == 0) return (_PERMISSION_CALL, "CALL");
427
+ if (_operationType == 1) return (_PERMISSION_DEPLOY, "CREATE");
428
+ if (_operationType == 2) return (_PERMISSION_DEPLOY, "CREATE2");
429
+ if (_operationType == 3) return (_PERMISSION_DEPLOY, "STATICCALL");
430
+ }
431
+
432
+ /**
433
+ * @dev return a boolean here to allow short-circuiting syntax && or ||
434
+ * eg1: _hasEnoughPermissions(...) || revert NotAuthorized(...)
435
+ * eg2: _isNotAdmin(...) && revert NotAuthorised(...)
436
+ */
437
+ function _notAuthorised(address _from, string memory _permission)
438
+ private
439
+ pure
440
+ returns (bool)
441
+ {
442
+ revert NotAuthorised(_from, _permission);
443
+ }
444
+ }
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.6;
3
+
4
+ // modules
5
+ import "./LSP6KeyManagerInitAbstract.sol";
6
+
7
+ /**
8
+ * @title Proxy implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage
9
+ * @author Fabian Vogelsteller, Jean Cavallera
10
+ * @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below
11
+ */
12
+ contract LSP6KeyManagerInit is LSP6KeyManagerInitAbstract {
13
+ /**
14
+ * @inheritdoc LSP6KeyManagerInitAbstract
15
+ */
16
+ function initialize(address _account) public virtual override initializer {
17
+ LSP6KeyManagerInitAbstract.initialize(_account);
18
+ }
19
+ }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.6;
3
+
4
+ // modules
5
+ import "./LSP6KeyManagerCore.sol";
6
+ import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
7
+ import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
8
+
9
+ /**
10
+ * @title Proxy implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage
11
+ * @author Fabian Vogelsteller, Jean Cavallera
12
+ * @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below
13
+ */
14
+ abstract contract LSP6KeyManagerInitAbstract is
15
+ Initializable,
16
+ LSP6KeyManagerCore
17
+ {
18
+ /**
19
+ * @notice Initiate the account with the address of the ERC725Account contract and sets LSP6KeyManager InterfaceId
20
+ * @param _account The address of the ER725Account to control
21
+ */
22
+ function initialize(address _account) public virtual onlyInitializing {
23
+ account = ERC725(_account);
24
+ _registerInterface(_INTERFACEID_LSP6);
25
+ }
26
+ }
@@ -0,0 +1,186 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // interfaces
6
+ import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
7
+ import "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
8
+
9
+ /**
10
+ * @dev Required interface of a LSP8 compliant contract.
11
+ */
12
+ interface ILSP7DigitalAsset is IERC165, IERC725Y {
13
+ // --- Events
14
+
15
+ /**
16
+ * @dev Emitted when `amount` tokens is transferred from `from` to `to`.
17
+ * @param operator The address of operator sending tokens
18
+ * @param from The address which tokens are sent
19
+ * @param to The receiving address
20
+ * @param amount The amount of tokens transferred
21
+ * @param force When set to TRUE, `to` may be any address but
22
+ * when set to FALSE `to` must be a contract that supports LSP1 UniversalReceiver
23
+ * @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses
24
+ */
25
+ event Transfer(
26
+ address indexed operator,
27
+ address indexed from,
28
+ address indexed to,
29
+ uint256 amount,
30
+ bool force,
31
+ bytes data
32
+ );
33
+
34
+ /**
35
+ * @dev Emitted when `tokenOwner` enables `operator` for `amount` tokens.
36
+ * @param operator The address authorized as an operator
37
+ * @param tokenOwner The token owner
38
+ * @param amount The amount of tokens `operator` address has access to from `tokenOwner`
39
+ */
40
+ event AuthorizedOperator(
41
+ address indexed operator,
42
+ address indexed tokenOwner,
43
+ uint256 indexed amount
44
+ );
45
+
46
+ /**
47
+ * @dev Emitted when `tokenOwner` disables `operator` for `amount` tokens.
48
+ * @param operator The address revoked from operating
49
+ * @param tokenOwner The token owner
50
+ */
51
+ event RevokedOperator(address indexed operator, address indexed tokenOwner);
52
+
53
+ // --- Token queries
54
+
55
+ /**
56
+ * @dev Returns the number of decimals used to get its user representation
57
+ * If the contract represents a NFT then 0 SHOULD be used, otherwise 18 is the common value
58
+ *
59
+ * NOTE: This information is only used for _display_ purposes: it in
60
+ * no way affects any of the arithmetic of the contract, including
61
+ * {balanceOf} and {transfer}.
62
+ */
63
+ function decimals() external view returns (uint256);
64
+
65
+ /**
66
+ * @dev Returns the number of existing tokens.
67
+ * @return The number of existing tokens
68
+ */
69
+ function totalSupply() external view returns (uint256);
70
+
71
+ // --- Token owner queries
72
+
73
+ /**
74
+ * @dev Returns the number of tokens owned by `tokenOwner`.
75
+ * @param tokenOwner The address to query
76
+ * @return The number of tokens owned by this address
77
+ */
78
+ function balanceOf(address tokenOwner) external view returns (uint256);
79
+
80
+ // --- Operator functionality
81
+
82
+ /**
83
+ * @param operator The address to authorize as an operator.
84
+ * @param amount The amount of tokens operator has access to.
85
+ * @dev Sets `amount` as the amount of tokens `operator` address has access to from callers tokens.
86
+ *
87
+ * See {isOperatorFor}.
88
+ *
89
+ * Requirements
90
+ *
91
+ * - `operator` cannot be calling address.
92
+ * - `operator` cannot be the zero address.
93
+ *
94
+ * Emits an {AuthorizedOperator} event.
95
+ */
96
+ function authorizeOperator(address operator, uint256 amount) external;
97
+
98
+ /**
99
+ * @param operator The address to revoke as an operator.
100
+ * @dev Removes `operator` address as an operator of callers tokens.
101
+ *
102
+ * See {isOperatorFor}.
103
+ *
104
+ * Requirements
105
+ *
106
+ * - `operator` cannot be calling address.
107
+ * - `operator` cannot be the zero address.
108
+ *
109
+ * Emits a {RevokedOperator} event.
110
+ */
111
+ function revokeOperator(address operator) external;
112
+
113
+ /**
114
+ * @param operator The address to query operator status for.
115
+ * @param tokenOwner The token owner.
116
+ * @return The amount of tokens `operator` address has access to from `tokenOwner`.
117
+ * @dev Returns amount of tokens `operator` address has access to from `tokenOwner`.
118
+ * Operators can send and burn tokens on behalf of their owners. The tokenOwner is their own
119
+ * operator.
120
+ */
121
+ function isOperatorFor(address operator, address tokenOwner)
122
+ external
123
+ view
124
+ returns (uint256);
125
+
126
+ // --- Transfer functionality
127
+
128
+ /**
129
+ * @param from The sending address.
130
+ * @param to The receiving address.
131
+ * @param amount The amount of tokens to transfer.
132
+ * @param force When set to TRUE, to may be any address but
133
+ * when set to FALSE to must be a contract that supports LSP1 UniversalReceiver
134
+ * @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
135
+ *
136
+ * @dev Transfers `amount` of tokens from `from` to `to`. The `force` parameter will be used
137
+ * when notifying the token sender and receiver.
138
+ *
139
+ * Requirements:
140
+ *
141
+ * - `from` cannot be the zero address.
142
+ * - `to` cannot be the zero address.
143
+ * - `amount` tokens must be owned by `from`.
144
+ * - If the caller is not `from`, it must be an operator for `from` with access to at least
145
+ * `amount` tokens.
146
+ *
147
+ * Emits a {Transfer} event.
148
+ */
149
+ function transfer(
150
+ address from,
151
+ address to,
152
+ uint256 amount,
153
+ bool force,
154
+ bytes memory data
155
+ ) external;
156
+
157
+ /**
158
+ * @param from The list of sending addresses.
159
+ * @param to The list of receiving addresses.
160
+ * @param amount The amount of tokens to transfer.
161
+ * @param force When set to TRUE, to may be any address but
162
+ * when set to FALSE to must be a contract that supports LSP1 UniversalReceiver
163
+ * @param data Additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
164
+ *
165
+ * @dev Transfers many tokens based on the list `from`, `to`, `amount`. If any transfer fails
166
+ * the call will revert.
167
+ *
168
+ * Requirements:
169
+ *
170
+ * - `from`, `to`, `amount` lists are the same length.
171
+ * - no values in `from` can be the zero address.
172
+ * - no values in `to` can be the zero address.
173
+ * - each `amount` tokens must be owned by `from`.
174
+ * - If the caller is not `from`, it must be an operator for `from` with access to at least
175
+ * `amount` tokens.
176
+ *
177
+ * Emits {Transfer} events.
178
+ */
179
+ function transferBatch(
180
+ address[] memory from,
181
+ address[] memory to,
182
+ uint256[] memory amount,
183
+ bool force,
184
+ bytes[] memory data
185
+ ) external;
186
+ }
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: CC0-1.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // --- ERC165 interface ids
5
+ bytes4 constant _INTERFACEID_LSP7 = 0xe33f65c3;
6
+
7
+ // --- ERC725Y entries
8
+
9
+ // --- Token Hooks
10
+ bytes32 constant _TYPEID_LSP7_TOKENSSENDER = 0x40b8bec57d7b5ff0dbd9e9acd0a47dfeb0101e1a203766f5ccab00445fbf39e9; // keccak256("LSP7TokensSender")
11
+
12
+ bytes32 constant _TYPEID_LSP7_TOKENSRECIPIENT = 0xdbe2c314e1aee2970c72666f2ebe8933a8575263ea71e5ff6a9178e95d47a26f; // keccak256("LSP7TokensRecipient")