@lukso/lsp7-contracts 0.16.8 → 0.18.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 (82) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +100 -5
  3. package/artifacts/IAccessControlExtended.json +285 -0
  4. package/artifacts/ILSP7CappedBalance.json +27 -0
  5. package/artifacts/ILSP7CappedSupply.json +27 -0
  6. package/artifacts/ILSP7DigitalAsset.json +6 -3
  7. package/artifacts/ILSP7Mintable.json +62 -0
  8. package/artifacts/ILSP7NonTransferable.json +116 -0
  9. package/artifacts/ILSP7Revokable.json +112 -0
  10. package/artifacts/LSP7Burnable.json +7 -4
  11. package/artifacts/LSP7BurnableInitAbstract.json +7 -4
  12. package/artifacts/LSP7CappedBalanceAbstract.json +1159 -0
  13. package/artifacts/LSP7CappedBalanceInitAbstract.json +1167 -0
  14. package/artifacts/{LSP7CappedSupply.json → LSP7CappedSupplyAbstract.json} +8 -15
  15. package/artifacts/LSP7CappedSupplyInitAbstract.json +7 -14
  16. package/artifacts/LSP7CustomizableToken.json +1647 -0
  17. package/artifacts/LSP7CustomizableTokenInit.json +1644 -0
  18. package/artifacts/LSP7DigitalAsset.json +6 -3
  19. package/artifacts/LSP7DigitalAssetInitAbstract.json +6 -3
  20. package/artifacts/LSP7Mintable.json +376 -5
  21. package/artifacts/LSP7MintableAbstract.json +1186 -0
  22. package/artifacts/LSP7MintableInit.json +369 -5
  23. package/artifacts/LSP7MintableInitAbstract.json +1194 -0
  24. package/artifacts/LSP7NonTransferableAbstract.json +1242 -0
  25. package/artifacts/LSP7NonTransferableInitAbstract.json +1250 -0
  26. package/artifacts/LSP7RevokableAbstract.json +1223 -0
  27. package/artifacts/LSP7RevokableInitAbstract.json +1231 -0
  28. package/artifacts/LSP7Votes.json +66 -4
  29. package/artifacts/LSP7VotesInitAbstract.json +66 -4
  30. package/contracts/LSP7DigitalAsset.sol +56 -65
  31. package/contracts/LSP7DigitalAssetInitAbstract.sol +49 -71
  32. package/contracts/extensions/AccessControlExtended/AccessControlExtendedAbstract.sol +368 -0
  33. package/contracts/extensions/AccessControlExtended/AccessControlExtendedConstants.sol +13 -0
  34. package/contracts/extensions/AccessControlExtended/AccessControlExtendedErrors.sol +23 -0
  35. package/contracts/extensions/AccessControlExtended/AccessControlExtendedInitAbstract.sol +389 -0
  36. package/contracts/extensions/AccessControlExtended/IAccessControlExtended.sol +51 -0
  37. package/contracts/extensions/{LSP7Burnable.sol → LSP7Burnable/LSP7Burnable.sol} +2 -2
  38. package/contracts/extensions/{LSP7BurnableInitAbstract.sol → LSP7Burnable/LSP7BurnableInitAbstract.sol} +2 -4
  39. package/contracts/extensions/LSP7CappedBalance/ILSP7CappedBalance.sol +11 -0
  40. package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceAbstract.sol +129 -0
  41. package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceErrors.sol +10 -0
  42. package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceInitAbstract.sol +179 -0
  43. package/contracts/extensions/LSP7CappedSupply/ILSP7CappedSupply.sol +11 -0
  44. package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyAbstract.sol +56 -0
  45. package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyErrors.sol +6 -0
  46. package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyInitAbstract.sol +96 -0
  47. package/contracts/extensions/LSP7Mintable/ILSP7Mintable.sol +27 -0
  48. package/contracts/extensions/LSP7Mintable/LSP7MintableAbstract.sol +105 -0
  49. package/contracts/extensions/LSP7Mintable/LSP7MintableErrors.sol +5 -0
  50. package/contracts/extensions/LSP7Mintable/LSP7MintableInitAbstract.sol +156 -0
  51. package/contracts/extensions/LSP7NonTransferable/ILSP7NonTransferable.sol +54 -0
  52. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableAbstract.sol +192 -0
  53. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableErrors.sol +14 -0
  54. package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableInitAbstract.sol +249 -0
  55. package/contracts/extensions/LSP7Revokable/ILSP7Revokable.sol +37 -0
  56. package/contracts/extensions/LSP7Revokable/LSP7RevokableAbstract.sol +138 -0
  57. package/contracts/extensions/LSP7Revokable/LSP7RevokableErrors.sol +4 -0
  58. package/contracts/extensions/LSP7Revokable/LSP7RevokableInitAbstract.sol +191 -0
  59. package/contracts/extensions/{LSP7Votes.sol → LSP7Votes/LSP7Votes.sol} +37 -20
  60. package/contracts/extensions/LSP7Votes/LSP7VotesErrors.sol +24 -0
  61. package/contracts/extensions/{LSP7VotesInitAbstract.sol → LSP7Votes/LSP7VotesInitAbstract.sol} +37 -21
  62. package/contracts/presets/LSP7CustomizableToken.sol +262 -0
  63. package/contracts/presets/LSP7CustomizableTokenConstants.sol +32 -0
  64. package/contracts/presets/LSP7CustomizableTokenInit.sol +294 -0
  65. package/contracts/presets/LSP7Mintable.sol +14 -23
  66. package/contracts/presets/LSP7MintableInit.sol +16 -11
  67. package/dist/abi.cjs +7664 -59
  68. package/dist/abi.d.cts +11223 -277
  69. package/dist/abi.d.mts +11223 -277
  70. package/dist/abi.d.ts +11223 -277
  71. package/dist/abi.mjs +7648 -59
  72. package/dist/constants.cjs +21 -0
  73. package/dist/constants.d.cts +12 -1
  74. package/dist/constants.d.mts +12 -1
  75. package/dist/constants.d.ts +12 -1
  76. package/dist/constants.mjs +16 -1
  77. package/package.json +33 -9
  78. package/contracts/extensions/LSP7CappedSupply.sol +0 -83
  79. package/contracts/extensions/LSP7CappedSupplyInitAbstract.sol +0 -86
  80. package/contracts/presets/ILSP7Mintable.sol +0 -32
  81. package/contracts/presets/LSP7MintableInitAbstract.sol +0 -57
  82. /package/contracts/extensions/{LSP7VotesConstants.sol → LSP7Votes/LSP7VotesConstants.sol} +0 -0
