@lukso/lsp-smart-contracts 0.12.0-rc.0 → 0.12.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 (119) 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 +22 -0
  8. package/artifacts/LSP7CappedSupplyInitAbstract.json +22 -0
  9. package/artifacts/LSP7CompatibleERC20.json +22 -0
  10. package/artifacts/LSP7CompatibleERC20InitAbstract.json +22 -0
  11. package/artifacts/LSP7CompatibleERC20Mintable.json +24 -2
  12. package/artifacts/LSP7CompatibleERC20MintableInit.json +24 -2
  13. package/artifacts/LSP7DigitalAsset.json +22 -0
  14. package/artifacts/LSP7DigitalAssetInitAbstract.json +22 -0
  15. package/artifacts/LSP7Mintable.json +24 -2
  16. package/artifacts/LSP7MintableInit.json +24 -2
  17. package/artifacts/LSP8CappedSupply.json +11 -0
  18. package/artifacts/LSP8CappedSupplyInitAbstract.json +11 -0
  19. package/artifacts/LSP8CompatibleERC721.json +11 -0
  20. package/artifacts/LSP8CompatibleERC721InitAbstract.json +11 -0
  21. package/artifacts/LSP8CompatibleERC721Mintable.json +13 -2
  22. package/artifacts/LSP8CompatibleERC721MintableInit.json +13 -2
  23. package/artifacts/LSP8IdentifiableDigitalAsset.json +11 -0
  24. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +11 -0
  25. package/artifacts/LSP8Mintable.json +13 -2
  26. package/artifacts/LSP8MintableInit.json +13 -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 +6 -1
  33. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +18 -4
  34. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +132 -66
  35. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +3 -2
  36. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +14 -3
  37. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +11 -10
  38. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +12 -8
  39. package/contracts/LSP17ContractExtension/LSP17Extension.sol +2 -1
  40. package/contracts/LSP17Extensions/OnERC721ReceivedExtension.sol +2 -1
  41. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +32 -11
  42. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +25 -9
  43. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +4 -3
  44. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +43 -49
  45. package/contracts/LSP20CallVerification/LSP20Errors.sol +2 -2
  46. package/contracts/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.sol +1 -5
  47. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +2 -1
  48. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +54 -8
  49. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +2 -1
  50. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +14 -16
  51. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +9 -5
  52. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +60 -0
  53. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +1 -1
  54. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +7 -5
  55. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +111 -175
  56. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +7 -5
  57. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +5 -0
  58. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +8 -1
  59. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +7 -1
  60. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +5 -0
  61. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +8 -5
  62. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +6 -5
  63. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +30 -73
  64. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +6 -5
  65. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +7 -7
  66. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +7 -7
  67. package/contracts/LSP9Vault/ILSP9Vault.sol +0 -8
  68. package/contracts/LSP9Vault/LSP9Constants.sol +6 -1
  69. package/contracts/LSP9Vault/LSP9Vault.sol +14 -4
  70. package/contracts/LSP9Vault/LSP9VaultCore.sol +80 -37
  71. package/contracts/LSP9Vault/LSP9VaultInit.sol +3 -2
  72. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +12 -3
  73. package/contracts/UniversalProfile.sol +5 -3
  74. package/contracts/UniversalProfileInit.sol +9 -6
  75. package/contracts/UniversalProfileInitAbstract.sol +5 -3
  76. package/contracts/Version.sol +17 -0
  77. package/devdocs/LSP0ERC725Account.json +11 -10
  78. package/devdocs/LSP0ERC725AccountInit.json +10 -9
  79. package/devdocs/LSP6KeyManager.json +11 -0
  80. package/devdocs/LSP6KeyManagerInit.json +11 -0
  81. package/devdocs/LSP7CappedSupply.json +10 -10
  82. package/devdocs/LSP7CappedSupplyInitAbstract.json +10 -10
  83. package/devdocs/LSP7CompatibleERC20.json +10 -10
  84. package/devdocs/LSP7CompatibleERC20InitAbstract.json +10 -10
  85. package/devdocs/LSP7CompatibleERC20Mintable.json +10 -10
  86. package/devdocs/LSP7CompatibleERC20MintableInit.json +10 -10
  87. package/devdocs/LSP7DigitalAsset.json +10 -10
  88. package/devdocs/LSP7DigitalAssetInitAbstract.json +10 -10
  89. package/devdocs/LSP7Mintable.json +10 -10
  90. package/devdocs/LSP7MintableInit.json +10 -10
  91. package/devdocs/LSP8CappedSupply.json +3 -2
  92. package/devdocs/LSP8CappedSupplyInitAbstract.json +3 -2
  93. package/devdocs/LSP8CompatibleERC721.json +3 -2
  94. package/devdocs/LSP8CompatibleERC721InitAbstract.json +3 -2
  95. package/devdocs/LSP8CompatibleERC721Mintable.json +3 -2
  96. package/devdocs/LSP8CompatibleERC721MintableInit.json +3 -2
  97. package/devdocs/LSP8IdentifiableDigitalAsset.json +3 -2
  98. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +3 -2
  99. package/devdocs/LSP8Mintable.json +3 -2
  100. package/devdocs/LSP8MintableInit.json +3 -2
  101. package/devdocs/LSP9Vault.json +6 -6
  102. package/devdocs/LSP9VaultInit.json +6 -6
  103. package/devdocs/UniversalProfile.json +11 -10
  104. package/devdocs/UniversalProfileInit.json +11 -10
  105. package/dist/constants.cjs.js +822 -459
  106. package/dist/constants.d.ts +633 -298
  107. package/dist/constants.es.js +822 -459
  108. package/package.json +1 -3
  109. package/userdocs/LSP0ERC725Account.json +3 -3
  110. package/userdocs/LSP0ERC725AccountInit.json +3 -3
  111. package/userdocs/LSP1UniversalReceiverDelegateUP.json +3 -0
  112. package/userdocs/LSP1UniversalReceiverDelegateVault.json +3 -0
  113. package/userdocs/LSP6KeyManager.json +3 -0
  114. package/userdocs/LSP6KeyManagerInit.json +3 -0
  115. package/userdocs/LSP9Vault.json +3 -3
  116. package/userdocs/LSP9VaultInit.json +3 -3
  117. package/userdocs/UniversalProfile.json +3 -3
  118. package/userdocs/UniversalProfileInit.json +3 -3
  119. package/CONTRIBUTING.md +0 -188
