@lukso/lsp-smart-contracts 0.5.0 → 0.6.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 (138) hide show
  1. package/README.md +29 -9
  2. package/artifacts/LSP0ERC725Account.json +392 -0
  3. package/artifacts/LSP0ERC725AccountInit.json +433 -0
  4. package/artifacts/LSP1UniversalReceiverDelegateUP.json +2 -7
  5. package/artifacts/LSP1UniversalReceiverDelegateVault.json +2 -7
  6. package/artifacts/LSP4Compatibility.json +195 -0
  7. package/artifacts/LSP4DigitalAssetMetadata.json +169 -0
  8. package/artifacts/LSP4DigitalAssetMetadataInit.json +231 -0
  9. package/artifacts/LSP6KeyManager.json +34 -28
  10. package/artifacts/LSP6KeyManagerInit.json +42 -23
  11. package/artifacts/LSP7CappedSupply.json +133 -8
  12. package/artifacts/LSP7CappedSupplyInit.json +160 -32
  13. package/artifacts/LSP7CompatibilityForERC20.json +125 -10
  14. package/artifacts/LSP7CompatibilityForERC20Init.json +727 -0
  15. package/artifacts/LSP7DigitalAsset.json +125 -10
  16. package/artifacts/LSP7DigitalAssetInit.json +149 -31
  17. package/artifacts/LSP7Mintable.json +126 -11
  18. package/artifacts/LSP7MintableInit.json +150 -32
  19. package/artifacts/LSP8CappedSupply.json +134 -8
  20. package/artifacts/LSP8CappedSupplyInit.json +169 -17
  21. package/artifacts/LSP8CompatibilityForERC721.json +126 -10
  22. package/artifacts/LSP8CompatibilityForERC721Init.json +873 -0
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +126 -10
  24. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +158 -16
  25. package/artifacts/LSP8Mintable.json +138 -11
  26. package/artifacts/LSP8MintableInit.json +170 -17
  27. package/artifacts/LSP9Vault.json +368 -0
  28. package/artifacts/LSP9VaultInit.json +409 -0
  29. package/artifacts/UniversalFactory.json +127 -0
  30. package/artifacts/UniversalProfile.json +65 -14
  31. package/artifacts/UniversalProfileInit.json +104 -14
  32. package/artifacts/UniversalReceiverAddressStore.json +204 -0
  33. package/constants.js +352 -0
  34. package/contracts/Custom/ClaimOwnership.sol +31 -0
  35. package/contracts/Custom/ERC165Checker.sol +130 -0
  36. package/contracts/Custom/IClaimOwnership.sol +10 -0
  37. package/contracts/Factories/UniversalFactory.sol +155 -0
  38. package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -9
  39. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +6 -8
  40. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +89 -46
  41. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +5 -5
  42. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +6 -21
  43. package/contracts/LSP10ReceivedVaults/LSP10Constants.sol +10 -0
  44. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +2 -8
  45. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +59 -185
  46. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +48 -6
  47. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +45 -92
  48. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +39 -6
  49. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +47 -0
  50. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +205 -0
  51. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
  52. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  53. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +5 -14
  54. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
  55. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +11 -8
  56. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
  57. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +14 -20
  58. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
  59. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +157 -0
  60. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +21 -18
  61. package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -25
  62. package/contracts/LSP6KeyManager/LSP6Errors.sol +37 -0
  63. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -4
  64. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +429 -332
  65. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +6 -5
  66. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +7 -15
  67. package/contracts/LSP6KeyManager/LSP6Utils.sol +111 -0
  68. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
  69. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
  70. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +23 -9
  71. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +70 -94
  72. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +8 -9
  73. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +25 -23
  74. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
  75. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
  76. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +2 -4
  77. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +8 -7
  78. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
  79. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
  80. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +9 -17
  81. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +33 -21
  82. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Core.sol +20 -39
  83. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol +3 -3
  84. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +39 -28
  85. package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
  86. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7Mintable.sol +4 -3
  87. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableCore.sol +5 -5
  88. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableInit.sol +3 -2
  89. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +34 -0
  90. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -16
  91. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +6 -3
  92. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +22 -0
  93. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +23 -10
  94. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +102 -135
  95. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +8 -11
  96. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +24 -21
  97. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
  98. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +3 -11
  99. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +9 -15
  100. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +14 -12
  101. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +3 -8
  102. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +11 -20
  103. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +41 -33
  104. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Core.sol +27 -84
  105. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol +4 -6
  106. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +40 -41
  107. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
  108. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8Mintable.sol +4 -3
  109. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableCore.sol +5 -8
  110. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableInit.sol +4 -3
  111. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +35 -0
  112. package/contracts/LSP9Vault/LSP9Constants.sol +13 -4
  113. package/contracts/LSP9Vault/LSP9Vault.sol +15 -37
  114. package/contracts/LSP9Vault/LSP9VaultCore.sol +101 -82
  115. package/contracts/LSP9Vault/LSP9VaultInit.sol +5 -4
  116. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +15 -45
  117. package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
  118. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
  119. package/contracts/Legacy/UniversalReceiverAddressStore.sol +59 -0
  120. package/contracts/UniversalProfile.sol +10 -5
  121. package/contracts/UniversalProfileInit.sol +5 -4
  122. package/contracts/UniversalProfileInitAbstract.sol +14 -20
  123. package/contracts/Utils/UtilsLib.sol +47 -11
  124. package/package.json +23 -9
  125. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
  126. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
  127. package/constants.ts +0 -356
  128. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +0 -52
  129. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +0 -26
  130. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +0 -28
  131. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +0 -41
  132. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +0 -23
  133. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +0 -25
  134. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +0 -47
  135. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
  136. package/contracts/Utils/ERC725Utils.sol +0 -169
  137. package/contracts/Utils/LSP2Utils.sol +0 -127
  138. package/contracts/Utils/LSP6Utils.sol +0 -63
