@lukso/lsp-smart-contracts 0.12.0-rc.0 → 0.12.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 (135) hide show
  1. package/artifacts/LSP0ERC725Account.json +18 -24
  2. package/artifacts/LSP0ERC725AccountInit.json +18 -24
  3. package/artifacts/LSP1UniversalReceiverDelegateUP.json +15 -2
  4. package/artifacts/LSP1UniversalReceiverDelegateVault.json +15 -2
  5. package/artifacts/LSP6KeyManager.json +25 -2
  6. package/artifacts/LSP6KeyManagerInit.json +25 -2
  7. package/artifacts/LSP7CappedSupply.json +35 -0
  8. package/artifacts/LSP7CappedSupplyInitAbstract.json +35 -0
  9. package/artifacts/LSP7CompatibleERC20.json +35 -0
  10. package/artifacts/LSP7CompatibleERC20InitAbstract.json +35 -0
  11. package/artifacts/LSP7CompatibleERC20Mintable.json +37 -2
  12. package/artifacts/LSP7CompatibleERC20MintableInit.json +37 -2
  13. package/artifacts/LSP7DigitalAsset.json +35 -0
  14. package/artifacts/LSP7DigitalAssetInitAbstract.json +35 -0
  15. package/artifacts/LSP7Mintable.json +37 -2
  16. package/artifacts/LSP7MintableInit.json +37 -2
  17. package/artifacts/LSP8CappedSupply.json +24 -0
  18. package/artifacts/LSP8CappedSupplyInitAbstract.json +24 -0
  19. package/artifacts/LSP8CompatibleERC721.json +24 -0
  20. package/artifacts/LSP8CompatibleERC721InitAbstract.json +24 -0
  21. package/artifacts/LSP8CompatibleERC721Mintable.json +26 -2
  22. package/artifacts/LSP8CompatibleERC721MintableInit.json +26 -2
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +24 -0
  24. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +24 -0
  25. package/artifacts/LSP8Mintable.json +26 -2
  26. package/artifacts/LSP8MintableInit.json +26 -2
  27. package/artifacts/LSP9Vault.json +15 -21
  28. package/artifacts/LSP9VaultInit.json +15 -21
  29. package/artifacts/UniversalProfile.json +18 -24
  30. package/artifacts/UniversalProfileInit.json +18 -24
  31. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +0 -8
  32. package/contracts/LSP0ERC725Account/LSP0Constants.sol +5 -0
  33. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +12 -2
  34. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +75 -30
  35. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
  36. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +11 -2
  37. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +12 -8
  38. package/contracts/LSP17ContractExtension/LSP17Extension.sol +2 -1
  39. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +30 -7
  40. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +16 -7
  41. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +3 -2
  42. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +43 -49
  43. package/contracts/LSP20CallVerification/LSP20Errors.sol +2 -2
  44. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +42 -2
  45. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +3 -3
  46. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +60 -0
  47. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
  48. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +7 -5
  49. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +122 -176
  50. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +7 -5
  51. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  52. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +8 -1
  53. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +7 -1
  54. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -0
  55. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +8 -5
  56. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +6 -5
  57. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +41 -74
  58. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +6 -5
  59. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +10 -7
  60. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +10 -7
  61. package/contracts/LSP9Vault/ILSP9Vault.sol +0 -8
  62. package/contracts/LSP9Vault/LSP9Constants.sol +5 -0
  63. package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
  64. package/contracts/LSP9Vault/LSP9VaultCore.sol +63 -27
  65. package/contracts/LSP9Vault/LSP9VaultInit.sol +1 -1
  66. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
  67. package/contracts/UniversalProfile.sol +1 -1
  68. package/contracts/UniversalProfileInit.sol +1 -1
  69. package/contracts/UniversalProfileInitAbstract.sol +1 -1
  70. package/contracts/Version.sol +16 -0
  71. package/devdocs/LSP0ERC725Account.json +14 -8
  72. package/devdocs/LSP0ERC725AccountInit.json +14 -8
  73. package/devdocs/LSP1UniversalReceiverDelegateUP.json +6 -0
  74. package/devdocs/LSP1UniversalReceiverDelegateVault.json +6 -0
  75. package/devdocs/LSP6KeyManager.json +16 -0
  76. package/devdocs/LSP6KeyManagerInit.json +16 -0
  77. package/devdocs/LSP7CappedSupply.json +16 -10
  78. package/devdocs/LSP7CappedSupplyInitAbstract.json +16 -10
  79. package/devdocs/LSP7CompatibleERC20.json +16 -10
  80. package/devdocs/LSP7CompatibleERC20InitAbstract.json +16 -10
  81. package/devdocs/LSP7CompatibleERC20Mintable.json +16 -10
  82. package/devdocs/LSP7CompatibleERC20MintableInit.json +16 -10
  83. package/devdocs/LSP7DigitalAsset.json +16 -10
  84. package/devdocs/LSP7DigitalAssetInitAbstract.json +16 -10
  85. package/devdocs/LSP7Mintable.json +16 -10
  86. package/devdocs/LSP7MintableInit.json +16 -10
  87. package/devdocs/LSP8CappedSupply.json +9 -2
  88. package/devdocs/LSP8CappedSupplyInitAbstract.json +9 -2
  89. package/devdocs/LSP8CompatibleERC721.json +9 -2
  90. package/devdocs/LSP8CompatibleERC721InitAbstract.json +9 -2
  91. package/devdocs/LSP8CompatibleERC721Mintable.json +9 -2
  92. package/devdocs/LSP8CompatibleERC721MintableInit.json +9 -2
  93. package/devdocs/LSP8IdentifiableDigitalAsset.json +9 -2
  94. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +9 -2
  95. package/devdocs/LSP8Mintable.json +9 -2
  96. package/devdocs/LSP8MintableInit.json +9 -2
  97. package/devdocs/LSP9Vault.json +12 -6
  98. package/devdocs/LSP9VaultInit.json +12 -6
  99. package/devdocs/UniversalProfile.json +14 -8
  100. package/devdocs/UniversalProfileInit.json +14 -8
  101. package/dist/constants.cjs.js +1211 -454
  102. package/dist/constants.d.ts +1277 -374
  103. package/dist/constants.es.js +1211 -454
  104. package/package.json +1 -3
  105. package/userdocs/LSP0ERC725Account.json +3 -3
  106. package/userdocs/LSP0ERC725AccountInit.json +3 -3
  107. package/userdocs/LSP1UniversalReceiverDelegateUP.json +3 -0
  108. package/userdocs/LSP1UniversalReceiverDelegateVault.json +3 -0
  109. package/userdocs/LSP6KeyManager.json +3 -0
  110. package/userdocs/LSP6KeyManagerInit.json +3 -0
  111. package/userdocs/LSP7CappedSupply.json +3 -0
  112. package/userdocs/LSP7CappedSupplyInitAbstract.json +3 -0
  113. package/userdocs/LSP7CompatibleERC20.json +3 -0
  114. package/userdocs/LSP7CompatibleERC20InitAbstract.json +3 -0
  115. package/userdocs/LSP7CompatibleERC20Mintable.json +3 -0
  116. package/userdocs/LSP7CompatibleERC20MintableInit.json +3 -0
  117. package/userdocs/LSP7DigitalAsset.json +3 -0
  118. package/userdocs/LSP7DigitalAssetInitAbstract.json +3 -0
  119. package/userdocs/LSP7Mintable.json +3 -0
  120. package/userdocs/LSP7MintableInit.json +3 -0
  121. package/userdocs/LSP8CappedSupply.json +3 -0
  122. package/userdocs/LSP8CappedSupplyInitAbstract.json +3 -0
  123. package/userdocs/LSP8CompatibleERC721.json +3 -0
  124. package/userdocs/LSP8CompatibleERC721InitAbstract.json +3 -0
  125. package/userdocs/LSP8CompatibleERC721Mintable.json +3 -0
  126. package/userdocs/LSP8CompatibleERC721MintableInit.json +3 -0
  127. package/userdocs/LSP8IdentifiableDigitalAsset.json +3 -0
  128. package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +3 -0
  129. package/userdocs/LSP8Mintable.json +3 -0
  130. package/userdocs/LSP8MintableInit.json +3 -0
  131. package/userdocs/LSP9Vault.json +3 -3
  132. package/userdocs/LSP9VaultInit.json +3 -3
  133. package/userdocs/UniversalProfile.json +3 -3
  134. package/userdocs/UniversalProfileInit.json +3 -3
  135. package/CONTRIBUTING.md +0 -188