@@ -50,11 +50,13 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
50
50
  * @dev Emitted when `tokenOwner` disables `operator` for `amount` tokens and set its {`authorizedAmountFor(...)`} to `0`.
51
51
  * @param operator The address revoked from operating
52
52
  * @param tokenOwner The token owner
53
+ * @param notified Bool indicating whether the operator has been notified or not
53
54
  * @param operatorNotificationData The data to notify the operator about via LSP1.
54
55
  */
55
56
  event RevokedOperator(
56
57
  address indexed operator,
57
58
  address indexed tokenOwner,
59
+ bool notified,
58
60
  bytes operatorNotificationData
59
61
  );
60
62
 
@@ -101,6 +103,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
101
103
 
102
104
  /**
103
105
  * @dev Sets an `amount` of tokens that an `operator` has access from the caller's balance (allowance). See {authorizedAmountFor}.
106
+ * Notify the operator based on the LSP1-UniversalReceiver standard
104
107
  *
105
108
  * @param operator The address to authorize as an operator.
106
109
  * @param amount The allowance amount of tokens operator has access to.
@@ -123,6 +126,7 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
123
126
  * on behalf of the token owner (the caller of the function `msg.sender`). See also {authorizedAmountFor}.
124
127
  *
125
128
  * @param operator The address to revoke as an operator.
129
+ * @param notify Boolean indicating whether to notify the operator or not.
126
130
  * @param operatorNotificationData The data to notify the operator about via LSP1.
127
131
  *
128
132
  * @custom:requirements
@@ -133,6 +137,62 @@ interface ILSP7DigitalAsset is IERC165, IERC725Y {
133
137
  */
