@lukso/lsp-smart-contracts 0.11.0-rc.0 → 0.11.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 (199) hide show
  1. package/README.md +1 -0
  2. package/artifacts/LSP0ERC725Account.json +7 -2
  3. package/artifacts/LSP0ERC725AccountInit.json +7 -2
  4. package/artifacts/LSP11BasicSocialRecovery.json +2 -2
  5. package/artifacts/LSP11BasicSocialRecoveryInit.json +2 -2
  6. package/artifacts/LSP1UniversalReceiverDelegateUP.json +3 -79
  7. package/artifacts/LSP1UniversalReceiverDelegateVault.json +3 -41
  8. package/artifacts/LSP23LinkedContractsFactory.json +544 -0
  9. package/artifacts/LSP6KeyManager.json +24 -19
  10. package/artifacts/LSP6KeyManagerInit.json +24 -19
  11. package/artifacts/LSP7CappedSupply.json +88 -0
  12. package/artifacts/LSP7CappedSupplyInitAbstract.json +88 -0
  13. package/artifacts/LSP7CompatibleERC20.json +88 -0
  14. package/artifacts/LSP7CompatibleERC20InitAbstract.json +88 -0
  15. package/artifacts/LSP7CompatibleERC20Mintable.json +90 -2
  16. package/artifacts/LSP7CompatibleERC20MintableInit.json +90 -2
  17. package/artifacts/LSP7DigitalAsset.json +88 -0
  18. package/artifacts/LSP7DigitalAssetInitAbstract.json +88 -0
  19. package/artifacts/LSP7Mintable.json +90 -2
  20. package/artifacts/LSP7MintableInit.json +90 -2
  21. package/artifacts/LSP8CappedSupply.json +59 -0
  22. package/artifacts/LSP8CappedSupplyInitAbstract.json +59 -0
  23. package/artifacts/LSP8CompatibleERC721.json +60 -1
  24. package/artifacts/LSP8CompatibleERC721InitAbstract.json +60 -1
  25. package/artifacts/LSP8CompatibleERC721Mintable.json +62 -3
  26. package/artifacts/LSP8CompatibleERC721MintableInit.json +62 -3
  27. package/artifacts/LSP8IdentifiableDigitalAsset.json +59 -0
  28. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +59 -0
  29. package/artifacts/LSP8Mintable.json +61 -2
  30. package/artifacts/LSP8MintableInit.json +61 -2
  31. package/artifacts/LSP9Vault.json +7 -2
  32. package/artifacts/LSP9VaultInit.json +7 -2
  33. package/artifacts/UniversalProfile.json +7 -2
  34. package/artifacts/UniversalProfileInit.json +7 -2
  35. package/contracts/LSP0ERC725Account/ILSP0ERC725Account.sol +8 -36
  36. package/contracts/LSP0ERC725Account/LSP0Constants.sol +1 -1
  37. package/contracts/LSP0ERC725Account/LSP0ERC725Account.sol +15 -30
  38. package/contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol +122 -206
  39. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInit.sol +18 -36
  40. package/contracts/LSP0ERC725Account/LSP0ERC725AccountInitAbstract.sol +8 -34
  41. package/contracts/LSP10ReceivedVaults/LSP10Utils.sol +148 -177
  42. package/contracts/LSP14Ownable2Step/ILSP14Ownable2Step.sol +21 -20
  43. package/contracts/LSP14Ownable2Step/LSP14Errors.sol +13 -2
  44. package/contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol +50 -20
  45. package/contracts/LSP17ContractExtension/LSP17Errors.sol +10 -0
  46. package/contracts/LSP17ContractExtension/LSP17Extendable.sol +16 -34
  47. package/contracts/LSP17ContractExtension/LSP17Utils.sol +1 -1
  48. package/contracts/LSP1UniversalReceiver/ILSP1UniversalReceiver.sol +16 -11
  49. package/contracts/LSP1UniversalReceiver/LSP1Errors.sol +5 -10
  50. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateUP/LSP1UniversalReceiverDelegateUP.sol +192 -177
  51. package/contracts/LSP1UniversalReceiver/LSP1UniversalReceiverDelegateVault/LSP1UniversalReceiverDelegateVault.sol +150 -88
  52. package/contracts/LSP1UniversalReceiver/LSP1Utils.sol +66 -48
  53. package/contracts/LSP20CallVerification/LSP20CallVerification.sol +1 -1
  54. package/contracts/LSP23LinkedContractsDeployment/ILSP23LinkedContractsFactory.sol +192 -0
  55. package/contracts/LSP23LinkedContractsDeployment/IPostDeploymentModule.sol +18 -0
  56. package/contracts/LSP23LinkedContractsDeployment/LSP23Errors.sol +24 -0
  57. package/contracts/LSP23LinkedContractsDeployment/LSP23LinkedContractsFactory.sol +392 -0
  58. package/contracts/{LSP23MultiChainDeployment → LSP23LinkedContractsDeployment}/modules/UniversalProfileInitPostDeploymentModule.sol +5 -1
  59. package/contracts/LSP23LinkedContractsDeployment/modules/UniversalProfilePostDeploymentModule.sol +61 -0
  60. package/contracts/LSP25ExecuteRelayCall/ILSP25ExecuteRelayCall.sol +68 -0
  61. package/contracts/LSP25ExecuteRelayCall/LSP25Constants.sol +8 -0
  62. package/contracts/LSP25ExecuteRelayCall/LSP25Errors.sol +17 -0
  63. package/contracts/LSP25ExecuteRelayCall/LSP25MultiChannelNonce.sol +143 -0
  64. package/contracts/LSP2ERC725YJSONSchema/LSP2Utils.sol +256 -61
  65. package/contracts/{LSP3UniversalProfile → LSP3ProfileMetadata}/LSP3Constants.sol +3 -3
  66. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol +9 -8
  67. package/contracts/LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadataInitAbstract.sol +13 -6
  68. package/contracts/LSP4DigitalAssetMetadata/LSP4Errors.sol +4 -4
  69. package/contracts/LSP5ReceivedAssets/LSP5Utils.sol +148 -189
  70. package/contracts/LSP6KeyManager/ILSP6KeyManager.sol +26 -54
  71. package/contracts/LSP6KeyManager/LSP6Constants.sol +1 -3
  72. package/contracts/LSP6KeyManager/LSP6Errors.sol +142 -63
  73. package/contracts/LSP6KeyManager/LSP6KeyManager.sol +7 -4
  74. package/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +125 -80
  75. package/contracts/LSP6KeyManager/LSP6KeyManagerInit.sol +8 -4
  76. package/contracts/LSP6KeyManager/LSP6KeyManagerInitAbstract.sol +1 -1
  77. package/contracts/LSP6KeyManager/LSP6Modules/LSP6ExecuteModule.sol +52 -84
  78. package/contracts/LSP6KeyManager/LSP6Modules/LSP6SetDataModule.sol +59 -10
  79. package/contracts/LSP6KeyManager/LSP6Utils.sol +67 -46
  80. package/contracts/LSP7DigitalAsset/ILSP7DigitalAsset.sol +116 -78
  81. package/contracts/LSP7DigitalAsset/LSP7Constants.sol +4 -1
  82. package/contracts/LSP7DigitalAsset/LSP7DigitalAsset.sol +128 -6
  83. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol +212 -80
  84. package/contracts/LSP7DigitalAsset/LSP7DigitalAssetInitAbstract.sol +126 -3
  85. package/contracts/LSP7DigitalAsset/LSP7Errors.sol +7 -5
  86. package/contracts/LSP7DigitalAsset/extensions/ILSP7CompatibleERC20.sol +27 -14
  87. package/contracts/LSP7DigitalAsset/extensions/LSP7Burnable.sol +2 -4
  88. package/contracts/LSP7DigitalAsset/extensions/LSP7BurnableInitAbstract.sol +2 -4
  89. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupply.sol +29 -11
  90. package/contracts/LSP7DigitalAsset/extensions/LSP7CappedSupplyInitAbstract.sol +30 -9
  91. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20.sol +46 -14
  92. package/contracts/LSP7DigitalAsset/extensions/LSP7CompatibleERC20InitAbstract.sol +43 -12
  93. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20Mintable.sol +14 -0
  94. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInit.sol +9 -4
  95. package/contracts/LSP7DigitalAsset/presets/LSP7CompatibleERC20MintableInitAbstract.sol +7 -1
  96. package/contracts/LSP7DigitalAsset/presets/LSP7Mintable.sol +8 -8
  97. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInit.sol +7 -6
  98. package/contracts/LSP7DigitalAsset/presets/LSP7MintableInitAbstract.sol +10 -2
  99. package/contracts/LSP8IdentifiableDigitalAsset/ILSP8IdentifiableDigitalAsset.sol +120 -92
  100. package/contracts/LSP8IdentifiableDigitalAsset/LSP8Constants.sol +4 -1
  101. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAsset.sol +135 -6
  102. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetCore.sol +128 -38
  103. package/contracts/LSP8IdentifiableDigitalAsset/LSP8IdentifiableDigitalAssetInitAbstract.sol +134 -5
  104. package/contracts/LSP8IdentifiableDigitalAsset/extensions/ILSP8CompatibleERC721.sol +83 -41
  105. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Burnable.sol +13 -5
  106. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8BurnableInitAbstract.sol +24 -0
  107. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupply.sol +30 -12
  108. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CappedSupplyInitAbstract.sol +31 -10
  109. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +96 -31
  110. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +98 -23
  111. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8Enumerable.sol +21 -4
  112. package/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8EnumerableInitAbstract.sol +12 -2
  113. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721Mintable.sol +21 -0
  114. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInit.sol +9 -4
  115. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8CompatibleERC721MintableInitAbstract.sol +13 -0
  116. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8Mintable.sol +15 -6
  117. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInit.sol +7 -5
  118. package/contracts/LSP8IdentifiableDigitalAsset/presets/LSP8MintableInitAbstract.sol +17 -2
  119. package/contracts/LSP9Vault/ILSP9Vault.sol +10 -5
  120. package/contracts/LSP9Vault/LSP9Errors.sol +3 -2
  121. package/contracts/LSP9Vault/LSP9Vault.sol +12 -4
  122. package/contracts/LSP9Vault/LSP9VaultCore.sol +245 -182
  123. package/contracts/LSP9Vault/LSP9VaultInit.sol +10 -3
  124. package/contracts/LSP9Vault/LSP9VaultInitAbstract.sol +11 -6
  125. package/contracts/UniversalProfile.sol +8 -6
  126. package/contracts/UniversalProfileInit.sol +6 -6
  127. package/contracts/UniversalProfileInitAbstract.sol +10 -3
  128. package/devdocs/LSP0ERC725Account.json +54 -37
  129. package/devdocs/LSP0ERC725AccountInit.json +56 -38
  130. package/devdocs/LSP1UniversalReceiverDelegateUP.json +14 -55
  131. package/devdocs/LSP1UniversalReceiverDelegateVault.json +9 -33
  132. package/devdocs/LSP23LinkedContractsFactory.json +81 -0
  133. package/devdocs/LSP4DigitalAssetMetadata.json +5 -5
  134. package/devdocs/LSP4DigitalAssetMetadataInitAbstract.json +4 -4
  135. package/devdocs/LSP6KeyManager.json +109 -70
  136. package/devdocs/LSP6KeyManagerInit.json +109 -70
  137. package/devdocs/LSP7CappedSupply.json +90 -42
  138. package/devdocs/LSP7CappedSupplyInitAbstract.json +86 -40
  139. package/devdocs/LSP7CompatibleERC20.json +79 -43
  140. package/devdocs/LSP7CompatibleERC20InitAbstract.json +75 -39
  141. package/devdocs/LSP7CompatibleERC20Mintable.json +87 -40
  142. package/devdocs/LSP7CompatibleERC20MintableInit.json +82 -42
  143. package/devdocs/LSP7DigitalAsset.json +76 -40
  144. package/devdocs/LSP7DigitalAssetInitAbstract.json +73 -37
  145. package/devdocs/LSP7Mintable.json +79 -51
  146. package/devdocs/LSP7MintableInit.json +78 -49
  147. package/devdocs/LSP8CappedSupply.json +72 -43
  148. package/devdocs/LSP8CappedSupplyInitAbstract.json +68 -41
  149. package/devdocs/LSP8CompatibleERC721.json +85 -64
  150. package/devdocs/LSP8CompatibleERC721InitAbstract.json +81 -60
  151. package/devdocs/LSP8CompatibleERC721Mintable.json +98 -60
  152. package/devdocs/LSP8CompatibleERC721MintableInit.json +93 -62
  153. package/devdocs/LSP8IdentifiableDigitalAsset.json +58 -41
  154. package/devdocs/LSP8IdentifiableDigitalAssetInitAbstract.json +57 -40
  155. package/devdocs/LSP8Mintable.json +65 -48
  156. package/devdocs/LSP8MintableInit.json +64 -47
  157. package/devdocs/LSP9Vault.json +61 -18
  158. package/devdocs/LSP9VaultInit.json +59 -17
  159. package/devdocs/UniversalProfile.json +53 -35
  160. package/devdocs/UniversalProfileInit.json +53 -35
  161. package/dist/constants.cjs.js +6236 -2587
  162. package/dist/constants.d.ts +3851 -1129
  163. package/dist/constants.es.js +6236 -2587
  164. package/package.json +6 -4
  165. package/userdocs/LSP0ERC725Account.json +40 -8
  166. package/userdocs/LSP0ERC725AccountInit.json +40 -8
  167. package/userdocs/LSP1UniversalReceiverDelegateUP.json +18 -2
  168. package/userdocs/LSP1UniversalReceiverDelegateVault.json +18 -2
  169. package/userdocs/LSP23LinkedContractsFactory.json +29 -0
  170. package/userdocs/LSP4DigitalAssetMetadata.json +1 -1
  171. package/userdocs/LSP6KeyManager.json +144 -6
  172. package/userdocs/LSP6KeyManagerInit.json +147 -6
  173. package/userdocs/LSP7CappedSupply.json +18 -3
  174. package/userdocs/LSP7CappedSupplyInitAbstract.json +17 -2
  175. package/userdocs/LSP7CompatibleERC20.json +3 -9
  176. package/userdocs/LSP7CompatibleERC20InitAbstract.json +2 -8
  177. package/userdocs/LSP7CompatibleERC20Mintable.json +5 -8
  178. package/userdocs/LSP7CompatibleERC20MintableInit.json +3 -9
  179. package/userdocs/LSP7DigitalAsset.json +2 -2
  180. package/userdocs/LSP7DigitalAssetInitAbstract.json +2 -2
  181. package/userdocs/LSP7Mintable.json +3 -3
  182. package/userdocs/LSP7MintableInit.json +3 -3
  183. package/userdocs/LSP8CappedSupply.json +16 -1
  184. package/userdocs/LSP8CappedSupplyInitAbstract.json +15 -0
  185. package/userdocs/LSP8CompatibleERC721.json +24 -3
  186. package/userdocs/LSP8CompatibleERC721InitAbstract.json +23 -2
  187. package/userdocs/LSP8CompatibleERC721Mintable.json +29 -2
  188. package/userdocs/LSP8CompatibleERC721MintableInit.json +27 -3
  189. package/userdocs/LSP8Mintable.json +4 -1
  190. package/userdocs/LSP8MintableInit.json +4 -1
  191. package/userdocs/LSP9Vault.json +50 -4
  192. package/userdocs/LSP9VaultInit.json +50 -4
  193. package/userdocs/UniversalProfile.json +40 -8
  194. package/userdocs/UniversalProfileInit.json +40 -8
  195. package/contracts/LSP0ERC725Account/LSP0Utils.sol +0 -47
  196. package/contracts/LSP23MultiChainDeployment/IOwnerControlledContractDeployer.sol +0 -174
  197. package/contracts/LSP23MultiChainDeployment/IPostDeploymentModule.sol +0 -10
  198. package/contracts/LSP23MultiChainDeployment/LSP23Errors.sol +0 -24
  199. package/contracts/LSP23MultiChainDeployment/OwnerControlledContractDeployer.sol +0 -388