@@ -103,8 +103,9 @@ abstract contract LSP7DigitalAssetInitAbstract is
103
103
  /**
104
104
  * @dev Forwards the call with the received value to an extension mapped to a function selector.
105
105
  *
106
- * Calls {_getExtension} to get the address of the extension mapped to the function selector being
106
+ * Calls {_getExtensionAndForwardValue} to get the address of the extension mapped to the function selector being
107
107
  * called on the account. If there is no extension, the address(0) will be returned.
108
+ * Forwards the value if the extension is payable.
108
109
  *
109
110
  * Reverts if there is no extension for the function being called.
110
111
  *
@@ -119,7 +120,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
119
120
  bytes calldata callData
120
121
  ) internal virtual override returns (bytes memory) {
121
122
  // If there is a function selector
122
- address extension = _getExtension(msg.sig);
123
+ (address extension, ) = _getExtensionAndForwardValue(msg.sig);
123
124
 
124
125
  // if no extension was found, revert
125
126
  if (extension == address(0))
@@ -147,10 +148,11 @@ abstract contract LSP7DigitalAssetInitAbstract is
147
148
  * @dev Returns the extension address stored under the following data key:
148
149
  * - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
149
150
  * - If no extension is stored, returns the address(0).
151
+ * - We do not check that payable bool as in lsp7 standard we will always forward the value to the extension
150
152
  */