@@ -2,18 +2,19 @@
2
2
  pragma solidity ^0.8.6;
3
3
 
4
4
  // modules
5
- import "./LSP6KeyManagerInitAbstract.sol";
5
+ import {LSP6KeyManagerInitAbstract} from "./LSP6KeyManagerInitAbstract.sol";
6
6
 
7
7
  /**
8
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
9
+ * @author Fabian Vogelsteller <frozeman>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
10
10
  * @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below
11
11
  */
12
12
  contract LSP6KeyManagerInit is LSP6KeyManagerInitAbstract {
13
13
  /**
14
- * @inheritdoc LSP6KeyManagerInitAbstract
14
+ * @notice Initiate the account with the address of the ERC725Account contract and sets LSP6KeyManager InterfaceId
15
+ * @param _account The address of the ER725Account to control
15
16
  */
16
- function initialize(address _account) public virtual override initializer {
17
- LSP6KeyManagerInitAbstract.initialize(_account);
17
+ function initialize(address _account) public virtual initializer {
18
+ LSP6KeyManagerInitAbstract._initialize(_account);
18
19
  }
19
20
  }
@@ -2,25 +2,17 @@
2
2
  pragma solidity ^0.8.6;
3
3
 
4
4
  // modules
5
- import "./LSP6KeyManagerCore.sol";
6
- import "@openzeppelin/contracts/utils/introspection/ERC165Storage.sol";
7
- import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
5
+ import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
6
+ import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
7
+ import {LSP6KeyManagerCore} from "./LSP6KeyManagerCore.sol";
8
8
 
9
9
  /**
10
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
11
+ * @author Fabian Vogelsteller <frozeman>, Jean Cavallera (CJ42), Yamen Merhi (YamenMerhi)
12
12
  * @dev all the permissions can be set on the ERC725 Account using `setData(...)` with the keys constants below
13
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);
14
+ abstract contract LSP6KeyManagerInitAbstract is Initializable, LSP6KeyManagerCore {
15
+ function _initialize(address _account) internal virtual onlyInitializing {
16
+ target = _account;
25
17
  }
26
18
  }
@@ -0,0 +1,111 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ // interfaces
5
+ import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
6
+ import {ILSP6KeyManager} from "./ILSP6KeyManager.sol";
7
+
8
+ // libraries
9
+ import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
10
+
11
+ // constants
12
+ import "../LSP6KeyManager/LSP6Constants.sol";
13
+
14
+ library LSP6Utils {
15
+ using LSP2Utils for bytes12;
16
+
17
+ function getPermissionsFor(IERC725Y _account, address _address)
18
+ internal
19
+ view
20
+ returns (bytes32)
21
+ {
22
+ bytes memory permissions = _account.getData(
23
+ LSP2Utils.generateMappingWithGroupingKey(
24
+ _LSP6KEY_ADDRESSPERMISSIONS_PERMISSIONS_PREFIX,
25
+ bytes20(_address)
26
+ )
27
+ );
28
+
29
+ return bytes32(permissions);
30
+ }
31
+
32
+ function getAllowedAddressesFor(IERC725Y _account, address _address)
33
+ internal
34
+ view
35
+ returns (bytes memory)
36
+ {
37
+ return
38
+ _account.getData(
39
+ LSP2Utils.generateMappingWithGroupingKey(
40
+ _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDADDRESSES_PREFIX,
41
+ bytes20(_address)
42
+ )
43
+ );
44
+ }
45
+
46
+ function getAllowedFunctionsFor(IERC725Y _account, address _address)
47
+ internal
48
+ view
49
+ returns (bytes memory)
50
+ {
51
+ return
52
+ _account.getData(
53
+ LSP2Utils.generateMappingWithGroupingKey(
54
+ _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDFUNCTIONS_PREFIX,
55
+ bytes20(_address)
56
+ )
57
+ );
58
+ }
59
+
60
+ function getAllowedStandardsFor(IERC725Y _account, address _address)
61
+ internal
62
+ view
63
+ returns (bytes memory)
64
+ {
65
+ return
66
+ _account.getData(
67
+ LSP2Utils.generateMappingWithGroupingKey(
68
+ _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDSTANDARDS_PREFIX,
69
+ bytes20(_address)
70
+ )
71
+ );
72
+ }
73
+
74
+ function getAllowedERC725YKeysFor(IERC725Y _account, address _address)
75
+ internal
76
+ view
77
+ returns (bytes memory)
78
+ {
79
+ return
80
+ _account.getData(
81
+ LSP2Utils.generateMappingWithGroupingKey(
82
+ _LSP6KEY_ADDRESSPERMISSIONS_ALLOWEDERC725YKEYS_PREFIX,
83
+ bytes20(_address)
84
+ )
85
+ );
86
+ }
87
+
88
+ /**
89
+ * @dev compare the permissions `_addressPermissions` of an address
90
+ * to check if they includes the permissions `_permissionToCheck`
91
+ * @param _addressPermission the permissions of an address stored on an ERC725 account
92
+ * @param _permissionToCheck the permissions to check
93
+ * @return true if `_addressPermissions` includes `_permissionToCheck`, false otherwise
94
+ */
95
+ function hasPermission(bytes32 _addressPermission, bytes32 _permissionToCheck)
96
+ internal
97
+ pure
98
+ returns (bool)
99
+ {
100
+ return (_addressPermission & _permissionToCheck) == _permissionToCheck;
101
+ }
102
+
103
+ function setDataViaKeyManager(
104
+ address keyManagerAddress,
105
+ bytes32[] memory keys,
106
+ bytes[] memory values
107
+ ) internal returns (bytes memory result) {
108
+ bytes memory payload = abi.encodeWithSelector(hex"14a6e293", keys, values);
109
+ result = ILSP6KeyManager(keyManagerAddress).execute(payload);
110
+ }
111
+ }
@@ -3,8 +3,8 @@
3
3
  pragma solidity ^0.8.0;
