@lukso/lsp-smart-contracts 0.11.1 → 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 (224) hide show
  1. package/README.md +10 -2
  2. package/artifacts/Create2Factory.json +2 -2
  3. package/artifacts/LSP0ERC725Account.json +68 -47
  4. package/artifacts/LSP0ERC725AccountInit.json +68 -47
  5. package/artifacts/LSP11BasicSocialRecovery.json +18 -2
  6. package/artifacts/LSP11BasicSocialRecoveryInit.json +18 -2
  7. package/artifacts/LSP16UniversalFactory.json +3 -3
  8. package/artifacts/LSP1UniversalReceiverDelegateUP.json +27 -46
  9. package/artifacts/LSP1UniversalReceiverDelegateVault.json +27 -46
  10. package/artifacts/LSP23LinkedContractsFactory.json +3 -3
  11. package/artifacts/LSP4DigitalAssetMetadata.json +16 -0
  12. package/artifacts/LSP4DigitalAssetMetadataInitAbstract.json +16 -0
  13. package/artifacts/LSP6KeyManager.json +34 -6
  14. package/artifacts/LSP6KeyManagerInit.json +34 -6
  15. package/artifacts/LSP7CappedSupply.json +64 -4
  16. package/artifacts/LSP7CappedSupplyInitAbstract.json +64 -4
  17. package/artifacts/LSP7CompatibleERC20.json +83 -23
  18. package/artifacts/LSP7CompatibleERC20InitAbstract.json +83 -23
  19. package/artifacts/LSP7CompatibleERC20Mintable.json +86 -26
  20. package/artifacts/LSP7CompatibleERC20MintableInit.json +86 -26
  21. package/artifacts/LSP7DigitalAsset.json +64 -4
  22. package/artifacts/LSP7DigitalAssetInitAbstract.json +64 -4
  23. package/artifacts/LSP7Mintable.json +67 -7
  24. package/artifacts/LSP7MintableInit.json +67 -7
  25. package/artifacts/LSP8CappedSupply.json +57 -3
  26. package/artifacts/LSP8CappedSupplyInitAbstract.json +57 -3
  27. package/artifacts/LSP8CompatibleERC721.json +79 -25
  28. package/artifacts/LSP8CompatibleERC721InitAbstract.json +79 -25
  29. package/artifacts/LSP8CompatibleERC721Mintable.json +87 -28
  30. package/artifacts/LSP8CompatibleERC721MintableInit.json +87 -28
  31. package/artifacts/LSP8IdentifiableDigitalAsset.json +57 -3
  32. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +57 -3
  33. package/artifacts/LSP8Mintable.json +65 -6
  34. package/artifacts/LSP8MintableInit.json +65 -6
  35. package/artifacts/LSP9Vault.json +51 -35
  36. package/artifacts/LSP9VaultInit.json +51 -35
  37. package/artifacts/UniversalProfile.json +68 -47
  38. package/artifacts/UniversalProfileInit.json +68 -47
  39. package/contracts/Factories/Create2Factory.sol +1 -1
  40. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +0 -22
  41. package/contracts/LSP0ERC725Account/LSP0Constants.sol +6 -1
  42. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +12 -2
  43. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +196 -123
  44. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +1 -1
  45. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +11 -2
  46. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +5 -3
  47. package/contracts/LSP11BasicSocialRecovery/LSP11BasicSocialRecoveryCore.sol +54 -14
  48. package/contracts/LSP11BasicSocialRecovery/LSP11Constants.sol +1 -1
  49. package/contracts/LSP11BasicSocialRecovery/LSP11Errors.sol +1 -1
  50. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +2 -2
  51. package/contracts/LSP14Ownable2Step/LSP14Constants.sol +1 -1
  52. package/contracts/LSP14Ownable2Step/LSP14Errors.sol +9 -3
  53. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +16 -12
  54. package/contracts/LSP16UniversalFactory/LSP16UniversalFactory.sol +65 -96
  55. package/contracts/LSP17ContractExtension/LSP17Errors.sol +1 -1
  56. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +22 -15
  57. package/contracts/LSP17ContractExtension/LSP17Extension.sol +6 -5
  58. package/contracts/LSP17Extensions/Extension4337.sol +101 -0
  59. package/contracts/LSP17Extensions/OnERC721ReceivedExtension.sol +15 -0
  60. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +1 -2
  61. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiverDelegate.sol +24 -0
  62. package/contracts/LSP1UniversalReceiver/LSP1Constants.sol +1 -0
  63. package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +0 -6
  64. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +49 -33
  65. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +33 -27
  66. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +5 -48
  67. package/contracts/LSP20CallVerification/ILSP20CallVerifier.sol +13 -9
  68. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +64 -45
  69. package/contracts/LSP20CallVerification/LSP20Constants.sol +6 -6
  70. package/contracts/LSP20CallVerification/LSP20Errors.sol +10 -4
  71. package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/ILSP23LinkedContractsFactory.sol +1 -1
  72. package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/IPostDeploymentModule.sol +1 -1
  73. package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/LSP23Errors.sol +1 -1
  74. package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/LSP23LinkedContractsFactory.sol +5 -1
  75. package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/modules/UniversalProfileInitPostDeploymentModule.sol +1 -1
  76. package/contracts/{LSP23LinkedContractsDeployment → LSP23LinkedContractsFactory}/modules/UniversalProfilePostDeploymentModule.sol +1 -1
  77. package/contracts/LSP25ExecuteRelayCall/LSP25Constants.sol +1 -1
  78. package/contracts/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.sol +8 -3
  79. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +1 -97
  80. package/contracts/LSP3ProfileMetadata/LSP3Constants.sol +1 -1
  81. package/contracts/LSP4DigitalAssetMetadata/LSP4Constants.sol +1 -1
  82. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +8 -3
  83. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +8 -3
  84. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +4 -3
  85. package/contracts/LSP6KeyManager/LSP6Constants.sol +4 -3
  86. package/contracts/LSP6KeyManager/LSP6Errors.sol +2 -23
  87. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +0 -1
  88. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +176 -101
  89. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +0 -1
  90. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +1 -2
  91. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteRelayCallModule.sol +27 -0
  92. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +34 -28
  93. package/contracts/LSP6KeyManager/LSP6Utils.sol +29 -2
  94. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +70 -10
  95. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +2 -2
  96. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +29 -13
  97. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +273 -265
  98. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +28 -12
  99. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +17 -3
  100. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +5 -1
  101. package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +4 -1
  102. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +7 -7
  103. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +3 -3
  104. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +128 -54
  105. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +129 -54
  106. package/contracts/LSP7DigitalAsset/presets/ILSP7Mintable.sol +3 -3
  107. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +4 -4
  108. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +2 -2
  109. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +4 -4
  110. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +4 -4
  111. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +1 -1
  112. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +4 -4
  113. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +16 -11
  114. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +20 -6
  115. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Errors.sol +32 -16
  116. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +67 -16
  117. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +143 -137
  118. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +69 -15
  119. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +1 -1
  120. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8BurnableInitAbstract.sol +1 -1
  121. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +7 -7
  122. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +3 -3
  123. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +172 -80
  124. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +178 -91
  125. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +7 -7
  126. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +7 -7
  127. package/contracts/LSP8IdentifiableDigitalAsset/presets/ILSP8Mintable.sol +3 -3
  128. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +8 -7
  129. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +5 -3
  130. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +13 -7
  131. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +9 -8
  132. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +9 -3
  133. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +10 -8
  134. package/contracts/LSP9Vault/ILSP9Vault.sol +0 -21
  135. package/contracts/LSP9Vault/LSP9Constants.sol +6 -1
  136. package/contracts/LSP9Vault/LSP9Errors.sol +1 -1
  137. package/contracts/LSP9Vault/LSP9Vault.sol +11 -2
  138. package/contracts/LSP9Vault/LSP9VaultCore.sol +119 -66
  139. package/contracts/LSP9Vault/LSP9VaultInit.sol +1 -1
  140. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -2
  141. package/contracts/UniversalProfile.sol +1 -1
  142. package/contracts/UniversalProfileInit.sol +1 -1
  143. package/contracts/UniversalProfileInitAbstract.sol +1 -1
  144. package/contracts/Version.sol +16 -0
  145. package/devdocs/LSP0ERC725Account.json +86 -52
  146. package/devdocs/LSP0ERC725AccountInit.json +86 -52
  147. package/devdocs/LSP11BasicSocialRecovery.json +13 -0
  148. package/devdocs/LSP11BasicSocialRecoveryInit.json +13 -0
  149. package/devdocs/LSP16UniversalFactory.json +9 -9
  150. package/devdocs/LSP1UniversalReceiverDelegateUP.json +7 -6
  151. package/devdocs/LSP1UniversalReceiverDelegateVault.json +7 -6
  152. package/devdocs/LSP4DigitalAssetMetadata.json +32 -10
  153. package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +32 -10
  154. package/devdocs/LSP6KeyManager.json +27 -13
  155. package/devdocs/LSP6KeyManagerInit.json +27 -13
  156. package/devdocs/LSP7CappedSupply.json +61 -28
  157. package/devdocs/LSP7CappedSupplyInitAbstract.json +61 -28
  158. package/devdocs/LSP7CompatibleERC20.json +102 -32
  159. package/devdocs/LSP7CompatibleERC20InitAbstract.json +102 -32
  160. package/devdocs/LSP7CompatibleERC20Mintable.json +102 -32
  161. package/devdocs/LSP7CompatibleERC20MintableInit.json +102 -32
  162. package/devdocs/LSP7DigitalAsset.json +61 -28
  163. package/devdocs/LSP7DigitalAssetInitAbstract.json +61 -28
  164. package/devdocs/LSP7Mintable.json +61 -28
  165. package/devdocs/LSP7MintableInit.json +61 -28
  166. package/devdocs/LSP8CappedSupply.json +66 -27
  167. package/devdocs/LSP8CappedSupplyInitAbstract.json +66 -27
  168. package/devdocs/LSP8CompatibleERC721.json +93 -33
  169. package/devdocs/LSP8CompatibleERC721InitAbstract.json +93 -33
  170. package/devdocs/LSP8CompatibleERC721Mintable.json +95 -35
  171. package/devdocs/LSP8CompatibleERC721MintableInit.json +96 -36
  172. package/devdocs/LSP8IdentifiableDigitalAsset.json +70 -28
  173. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +66 -27
  174. package/devdocs/LSP8Mintable.json +68 -29
  175. package/devdocs/LSP8MintableInit.json +69 -30
  176. package/devdocs/LSP9Vault.json +69 -41
  177. package/devdocs/LSP9VaultInit.json +69 -41
  178. package/devdocs/UniversalProfile.json +86 -52
  179. package/devdocs/UniversalProfileInit.json +86 -52
  180. package/dist/constants.cjs.js +5565 -2846
  181. package/dist/constants.d.ts +3996 -1182
  182. package/dist/constants.es.js +5564 -2846
  183. package/package.json +8 -8
  184. package/userdocs/LSP0ERC725Account.json +20 -11
  185. package/userdocs/LSP0ERC725AccountInit.json +20 -11
  186. package/userdocs/LSP16UniversalFactory.json +26 -1
  187. package/userdocs/LSP1UniversalReceiverDelegateUP.json +4 -11
  188. package/userdocs/LSP1UniversalReceiverDelegateVault.json +4 -11
  189. package/userdocs/LSP4DigitalAssetMetadata.json +7 -4
  190. package/userdocs/LSP4DigitalAssetMetadataInitAbstract.json +7 -4
  191. package/userdocs/LSP6KeyManager.json +3 -5
  192. package/userdocs/LSP6KeyManagerInit.json +3 -5
  193. package/userdocs/LSP7CappedSupply.json +17 -6
  194. package/userdocs/LSP7CappedSupplyInitAbstract.json +16 -5
  195. package/userdocs/LSP7CompatibleERC20.json +18 -5
  196. package/userdocs/LSP7CompatibleERC20InitAbstract.json +18 -5
  197. package/userdocs/LSP7CompatibleERC20Mintable.json +18 -5
  198. package/userdocs/LSP7CompatibleERC20MintableInit.json +18 -5
  199. package/userdocs/LSP7DigitalAsset.json +18 -5
  200. package/userdocs/LSP7DigitalAssetInitAbstract.json +18 -5
  201. package/userdocs/LSP7Mintable.json +18 -5
  202. package/userdocs/LSP7MintableInit.json +18 -5
  203. package/userdocs/LSP8CappedSupply.json +16 -5
  204. package/userdocs/LSP8CappedSupplyInitAbstract.json +15 -4
  205. package/userdocs/LSP8CompatibleERC721.json +30 -17
  206. package/userdocs/LSP8CompatibleERC721InitAbstract.json +30 -17
  207. package/userdocs/LSP8CompatibleERC721Mintable.json +31 -18
  208. package/userdocs/LSP8CompatibleERC721MintableInit.json +32 -19
  209. package/userdocs/LSP8IdentifiableDigitalAsset.json +18 -5
  210. package/userdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +17 -4
  211. package/userdocs/LSP8Mintable.json +18 -5
  212. package/userdocs/LSP8MintableInit.json +19 -6
  213. package/userdocs/LSP9Vault.json +23 -14
  214. package/userdocs/LSP9VaultInit.json +23 -14
  215. package/userdocs/UniversalProfile.json +20 -11
  216. package/userdocs/UniversalProfileInit.json +20 -11
  217. package/CONTRIBUTING.md +0 -184
  218. package/artifacts/LSP4Compatibility.json +0 -216
  219. package/contracts/LSP4DigitalAssetMetadata/ILSP4Compatibility.sol +0 -25
  220. package/contracts/LSP4DigitalAssetMetadata/LSP4Compatibility.sol +0 -38
  221. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +0 -83
  222. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +0 -175
  223. package/devdocs/LSP4Compatibility.json +0 -79
  224. package/userdocs/LSP4Compatibility.json +0 -20