151
- function _getExtension(
153
+ function _getExtensionAndForwardValue(
152
154
  bytes4 functionSelector
153
- ) internal view virtual override returns (address) {
155
+ ) internal view virtual override returns (address, bool) {
154
156
  // Generate the data key relevant for the functionSelector being called
155
157
  bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
156
158
  _LSP17_EXTENSION_PREFIX,
@@ -164,7 +166,7 @@ abstract contract LSP7DigitalAssetInitAbstract is
164
166
  if (extensionAddress.length != 20 && extensionAddress.length != 0)
165
167
  revert InvalidExtensionAddress(extensionAddress);
166
168
 
167
- return address(bytes20(extensionAddress));
169
+ return (address(bytes20(extensionAddress)), true);
168
170
  }
169
171
 
170
172
  /**
@@ -77,3 +77,8 @@ error LSP7DecreasedAllowanceBelowZero();
77
77
  * @notice LSP7 contract cannot receive native tokens.
78
78
  */
79
79
  error LSP7TokenContractCannotHoldValue();
80
+
81
+ /**
82
+ * @dev Reverts when token owner call {increaseAllowance} for an operator that does not have any allowance
83
+ */
84
+ error OperatorAllowanceCannotBeIncreasedFromZero(address operator);
@@ -140,7 +140,12 @@ abstract contract LSP7CompatibleERC20 is IERC20Metadata, LSP7DigitalAsset {
140
140
  address operator,
141
141
  uint256 amount
142
142
  ) public virtual returns (bool) {
143
- authorizeOperator(operator, amount, "");
143
+ if (amount != 0) {
144
+ authorizeOperator(operator, amount, "");
145
+ } else {
146
+ revokeOperator(operator, false, "");
147
+ }
148
+
144
149
  return true;
145
150
  }
146
151
 
@@ -193,12 +198,14 @@ abstract contract LSP7CompatibleERC20 is IERC20Metadata, LSP7DigitalAsset {
193
198
  address tokenOwner,
194
199
  address operator,
195
200
  uint256 amount,
201
+ bool notified,
196
202
  bytes memory operatorNotificationData
197
203
  ) internal virtual override {
198
204
  super._updateOperator(
199
205
  tokenOwner,
200
206
  operator,
201
207
  amount,
208
+ notified,
202
209
  operatorNotificationData
203
210
  );
204
211
  emit IERC20.Approval(tokenOwner, operator, amount);
@@ -153,7 +153,11 @@ abstract contract LSP7CompatibleERC20InitAbstract is
153
153
  address operator,
154
154
  uint256 amount
155
155
  ) public virtual returns (bool) {
156
- authorizeOperator(operator, amount, "");
156
+ if (amount != 0) {
157
+ authorizeOperator(operator, amount, "");
158
+ } else {
159
+ revokeOperator(operator, false, "");
160
+ }
157
161
  return true;
158
162
  }
159
163
 
@@ -206,12 +210,14 @@ abstract contract LSP7CompatibleERC20InitAbstract is
206
210
  address tokenOwner,
207
211
  address operator,
208
212
  uint256 amount,
213
+ bool notified,
209
214
  bytes memory operatorNotificationData
210
215
  ) internal virtual override {
211
216
  super._updateOperator(
212
217
  tokenOwner,
213
218
  operator,
214
219
  amount,
220
+ notified,
215
221
  operatorNotificationData
216
222
  );
217
223
  emit IERC20.Approval(tokenOwner, operator, amount);
@@ -51,12 +51,14 @@ interface ILSP8IdentifiableDigitalAsset is IERC165, IERC725Y {
51
51
  * @param operator The address revoked from the operator array ({getOperatorsOf}).
52
52
  * @param tokenOwner The owner of the `tokenId`.
53
53
  * @param tokenId The tokenId `operator` is revoked from operating on.
54
+ * @param notified Bool indicating whether the operator has been notified or not
54
55
  * @param operatorNotificationData The data to notify the operator about via LSP1.
55
56
  */
56
57
  event RevokedOperator(
57
58
  address indexed operator,
58
59
  address indexed tokenOwner,
59
60
  bytes32 indexed tokenId,
61
+ bool notified,
60
62
  bytes operatorNotificationData
61
63
  );
62
64
 
@@ -102,6 +104,7 @@ interface ILSP8IdentifiableDigitalAsset is IERC165, IERC725Y {
102
104
 
103
105
  /**
104
106
  * @dev Allow an `operator` address to transfer or burn a specific `tokenId` on behalf of its token owner. See {isOperatorFor}.
107
+ * Notify the operator based on the LSP1-UniversalReceiver standard
105
108
  *
106
109
  * @param operator The address to authorize as an operator.
107
110
  * @param tokenId The token ID operator has access to.
@@ -127,6 +130,7 @@ interface ILSP8IdentifiableDigitalAsset is IERC165, IERC725Y {
127
130
  *
128
131
  * @param operator The address to revoke as an operator.
129
132
  * @param tokenId The tokenId `operator` is revoked from operating on.
133
+ * @param notify Boolean indicating whether to notify the operator or not
130
134
  * @param operatorNotificationData The data to notify the operator about via LSP1.
131
135
  *
132
136
  * @custom:requirements
@@ -140,6 +144,7 @@ interface ILSP8IdentifiableDigitalAsset is IERC165, IERC725Y {
140
144
  function revokeOperator(
141
145
  address operator,
142
146
  bytes32 tokenId,
147
+ bool notify,
143
148
  bytes memory operatorNotificationData
144
149
  ) external;
145
150
 
@@ -2,18 +2,21 @@
2
2
  pragma solidity ^0.8.4;
3
3
 
4
4
  // --- ERC165 interface ids
5
- bytes4 constant _INTERFACEID_LSP8 = 0x1ae9ba1f;
5
+ bytes4 constant _INTERFACEID_LSP8 = 0x30dc5278;
6
6
 
7
7
  // --- ERC725Y Data Keys
8
8
 
9
9
  // keccak256('LSP8TokenIdType')
10
10
  bytes32 constant _LSP8_TOKENID_TYPE_KEY = 0x715f248956de7ce65e94d9d836bfead479f7e70d69b718d47bfe7b00e05b4fe4;
11
11
 
12
- // bytes10(keccak256('LSP8MetadataAddress')) + bytes2(0)
13
- bytes12 constant _LSP8_METADATA_ADDRESS_KEY_PREFIX = 0x73dcc7c3c4096cdc7f8a0000;
12
+ // bytes10(keccak256('LSP8MetadataTokenURI')) + bytes2(0)
13
+ bytes12 constant _LSP8_METADATA_TOKEN_URI_PREFIX = 0x1339e76a390b7b9ec9010000;
14
14
 
15
- // bytes10(keccak256('LSP8MetadataJSON')) + bytes2(0)
16
- bytes12 constant _LSP8_METADATA_JSON_KEY_PREFIX = 0x9a26b4060ae7f7d5e3cd0000;
15
+ // keccak256('LSP8TokenMetadataBaseURI')
16
+ bytes32 constant _LSP8_TOKEN_METADATA_BASE_URI = 0x1a7628600c3bac7101f53697f48df381ddc36b9015e7d7c9c5633d1252aa2843;
17
+
18
+ // keccak256('LSP8ReferenceContract')
19
+ bytes32 constant _LSP8_REFERENCE_CONTRACT = 0x708e7b881795f2e6b6c2752108c177ec89248458de3bf69d0d43480b3e5034e6;
17
20
 
18
21
  // --- Token Hooks
19
22
 
@@ -130,8 +130,9 @@ abstract contract LSP8IdentifiableDigitalAsset is
130
130
  /**
131
131
  * @dev Forwards the call with the received value to an extension mapped to a function selector.
132
132
  *
133
- * Calls {_getExtension} to get the address of the extension mapped to the function selector being
133
+ * Calls {_getExtensionAndForwardValue} to get the address of the extension mapped to the function selector being
134
134
  * called on the account. If there is no extension, the address(0) will be returned.
135
+ * We will always forward the value to the extension, as the LSP8 contract is not supposed to hold any native tokens.
135
136
  *
136
137
  * Reverts if there is no extension for the function being called.
137
138
  *
@@ -146,7 +147,7 @@ abstract contract LSP8IdentifiableDigitalAsset is
146
147
  bytes calldata callData
147
148
  ) internal virtual override returns (bytes memory) {
148
149
  // If there is a function selector
149
- address extension = _getExtension(msg.sig);
150
+ (address extension, ) = _getExtensionAndForwardValue(msg.sig);
150
151
 
151
152
  // if no extension was found, revert
152
153
  if (extension == address(0))
@@ -175,9 +176,9 @@ abstract contract LSP8IdentifiableDigitalAsset is
175
176
  * - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
176
177
  * - If no extension is stored, returns the address(0).
177
178
  */
178
- function _getExtension(
179
+ function _getExtensionAndForwardValue(
179
180
  bytes4 functionSelector
180
- ) internal view virtual override returns (address) {
181
+ ) internal view virtual override returns (address, bool) {
181
182
  // Generate the data key relevant for the functionSelector being called
182
183
  bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
183
184
  _LSP17_EXTENSION_PREFIX,
@@ -191,7 +192,7 @@ abstract contract LSP8IdentifiableDigitalAsset is
191
192
  if (extensionAddress.length != 20 && extensionAddress.length != 0)
192
193
  revert InvalidExtensionAddress(extensionAddress);
193
194
 
194
- return address(bytes20(extensionAddress));
195
+ return (address(bytes20(extensionAddress)), true);
195
196
  }
196
197
 
197
198
  /**
@@ -3,12 +3,15 @@ pragma solidity ^0.8.4;
3
3
 
4
4
  // interfaces
5
5
  import {
6
- ILSP1UniversalReceiver
6
+ ILSP1UniversalReceiver as ILSP1
7
7
  } from "../LSP1UniversalReceiver/ILSP1UniversalReceiver.sol";
8
8
  import {
9
9
  ILSP8IdentifiableDigitalAsset
10
10
  } from "./ILSP8IdentifiableDigitalAsset.sol";
11
11
 
12
+ // modules
13
+ import {Version} from "../Version.sol";
14
+
12
15
  // libraries
13
16
  import {
14
17
  EnumerableSet
@@ -16,6 +19,7 @@ import {
16
19
  import {
17
20
  ERC165Checker
18
21
  } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
22
+ import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
19
23
 
20
24
  // errors
21
25
  import {
@@ -48,10 +52,13 @@ import {
48
52
  * @dev Core Implementation of a LSP8 compliant contract.
49
53
  */
50
54
  abstract contract LSP8IdentifiableDigitalAssetCore is
51
- ILSP8IdentifiableDigitalAsset
55
+ ILSP8IdentifiableDigitalAsset,
56
+ Version
52
57
  {
53
58
  using EnumerableSet for EnumerableSet.AddressSet;
54
59
  using EnumerableSet for EnumerableSet.Bytes32Set;
60
+ using ERC165Checker for address;
61
+ using LSP1Utils for address;
55
62
 
56
63
  // --- Storage
57
64
 
@@ -149,9 +156,14 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
149
156
  bytes memory lsp1Data = abi.encode(
150
157
  msg.sender,
151
158
  tokenId,
159
+ true, // authorized
152
160
  operatorNotificationData
153
161
  );
154
- _notifyTokenOperator(operator, lsp1Data);
162
+
163
+ operator.tryNotifyUniversalReceiver(
164
+ _TYPEID_LSP8_TOKENOPERATOR,
165
+ lsp1Data
166
+ );
155
167
  }
156
168
 
157
169
  /**
@@ -160,6 +172,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
160
172
  function revokeOperator(
161
173
  address operator,
162
174
  bytes32 tokenId,
175
+ bool notify,
163
176
  bytes memory operatorNotificationData
164
177
  ) public virtual override {
165
178
  address tokenOwner = tokenOwnerOf(tokenId);
@@ -180,15 +193,23 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
180
193
  operator,
181
194
  tokenOwner,
182
195
  tokenId,
196
+ notify,
183
197
  operatorNotificationData
184
198
  );
185
199
 
186
- bytes memory lsp1Data = abi.encode(
187
- msg.sender,
188
- tokenId,
189
- operatorNotificationData
190
- );
191
- _notifyTokenOperator(operator, lsp1Data);
200
+ if (notify) {
201
+ bytes memory lsp1Data = abi.encode(
202
+ msg.sender,
203
+ tokenId,
204
+ false, // unauthorized
205
+ operatorNotificationData
206
+ );
207
+
208
+ operator.tryNotifyUniversalReceiver(
209
+ _TYPEID_LSP8_TOKENOPERATOR,
210
+ lsp1Data
211
+ );
212
+ }
192
213
  }
193
214
 
194
215
  /**
@@ -281,6 +302,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
281
302
  address operator,
282
303
  address tokenOwner,
283
304
  bytes32 tokenId,
305
+ bool notified,
284
306
  bytes memory operatorNotificationData
285
307
  ) internal virtual {
286
308
  bool isRemoved = _operators[tokenId].remove(operator);
@@ -290,6 +312,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
290
312
  operator,
291
313
  tokenOwner,
292
314
  tokenId,
315
+ notified,
293
316
  operatorNotificationData
294
317
  );
295
318
  }
@@ -319,7 +342,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
319
342
  for (uint256 i; i < operatorListLength; ) {
320
343
  // we are emptying the list, always remove from index 0
321
344
  operator = operatorsForTokenId.at(0);
322
- _revokeOperator(operator, tokenOwner, tokenId, "");
345
+ _revokeOperator(operator, tokenOwner, tokenId, false, "");
323
346
 
324
347
  unchecked {
325
348
  ++i;
@@ -443,7 +466,11 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
443
466
  tokenId,
444
467
  data
445
468
  );
446
- _notifyTokenSender(tokenOwner, lsp1Data);
469
+
470
+ tokenOwner.tryNotifyUniversalReceiver(
471
+ _TYPEID_LSP8_TOKENSSENDER,
472
+ lsp1Data
473
+ );
447
474
  }
448
475
 
449
476
  /**
@@ -509,7 +536,7 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
509
536
 
510
537
  bytes memory lsp1Data = abi.encode(from, to, tokenId, data);
511
538
 
512
- _notifyTokenSender(from, lsp1Data);
539
+ from.tryNotifyUniversalReceiver(_TYPEID_LSP8_TOKENSSENDER, lsp1Data);
513
540
  _notifyTokenReceiver(to, force, lsp1Data);
514
541
  }
515
542
 
@@ -545,58 +572,6 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
545
572
  bytes memory data // solhint-disable-next-line no-empty-blocks
546
573
  ) internal virtual {}
547
574
 
548
- /**
549
- * @dev Attempt to notify the operator `operator` about the `tokenId` tokens being authorized.
550
- * This is done by calling its {universalReceiver} function with the `_TYPEID_LSP8_TOKENOPERATOR` as typeId, if `operator` is a contract that supports the LSP1 interface.
551
- * If `operator` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
552
-
553
- * @param operator The address to call the {universalReceiver} function on.
554
- * @param lsp1Data the data to be sent to the `operator` address in the `universalReceiver` call.
555
- */
556
- function _notifyTokenOperator(
557
- address operator,
558
- bytes memory lsp1Data
559
- ) internal virtual {
560
- if (
561
- ERC165Checker.supportsERC165InterfaceUnchecked(
562
- operator,
563
- _INTERFACEID_LSP1
564
- )
565
- ) {
566
- try
567
- ILSP1UniversalReceiver(operator).universalReceiver(
568
- _TYPEID_LSP8_TOKENOPERATOR,
569
- lsp1Data
570
- )
571
- {
572
- return;
573
- } catch {
574
- return;
575
- }
576
- }
577
- }
578
-
579
- /**
580
- * @dev An attempt is made to notify the token sender about the `tokenId` changing owners using
581
- * LSP1 interface.
582
- */
583
- function _notifyTokenSender(
584
- address from,
585
- bytes memory lsp1Data
586
- ) internal virtual {
587
- if (
588
- ERC165Checker.supportsERC165InterfaceUnchecked(
589
- from,
590
- _INTERFACEID_LSP1
591
- )
592
- ) {
593
- ILSP1UniversalReceiver(from).universalReceiver(
594
- _TYPEID_LSP8_TOKENSSENDER,
595
- lsp1Data
596
- );
597
- }
598
- }
599
-
600
575
  /**
601
576
  * @dev An attempt is made to notify the token receiver about the `tokenId` changing owners
602
577
  * using LSP1 interface. When force is FALSE the token receiver MUST support LSP1.
@@ -608,16 +583,8 @@ abstract contract LSP8IdentifiableDigitalAssetCore is
608
583
  bool force,
609
584
  bytes memory lsp1Data
610
585
  ) internal virtual {
611
- if (
612
- ERC165Checker.supportsERC165InterfaceUnchecked(
613
- to,
614
- _INTERFACEID_LSP1
615
- )
616
- ) {
617
- ILSP1UniversalReceiver(to).universalReceiver(
618
- _TYPEID_LSP8_TOKENSRECIPIENT,
619
- lsp1Data
620
- );
586
+ if (to.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
587
+ ILSP1(to).universalReceiver(_TYPEID_LSP8_TOKENSRECIPIENT, lsp1Data);
621
588
  } else if (!force) {
622
589
  if (to.code.length != 0) {
623
590
  revert LSP8NotifyTokenReceiverContractMissingLSP1Interface(to);
@@ -133,8 +133,9 @@ abstract contract LSP8IdentifiableDigitalAssetInitAbstract is
133
133
  /**
134
134
  * @dev Forwards the call with the received value to an extension mapped to a function selector.
135
135
  *
136
- * Calls {_getExtension} to get the address of the extension mapped to the function selector being
136
+ * Calls {_getExtensionAndForwardValue} to get the address of the extension mapped to the function selector being
137
137
  * called on the account. If there is no extension, the address(0) will be returned.
138
+ * We will always forward the value to the extension, as the LSP8 contract is not supposed to hold any native tokens.
138
139
  *
139
140
  * Reverts if there is no extension for the function being called.
140
141
  *
@@ -149,7 +150,7 @@ abstract contract LSP8IdentifiableDigitalAssetInitAbstract is
149
150
  bytes calldata callData
150
151
  ) internal virtual override returns (bytes memory) {
151
152
  // If there is a function selector
152
- address extension = _getExtension(msg.sig);
153
+ (address extension, ) = _getExtensionAndForwardValue(msg.sig);
153
154
 
154
155
  // if no extension was found, revert
155
156
  if (extension == address(0))
@@ -178,9 +179,9 @@ abstract contract LSP8IdentifiableDigitalAssetInitAbstract is
178
179
  * - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
179
180
  * - If no extension is stored, returns the address(0).
180
181
  */
181
- function _getExtension(
182
+ function _getExtensionAndForwardValue(
182
183
  bytes4 functionSelector
183
- ) internal view virtual override returns (address) {
184
+ ) internal view virtual override returns (address, bool) {
184
185
  // Generate the data key relevant for the functionSelector being called
185
186
  bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
186
187
  _LSP17_EXTENSION_PREFIX,
@@ -194,7 +195,7 @@ abstract contract LSP8IdentifiableDigitalAssetInitAbstract is
194
195
  if (extensionAddress.length != 20 && extensionAddress.length != 0)
195
196
  revert InvalidExtensionAddress(extensionAddress);
196
197
 
197
- return address(bytes20(extensionAddress));
198
+ return (address(bytes20(extensionAddress)), true);
198
199
  }
199
200
 
200
201
  /**
@@ -12,10 +12,11 @@ import {
12
12
  } from "@openzeppelin/contracts/interfaces/IERC721Metadata.sol";
13
13
 
14
14
  // libraries
15
+ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
15
16
  import {
16
17
  EnumerableSet
17
18
  } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
18
- import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
19
+ import {LSP1Utils} from "../../LSP1UniversalReceiver/LSP1Utils.sol";
19
20
 
20
21
  // modules
21
22
  import {
@@ -38,6 +39,7 @@ import {
38
39
  _LSP4_TOKEN_NAME_KEY,
39
40
  _LSP4_TOKEN_SYMBOL_KEY
40
41
  } from "../../LSP4DigitalAssetMetadata/LSP4Constants.sol";
42
+ import {_TYPEID_LSP8_TOKENOPERATOR} from "../LSP8Constants.sol";
41
43
 
42
44
  /**
43
45
  * @dev LSP8 extension, for compatibility for clients / tools that expect ERC721.
@@ -46,7 +48,9 @@ abstract contract LSP8CompatibleERC721 is
46
48
  IERC721Metadata,
47
49
  LSP8IdentifiableDigitalAsset
48
50
  {
51
+ using BytesLib for bytes;
49
52
  using EnumerableSet for EnumerableSet.AddressSet;
53
+ using LSP1Utils for address;
50
54
 
51
55
  /**
52
56
  * @dev Mapping from owner to operator approvals for backward compatibility with ERC721
@@ -141,11 +145,7 @@ abstract contract LSP8CompatibleERC721 is
141
145
  // offset = bytes4(hashSig) + bytes32(contentHash) -> 4 + 32 = 36
142
146
  uint256 offset = 36;
143
147
 
144
- bytes memory uriBytes = BytesLib.slice(
145
- data,
146
- offset,
147
- data.length - offset
148
- );
148
+ bytes memory uriBytes = data.slice(offset, data.length - offset);
149
149
  return string(uriBytes);
150
150
  }
151
151
 
@@ -357,7 +357,10 @@ abstract contract LSP8CompatibleERC721 is
357
357
  tokenId,
358
358
  operatorNotificationData
359
359
  );
360
- _notifyTokenOperator(operator, lsp1Data);
360
+ operator.tryNotifyUniversalReceiver(
361
+ _TYPEID_LSP8_TOKENOPERATOR,
362
+ lsp1Data
363
+ );
361
364
  }
362
365
 
363
366
  /**
@@ -12,10 +12,11 @@ import {
12
12
  } from "@openzeppelin/contracts/interfaces/IERC721Metadata.sol";
13
13
 
14
14
  // libraries
15
+ import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
15
16
  import {
16
17
  EnumerableSet
17
18
  } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
18
- import {BytesLib} from "solidity-bytes-utils/contracts/BytesLib.sol";
19
+ import {LSP1Utils} from "../../LSP1UniversalReceiver/LSP1Utils.sol";
19
20
 
20
21
  // modules
21
22
  import {
@@ -38,6 +39,7 @@ import {
38
39
  _LSP4_TOKEN_NAME_KEY,
39
40
  _LSP4_TOKEN_SYMBOL_KEY
40
41
  } from "../../LSP4DigitalAssetMetadata/LSP4Constants.sol";
42
+ import {_TYPEID_LSP8_TOKENOPERATOR} from "../LSP8Constants.sol";
41
43
 
42
44
  /**
43
45
  * @dev LSP8 extension, for compatibility for clients / tools that expect ERC721.
@@ -46,7 +48,9 @@ abstract contract LSP8CompatibleERC721InitAbstract is
46
48
  IERC721Metadata,
47
49
  LSP8IdentifiableDigitalAssetInitAbstract
48
50
  {
51
+ using BytesLib for bytes;
49
52
  using EnumerableSet for EnumerableSet.AddressSet;
53
+ using LSP1Utils for address;
50
54
 
51
55
  /**
52
56
  * @dev Mapping from owner to operator approvals for backward compatibility with ERC721
@@ -149,11 +153,7 @@ abstract contract LSP8CompatibleERC721InitAbstract is
149
153
  // offset = bytes4(hashSig) + bytes32(contentHash) -> 4 + 32 = 36
150
154
  uint256 offset = 36;
151
155
 
152
- bytes memory uriBytes = BytesLib.slice(
153
- data,
154
- offset,
155
- data.length - offset
156
- );
156
+ bytes memory uriBytes = data.slice(offset, data.length - offset);
157
157
  return string(uriBytes);
158
158
  }
159
159
 
@@ -366,7 +366,10 @@ abstract contract LSP8CompatibleERC721InitAbstract is
366
366
  tokenId,
367
367
  operatorNotificationData
368
368
  );
369
- _notifyTokenOperator(operator, lsp1Data);
369
+ operator.tryNotifyUniversalReceiver(
370
+ _TYPEID_LSP8_TOKENOPERATOR,
371
+ lsp1Data
372
+ );
370
373
  }
371
374
 
372
375
  /**
@@ -6,14 +6,6 @@ pragma solidity ^0.8.4;
6
6
  * @dev Could be owned by an EOA or by a contract and is able to receive and send assets. Also allows for registering received assets by leveraging the key-value storage.
7
7
  */
8
8
  interface ILSP9Vault {
9
- /**
10
- * @notice `value` native tokens received from `sender`.
11
- * @dev Emitted when receiving native tokens.
12
- * @param sender The address that sent some native tokens to this contract.
13
- * @param value The amount of native tokens received.
14
- */
15
- event ValueReceived(address indexed sender, uint256 indexed value);
16
-
17
9
  /**
18
10
  * @notice Executing the following batch of abi-encoded function calls on the contract: `data`.
19
11
  *
@@ -12,6 +12,11 @@ bytes32 constant _LSP9_SUPPORTED_STANDARDS_KEY = 0xeafec4d89fa9619884b600007c033
12
12
  // bytes4(keccak256('LSP9Vault'))
13
13
  bytes constant _LSP9_SUPPORTED_STANDARDS_VALUE = hex"7c0334a1";
14
14
 
15
+ // --- Native Token Type Id
16
+
17
+ // keccak256('LSP9ValueReceived')
18
+ bytes32 constant _TYPEID_LSP9_VALUE_RECEIVED = 0x468cd1581d7bc001c3b685513d2b929b55437be34700410383d58f3aa1ea0abc;
19
+
15
20
  // Ownerhsip Transfer Type IDs
16
21
 
17
22
  // keccak256('LSP9OwnershipTransferStarted')
@@ -14,6 +14,7 @@ import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
14
14
  import {
15
15
  _LSP9_SUPPORTED_STANDARDS_KEY,
16
16
  _LSP9_SUPPORTED_STANDARDS_VALUE,
17
+ _TYPEID_LSP9_VALUE_RECEIVED,
17
18
  _TYPEID_LSP9_OwnershipTransferred_RecipientNotification
18
19
  } from "../LSP9Vault/LSP9Constants.sol";
19
20
 
@@ -32,13 +33,21 @@ contract LSP9Vault is LSP9VaultCore {
32
33
  * @param newOwner The new owner of the contract.
33
34
  *
34
35
  * @custom:events
35
- * - {ValueReceived} event when funding the contract on deployment.
36
+ * - {UniversalReceiver} event when funding the contract on deployment.
36
37
  * - {OwnershipTransferred} event when `initialOwner` is set as the contract {owner}.
37
38
  * - {DataChanged} event when setting the {_LSP9_SUPPORTED_STANDARDS_KEY}.
38
39
  * - {UniversalReceiver} event when notifying the `initialOwner`.
39
40
  */
40
41
  constructor(address newOwner) payable {
41
- if (msg.value != 0) emit ValueReceived(msg.sender, msg.value);
42
+ if (msg.value != 0) {
43
+ emit UniversalReceiver(
44
+ msg.sender,
45
+ msg.value,
46
+ _TYPEID_LSP9_VALUE_RECEIVED,
47
+ "",
48
+ ""
49
+ );
50
+ }
42
51
 
43
52
  OwnableUnset._setOwner(newOwner);
44
53