@lukso/lsp7-contracts 0.15.0-rc.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 (41) hide show
  1. package/README.md +3 -0
  2. package/artifacts/LSP7CappedSupply.json +828 -0
  3. package/artifacts/LSP7CappedSupplyInitAbstract.json +841 -0
  4. package/artifacts/LSP7DigitalAsset.json +805 -0
  5. package/artifacts/LSP7DigitalAssetInitAbstract.json +818 -0
  6. package/artifacts/LSP7Mintable.json +864 -0
  7. package/artifacts/LSP7MintableInit.json +884 -0
  8. package/contracts/ILSP7DigitalAsset.sol +309 -0
  9. package/contracts/LSP7Constants.sol +16 -0
  10. package/contracts/LSP7DigitalAsset.sol +198 -0
  11. package/contracts/LSP7DigitalAssetCore.sol +744 -0
  12. package/contracts/LSP7DigitalAssetInitAbstract.sol +194 -0
  13. package/contracts/LSP7Errors.sol +103 -0
  14. package/contracts/extensions/LSP7Burnable.sol +26 -0
  15. package/contracts/extensions/LSP7BurnableInitAbstract.sol +27 -0
  16. package/contracts/extensions/LSP7CappedSupply.sol +83 -0
  17. package/contracts/extensions/LSP7CappedSupplyInitAbstract.sol +86 -0
  18. package/contracts/presets/ILSP7Mintable.sol +32 -0
  19. package/contracts/presets/LSP7Mintable.sol +53 -0
  20. package/contracts/presets/LSP7MintableInit.sol +44 -0
  21. package/contracts/presets/LSP7MintableInitAbstract.sol +57 -0
  22. package/dist/index.cjs +14 -0
  23. package/dist/index.d.cts +8 -0
  24. package/dist/index.d.mts +8 -0
  25. package/dist/index.d.ts +8 -0
  26. package/dist/index.mjs +11 -0
  27. package/package.json +54 -0
  28. package/types/LSP7CappedSupply.ts +712 -0
  29. package/types/LSP7CappedSupplyInitAbstract.ts +743 -0
  30. package/types/LSP7DigitalAsset.ts +698 -0
  31. package/types/LSP7DigitalAssetInitAbstract.ts +729 -0
  32. package/types/LSP7Mintable.ts +717 -0
  33. package/types/LSP7MintableInit.ts +779 -0
  34. package/types/common.ts +131 -0
  35. package/types/contracts/LSP7DigitalAsset.ts +698 -0
  36. package/types/contracts/LSP7DigitalAssetInitAbstract.ts +729 -0
  37. package/types/contracts/extensions/LSP7CappedSupply.ts +712 -0
  38. package/types/contracts/extensions/LSP7CappedSupplyInitAbstract.ts +743 -0
  39. package/types/contracts/presets/LSP7Mintable.ts +717 -0
  40. package/types/contracts/presets/LSP7MintableInit.ts +779 -0
  41. package/types/index.ts +16 -0
