@lukso/lsp-smart-contracts 0.4.3 → 0.5.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.
Files changed (49) hide show
  1. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -2
  2. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +2 -2
  3. package/artifacts/LSP6KeyManager.json +18 -2
  4. package/artifacts/LSP6KeyManagerInit.json +18 -2
  5. package/artifacts/LSP7CompatibilityForERC20.json +78 -2
  6. package/artifacts/LSP7DigitalAsset.json +2 -2
  7. package/artifacts/LSP7DigitalAssetInit.json +2 -2
  8. package/artifacts/LSP7Mintable.json +2 -2
  9. package/artifacts/LSP7MintableInit.json +2 -2
  10. package/artifacts/LSP8CompatibilityForERC721.json +11 -6
  11. package/artifacts/LSP8IdentifiableDigitalAsset.json +2 -2
  12. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +2 -2
  13. package/artifacts/LSP8Mintable.json +2 -2
  14. package/artifacts/LSP8MintableInit.json +2 -2
  15. package/artifacts/UniversalProfile.json +2 -34
  16. package/artifacts/UniversalProfileInit.json +2 -34
  17. package/constants.ts +6 -0
  18. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +1 -1
  19. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +3 -3
  20. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +2 -2
  21. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +13 -0
  22. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +2 -2
  23. package/contracts/LSP6KeyManager/LSP6Constants.sol +2 -1
  24. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +166 -48
  25. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +1 -1
  26. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +0 -2
  27. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +2 -2
  28. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +20 -2
  29. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +1 -1
  30. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +2 -2
  31. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +25 -45
  32. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Core.sol +126 -0
  33. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol +22 -0
  34. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +55 -0
  35. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +2 -2
  36. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +2 -2
  37. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +14 -11
  38. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +2 -2
  39. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +2 -2
  40. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +25 -185
  41. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Core.sol +244 -0
  42. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol +27 -0
  43. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +90 -0
  44. package/contracts/LSP9Vault/LSP9VaultCore.sol +1 -1
  45. package/contracts/UniversalProfile.sol +1 -15
  46. package/contracts/UniversalProfileInitAbstract.sol +1 -16
  47. package/contracts/Utils/LSP6Utils.sol +0 -14
  48. package/package.json +1 -1
  49. package/contracts/UniversalProfileCore.sol +0 -56
@@ -16,6 +16,7 @@ import "../Utils/ERC725Utils.sol";
16
16
  import "@openzeppelin/contracts/utils/Address.sol";
17
17
  import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
18
18
  import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
19
+ import "solidity-bytes-utils/contracts/BytesLib.sol";
19
20
 
20
21
  // constants
21
22
  import "./LSP6Constants.sol";
@@ -43,6 +44,13 @@ error NotAllowedAddress(address from, address disallowedAddress);
43
44
  */
44
45
  error NotAllowedFunction(address from, bytes4 disallowedFunction);
45
46
 
47
+ /**
48
+ * @dev address `from` is not authorised to set the key `disallowedKey` on the account
49
+ * @param from address making the request
50
+ * @param disallowedKey a bytes32 key that `from` is not authorised to set on the ERC725Y storage
51
+ */
52
+ error NotAllowedERC725YKey(address from, bytes32 disallowedKey);
53
+
46
54
  /**
47
55
  * @title Core implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage
48
56
  * @author Fabian Vogelsteller, Jean Cavallera
@@ -50,6 +58,7 @@ error NotAllowedFunction(address from, bytes4 disallowedFunction);
50
58
  */
51
59
  abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
52
60
  using ERC725Utils for ERC725Y;
61
+ using LSP2Utils for ERC725Y;
53
62
  using LSP6Utils for ERC725;
54
63
  using Address for address;
55
64
  using ECDSA for bytes32;
@@ -239,8 +248,8 @@ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
239
248
  } else if (erc725Function == account.transferOwnership.selector) {
240
249
  bytes32 permissions = account.getPermissionsFor(_from);
241
250
 
242
- _hasPermission(_PERMISSION_CHANGEOWNER, permissions) ||
243
- _notAuthorised(_from, "TRANSFEROWNERSHIP");
251
+ if (!_hasPermission(_PERMISSION_CHANGEOWNER, permissions))
252
+ revert NotAuthorised(_from, "TRANSFEROWNERSHIP");
244
253
  } else {
245
254
  revert("_verifyPermissions: unknown ERC725 selector");
246
255
  }
