@lukso/lsp7-contracts 0.15.0 → 0.16.3

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 (39) hide show
  1. package/README.md +12 -2
  2. package/artifacts/ILSP7DigitalAsset.json +0 -112
  3. package/artifacts/LSP7Burnable.json +0 -11
  4. package/artifacts/LSP7BurnableInitAbstract.json +0 -16
  5. package/artifacts/LSP7CappedSupply.json +0 -11
  6. package/artifacts/LSP7CappedSupplyInitAbstract.json +0 -16
  7. package/artifacts/LSP7DigitalAsset.json +0 -11
  8. package/artifacts/LSP7DigitalAssetInitAbstract.json +0 -16
  9. package/artifacts/LSP7Mintable.json +2 -13
  10. package/artifacts/LSP7MintableInit.json +2 -13
  11. package/artifacts/LSP7Votes.json +1154 -0
  12. package/artifacts/LSP7VotesInitAbstract.json +1146 -0
  13. package/contracts/ILSP7DigitalAsset.sol +2 -9
  14. package/contracts/LSP7Constants.sol +10 -0
  15. package/contracts/LSP7DigitalAsset.sol +748 -27
  16. package/contracts/LSP7DigitalAssetInitAbstract.sol +752 -14
  17. package/contracts/extensions/LSP7CappedSupply.sol +1 -1
  18. package/contracts/extensions/LSP7CappedSupplyInitAbstract.sol +1 -1
  19. package/contracts/extensions/LSP7Votes.sol +416 -0
  20. package/contracts/extensions/LSP7VotesConstants.sol +8 -0
  21. package/contracts/extensions/LSP7VotesInitAbstract.sol +443 -0
  22. package/dist/index.cjs +5 -1
  23. package/dist/index.d.cts +5 -3
  24. package/dist/index.d.mts +5 -3
  25. package/dist/index.d.ts +5 -3
  26. package/dist/index.mjs +5 -1
  27. package/package.json +5 -6
  28. package/types/index.ts +3488 -1480
  29. package/contracts/LSP7DigitalAssetCore.sol +0 -744
  30. package/types/common.ts +0 -131
  31. package/types/contracts/ILSP7DigitalAsset.ts +0 -626
  32. package/types/contracts/LSP7DigitalAsset.ts +0 -698
  33. package/types/contracts/LSP7DigitalAssetInitAbstract.ts +0 -729
  34. package/types/contracts/extensions/LSP7Burnable.ts +0 -717
  35. package/types/contracts/extensions/LSP7BurnableInitAbstract.ts +0 -748
  36. package/types/contracts/extensions/LSP7CappedSupply.ts +0 -712
  37. package/types/contracts/extensions/LSP7CappedSupplyInitAbstract.ts +0 -743
  38. package/types/contracts/presets/LSP7Mintable.ts +0 -717
  39. package/types/contracts/presets/LSP7MintableInit.ts +0 -779