@@ -10,22 +10,37 @@ import {
10
10
  LSP4DigitalAssetMetadata
11
11
  } from "../LSP4DigitalAssetMetadata/LSP4DigitalAssetMetadata.sol";
12
12
  import {LSP7DigitalAssetCore} from "./LSP7DigitalAssetCore.sol";
13
+ import {LSP17Extendable} from "../LSP17ContractExtension/LSP17Extendable.sol";
14
+
15
+ // libraries
16
+ import {LSP2Utils} from "../LSP2ERC725YJSONSchema/LSP2Utils.sol";
13
17
 
14
18
  // constants
15
19
  import {_INTERFACEID_LSP7} from "./LSP7Constants.sol";
16
20
 
21
+ import "../LSP17ContractExtension/LSP17Constants.sol";
22
+
23
+ // errors
24
+
25
+ import {
26
+ NoExtensionFoundForFunctionSelector,
27
+ InvalidFunctionSelector,
28
+ InvalidExtensionAddress
29
+ } from "../LSP17ContractExtension/LSP17Errors.sol";
30
+
17
31
  /**
18
- * @title LSP7DigitalAsset contract
32
+ * @title Implementation of a LSP7 Digital Asset, a contract that represents a fungible token.
19
33
  * @author Matthew Stevens
20
- * @dev Implementation of a LSP7 compliant contract.
21
34
  *
35
+ * @dev Minting and transferring are supplied with a `uint256` amount.
22
36
  * This implementation is agnostic to the way tokens are created.
23
37
  * A supply mechanism has to be added in a derived contract using {_mint}
24
38
  * For a generic mechanism, see {LSP7Mintable}.
25
39
  */
