@lukso/lsp8-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 (51) hide show
  1. package/README.md +49 -2
  2. package/contracts/ILSP8IdentifiableDigitalAsset.sol +2 -8
  3. package/contracts/LSP8Constants.sol +4 -0
  4. package/contracts/LSP8IdentifiableDigitalAsset.sol +796 -36
  5. package/contracts/LSP8IdentifiableDigitalAssetInitAbstract.sol +806 -36
  6. package/contracts/extensions/LSP8CappedSupply.sol +1 -1
  7. package/contracts/extensions/LSP8CappedSupplyInitAbstract.sol +1 -1
  8. package/contracts/extensions/LSP8Enumerable.sol +6 -5
  9. package/contracts/extensions/LSP8EnumerableInitAbstract.sol +5 -5
  10. package/contracts/extensions/LSP8Votes.sol +94 -0
  11. package/contracts/extensions/LSP8VotesConstants.sol +8 -0
  12. package/contracts/extensions/LSP8VotesInitAbstract.sol +116 -0
  13. package/dist/abi.cjs +6432 -0
  14. package/dist/abi.d.cts +9539 -0
  15. package/dist/abi.d.mts +9539 -0
  16. package/dist/abi.d.ts +9539 -0
  17. package/dist/abi.mjs +6418 -0
  18. package/dist/{index.cjs → constants.cjs} +5 -1
  19. package/dist/constants.d.cts +35 -0
  20. package/dist/constants.d.mts +35 -0
  21. package/dist/constants.d.ts +35 -0
  22. package/dist/{index.mjs → constants.mjs} +5 -1
  23. package/package.json +36 -29
  24. package/artifacts/ILSP8IdentifiableDigitalAsset.json +0 -602
  25. package/artifacts/LSP8Burnable.json +0 -954
  26. package/artifacts/LSP8BurnableInitAbstract.json +0 -967
  27. package/artifacts/LSP8CappedSupply.json +0 -959
  28. package/artifacts/LSP8CappedSupplyInitAbstract.json +0 -972
  29. package/artifacts/LSP8Enumerable.json +0 -955
  30. package/artifacts/LSP8EnumerableInitAbstract.json +0 -968
  31. package/artifacts/LSP8IdentifiableDigitalAsset.json +0 -936
  32. package/artifacts/LSP8IdentifiableDigitalAssetInitAbstract.json +0 -949
  33. package/artifacts/LSP8Mintable.json +0 -1006
  34. package/artifacts/LSP8MintableInit.json +0 -1026
  35. package/contracts/LSP8IdentifiableDigitalAssetCore.sol +0 -809
  36. package/dist/index.d.cts +0 -33
  37. package/dist/index.d.mts +0 -33
  38. package/dist/index.d.ts +0 -33
  39. package/types/common.ts +0 -131
  40. package/types/contracts/ILSP8IdentifiableDigitalAsset.ts +0 -706
  41. package/types/contracts/LSP8IdentifiableDigitalAsset.ts +0 -778
  42. package/types/contracts/LSP8IdentifiableDigitalAssetInitAbstract.ts +0 -813
  43. package/types/contracts/extensions/LSP8Burnable.ts +0 -797
  44. package/types/contracts/extensions/LSP8BurnableInitAbstract.ts +0 -829
  45. package/types/contracts/extensions/LSP8CappedSupply.ts +0 -792
  46. package/types/contracts/extensions/LSP8CappedSupplyInitAbstract.ts +0 -824
  47. package/types/contracts/extensions/LSP8Enumerable.ts +0 -790
  48. package/types/contracts/extensions/LSP8EnumerableInitAbstract.ts +0 -821
  49. package/types/contracts/presets/LSP8Mintable.ts +0 -797
  50. package/types/contracts/presets/LSP8MintableInit.ts +0 -860
  51. package/types/index.ts +0 -9738