@@ -259,34 +268,127 @@ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
259
268
  {
260
269
  bytes32 permissions = account.getPermissionsFor(_from);
261
270
 
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
- }
271
+ (bytes32[] memory inputKeys, ) = abi.decode(
272
+ _data[4:],
273
+ (bytes32[], bytes[])
274
+ );
275
+
276
+ bool isSettingERC725YKeys = false;
277
+
278
+ // loop through the keys we are trying to set
279
+ for (uint256 ii = 0; ii < inputKeys.length; ii++) {
280
+ bytes32 key = inputKeys[ii];
281
+
282
+ // prettier-ignore
283
+ // if the key is a permission key
284
+ if (bytes8(key) == _SET_PERMISSIONS_PREFIX) {
285
+ _verifyCanSetPermissions(key, _from, permissions);
286
+
287
+ // "nullify permission keys,
288
+ // so that they do not get check against allowed ERC725Y keys
289
+ inputKeys[ii] = bytes32(0);
290
+
291
+ // if the key is any other bytes32 key
283
292
  } else {
284
- _hasPermission(_PERMISSION_SETDATA, permissions) ||
285
- _notAuthorised(_from, "SETDATA");
293
+ isSettingERC725YKeys = true;
294
+ }
295
+ }
296
+
297
+ if (isSettingERC725YKeys) {
298
+ if (!_hasPermission(_PERMISSION_SETDATA, permissions))
299
+ revert NotAuthorised(_from, "SETDATA");
300
+
301
+ _verifyAllowedERC725YKeys(_from, inputKeys);
302
+ }
303
+ }
304
+
305
+ function _verifyCanSetPermissions(
306
+ bytes32 _key,
307
+ address _from,
308
+ bytes32 _callerPermissions
309
+ ) internal view {
310
+ // prettier-ignore
311
+ // check if some permissions are already stored under this key
312
+ if (bytes32(ERC725Y(account).getDataSingle(_key)) == bytes32(0)) {
313
+ // if nothing is stored under this key,
314
+ // we are trying to ADD permissions for a NEW address
315
+ if (!_hasPermission(_PERMISSION_ADDPERMISSIONS, _callerPermissions))
316
+ revert NotAuthorised(_from, "ADDPERMISSIONS");
317
+ } else {
318
+ // if there are already a value stored under this key,
319
+ // we are trying to CHANGE the permissions of an address
320
+ // (that has already some EXISTING permissions set)
321
+ if (!_hasPermission(_PERMISSION_CHANGEPERMISSIONS, _callerPermissions))
322
+ revert NotAuthorised(_from, "CHANGEPERMISSIONS");
323
+ }
324
+ }
325
+
326
+ function _verifyAllowedERC725YKeys(
327
+ address _from,
328
+ bytes32[] memory _inputKeys
329
+ ) internal view {
330
+ bytes memory allowedERC725YKeysEncoded = ERC725Y(account).getDataSingle(
331
+ LSP2Utils.generateBytes20MappingWithGroupingKey(
332
+ _ADDRESS_ALLOWEDERC725YKEYS,
333
+ bytes20(_from)
334
+ )
335
+ );
336
+
337
+ // whitelist any ERC725Y key if nothing in the list
338
+ if (allowedERC725YKeysEncoded.length == 0) return;
339
+
340
+ bytes32[] memory allowedERC725YKeys = abi.decode(
341
+ allowedERC725YKeysEncoded,
342
+ (bytes32[])
343
+ );
344
+
345
+ bytes memory allowedKeySlice;
346
+ bytes memory inputKeySlice;
347
+ uint256 sliceLength;
348
+
349
+ bool isAllowedKey;
350
+
351
+ // save the not allowed key for cusom revert error
352
+ bytes32 notAllowedKey;
353
+
354
+ // loop through each allowed ERC725Y key retrieved from storage
355
+ for (uint256 ii = 0; ii < allowedERC725YKeys.length; ii++) {
356
+ // save the length of the slice
357
+ // so to know which part to compare for each key we are trying to set
358
+ (allowedKeySlice, sliceLength) = _extractKeySlice(
359
+ allowedERC725YKeys[ii]
360
+ );
361
+
362
+ // loop through each keys given as input
363
+ for (uint256 jj = 0; jj < _inputKeys.length; jj++) {
364
+ // skip permissions keys that have been "nulled" previously
365
+ if (_inputKeys[jj] == bytes32(0)) continue;
366
+
367
+ // extract the slice to compare with the allowed key
368
+ inputKeySlice = BytesLib.slice(
369
+ bytes.concat(_inputKeys[jj]),
370
+ 0,
371
+ sliceLength
372
+ );
373
+
374
+ isAllowedKey =
375
+ keccak256(allowedKeySlice) == keccak256(inputKeySlice);
376
+
377
+ // if the keys match, the key is allowed so stop iteration
378
+ if (isAllowedKey) break;
379
+
380
+ // if the keys do not match, save this key as a not allowed key
381
+ notAllowedKey = _inputKeys[jj];
286
382
  }
287
383
 
288
- pointer += 32; // move calldata pointer
384
+ // if after checking all the keys given as input we did not find any not allowed key
385
+ // stop checking the other allowed ERC725Y keys
386
+ if (isAllowedKey == true) break;
289
387
  }
388
+
389
+ // we always revert with the last not-allowed key that we found in the keys given as inputs
390
+ if (isAllowedKey == false)
391
+ revert NotAllowedERC725YKey(_from, notAllowedKey);
290
392
  }