@@ -1,744 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- pragma solidity ^0.8.4;
3
-
4
- // interfaces
5
- import {
6
- ILSP1UniversalReceiver as ILSP1
7
- } from "@lukso/lsp1-contracts/contracts/ILSP1UniversalReceiver.sol";
8
- import {ILSP7DigitalAsset} from "./ILSP7DigitalAsset.sol";
9
-
10
- // modules
11
-
12
- // libraries
13
- import {
14
- EnumerableSet
15
- } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
16
- import {
17
- ERC165Checker
18
- } from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
19
- import {LSP1Utils} from "@lukso/lsp1-contracts/contracts/LSP1Utils.sol";
20
-
21
- // errors
22
- import {
23
- LSP7AmountExceedsAuthorizedAmount,
24
- LSP7InvalidTransferBatch,
25
- LSP7AmountExceedsBalance,
26
- LSP7DecreasedAllowanceBelowZero,
27
- LSP7CannotUseAddressZeroAsOperator,
28
- LSP7TokenOwnerCannotBeOperator,
29
- LSP7CannotSendWithAddressZero,
30
- LSP7NotifyTokenReceiverContractMissingLSP1Interface,
31
- LSP7NotifyTokenReceiverIsEOA,
32
- OperatorAllowanceCannotBeIncreasedFromZero,
33
- LSP7BatchCallFailed,
34
- LSP7RevokeOperatorNotAuthorized,
35
- LSP7DecreaseAllowanceNotAuthorized
36
- } from "./LSP7Errors.sol";
37
-
38
- // constants
39
- import {
40
- _INTERFACEID_LSP1
41
- } from "@lukso/lsp1-contracts/contracts/LSP1Constants.sol";
42
- import {
43
- _TYPEID_LSP7_TOKENOPERATOR,
44
- _TYPEID_LSP7_TOKENSSENDER,
45
- _TYPEID_LSP7_TOKENSRECIPIENT
46
- } from "./LSP7Constants.sol";
47
-
48
- /**
49
- * @title LSP7DigitalAsset contract
50
- * @author Matthew Stevens
51
- * @dev Core Implementation of a LSP7 compliant contract.
52
- *
53
- * This contract implement the core logic of the functions for the {ILSP7DigitalAsset} interface.
54
- */
55
- abstract contract LSP7DigitalAssetCore is ILSP7DigitalAsset {
56
- using EnumerableSet for EnumerableSet.AddressSet;
57
-
58
- // --- Storage
59
-
60
- bool internal _isNonDivisible;
61
-
62
- uint256 internal _existingTokens;
63
-
64
- // Mapping from `tokenOwner` to an `amount` of tokens
65
- mapping(address => uint256) internal _tokenOwnerBalances;
66
-
67
- // Mapping an `address` to its authorized operator addresses.
68
- mapping(address => EnumerableSet.AddressSet) internal _operators;
69
-
70
- // Mapping a `tokenOwner` to an `operator` to `amount` of tokens.
71
- mapping(address => mapping(address => uint256))
72
- internal _operatorAuthorizedAmount;
73
-
74
- // --- Token queries
75
-
76
- /**
77
- * @inheritdoc ILSP7DigitalAsset
78
- */
79
- function decimals() public view virtual override returns (uint8) {
80
- return _isNonDivisible ? 0 : 18;
81
- }
82
-
83
- /**
84
- * @inheritdoc ILSP7DigitalAsset
85
- */
86
- function totalSupply() public view virtual override returns (uint256) {
87
- return _existingTokens;
88
- }
89
-
90
- // --- Token owner queries
91
-
92
- /**
93
- * @inheritdoc ILSP7DigitalAsset
94
- */
95
- function balanceOf(
96
- address tokenOwner
97
- ) public view virtual override returns (uint256) {
98
- return _tokenOwnerBalances[tokenOwner];
99
- }
100
-
101
- // --- General functionality
102
-
103
- /**
104
- * @inheritdoc ILSP7DigitalAsset
105
- *
106
- * @custom:info It's not possible to send value along the functions call due to the use of `delegatecall`.
107
- */
108
- function batchCalls(
109
- bytes[] calldata data
110
- ) public virtual override returns (bytes[] memory results) {
111
- results = new bytes[](data.length);
112
- for (uint256 i; i < data.length; ) {
113
- (bool success, bytes memory result) = address(this).delegatecall(
114
- data[i]
115
- );
116
-
117
- if (!success) {
118
- // Look for revert reason and bubble it up if present
119
- if (result.length != 0) {
120
- // The easiest way to bubble the revert reason is using memory via assembly
121
- // solhint-disable no-inline-assembly
122
- /// @solidity memory-safe-assembly
123
- assembly {
124
- let returndata_size := mload(result)
125
- revert(add(32, result), returndata_size)
126
- }
127
- } else {
128
- revert LSP7BatchCallFailed({callIndex: i});
129
- }
130
- }
131
-
132
- results[i] = result;
133
-
134
- unchecked {
135
- ++i;
136
- }
137
- }
138
- }
139
-
140
- // --- Operator functionality
141
-
142
- /**
143
- * @inheritdoc ILSP7DigitalAsset
144
- *
145
- * @custom:danger To avoid front-running and Allowance Double-Spend Exploit when
146
- * increasing or decreasing the authorized amount of an operator, it is advised to
147
- * use the {increaseAllowance} and {decreaseAllowance} functions.
148
- *
149
- * For more information, see:
150
- * https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/
151
- */
152
- function authorizeOperator(
153
- address operator,
154
- uint256 amount,
155
- bytes memory operatorNotificationData
156
- ) public virtual override {
157
- _updateOperator(
158
- msg.sender,
159
- operator,
160
- amount,
161
- true,
162
- operatorNotificationData
163
- );
164
-
165
- bytes memory lsp1Data = abi.encode(
166
- msg.sender,
167
- amount,
168
- operatorNotificationData
169
- );
170
-
171
- _notifyTokenOperator(operator, lsp1Data);
172
- }
173
-
174
- /**
175
- * @inheritdoc ILSP7DigitalAsset
176
- */
177
- function revokeOperator(
178
- address operator,
179
- address tokenOwner,
180
- bool notify,
181
- bytes memory operatorNotificationData
182
- ) public virtual override {
183
- if (msg.sender != tokenOwner && msg.sender != operator) {
184
- revert LSP7RevokeOperatorNotAuthorized(
185
- msg.sender,
186
- tokenOwner,
187
- operator
188
- );
189
- }
190
-
191
- _updateOperator(
192
- tokenOwner,
193
- operator,
194
- 0,
195
- notify,
196
- operatorNotificationData
197
- );
198
-
199
- if (notify) {
200
- bytes memory lsp1Data = abi.encode(
201
- tokenOwner,
202
- 0,
203
- operatorNotificationData
204
- );
205
-
206
- _notifyTokenOperator(operator, lsp1Data);
207
- }
208
- }
209
-
210
- /**
211
- * @inheritdoc ILSP7DigitalAsset
212
- */
213
- function authorizedAmountFor(
214
- address operator,
215
- address tokenOwner
216
- ) public view virtual override returns (uint256) {
217
- if (tokenOwner == operator) {
218
- return _tokenOwnerBalances[tokenOwner];
219
- } else {
220
- return _operatorAuthorizedAmount[tokenOwner][operator];
221
- }
222
- }
223
-
224
- /**
225
- * @inheritdoc ILSP7DigitalAsset
226
- */
227
- function getOperatorsOf(
228
- address tokenOwner
229
- ) public view virtual override returns (address[] memory) {
230
- return _operators[tokenOwner].values();
231
- }
232
-
233
- /**
234
- * @inheritdoc ILSP7DigitalAsset
235
- */
236
- function increaseAllowance(
237
- address operator,
238
- uint256 addedAmount,
239
- bytes memory operatorNotificationData
240
- ) public virtual override {
241
- uint256 oldAllowance = authorizedAmountFor(operator, msg.sender);
242
- if (oldAllowance == 0)
243
- revert OperatorAllowanceCannotBeIncreasedFromZero(operator);
244
-
245
- uint256 newAllowance = oldAllowance + addedAmount;
246
-
247
- _updateOperator(
248
- msg.sender,
249
- operator,
250
- newAllowance,
251
- true,
252
- operatorNotificationData
253
- );
254
-
255
- bytes memory lsp1Data = abi.encode(
256
- msg.sender,
257
- newAllowance,
258
- operatorNotificationData
259
- );
260
-
261
- _notifyTokenOperator(operator, lsp1Data);
262
- }
263
-
264
- /**
265
- * @inheritdoc ILSP7DigitalAsset
266
- */
267
- function decreaseAllowance(
268
- address operator,
269
- address tokenOwner,
270
- uint256 subtractedAmount,
271
- bytes memory operatorNotificationData
272
- ) public virtual override {
273
- if (msg.sender != tokenOwner && msg.sender != operator) {
274
- revert LSP7DecreaseAllowanceNotAuthorized(
275
- msg.sender,
276
- tokenOwner,
277
- operator
278
- );
279
- }
280
-
281
- uint256 currentAllowance = authorizedAmountFor(operator, tokenOwner);
282
- if (currentAllowance < subtractedAmount) {
283
- revert LSP7DecreasedAllowanceBelowZero();
284
- }
285
-
286
- uint256 newAllowance;
287
- unchecked {
288
- newAllowance = currentAllowance - subtractedAmount;
289
- _updateOperator(
290
- tokenOwner,
291
- operator,
292
- newAllowance,
293
- true,
294
- operatorNotificationData
295
- );
296
- }
297
-
298
- bytes memory lsp1Data = abi.encode(
299
- tokenOwner,
300
- newAllowance,
301
- operatorNotificationData
302
- );
303
-
304
- _notifyTokenOperator(operator, lsp1Data);
305
- }
306
-
307
- // --- Transfer functionality
308
-
309
- /**
310
- * @inheritdoc ILSP7DigitalAsset
311
- */
312
- function transfer(
313
- address from,
314
- address to,
315
- uint256 amount,
316
- bool force,
317
- bytes memory data
318
- ) public virtual override {
319
- if (msg.sender != from) {
320
- _spendAllowance({
321
- operator: msg.sender,
322
- tokenOwner: from,
323
- amountToSpend: amount
324
- });
325
- }
326
-
327
- _transfer(from, to, amount, force, data);
328
- }
329
-
330
- /**
331
- * @inheritdoc ILSP7DigitalAsset
332
- */
333
- function transferBatch(
334
- address[] memory from,
335
- address[] memory to,
336
- uint256[] memory amount,
337
- bool[] memory force,
338
- bytes[] memory data
339
- ) public virtual override {
340
- uint256 fromLength = from.length;
341
- if (
342
- fromLength != to.length ||
343
- fromLength != amount.length ||
344
- fromLength != force.length ||
345
- fromLength != data.length
346
- ) {
347
- revert LSP7InvalidTransferBatch();
348
- }
349
-
350
- for (uint256 i; i < fromLength; ) {
351
- // using the public transfer function to handle updates to operator authorized amounts
352
- transfer(from[i], to[i], amount[i], force[i], data[i]);
353
-
354
- unchecked {
355
- ++i;
356
- }
357
- }
358
- }
359
-
360
- /**
361
- * @dev Changes token `amount` the `operator` has access to from `tokenOwner` tokens.
362
- * If the amount is zero the operator is removed from the list of operators, otherwise he is added to the list of operators.
363
- * If the amount is zero then the operator is being revoked, otherwise the operator amount is being modified.
364
- *
365
- * @param tokenOwner The address that will give `operator` an allowance for on its balance.
366
- * @param operator The address to grant an allowance to spend.
367
- * @param allowance The maximum amount of token that `operator` can spend from the `tokenOwner`'s balance.
368
- * @param notified Boolean indicating whether the operator has been notified about the change of allowance
369
- * @param operatorNotificationData The data to send to the universalReceiver function of the operator in case of notifying
370
- *
371
- * @custom:events
372
- * - {OperatorRevoked} event when operator's allowance is set to `0`.
373
- * - {OperatorAuthorizationChanged} event when operator's allowance is set to any other amount.
374
- *
375
- * @custom:requirements
376
- * - `operator` cannot be the zero address.
377
- * - `operator` cannot be the same address as `tokenOwner`.
378
- */
379
- function _updateOperator(
380
- address tokenOwner,
381
- address operator,
382
- uint256 allowance,
383
- bool notified,
384
- bytes memory operatorNotificationData
385
- ) internal virtual {
386
- if (operator == address(0)) {
387
- revert LSP7CannotUseAddressZeroAsOperator();
388
- }
389
-
390
- if (operator == tokenOwner) {
391
- revert LSP7TokenOwnerCannotBeOperator();
392
- }
393
-
394
- _operatorAuthorizedAmount[tokenOwner][operator] = allowance;
395
-
396
- if (allowance != 0) {
397
- _operators[tokenOwner].add(operator);
398
- emit OperatorAuthorizationChanged(
399
- operator,
400
- tokenOwner,
401
- allowance,
402
- operatorNotificationData
403
- );
404
- } else {
405
- _operators[tokenOwner].remove(operator);
406
- emit OperatorRevoked(
407
- operator,
408
- tokenOwner,
409
- notified,
410
- operatorNotificationData
411
- );
412
- }
413
- }
414
-
415
- /**
416
- * @dev Mints `amount` of tokens and transfers it to `to`.
417
- *
418
- * @custom:info Any logic in the:
419
- * - {_beforeTokenTransfer} function will run before updating the balances.
420
- * - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the recipient via LSP1**.
421
- *
422
- * @param to The address to mint tokens for.
423
- * @param amount The amount of tokens to mint.
424
- * @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
425
- * @param data Additional data the caller wants included in the emitted {Transfer} event, and sent in the LSP1 hook to the `to` address.
426
- *
427
- * @custom:requirements
428
- * - `to` cannot be the zero address.
429
- *
430
- * @custom:events {Transfer} event with `address(0)` as `from`.
431
- */
432
- function _mint(
433
- address to,
434
- uint256 amount,
435
- bool force,
436
- bytes memory data
437
- ) internal virtual {
438
- if (to == address(0)) {
439
- revert LSP7CannotSendWithAddressZero();
440
- }
441
-
442
- _beforeTokenTransfer(address(0), to, amount, data);
443
-
444
- // tokens being minted
445
- _existingTokens += amount;
446
-
447
- _tokenOwnerBalances[to] += amount;
448
-
449
- emit Transfer({
450
- operator: msg.sender,
451
- from: address(0),
452
- to: to,
453
- amount: amount,
454
- force: force,
455
- data: data
456
- });
457
-
458
- _afterTokenTransfer(address(0), to, amount, data);
459
-
460
- bytes memory lsp1Data = abi.encode(
461
- msg.sender,
462
- address(0),
463
- to,
464
- amount,
465
- data
466
- );
467
- _notifyTokenReceiver(to, force, lsp1Data);
468
- }
469
-
470
- /**
471
- * @dev Burns (= destroys) `amount` of tokens, decrease the `from` balance. This is done by sending them to the zero address.
472
- *
473
- * Both the sender and recipient will be notified of the token transfer through the LSP1 {universalReceiver}
474
- * function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
475
- * all the parameters in the calldata packed encoded.
476
- *
477
- * @custom:info Any logic in the:
478
- * - {_beforeTokenTransfer} function will run before updating the balances.
479
- * - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender via LSP1**.
480
- *
481
- * @param from The address to burn tokens from its balance.
482
- * @param amount The amount of tokens to burn.
483
- * @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
484
- *
485
- * @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`.
486
- *
487
- * @custom:requirements
488
- * - `from` cannot be the zero address.
489
- * - `from` must have at least `amount` tokens.
490
- * - If the caller is not `from`, it must be an operator for `from` with access to at least
491
- * `amount` tokens.
492
- *
493
- * @custom:events {Transfer} event with `address(0)` as the `to` address
494
- */
495
- function _burn(
496
- address from,
497
- uint256 amount,
498
- bytes memory data
499
- ) internal virtual {
500
- if (from == address(0)) {
501
- revert LSP7CannotSendWithAddressZero();
502
- }
503
-
504
- _beforeTokenTransfer(from, address(0), amount, data);
505
-
506
- uint256 balance = _tokenOwnerBalances[from];
507
- if (amount > balance) {
508
- revert LSP7AmountExceedsBalance(balance, from, amount);
509
- }
510
- // tokens being burnt
511
- _existingTokens -= amount;
512
-
513
- _tokenOwnerBalances[from] -= amount;
514
-
515
- emit Transfer({
516
- operator: msg.sender,
517
- from: from,
518
- to: address(0),
519
- amount: amount,
520
- force: false,
521
- data: data
522
- });
523
-
524
- _afterTokenTransfer(from, address(0), amount, data);
525
-
526
- bytes memory lsp1Data = abi.encode(
527
- msg.sender,
528
- from,
529
- address(0),
530
- amount,
531
- data
532
- );
533
- _notifyTokenSender(from, lsp1Data);
534
- }
535
-
536
- /**
537
- * @dev Spend `amountToSpend` from the `operator`'s authorized on behalf of the `tokenOwner`.
538
- *
539
- * @param operator The address of the operator to decrease the allowance of.
540
- * @param tokenOwner The address that granted an allowance on its balance to `operator`.
541
- * @param amountToSpend The amount of tokens to substract in allowance of `operator`.
542
- *
543
- * @custom:events
544
- * - {OperatorRevoked} event when operator's allowance is set to `0`.
545
- * - {OperatorAuthorizationChanged} event when operator's allowance is set to any other amount.
546
- *
547
- * @custom:requirements
548
- * - The `amountToSpend` MUST be at least the allowance granted to `operator` (accessible via {`authorizedAmountFor}`)
549
- * - `operator` cannot be the zero address.
550
- * - `operator` cannot be the same address as `tokenOwner`.
551
- */
552
- function _spendAllowance(
553
- address operator,
554
- address tokenOwner,
555
- uint256 amountToSpend
556
- ) internal virtual {
557
- uint256 authorizedAmount = _operatorAuthorizedAmount[tokenOwner][
558
- operator
559
- ];
560
-
561
- if (amountToSpend > authorizedAmount) {
562
- revert LSP7AmountExceedsAuthorizedAmount(
563
- tokenOwner,
564
- authorizedAmount,
565
- operator,
566
- amountToSpend
567
- );
568
- }
569
-
570
- _updateOperator({
571
- tokenOwner: tokenOwner,
572
- operator: operator,
573
- allowance: authorizedAmount - amountToSpend,
574
- notified: false,
575
- operatorNotificationData: ""
576
- });
577
- }
578
-
579
- /**
580
- * @dev Transfer tokens from `from` to `to` by decreasing the balance of `from` by `-amount` and increasing the balance
581
- * of `to` by `+amount`.
582
- *
583
- * Both the sender and recipient will be notified of the token transfer through the LSP1 {universalReceiver}
584
- * function, if they are contracts that support the LSP1 interface. Their `universalReceiver` function will receive
585
- * all the parameters in the calldata packed encoded.
586
- *
587
- * @custom:info Any logic in the:
588
- * - {_beforeTokenTransfer} function will run before updating the balances.
589
- * - {_afterTokenTransfer} function will run after updating the balances, **but before notifying the sender/recipient via LSP1**.
590
- *
591
- * @param from The address to decrease the balance.
592
- * @param to The address to increase the balance.
593
- * @param amount The amount of tokens to transfer from `from` to `to`.
594
- * @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
595
- * @param data Additional data the caller wants included in the emitted event, and sent in the LSP1 hook to the `from` and `to` address.
596
- *
597
- * @custom:requirements
598
- * - `from` cannot be the zero address.
599
- * - `to` cannot be the zero address.
600
- * - `from` must have at least `amount` of tokens.
601
- *
602
- * @custom:events {Transfer} event.
603
- */
604
- function _transfer(
605
- address from,
606
- address to,
607
- uint256 amount,
608
- bool force,
609
- bytes memory data
610
- ) internal virtual {
611
- if (from == address(0) || to == address(0)) {
612
- revert LSP7CannotSendWithAddressZero();
613
- }
614
-
615
- _beforeTokenTransfer(from, to, amount, data);
616
-
617
- uint256 balance = _tokenOwnerBalances[from];
618
- if (amount > balance) {
619
- revert LSP7AmountExceedsBalance(balance, from, amount);
620
- }
621
-
622
- _tokenOwnerBalances[from] -= amount;
623
- _tokenOwnerBalances[to] += amount;
624
-
625
- emit Transfer({
626
- operator: msg.sender,
627
- from: from,
628
- to: to,
629
- amount: amount,
630
- force: force,
631
- data: data
632
- });
633
-
634
- _afterTokenTransfer(from, to, amount, data);
635
-
636
- bytes memory lsp1Data = abi.encode(msg.sender, from, to, amount, data);
637
-
638
- _notifyTokenSender(from, lsp1Data);
639
- _notifyTokenReceiver(to, force, lsp1Data);
640
- }
641
-
642
- /**
643
- * @dev Hook that is called before any token transfer, including minting and burning.
644
- * Allows to run custom logic before updating balances and notifiying sender/recipient by overriding this function.
645
- *
646
- * @param from The sender address
647
- * @param to The recipient address
648
- * @param amount The amount of token to transfer
649
- * @param data The data sent alongside the transfer
650
- */
651
- function _beforeTokenTransfer(
652
- address from,
653
- address to,
654
- uint256 amount,
655
- bytes memory data // solhint-disable-next-line no-empty-blocks
656
- ) internal virtual {}
657
-
658
- /**
659
- * @dev Hook that is called after any token transfer, including minting and burning.
660
- * Allows to run custom logic after updating balances, but **before notifiying sender/recipient** by overriding this function.
661
- *
662
- * @param from The sender address
663
- * @param to The recipient address
664
- * @param amount The amount of token to transfer
665
- * @param data The data sent alongside the transfer
666
- */
667
- function _afterTokenTransfer(
668
- address from,
669
- address to,
670
- uint256 amount,
671
- bytes memory data // solhint-disable-next-line no-empty-blocks
672
- ) internal virtual {}
673
-
674
- /**
675
- * @dev Attempt to notify the operator `operator` about the `amount` tokens being authorized with.
676
- * 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.
677
- * If `operator` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
678
-
679
- * @param operator The address to call the {universalReceiver} function on.
680
- * @param lsp1Data the data to be sent to the `operator` address in the `universalReceiver` call.
681
- */
682
- function _notifyTokenOperator(
683
- address operator,
684
- bytes memory lsp1Data
685
- ) internal virtual {
686
- LSP1Utils.notifyUniversalReceiver(
687
- operator,
688
- _TYPEID_LSP7_TOKENOPERATOR,
689
- lsp1Data
690
- );
691
- }
692
-
693
- /**
694
- * @dev Attempt to notify the token sender `from` about the `amount` of tokens being transferred.
695
- * 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.
696
- * If `from` is an EOA or a contract that does not support the LSP1 interface, nothing will happen and no notification will be sent.
697
-
698
- * @param from The address to call the {universalReceiver} function on.
699
- * @param lsp1Data the data to be sent to the `from` address in the `universalReceiver` call.
700
- */
701
- function _notifyTokenSender(
702
- address from,
703
- bytes memory lsp1Data
704
- ) internal virtual {
705
- LSP1Utils.notifyUniversalReceiver(
706
- from,
707
- _TYPEID_LSP7_TOKENSSENDER,
708
- lsp1Data
709
- );
710
- }
711
-
712
- /**
713
- * @dev Attempt to notify the token receiver `to` about the `amount` tokens being received.
714
- * 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.
715
- *
716
- * 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.
717
- * - if `force` is set to `true`, nothing will happen and no notification will be sent.
718
- * - if `force` is set to `false, the transaction will revert.
719
- *
720
- * @param to The address to call the {universalReceiver} function on.
721
- * @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
722
- * @param lsp1Data The data to be sent to the `to` address in the `universalReceiver(...)` call.
723
- */
724
- function _notifyTokenReceiver(
725
- address to,
726
- bool force,
727
- bytes memory lsp1Data
728
- ) internal virtual {
729
- if (
730
- ERC165Checker.supportsERC165InterfaceUnchecked(
731
- to,
732
- _INTERFACEID_LSP1
733
- )
734
- ) {
735
- ILSP1(to).universalReceiver(_TYPEID_LSP7_TOKENSRECIPIENT, lsp1Data);
736
- } else if (!force) {
737
- if (to.code.length != 0) {
738
- revert LSP7NotifyTokenReceiverContractMissingLSP1Interface(to);
739
- } else {
740
- revert LSP7NotifyTokenReceiverIsEOA(to);
741
- }
742
- }
743
- }
744
- }