26
40
  abstract contract LSP7DigitalAsset is
27
41
  LSP4DigitalAssetMetadata,
28
- LSP7DigitalAssetCore
42
+ LSP7DigitalAssetCore,
43
+ LSP17Extendable
29
44
  {
30
45
  /**
31
46
  * @notice Sets the token-Metadata
@@ -43,14 +58,121 @@ abstract contract LSP7DigitalAsset is
43
58
  _isNonDivisible = isNonDivisible_;
44
59
  }
45
60
 
61
+ // fallback function
62
+
63
+ // solhint-disable no-complex-fallback
64
+ /**
65
+ * @notice The `fallback` function was called with the following amount of native tokens: `msg.value`; and the following calldata: `callData`.
66
+ *
67
+ * @dev Achieves the goal of [LSP-17-ContractExtension] standard by extending the contract to handle calls of functions that do not exist natively,
68
+ * forwarding the function call to the extension address mapped to the function being called.
69
+ *
70
+ * This function is executed when:
71
+ * - Sending data of length less than 4 bytes to the contract.
72
+ * - The first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
73
+ * - Receiving native tokens
74
+ *
75
+ * 1. If the data is equal or longer than 4 bytes, the [ERC-725Y] storage is queried with the following data key: [_LSP17_EXTENSION_PREFIX] + `bytes4(msg.sig)` (Check [LSP-2-ERC725YJSONSchema] for encoding the data key)
76
+ *
77
+ * - If there is no address stored under the following data key, revert with {NoExtensionFoundForFunctionSelector(bytes4)}. The data key relative to `bytes4(0)` is an exception, where no reverts occurs if there is no extension address stored under. This exception is made to allow users to send random data (graffiti) to the account and to be able to react on it.
78
+ *
79
+ * - If there is an address, forward the `msg.data` to the extension using the CALL opcode, appending 52 bytes (20 bytes of `msg.sender` and 32 bytes of `msg.value`). Return what the calls returns, or revert if the call failed.
80
+ *
81
+ * 2. If the data sent to this function is of length less than 4 bytes (not a function selector), revert.
82
+ */
83
+ fallback(
84
+ bytes calldata callData
85
+ ) external payable virtual returns (bytes memory) {
86
+ if (msg.data.length < 4) {
87
+ revert InvalidFunctionSelector(callData);
88
+ }
89
+ return _fallbackLSP17Extendable(callData);
90
+ }
91
+
92
+ /**
93
+ * @dev Forwards the call with the received value to an extension mapped to a function selector.
94
+ *
95
+ * Calls {_getExtension} to get the address of the extension mapped to the function selector being
96
+ * called on the account. If there is no extension, the address(0) will be returned.
97
+ *
98
+ * Reverts if there is no extension for the function being called.
99
+ *
100
+ * If there is an extension for the function selector being called, it calls the extension with the
101
+ * CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
102
+ * 32 bytes of the {msg.value}
103
+ *
104
+ * Because the function uses assembly {return()/revert()} to terminate the call, it cannot be
105
+ * called before other codes in fallback().
106
+ *
107
+ * Otherwise, the codes after _fallbackLSP17Extendable() may never be reached.
108
+ */
109
+ function _fallbackLSP17Extendable(
110
+ bytes calldata callData
111
+ ) internal virtual override returns (bytes memory) {
112
+ // If there is a function selector
113
+ address extension = _getExtension(msg.sig);
114
+
115
+ // if no extension was found, revert
116
+ if (extension == address(0))
117
+ revert NoExtensionFoundForFunctionSelector(msg.sig);
118
+
119
+ (bool success, bytes memory result) = extension.call{value: msg.value}(
120
+ abi.encodePacked(callData, msg.sender, msg.value)
121
+ );
122
+
123
+ if (success) {
124
+ return result;
125
+ } else {
126
+ // `mload(result)` -> offset in memory where `result.length` is located
127
+ // `add(result, 32)` -> offset in memory where `result` data starts
128
+ // solhint-disable no-inline-assembly
129
+ /// @solidity memory-safe-assembly
130
+ assembly {
131
+ let resultdata_size := mload(result)
132
+ revert(add(result, 32), resultdata_size)
133
+ }
134
+ }
135
+ }
136
+
137
+ /**
138
+ * @dev Returns the extension address stored under the following data key:
139
+ * - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
140
+ * - If no extension is stored, returns the address(0).
141
+ */
142
+ function _getExtension(
143
+ bytes4 functionSelector
144
+ ) internal view virtual override returns (address) {
145
+ // Generate the data key relevant for the functionSelector being called
146
+ bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
147
+ _LSP17_EXTENSION_PREFIX,
148
+ functionSelector
149
+ );
150
+
151
+ // Check if there is an extension stored under the generated data key
152
+ bytes memory extensionAddress = ERC725YCore._getData(
153
+ mappedExtensionDataKey
154
+ );
155
+ if (extensionAddress.length != 20 && extensionAddress.length != 0)
156
+ revert InvalidExtensionAddress(extensionAddress);
157
+
158
+ return address(bytes20(extensionAddress));
159
+ }
160
+
46
161
  /**
47
- * @dev See {IERC165-supportsInterface}.
162
+ * @inheritdoc IERC165
48
163
  */