@@ -1,23 +1,38 @@
1
- // SPDX-License-Identifier: CC0-1.0
1
+ // SPDX-License-Identifier: Apache-2.0
2
2
  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
11
+ import {Version} from "../Version.sol";
14
12
 
13
+ // libraries
15
14
  import {
16
15
  EnumerableSet
17
16
  } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
17
+ import {
18
+ ERC165Checker
19
+ } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
20
+ import {LSP1Utils} from "../LSP1UniversalReceiver/LSP1Utils.sol";
18
21
 
19
22
  // errors
20
- import "./LSP7Errors.sol";
23
+ import {
24
+ LSP7CannotSendToSelf,
25
+ LSP7AmountExceedsAuthorizedAmount,
26
+ LSP7InvalidTransferBatch,
27
+ LSP7AmountExceedsBalance,
28
+ LSP7DecreasedAllowanceBelowZero,
29
+ LSP7CannotUseAddressZeroAsOperator,
30
+ LSP7TokenOwnerCannotBeOperator,
31
+ LSP7CannotSendWithAddressZero,
32
+ LSP7NotifyTokenReceiverContractMissingLSP1Interface,
33
+ LSP7NotifyTokenReceiverIsEOA,
34
+ OperatorAllowanceCannotBeIncreasedFromZero
35
+ } from "./LSP7Errors.sol";
21
36
 