@@ -0,0 +1,138 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ // modules
5
+ import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
6
+ import {LSP7DigitalAsset} from "../../LSP7DigitalAsset.sol";
7
+ import {
8
+ AccessControlExtendedAbstract
9
+ } from "../AccessControlExtended/AccessControlExtendedAbstract.sol";
10
+
11
+ // interfaces
12
+ import {ILSP7Revokable} from "./ILSP7Revokable.sol";
13
+
14
+ // errors
15
+ import {
16
+ AccessControlUnauthorizedAccount
17
+ } from "../AccessControlExtended/AccessControlExtendedErrors.sol";
18
+ import {LSP7RevokableFeatureDisabled} from "./LSP7RevokableErrors.sol";
19
+
20
+ /// @title LSP7RevokableAbstract
21
+ /// @dev Abstract contract implementing revokable functionality for LSP7 tokens.
22
+ /// Allows addresses with the `REVOKER_ROLE` to revoke tokens from any holder
23
+ /// back to the contract owner or any other address that also has revoke rights.
24
+ ///
25
+ /// Use cases include:
26
+ /// - Memberships: Revoke membership tokens when they expire or are terminated
27
+ /// - Role badges: Remove role badges from community members
28
+ /// - Compliance: Freeze or reverse tokens for regulatory requirements
29
+ /// - Vesting: Revoke unvested tokens if conditions are not met
30
+ abstract contract LSP7RevokableAbstract is
31
+ ILSP7Revokable,
32
+ LSP7DigitalAsset,
33
+ AccessControlExtendedAbstract
34
+ {
35
+ bool internal _isRevokable;
36
+
37
+ /// @dev keccak256("REVOKER_ROLE")
38
+ bytes32 public constant REVOKER_ROLE =
39
+ 0xce3f34913921da558f105cefb578d87278debbbd073a8d552b5de0d168deee30;
40
+
41
+ constructor(bool isRevokable_) {
42
+ _isRevokable = isRevokable_;
43
+
44
+ if (isRevokable_) {
45
+ _grantRole(REVOKER_ROLE, owner());
46
+ }
47
+ }
48
+
49
+ /// @inheritdoc ILSP7Revokable
50
+ function isRevokable() public view virtual override returns (bool) {
51
+ return _isRevokable;
52
+ }
53
+
54
+ /// @inheritdoc ILSP7Revokable
55
+ /// @custom:warning Once this function is called, any address holding the `REVOKER_ROLE` will be inoperable.
56
+ /// @custom:info The list of addresses holding the `REVOKER_ROLE` remains populated after the revokable feature is switched off.
57
+ function disableRevokable() public virtual override onlyOwner {
58
+ require(isRevokable(), LSP7RevokableFeatureDisabled());
59
+ _isRevokable = false;
60
+ emit RevokableStatusChanged({enabled: false});
61
+ }
62
+
63
+ /// @inheritdoc ILSP7Revokable
64
+ function revoke(
65
+ address from,
66
+ address to,
67
+ uint256 amount,
68
+ bytes memory data
69
+ ) public virtual override onlyRole(REVOKER_ROLE) {
70
+ require(isRevokable(), LSP7RevokableFeatureDisabled());
71
+ require(
72
+ to == owner() || hasRole(REVOKER_ROLE, to),
73
+ AccessControlUnauthorizedAccount(to, REVOKER_ROLE)
74
+ );
75
+
76
+ emit TokenRevoked({
77
+ revoker: msg.sender,
78
+ from: from,
79
+ to: to,
80
+ amount: amount,
81
+ data: data
82
+ });
83
+
84
+ // We assume revokers are trusted when specifying revocation destinations.
85
+ // Therefore, we bypass LSP1 receiver checks.
86
+ _transfer({
87
+ from: from,
88
+ to: to,
89
+ amount: amount,
90
+ force: true,
91
+ data: data
92
+ });
93
+ }
94
+
95
+ function supportsInterface(
96
+ bytes4 interfaceId
97
+ )
98
+ public
99
+ view
100
+ virtual
101
+ override(AccessControlExtendedAbstract, LSP7DigitalAsset)
102
+ returns (bool)
103
+ {
104
+ return
105
+ AccessControlExtendedAbstract.supportsInterface(interfaceId) ||
106
+ LSP7DigitalAsset.supportsInterface(interfaceId);
107
+ }
108
+
109
+ /// @dev Overridden function to ensure previous revokers do not persist after contract ownership has been transferred.
110
+ /// The only exception is if the old contract owner had the `REVOKER_ROLE`. This role will be given to the new owner.
111
+ ///
112
+ /// @custom:warning This function clears the entire `REVOKER_ROLE` member set.
113
+ /// - Gas cost scales linearly with the number of addresses with the `REVOKER_ROLE`.
114
+ /// - If the number of addresses with the `REVOKER_ROLE` is large, it might consume a lot of gas,
115
+ /// leading the transaction to approach or exceed the block gas limit and fail.
116
+ /// Consider revoking addresses with the `REVOKER_ROLE` in batches in separate transactions to mitigate this.
117
+ function _transferOwnership(
118
+ address newOwner
119
+ ) internal virtual override(AccessControlExtendedAbstract, Ownable) {
120
+ // restore default admin hierarchy so a previously-installed custom admin
121
+ // cannot grant REVOKER_ROLE to new accounts post-transfer
122
+ _setRoleAdmin(REVOKER_ROLE, DEFAULT_ADMIN_ROLE);
123
+
124
+ // Transfer all roles from old owner to new owner first (including the `REVOKER_ROLE`)
125
+ // before clearing the list of revokers.
126
+ super._transferOwnership(newOwner);
127
+
128
+ address[] memory revokers = getRoleMembers(REVOKER_ROLE);
129
+
130
+ for (uint256 ii = 0; ii < revokers.length; ++ii) {
131
+ // Exclude the new owner from the list of revokers to delete.
132
+ address revoker = revokers[ii];
133
+ if (revoker == newOwner) continue;
134
+
135
+ _revokeRole(REVOKER_ROLE, revoker);
136
+ }
137
+ }
138
+ }
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ error LSP7RevokableFeatureDisabled();
@@ -0,0 +1,191 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
+
4
+ // modules
5
+ import {
6
+ OwnableUpgradeable
7
+ } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
8
+ import {
9
+ LSP7DigitalAssetInitAbstract
10
+ } from "../../LSP7DigitalAssetInitAbstract.sol";
11
+ import {
12
+ AccessControlExtendedInitAbstract
13
+ } from "../AccessControlExtended/AccessControlExtendedInitAbstract.sol";
14
+
15
+ // interfaces
16
+ import {ILSP7Revokable} from "./ILSP7Revokable.sol";
17
+
18
+ // errors
19
+ import {
20
+ AccessControlUnauthorizedAccount
21
+ } from "../AccessControlExtended/AccessControlExtendedErrors.sol";
22
+ import {LSP7RevokableFeatureDisabled} from "./LSP7RevokableErrors.sol";
23
+
24
+ /// @title LSP7RevokableInitAbstract
25
+ /// @dev Abstract contract implementing revokable functionality for LSP7 tokens (initializer version).
26
+ /// Allows addresses with the `REVOKER_ROLE` to revoke tokens from any holder
27
+ /// back to the contract owner or any other address that also has revoke rights.
28
+ ///
29
+ /// This version is for proxy deployments using the initializer pattern.
30
+ ///
31
+ /// Use cases include:
32
+ /// - Memberships: Revoke membership tokens when they expire or are terminated
33
+ /// - Role badges: Remove role badges from community members
34
+ /// - Compliance: Freeze or reverse tokens for regulatory requirements
35
+ /// - Vesting: Revoke unvested tokens if conditions are not met
36
+ abstract contract LSP7RevokableInitAbstract is
37
+ ILSP7Revokable,
38
+ LSP7DigitalAssetInitAbstract,
39
+ AccessControlExtendedInitAbstract
40
+ {
41
+ bool internal _isRevokable;
42
+
43
+ /// @dev keccak256("REVOKER_ROLE")
44
+ bytes32 public constant REVOKER_ROLE =
45
+ 0xce3f34913921da558f105cefb578d87278debbbd073a8d552b5de0d168deee30;
46
+
47
+ /// @notice Initializes the LSP7Revokable contract with base token params.
48
+ /// @dev Initializes the LSP7DigitalAsset base contract.
49
+ /// @param name_ The name of the token.
50
+ /// @param symbol_ The symbol of the token.
51
+ /// @param newOwner_ The owner of the contract (implicitly a revoker).
52
+ /// @param lsp4TokenType_ The token type (see LSP4).
53
+ /// @param isNonDivisible_ Whether the token is non-divisible.
54
+ /// @param isRevokable_ Whether token revocation is enabled.
55
+ function __LSP7Revokable_init(
56
+ string memory name_,
57
+ string memory symbol_,
58
+ address newOwner_,
59
+ uint256 lsp4TokenType_,
60
+ bool isNonDivisible_,
61
+ bool isRevokable_
62
+ ) internal virtual onlyInitializing {
63
+ LSP7DigitalAssetInitAbstract._initialize(
64
+ name_,
65
+ symbol_,
66
+ newOwner_,
67
+ lsp4TokenType_,
68
+ isNonDivisible_
69
+ );
70
+ __AccessControlExtended_init();
71
+ __LSP7Revokable_init_unchained(isRevokable_);
72
+ }
73
+
74
+ /// @notice Unchained initializer for LSP7Revokable.
75
+ function __LSP7Revokable_init_unchained(
76
+ bool isRevokable_
77
+ ) internal virtual onlyInitializing {
78
+ _isRevokable = isRevokable_;
79
+
80
+ if (isRevokable_) {
81
+ _grantRole(REVOKER_ROLE, owner());
82
+ }
83
+ }
84
+
85
+ /// @inheritdoc ILSP7Revokable
86
+ function isRevokable() public view virtual override returns (bool) {
87
+ return _isRevokable;
88
+ }
89
+
90
+ /// @inheritdoc ILSP7Revokable
91
+ /// @custom:warning Once this function is called, any address holding the `REVOKER_ROLE` will be inoperable.
92
+ /// @custom:info The list of addresses holding the `REVOKER_ROLE` remains populated after the revokable feature is switched off.
93
+ function disableRevokable() public virtual override onlyOwner {
94
+ require(isRevokable(), LSP7RevokableFeatureDisabled());
95
+ _isRevokable = false;
96
+ emit RevokableStatusChanged({enabled: false});
97
+ }
98
+
99
+ /// @inheritdoc ILSP7Revokable
100
+ function revoke(
101
+ address from,
102
+ address to,
103
+ uint256 amount,
104
+ bytes memory data
105
+ ) public virtual override onlyRole(REVOKER_ROLE) {
106
+ require(isRevokable(), LSP7RevokableFeatureDisabled());
107
+ require(
108
+ to == owner() || hasRole(REVOKER_ROLE, to),
109
+ AccessControlUnauthorizedAccount(to, REVOKER_ROLE)
110
+ );
111
+
112
+ emit TokenRevoked({
113
+ revoker: msg.sender,
114
+ from: from,
115
+ to: to,
116
+ amount: amount,
117
+ data: data
118
+ });
119
+
120
+ // We assume revokers are trusted when specifying revocation destinations.
121
+ // Therefore, we bypass LSP1 receiver checks.
122
+ _transfer({
123
+ from: from,
124
+ to: to,
125
+ amount: amount,
126
+ force: true,
127
+ data: data
128
+ });
129
+ }
130
+
131
+ function supportsInterface(
132
+ bytes4 interfaceId
133
+ )
134
+ public
135
+ view
136
+ virtual
137
+ override(
138
+ AccessControlExtendedInitAbstract,
139
+ LSP7DigitalAssetInitAbstract
140
+ )
141
+ returns (bool)
142
+ {
143
+ return
144
+ AccessControlExtendedInitAbstract.supportsInterface(interfaceId) ||
145
+ LSP7DigitalAssetInitAbstract.supportsInterface(interfaceId);
146
+ }
147
+
148
+ /// @dev Overridden function to ensure previous revokers do not persist after contract ownership has been transferred.
149
+ /// The only exception is if the old contract owner had the `REVOKER_ROLE`. This role will be given to the new owner.
150
+ ///
151
+ /// @custom:warning This function clears the entire `REVOKER_ROLE` member set.
152
+ /// - Gas cost scales linearly with the number of addresses with the `REVOKER_ROLE`.
153
+ /// - If the number of addresses with the `REVOKER_ROLE` is large, it might consume a lot of gas,
154
+ /// leading the transaction to approach or exceed the block gas limit and fail.
155
+ /// Consider revoking addresses with the `REVOKER_ROLE` in batches in separate transactions to mitigate this.
156
+ function _transferOwnership(
157
+ address newOwner
158
+ )
159
+ internal
160
+ virtual
161
+ override(AccessControlExtendedInitAbstract, OwnableUpgradeable)
162
+ {
163
+ // restore default admin hierarchy so a previously-installed custom admin
164
+ // cannot grant REVOKER_ROLE to new accounts post-transfer
165
+ _setRoleAdmin(REVOKER_ROLE, DEFAULT_ADMIN_ROLE);
166
+
167
+ // Transfer all roles from old owner to new owner first (including the `REVOKER_ROLE`)
168
+ // before clearing the list of revokers.
169
+ super._transferOwnership(newOwner);
170
+
171
+ address[] memory revokers = getRoleMembers(REVOKER_ROLE);
172
+
173
+ for (uint256 ii = 0; ii < revokers.length; ++ii) {
174
+ // Exclude the new owner from the list of revokers to delete.
175
+ address revoker = revokers[ii];
176
+ if (revoker == newOwner) continue;
177
+
178
+ _revokeRole(REVOKER_ROLE, revoker);
179
+ }
180
+ }
181
+
182
+ /**
183
+ * @dev This empty reserved space is put in place to allow future versions to add new
184
+ * variables without shifting down storage in the inheritance chain.
185
+ * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
186
+ *
187
+ * @custom:info The size of the `__gap` array is calculated so that the amount of storage used by the contract
188
+ * always adds up to the same number (in this case 50 storage slots).
189
+ */
190
+ uint256[49] private __gap;
191
+ }
@@ -1,18 +1,34 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
3
 
