@lukso/lsp7-contracts 0.16.6 → 0.17.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.
- package/LICENSE +201 -0
- package/README.md +56 -6
- package/artifacts/IAccessControlExtended.json +285 -0
- package/artifacts/ILSP7CappedBalance.json +27 -0
- package/artifacts/ILSP7CappedSupply.json +27 -0
- package/artifacts/ILSP7DigitalAsset.json +6 -3
- package/artifacts/ILSP7Mintable.json +62 -0
- package/artifacts/ILSP7NonTransferable.json +110 -0
- package/artifacts/ILSP7Revokable.json +75 -0
- package/artifacts/LSP7Burnable.json +7 -4
- package/artifacts/LSP7BurnableInitAbstract.json +7 -4
- package/artifacts/LSP7CappedBalanceAbstract.json +1159 -0
- package/artifacts/LSP7CappedBalanceInitAbstract.json +1167 -0
- package/artifacts/{LSP7CappedSupply.json → LSP7CappedSupplyAbstract.json} +8 -15
- package/artifacts/LSP7CappedSupplyInitAbstract.json +7 -14
- package/artifacts/LSP7CustomizableToken.json +1604 -0
- package/artifacts/LSP7CustomizableTokenInit.json +1601 -0
- package/artifacts/LSP7DigitalAsset.json +6 -3
- package/artifacts/LSP7DigitalAssetInitAbstract.json +6 -3
- package/artifacts/LSP7Mintable.json +376 -5
- package/artifacts/LSP7MintableAbstract.json +1186 -0
- package/artifacts/LSP7MintableInit.json +369 -5
- package/artifacts/LSP7MintableInitAbstract.json +1194 -0
- package/artifacts/LSP7NonTransferableAbstract.json +1236 -0
- package/artifacts/LSP7NonTransferableInitAbstract.json +1244 -0
- package/artifacts/LSP7RevokableAbstract.json +1186 -0
- package/artifacts/LSP7RevokableInitAbstract.json +1194 -0
- package/artifacts/LSP7Votes.json +66 -4
- package/artifacts/LSP7VotesInitAbstract.json +66 -4
- package/contracts/LSP7DigitalAsset.sol +56 -65
- package/contracts/LSP7DigitalAssetInitAbstract.sol +49 -71
- package/contracts/extensions/AccessControlExtended/AccessControlExtendedAbstract.sol +368 -0
- package/contracts/extensions/AccessControlExtended/AccessControlExtendedConstants.sol +13 -0
- package/contracts/extensions/AccessControlExtended/AccessControlExtendedErrors.sol +23 -0
- package/contracts/extensions/AccessControlExtended/AccessControlExtendedInitAbstract.sol +389 -0
- package/contracts/extensions/AccessControlExtended/IAccessControlExtended.sol +51 -0
- package/contracts/extensions/{LSP7Burnable.sol → LSP7Burnable/LSP7Burnable.sol} +2 -2
- package/contracts/extensions/{LSP7BurnableInitAbstract.sol → LSP7Burnable/LSP7BurnableInitAbstract.sol} +2 -4
- package/contracts/extensions/LSP7CappedBalance/ILSP7CappedBalance.sol +11 -0
- package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceAbstract.sol +129 -0
- package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceErrors.sol +10 -0
- package/contracts/extensions/LSP7CappedBalance/LSP7CappedBalanceInitAbstract.sol +179 -0
- package/contracts/extensions/LSP7CappedSupply/ILSP7CappedSupply.sol +11 -0
- package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyAbstract.sol +56 -0
- package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyErrors.sol +6 -0
- package/contracts/extensions/LSP7CappedSupply/LSP7CappedSupplyInitAbstract.sol +96 -0
- package/contracts/extensions/LSP7Mintable/ILSP7Mintable.sol +27 -0
- package/contracts/extensions/LSP7Mintable/LSP7MintableAbstract.sol +105 -0
- package/contracts/extensions/LSP7Mintable/LSP7MintableErrors.sol +5 -0
- package/contracts/extensions/LSP7Mintable/LSP7MintableInitAbstract.sol +156 -0
- package/contracts/extensions/LSP7NonTransferable/ILSP7NonTransferable.sol +48 -0
- package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableAbstract.sol +183 -0
- package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableErrors.sol +14 -0
- package/contracts/extensions/LSP7NonTransferable/LSP7NonTransferableInitAbstract.sol +240 -0
- package/contracts/extensions/LSP7Revokable/ILSP7Revokable.sol +28 -0
- package/contracts/extensions/LSP7Revokable/LSP7RevokableAbstract.sol +130 -0
- package/contracts/extensions/LSP7Revokable/LSP7RevokableErrors.sol +4 -0
- package/contracts/extensions/LSP7Revokable/LSP7RevokableInitAbstract.sol +183 -0
- package/contracts/extensions/{LSP7Votes.sol → LSP7Votes/LSP7Votes.sol} +37 -20
- package/contracts/extensions/LSP7Votes/LSP7VotesErrors.sol +24 -0
- package/contracts/extensions/{LSP7VotesInitAbstract.sol → LSP7Votes/LSP7VotesInitAbstract.sol} +37 -21
- package/contracts/presets/LSP7CustomizableToken.sol +262 -0
- package/contracts/presets/LSP7CustomizableTokenConstants.sol +32 -0
- package/contracts/presets/LSP7CustomizableTokenInit.sol +294 -0
- package/contracts/presets/LSP7Mintable.sol +14 -23
- package/contracts/presets/LSP7MintableInit.sol +16 -11
- package/dist/abi.cjs +7519 -54
- package/dist/abi.d.cts +11109 -338
- package/dist/abi.d.mts +11109 -338
- package/dist/abi.d.ts +11109 -338
- package/dist/abi.mjs +7503 -54
- package/dist/constants.cjs +21 -0
- package/dist/constants.d.cts +12 -1
- package/dist/constants.d.mts +12 -1
- package/dist/constants.d.ts +12 -1
- package/dist/constants.mjs +16 -1
- package/package.json +39 -15
- package/contracts/extensions/LSP7CappedSupply.sol +0 -83
- package/contracts/extensions/LSP7CappedSupplyInitAbstract.sol +0 -86
- package/contracts/presets/ILSP7Mintable.sol +0 -32
- package/contracts/presets/LSP7MintableInitAbstract.sol +0 -57
- /package/contracts/extensions/{LSP7VotesConstants.sol → LSP7Votes/LSP7VotesConstants.sol} +0 -0
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
// We assume revokers are trusted when specifying revocation destinations.
|
|
113
|
+
// Therefore, we bypass LSP1 receiver checks.
|
|
114
|
+
_transfer({
|
|
115
|
+
from: from,
|
|
116
|
+
to: to,
|
|
117
|
+
amount: amount,
|
|
118
|
+
force: true,
|
|
119
|
+
data: data
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function supportsInterface(
|
|
124
|
+
bytes4 interfaceId
|
|
125
|
+
)
|
|
126
|
+
public
|
|
127
|
+
view
|
|
128
|
+
virtual
|
|
129
|
+
override(
|
|
130
|
+
AccessControlExtendedInitAbstract,
|
|
131
|
+
LSP7DigitalAssetInitAbstract
|
|
132
|
+
)
|
|
133
|
+
returns (bool)
|
|
134
|
+
{
|
|
135
|
+
return
|
|
136
|
+
AccessControlExtendedInitAbstract.supportsInterface(interfaceId) ||
|
|
137
|
+
LSP7DigitalAssetInitAbstract.supportsInterface(interfaceId);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// @dev Overridden function to ensure previous revokers do not persist after contract ownership has been transferred.
|
|
141
|
+
/// The only exception is if the old contract owner had the `REVOKER_ROLE`. This role will be given to the new owner.
|
|
142
|
+
///
|
|
143
|
+
/// @custom:warning This function clears the entire `REVOKER_ROLE` member set.
|
|
144
|
+
/// - Gas cost scales linearly with the number of addresses with the `REVOKER_ROLE`.
|
|
145
|
+
/// - If the number of addresses with the `REVOKER_ROLE` is large, it might consume a lot of gas,
|
|
146
|
+
/// leading the transaction to approach or exceed the block gas limit and fail.
|
|
147
|
+
/// Consider revoking addresses with the `REVOKER_ROLE` in batches in separate transactions to mitigate this.
|
|
148
|
+
function _transferOwnership(
|
|
149
|
+
address newOwner
|
|
150
|
+
)
|
|
151
|
+
internal
|
|
152
|
+
virtual
|
|
153
|
+
override(AccessControlExtendedInitAbstract, OwnableUpgradeable)
|
|
154
|
+
{
|
|
155
|
+
// restore default admin hierarchy so a previously-installed custom admin
|
|
156
|
+
// cannot grant REVOKER_ROLE to new accounts post-transfer
|
|
157
|
+
_setRoleAdmin(REVOKER_ROLE, DEFAULT_ADMIN_ROLE);
|
|
158
|
+
|
|
159
|
+
// Transfer all roles from old owner to new owner first (including the `REVOKER_ROLE`)
|
|
160
|
+
// before clearing the list of revokers.
|
|
161
|
+
super._transferOwnership(newOwner);
|
|
162
|
+
|
|
163
|
+
address[] memory revokers = getRoleMembers(REVOKER_ROLE);
|
|
164
|
+
|
|
165
|
+
for (uint256 ii = 0; ii < revokers.length; ++ii) {
|
|
166
|
+
// Exclude the new owner from the list of revokers to delete.
|
|
167
|
+
address revoker = revokers[ii];
|
|
168
|
+
if (revoker == newOwner) continue;
|
|
169
|
+
|
|
170
|
+
_revokeRole(REVOKER_ROLE, revoker);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @dev This empty reserved space is put in place to allow future versions to add new
|
|
176
|
+
* variables without shifting down storage in the inheritance chain.
|
|
177
|
+
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
178
|
+
*
|
|
179
|
+
* @custom:info The size of the `__gap` array is calculated so that the amount of storage used by the contract
|
|
180
|
+
* always adds up to the same number (in this case 50 storage slots).
|
|
181
|
+
*/
|
|
182
|
+
uint256[49] private __gap;
|
|
183
|
+
}
|
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
pragma solidity ^0.8.
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.27;
|
|
3
3
|
|
|
4
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,
|
|
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(),
|
|
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(),
|
|
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,
|
|
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(
|
|
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);
|
package/contracts/extensions/{LSP7VotesInitAbstract.sol → LSP7Votes/LSP7VotesInitAbstract.sol}
RENAMED
|
@@ -1,23 +1,38 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
pragma solidity ^0.8.
|
|
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 "
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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,
|
|
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(),
|
|
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(),
|
|
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,
|
|
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(
|
|
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;
|