134
138
  function revokeOperator(
135
139
  address operator,
140
+ bool notify,
141
+ bytes memory operatorNotificationData
142
+ ) external;
143
+
144
+ /**
145
+ * @custom:info This function in the LSP7 contract can be used as a prevention mechanism
146
+ * against double spending allowance vulnerability.
147
+ *
148
+ * @notice Increase the allowance of `operator` by +`addedAmount`
149
+ *
150
+ * @dev Atomically increases the allowance granted to `operator` by the caller.
151
+ * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
152
+ * for the double spending allowance problem.
153
+ * Notify the operator based on the LSP1-UniversalReceiver standard
154
+ *
155
+ * @param operator The operator to increase the allowance for `msg.sender`
156
+ * @param addedAmount The additional amount to add on top of the current operator's allowance
157
+ *
158
+ * @custom:requirements
159
+ * - `operator` cannot be the same address as `msg.sender`
160
+ * - `operator` cannot be the zero address.
161
+ *
162
+ * @custom:events {AuthorizedOperator} indicating the updated allowance
163
+ */
164
+ function increaseAllowance(
165
+ address operator,
166
+ uint256 addedAmount,
167
+ bytes memory operatorNotificationData
168
+ ) external;
169
+
170
+ /**
171
+ * @custom:info This function in the LSP7 contract can be used as a prevention mechanism
172
+ * against the double spending allowance vulnerability.
173
+ *
174
+ * @notice Decrease the allowance of `operator` by -`subtractedAmount`
175
+ *
176
+ * @dev Atomically decreases the allowance granted to `operator` by the caller.
177
+ * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
178
+ * for the double spending allowance problem.
179
+ * Notify the operator based on the LSP1-UniversalReceiver standard
180
+ *
181
+ * @custom:events
182
+ * - {AuthorizedOperator} event indicating the updated allowance after decreasing it.
183
+ * - {RevokeOperator} event if `subtractedAmount` is the full allowance,
184
+ * indicating `operator` does not have any alauthorizedAmountForlowance left for `msg.sender`.
185
+ *
186
+ * @param operator The operator to decrease allowance for `msg.sender`
187
+ * @param subtractedAmount The amount to decrease by in the operator's allowance.
188
+ *
189
+ * @custom:requirements
190
+ * - `operator` cannot be the zero address.
191
+ * - `operator` must have allowance for the caller of at least `subtractedAmount`.
192
+ */
193
+ function decreaseAllowance(
194
+ address operator,
195
+ uint256 subtractedAmount,
136
196
  bytes memory operatorNotificationData
137
197
  ) external;
138
198
 
@@ -2,7 +2,7 @@
2
2
  pragma solidity ^0.8.4;
3
3
 
4
4
  // --- ERC165 interface ids
5
- bytes4 constant _INTERFACEID_LSP7 = 0x05519512;
5
+ bytes4 constant _INTERFACEID_LSP7 = 0xdaa746b7;
6
6
 
7
7
  // --- Token Hooks
8
8
 
@@ -108,8 +108,9 @@ abstract contract LSP7DigitalAsset is
108
108
  /**
109
109
  * @dev Forwards the call with the received value to an extension mapped to a function selector.
110
110
  *
111
- * Calls {_getExtension} to get the address of the extension mapped to the function selector being
111
+ * Calls {_getExtensionAndForwardValue} to get the address of the extension mapped to the function selector being
112
112
  * called on the account. If there is no extension, the address(0) will be returned.
113
+ * Forwards the value if the extension is payable.
113
114
  *
114
115
  * Reverts if there is no extension for the function being called.
115
116
  *
@@ -124,7 +125,7 @@ abstract contract LSP7DigitalAsset is
124
125
  bytes calldata callData
125
126
  ) internal virtual override returns (bytes memory) {
126
127
  // If there is a function selector
127
- address extension = _getExtension(msg.sig);
128
+ (address extension, ) = _getExtensionAndForwardValue(msg.sig);
128
129
 
129
130
  // if no extension was found, revert
130
131
  if (extension == address(0))
@@ -152,10 +153,11 @@ abstract contract LSP7DigitalAsset is
152
153
  * @dev Returns the extension address stored under the following data key:
153
154
  * - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
154
155
  * - If no extension is stored, returns the address(0).
156
+ * - we do not check that payable bool as in lsp7 standard we will always forward the value to the extension
155
157
  */