291
393
 
292
394
  /**
@@ -314,18 +416,19 @@ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
314
416
  string memory operationName
315
417
  ) = _extractPermissionFromOperation(operationType);
316
418
 
317
- _hasPermission(permissionRequired, permissions) ||
318
- _notAuthorised(_from, operationName);
419
+ if (!_hasPermission(permissionRequired, permissions))
420
+ revert NotAuthorised(_from, operationName);
319
421
 
320
422
  if (
321
423
  (value > 0) &&
322
424
  !_hasPermission(_PERMISSION_TRANSFERVALUE, permissions)
323
- ) _notAuthorised(_from, "TRANSFERVALUE");
425
+ ) {
426
+ revert NotAuthorised(_from, "TRANSFERVALUE");
427
+ }
324
428
  }
325
429
 
326
430
  /**
327
- * @dev verify if `_from` is authorised to use the linked ERC725Account
328
- * to interact with address `_to`
431
+ * @dev verify if `_from` is authorised to interact with address `_to` via the linked ERC725Account
329
432
  * @param _from the caller address
330
433
  * @param _to the address to interact with
331
434
  */
@@ -346,10 +449,21 @@ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
346
449
  revert NotAllowedAddress(_from, _to);
347
450
  }
348
451
 
349
- function _verifyAllowedStandard(address _from, address to) internal view {
350
- bytes memory allowedStandards = account.getAllowedStandardsFor(_from);
452
+ /**
453
+ * @dev if `_from` is restricted to interact with contracts that implement a specific interface,
454
+ * verify that `_to` implements one of these interface.
455
+ * @param _from the caller address
456
+ * @param _to the address of the contract to interact with
457
+ */
458
+ function _verifyAllowedStandard(address _from, address _to) internal view {
459
+ bytes memory allowedStandards = ERC725Y(account).getDataSingle(
460
+ LSP2Utils.generateBytes20MappingWithGroupingKey(
461
+ _ADDRESS_ALLOWEDSTANDARDS,
462
+ bytes20(_from)
463
+ )
464
+ );
351
465
 
352
- // whitelist any standard interface if nothing in the list
466
+ // whitelist any standard interface (ERC165) if nothing in the list
353
467
  if (allowedStandards.length == 0) return;
354
468
 
355
469
  bytes4[] memory allowedStandardsList = abi.decode(
@@ -358,7 +472,7 @@ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
358
472
  );
359
473
 
360
474
  for (uint256 ii = 0; ii < allowedStandardsList.length; ii++) {
361
- if (to.supportsInterface(allowedStandardsList[ii])) return;
475
+ if (_to.supportsInterface(allowedStandardsList[ii])) return;
362
476
  }
363
477
  revert("Not Allowed Standards");
364
478
  }
@@ -406,6 +520,23 @@ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
406
520
  : false;
407
521
  }