4
4
 
5
5
  // interfaces
6
- import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
7
- import "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
6
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
7
+ import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
8
8
 
9
9
  /**
10
10
  * @dev Required interface of a LSP8 compliant contract.
@@ -88,7 +88,6 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
88
88
  *
89
89
  * Requirements
90
90
  *
91
- * - `operator` cannot be calling address.
92
91
  * - `operator` cannot be the zero address.
93
92
  *
94
93
  * Emits an {AuthorizedOperator} event.
@@ -103,7 +102,6 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
103
102
  *
104
103
  * Requirements
105
104
  *
106
- * - `operator` cannot be calling address.
107
105
  * - `operator` cannot be the zero address.
108
106
  *
109
107
  * Emits a {RevokedOperator} event.
@@ -118,10 +116,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
118
116
  * Operators can send and burn tokens on behalf of their owners. The tokenOwner is their own
119
117
  * operator.
120
118
  */
121
- function isOperatorFor(address operator, address tokenOwner)
122
- external
123
- view
124
- returns (uint256);
119
+ function isOperatorFor(address operator, address tokenOwner) external view returns (uint256);
125
120
 
126
121
  // --- Transfer functionality
127
122
 
@@ -4,9 +4,10 @@ pragma solidity ^0.8.0;
4
4
  // --- ERC165 interface ids