156
- function _getExtension(
158
+ function _getExtensionAndForwardValue(
157
159
  bytes4 functionSelector
158
- ) internal view virtual override returns (address) {
160
+ ) internal view virtual override returns (address, bool) {
159
161
  // Generate the data key relevant for the functionSelector being called
160
162
  bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
161
163
  _LSP17_EXTENSION_PREFIX,
@@ -169,7 +171,7 @@ abstract contract LSP7DigitalAsset is
169
171
  if (extensionAddress.length != 20 && extensionAddress.length != 0)
170
172
  revert InvalidExtensionAddress(extensionAddress);
171
173
 
172
- return address(bytes20(extensionAddress));
174
+ return (address(bytes20(extensionAddress)), true);
173
175
  }
174
176
 
175
177
  /**
@@ -3,18 +3,20 @@ 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 {ILSP7DigitalAsset} from "./ILSP7DigitalAsset.sol";
9
9
 
10
- // libraries
11
- import {
12
- ERC165Checker
13
- } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
10
+ // modules
14
11
 
12
+ // libraries
15
13
  import {
16
14
  EnumerableSet
17
15
  } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
16
+ import {
17
+ ERC165Checker
18
+ } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
19
+ import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
18
20
 
19
21
  // errors
20
22
  import {
@@ -27,7 +29,8 @@ import {
27
29
  LSP7TokenOwnerCannotBeOperator,
28
30
  LSP7CannotSendWithAddressZero,
29
31
  LSP7NotifyTokenReceiverContractMissingLSP1Interface,
30
- LSP7NotifyTokenReceiverIsEOA
32
+ LSP7NotifyTokenReceiverIsEOA,
33
+ OperatorAllowanceCannotBeIncreasedFromZero
31
34
  } from "./LSP7Errors.sol";
32
35
 
33
36
  // constants
@@ -50,6 +53,8 @@ import {
50
53
  */
51
54
  abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
52
55
  using EnumerableSet for EnumerableSet.AddressSet;
56
+ using ERC165Checker for address;
57
+ using LSP1Utils for address;
53
58
 
54
59
  // --- Storage
55
60
 
@@ -113,14 +118,21 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
113
118
  uint256 amount,
114
119
  bytes memory operatorNotificationData
115
120
  ) public virtual override {
116
- _updateOperator(msg.sender, operator, amount, operatorNotificationData);
121
+ _updateOperator(
122
+ msg.sender,
123
+ operator,
124
+ amount,
125
+ true,
126
+ operatorNotificationData
127
+ );
117
128
 
118
129
  bytes memory lsp1Data = abi.encode(
119
130
  msg.sender,
120
131
  amount,
121
132
  operatorNotificationData
122
133
  );
123
- _notifyTokenOperator(operator, lsp1Data);
134
+
135
+ operator.notifyUniversalReceiver(_TYPEID_LSP7_TOKENOPERATOR, lsp1Data);
124
136
  }
125
137
 
126
138
  /**
@@ -128,16 +140,29 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
128
140
  */