@@ -0,0 +1,309 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ pragma solidity ^0.8.4;
4
+
5
+ // interfaces
6
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
7
+ import {
8
+ IERC725Y
9
+ } from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";
10
+
11
+ /**
12
+ * @title Interface of the LSP7 - Digital Asset standard, a fungible digital asset.
13
+ */
14
+ interface ILSP7DigitalAsset is IERC165, IERC725Y {
15
+ // --- Events
16
+
17
+ /**
18
+ * @dev Emitted when the `from` transferred successfully `amount` of tokens to `to`.
19
+ * @param operator The address of the operator that executed the transfer.
20
+ * @param from The address which tokens were sent from (balance decreased by `-amount`).
21
+ * @param to The address that received the tokens (balance increased by `+amount`).
22
+ * @param amount The amount of tokens transferred.
23
+ * @param force if the transferred enforced the `to` recipient address to be a contract that implements the LSP1 standard or not.
24
+ * @param data Any additional data included by the caller during the transfer, and sent in the LSP1 hooks to the `from` and `to` addresses.
25
+ */
26
+ event Transfer(
27
+ address indexed operator,
28
+ address indexed from,
29
+ address indexed to,
30
+ uint256 amount,
31
+ bool force,
32
+ bytes data
33
+ );
34
+
35
+ /**
36
+ * @dev Emitted when `tokenOwner` enables `operator` for `amount` tokens.
37
+ * @param operator The address authorized as an operator
38
+ * @param tokenOwner The token owner
39
+ * @param amount The amount of tokens `operator` address has access to from `tokenOwner`
40
+ * @param operatorNotificationData The data to notify the operator about via LSP1.
41
+ */
42
+ event OperatorAuthorizationChanged(
43
+ address indexed operator,
44
+ address indexed tokenOwner,
45
+ uint256 indexed amount,
46
+ bytes operatorNotificationData
47
+ );
48
+
49
+ /**
50
+ * @dev Emitted when `tokenOwner` disables `operator` for `amount` tokens and set its {`authorizedAmountFor(...)`} to `0`.
51
+ * @param operator The address revoked from operating
52
+ * @param tokenOwner The token owner
53
+ * @param notified Bool indicating whether the operator has been notified or not
54
+ * @param operatorNotificationData The data to notify the operator about via LSP1.
55
+ */
56
+ event OperatorRevoked(
57
+ address indexed operator,
58
+ address indexed tokenOwner,
59
+ bool indexed notified,
60
+ bytes operatorNotificationData
61
+ );
62
+
63
+ // --- Token queries
64
+
65
+ /**
66
+ * @dev Returns the number of decimals used to get its user representation.
67
+ * If the asset contract has been set to be non-divisible via the `isNonDivisible_` parameter in
68
+ * the `constructor`, the decimals returned wiil be `0`. Otherwise `18` is the common value.
69
+ *
70
+ * @custom:notice This information is only used for _display_ purposes: it in
71
+ * no way affects any of the arithmetic of the contract, including
72
+ * {balanceOf} and {transfer}.
73
+ *
74
+ * @return the number of decimals. If `0` is returned, the asset is non-divisible.
75
+ */
76
+ function decimals() external view returns (uint8);
77
+
78
+ /**
79
+ * @dev Returns the number of existing tokens that have been minted in this contract.
80
+ * @return The number of existing tokens.
81
+ */
82
+ function totalSupply() external view returns (uint256);
83
+
84
+ // --- Token owner queries
85
+
86
+ /**
87
+ * @dev Get the number of tokens owned by `tokenOwner`.
88
+ * If the token is divisible (the {decimals} function returns `18`), the amount returned should be divided
89
+ * by 1e18 to get a better picture of the actual balance of the `tokenOwner`.
90
+ *
91
+ * _Example:_
92
+ *
93
+ * ```
94
+ * balanceOf(someAddress) -> 42_000_000_000_000_000_000 / 1e18 = 42 tokens
95
+ * ```
96
+ *
97
+ * @param tokenOwner The address of the token holder to query the balance for.
98
+ * @return The amount of tokens owned by `tokenOwner`.
99
+ */
100
+ function balanceOf(address tokenOwner) external view returns (uint256);
101
+
102
+ // --- Operator functionality
103
+
104
+ /**
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
107
+ *
108
+ * @param operator The address to authorize as an operator.
109
+ * @param amount The allowance amount of tokens operator has access to.
110
+ * @param operatorNotificationData The data to notify the operator about via LSP1.
111
+ *
112
+ * @custom:requirements
113
+ * - `operator` cannot be the zero address.
114
+ *
115
+ * @custom:events {OperatorAuthorizationChanged} when allowance is given to a new operator or
116
+ * an existing operator's allowance is updated.
117
+ */
118
+ function authorizeOperator(
119
+ address operator,
120
+ uint256 amount,
121
+ bytes memory operatorNotificationData
122
+ ) external;
123
+
124
+ /**
125
+ * @dev Enables `tokenOwner` to remove `operator` for its tokens, disallowing it to send any amount of tokens on its behalf.
126
+ * This function also allows the `operator` to remove itself if it is the caller of this function
127
+ *
128
+ * @param operator The address to revoke as an operator.
129
+ * @param tokenOwner The address of the token owner.
130
+ * @param notify Boolean indicating whether to notify the operator or not.
131
+ * @param operatorNotificationData The data to notify the operator about via LSP1.
132
+ *
133
+ * @custom:requirements
134
+ * - caller MUST be `operator` or `tokenOwner`
135
+ * - `operator` cannot be the zero address.
136
+ *
137
+ * @custom:events {OperatorRevoked} event with address of the operator being revoked for the caller (token holder).
138
+ */
139
+ function revokeOperator(
140
+ address operator,
141
+ address tokenOwner,
142
+ bool notify,
143
+ bytes memory operatorNotificationData
144
+ ) external;
145
+
146
+ /**
147
+ * @custom:info This function in the LSP7 contract can be used as a prevention mechanism
148
+ * against double spending allowance vulnerability.
149
+ *
150
+ * @notice Increase the allowance of `operator` by +`addedAmount`
151
+ *
152
+ * @dev Atomically increases the allowance granted to `operator` by the caller.
153
+ * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
154
+ * for the double spending allowance problem.
155
+ * Notify the operator based on the LSP1-UniversalReceiver standard
156
+ *
157
+ * @param operator The operator to increase the allowance for `msg.sender`
158
+ * @param addedAmount The additional amount to add on top of the current operator's allowance
159
+ *
160
+ * @custom:requirements
161
+ * - `operator` cannot be the same address as `msg.sender`
162
+ * - `operator` cannot be the zero address.
163
+ *
164
+ * @custom:events {OperatorAuthorizationChanged} indicating the updated allowance
165
+ */
166
+ function increaseAllowance(
167
+ address operator,
168
+ uint256 addedAmount,
169
+ bytes memory operatorNotificationData
170
+ ) external;
171
+
172
+ /**
173
+ * @custom:info This function in the LSP7 contract can be used as a prevention mechanism
174
+ * against the double spending allowance vulnerability.
175
+ *
176
+ * @notice Decrease the allowance of `operator` by -`subtractedAmount`
177
+ *
178
+ * @dev Atomically decreases the allowance granted to `operator` by the caller.
179
+ * This is an alternative approach to {authorizeOperator} that can be used as a mitigation
180
+ * for the double spending allowance problem.
181
+ * Notify the operator based on the LSP1-UniversalReceiver standard
182
+ *
183
+ * @custom:events
184
+ * - {OperatorAuthorizationChanged} event indicating the updated allowance after decreasing it.
185
+ * - {OperatorRevoked} event if `subtractedAmount` is the full allowance,
186
+ * indicating `operator` does not have any alauthorizedAmountForlowance left for `msg.sender`.
187
+ *
188
+ * @param operator The operator to decrease allowance for `msg.sender`
189
+ * @param tokenOwner The address of the token owner.
190
+ * @param subtractedAmount The amount to decrease by in the operator's allowance.
191
+ *
192
+ * @custom:requirements
193
+ * - `operator` cannot be the zero address.
194
+ * - `operator` must have allowance for the caller of at least `subtractedAmount`.
195
+ */
196
+ function decreaseAllowance(
197
+ address operator,
198
+ address tokenOwner,
199
+ uint256 subtractedAmount,
200
+ bytes memory operatorNotificationData
201
+ ) external;
202
+
203
+ /**
204
+ * @dev Get the amount of tokens `operator` address has access to from `tokenOwner`.
205
+ * Operators can send and burn tokens on behalf of their owners.
206
+ *
207
+ * @param operator The operator's address to query the authorized amount for.
208
+ * @param tokenOwner The token owner that `operator` has allowance on.
209
+ *
210
+ * @return The amount of tokens the `operator`'s address has access on the `tokenOwner`'s balance.
211
+ *
212
+ * @custom:info If this function is called with the same address for `operator` and `tokenOwner`, it will simply read the `tokenOwner`'s balance
213
+ * (since a tokenOwner is its own operator).
214
+ */
215
+ function authorizedAmountFor(
216
+ address operator,
217
+ address tokenOwner
218
+ ) external view returns (uint256);
219
+
220
+ /**
221
+ * @dev Returns all `operator` addresses that are allowed to transfer or burn on behalf of `tokenOwner`.
222
+ *
223
+ * @param tokenOwner The token owner to get the operators for.
224
+ * @return An array of operators allowed to transfer or burn tokens on behalf of `tokenOwner`.
225
+ */
226
+ function getOperatorsOf(
227
+ address tokenOwner
228
+ ) external view returns (address[] memory);
229
+
230
+ // --- Transfer functionality
231
+
232
+ /**
233
+ * @dev Transfers an `amount` of tokens from the `from` address to the `to` address and notify both sender and recipients via the LSP1 {`universalReceiver(...)`} function.
234
+ * If the tokens are transferred by an operator on behalf of a token holder, the allowance for the operator will be decreased by `amount` once the token transfer
235
+ * has been completed (See {authorizedAmountFor}).
236
+ *
237
+ * @param from The sender address.
238
+ * @param to The recipient address.
239
+ * @param amount The amount of tokens to transfer.
240
+ * @param force When set to `true`, the `to` address CAN be any address. When set to `false`, the `to` address MUST be a contract that supports the LSP1 UniversalReceiver standard.
241
+ * @param data Any additional data the caller wants included in the emitted event, and sent in the hooks of the `from` and `to` addresses.
242
+ *
243
+ * @custom:requirements
244
+ * - `from` cannot be the zero address.
245
+ * - `to` cannot be the zero address.
246
+ * - `from` and `to` cannot be the same address (`from` cannot send tokens to itself).
247
+ * - `from` MUST have a balance of at least `amount` tokens.
248
+ * - If the caller is not `from`, it must be an operator for `from` with an allowance of at least `amount` of tokens.
249
+ *
250
+ * @custom:events
251
+ * - {Transfer} event when tokens get successfully transferred.
252
+ * - if the transfer is triggered by an operator, either the {OperatorAuthorizationChanged} event will be emitted with the updated allowance or the {OperatorRevoked}
253
+ * event will be emitted if the operator has no more allowance left.
254
+ *
255
+ * @custom:hint The `force` parameter **MUST be set to `true`** to transfer tokens to Externally Owned Accounts (EOAs)
256
+ * or contracts that do not implement the LSP1 Universal Receiver Standard. Otherwise the function will revert making the transfer fail.
257
+ *
258
+ * @custom:info if the `to` address is a contract that implements LSP1, it will always be notified via its `universalReceiver(...)` function, regardless if `force` is set to `true` or `false`.
259
+ *
260
+ * @custom:warning Be aware that when either the sender or the recipient can have logic that revert in their `universalReceiver(...)` function when being notified.
261
+ * This even if the `force` was set to `true`.
262
+ */
263
+ function transfer(
264
+ address from,
265
+ address to,
266
+ uint256 amount,
267
+ bool force,
268
+ bytes memory data
269
+ ) external;
270
+
271
+ /**
272
+ * @dev Same as {`transfer(...)`} but transfer multiple tokens based on the arrays of `from`, `to`, `amount`.
273
+ *
274
+ * @custom:info If any transfer in the batch fail or revert, the whole call will revert.
275
+ *
276
+ * @param from An array of sending addresses.
277
+ * @param to An array of receiving addresses.
278
+ * @param amount An array of amount of tokens to transfer for each `from -> to` transfer.
279
+ * @param force For each transfer, when set to `true`, the `to` address CAN be any address. When set to `false`, the `to` address MUST be a contract that supports the LSP1 UniversalReceiver standard.
280
+ * @param data An array of additional data the caller wants included in the emitted event, and sent in the hooks to `from` and `to` addresses.
281
+ *
282
+ * @custom:requirements
283
+ * - `from`, `to`, `amount` lists MUST be of the same length.
284
+ * - no values in `from` can be the zero address.
285
+ * - no values in `to` can be the zero address.
286
+ * - each `amount` tokens MUST be owned by `from`.
287
+ * - for each transfer, if the caller is not `from`, it MUST be an operator for `from` with access to at least `amount` tokens.
288
+ *
289
+ * @custom:events {Transfer} event **for each token transfer**.
290
+ */
291
+ function transferBatch(
292
+ address[] memory from,
293
+ address[] memory to,
294
+ uint256[] memory amount,
295
+ bool[] memory force,
296
+ bytes[] memory data
297
+ ) external;
298
+
299
+ /**
300
+ * @notice Executing the following batch of abi-encoded function calls on the contract: `data`.
301
+ *
302
+ * @dev Allows a caller to batch different function calls in one call. Perform a `delegatecall` on self, to call different functions with preserving the context.
303
+ * @param data An array of ABI encoded function calls to be called on the contract.
304
+ * @return results An array of abi-encoded data returned by the functions executed.
305
+ */
306
+ function batchCalls(
307
+ bytes[] calldata data
308
+ ) external returns (bytes[] memory results);
309
+ }
@@ -0,0 +1,16 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.4;
3
+
4
+ // --- ERC165 interface ids
5
+ bytes4 constant _INTERFACEID_LSP7 = 0xc52d6008;
6
+
7
+ // --- Token Hooks
8
+
9
+ // keccak256('LSP7Tokens_SenderNotification')
10
+ bytes32 constant _TYPEID_LSP7_TOKENSSENDER = 0x429ac7a06903dbc9c13dfcb3c9d11df8194581fa047c96d7a4171fc7402958ea;
11
+
12
+ // keccak256('LSP7Tokens_RecipientNotification')
13
+ bytes32 constant _TYPEID_LSP7_TOKENSRECIPIENT = 0x20804611b3e2ea21c480dc465142210acf4a2485947541770ec1fb87dee4a55c;
14
+
15
+ // keccak256('LSP7Tokens_OperatorNotification')
16
+ bytes32 constant _TYPEID_LSP7_TOKENOPERATOR = 0x386072cc5a58e61263b434c722725f21031cd06e7c552cfaa06db5de8a320dbc;
@@ -0,0 +1,198 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.4;
3
+
4
+ // interfaces
5
+ import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
6
+
7
+ // modules
8
+ import {ERC725YCore} from "@erc725/smart-contracts/contracts/ERC725YCore.sol";
9
+ import {
10
+ LSP4DigitalAssetMetadata
11
+ } from "@lukso/lsp4-contracts/contracts/LSP4DigitalAssetMetadata.sol";
12
+ import {LSP7DigitalAssetCore} from "./LSP7DigitalAssetCore.sol";
13
+ import {
14
+ LSP17Extendable
15
+ } from "@lukso/lsp17contractextension-contracts/contracts/LSP17Extendable.sol";
16
+
17
+ // libraries
18
+ import {LSP2Utils} from "@lukso/lsp2-contracts/contracts/LSP2Utils.sol";
19
+
20
+ // constants
21
+ import {_INTERFACEID_LSP7} from "./LSP7Constants.sol";
22
+ import {LSP7TokenContractCannotHoldValue} from "./LSP7Errors.sol";
23
+
24
+ import {
25
+ _LSP17_EXTENSION_PREFIX
26
+ } from "@lukso/lsp17contractextension-contracts/contracts/LSP17Constants.sol";
27
+
28
+ // errors
29
+
30
+ import {
31
+ NoExtensionFoundForFunctionSelector,
32
+ InvalidFunctionSelector,
33
+ InvalidExtensionAddress
34
+ } from "@lukso/lsp17contractextension-contracts/contracts/LSP17Errors.sol";
35
+
36
+ /**
37
+ * @title Implementation of a LSP7 Digital Asset, a contract that represents a fungible token.
38
+ * @author Matthew Stevens
39
+ *
40
+ * @dev Minting and transferring are supplied with a `uint256` amount.
41
+ * This implementation is agnostic to the way tokens are created.
42
+ * A supply mechanism has to be added in a derived contract using {_mint}
43
+ * For a generic mechanism, see {LSP7Mintable}.
44
+ */
45
+ abstract contract LSP7DigitalAsset is
46
+ LSP4DigitalAssetMetadata,
47
+ LSP7DigitalAssetCore,
48
+ LSP17Extendable
49
+ {
50
+ /**
51
+ * @notice Sets the token-Metadata
52
+ * @param name_ The name of the token.
53
+ * @param symbol_ The symbol of the token.
54
+ * @param newOwner_ The owner of the the token-Metadata.
55
+ * @param lsp4TokenType_ The type of token this digital asset contract represents (`0` = Token, `1` = NFT, `2` = Collection).
56
+ * @param isNonDivisible_ Specify if the LSP7 token is a fungible or non-fungible token.
57
+ */
58
+ constructor(
59
+ string memory name_,
60
+ string memory symbol_,
61
+ address newOwner_,
62
+ uint256 lsp4TokenType_,
63
+ bool isNonDivisible_
64
+ ) LSP4DigitalAssetMetadata(name_, symbol_, newOwner_, lsp4TokenType_) {
65
+ _isNonDivisible = isNonDivisible_;
66
+ }
67
+
68
+ // fallback function
69
+
70
+ /**
71
+ * @notice The `fallback` function was called with the following amount of native tokens: `msg.value`; and the following calldata: `callData`.
72
+ *
73
+ * @dev Achieves the goal of [LSP-17-ContractExtension] standard by extending the contract to handle calls of functions that do not exist natively,
74
+ * forwarding the function call to the extension address mapped to the function being called.
75
+ *
76
+ * This function is executed when:
77
+ * - Sending data of length less than 4 bytes to the contract.
78
+ * - The first 4 bytes of the calldata do not match any publicly callable functions from the contract ABI.
79
+ * - Receiving native tokens
80
+ *
81
+ * 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)
82
+ *
83
+ * - 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.
84
+ *
85
+ * - 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.
86
+ *
87
+ * 2. If the data sent to this function is of length less than 4 bytes (not a function selector), revert.
88
+ */
89
+ // solhint-disable-next-line no-complex-fallback
90
+ fallback(
91
+ bytes calldata callData
92
+ ) external payable virtual returns (bytes memory) {
93
+ if (msg.data.length < 4) {
94
+ revert InvalidFunctionSelector(callData);
95
+ }
96
+ return _fallbackLSP17Extendable(callData);
97
+ }
98
+
99
+ /**
100
+ * @dev Reverts whenever someone tries to send native tokens to a LSP7 contract.
101
+ * @notice LSP7 contract cannot receive native tokens.
102
+ */
103
+ receive() external payable virtual {
104
+ // revert on empty calls with no value
105
+ if (msg.value == 0) {
106
+ revert InvalidFunctionSelector(hex"00000000");
107
+ }
108
+
109
+ revert LSP7TokenContractCannotHoldValue();
110
+ }
111
+
112
+ /**
113
+ * @dev Forwards the call with the received value to an extension mapped to a function selector.
114
+ *
115
+ * Calls {_getExtensionAndForwardValue} to get the address of the extension mapped to the function selector being
116
+ * called on the account. If there is no extension, the address(0) will be returned.
117
+ * Forwards the value if the extension is payable.
118
+ *
119
+ * Reverts if there is no extension for the function being called.
120
+ *
121
+ * If there is an extension for the function selector being called, it calls the extension with the
122
+ * CALL opcode, passing the {msg.data} appended with the 20 bytes of the {msg.sender} and
123
+ * 32 bytes of the {msg.value}
124
+ *
125
+ * @custom:info The LSP7 Token contract should not hold any native tokens. Any native tokens received by the contract
126
+ * will be forwarded to the extension address mapped to the selector from `msg.sig`.
127
+ */
128
+ function _fallbackLSP17Extendable(
129
+ bytes calldata callData
130
+ ) internal virtual override returns (bytes memory) {
131
+ // If there is a function selector
132
+ (address extension, ) = _getExtensionAndForwardValue(msg.sig);
133
+
134
+ // if no extension was found, revert
135
+ if (extension == address(0))
136
+ revert NoExtensionFoundForFunctionSelector(msg.sig);
137
+
138
+ (bool success, bytes memory result) = extension.call{value: msg.value}(
139
+ abi.encodePacked(callData, msg.sender, msg.value)
140
+ );
141
+
142
+ if (success) {
143
+ return result;
144
+ } else {
145
+ // `mload(result)` -> offset in memory where `result.length` is located
146
+ // `add(result, 32)` -> offset in memory where `result` data starts
147
+ /// @solidity memory-safe-assembly
148
+ // solhint-disable-next-line no-inline-assembly
149
+ assembly {
150
+ let resultdata_size := mload(result)
151
+ revert(add(result, 32), resultdata_size)
152
+ }
153
+ }
154
+ }
155
+
156
+ /**
157
+ * @dev Returns the extension address stored under the following data key:
158
+ * - {_LSP17_EXTENSION_PREFIX} + `<bytes4>` (Check [LSP2-ERC725YJSONSchema] for encoding the data key).
159
+ * - If no extension is stored, returns the address(0).
160
+ * - we do not check that payable bool as in lsp7 standard we will always forward the value to the extension
161
+ */
162
+ function _getExtensionAndForwardValue(
163
+ bytes4 functionSelector
164
+ ) internal view virtual override returns (address, bool) {
165
+ // Generate the data key relevant for the functionSelector being called
166
+ bytes32 mappedExtensionDataKey = LSP2Utils.generateMappingKey(
167
+ _LSP17_EXTENSION_PREFIX,
168
+ functionSelector
169
+ );
170
+
171
+ // Check if there is an extension stored under the generated data key
172
+ bytes memory extensionAddress = ERC725YCore._getData(
173
+ mappedExtensionDataKey
174
+ );
175
+ if (extensionAddress.length != 20 && extensionAddress.length != 0)
176
+ revert InvalidExtensionAddress(extensionAddress);
177
+
178
+ return (address(bytes20(extensionAddress)), true);
179
+ }
180
+
181
+ /**
182
+ * @inheritdoc IERC165
183
+ */
184
+ function supportsInterface(
185
+ bytes4 interfaceId
186
+ )
187
+ public
188
+ view
189
+ virtual
190
+ override(IERC165, ERC725YCore, LSP17Extendable)
191
+ returns (bool)
192
+ {
193
+ return
194
+ interfaceId == _INTERFACEID_LSP7 ||
195
+ super.supportsInterface(interfaceId) ||
196
+ LSP17Extendable._supportsInterfaceInERC165Extension(interfaceId);
197
+ }
198
+ }