5
5
  bytes4 constant _INTERFACEID_LSP7 = 0xe33f65c3;
6
6
 
7
- // --- ERC725Y entries
8
-
9
7
  // --- Token Hooks
10
- bytes32 constant _TYPEID_LSP7_TOKENSSENDER = 0x40b8bec57d7b5ff0dbd9e9acd0a47dfeb0101e1a203766f5ccab00445fbf39e9; // keccak256("LSP7TokensSender")
11
8
 
12
- bytes32 constant _TYPEID_LSP7_TOKENSRECIPIENT = 0xdbe2c314e1aee2970c72666f2ebe8933a8575263ea71e5ff6a9178e95d47a26f; // keccak256("LSP7TokensRecipient")
9
+ // keccak256('LSP7TokensSender')
10
+ bytes32 constant _TYPEID_LSP7_TOKENSSENDER = 0x40b8bec57d7b5ff0dbd9e9acd0a47dfeb0101e1a203766f5ccab00445fbf39e9;
11
+
12
+ // keccak256('LSP7TokensRecipient')
13
+ bytes32 constant _TYPEID_LSP7_TOKENSRECIPIENT = 0xdbe2c314e1aee2970c72666f2ebe8933a8575263ea71e5ff6a9178e95d47a26f;
@@ -1,23 +1,25 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- // constants
5
- import "./LSP7Constants.sol";
6
- import "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
4
+ // interfaces
5
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
7
6
 
8
7
  // modules
9
- import "./LSP7DigitalAssetCore.sol";
10
- import "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol";
11
- import "@erc725/smart-contracts/contracts/ERC725Y.sol";
8
+ import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
9
+ import {LSP4DigitalAssetMetadata} from "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol";
10
+ import {LSP7DigitalAssetCore} from "./LSP7DigitalAssetCore.sol";
11
+
12
+ // constants
13
+ import {_INTERFACEID_LSP7} from "./LSP7Constants.sol";
12
14
 
13
15
  /**
14
16
  * @title LSP7DigitalAsset contract
15
17
  * @author Matthew Stevens
16
18
  * @dev Implementation of a LSP7 compliant contract.
17
19
  */