4
- import {LSP7DigitalAsset} from "../LSP7DigitalAsset.sol";
4
+ // interfaces
5
+ import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
6
+
7
+ // modules
8
+ import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
9
+ import {LSP7DigitalAsset} from "../../LSP7DigitalAsset.sol";
10
+
11
+ // libraries
12
+ import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";
13
+ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
14
+ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
15
+ import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
16
+ import {LSP1Utils} from "@lukso/lsp1-contracts/contracts/LSP1Utils.sol";
17
+
18
+ // constants
5
19
  import {
6
20
  _TYPEID_LSP7_VOTESDELEGATOR,
7
21
  _TYPEID_LSP7_VOTESDELEGATEE
8
22
  } from "./LSP7VotesConstants.sol";
9
- import {LSP1Utils} from "@lukso/lsp1-contracts/contracts/LSP1Utils.sol";
10
- import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
11
- import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
12
- import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
13
- import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
14
- import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
15
- import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";
23
+
24
+ // errors
25
+ import {
26
+ LSP7VotesBrokenClockMode,
27
+ LSP7VotesFutureLookup,
28
+ LSP7VotesSignatureExpired,
29
+ LSP7VotesInvalidNonce,
30
+ LSP7VotesExceededSafeSupply
31
+ } from "./LSP7VotesErrors.sol";
16
32
 