49
164
  function supportsInterface(
50
165
  bytes4 interfaceId
51
- ) public view virtual override(IERC165, ERC725YCore) returns (bool) {
166
+ )
167
+ public
168
+ view
169
+ virtual
170
+ override(IERC165, ERC725YCore, LSP17Extendable)
171
+ returns (bool)
172
+ {
52
173
  return
53
174
  interfaceId == _INTERFACEID_LSP7 ||
54
- super.supportsInterface(interfaceId);
175
+ super.supportsInterface(interfaceId) ||
176
+ LSP17Extendable._supportsInterfaceInERC165Extension(interfaceId);
55
177
  }
56
178
  }
@@ -12,12 +12,17 @@ import {
12
12
  ERC165Checker
13
13
  } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
14
14
 
15
+ import {
16
+ EnumerableSet
17
+ } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
18
+
15
19
  // errors
16
20
  import "./LSP7Errors.sol";
17
21
 
18
22
  // constants
19
23
  import {_INTERFACEID_LSP1} from "../LSP1UniversalReceiver/LSP1Constants.sol";
20
24
  import {
25
+ _TYPEID_LSP7_TOKENOPERATOR,
21
26
  _TYPEID_LSP7_TOKENSSENDER,
22
27
  _TYPEID_LSP7_TOKENSRECIPIENT
23
28
  } from "./LSP7Constants.sol";