18
- contract LSP7DigitalAsset is LSP7DigitalAssetCore, LSP4DigitalAssetMetadata {
20
+ contract LSP7DigitalAsset is LSP4DigitalAssetMetadata, LSP7DigitalAssetCore {
19
21
  /**
20
- * @notice Sets the token-Metadata and register LSP7InterfaceId
22
+ * @notice Sets the token-Metadata
21
23
  * @param name_ The name of the token
22
24
  * @param symbol_ The symbol of the token
23
25
  * @param newOwner_ The owner of the the token-Metadata
@@ -30,6 +32,18 @@ contract LSP7DigitalAsset is LSP7DigitalAssetCore, LSP4DigitalAssetMetadata {
30
32
  bool isNFT_
31
33
  ) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_) {
32
34
  _isNFT = isNFT_;
33
- _registerInterface(_INTERFACEID_LSP7);
35
+ }
36
+
37
+ /**
38
+ * @dev See {IERC165-supportsInterface}.
39
+ */
40
+ function supportsInterface(bytes4 interfaceId)
41
+ public
42
+ view
43
+ virtual
44
+ override(IERC165, ERC725YCore)
45
+ returns (bool)
46
+ {
47
+ return interfaceId == _INTERFACEID_LSP7 || super.supportsInterface(interfaceId);
34
48
  }
35
49
  }
@@ -1,23 +1,25 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- // constants
5
- import "./LSP7Constants.sol";
6
- import "../LSP1UniversalReceiver/LSP1Constants.sol";
7
- import "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
8
-
9
4
  // interfaces
10
- import "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
11
- import "./ILSP7DigitalAsset.sol";
5
+ import {ILSP1UniversalReceiver} from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
6
+ import {ILSP7DigitalAsset} from "./ILSP7DigitalAsset.sol";
7
+
8
+ // libraries
9
+ import {ERC165Checker} from "../Custom/ERC165Checker.sol";
12
10
 
13
11
  // modules
14
- import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
15
- import "@openzeppelin/contracts/utils/Address.sol";
16
- import "@openzeppelin/contracts/utils/Context.sol";
17
- import "@erc725/smart-contracts/contracts/ERC725Y.sol";
12
+ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
13
+ import {Address} from "@openzeppelin/contracts/utils/Address.sol";
14
+ import {Context} from "@openzeppelin/contracts/utils/Context.sol";
15
+ import {ERC725Y} from "@erc725/smart-contracts/contracts/ERC725Y.sol";
18
16
 
19
- // library
20
- import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
17
+ // errors
18
+ import "./LSP7Errors.sol";
19
+
20
+ // constants
21
+ import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
22
+ import {_TYPEID_LSP7_TOKENSSENDER, _TYPEID_LSP7_TOKENSRECIPIENT} from "./LSP7Constants.sol";
21
23
 
22
24
  /**
23
25
  * @title LSP7DigitalAsset contract
@@ -37,8 +39,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
37
39
  mapping(address => uint256) internal _tokenOwnerBalances;
38
40
 
39
41
  // Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
40
- mapping(address => mapping(address => uint256))
41
- internal _operatorAuthorizedAmount;
42
+ mapping(address => mapping(address => uint256)) internal _operatorAuthorizedAmount;
42
43
 
43
44
  // --- Token queries
44
45
 
@@ -61,12 +62,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
61
62
  /**
62
63
  * @inheritdoc ILSP7DigitalAsset
63
64
  */
64
- function balanceOf(address tokenOwner)
65
- public
66
- view
67
- override
68
- returns (uint256)
69
- {
65
+ function balanceOf(address tokenOwner) public view override returns (uint256) {
70
66
  return _tokenOwnerBalances[tokenOwner];
71
67
  }
72
68
 
@@ -75,11 +71,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
75
71
  /**
76
72
  * @inheritdoc ILSP7DigitalAsset
77
73
  */
78
- function authorizeOperator(address operator, uint256 amount)
79
- public
80
- virtual
81
- override
82
- {
74
+ function authorizeOperator(address operator, uint256 amount) public virtual override {
83
75
  _updateOperator(_msgSender(), operator, amount);
84
76
  }
85
77
 
@@ -122,15 +114,11 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
122
114
  address operator = _msgSender();
123
115
  if (operator != from) {
124
116
  uint256 operatorAmount = _operatorAuthorizedAmount[from][operator];
125
- require(
126
- operatorAmount >= amount,
127
- "LSP7: transfer amount exceeds operator authorized amount"
128
- );
129
- _updateOperator(
130
- from,
131
- operator,
132
- _operatorAuthorizedAmount[from][operator] - amount
133
- );
117
+ if (amount > operatorAmount) {
118
+ revert LSP7AmountExceedsAuthorizedAmount(from, operatorAmount, operator, amount);
119
+ }
120
+
121
+ _updateOperator(from, operator, operatorAmount - amount);
134
122
  }
135
123
 
136
124
  _transfer(from, to, amount, force, data);
@@ -146,12 +134,11 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
146
134
  bool force,
147
135
  bytes[] memory data
148
136
  ) external virtual override {
149
- require(
150
- from.length == to.length &&
151
- from.length == amount.length &&
152
- from.length == data.length,
153
- "LSP7: transferBatch list length mismatch"
154
- );
137
+ if (
138
+ from.length != to.length || from.length != amount.length || from.length != data.length
139
+ ) {
140
+ revert LSP7InvalidTransferBatch();
141
+ }
155
142
 
156
143
  for (uint256 i = 0; i < from.length; i++) {
157
144
  // using the public transfer function to handle updates to operator authorized amounts
@@ -170,7 +157,6 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
170
157
  *
171
158
  * Requirements
172
159
  *
173
- * - `operator` cannot be calling address.
174
160
  * - `operator` cannot be the zero address.
175
161
  */
176
162
  function _updateOperator(
@@ -178,22 +164,18 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
178
164
  address operator,
179
165
  uint256 amount
180
166
  ) internal virtual {
181
- require(
182
- operator != tokenOwner,
183
- "LSP7: updating operator failed, can not use token owner as operator"
184
- );
185
- require(
186
- operator != address(0),
187
- "LSP7: updating operator failed, operator can not be zero address"
188
- );
189
- require(
190
- tokenOwner != address(0),
191
- "LSP7: updating operator failed, can not set operator for zero address"
192
- );
167
+ if (operator == address(0)) {
168
+ revert LSP7CannotUseAddressZeroAsOperator();
169
+ }
170
+
171
+ // tokenOwner is always their own operator, no update required
172
+ if (operator == tokenOwner) {
173
+ return;
174
+ }
193
175
 
194
176
  _operatorAuthorizedAmount[tokenOwner][operator] = amount;
195
177
 
196
- if (amount > 0) {
178
+ if (amount != 0) {
197
179
  emit AuthorizedOperator(operator, tokenOwner, amount);
198
180
  } else {
199
181
  emit RevokedOperator(operator, tokenOwner);
@@ -215,7 +197,9 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
215
197
  bool force,
216
198
  bytes memory data
217
199
  ) internal virtual {
218
- require(to != address(0), "LSP7: mint to the zero address not allowed");
200
+ if (to == address(0)) {
201
+ revert LSP7CannotSendWithAddressZero();
202
+ }
219
203
 
220
204
  address operator = _msgSender();
221
205
 
@@ -245,28 +229,31 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
245
229
  uint256 amount,
246
230
  bytes memory data
247
231
  ) internal virtual {
248
- require(from != address(0), "LSP7: burn from the zero address");
249
- require(
250
- _tokenOwnerBalances[from] >= amount,
251
- "LSP7: burn amount exceeds tokenOwner balance"
252
- );
232
+ if (from == address(0)) {
233
+ revert LSP7CannotSendWithAddressZero();
234
+ }
235
+
236
+ uint256 balance = _tokenOwnerBalances[from];
237
+ if (amount > balance) {
238
+ revert LSP7AmountExceedsBalance(balance, from, amount);
239
+ }
253
240
 
254
241
  address operator = _msgSender();
255
242
  if (operator != from) {
256
- require(
257
- _operatorAuthorizedAmount[from][operator] >= amount,
258
- "LSP7: burn amount exceeds operator authorized amount"
259
- );
243
+ uint256 authorizedAmount = _operatorAuthorizedAmount[from][operator];
244
+ if (amount > authorizedAmount) {
245
+ revert LSP7AmountExceedsAuthorizedAmount(from, authorizedAmount, operator, amount);
246
+ }
260
247
  _operatorAuthorizedAmount[from][operator] -= amount;
261
248
  }
262
249
 
263
- _notifyTokenSender(from, address(0), amount, data);
264
-
265
250
  _beforeTokenTransfer(from, address(0), amount);
266
251
 
267
252
  _tokenOwnerBalances[from] -= amount;
268
253
 
269
254
  emit Transfer(operator, from, address(0), amount, false, data);
255
+
256
+ _notifyTokenSender(from, address(0), amount, data);
270
257
  }
271
258
 
272
259
  /**
@@ -289,16 +276,16 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
289
276
  bool force,
290
277
  bytes memory data
291
278
  ) internal virtual {
292
- require(from != address(0), "LSP7: transfer from the zero address");
293
- require(to != address(0), "LSP7: transfer to the zero address");
294
- require(
295
- _tokenOwnerBalances[from] >= amount,
296
- "LSP7: transfer amount exceeds tokenOwner balance"
297
- );
279
+ if (from == address(0) || to == address(0)) {
280
+ revert LSP7CannotSendWithAddressZero();
281
+ }
298
282
 
299
- address operator = _msgSender();
283
+ uint256 balance = _tokenOwnerBalances[from];
284
+ if (amount > balance) {
285
+ revert LSP7AmountExceedsBalance(balance, from, amount);
286
+ }
300
287
 
301
- _notifyTokenSender(from, to, amount, data);
288
+ address operator = _msgSender();
302
289
 
303
290
  _beforeTokenTransfer(from, to, amount);
304
291
 
@@ -307,6 +294,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
307
294
 
308
295
  emit Transfer(operator, from, to, amount, force, data);
309
296
 
297
+ _notifyTokenSender(from, to, amount, data);
310
298
  _notifyTokenReceiver(from, to, amount, force, data);
311
299
  }
312
300
 
@@ -347,15 +335,9 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
347
335
  uint256 amount,
348
336
  bytes memory data
349
337
  ) internal virtual {
350
- if (
351
- ERC165Checker.supportsERC165(from) &&
352
- ERC165Checker.supportsInterface(from, _INTERFACEID_LSP1)
353
- ) {
338
+ if (ERC165Checker.supportsERC165Interface(from, _INTERFACEID_LSP1)) {
354
339
  bytes memory packedData = abi.encodePacked(from, to, amount, data);
355
- ILSP1UniversalReceiver(from).universalReceiver(
356
- _TYPEID_LSP7_TOKENSSENDER,
357
- packedData
358
- );
340
+ ILSP1UniversalReceiver(from).universalReceiver(_TYPEID_LSP7_TOKENSSENDER, packedData);
359
341
  }
360
342
  }
361
343
 
@@ -372,20 +354,14 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
372
354
  bool force,
373
355
  bytes memory data
374
356
  ) internal virtual {
375
- if (
376
- ERC165Checker.supportsERC165(to) &&
377
- ERC165Checker.supportsInterface(to, _INTERFACEID_LSP1)
378
- ) {
357
+ if (ERC165Checker.supportsERC165Interface(to, _INTERFACEID_LSP1)) {
379
358
  bytes memory packedData = abi.encodePacked(from, to, amount, data);
380
- ILSP1UniversalReceiver(to).universalReceiver(
381
- _TYPEID_LSP7_TOKENSRECIPIENT,
382
- packedData
383
- );
359
+ ILSP1UniversalReceiver(to).universalReceiver(_TYPEID_LSP7_TOKENSRECIPIENT, packedData);
384
360
  } else if (!force) {
385
- if (to.isContract()) {
386
- revert("LSP7: token receiver contract missing LSP1 interface");
361
+ if (to.code.length != 0) {
362
+ revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
387
363
  } else {
388
- revert("LSP7: token receiver is EOA");
364
+ revert LSP7NotifyTokenReceiverIsEOA(to);
389
365
  }
390
366
  }
391
367
  }
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8.0;
3
3
 
4
4
  // modules
5
- import "./LSP7DigitalAssetInitAbstract.sol";
5
+ import {LSP7DigitalAssetInitAbstract} from "./LSP7DigitalAssetInitAbstract.sol";
6
6
 
7
7
  /**
8
8
  * @title LSP7DigitalAsset contract
@@ -11,19 +11,18 @@ import "./LSP7DigitalAssetInitAbstract.sol";
11
11
  */
12
12
  contract LSP7DigitalAssetInit is LSP7DigitalAssetInitAbstract {
13
13
  /**
14
- * @inheritdoc LSP7DigitalAssetInitAbstract
14
+ * @notice Sets the token-Metadata
15
+ * @param name_ The name of the token
16
+ * @param symbol_ The symbol of the token
17
+ * @param newOwner_ The owner of the the token-Metadata
18
+ * @param isNFT_ Specify if the LSP7 token is a fungible or non-fungible token
15
19
  */
16
20
  function initialize(
17
21
  string memory name_,
18
22
  string memory symbol_,
19
23
  address newOwner_,
20
24
  bool isNFT_
21
- ) public virtual override initializer {
22
- LSP7DigitalAssetInitAbstract.initialize(
23
- name_,
24
- symbol_,
25
- newOwner_,
26
- isNFT_
27
- );
25
+ ) public virtual initializer {
26
+ LSP7DigitalAssetInitAbstract._initialize(name_, symbol_, newOwner_, isNFT_);
28
27
  }
29
28
  }
@@ -1,13 +1,16 @@
1
1
  // SPDX-License-Identifier: CC0-1.0
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- // constants
5
- import "./LSP7Constants.sol";
6
- import "../LSP4DigitalAssetMetadata/LSP4Constants.sol";
4
+ // interfaces
5
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
7
6
 
8
7
  // modules
9
- import "./LSP7DigitalAssetCore.sol";
10
- import "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol";
8
+ import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
9
+ import {LSP4DigitalAssetMetadataInitAbstract} from "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol";
10
+ import {LSP7DigitalAssetCore} from "./LSP7DigitalAssetCore.sol";
11
+
12
+ // constants
13
+ import {_INTERFACEID_LSP7} from "./LSP7Constants.sol";
11
14
 
12
15
  /**
13
16
  * @title LSP7DigitalAsset contract
@@ -15,30 +18,29 @@ import "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol";
15
18
  * @dev Proxy Implementation of a LSP7 compliant contract.
16
19
  */
17
20
  abstract contract LSP7DigitalAssetInitAbstract is
18
- LSP7DigitalAssetCore,
19
- Initializable,
20
- LSP4DigitalAssetMetadataInitAbstract
21
+ LSP4DigitalAssetMetadataInitAbstract,
22
+ LSP7DigitalAssetCore
21
23
  {
22
- /**
23
- * @notice Sets the token-Metadata and register LSP7InterfaceId
24
- * @param name_ The name of the token
25
- * @param symbol_ The symbol of the token
26
- * @param newOwner_ The owner of the the token-Metadata
27
- * @param isNFT_ Specify if the LSP7 token is a fungible or non-fungible token
28
- */
29
- function initialize(
24
+ function _initialize(
30
25
  string memory name_,
31
26
  string memory symbol_,
32
27
  address newOwner_,
33
28
  bool isNFT_
34
- ) public virtual onlyInitializing {
29
+ ) internal virtual onlyInitializing {
35
30
  _isNFT = isNFT_;
36
- LSP4DigitalAssetMetadataInitAbstract.initialize(
37
- name_,
38
- symbol_,
39
- newOwner_
40
- );
31
+ LSP4DigitalAssetMetadataInitAbstract._initialize(name_, symbol_, newOwner_);
32
+ }
41
33
 
42
- _registerInterface(_INTERFACEID_LSP7);
34
+ /**
35
+ * @dev See {IERC165-supportsInterface}.
36
+ */
37
+ function supportsInterface(bytes4 interfaceId)
38
+ public
39
+ view
40
+ virtual
41
+ override(IERC165, ERC725YCore)
42
+ returns (bool)
43
+ {
44
+ return interfaceId == _INTERFACEID_LSP7 || super.supportsInterface(interfaceId);
43
45
  }
44
46
  }