@@ -51,7 +51,7 @@ abstract contract LSP8CappedSupply is LSP8IdentifiableDigitalAsset {
51
51
  * @notice The maximum supply amount of tokens allowed to exist is `_TOKEN_SUPPLY_CAP`.
52
52
  *
53
53
  * @dev Get the maximum number of tokens that can exist to circulate. Once {totalSupply} reaches
54
- * reaches {totalSuuplyCap}, it is not possible to mint more tokens.
54
+ * reaches {totalSupplyCap}, it is not possible to mint more tokens.
55
55
  *
56
56
  * @return The maximum number of tokens that can exist in the contract.
57
57
  */
@@ -54,7 +54,7 @@ abstract contract LSP8CappedSupplyInitAbstract is
54
54
  * @notice The maximum supply amount of tokens allowed to exist is `_tokenSupplyCap`.
55
55
  *
56
56
  * @dev Get the maximum number of tokens that can exist to circulate. Once {totalSupply} reaches
57
- * reaches {totalSuuplyCap}, it is not possible to mint more tokens.
57
+ * reaches {totalSupplyCap}, it is not possible to mint more tokens.
58
58
  *
59
59
  * @return The maximum number of tokens that can exist in the contract.
60
60
  */
@@ -3,8 +3,7 @@ pragma solidity ^0.8.12;
3
3
 
4
4
  // modules
5
5
  import {
6
- LSP8IdentifiableDigitalAsset,
7
- LSP8IdentifiableDigitalAssetCore
6
+ LSP8IdentifiableDigitalAsset
8
7
  } from "../LSP8IdentifiableDigitalAsset.sol";
9
8
 
10
9
  /**
@@ -31,19 +30,21 @@ abstract contract LSP8Enumerable is LSP8IdentifiableDigitalAsset {
31
30
  }
32
31
 
33
32
  /**
34
- * @inheritdoc LSP8IdentifiableDigitalAssetCore
33
+ * @inheritdoc LSP8IdentifiableDigitalAsset
35
34
  *
36
35
  * @param from The address sending the `tokenId` (`address(0)` when `tokenId` is being minted).
37
36
  * @param to The address receiving the `tokenId` (`address(0)` when `tokenId` is being burnt).
38
37
  * @param tokenId The bytes32 identifier of the token being transferred.
38
+ * @param force A boolean that describe if transfer to a `to` address that does not support LSP1 is allowed or not.
39
39
  * @param data The data sent alongside the the token transfer.
40
40
  */
41
41
  function _beforeTokenTransfer(
42
42
  address from,
43
43
  address to,
44
44
  bytes32 tokenId,
45
+ bool force,
45
46
  bytes memory data
46
- ) internal virtual override(LSP8IdentifiableDigitalAssetCore) {
47
+ ) internal virtual override {
47
48
  // `tokenId` being minted
48
49
  if (from == address(0)) {
49
50
  uint256 index = totalSupply();
@@ -64,6 +65,6 @@ abstract contract LSP8Enumerable is LSP8IdentifiableDigitalAsset {
64
65
  delete _tokenIndex[tokenId];
65
66
  }
66
67
 
67
- super._beforeTokenTransfer(from, to, tokenId, data);
68
+ super._beforeTokenTransfer(from, to, tokenId, force, data);
68
69
  }
69
70
  }
@@ -3,8 +3,7 @@ pragma solidity ^0.8.12;
3
3
 
4
4
  // modules
5
5
  import {
6
- LSP8IdentifiableDigitalAssetInitAbstract,
7
- LSP8IdentifiableDigitalAssetCore
6
+ LSP8IdentifiableDigitalAssetInitAbstract
8
7
  } from "../LSP8IdentifiableDigitalAssetInitAbstract.sol";
9
8
 
10
9
  /**
@@ -31,7 +30,7 @@ abstract contract LSP8EnumerableInitAbstract is
31
30
  }
32
31
 
33
32
  /**
34
- * @inheritdoc LSP8IdentifiableDigitalAssetCore
33
+ * @inheritdoc LSP8IdentifiableDigitalAssetInitAbstract
35
34
  *
36
35
  * @param from The address sending the `tokenId` (`address(0)` when `tokenId` is being minted).
37
36
  * @param to The address receiving the `tokenId` (`address(0)` when `tokenId` is being burnt).
@@ -42,8 +41,9 @@ abstract contract LSP8EnumerableInitAbstract is
42
41
  address from,
43
42
  address to,
44
43
  bytes32 tokenId,
44
+ bool force,
45
45
  bytes memory data
46
- ) internal virtual override(LSP8IdentifiableDigitalAssetCore) {
46
+ ) internal virtual override {
47
47
  if (from == address(0)) {
48
48
  uint256 index = totalSupply();
49
49
  _indexToken[index] = tokenId;
@@ -59,6 +59,6 @@ abstract contract LSP8EnumerableInitAbstract is
59
59
  delete _indexToken[lastIndex];
60
60
  delete _tokenIndex[tokenId];
61
61
  }
62
- super._beforeTokenTransfer(from, to, tokenId, data);
62
+ super._beforeTokenTransfer(from, to, tokenId, force, data);
63
63
  }
64
64
  }
@@ -0,0 +1,94 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.0;
4
+
5
+ import {
6
+ LSP8IdentifiableDigitalAsset
7
+ } from "../LSP8IdentifiableDigitalAsset.sol";
8
+ import {Votes} from "@openzeppelin/contracts/governance/utils/Votes.sol";
9
+ import {
10
+ _TYPEID_LSP8_VOTESDELEGATOR,
11
+ _TYPEID_LSP8_VOTESDELEGATEE
12
+ } from "./LSP8VotesConstants.sol";
13
+ import {LSP1Utils} from "@lukso/lsp1-contracts/contracts/LSP1Utils.sol";
14
+
15
+ /**
16
+ * @dev Extension of LSP8 to support voting and delegation as implemented by {Votes}, where each individual NFT counts
17
+ * as 1 vote unit.
18
+ *
19
+ * Tokens do not count as votes until they are delegated, because votes must be tracked which incurs an additional cost
20
+ * on every transfer. Token holders can either delegate to a trusted representative who will decide how to make use of
21
+ * the votes in governance decisions, or they can delegate to themselves to be their own representative.
22
+ */
23
+ abstract contract LSP8Votes is LSP8IdentifiableDigitalAsset, Votes {
24
+ /**
25
+ * @dev Adjusts votes when tokens are transferred.
26
+ *
27
+ * @custom:events {DelegateVotesChanged} event.
28
+ */
29
+ function _afterTokenTransfer(
30
+ address from,
31
+ address to,
32
+ bytes32 tokenId,
33
+ bool force,
34
+ bytes memory data
35
+ ) internal virtual override {
36
+ _transferVotingUnits(from, to, 1);
37
+ super._afterTokenTransfer(from, to, tokenId, force, data);
38
+ }
39
+
40
+ /**
41
+ * @dev Returns the balance of `account`.
42
+ *
43
+ * @custom:warning Overriding this function will likely result in incorrect vote tracking.
44
+ */
45
+ function _getVotingUnits(
46
+ address account
47
+ ) internal view virtual override returns (uint256) {
48
+ return balanceOf(account);
49
+ }
50
+
51
+ /**
52
+ * @dev Override of the {_delegate} function that includes notification via LSP1.
53
+ * The delegator and delegatee are both notified via their `universalReceiver(...)` function if they contracts implementing the LSP1 interface.
54
+ *
55
+ * @custom:events {DelegateChanged} event.
56
+ */
57
+ function _delegate(
58
+ address delegator,
59
+ address delegatee
60
+ ) internal virtual override {
61
+ uint256 delegatorBalance = balanceOf(delegator);
62
+
63
+ super._delegate(delegator, delegatee);
64
+
65
+ // Notify the delegator if it's not address(0)
66
+ if (delegator != address(0)) {
67
+ bytes memory delegatorNotificationData = abi.encode(
68
+ msg.sender,
69
+ delegatee,
70
+ delegatorBalance
71
+ );
72
+ LSP1Utils.notifyUniversalReceiver(
73
+ delegator,
74
+ _TYPEID_LSP8_VOTESDELEGATOR,
75
+ delegatorNotificationData
76
+ );
77
+ }
78
+
79
+ // Only notify the new delegatee if it's not address(0) and if there's actual voting power
80
+ if (delegatee != address(0) && delegatorBalance > 0) {
81
+ bytes memory delegateeNotificationData = abi.encode(
82
+ msg.sender,
83
+ delegator,
84
+ delegatorBalance
85
+ );
86
+
87
+ LSP1Utils.notifyUniversalReceiver(
88
+ delegatee,
89
+ _TYPEID_LSP8_VOTESDELEGATEE,
90
+ delegateeNotificationData
91
+ );
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,8 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.4;
3
+
4
+ // keccak256('LSP8Tokens_VotesDelegatorNotification')
5
+ bytes32 constant _TYPEID_LSP8_VOTESDELEGATOR = 0x2f6d3f668c2e57dbae4c255f2d9e0b69d47a8848d69a2251cce137529e34743e;
6
+
7
+ // keccak256('LSP8Tokens_VotesDelegateeNotification')
8
+ bytes32 constant _TYPEID_LSP8_VOTESDELEGATEE = 0x19419598f788eae88574bbb83ec563ad0cb43cd7ddbbc88857b2efa2d8faa8eb;
@@ -0,0 +1,116 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {
5
+ LSP8IdentifiableDigitalAssetInitAbstract
6
+ } from "../LSP8IdentifiableDigitalAssetInitAbstract.sol";
7
+ import {
8
+ VotesUpgradeable
9
+ } from "@openzeppelin/contracts-upgradeable/governance/utils/VotesUpgradeable.sol";
10
+ import {
11
+ _TYPEID_LSP8_VOTESDELEGATOR,
12
+ _TYPEID_LSP8_VOTESDELEGATEE
13
+ } from "./LSP8VotesConstants.sol";
14
+ import {LSP1Utils} from "@lukso/lsp1-contracts/contracts/LSP1Utils.sol";
15
+
16
+ /**
17
+ * @dev Extension of LSP8 to support voting and delegation as implemented by {Votes}, where each individual NFT counts
18
+ * as 1 vote unit.
19
+ *
20
+ * Tokens do not count as votes until they are delegated, because votes must be tracked which incurs an additional cost
21
+ * on every transfer. Token holders can either delegate to a trusted representative who will decide how to make use of
22
+ * the votes in governance decisions, or they can delegate to themselves to be their own representative.
23
+ */
24
+ abstract contract LSP8VotesInitAbstract is
25
+ LSP8IdentifiableDigitalAssetInitAbstract,
26
+ VotesUpgradeable
27
+ {
28
+ function _initialize(
29
+ string memory name_,
30
+ string memory symbol_,
31
+ address newOwner_,
32
+ uint256 tokenIdType_,
33
+ uint256 tokenIdFormat_,
34
+ string memory version_
35
+ ) internal virtual onlyInitializing {
36
+ LSP8IdentifiableDigitalAssetInitAbstract._initialize(
37
+ name_,
38
+ symbol_,
39
+ newOwner_,
40
+ tokenIdType_,
41
+ tokenIdFormat_
42
+ );
43
+ __EIP712_init(name_, version_);
44
+ }
45
+
46
+ /**
47
+ * @dev Adjusts votes when tokens are transferred.
48
+ *
49
+ * Emits a {IVotes-DelegateVotesChanged} event.
50
+ */
51
+ function _afterTokenTransfer(
52
+ address from,
53
+ address to,
54
+ bytes32 tokenId,
55
+ bool force,
56
+ bytes memory data
57
+ ) internal virtual override {
58
+ _transferVotingUnits(from, to, 1);
59
+ super._afterTokenTransfer(from, to, tokenId, force, data);
60
+ }
61
+
62
+ /**
63
+ * @dev Returns the balance of `account`.
64
+ *
65
+ * @custom:warning Overriding this function will likely result in incorrect vote tracking.
66
+ */
67
+ function _getVotingUnits(
68
+ address account
69
+ ) internal view virtual override returns (uint256) {
70
+ return balanceOf(account);
71
+ }
72
+
73
+ /**
74
+ * @dev Override of the {_delegate} function that includes notification via LSP1.
75
+ * The delegator and delegatee are both notified via their `universalReceiver(...)` function if they contracts implementing the LSP1 interface.
76
+ *
77
+ * @custom:events {DelegateChanged} event.
78
+ */
79
+ function _delegate(
80
+ address delegator,
81
+ address delegatee
82
+ ) internal virtual override {
83
+ uint256 delegatorBalance = balanceOf(delegator);
84
+
85
+ super._delegate(delegator, delegatee);
86
+
87
+ // Notify the delegator if it's not address(0)
88
+ if (delegator != address(0)) {
89
+ bytes memory delegatorNotificationData = abi.encode(
90
+ msg.sender,
91
+ delegatee,
92
+ delegatorBalance
93
+ );
94
+ LSP1Utils.notifyUniversalReceiver(
95
+ delegator,
96
+ _TYPEID_LSP8_VOTESDELEGATOR,
97
+ delegatorNotificationData
98
+ );
99
+ }
100
+
101
+ // Only notify the new delegatee if it's not address(0) and if there's actual voting power
102
+ if (delegatee != address(0) && delegatorBalance > 0) {
103
+ bytes memory delegateeNotificationData = abi.encode(
104
+ msg.sender,
105
+ delegator,
106
+ delegatorBalance
107
+ );
108
+
109
+ LSP1Utils.notifyUniversalReceiver(
110
+ delegatee,
111
+ _TYPEID_LSP8_VOTESDELEGATEE,
112
+ delegateeNotificationData
113
+ );
114
+ }
115
+ }
116
+ }