408
522
 
523
+ function _extractKeySlice(bytes32 _key)
524
+ internal
525
+ pure
526
+ returns (bytes memory keySlice_, uint256 sliceLength_)
527
+ {
528
+ // check each individual bytes of the allowed key, starting from the end (right to left)
529
+ for (uint256 index = 31; index >= 0; index--) {
530
+ // find where the first non-empty bytes starts (skip empty bytes 0x00)
531
+ if (_key[index] != 0x00) {
532
+ // stop as soon as we find a non-empty byte
533
+ sliceLength_ = index + 1;
534
+ keySlice_ = BytesLib.slice(bytes.concat(_key), 0, sliceLength_);
535
+ break;
536
+ }
537
+ }
538
+ }
539
+
409
540
  /**
410
541
  * @dev extract the required permission + a descriptive string, based on the `_operationType`
411
542
  * being run via ERC725Account.execute(...)
@@ -428,17 +559,4 @@ abstract contract LSP6KeyManagerCore is ILSP6KeyManager, ERC165Storage {
428
559
  if (_operationType == 2) return (_PERMISSION_DEPLOY, "CREATE2");
429
560
  if (_operationType == 3) return (_PERMISSION_DEPLOY, "STATICCALL");
430
561
  }
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
562
  }
@@ -15,7 +15,7 @@ import "@erc725/smart-contracts/contracts/ERC725Y.sol";
15
15
  * @author Matthew Stevens
16
16
  * @dev Implementation of a LSP7 compliant contract.
17
17
  */