@@ -29,20 +34,24 @@ import {
29
34
  *
30
35
  * This contract implement the core logic of the functions for the {ILSP7DigitalAsset} interface.
31
36
  *
32
- * Similar to ERC20, the non-standard {decreaseAllowance} and {increaseAllowance}
33
- * functions have been added to mitigate the well-known issues around setting allowances.
37
+ * Similar to ERC20, the non-standard {increaseAllowance} and {decreaseAllowance} functions
38
+ * have been added to mitigate the well-known issues around setting allowances.
34
39
  */
35
40
  abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
41
+ using EnumerableSet for EnumerableSet.AddressSet;
36
42
  // --- Storage
37
43
 
38
44
  // Mapping from `tokenOwner` to an `amount` of tokens
39
- mapping(address => uint256) private _tokenOwnerBalances;
45
+ mapping(address => uint256) internal _tokenOwnerBalances;
40
46
 
41
47
  // Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
42
48
  mapping(address => mapping(address => uint256))
43
- private _operatorAuthorizedAmount;
49
+ internal _operatorAuthorizedAmount;
50
+
51
+ // Mapping an `address` to its authorized operator addresses.
52
+ mapping(address => EnumerableSet.AddressSet) internal _operators;
44
53
 
45
- uint256 private _existingTokens;
54
+ uint256 internal _existingTokens;
46
55
 
47
56
  bool internal _isNonDivisible;
48
57
 
@@ -78,28 +87,45 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
78
87
  /**
79
88
  * @inheritdoc ILSP7DigitalAsset
80
89
  *
81
- * @dev To avoid front-running and Allowance Double-Spend Exploit when
82
- * increasing or decreasing the authorized amount of an operator,
83
- * it is advised to:
84
- * 1. call {revokeOperator} first, and
85
- * 2. then re-call {authorizeOperator} with the new amount
90
+ * @custom:danger To avoid front-running and Allowance Double-Spend Exploit when
91
+ * increasing or decreasing the authorized amount of an operator, it is advised to:
86
92
  *
87
- * for more information, see:
88
- * https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/
93
+ * 1. either call {revokeOperator} first, and then re-call {authorizeOperator} with the new amount.
94
+ * 2. or use the non-standard functions {increaseAllowance} or {decreaseAllowance}.
89
95
  *
96
+ * For more information, see:
97
+ * https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/
90
98
  */
91
99
  function authorizeOperator(
92
100
  address operator,
93
- uint256 amount
101
+ uint256 amount,
102
+ bytes memory operatorNotificationData
94
103
  ) public virtual {
95
- _updateOperator(msg.sender, operator, amount);
104
+ _updateOperator(msg.sender, operator, amount, operatorNotificationData);
105
+
106
+ bytes memory lsp1Data = abi.encode(
107
+ msg.sender,
108
+ amount,
109
+ operatorNotificationData
110
+ );
111
+ _notifyTokenOperator(operator, lsp1Data);
96
112
  }
97
113
 
98
114
  /**
99
115
  * @inheritdoc ILSP7DigitalAsset
100
116
  */
101
- function revokeOperator(address operator) public virtual {
102
- _updateOperator(msg.sender, operator, 0);
117
+ function revokeOperator(
118
+ address operator,
119
+ bytes memory operatorNotificationData
120
+ ) public virtual {
121
+ _updateOperator(msg.sender, operator, 0, operatorNotificationData);
122
+
123
+ bytes memory lsp1Data = abi.encode(
124
+ msg.sender,
125
+ 0,
126
+ operatorNotificationData
127
+ );
128
+ _notifyTokenOperator(operator, lsp1Data);
103
129
  }
104
130
 
105
131
  /**
@@ -116,6 +142,15 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
116
142
  }
117
143
  }
118
144
 
145
+ /**
146
+ * @inheritdoc ILSP7DigitalAsset
147
+ */
148
+ function getOperatorsOf(
149
+ address tokenOwner
150
+ ) public view virtual returns (address[] memory) {
151
+ return _operators[tokenOwner].values();
152
+ }
153
+
119
154
  // --- Transfer functionality
120
155
 
121
156
  /**
@@ -142,7 +177,7 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
142
177
  );
143
178
  }
144
179
 
145
- _updateOperator(from, operator, operatorAmount - amount);
180
+ _updateOperator(from, operator, operatorAmount - amount, "");
146
181
  }
147
182
 
148
183
  _transfer(from, to, amount, allowNonLSP1Recipient, data);
@@ -185,85 +220,117 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
185
220
  }
186
221
 
187
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
+ *
188
227
  * @notice Increase the allowance of `operator` by +`addedAmount`
189
- * @dev Atomically increases the allowance granted to `operator` by the caller.
190
228
  *
229
+ * @dev Atomically increases the allowance granted to `operator` by the caller.
191
230
  * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
192
- * for problems described in {ILSP7DigitalAsset}.
193
- *
194
- * Emits an {AuthorizedOperator} event indicating the updated allowance.
231
+ * for the double spending allowance problem.
195
232
  *
196
233
  * @param operator the operator to increase the allowance for `msg.sender`
197
234
  * @param addedAmount the additional amount to add on top of the current operator's allowance
198
235
  *
199
- * @dev Requirements:
236
+ * @custom:requirements
200
237
  * - `operator` cannot be the same address as `msg.sender`
201
238
  * - `operator` cannot be the zero address.
239
+ *
240
+ * @custom:events {AuthorizedOperator} indicating the updated allowance
202
241
  */
203
242
  function increaseAllowance(
204
243
  address operator,
205
- uint256 addedAmount
244
+ uint256 addedAmount,
245
+ bytes memory operatorNotificationData
206
246
  ) public virtual {
247
+ uint256 newAllowance = authorizedAmountFor(operator, msg.sender) +
248
+ addedAmount;
207
249
  _updateOperator(
208
250
  msg.sender,
209
251
  operator,
210
- authorizedAmountFor(operator, msg.sender) + addedAmount
252
+ newAllowance,
253
+ operatorNotificationData
254
+ );
255
+
256
+ bytes memory lsp1Data = abi.encode(
257
+ msg.sender,
258
+ newAllowance,
259
+ operatorNotificationData
211
260
  );
261
+ _notifyTokenOperator(operator, lsp1Data);
212
262
  }
213
263
 
214
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
+ *
215
269
  * @notice Decrease the allowance of `operator` by -`substractedAmount`
270
+ *
216
271
  * @dev Atomically decreases the allowance granted to `operator` by the caller.
217
272
  * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
218
- * for problems described in {ILSP7DigitalAsset}
273
+ * for the double spending allowance problem.
219
274
  *
220
- * Emits:
221
- * - an {AuthorizedOperator} event indicating the updated allowance after decreasing it.
222
- * - a {RevokeOperator} event if `substractedAmount` is the full allowance,
223
- * indicating `operator` does not have any allowance left for `msg.sender`.
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`.
224
279
  *
225
280
  * @param operator the operator to decrease allowance for `msg.sender`
226
281
  * @param substractedAmount the amount to decrease by in the operator's allowance.
227
282
  *
228
- * @dev Requirements:
283
+ * @custom:requirements
229
284
  * - `operator` cannot be the zero address.
230
- * - operator` must have allowance for the caller of at least `substractedAmount`.
285
+ * - `operator` must have allowance for the caller of at least `substractedAmount`.
231
286
  */
232
287
  function decreaseAllowance(
233
288
  address operator,
234
- uint256 substractedAmount
289
+ uint256 substractedAmount,
290
+ bytes memory operatorNotificationData
235
291
  ) public virtual {
236
292
  uint256 currentAllowance = authorizedAmountFor(operator, msg.sender);
237
293
  if (currentAllowance < substractedAmount) {
238
294
  revert LSP7DecreasedAllowanceBelowZero();
239
295
  }
240
296
 
297
+ uint256 newAllowance;
241
298
  unchecked {
299
+ newAllowance = currentAllowance - substractedAmount;
242
300
  _updateOperator(
243
301
  msg.sender,
244
302
  operator,
245
- currentAllowance - substractedAmount
303
+ newAllowance,
304
+ operatorNotificationData
246
305
  );
247
306
  }
307
+
308
+ bytes memory lsp1Data = abi.encode(
309
+ msg.sender,
310
+ newAllowance,
311
+ operatorNotificationData
312
+ );
313
+ _notifyTokenOperator(operator, lsp1Data);
248
314
  }
249
315
 
250
316
  /**
251
- * @dev Changes token `amount` the `operator` has access to from `tokenOwner` tokens. If the
252
- * amount is zero then the operator is being revoked, otherwise the operator amount is being
253
- * modified.
254
- *
255
- * See {authorizedAmountFor}.
256
- *
257
- * Emits either {AuthorizedOperator} or {RevokedOperator} event.
317
+ * @dev Changes token `amount` the `operator` has access to from `tokenOwner` tokens.
318
+ * If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators.
319
+ * If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified.
258
320
  *
259
- * Requirements
321
+ * @custom:events
322
+ * - {RevokedOperator} event when operator's allowance is set to `0`.
323
+ * - {AuthorizedOperator} event when operator's allowance is set to any other amount.
260
324
  *
325
+ * @custom:requirements
261
326
  * - `operator` cannot be the zero address.
327
+ * - `operator` cannot be the same address as `tokenOwner`.
262
328
  */
263
329
  function _updateOperator(
264
330
  address tokenOwner,
265
331
  address operator,
266
- uint256 amount
332
+ uint256 amount,
333
+ bytes memory operatorNotificationData
267
334
  ) internal virtual {
268
335
  if (operator == address(0)) {
269
336
  revert LSP7CannotUseAddressZeroAsOperator();
@@ -276,20 +343,35 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
276
343
  _operatorAuthorizedAmount[tokenOwner][operator] = amount;
277
344
 
278
345
  if (amount != 0) {
279
- emit AuthorizedOperator(operator, tokenOwner, amount);
346
+ _operators[tokenOwner].add(operator);
347
+ emit AuthorizedOperator(
348
+ operator,
349
+ tokenOwner,
350
+ amount,
351
+ operatorNotificationData
352
+ );
280
353
  } else {
281
- emit RevokedOperator(operator, tokenOwner);
354
+ _operators[tokenOwner].remove(operator);
355
+ emit RevokedOperator(
356
+ operator,
357
+ tokenOwner,
358
+ operatorNotificationData
359
+ );
282
360
  }
283
361
  }
284
362
 
285
363
  /**
286
- * @dev Mints `amount` tokens and transfers it to `to`.
364
+ * @dev Mints `amount` of tokens and transfers it to `to`.
287
365
  *
288
- * Requirements:
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.
369
+ * @param data Additional data the caller wants included in the emitted {Transfer} event, and sent in the LSP1 hook to the `to` address.
289
370
  *
371
+ * @custom:requirements
290
372
  * - `to` cannot be the zero address.
291
373
  *
292
- * Emits a {Transfer} event.
374
+ * @custom:events {Transfer} event with `address(0)` as `from`.
293
375
  */
294
376
  function _mint(
295
377
  address to,
@@ -319,21 +401,32 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
319
401
  data
320
402
  );
321
403
 
322
- bytes memory lsp1Data = abi.encodePacked(address(0), to, amount, data);
404
+ bytes memory lsp1Data = abi.encode(address(0), to, amount, data);
323
405
  _notifyTokenReceiver(to, allowNonLSP1Recipient, lsp1Data);
324
406
  }
325
407
 
326
408
  /**
327
- * @dev Destroys `amount` tokens.
409
+ * @dev Burns (= destroys) `amount` of tokens, decrease the `from` balance. This is done by sending them to the zero address.
410
+ *
411
+ * Both the sender and recipient will be notified of the token transfer through the LSP1 {universalReceiver}
412
+ * function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
413
+ * all the parameters in the calldata packed encoded.
414
+ *
415
+ * Any logic in the {_beforeTokenTransfer} function will run before updating the balances.
328
416
  *
329
- * Requirements:
417
+ * @param from the address to burn tokens from its balance.
418
+ * @param amount the amount of tokens to burn.
419
+ * @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
330
420
  *
421
+ * @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`.
422
+ *
423
+ * @custom:requirements
331
424
  * - `from` cannot be the zero address.
332
425
  * - `from` must have at least `amount` tokens.
333
426
  * - If the caller is not `from`, it must be an operator for `from` with access to at least
334
427
  * `amount` tokens.
335
428
  *
336
- * Emits a {Transfer} event.
429
+ * @custom:events {Transfer} event with `address(0)` as the `to` address
337
430
  */
338
431
  function _burn(
339
432
  address from,
@@ -367,34 +460,39 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
367
460
 
368
461
  _beforeTokenTransfer(from, address(0), amount);
369
462
 
370
- // tokens being burned
463
+ // tokens being burnt
371
464
  _existingTokens -= amount;
372
465
 
373
466
  _tokenOwnerBalances[from] -= amount;
374
467
 
375
468
  emit Transfer(operator, from, address(0), amount, false, data);
376
469
 
377
- bytes memory lsp1Data = abi.encodePacked(
378
- from,
379
- address(0),
380
- amount,
381
- data
382
- );
470
+ bytes memory lsp1Data = abi.encode(from, address(0), amount, data);
383
471
  _notifyTokenSender(from, lsp1Data);
384
472
  }
385
473
 
386
474
  /**
387
- * @dev Transfers `amount` tokens from `from` to `to`.
475
+ * @dev Transfer tokens from `from` to `to` by decreasing the balance of `from` by `-amount` and increasing the balance
476
+ * of `to` by `+amount`.
388
477
  *
389
- * Requirements:
478
+ * Both the sender and recipient will be notified of the token transfer through the LSP1 {universalReceiver}
479
+ * function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
480
+ * all the parameters in the calldata packed encoded.
390
481
  *
391
- * - `to` cannot be the zero address.
482
+ * Any logic in the {_beforeTokenTransfer} function will run before updating the balances.
483
+ *
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.
488
+ * @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
+ *
490
+ * @custom:requirements
392
491
  * - `from` cannot be the zero address.
393
- * - `from` must have at least `amount` tokens.
394
- * - If the caller is not `from`, it must be an operator for `from` with access to at least
395
- * `amount` tokens.
492
+ * - `to` cannot be the zero address.
493
+ * - `from` must have at least `amount` of tokens.
396
494
  *
397
- * Emits a {Transfer} event.
495
+ * @custom:events {Transfer} event.
398
496
  */
399
497
  function _transfer(
400
498
  address from,
@@ -421,23 +519,19 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
421
519
 
422
520
  emit Transfer(operator, from, to, amount, allowNonLSP1Recipient, data);
423
521
 
424
- bytes memory lsp1Data = abi.encodePacked(from, to, amount, data);
522
+ bytes memory lsp1Data = abi.encode(from, to, amount, data);
425
523
 
426
524
  _notifyTokenSender(from, lsp1Data);
427
525
  _notifyTokenReceiver(to, allowNonLSP1Recipient, lsp1Data);
428
526
  }
429
527
 
430
528
  /**
431
- * @dev Hook that is called before any token transfer. This includes minting
432
- * and burning.
433
- *
434
- * Calling conditions:
529
+ * @dev Hook that is called before any token transfer, including minting and burning.
530
+ * Allows to run custom logic before updating balances and notifiying sender/recipient by overriding this function.
435
531
  *
436
- * - When `from` and `to` are both non-zero, ``from``'s `amount` tokens will be
437
- * transferred to `to`.
438
- * - When `from` is zero, `amount` tokens will be minted for `to`.
439
- * - When `to` is zero, ``from``'s `amount` tokens will be burned.
440
- * - `from` and `to` are never both zero.
532
+ * @param from The sender address
533
+ * @param to The recipient address
534
+ * @param amount The amount of token to transfer
441
535
  */
442
536
  function _beforeTokenTransfer(
443
537
  address from,
@@ -446,8 +540,40 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
446
540
  ) internal virtual {}
447
541
 
448
542
  /**
449
- * @dev An attempt is made to notify the token sender about the `amount` tokens changing owners using
450
- * LSP1 interface.
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.
451
577
  */
452
578
  function _notifyTokenSender(
453
579
  address from,
@@ -467,10 +593,16 @@ abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
467
593
  }
468
594
 
469
595
  /**
470
- * @dev An attempt is made to notify the token receiver about the `amount` tokens changing owners
471
- * using LSP1 interface. When allowNonLSP1Recipient is FALSE the token receiver MUST support LSP1.
596
+ * @dev Attempt to notify the token receiver `to` about the `amount` tokens being received.
597
+ * 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
+ *
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.
472
602
  *
473
- * The receiver may revert when the token being sent is not wanted.
603
+ * @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.
474
606
  */
475
607
  function _notifyTokenReceiver(
476
608
  address to,