17
33
  /**
18
34
  * @dev Extension of LSP7 to support Compound-like voting and delegation. This version is more generic than Compound's,
@@ -39,6 +55,7 @@ abstract contract LSP7Votes is LSP7DigitalAsset, EIP712, IERC5805 {
39
55
  }
40
56
 
41
57
  bytes32 internal constant _DELEGATION_TYPEHASH =
58
+ // solhint-disable-next-line gas-small-strings
42
59
  keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
43
60
 
44
61
  mapping(address => address) private _delegates;
@@ -58,7 +75,7 @@ abstract contract LSP7Votes is LSP7DigitalAsset, EIP712, IERC5805 {
58
75
  // solhint-disable-next-line func-name-mixedcase
59
76
  function CLOCK_MODE() public view virtual override returns (string memory) {
60
77
  // Check that the clock was not modified
61
- require(clock() == block.number, "LSP7Votes: broken clock mode");
78
+ require(clock() == block.number, LSP7VotesBrokenClockMode());
62
79
  return "mode=blocknumber&from=default";
63
80
  }
64
81
 
@@ -117,7 +134,7 @@ abstract contract LSP7Votes is LSP7DigitalAsset, EIP712, IERC5805 {
117
134
  address account,
118
135
  uint256 timepoint
119
136
  ) public view virtual override returns (uint256) {
120
- require(timepoint < clock(), "LSP7Votes: future lookup");
137
+ require(timepoint < clock(), LSP7VotesFutureLookup(timepoint));
121
138
  return _checkpointsLookup(_checkpoints[account], timepoint);
122
139
  }
123
140
 
@@ -131,7 +148,7 @@ abstract contract LSP7Votes is LSP7DigitalAsset, EIP712, IERC5805 {
131
148
  function getPastTotalSupply(
132
149
  uint256 timepoint
133
150
  ) public view virtual override returns (uint256) {
134
- require(timepoint < clock(), "LSP7Votes: future lookup");
151
+ require(timepoint < clock(), LSP7VotesFutureLookup(timepoint));
135
152
  return _checkpointsLookup(_totalSupplyCheckpoints, timepoint);
136
153
  }
137
154
 
@@ -201,7 +218,7 @@ abstract contract LSP7Votes is LSP7DigitalAsset, EIP712, IERC5805 {
201
218
  bytes32 s
202
219
  ) public virtual override {
203
220
  // solhint-disable-next-line not-rely-on-time
204
- require(block.timestamp <= expiry, "LSP7Votes: signature expired");
221
+ require(block.timestamp <= expiry, LSP7VotesSignatureExpired(expiry));
205
222
  address signer = ECDSA.recover(
206
223
  _hashTypedDataV4(
207
224
  keccak256(
@@ -212,7 +229,10 @@ abstract contract LSP7Votes is LSP7DigitalAsset, EIP712, IERC5805 {
212
229
  r,
213
230
  s
214
231
  );
215
- require(nonce == _useNonce(signer), "LSP7Votes: invalid nonce");
232
+ require(
233
+ nonce == _useNonce(signer),
234
+ LSP7VotesInvalidNonce(signer, nonce)
235
+ );
216
236
  _delegate(signer, delegatee);
217
237
  }
218
238
 
@@ -259,10 +279,7 @@ abstract contract LSP7Votes is LSP7DigitalAsset, EIP712, IERC5805 {
259
279
  if (from == address(0)) {
260
280
  uint256 supply = totalSupply();
261
281
  uint256 cap = _maxSupply();
262
- require(
263
- supply <= cap,
264
- "LSP7Votes: total supply risks overflowing votes"
265
- );
282
+ require(supply <= cap, LSP7VotesExceededSafeSupply(supply, cap));
266
283
  }
267
284
  _transferVotingUnits(from, to, value);
268
285
  }
@@ -355,7 +372,7 @@ abstract contract LSP7Votes is LSP7DigitalAsset, EIP712, IERC5805 {
355
372
 
356
373
  unchecked {
357
374
  Checkpoint memory oldCkpt = pos == 0
358
- ? Checkpoint(0, 0)
375
+ ? Checkpoint({fromBlock: 0, votes: 0})
359
376
  : _unsafeAccess(ckpts, pos - 1);
360
377
 
361
378
  oldWeight = oldCkpt.votes;
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ error LSP7VotesBrokenClockMode();
5
+
6
+ /**
7
+ * @dev Reverts when attempting to lookup a previous votes or total supply for a timepoint in the future.
8
+ */
9
+ error LSP7VotesFutureLookup(uint256 timepoint);
10
+
11
+ /**
12
+ * @dev Reverts when a signature is expired.
13
+ */
14
+ error LSP7VotesSignatureExpired(uint256 expiry);
15
+
16
+ /**
17
+ * @dev Reverts when the `nonce` for `signer` is invalid.
18
+ */
19
+ error LSP7VotesInvalidNonce(address signer, uint256 nonce);
20
+
21
+ /**
22
+ * @dev Reverts when the total supply of tokens is greater than the token supply cap.
23
+ */
24
+ error LSP7VotesExceededSafeSupply(uint256 supply, uint256 cap);
@@ -1,23 +1,38 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.27;
3
3
 