129
141
  function revokeOperator(
130
142
  address operator,
143
+ bool notify,
131
144
  bytes memory operatorNotificationData
132
145
  ) public virtual override {
133
- _updateOperator(msg.sender, operator, 0, operatorNotificationData);
134
-
135
- bytes memory lsp1Data = abi.encode(
146
+ _updateOperator(
136
147
  msg.sender,
148
+ operator,
137
149
  0,
150
+ notify,
138
151
  operatorNotificationData
139
152
  );
140
- _notifyTokenOperator(operator, lsp1Data);
153
+
154
+ if (notify) {
155
+ bytes memory lsp1Data = abi.encode(
156
+ msg.sender,
157
+ 0,
158
+ operatorNotificationData
159
+ );
160
+
161
+ operator.notifyUniversalReceiver(
162
+ _TYPEID_LSP7_TOKENOPERATOR,
163
+ lsp1Data
164
+ );
165
+ }
141
166
  }
142
167
 
143
168
  /**
@@ -163,6 +188,71 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
163
188
  return _operators[tokenOwner].values();
164
189
  }
165
190
 
191
+ /**
192
+ * @inheritdoc ILSP7DigitalAsset
193
+ */
194
+ function increaseAllowance(
195
+ address operator,
196
+ uint256 addedAmount,
197
+ bytes memory operatorNotificationData
198
+ ) public virtual override {
199
+ uint256 oldAllowance = authorizedAmountFor(operator, msg.sender);
200
+ if (oldAllowance == 0)
201
+ revert OperatorAllowanceCannotBeIncreasedFromZero(operator);
202
+
203
+ uint256 newAllowance = oldAllowance + addedAmount;
204
+
205
+ _updateOperator(
206
+ msg.sender,
207
+ operator,
208
+ newAllowance,
209
+ true,
210
+ operatorNotificationData
211
+ );
212
+
213
+ bytes memory lsp1Data = abi.encode(
214
+ msg.sender,
215
+ newAllowance,
216
+ operatorNotificationData
217
+ );
218
+
219
+ operator.notifyUniversalReceiver(_TYPEID_LSP7_TOKENOPERATOR, lsp1Data);
220
+ }
221
+
222
+ /**
223
+ * @inheritdoc ILSP7DigitalAsset
224
+ */
225
+ function decreaseAllowance(
226
+ address operator,
227
+ uint256 subtractedAmount,
228
+ bytes memory operatorNotificationData
229
+ ) public virtual override {
230
+ uint256 currentAllowance = authorizedAmountFor(operator, msg.sender);
231
+ if (currentAllowance < subtractedAmount) {
232
+ revert LSP7DecreasedAllowanceBelowZero();
233
+ }
234
+
235
+ uint256 newAllowance;
236
+ unchecked {
237
+ newAllowance = currentAllowance - subtractedAmount;
238
+ _updateOperator(
239
+ msg.sender,
240
+ operator,
241
+ newAllowance,
242
+ true,
243
+ operatorNotificationData
244
+ );
245
+ }
246
+
247
+ bytes memory lsp1Data = abi.encode(
248
+ msg.sender,
249
+ newAllowance,
250
+ operatorNotificationData
251
+ );
252
+
253
+ operator.notifyUniversalReceiver(_TYPEID_LSP7_TOKENOPERATOR, lsp1Data);
254
+ }
255
+
166
256
  // --- Transfer functionality
167
257
 
168
258
  /**
@@ -218,101 +308,6 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
218
308
  }
219
309
  }
220
310
 
221
- /**
222
- * @custom:info This is a non-standard function, not part of the LSP7 standard interface.
223
- * It has been added in the LSP7 contract implementation so that it can be used as a prevention mechanism
224
- * against double spending allowance vulnerability.
225
- *
226
- * @notice Increase the allowance of `operator` by +`addedAmount`
227
- *
228
- * @dev Atomically increases the allowance granted to `operator` by the caller.
229
- * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
230
- * for the double spending allowance problem.
231
- *
232
- * @param operator The operator to increase the allowance for `msg.sender`
233
- * @param addedAmount The additional amount to add on top of the current operator's allowance
234
- *
235
- * @custom:requirements
236
- * - `operator` cannot be the same address as `msg.sender`
237
- * - `operator` cannot be the zero address.
238
- *
239
- * @custom:events {AuthorizedOperator} indicating the updated allowance
240
- */
241
- function increaseAllowance(
242
- address operator,
243
- uint256 addedAmount,
244
- bytes memory operatorNotificationData
245
- ) public virtual {
246
- uint256 newAllowance = authorizedAmountFor(operator, msg.sender) +
247
- addedAmount;
248
-
249
- _updateOperator(
250
- msg.sender,
251
- operator,
252
- newAllowance,
253
- operatorNotificationData
254
- );
255
-
256
- bytes memory lsp1Data = abi.encode(
257
- msg.sender,
258
- newAllowance,
259
- operatorNotificationData
260
- );
261
- _notifyTokenOperator(operator, lsp1Data);
262
- }
263
-
264
- /**
265
- * @custom:info This is a non-standard function, not part of the LSP7 standard interface.
266
- * It has been added in the LSP7 contract implementation so that it can be used as a prevention mechanism
267
- * against the double spending allowance vulnerability.
268
- *
269
- * @notice Decrease the allowance of `operator` by -`subtractedAmount`
270
- *
271
- * @dev Atomically decreases the allowance granted to `operator` by the caller.
272
- * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
273
- * for the double spending allowance problem.
274
- *
275
- * @custom:events
276
- * - {AuthorizedOperator} event indicating the updated allowance after decreasing it.
277
- * - {RevokeOperator} event if `subtractedAmount` is the full allowance,
278
- * indicating `operator` does not have any alauthorizedAmountForlowance left for `msg.sender`.
279
- *
280
- * @param operator The operator to decrease allowance for `msg.sender`
281
- * @param subtractedAmount The amount to decrease by in the operator's allowance.
282
- *
283
- * @custom:requirements
284
- * - `operator` cannot be the zero address.
285
- * - `operator` must have allowance for the caller of at least `subtractedAmount`.
286
- */
287
- function decreaseAllowance(
288
- address operator,
289
- uint256 subtractedAmount,
290
- bytes memory operatorNotificationData
291
- ) public virtual {
292
- uint256 currentAllowance = authorizedAmountFor(operator, msg.sender);
293
- if (currentAllowance < subtractedAmount) {
294
- revert LSP7DecreasedAllowanceBelowZero();
295
- }
296
-
297
- uint256 newAllowance;
298
- unchecked {
299
- newAllowance = currentAllowance - subtractedAmount;
300
- _updateOperator(
301
- msg.sender,
302
- operator,
303
- newAllowance,
304
- operatorNotificationData
305
- );
306
- }
307
-
308
- bytes memory lsp1Data = abi.encode(
309
- msg.sender,
310
- newAllowance,
311
- operatorNotificationData
312
- );
313
- _notifyTokenOperator(operator, lsp1Data);
314
- }
315
-
316
311
  /**
317
312
  * @dev Changes token `amount` the `operator` has access to from `tokenOwner` tokens.
318
313
  * If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators.
@@ -321,6 +316,8 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
321
316
  * @param tokenOwner The address that will give `operator` an allowance for on its balance.
322
317
  * @param operator The address to grant an allowance to spend.
323
318
  * @param allowance The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance.
319
+ * @param notified Boolean indicating whether the operator has been notified about the change of allowance
320
+ * @param operatorNotificationData The data to send to the universalReceiver function of the operator in case of notifying
324
321
  *
325
322
  * @custom:events
326
323
  * - {RevokedOperator} event when operator's allowance is set to `0`.
@@ -334,6 +331,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
334
331
  address tokenOwner,
335
332
  address operator,
336
333
  uint256 allowance,
334
+ bool notified,
337
335
  bytes memory operatorNotificationData
338
336
  ) internal virtual {
339
337
  if (operator == address(0)) {
@@ -359,6 +357,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
359
357
  emit RevokedOperator(
360
358
  operator,
361
359
  tokenOwner,
360
+ notified,
362
361
  operatorNotificationData
363
362
  );
364
363
  }
@@ -465,7 +464,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
465
464
  _afterTokenTransfer(from, address(0), amount, data);
466
465
 
467
466
  bytes memory lsp1Data = abi.encode(from, address(0), amount, data);
468
- _notifyTokenSender(from, lsp1Data);
467
+ from.notifyUniversalReceiver(_TYPEID_LSP7_TOKENSSENDER, lsp1Data);
469
468
  }
470
469
 
471
470
  /**
@@ -506,6 +505,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
506
505
  tokenOwner: tokenOwner,
507
506
  operator: operator,
508
507
  allowance: authorizedAmount - amountToSpend,
508
+ notified: false,
509
509
  operatorNotificationData: ""
510
510
  });
511
511
  }
@@ -562,7 +562,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
562
562
 
563
563
  bytes memory lsp1Data = abi.encode(from, to, amount, data);
564
564
 
565
- _notifyTokenSender(from, lsp1Data);
565
+ from.notifyUniversalReceiver(_TYPEID_LSP7_TOKENSSENDER, lsp1Data);
566
566
  _notifyTokenReceiver(to, force, lsp1Data);
567
567
  }
568
568
 
@@ -598,62 +598,6 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
598
598
  bytes memory data // solhint-disable-next-line no-empty-blocks
599
599
  ) internal virtual {}
600
600
 
601
- /**
602
- * @dev Attempt to notify the operator `operator` about the `amount` tokens being authorized with.
603
- * This is done by calling its {universalReceiver} function with the `_TYPEID_LSP7_TOKENOPERATOR` as typeId, if `operator` is a contract that supports the LSP1 interface.
604
- * If `operator` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
605
-
606
- * @param operator The address to call the {universalReceiver} function on.
607
- * @param lsp1Data the data to be sent to the `operator` address in the `universalReceiver` call.
608
- */
609
- function _notifyTokenOperator(
610
- address operator,
611
- bytes memory lsp1Data
612
- ) internal virtual {
613
- if (
614
- ERC165Checker.supportsERC165InterfaceUnchecked(
615
- operator,
616
- _INTERFACEID_LSP1
617
- )
618
- ) {
619
- try
620
- ILSP1UniversalReceiver(operator).universalReceiver(
621
- _TYPEID_LSP7_TOKENOPERATOR,
622
- lsp1Data
623
- )
624
- {
625
- return;
626
- } catch {
627
- return;
628
- }
629
- }
630
- }
631
-
632
- /**
633
- * @dev Attempt to notify the token sender `from` about the `amount` of tokens being transferred.
634
- * This is done by calling its {universalReceiver} function with the `_TYPEID_LSP7_TOKENSSENDER` as typeId, if `from` is a contract that supports the LSP1 interface.
635
- * If `from` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
636
-
637
- * @param from The address to call the {universalReceiver} function on.
638
- * @param lsp1Data the data to be sent to the `from` address in the `universalReceiver` call.
639
- */
640
- function _notifyTokenSender(
641
- address from,
642
- bytes memory lsp1Data
643
- ) internal virtual {
644
- if (
645
- ERC165Checker.supportsERC165InterfaceUnchecked(
646
- from,
647
- _INTERFACEID_LSP1
648
- )
649
- ) {
650
- ILSP1UniversalReceiver(from).universalReceiver(
651
- _TYPEID_LSP7_TOKENSSENDER,
652
- lsp1Data
653
- );
654
- }
655
- }
656
-
657
601
  /**
658
602
  * @dev Attempt to notify the token receiver `to` about the `amount` tokens being received.
659
603
  * This is done by calling its {universalReceiver} function with the `_TYPEID_LSP7_TOKENSRECIPIENT` as typeId, if `to` is a contract that supports the LSP1 interface.
@@ -671,16 +615,8 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
671
615
  bool force,
672
616
  bytes memory lsp1Data
673
617
  ) internal virtual {
674
- if (
675
- ERC165Checker.supportsERC165InterfaceUnchecked(
676
- to,
677
- _INTERFACEID_LSP1
678
- )
679
- ) {
680
- ILSP1UniversalReceiver(to).universalReceiver(
681
- _TYPEID_LSP7_TOKENSRECIPIENT,
682
- lsp1Data
683
- );
618
+ if (to.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
619
+ ILSP1(to).universalReceiver(_TYPEID_LSP7_TOKENSRECIPIENT, lsp1Data);
684
620
  } else if (!force) {
685
621
  if (to.code.length != 0) {
686
622
  revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
@@ -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);