@lukso/lsp-smart-contracts 0.4.3 → 0.6.1

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 (141) hide show
  1. package/README.md +38 -9
  2. package/artifacts/LSP0ERC725Account.json +398 -0
  3. package/artifacts/LSP0ERC725AccountInit.json +439 -0
  4. package/artifacts/LSP1UniversalReceiverDelegateUP.json +7 -7
  5. package/artifacts/LSP1UniversalReceiverDelegateVault.json +7 -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 +50 -28
  10. package/artifacts/LSP6KeyManagerInit.json +58 -23
  11. package/artifacts/LSP7CappedSupply.json +136 -11
  12. package/artifacts/LSP7CappedSupplyInit.json +163 -35
  13. package/artifacts/LSP7CompatibilityForERC20.json +204 -13
  14. package/artifacts/LSP7CompatibilityForERC20Init.json +727 -0
  15. package/artifacts/LSP7DigitalAsset.json +128 -13
  16. package/artifacts/LSP7DigitalAssetInit.json +152 -34
  17. package/artifacts/LSP7Mintable.json +129 -14
  18. package/artifacts/LSP7MintableInit.json +153 -35
  19. package/artifacts/LSP8CappedSupply.json +137 -11
  20. package/artifacts/LSP8CappedSupplyInit.json +172 -20
  21. package/artifacts/LSP8CompatibilityForERC721.json +138 -17
  22. package/artifacts/LSP8CompatibilityForERC721Init.json +873 -0
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +129 -13
  24. package/artifacts/LSP8IdentifiableDigitalAssetInit.json +161 -19
  25. package/artifacts/LSP8Mintable.json +141 -14
  26. package/artifacts/LSP8MintableInit.json +173 -20
  27. package/artifacts/LSP9Vault.json +374 -0
  28. package/artifacts/LSP9VaultInit.json +415 -0
  29. package/artifacts/UniversalFactory.json +127 -0
  30. package/artifacts/UniversalProfile.json +78 -53
  31. package/artifacts/UniversalProfileInit.json +117 -53
  32. package/artifacts/UniversalReceiverAddressStore.json +209 -0
  33. package/constants.js +500 -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 +92 -48
  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/ILSP1UniversalReceiver.sol +3 -0
  45. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +4 -2
  46. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +3 -9
  47. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/Handling/TokenAndVaultHandling.sol +61 -165
  48. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +49 -6
  49. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/Handling/TokenHandling.sol +50 -90
  50. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +40 -6
  51. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +48 -0
  52. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +205 -0
  53. package/contracts/LSP3UniversalProfile/LSP3Constants.sol +11 -0
  54. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +1 -1
  55. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +6 -15
  56. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +10 -4
  57. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +11 -8
  58. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInit.sol +9 -13
  59. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +14 -20
  60. package/contracts/LSP5ReceivedAssets/LSP5Constants.sol +10 -0
  61. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +205 -0
  62. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +21 -18
  63. package/contracts/LSP6KeyManager/LSP6Constants.sol +61 -24
  64. package/contracts/LSP6KeyManager/LSP6Errors.sol +37 -0
  65. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +3 -4
  66. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +475 -260
  67. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +6 -5
  68. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +7 -15
  69. package/contracts/LSP6KeyManager/LSP6Utils.sol +111 -0
  70. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +3 -8
  71. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +5 -4
  72. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +22 -8
  73. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +70 -96
  74. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInit.sol +8 -9
  75. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +23 -21
  76. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +23 -0
  77. package/contracts/LSP7DigitalAsset/extensions/ILSP7CappedSupply.sol +1 -1
  78. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibilityForERC20.sol +22 -6
  79. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +7 -6
  80. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyCore.sol +14 -12
  81. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInit.sol +3 -8
  82. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +9 -17
  83. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20.sol +37 -45
  84. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Core.sol +107 -0
  85. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20Init.sol +22 -0
  86. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibilityForERC20InitAbstract.sol +66 -0
  87. package/contracts/LSP7DigitalAsset/{extensions → presets}/ILSP7Mintable.sol +1 -1
  88. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7Mintable.sol +4 -3
  89. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableCore.sol +5 -5
  90. package/contracts/LSP7DigitalAsset/{extensions → presets}/LSP7MintableInit.sol +3 -2
  91. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +34 -0
  92. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -16
  93. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +6 -3
  94. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +22 -0
  95. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +21 -8
  96. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +102 -135
  97. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInit.sol +8 -11
  98. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +22 -19
  99. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CappedSupply.sol +1 -1
  100. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibilityForERC721.sol +17 -22
  101. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +9 -15
  102. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyCore.sol +14 -12
  103. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInit.sol +3 -8
  104. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +9 -18
  105. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721.sol +37 -189
  106. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Core.sol +187 -0
  107. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721Init.sol +25 -0
  108. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibilityForERC721InitAbstract.sol +89 -0
  109. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/ILSP8Mintable.sol +1 -1
  110. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8Mintable.sol +4 -3
  111. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableCore.sol +5 -8
  112. package/contracts/LSP8IdentifiableDigitalAsset/{extensions → presets}/LSP8MintableInit.sol +4 -3
  113. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +35 -0
  114. package/contracts/LSP9Vault/LSP9Constants.sol +14 -5
  115. package/contracts/LSP9Vault/LSP9Vault.sol +15 -37
  116. package/contracts/LSP9Vault/LSP9VaultCore.sol +105 -85
  117. package/contracts/LSP9Vault/LSP9VaultInit.sol +5 -4
  118. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +15 -45
  119. package/contracts/Legacy/Registries/AddressRegistry.sol +43 -0
  120. package/contracts/Legacy/Registries/AddressRegistryRequiresERC725.sol +33 -0
  121. package/contracts/Legacy/UniversalReceiverAddressStore.sol +60 -0
  122. package/contracts/UniversalProfile.sol +11 -20
  123. package/contracts/UniversalProfileInit.sol +5 -4
  124. package/contracts/UniversalProfileInitAbstract.sol +14 -35
  125. package/contracts/Utils/UtilsLib.sol +47 -11
  126. package/package.json +23 -9
  127. package/artifacts/LSP1UniversalReceiverDelegateUPInit.json +0 -66
  128. package/artifacts/LSP1UniversalReceiverDelegateVaultInit.json +0 -66
  129. package/constants.ts +0 -350
  130. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPCore.sol +0 -52
  131. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInit.sol +0 -26
  132. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUPInitAbstract.sol +0 -28
  133. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultCore.sol +0 -41
  134. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInit.sol +0 -23
  135. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVaultInitAbstract.sol +0 -25
  136. package/contracts/LSP7DigitalAsset/extensions/LSP7MintableInitAbstract.sol +0 -47
  137. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8MintableInitAbstract.sol +0 -44
  138. package/contracts/UniversalProfileCore.sol +0 -56
  139. package/contracts/Utils/ERC725Utils.sol +0 -169
  140. package/contracts/Utils/LSP2Utils.sol +0 -127
  141. package/contracts/Utils/LSP6Utils.sol +0 -77