4
+ // interfaces
5
+ import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
6
+
7
+ // modules
8
+ import {
9
+ EIP712Upgradeable
10
+ } from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
4
11
  import {
5
12
  LSP7DigitalAssetInitAbstract
6
- } from "../LSP7DigitalAssetInitAbstract.sol";
13
+ } from "../../LSP7DigitalAssetInitAbstract.sol";
14
+
15
+ // libraries
16
+ import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";
17
+ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
18
+ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
19
+ import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
20
+ import {LSP1Utils} from "@lukso/lsp1-contracts/contracts/LSP1Utils.sol";
21
+
22
+ // constants
7
23
  import {
8
24
  _TYPEID_LSP7_VOTESDELEGATOR,
9
25
  _TYPEID_LSP7_VOTESDELEGATEE
10
26
  } from "./LSP7VotesConstants.sol";
11
27
 
12
- import {LSP1Utils} from "@lukso/lsp1-contracts/contracts/LSP1Utils.sol";
13
- import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
14
- import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
15
- import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
16
- import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
28
+ // errors
17
29
  import {
18
- EIP712Upgradeable
19
- } from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
20
- import {Counters} from "@openzeppelin/contracts/utils/Counters.sol";
30
+ LSP7VotesBrokenClockMode,
31
+ LSP7VotesFutureLookup,
32
+ LSP7VotesSignatureExpired,
33
+ LSP7VotesInvalidNonce,
34
+ LSP7VotesExceededSafeSupply
35
+ } from "./LSP7VotesErrors.sol";
21
36
 
