@lukso/lsp11-contracts 0.1.2

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.
@@ -0,0 +1,326 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.9;
3
+
4
+ /**
5
+ * @title ILSP11SocialRecovery
6
+ * @notice Contract providing a mechanism for account recovery through a designated set of guardians.
7
+ */
8
+ interface ILSP11SocialRecovery {
9
+ /**
10
+ * @notice Event emitted when a guardian is added for an account.
11
+ * @param account The account for which the guardian is being added.
12
+ * @param guardian The address of the new guardian being added.
13
+ */
14
+ event GuardianAdded(address indexed account, address indexed guardian);
15
+
16
+ /**
17
+ * @notice Event emitted when a guardian is removed for an account.
18
+ * @param account The account from which the guardian is being removed.
19
+ * @param guardian The address of the guardian being removed.
20
+ */
21
+ event GuardianRemoved(address indexed account, address indexed guardian);
22
+
23
+ /**
24
+ * @notice Event emitted when the guardian threshold for an account is changed.
25
+ * @param account The account for which the guardian threshold is being changed.
26
+ * @param guardianThreshold The new guardian threshold for the account.
27
+ */
28
+ event GuardiansThresholdChanged(
29
+ address indexed account,
30
+ uint256 indexed guardianThreshold
31
+ );
32
+
33
+ /**
34
+ * @notice Event emitted when the secret hash associated with an account is changed.
35
+ * @param account The account for which the secret hash is being changed.
36
+ * @param secretHash The new secret hash for the account.
37
+ */
38
+ event SecretHashChanged(
39
+ address indexed account,
40
+ bytes32 indexed secretHash
41
+ );
42
+
43
+ /**
44
+ * @notice Event emitted when the recovery delay associated with an account is changed.
45
+ * @param account The account for which the recovery delay is being changed.
46
+ * @param recoveryDelay The new recovery delay for the account in seconds.
47
+ */
48
+ event RecoveryDelayChanged(
49
+ address indexed account,
50
+ uint256 indexed recoveryDelay
51
+ );
52
+
53
+ /**
54
+ * @notice Event emitted when a guardian votes for an address to be recovered.
55
+ * @param account The account for which the vote is being cast.
56
+ * @param recoveryCounter The recovery counter at the time of voting.
57
+ * @param guardian The guardian casting the vote.
58
+ * @param guardianVotedAddress The address voted by the guardian for recovery.
59
+ */
60
+ event GuardianVotedFor(
61
+ address indexed account,
62
+ uint256 recoveryCounter,
63
+ address indexed guardian,
64
+ address indexed guardianVotedAddress
65
+ );
66
+
67
+ /**
68
+ * @notice Event emitted when a recovery process is cancelled for an account.
69
+ * @param account The account for which the recovery process was cancelled.
70
+ * @param previousRecoveryCounter The recovery counter before cancellation.
71
+ */
72
+ event RecoveryCancelled(
73
+ address indexed account,
74
+ uint256 indexed previousRecoveryCounter
75
+ );
76
+
77
+ /**
78
+ * @notice Event emitted when an address commits a secret hash to recover an account.
79
+ * @param account The account for which the secret hash is being committed.
80
+ * @param recoveryCounter The recovery counter at the time of the commitment.
81
+ * @param committedBy The address who made the commitment.
82
+ * @param commitment The commitment associated with the secret hash.
83
+ */
84
+ event SecretHashCommitted(
85
+ address indexed account,
86
+ uint256 recoveryCounter,
87
+ address indexed committedBy,
88
+ bytes32 indexed commitment
89
+ );
90
+
91
+ /**
92
+ * @notice Event emitted when a recovery process is successful for an account.
93
+ * @param account The account for which the recovery process was successful.
94
+ * @param recoveryCounter The recovery counter at the time of successful recovery.
95
+ * @param guardianVotedAddress The address voted by guardians for the successful recovery.
96
+ * @param calldataExecuted The calldata executed on the account recovered.
97
+ */
98
+ event RecoveryProcessSuccessful(
99
+ address indexed account,
100
+ uint256 indexed recoveryCounter,
101
+ address indexed guardianVotedAddress,
102
+ bytes calldataExecuted
103
+ );
104
+
105
+ /**
106
+ * @notice Get the array of addresses representing guardians associated with an account.
107
+ * @param account The account for which guardians are queried.
108
+ * @return An array of addresses representing guardians for the given account.
109
+ */
110
+ function getGuardiansOf(
111
+ address account
112
+ ) external view returns (address[] memory);
113
+
114
+ /**
115
+ * @notice Check if an address is a guardian for a specific account.
116
+ * @param account The account to check for guardian status.
117
+ * @param guardianAddress The address to verify if it's a guardian for the given account..
118
+ * @return A boolean indicating whether the address is a guardian for the given account.
119
+ */
120
+ function isGuardianOf(
121
+ address account,
122
+ address guardianAddress
123
+ ) external view returns (bool);
124
+
125
+ /**
126
+ * @notice Get the guardian threshold for a specific account.
127
+ * @param account The account for which the guardian threshold is queried.
128
+ * @return The guardian threshold set for the given account.
129
+ */
130
+ function getGuardiansThresholdOf(
131
+ address account
132
+ ) external view returns (uint256);
133
+
134
+ /**
135
+ * @notice Get the secret hash associated with a specific account.
136
+ * @param account The account for which the secret hash is queried.
137
+ * @return The secret hash associated with the given account.
138
+ */
139
+ function getSecretHashOf(address account) external view returns (bytes32);
140
+
141
+ /**
142
+ * @notice Get the recovery delay associated with a specific account.
143
+ * @param account The account for which the recovery delay is queried.
144
+ * @return The recovery delay associated with the given account.
145
+ */
146
+ function getRecoveryDelayOf(
147
+ address account
148
+ ) external view returns (uint256);
149
+
150
+ /**
151
+ * @notice Get the successful recovery counter for a specific account.
152
+ * @param account The account for which the recovery counter is queried.
153
+ * @return The successful recovery counter for the given account.
154
+ */
155
+ function getRecoveryCounterOf(
156
+ address account
157
+ ) external view returns (uint256);
158
+
159
+ /**
160
+ * @notice Get the timestamp of the first recovery timestamp of the vote for a specific account and recovery counter.
161
+ * @param account The account for which the vote is queried.
162
+ * @param recoveryCounter The recovery counter for which the vote is queried.
163
+ * @return The timestamp of the first recovery timestamp of the vote for a specific account and recovery counter.
164
+ */
165
+ function getFirstRecoveryTimestampOf(
166
+ address account,
167
+ uint256 recoveryCounter
168
+ ) external view returns (uint256);
169
+
170
+ /**
171
+ * @notice Get the address voted for recovery by a guardian for a specific account and recovery counter.
172
+ * @param account The account for which the vote is queried.
173
+ * @param recoveryCounter The recovery counter for which the vote is queried.
174
+ * @param guardian The guardian whose vote is queried.
175
+ * @return The address voted for recovery by the specified guardian for the given account and recovery counter.
176
+ */
177
+ function getVotedAddressByGuardian(
178
+ address account,
179
+ uint256 recoveryCounter,
180
+ address guardian
181
+ ) external view returns (address);
182
+
183
+ /**
184
+ * @notice Get the number of votes an address has received from guardians for a specific account and recovery counter.
185
+ * @param account The account for which the votes are queried.
186
+ * @param recoveryCounter The recovery counter for which the votes are queried.
187
+ * @param votedAddress The address for which the votes are queried.
188
+ * @return The number of votes the specified address has received from guardians for the given account and recovery counter.
189
+ */
190
+ function getVotesOfGuardianVotedAddress(
191
+ address account,
192
+ uint256 recoveryCounter,
193
+ address votedAddress
194
+ ) external view returns (uint256);
195
+
196
+ /**
197
+ * @notice Checks if the votes received by a given address from guardians have reached the threshold necessary for account recovery.
198
+ * @param account The account for which the threshold check is performed.
199
+ * @param recoveryCounter The recovery counter for which the threshold check is performed.
200
+ * @param votedAddress The address for which the votes are counted.
201
+ * @return A boolean indicating whether the votes for the specified address have reached the necessary threshold for the given account and recovery counter.
202
+ * @dev This function evaluates if the number of votes from guardians for a specific voted address meets or exceeds the required threshold for account recovery.
203
+ * This is part of the account recovery process where guardians vote for the legitimacy of a recovery address.
204
+ */
205
+ function hasReachedThreshold(
206
+ address account,
207
+ uint256 recoveryCounter,
208
+ address votedAddress
209
+ ) external view returns (bool);
210
+
211
+ /**
212
+ * @notice Get the commitment associated with an address for recovery for a specific account and recovery counter.
213
+ * @param account The account for which the commitment is queried.
214
+ * @param recoveryCounter The recovery counter for which the commitment is queried.
215
+ * @param committedBy The address who made the commitment.
216
+ * @return The commitment associated with the specified address for recovery for the given account and recovery counter.
217
+ */
218
+ function getCommitmentInfoOf(
219
+ address account,
220
+ uint256 recoveryCounter,
221
+ address committedBy
222
+ ) external view returns (bytes32, uint256);
223
+
224
+ /**
225
+ * @notice Adds a new guardian to the calling account.
226
+ * @param newGuardian The address of the new guardian to be added.
227
+ * @dev This function allows the account holder to add a new guardian to their account.
228
+ * If the provided address is already a guardian for the account, the function will revert.
229
+ * Emits a `GuardianAdded` event upon successful addition of the guardian.
230
+ */
231
+ function addGuardian(address account, address newGuardian) external;
232
+
233
+ /**
234
+ * @notice Removes an existing guardian from the calling account.
235
+ * @param existingGuardian The address of the existing guardian to be removed.
236
+ * @dev This function allows the account holder to remove an existing guardian from their account.
237
+ * If the provided address is not a current guardian or the removal would violate the guardian threshold, the function will revert.
238
+ * Emits a `GuardianRemoved` event upon successful removal of the guardian.
239
+ */
240
+ function removeGuardian(address account, address existingGuardian) external;
241
+
242
+ /**
243
+ * @notice Sets the guardian threshold for the calling account.
244
+ * @param newThreshold The new guardian threshold to be set for the calling account.
245
+ * @dev This function allows the account holder to set the guardian threshold for their account.
246
+ * If the provided threshold exceeds the number of current guardians, the function will revert.
247
+ * Emits a `GuardiansThresholdChanged` event upon successful threshold modification.
248
+ */
249
+ function setGuardiansThreshold(
250
+ address account,
251
+ uint256 newThreshold
252
+ ) external;
253
+
254
+ /**
255
+ * @notice Sets the recovery secret hash for the calling account.
256
+ * @param newRecoverSecretHash The new recovery secret hash to be set for the calling account.
257
+ * @dev This function allows the account holder to set a new recovery secret hash for their account.
258
+ * If the provided secret hash is zero, the function will revert.
259
+ * Emits a `SecretHashChanged` event upon successful secret hash modification.
260
+ */
261
+ function setRecoverySecretHash(
262
+ address account,
263
+ bytes32 newRecoverSecretHash
264
+ ) external;
265
+
266
+ /**
267
+ * @notice Sets the recovery delay for the calling account.
268
+ * @param account The address of the account to which the recovery delay will be set.
269
+ * @param recoveryDelay The new recovery delay to be set for the calling account.
270
+ * @dev This function allows the account to set a new recovery delay for their account.
271
+ * Emits a `RecoveryDelayChanged` event upon successful secret hash modification.
272
+ */
273
+ function setRecoveryDelay(address account, uint256 recoveryDelay) external;
274
+
275
+ /**
276
+ * @notice Allows a guardian to vote for an address to be recovered.
277
+ * @param account The account for which the vote is being cast.
278
+ * @param guardianVotedAddress The address voted by the guardian for recovery.
279
+ * @dev This function allows a guardian to vote for an address to be recovered in a recovery process.
280
+ * If the guardian has already voted for the provided address, the function will revert.
281
+ * Emits a `GuardianVotedFor` event upon successful vote.
282
+ */
283
+ function voteForRecovery(
284
+ address account,
285
+ address guardian,
286
+ address guardianVotedAddress
287
+ ) external;
288
+
289
+ /**
290
+ * @notice Commits a secret hash for an address to be recovered.
291
+ * @param account The account for which the secret hash is being committed.
292
+ * @param commitment The commitment associated with the secret hash.
293
+ * @dev This function allows an address to commit a secret hash for the recovery process.
294
+ * If the guardian has not voted for the provided address, the function will revert.
295
+ */
296
+ function commitToRecover(
297
+ address account,
298
+ address votedAddress,
299
+ bytes32 commitment
300
+ ) external;
301
+
302
+ /**
303
+ * @notice Initiates the account recovery process.
304
+ * @param account The account for which the recovery is being initiated.
305
+ * @param secretHash The hash associated with the recovery process.
306
+ * @param newSecretHash The new secret hash to be set for the account.
307
+ * @param calldataToExecute The calldata to be executed during the recovery process.
308
+ * @dev This function initiates the account recovery process and executes the provided calldata.
309
+ * If the new secret hash is zero or the number of votes is less than the guardian threshold, the function will revert.
310
+ * Emits a `RecoveryProcessSuccessful` event upon successful recovery process.
311
+ */
312
+ function recoverAccess(
313
+ address votedAddress,
314
+ address account,
315
+ bytes32 secretHash,
316
+ bytes32 newSecretHash,
317
+ bytes calldata calldataToExecute
318
+ ) external payable returns (bytes memory);
319
+
320
+ /**
321
+ * @notice Cancels the ongoing recovery process for the account by increasing the recovery counter.
322
+ * @dev This function allows the account holder to cancel the ongoing recovery process by incrementing the recovery counter.
323
+ * Emits a `RecoveryCancelled` event upon successful cancellation of the recovery process.
324
+ */
325
+ function cancelRecoveryProcess(address account) external;
326
+ }
@@ -0,0 +1,8 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.9;
3
+
4
+ // --- ERC165 interface ids
5
+ bytes4 constant _INTERFACEID_LSP11 = 0x23a45ef0;
6
+
7
+ // version number used to validate signed relayed call
8
+ uint256 constant LSP11_VERSION = 11;
@@ -0,0 +1,181 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.9;
3
+
4
+ /**
5
+ * @dev The guardian address already exists for the account.
6
+ * @param account The account trying to add the guardian.
7
+ * @param guardian The guardian address that already exists.
8
+ */
9
+ error GuardianAlreadyExists(address account, address guardian);
10
+
11
+ /**
12
+ * @dev The specified guardian address does not exist for the account.
13
+ * @param account The account trying to remove the guardian.
14
+ * @param guardian The guardian address that was not found.
15
+ */
16
+ error GuardianNotFound(address account, address guardian);
17
+
18
+ /**
19
+ * @dev The caller is not a guardian address provided.
20
+ * @param guardian Expected guardian address.
21
+ * @param caller Address of the caller.
22
+ */
23
+ error CallerIsNotGuardian(address guardian, address caller);
24
+
25
+ /**
26
+ * @dev The caller is not the account holder.
27
+ * @param account The expected account holder.
28
+ * @param caller Address of the caller.
29
+ */
30
+ error CallerIsNotTheAccount(address account, address caller);
31
+
32
+ /**
33
+ * @dev One or more batch calls failed.
34
+ * @param iteration The iteration at which the batch call failed.
35
+ */
36
+ error BatchCallsFailed(uint256 iteration);
37
+
38
+ /**
39
+ * @dev The caller is not the expected recoverer.
40
+ * @param votedAddress Expected voted address.
41
+ * @param caller Address of the caller.
42
+ */
43
+ error CallerIsNotVotedAddress(address votedAddress, address caller);
44
+
45
+ /**
46
+ * @dev The specified threshold exceeds the number of guardians.
47
+ * @param account The account trying to set the threshold.
48
+ * @param threshold The threshold value that exceeds the number of guardians.
49
+ */
50
+ error ThresholdExceedsGuardianNumber(address account, uint256 threshold);
51
+
52
+ /**
53
+ * @dev Removing the guardian would violate the guardian threshold.
54
+ * @param account The account trying to remove the guardian.
55
+ * @param threshold The guardian address that would cause a threshold violation if removed.
56
+ */
57
+ error GuardianNumberCannotGoBelowThreshold(address account, uint256 threshold);
58
+
59
+ /**
60
+ * @dev The secret guardian hash already exists for the account.
61
+ * @param account The account trying to add the secret guardian.
62
+ * @param secretGuardian The secret guardian hash that already exists.
63
+ */
64
+ error SecretGuardianAlreadyExists(address account, bytes32 secretGuardian);
65
+
66
+ /**
67
+ * @dev The specified secret guardian hash does not exist for the account.
68
+ * @param account The account trying to remove the secret guardian.
69
+ * @param secretGuardian The secret guardian hash that was not found.
70
+ */
71
+ error SecretGuardianNotFound(address account, bytes32 secretGuardian);
72
+
73
+ /**
74
+ * @dev Guardian is not authorized to vote for the account.
75
+ * @param account The account for which the vote is being cast.
76
+ * @param recoverer the caller
77
+ */
78
+ error CallerVotesHaveNotReachedThreshold(address account, address recoverer);
79
+
80
+ /**
81
+ * @dev The account has not been set up yet.
82
+ */
83
+ error AccountNotSetupYet();
84
+
85
+ /**
86
+ * @dev The address provided as a guardian is not registered as a guardian for the account.
87
+ * @param account The account in question.
88
+ * @param nonGuardian Address of a non-guardian .
89
+ */
90
+ error NotAGuardianOfTheAccount(address account, address nonGuardian);
91
+
92
+ /**
93
+ * @dev A guardian cannot vote for the same address twice.
94
+ * @param account The account for which the vote is being cast.
95
+ * @param guardian The guardian casting the vote.
96
+ * @param guardianVotedAddress The address voted by the guardian for recovery.
97
+ */
98
+ error CannotVoteToAddressTwice(
99
+ address account,
100
+ address guardian,
101
+ address guardianVotedAddress
102
+ );
103
+
104
+ /**
105
+ * @dev The voted address did not meet the recovery requirements.
106
+ * @param account The account for which recovery is being attempted.
107
+ * @param votedAddress The address that was voted for recovery.
108
+ */
109
+ error InvalidRecovery(address account, address votedAddress);
110
+
111
+ /**
112
+ * @dev The commitment provided is not valid.
113
+ * @param account The account for which the commitment is being checked.
114
+ * @param committer The address providing the commitment.
115
+ */
116
+ error InvalidCommitment(address account, address committer);
117
+
118
+ /**
119
+ * @dev The provided secret hash is not valid for recovery.
120
+ * @param account The account for which recovery is being attempted.
121
+ * @param secretHash The invalid secret hash provided.
122
+ */
123
+ error InvalidSecretHash(address account, bytes32 secretHash);
124
+
125
+ /**
126
+ * @dev The commitment provided is too early.
127
+ * @param account The account for which the commitment is being checked.
128
+ * @param committer The address providing the commitment.
129
+ */
130
+ error CannotRecoverAfterDirectCommit(address account, address committer);
131
+
132
+ /**
133
+ * @notice The relay call failed because an invalid nonce was provided for the address `signer` that signed the execute relay call.
134
+ * Invalid nonce: `invalidNonce`, signature of signer: `signature`.
135
+ *
136
+ * @dev Reverts when the `signer` address retrieved from the `signature` has an invalid nonce: `invalidNonce`.
137
+ *
138
+ * @param signer The address of the signer.
139
+ * @param invalidNonce The nonce retrieved for the `signer` address.
140
+ * @param signature The signature used to retrieve the `signer` address.
141
+ */
142
+ error InvalidRelayNonce(address signer, uint256 invalidNonce, bytes signature);
143
+
144
+ /**
145
+ * @dev Thrown when an attempt to recover is made before a specified delay period.
146
+ * @param account The account address.
147
+ * @param delay The delay of the account.
148
+ */
149
+ error CannotRecoverBeforeDelay(address account, uint256 delay);
150
+
151
+ /**
152
+ * @dev Thrown when the signer is not the voted address for a particular operation.
153
+ * @param votedAddress The address passed as a parameter as voted address.
154
+ * @param recoveredAddress The recovered address from the signature.
155
+ */
156
+ error SignerIsNotVotedAddress(address votedAddress, address recoveredAddress);
157
+
158
+ /**
159
+ * @dev Thrown when a relay call is not supported.
160
+ * @param functionSelector The unsupported function selector.
161
+ */
162
+ error RelayCallNotSupported(bytes4 functionSelector);
163
+
164
+ /**
165
+ * @dev Thrown when the total value sent in an LSP11 batch call is insufficient.
166
+ * @param totalValues The total value required.
167
+ * @param msgValue The value actually sent in the message.
168
+ */
169
+ error LSP11BatchInsufficientValueSent(uint256 totalValues, uint256 msgValue);
170
+
171
+ /**
172
+ * @dev Thrown when the total value sent in an LSP11 batch call exceeds the required amount.
173
+ * @param totalValues The total value required.
174
+ * @param msgValue The value actually sent in the message.
175
+ */
176
+ error LSP11BatchExcessiveValueSent(uint256 totalValues, uint256 msgValue);
177
+
178
+ /**
179
+ * @dev Thrown when there's a length mismatch in batch execute relay call parameters.
180
+ */
181
+ error BatchExecuteRelayCallParamsLengthMismatch();