22
37
  // constants
23
38
  import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
@@ -37,37 +52,40 @@ import {
37
52
  * Similar to ERC20, the non-standard {increaseAllowance} and {decreaseAllowance} functions
38
53
  * have been added to mitigate the well-known issues around setting allowances.
39
54
  */
40
- abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
55
+ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset, Version {
41
56
  using EnumerableSet for EnumerableSet.AddressSet;
57
+ using ERC165Checker for address;
58
+ using LSP1Utils for address;
59
+
42
60
  // --- Storage
43
61
 
62
+ bool internal _isNonDivisible;
63
+
64
+ uint256 internal _existingTokens;
65
+
44
66
  // Mapping from `tokenOwner` to an `amount` of tokens
45
67
  mapping(address => uint256) internal _tokenOwnerBalances;
46
68
 
47
- // Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
48
- mapping(address => mapping(address => uint256))
49
- internal _operatorAuthorizedAmount;
50
-
51
69
  // Mapping an `address` to its authorized operator addresses.
52
70
  mapping(address => EnumerableSet.AddressSet) internal _operators;
53
71
 
54
- uint256 internal _existingTokens;
55
-
56
- bool internal _isNonDivisible;
72
+ // Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
73
+ mapping(address => mapping(address => uint256))
74
+ internal _operatorAuthorizedAmount;
57
75
 
58
76
  // --- Token queries
59
77
 
60
78
  /**
61
79
  * @inheritdoc ILSP7DigitalAsset
62
80
  */
63
- function decimals() public view virtual returns (uint8) {
81
+ function decimals() public view virtual override returns (uint8) {
64
82
  return _isNonDivisible ? 0 : 18;
65
83
  }
66
84
 
67
85
  /**
68
86
  * @inheritdoc ILSP7DigitalAsset
69
87
  */
70
- function totalSupply() public view virtual returns (uint256) {
88
+ function totalSupply() public view virtual override returns (uint256) {
71
89
  return _existingTokens;
72
90
  }
73
91
 
@@ -78,7 +96,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
78
96
  */
79
97
  function balanceOf(
80
98
  address tokenOwner
81
- ) public view virtual returns (uint256) {
99
+ ) public view virtual override returns (uint256) {
82
100
  return _tokenOwnerBalances[tokenOwner];
83
101
  }
84
102
 
@@ -100,15 +118,25 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
100
118
  address operator,
101
119
  uint256 amount,
102
120
  bytes memory operatorNotificationData
103
- ) public virtual {
104
- _updateOperator(msg.sender, operator, amount, operatorNotificationData);
121
+ ) public virtual override {
122
+ _updateOperator(
123
+ msg.sender,
124
+ operator,
125
+ amount,
126
+ true,
127
+ operatorNotificationData
128
+ );
105
129
 
106
130
  bytes memory lsp1Data = abi.encode(
107
131
  msg.sender,
108
132
  amount,
109
133
  operatorNotificationData
110
134
  );
111
- _notifyTokenOperator(operator, lsp1Data);
135
+
136
+ operator.tryNotifyUniversalReceiver(
137
+ _TYPEID_LSP7_TOKENOPERATOR,
138
+ lsp1Data
139
+ );
112
140
  }
113
141
 
114
142
  /**
@@ -116,16 +144,29 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
116
144
  */
117
145
  function revokeOperator(
118
146
  address operator,
147
+ bool notify,
119
148
  bytes memory operatorNotificationData
120
- ) public virtual {
121
- _updateOperator(msg.sender, operator, 0, operatorNotificationData);
122
-
123
- bytes memory lsp1Data = abi.encode(
149
+ ) public virtual override {
150
+ _updateOperator(
124
151
  msg.sender,
152
+ operator,
125
153
  0,
154
+ notify,
126
155
  operatorNotificationData
127
156
  );
128
- _notifyTokenOperator(operator, lsp1Data);
157
+
158
+ if (notify) {
159
+ bytes memory lsp1Data = abi.encode(
160
+ msg.sender,
161
+ 0,
162
+ operatorNotificationData
163
+ );
164
+
165
+ operator.tryNotifyUniversalReceiver(
166
+ _TYPEID_LSP7_TOKENOPERATOR,
167
+ lsp1Data
168
+ );
169
+ }
129
170
  }
130
171
 
131
172
  /**
@@ -134,7 +175,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
134
175
  function authorizedAmountFor(
135
176
  address operator,
136
177
  address tokenOwner
137
- ) public view virtual returns (uint256) {
178
+ ) public view virtual override returns (uint256) {
138
179
  if (tokenOwner == operator) {
139
180
  return _tokenOwnerBalances[tokenOwner];
140
181
  } else {
@@ -147,109 +188,29 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
147
188
  */
148
189
  function getOperatorsOf(
149
190
  address tokenOwner
150
- ) public view virtual returns (address[] memory) {
191
+ ) public view virtual override returns (address[] memory) {
151
192
  return _operators[tokenOwner].values();
152
193
  }
153
194
 
154
- // --- Transfer functionality
155
-
156
- /**
157
- * @inheritdoc ILSP7DigitalAsset
158
- */
159
- function transfer(
160
- address from,
161
- address to,
162
- uint256 amount,
163
- bool allowNonLSP1Recipient,
164
- bytes memory data
165
- ) public virtual {
166
- if (from == to) revert LSP7CannotSendToSelf();
167
-
168
- address operator = msg.sender;
169
- if (operator != from) {
170
- uint256 operatorAmount = _operatorAuthorizedAmount[from][operator];
171
- if (amount > operatorAmount) {
172
- revert LSP7AmountExceedsAuthorizedAmount(
173
- from,
174
- operatorAmount,
175
- operator,
176
- amount
177
- );
178
- }
179
-
180
- _updateOperator(from, operator, operatorAmount - amount, "");
181
- }
182
-
183
- _transfer(from, to, amount, allowNonLSP1Recipient, data);
184
- }
185
-
186
195
  /**
187
196
  * @inheritdoc ILSP7DigitalAsset
188
197
  */
189
- function transferBatch(
190
- address[] memory from,
191
- address[] memory to,
192
- uint256[] memory amount,
193
- bool[] memory allowNonLSP1Recipient,
194
- bytes[] memory data
195
- ) public virtual {
196
- uint256 fromLength = from.length;
197
- if (
198
- fromLength != to.length ||
199
- fromLength != amount.length ||
200
- fromLength != allowNonLSP1Recipient.length ||
201
- fromLength != data.length
202
- ) {
203
- revert LSP7InvalidTransferBatch();
204
- }
205
-
206
- for (uint256 i = 0; i < fromLength; ) {
207
- // using the public transfer function to handle updates to operator authorized amounts
208
- transfer(
209
- from[i],
210
- to[i],
211
- amount[i],
212
- allowNonLSP1Recipient[i],
213
- data[i]
214
- );
215
-
216
- unchecked {
217
- ++i;
218
- }
219
- }
220
- }
221
-
222
- /**
223
- * @custom:info This is a non-standard function, not part of the LSP7 standard interface.
224
- * It has been added in the LSP7 contract implementation so that it can be used as a prevention mechanism
225
- * against double spending allowance vulnerability.
226
- *
227
- * @notice Increase the allowance of `operator` by +`addedAmount`
228
- *
229
- * @dev Atomically increases the allowance granted to `operator` by the caller.
230
- * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
231
- * for the double spending allowance problem.
232
- *
233
- * @param operator the operator to increase the allowance for `msg.sender`
234
- * @param addedAmount the additional amount to add on top of the current operator's allowance
235
- *
236
- * @custom:requirements
237
- * - `operator` cannot be the same address as `msg.sender`
238
- * - `operator` cannot be the zero address.
239
- *
240
- * @custom:events {AuthorizedOperator} indicating the updated allowance
241
- */
242
198
  function increaseAllowance(
243
199
  address operator,
244
200
  uint256 addedAmount,
245
201
  bytes memory operatorNotificationData
246
- ) public virtual {
247
- uint256 newAllowance = authorizedAmountFor(operator, msg.sender) +
248
- addedAmount;
202
+ ) public virtual override {
203
+ uint256 oldAllowance = authorizedAmountFor(operator, msg.sender);
204
+ if (oldAllowance == 0)
205
+ revert OperatorAllowanceCannotBeIncreasedFromZero(operator);
206
+
207
+ uint256 newAllowance = oldAllowance + addedAmount;
208
+
249
209
  _updateOperator(
250
210
  msg.sender,
251
211
  operator,
252
212
  newAllowance,
213
+ true,
253
214
  operatorNotificationData
254
215
  );
255
216
 
@@ -258,49 +219,34 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
258
219
  newAllowance,
259
220
  operatorNotificationData
260
221
  );
261
- _notifyTokenOperator(operator, lsp1Data);
222
+
223
+ operator.tryNotifyUniversalReceiver(
224
+ _TYPEID_LSP7_TOKENOPERATOR,
225
+ lsp1Data
226
+ );
262
227
  }
263
228
 
264
229
  /**
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 -`substractedAmount`
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 `substractedAmount` 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 substractedAmount 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 `substractedAmount`.
230
+ * @inheritdoc ILSP7DigitalAsset
286
231
  */
287
232
  function decreaseAllowance(
288
233
  address operator,
289
- uint256 substractedAmount,
234
+ uint256 subtractedAmount,
290
235
  bytes memory operatorNotificationData
291
- ) public virtual {
236
+ ) public virtual override {
292
237
  uint256 currentAllowance = authorizedAmountFor(operator, msg.sender);
293
- if (currentAllowance < substractedAmount) {
238
+ if (currentAllowance < subtractedAmount) {
294
239
  revert LSP7DecreasedAllowanceBelowZero();
295
240
  }
296
241
 
297
242
  uint256 newAllowance;
298
243
  unchecked {
299
- newAllowance = currentAllowance - substractedAmount;
244
+ newAllowance = currentAllowance - subtractedAmount;
300
245
  _updateOperator(
301
246
  msg.sender,
302
247
  operator,
303
248
  newAllowance,
249
+ true,
304
250
  operatorNotificationData
305
251
  );
306
252
  }
@@ -310,7 +256,66 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
310
256
  newAllowance,
311
257
  operatorNotificationData
312
258
  );
313
- _notifyTokenOperator(operator, lsp1Data);
259
+
260
+ operator.tryNotifyUniversalReceiver(
261
+ _TYPEID_LSP7_TOKENOPERATOR,
262
+ lsp1Data
263
+ );
264
+ }
265
+
266
+ // --- Transfer functionality
267
+
268
+ /**
269
+ * @inheritdoc ILSP7DigitalAsset
270
+ */
271
+ function transfer(
272
+ address from,
273
+ address to,
274
+ uint256 amount,
275
+ bool force,
276
+ bytes memory data
277
+ ) public virtual override {
278
+ if (from == to) revert LSP7CannotSendToSelf();
279
+
280
+ if (msg.sender != from) {
281
+ _spendAllowance({
282
+ operator: msg.sender,
283
+ tokenOwner: from,
284
+ amountToSpend: amount
285
+ });
286
+ }
287
+
288
+ _transfer(from, to, amount, force, data);
289
+ }
290
+
291
+ /**
292
+ * @inheritdoc ILSP7DigitalAsset
293
+ */
294
+ function transferBatch(
295
+ address[] memory from,
296
+ address[] memory to,
297
+ uint256[] memory amount,
298
+ bool[] memory force,
299
+ bytes[] memory data
300
+ ) public virtual override {
301
+ uint256 fromLength = from.length;
302
+ if (
303
+ fromLength != to.length ||
304
+ fromLength != amount.length ||
305
+ fromLength != force.length ||
306
+ fromLength != data.length
307
+ ) {
308
+ revert LSP7InvalidTransferBatch();
309
+ }
310
+
311
+ for (uint256 i; i < fromLength; ) {
312
+ // using the public transfer function to handle updates to operator authorized amounts
313
+ transfer(from[i], to[i], amount[i], force[i], data[i]);
314
+
315
+ unchecked {
316
+ ++i;
317
+ }
318
+ }
314
319
  }
315
320
 
316
321
  /**
@@ -318,6 +323,12 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
318
323
  * If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators.
319
324
  * If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified.
320
325
  *
326
+ * @param tokenOwner The address that will give `operator` an allowance for on its balance.
327
+ * @param operator The address to grant an allowance to spend.
328
+ * @param allowance The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance.
329
+ * @param notified Boolean indicating whether the operator has been notified about the change of allowance
330
+ * @param operatorNotificationData The data to send to the universalReceiver function of the operator in case of notifying
331
+ *
321
332
  * @custom:events
322
333
  * - {RevokedOperator} event when operator's allowance is set to `0`.
323
334
  * - {AuthorizedOperator} event when operator's allowance is set to any other amount.
@@ -329,7 +340,8 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
329
340
  function _updateOperator(
330
341
  address tokenOwner,
331
342
  address operator,
332
- uint256 amount,
343
+ uint256 allowance,
344
+ bool notified,
333
345
  bytes memory operatorNotificationData
334
346
  ) internal virtual {
335
347
  if (operator == address(0)) {
@@ -340,14 +352,14 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
340
352
  revert LSP7TokenOwnerCannotBeOperator();
341
353
  }
342
354
 
343
- _operatorAuthorizedAmount[tokenOwner][operator] = amount;
355
+ _operatorAuthorizedAmount[tokenOwner][operator] = allowance;
344
356
 
345
- if (amount != 0) {
357
+ if (allowance != 0) {
346
358
  _operators[tokenOwner].add(operator);
347
359
  emit AuthorizedOperator(
348
360
  operator,
349
361
  tokenOwner,
350
- amount,
362
+ allowance,
351
363
  operatorNotificationData
352
364
  );
353
365
  } else {
@@ -355,6 +367,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
355
367
  emit RevokedOperator(
356
368
  operator,
357
369
  tokenOwner,
370
+ notified,
358
371
  operatorNotificationData
359
372
  );
360
373
  }
@@ -363,9 +376,13 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
363
376
  /**
364
377
  * @dev Mints `amount` of tokens and transfers it to `to`.
365
378
  *
366
- * @param to the address to mint tokens for.
367
- * @param amount the amount of tokens to mint.
368
- * @param allowNonLSP1Recipient a boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
379
+ * @custom:info Any logic in the:
380
+ * - {_beforeTokenTransfer} function will run before updating the balances.
381
+ * - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the recipient via LSP1**.
382
+ *
383
+ * @param to The address to mint tokens for.
384
+ * @param amount The amount of tokens to mint.
385
+ * @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
369
386
  * @param data Additional data the caller wants included in the emitted {Transfer} event, and sent in the LSP1 hook to the `to` address.
370
387
  *
371
388
  * @custom:requirements
@@ -376,33 +393,26 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
376
393
  function _mint(
377
394
  address to,
378
395
  uint256 amount,
379
- bool allowNonLSP1Recipient,
396
+ bool force,
380
397
  bytes memory data
381
398
  ) internal virtual {
382
399
  if (to == address(0)) {
383
400
  revert LSP7CannotSendWithAddressZero();
384
401
  }
385
402
 
386
- address operator = msg.sender;
387
-
388
- _beforeTokenTransfer(address(0), to, amount);
403
+ _beforeTokenTransfer(address(0), to, amount, data);
389
404
 
390
405
  // tokens being minted
391
406
  _existingTokens += amount;
392
407
 
393
408
  _tokenOwnerBalances[to] += amount;
394
409
 
395
- emit Transfer(
396
- operator,
397
- address(0),
398
- to,
399
- amount,
400
- allowNonLSP1Recipient,
401
- data
402
- );
410
+ emit Transfer(msg.sender, address(0), to, amount, force, data);
411
+
412
+ _afterTokenTransfer(address(0), to, amount, data);
403
413
 
404
414
  bytes memory lsp1Data = abi.encode(address(0), to, amount, data);
405
- _notifyTokenReceiver(to, allowNonLSP1Recipient, lsp1Data);
415
+ _notifyTokenReceiver(to, force, lsp1Data);
406
416
  }
407
417
 
408
418
  /**
@@ -412,10 +422,12 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
412
422
  * function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
413
423
  * all the parameters in the calldata packed encoded.
414
424
  *
415
- * Any logic in the {_beforeTokenTransfer} function will run before updating the balances.
425
+ * @custom:info Any logic in the:
426
+ * - {_beforeTokenTransfer} function will run before updating the balances.
427
+ * - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender via LSP1**.
416
428
  *
417
- * @param from the address to burn tokens from its balance.
418
- * @param amount the amount of tokens to burn.
429
+ * @param from The address to burn tokens from its balance.
430
+ * @param amount The amount of tokens to burn.
419
431
  * @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
420
432
  *
421
433
  * @custom:hint In dApps, you can know which address is burning tokens by listening for the `Transfer` event and filter with the zero address as `to`.
@@ -442,33 +454,70 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
442
454
  revert LSP7AmountExceedsBalance(balance, from, amount);
443
455
  }
444
456
 
445
- address operator = msg.sender;
446
- if (operator != from) {
447
- uint256 authorizedAmount = _operatorAuthorizedAmount[from][
448
- operator
449
- ];
450
- if (amount > authorizedAmount) {
451
- revert LSP7AmountExceedsAuthorizedAmount(
452
- from,
453
- authorizedAmount,
454
- operator,
455
- amount
456
- );
457
- }
458
- _operatorAuthorizedAmount[from][operator] -= amount;
459
- }
460
-
461
- _beforeTokenTransfer(from, address(0), amount);
457
+ _beforeTokenTransfer(from, address(0), amount, data);
462
458
 
463
459
  // tokens being burnt
464
460
  _existingTokens -= amount;
465
461
 
466
462
  _tokenOwnerBalances[from] -= amount;
467
463
 
468
- emit Transfer(operator, from, address(0), amount, false, data);
464
+ emit Transfer(msg.sender, from, address(0), amount, false, data);
465
+ emit Transfer({
466
+ operator: msg.sender,
467
+ from: from,
468
+ to: address(0),
469
+ amount: amount,
470
+ force: false,
471
+ data: data
472
+ });
473
+
474
+ _afterTokenTransfer(from, address(0), amount, data);
469
475
 
470
476
  bytes memory lsp1Data = abi.encode(from, address(0), amount, data);
471
- _notifyTokenSender(from, lsp1Data);
477
+ from.tryNotifyUniversalReceiver(_TYPEID_LSP7_TOKENSSENDER, lsp1Data);
478
+ }
479
+
480
+ /**
481
+ * @dev Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`.
482
+ *
483
+ * @param operator The address of the operator to decrease the allowance of.
484
+ * @param tokenOwner The address that granted an allowance on its balance to `operator`.
485
+ * @param amountToSpend The amount of tokens to substract in allowance of `operator`.
486
+ *
487
+ * @custom:events
488
+ * - {RevokedOperator} event when operator's allowance is set to `0`.
489
+ * - {AuthorizedOperator} event when operator's allowance is set to any other amount.
490
+ *
491
+ * @custom:requirements
492
+ * - The `amountToSpend` MUST be at least the allowance granted to `operator` (accessible via {`authorizedAmountFor}`)
493
+ * - `operator` cannot be the zero address.
494
+ * - `operator` cannot be the same address as `tokenOwner`.
495
+ */
496
+ function _spendAllowance(
497
+ address operator,
498
+ address tokenOwner,
499
+ uint256 amountToSpend
500
+ ) internal virtual {
501
+ uint256 authorizedAmount = _operatorAuthorizedAmount[tokenOwner][
502
+ operator
503
+ ];
504
+
505
+ if (amountToSpend > authorizedAmount) {
506
+ revert LSP7AmountExceedsAuthorizedAmount(
507
+ tokenOwner,
508
+ authorizedAmount,
509
+ operator,
510
+ amountToSpend
511
+ );
512
+ }
513
+
514
+ _updateOperator({
515
+ tokenOwner: tokenOwner,
516
+ operator: operator,
517
+ allowance: authorizedAmount - amountToSpend,
518
+ notified: false,
519
+ operatorNotificationData: ""
520
+ });
472
521
  }
473
522
 
474
523
  /**
@@ -479,12 +528,14 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
479
528
  * function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
480
529
  * all the parameters in the calldata packed encoded.
481
530
  *
482
- * Any logic in the {_beforeTokenTransfer} function will run before updating the balances.
531
+ * @custom:info Any logic in the:
532
+ * - {_beforeTokenTransfer} function will run before updating the balances.
533
+ * - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender/recipient via LSP1**.
483
534
  *
484
- * @param from the address to decrease the balance.
485
- * @param to the address to increase the balance.
486
- * @param amount the amount of tokens to transfer from `from` to `to`.
487
- * @param allowNonLSP1Recipient a boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
535
+ * @param from The address to decrease the balance.
536
+ * @param to The address to increase the balance.
537
+ * @param amount The amount of tokens to transfer from `from` to `to`.
538
+ * @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
488
539
  * @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
489
540
  *
490
541
  * @custom:requirements
@@ -498,7 +549,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
498
549
  address from,
499
550
  address to,
500
551
  uint256 amount,
501
- bool allowNonLSP1Recipient,
552
+ bool force,
502
553
  bytes memory data
503
554
  ) internal virtual {
504
555
  if (from == address(0) || to == address(0)) {
@@ -510,19 +561,19 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
510
561
  revert LSP7AmountExceedsBalance(balance, from, amount);
511
562
  }
512
563
 
513
- address operator = msg.sender;
514
-
515
- _beforeTokenTransfer(from, to, amount);
564
+ _beforeTokenTransfer(from, to, amount, data);
516
565
 
517
566
  _tokenOwnerBalances[from] -= amount;
518
567
  _tokenOwnerBalances[to] += amount;
519
568
 
520
- emit Transfer(operator, from, to, amount, allowNonLSP1Recipient, data);
569
+ emit Transfer(msg.sender, from, to, amount, force, data);
570
+
571
+ _afterTokenTransfer(from, to, amount, data);
521
572
 
522
573
  bytes memory lsp1Data = abi.encode(from, to, amount, data);
523
574
 
524
- _notifyTokenSender(from, lsp1Data);
525
- _notifyTokenReceiver(to, allowNonLSP1Recipient, lsp1Data);
575
+ from.tryNotifyUniversalReceiver(_TYPEID_LSP7_TOKENSSENDER, lsp1Data);
576
+ _notifyTokenReceiver(to, force, lsp1Data);
526
577
  }
527
578
 
528
579
  /**
@@ -532,95 +583,52 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
532
583
  * @param from The sender address
533
584
  * @param to The recipient address
534
585
  * @param amount The amount of token to transfer
586
+ * @param data The data sent alongside the transfer
535
587
  */
536
588
  function _beforeTokenTransfer(
537
589
  address from,
538
590
  address to,
539
- uint256 amount
591
+ uint256 amount,
592
+ bytes memory data // solhint-disable-next-line no-empty-blocks
540
593
  ) internal virtual {}
541
594
 
542
595
  /**
543
- * @dev Attempt to notify the operator `operator` about the `amount` tokens being authorized with.
544
- * 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.
545
- * If `operator` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
546
-
547
- * @param operator The address to call the {universalReceiver} function on.
548
- * @param lsp1Data the data to be sent to the `operator` address in the `universalReceiver` call.
549
- */
550
- function _notifyTokenOperator(
551
- address operator,
552
- bytes memory lsp1Data
553
- ) internal virtual {
554
- if (
555
- ERC165Checker.supportsERC165InterfaceUnchecked(
556
- operator,
557
- _INTERFACEID_LSP1
558
- )
559
- ) {
560
- operator.call(
561
- abi.encodeWithSelector(
562
- ILSP1UniversalReceiver.universalReceiver.selector,
563
- _TYPEID_LSP7_TOKENOPERATOR,
564
- lsp1Data
565
- )
566
- );
567
- }
568
- }
569
-
570
- /**
571
- * @dev Attempt to notify the token sender `from` about the `amount` of tokens being transferred.
572
- * 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.
573
- * If `from` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
574
-
575
- * @param from The address to call the {universalReceiver} function on.
576
- * @param lsp1Data the data to be sent to the `from` address in the `universalReceiver` call.
596
+ * @dev Hook that is called after any token transfer, including minting and burning.
597
+ * Allows to run custom logic after updating balances, but **before notifiying sender/recipient** by overriding this function.
598
+ *
599
+ * @param from The sender address
600
+ * @param to The recipient address
601
+ * @param amount The amount of token to transfer
602
+ * @param data The data sent alongside the transfer
577
603
  */
578
- function _notifyTokenSender(
604
+ function _afterTokenTransfer(
579
605
  address from,
580
- bytes memory lsp1Data
581
- ) internal virtual {
582
- if (
583
- ERC165Checker.supportsERC165InterfaceUnchecked(
584
- from,
585
- _INTERFACEID_LSP1
586
- )
587
- ) {
588
- ILSP1UniversalReceiver(from).universalReceiver(
589
- _TYPEID_LSP7_TOKENSSENDER,
590
- lsp1Data
591
- );
592
- }
593
- }
606
+ address to,
607
+ uint256 amount,
608
+ bytes memory data // solhint-disable-next-line no-empty-blocks
609
+ ) internal virtual {}
594
610
 
595
611
  /**
596
612
  * @dev Attempt to notify the token receiver `to` about the `amount` tokens being received.
597
613
  * 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.
598
614
  *
599
- * If `to` is is an EOA or a contract that does not support the LSP1 interface, the behaviour will depend on the `allowNonLSP1Recipient` boolean flag.
600
- * - if `allowNonLSP1Recipient` is set to `true`, nothing will happen and no notification will be sent.
601
- * - if `allowNonLSP1Recipient` is set to `false, the transaction will revert.
615
+ * If `to` is is an EOA or a contract that does not support the LSP1 interface, the behaviour will depend on the `force` boolean flag.
616
+ * - if `force` is set to `true`, nothing will happen and no notification will be sent.
617
+ * - if `force` is set to `false, the transaction will revert.
602
618
  *
603
619
  * @param to The address to call the {universalReceiver} function on.
604
- * @param allowNonLSP1Recipient a boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
605
- * @param lsp1Data the data to be sent to the `to` address in the `universalReceiver(...)` call.
620
+ * @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
621
+ * @param lsp1Data The data to be sent to the `to` address in the `universalReceiver(...)` call.
606
622
  */
607
623
  function _notifyTokenReceiver(
608
624
  address to,
609
- bool allowNonLSP1Recipient,
625
+ bool force,
610
626
  bytes memory lsp1Data
611
627
  ) internal virtual {
612
- if (
613
- ERC165Checker.supportsERC165InterfaceUnchecked(
614
- to,
615
- _INTERFACEID_LSP1
616
- )
617
- ) {
618
- ILSP1UniversalReceiver(to).universalReceiver(
619
- _TYPEID_LSP7_TOKENSRECIPIENT,
620
- lsp1Data
621
- );
622
- } else if (!allowNonLSP1Recipient) {
623
- if (to.code.length > 0) {
628
+ if (to.supportsERC165InterfaceUnchecked(_INTERFACEID_LSP1)) {
629
+ ILSP1(to).universalReceiver(_TYPEID_LSP7_TOKENSRECIPIENT, lsp1Data);
630
+ } else if (!force) {
631
+ if (to.code.length != 0) {
624
632
  revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
625
633
  } else {
626
634
  revert LSP7NotifyTokenReceiverIsEOA(to);