@@ -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,14 +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/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
@@ -17,7 +19,7 @@ import "@erc725/smart-contracts/contracts/ERC725Y.sol";
17
19
  */
18
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 LSP4DigitalAssetMetadata, LSP7DigitalAssetCore {
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
@@ -25,8 +27,6 @@ import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
25
27
  * @dev Core Implementation of a LSP7 compliant contract.
26
28
  */
27
29
  abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
28
- using EnumerableSet for EnumerableSet.AddressSet;
29
- using EnumerableSet for EnumerableSet.Bytes32Set;
30
30
  using Address for address;
31
31
 
32
32
  // --- Storage
@@ -39,8 +39,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
39
39
  mapping(address => uint256) internal _tokenOwnerBalances;
40
40
 
41
41
  // Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
42
- mapping(address => mapping(address => uint256))
43
- internal _operatorAuthorizedAmount;
42
+ mapping(address => mapping(address => uint256)) internal _operatorAuthorizedAmount;
44
43
 
45
44
  // --- Token queries
46
45
 
@@ -63,12 +62,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
63
62
  /**
64
63
  * @inheritdoc ILSP7DigitalAsset
65
64
  */
66
- function balanceOf(address tokenOwner)
67
- public
68
- view
69
- override
70
- returns (uint256)
71
- {
65
+ function balanceOf(address tokenOwner) public view override returns (uint256) {
72
66
  return _tokenOwnerBalances[tokenOwner];
73
67
  }
74
68
 
@@ -77,11 +71,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
77
71
  /**
78
72
  * @inheritdoc ILSP7DigitalAsset
79
73
  */
80
- function authorizeOperator(address operator, uint256 amount)
81
- public
82
- virtual
83
- override
84
- {
74
+ function authorizeOperator(address operator, uint256 amount) public virtual override {
85
75
  _updateOperator(_msgSender(), operator, amount);
86
76
  }
87
77
 
@@ -124,15 +114,11 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
124
114
  address operator = _msgSender();
125
115
  if (operator != from) {
126
116
  uint256 operatorAmount = _operatorAuthorizedAmount[from][operator];
127
- require(
128
- operatorAmount >= amount,
129
- "LSP7: transfer amount exceeds operator authorized amount"
130
- );
131
- _updateOperator(
132
- from,
133
- operator,
134
- _operatorAuthorizedAmount[from][operator] - amount
135
- );
117
+ if (amount > operatorAmount) {
118
+ revert LSP7AmountExceedsAuthorizedAmount(from, operatorAmount, operator, amount);
119
+ }
120
+
121
+ _updateOperator(from, operator, operatorAmount - amount);
136
122
  }
137
123
 
138
124
  _transfer(from, to, amount, force, data);
@@ -148,12 +134,11 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
148
134
  bool force,
149
135
  bytes[] memory data
150
136
  ) external virtual override {
151
- require(
152
- from.length == to.length &&
153
- from.length == amount.length &&
154
- from.length == data.length,
155
- "LSP7: transferBatch list length mismatch"
156
- );
137
+ if (
138
+ from.length != to.length || from.length != amount.length || from.length != data.length
139
+ ) {
140
+ revert LSP7InvalidTransferBatch();
141
+ }
157
142
 
158
143
  for (uint256 i = 0; i < from.length; i++) {
159
144
  // using the public transfer function to handle updates to operator authorized amounts
@@ -172,7 +157,6 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
172
157
  *
173
158
  * Requirements
174
159
  *
175
- * - `operator` cannot be calling address.
176
160
  * - `operator` cannot be the zero address.
177
161
  */
178
162
  function _updateOperator(
@@ -180,22 +164,18 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
180
164
  address operator,
181
165
  uint256 amount
182
166
  ) internal virtual {
183
- require(
184
- operator != tokenOwner,
185
- "LSP7: updating operator failed, can not use token owner as operator"
186
- );
187
- require(
188
- operator != address(0),
189
- "LSP7: updating operator failed, operator can not be zero address"
190
- );
191
- require(
192
- tokenOwner != address(0),
193
- "LSP7: updating operator failed, can not set operator for zero address"
194
- );
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
+ }
195
175
 
196
176
  _operatorAuthorizedAmount[tokenOwner][operator] = amount;
197
177
 
198
- if (amount > 0) {
178
+ if (amount != 0) {
199
179
  emit AuthorizedOperator(operator, tokenOwner, amount);
200
180
  } else {
201
181
  emit RevokedOperator(operator, tokenOwner);
@@ -217,7 +197,9 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
217
197
  bool force,
218
198
  bytes memory data
219
199
  ) internal virtual {
220
- require(to != address(0), "LSP7: mint to the zero address not allowed");
200
+ if (to == address(0)) {
201
+ revert LSP7CannotSendWithAddressZero();
202
+ }
221
203
 
222
204
  address operator = _msgSender();
223
205
 
@@ -247,28 +229,31 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
247
229
  uint256 amount,
248
230
  bytes memory data
249
231
  ) internal virtual {
250
- require(from != address(0), "LSP7: burn from the zero address");
251
- require(
252
- _tokenOwnerBalances[from] >= amount,
253
- "LSP7: burn amount exceeds tokenOwner balance"
254
- );
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
+ }
255
240
 
256
241
  address operator = _msgSender();
257
242
  if (operator != from) {
258
- require(
259
- _operatorAuthorizedAmount[from][operator] >= amount,
260
- "LSP7: burn amount exceeds operator authorized amount"
261
- );
243
+ uint256 authorizedAmount = _operatorAuthorizedAmount[from][operator];
244
+ if (amount > authorizedAmount) {
245
+ revert LSP7AmountExceedsAuthorizedAmount(from, authorizedAmount, operator, amount);
246
+ }
262
247
  _operatorAuthorizedAmount[from][operator] -= amount;
263
248
  }
264
249
 
265
- _notifyTokenSender(from, address(0), amount, data);
266
-
267
250
  _beforeTokenTransfer(from, address(0), amount);
268
251
 
269
252
  _tokenOwnerBalances[from] -= amount;
270
253
 
271
254
  emit Transfer(operator, from, address(0), amount, false, data);
255
+
256
+ _notifyTokenSender(from, address(0), amount, data);
272
257
  }
273
258
 
274
259
  /**
@@ -291,16 +276,16 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
291
276
  bool force,
292
277
  bytes memory data
293
278
  ) internal virtual {
294
- require(from != address(0), "LSP7: transfer from the zero address");
295
- require(to != address(0), "LSP7: transfer to the zero address");
296
- require(
297
- _tokenOwnerBalances[from] >= amount,
298
- "LSP7: transfer amount exceeds tokenOwner balance"
299
- );
279
+ if (from == address(0) || to == address(0)) {
280
+ revert LSP7CannotSendWithAddressZero();
281
+ }
300
282
 
301
- address operator = _msgSender();
283
+ uint256 balance = _tokenOwnerBalances[from];
284
+ if (amount > balance) {
285
+ revert LSP7AmountExceedsBalance(balance, from, amount);
286
+ }
302
287
 
303
- _notifyTokenSender(from, to, amount, data);
288
+ address operator = _msgSender();
304
289
 
305
290
  _beforeTokenTransfer(from, to, amount);
306
291
 
@@ -309,6 +294,7 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
309
294
 
310
295
  emit Transfer(operator, from, to, amount, force, data);
311
296
 
297
+ _notifyTokenSender(from, to, amount, data);
312
298
  _notifyTokenReceiver(from, to, amount, force, data);
313
299
  }
314
300
 
@@ -349,15 +335,9 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
349
335
  uint256 amount,
350
336
  bytes memory data
351
337
  ) internal virtual {
352
- if (
353
- ERC165Checker.supportsERC165(from) &&
354
- ERC165Checker.supportsInterface(from, _INTERFACEID_LSP1)
355
- ) {
338
+ if (ERC165Checker.supportsERC165Interface(from, _INTERFACEID_LSP1)) {
356
339
  bytes memory packedData = abi.encodePacked(from, to, amount, data);
357
- ILSP1UniversalReceiver(from).universalReceiver(
358
- _TYPEID_LSP7_TOKENSSENDER,
359
- packedData
360
- );
340
+ ILSP1UniversalReceiver(from).universalReceiver(_TYPEID_LSP7_TOKENSSENDER, packedData);
361
341
  }
362
342
  }
363
343
 
@@ -374,20 +354,14 @@ abstract contract LSP7DigitalAssetCore is Context, ILSP7DigitalAsset {
374
354
  bool force,
375
355
  bytes memory data
376
356
  ) internal virtual {
377
- if (
378
- ERC165Checker.supportsERC165(to) &&
379
- ERC165Checker.supportsInterface(to, _INTERFACEID_LSP1)
380
- ) {
357
+ if (ERC165Checker.supportsERC165Interface(to, _INTERFACEID_LSP1)) {
381
358
  bytes memory packedData = abi.encodePacked(from, to, amount, data);
382
- ILSP1UniversalReceiver(to).universalReceiver(
383
- _TYPEID_LSP7_TOKENSRECIPIENT,
384
- packedData
385
- );
359
+ ILSP1UniversalReceiver(to).universalReceiver(_TYPEID_LSP7_TOKENSRECIPIENT, packedData);
386
360
  } else if (!force) {
387
- if (to.isContract()) {
388
- revert("LSP7: token receiver contract missing LSP1 interface");
361
+ if (to.code.length != 0) {
362
+ revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
389
363
  } else {
390
- revert("LSP7: token receiver is EOA");
364
+ revert LSP7NotifyTokenReceiverIsEOA(to);
391
365
  }
392
366
  }
393
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
- Initializable,
19
21
  LSP4DigitalAssetMetadataInitAbstract,
20
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
  }