18
- contract LSP7DigitalAsset is LSP4DigitalAssetMetadata, LSP7DigitalAssetCore {
18
+ contract LSP7DigitalAsset is LSP7DigitalAssetCore, LSP4DigitalAssetMetadata {
19
19
  /**
20
20
  * @notice Sets the token-Metadata and register LSP7InterfaceId
21
21
  * @param name_ The name of the token
@@ -25,8 +25,6 @@ import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
25
25
  * @dev Core Implementation of a LSP7 compliant contract.
26
26
  */
27
27
  abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
28
- using EnumerableSet for EnumerableSet.AddressSet;
29
- using EnumerableSet for EnumerableSet.Bytes32Set;
30
28
  using Address for address;
31
29
 
32
30
  // --- Storage
@@ -15,9 +15,9 @@ import "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol";
15
15
  * @dev Proxy Implementation of a LSP7 compliant contract.
16
16
  */
17
17
  abstract contract LSP7DigitalAssetInitAbstract is
18
+ LSP7DigitalAssetCore,
18
19
  Initializable,
19
- LSP4DigitalAssetMetadataInitAbstract,
20
- LSP7DigitalAssetCore
20
+ LSP4DigitalAssetMetadataInitAbstract
21
21
  {
22
22
  /**
23
23
  * @notice Sets the token-Metadata and register LSP7InterfaceId
@@ -9,15 +9,33 @@ import "../ILSP7DigitalAsset.sol";
9
9
  * @dev LSP8 extension, for compatibility for clients / tools that expect ERC20.
10
10
  */
11
11
  interface ILSP7CompatibilityForERC20 is ILSP7DigitalAsset {
12
+ /**
13
+ * @notice To provide compatibility with indexing ERC20 events.
14
+ * @dev Emitted when `amount` tokens is transferred from `from` to `to`.
15
+ * @param from The sending address
16
+ * @param to The receiving address
17
+ * @param value The amount of tokens transfered.
18
+ */
19
+ event Transfer(address indexed from, address indexed to, uint256 value);
20
+
21
+ /**
22
+ * @notice To provide compatibility with indexing ERC20 events.
23
+ * @dev Emitted when `owner` enables `spender` for `value` tokens.
24
+ * @param owner The account giving approval
25
+ * @param spender The account receiving approval
26
+ * @param value The amount of tokens `spender` has access to from `owner`
27
+ */
28
+ event Approval(address indexed owner, address indexed spender, uint256 value);
29
+
12
30
  /*
13
- * @dev Compatible with ERC20 tranfer
31
+ * @dev Compatible with ERC20 transfer
14
32
  * @param to The receiving address
15
33
  * @param amount The amount of tokens to transfer
16
34
  */
17
35
  function transfer(address to, uint256 amount) external;
18
36
 
19
37
  /*
20
- * @dev Compatible with ERC20 tranferFrom
38
+ * @dev Compatible with ERC20 transferFrom
21
39
  * @param from The sending address
22
40
  * @param to The receiving address
23
41
  * @param amount The amount of tokens to transfer
@@ -9,7 +9,7 @@ import "../LSP7DigitalAsset.sol";
9
9
  /**
10
10
  * @dev LSP7 extension, adds token supply cap.
11
11
  */
12
- abstract contract LSP7CappedSupply is LSP7DigitalAsset, LSP7CappedSupplyCore {
12
+ abstract contract LSP7CappedSupply is LSP7CappedSupplyCore, LSP7DigitalAsset {
13
13
  /**
14
14
  * @notice Sets the token max supply
15
15
  * @param tokenSupplyCap_ The Token max supply
@@ -11,8 +11,8 @@ import "../LSP7DigitalAssetInit.sol";
11
11
  */
12
12
  abstract contract LSP7CappedSupplyInitAbstract is
13
13
  Initializable,
14
- LSP7DigitalAssetInit,
15
- LSP7CappedSupplyCore
14
+ LSP7CappedSupplyCore,
15
+ LSP7DigitalAssetInit
16
16
  {
17
17
  /**
18
18
  * @notice Sets the token max supply
@@ -4,17 +4,9 @@ pragma solidity ^0.8.0;
4
4
 
5
5
  // modules
6
6
  import "../LSP7DigitalAsset.sol";
7
+ import "./LSP7CompatibilityForERC20Core.sol";
7
8
 
8
- // interfaces
9
- import "./ILSP7CompatibilityForERC20.sol";
10
-
11
- /**
12
- * @dev LSP7 extension, for compatibility for clients / tools that expect ERC20.
13
- */
14
- contract LSP7CompatibilityForERC20 is
15
- ILSP7CompatibilityForERC20,
16
- LSP7DigitalAsset
17
- {
9
+ contract LSP7CompatibilityForERC20 is LSP7CompatibilityForERC20Core, LSP7DigitalAsset {
18
10
  /* solhint-disable no-empty-blocks */
19
11
  /**
20
12
  * @notice Sets the name, the symbol and the owner of the token
@@ -26,51 +18,39 @@ contract LSP7CompatibilityForERC20 is
26
18
  string memory name_,
27
19
  string memory symbol_,
28
20
  address newOwner_
29
- ) LSP7DigitalAsset(name_, symbol_, newOwner_, false) {}
21
+ ) LSP7DigitalAsset(name_, symbol_, newOwner_, false) {
30
22
 
31
- /**
32
- * @inheritdoc ILSP7CompatibilityForERC20
33
- */
34
- function approve(address operator, uint256 amount)
35
- external
23
+ }
24
+
25
+ // --- Overrides
26
+
27
+ function authorizeOperator(address operator, uint256 amount)
28
+ public
36
29
  virtual
37
- override
30
+ override(LSP7DigitalAssetCore, LSP7CompatibilityForERC20Core)
38
31
  {
39
- return authorizeOperator(operator, amount);
32
+ super.authorizeOperator(operator, amount);
40
33
  }
41
34
 
42
- /**
43
- * @inheritdoc ILSP7CompatibilityForERC20
44
- */
45
- function allowance(address tokenOwner, address operator)
46
- external
47
- view
35
+ function _burn(address from, uint256 amount, bytes memory data)
36
+ internal
48
37
  virtual
49
- override
50
- returns (uint256)
38
+ override(LSP7DigitalAssetCore, LSP7CompatibilityForERC20Core)
51
39
  {
52
- return isOperatorFor(operator, tokenOwner);
40
+ super._burn(from, amount, data);
53
41
  }
54
42
 
55
- /**
56
- * @inheritdoc ILSP7CompatibilityForERC20
57
- * @dev Compatible with ERC20 transfer.
58
- * Using force=true so that EOA and any contract may receive the tokens.
59
- */
60
- function transfer(address to, uint256 amount) external virtual override {
61
- return transfer(_msgSender(), to, amount, true, "compat-transfer");
43
+ function _mint(address to, uint256 amount, bool force, bytes memory data)
44
+ internal
45
+ virtual
46
+ override(LSP7DigitalAssetCore, LSP7CompatibilityForERC20Core) {
47
+ super._mint(to, amount, force, data);
62
48
  }
63
49
 
64
- /**
65
- * @inheritdoc ILSP7CompatibilityForERC20
66
- * @dev Compatible with ERC20 transferFrom.
67
- * Using force=true so that EOA and any contract may receive the tokens.
68
- */
69
- function transferFrom(
70
- address from,
71
- address to,
72
- uint256 amount
73
- ) external virtual override {
74
- return transfer(from, to, amount, true, "compat-transferFrom");
50
+ function _transfer(address from, address to, uint256 amount, bool force, bytes memory data)
51
+ internal
52
+ virtual
53
+ override(LSP7DigitalAssetCore, LSP7CompatibilityForERC20Core) {
54
+ super._transfer(from, to, amount, force, data);
75
55
  }
76
56
  }
@@ -0,0 +1,126 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // modules
6
+ import "../../LSP4DigitalAssetMetadata/LSP4Compatibility.sol";
7
+ import "../LSP7DigitalAssetCore.sol";
8
+
9
+ // interfaces
10
+ import "./ILSP7CompatibilityForERC20.sol";
11
+
12
+ /**
13
+ * @dev LSP7 extension, for compatibility for clients / tools that expect ERC20.
14
+ */
15
+ abstract contract LSP7CompatibilityForERC20Core is
16
+ ILSP7CompatibilityForERC20,
17
+ LSP7DigitalAssetCore,
18
+ LSP4Compatibility
19
+ {
20
+ /**
21
+ * @inheritdoc ILSP7CompatibilityForERC20
22
+ */
23
+ function approve(address operator, uint256 amount)
24
+ external
25
+ virtual
26
+ override
27
+ {
28
+ return authorizeOperator(operator, amount);
29
+ }
30
+
31
+ /**
32
+ * @inheritdoc ILSP7CompatibilityForERC20
33
+ */
34
+ function allowance(address tokenOwner, address operator)
35
+ external
36
+ view
37
+ virtual
38
+ override
39
+ returns (uint256)
40
+ {
41
+ return isOperatorFor(operator, tokenOwner);
42
+ }
43
+
44
+ /**
45
+ * @inheritdoc ILSP7CompatibilityForERC20
46
+ * @dev Compatible with ERC20 transfer.
47
+ * Using force=true so that EOA and any contract may receive the tokens.
48
+ */
49
+ function transfer(address to, uint256 amount) external virtual override {
50
+ return transfer(_msgSender(), to, amount, true, "compat-transfer");
51
+ }
52
+
53
+ /**
54
+ * @inheritdoc ILSP7CompatibilityForERC20
55
+ * @dev Compatible with ERC20 transferFrom.
56
+ * Using force=true so that EOA and any contract may receive the tokens.
57
+ */
58
+ function transferFrom(
59
+ address from,
60
+ address to,
61
+ uint256 amount
62
+ ) external virtual override {
63
+ return transfer(from, to, amount, true, "compat-transferFrom");
64
+ }
65
+
66
+ // --- Overrides
67
+
68
+ function authorizeOperator(address operator, uint256 amount)
69
+ public
70
+ virtual
71
+ override(ILSP7DigitalAsset, LSP7DigitalAssetCore)
72
+ {
73
+ super.authorizeOperator(operator, amount);
74
+
75
+ emit Approval(
76
+ _msgSender(),
77
+ operator,
78
+ amount
79
+ );
80
+ }
81
+
82
+ function _transfer(
83
+ address from,
84
+ address to,
85
+ uint256 amount,
86
+ bool force,
87
+ bytes memory data
88
+ ) internal virtual override {
89
+ super._transfer(from, to, amount, force, data);
90
+
91
+ emit Transfer(
92
+ from,
93
+ to,
94
+ amount
95
+ );
96
+ }
97
+
98
+ function _mint(
99
+ address to,
100
+ uint256 amount,
101
+ bool force,
102
+ bytes memory data
103
+ ) internal virtual override {
104
+ super._mint(to, amount, force, data);
105
+
106
+ emit Transfer(
107
+ address(0),
108
+ to,
109
+ amount
110
+ );
111
+ }
112
+
113
+ function _burn(address from, uint256 amount, bytes memory data)
114
+ internal
115
+ virtual
116
+ override
117
+ {
118
+ super._burn(from, amount, data);
119
+
120
+ emit Transfer(
121
+ from,
122
+ address(0),
123
+ amount
124
+ );
125
+ }
126
+ }
@@ -0,0 +1,22 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // modules
6
+ import "./LSP7CompatibilityForERC20InitAbstract.sol";
7
+
8
+ contract LSP7CompatibilityForERC20Init is LSP7CompatibilityForERC20InitAbstract {
9
+ /**
10
+ * @notice Sets the name, the symbol and the owner of the token
11
+ * @param name_ The name of the token
12
+ * @param symbol_ The symbol of the token
13
+ * @param newOwner_ The owner of the token
14
+ */
15
+ function initialize(
16
+ string memory name_,
17
+ string memory symbol_,
18
+ address newOwner_
19
+ ) public virtual override initializer {
20
+ LSP7CompatibilityForERC20InitAbstract.initialize(name_, symbol_, newOwner_);
21
+ }
22
+ }
@@ -0,0 +1,55 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ // modules
6
+ import "../LSP7DigitalAssetInitAbstract.sol";
7
+ import "./LSP7CompatibilityForERC20Core.sol";
8
+
9
+ contract LSP7CompatibilityForERC20InitAbstract is LSP7CompatibilityForERC20Core, LSP7DigitalAssetInitAbstract {
10
+ /**
11
+ * @notice Sets the name, the symbol and the owner of the token
12
+ * @param name_ The name of the token
13
+ * @param symbol_ The symbol of the token
14
+ * @param newOwner_ The owner of the token
15
+ */
16
+ function initialize(
17
+ string memory name_,
18
+ string memory symbol_,
19
+ address newOwner_
20
+ ) public virtual override onlyInitializing {
21
+ LSP7DigitalAssetInitAbstract.initialize(name_, symbol_, newOwner_, false);
22
+ }
23
+
24
+ // --- Overrides
25
+
26
+ function authorizeOperator(address operator, uint256 amount)
27
+ public
28
+ virtual
29
+ override(LSP7DigitalAssetCore, LSP7CompatibilityForERC20Core)
30
+ {
31
+ super.authorizeOperator(operator, amount);
32
+ }
33
+
34
+ function _burn(address from, uint256 amount, bytes memory data)
35
+ internal
36
+ virtual
37
+ override(LSP7DigitalAssetCore, LSP7CompatibilityForERC20Core)
38
+ {
39
+ super._burn(from, amount, data);
40
+ }
41
+
42
+ function _mint(address to, uint256 amount, bool force, bytes memory data)
43
+ internal
44
+ virtual
45
+ override(LSP7DigitalAssetCore, LSP7CompatibilityForERC20Core) {
46
+ super._mint(to, amount, force, data);
47
+ }
48
+
49
+ function _transfer(address from, address to, uint256 amount, bool force, bytes memory data)
50
+ internal
51
+ virtual
52
+ override(LSP7DigitalAssetCore, LSP7CompatibilityForERC20Core) {
53
+ super._transfer(from, to, amount, force, data);
54
+ }
55
+ }