22
37
  /**
23
38
  * @dev Extension of LSP7 to support Compound-like voting and delegation. This version is more generic than Compound's,
@@ -48,6 +63,7 @@ abstract contract LSP7VotesInitAbstract is
48
63
  }
49
64
 
50
65
  bytes32 internal constant _DELEGATION_TYPEHASH =
66
+ // solhint-disable-next-line gas-small-strings
51
67
  keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
52
68
 
53
69
  mapping(address => address) private _delegates;
@@ -85,7 +101,7 @@ abstract contract LSP7VotesInitAbstract is
85
101
  // solhint-disable-next-line func-name-mixedcase
86
102
  function CLOCK_MODE() public view virtual override returns (string memory) {
87
103
  // Check that the clock was not modified
88
- require(clock() == block.number, "LSP7Votes: broken clock mode");
104
+ require(clock() == block.number, LSP7VotesBrokenClockMode());
89
105
  return "mode=blocknumber&from=default";
90
106
  }
91
107
 
@@ -144,7 +160,7 @@ abstract contract LSP7VotesInitAbstract is
144
160
  address account,
145
161
  uint256 timepoint
146
162
  ) public view virtual override returns (uint256) {
147
- require(timepoint < clock(), "LSP7Votes: future lookup");
163
+ require(timepoint < clock(), LSP7VotesFutureLookup(timepoint));
148
164
  return _checkpointsLookup(_checkpoints[account], timepoint);
149
165
  }
150
166
 
@@ -158,7 +174,7 @@ abstract contract LSP7VotesInitAbstract is
158
174
  function getPastTotalSupply(
159
175
  uint256 timepoint
160
176
  ) public view virtual override returns (uint256) {
161
- require(timepoint < clock(), "LSP7Votes: future lookup");
177
+ require(timepoint < clock(), LSP7VotesFutureLookup(timepoint));
162
178
  return _checkpointsLookup(_totalSupplyCheckpoints, timepoint);
163
179
  }
164
180
 
@@ -228,7 +244,7 @@ abstract contract LSP7VotesInitAbstract is
228
244
  bytes32 s
229
245
  ) public virtual override {
230
246
  // solhint-disable-next-line not-rely-on-time
231
- require(block.timestamp <= expiry, "LSP7Votes: signature expired");
247
+ require(block.timestamp <= expiry, LSP7VotesSignatureExpired(expiry));
232
248
  address signer = ECDSA.recover(
233
249
  _hashTypedDataV4(
234
250
  keccak256(
@@ -239,7 +255,10 @@ abstract contract LSP7VotesInitAbstract is
239
255
  r,
240
256
  s
241
257
  );
242
- require(nonce == _useNonce(signer), "LSP7Votes: invalid nonce");
258
+ require(
259
+ nonce == _useNonce(signer),
260
+ LSP7VotesInvalidNonce(signer, nonce)
261
+ );
243
262
  _delegate(signer, delegatee);
244
263
  }
245
264
 
@@ -286,10 +305,7 @@ abstract contract LSP7VotesInitAbstract is
286
305
  if (from == address(0)) {
287
306
  uint256 supply = totalSupply();
288
307
  uint256 cap = _maxSupply();
289
- require(
290
- supply <= cap,
291
- "LSP7Votes: total supply risks overflowing votes"
292
- );
308
+ require(supply <= cap, LSP7VotesExceededSafeSupply(supply, cap));
293
309
  }
294
310
  _transferVotingUnits(from, to, value);
295
311
  }
@@ -382,7 +398,7 @@ abstract contract LSP7VotesInitAbstract is
382
398
 
383
399
  unchecked {
384
400
  Checkpoint memory oldCkpt = pos == 0
385
- ? Checkpoint(0, 0)
401
+ ? Checkpoint({fromBlock: 0, votes: 0})
386
402
  : _unsafeAccess(ckpts, pos - 1);
387
403
 
388
404
  oldWeight = oldCkpt.votes;