-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStakingActivityChecker.sol
62 lines (55 loc) · 2.59 KB
/
StakingActivityChecker.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
// Multisig interface
interface IMultisig {
/// @dev Gets the multisig nonce.
/// @return Multisig nonce.
function nonce() external view returns (uint256);
}
/// @dev Zero value when it has to be different from zero.
error ZeroValue();
/// @title StakingActiveChecker - Smart contract for performing a service staking activity check
/// @author Aleksandr Kuperman - <aleksandr.kuperman@valory.xyz>
/// @author Andrey Lebedev - <andrey.lebedev@valory.xyz>
/// @author Mariapia Moscatiello - <mariapia.moscatiello@valory.xyz>
contract StakingActivityChecker {
// Liveness ratio in the format of 1e18
uint256 public immutable livenessRatio;
/// @dev StakingNativeToken initialization.
/// @param _livenessRatio Liveness ratio in the format of 1e18.
constructor(uint256 _livenessRatio) {
// Check for zero value
if (_livenessRatio == 0) {
revert ZeroValue();
}
livenessRatio = _livenessRatio;
}
/// @dev Gets service multisig nonces.
/// @param multisig Service multisig address.
/// @return nonces Set of a single service multisig nonce.
function getMultisigNonces(address multisig) external view virtual returns (uint256[] memory nonces) {
nonces = new uint256[](1);
nonces[0] = IMultisig(multisig).nonce();
}
/// @dev Checks if the service multisig liveness ratio passes the defined liveness threshold.
/// @notice The formula for calculating the ratio is the following:
/// currentNonce - service multisig nonce at time now (block.timestamp);
/// lastNonce - service multisig nonce at the previous checkpoint or staking time (tsStart);
/// ratio = (currentNonce - lastNonce) / (block.timestamp - tsStart).
/// @param curNonces Current service multisig set of a single nonce.
/// @param lastNonces Last service multisig set of a single nonce.
/// @param ts Time difference between current and last timestamps.
/// @return ratioPass True, if the liveness ratio passes the check.
function isRatioPass(
uint256[] memory curNonces,
uint256[] memory lastNonces,
uint256 ts
) external view virtual returns (bool ratioPass) {
// If the checkpoint was called in the exact same block, the ratio is zero
// If the current nonce is not greater than the last nonce, the ratio is zero
if (ts > 0 && curNonces[0] > lastNonces[0]) {
uint256 ratio = ((curNonces[0] - lastNonces[0]) * 1e18) / ts;
ratioPass = (ratio >= livenessRatio);
}
}
}