Skip to content

Commit f94f4f1

Browse files
authored
feat: update initialize version for settlement
1 parent bbec69f commit f94f4f1

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

src/Settlement.sol

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ import {
1313
RewardsAlreadyDistributed,
1414
SubmissionIntervalNotElapsed
1515
} from "./libraries/Errors.sol";
16-
import {AccessControlEnumerable} from
17-
"@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
16+
import {
17+
AccessControlEnumerable
18+
} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
1819
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
1920
import {Multicall} from "@openzeppelin/contracts/utils/Multicall.sol";
21+
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
22+
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
2023

2124
contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnumerable {
22-
string public constant version = "2.1.0";
25+
using Math for uint256;
26+
using SafeCast for uint256;
27+
28+
string public constant version = "2.0.0";
2329

2430
/// @dev Duration of an epoch.
2531
uint256 public constant EPOCH_DURATION = 18 hours;
@@ -49,7 +55,8 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
4955
// distributed operation rewards for each epoch
5056
mapping(uint256 epoch => uint256 operationRewards) internal _distributedOperationRewards;
5157
// rewarded node addresses
52-
mapping(uint256 epoch => mapping(address nodeAddr => bool rewarded)) internal _rewardedAddresses;
58+
mapping(uint256 epoch => mapping(address nodeAddr => bool rewarded)) internal
59+
_rewardedAddresses;
5360

5461
modifier validEpoch(uint256 epoch) {
5562
if (epoch < _currentEpoch || epoch > _currentEpoch + 1) {
@@ -75,7 +82,7 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
7582
address oracleAccount,
7683
uint256 startTime,
7784
uint256 operationRewardsPercent
78-
) external override reinitializer(4) {
85+
) external override reinitializer(6) {
7986
if (staking != address(0)) {
8087
_staking = staking;
8188
}
@@ -89,7 +96,9 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
8996
_startTimestamp = startTime;
9097
}
9198

92-
_updateRewardsRatio(operationRewardsPercent);
99+
if (operationRewardsPercent > 0) {
100+
_updateRewardsRatio(operationRewardsPercent);
101+
}
93102
}
94103

95104
/// @inheritdoc ISettlement
@@ -112,7 +121,10 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
112121
IStaking(_staking).setSettlementPhase(!isFinal);
113122

114123
// distribute rewards
115-
IStaking(_staking).distributeRewards{value: data.rewardsToSend}(
124+
IStaking(_staking)
125+
.distributeRewards{
126+
value: data.rewardsToSend
127+
}(
116128
data.epochInfo,
117129
nodeAddrs,
118130
operationRewards,
@@ -195,9 +207,8 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
195207
function _updateRewardsRatio(uint256 operationRewardsPercent) internal {
196208
_totalOperationRewardsPerEpoch =
197209
(TOTAL_REWARDS_PER_YEAR * EPOCH_DURATION * operationRewardsPercent) / (100 * 365 days);
198-
_totalStakingRewardsPerEpoch = (
199-
(TOTAL_REWARDS_PER_YEAR * EPOCH_DURATION) * (100 - operationRewardsPercent)
200-
) / (100 * 365 days);
210+
_totalStakingRewardsPerEpoch = ((TOTAL_REWARDS_PER_YEAR * EPOCH_DURATION)
211+
* (100 - operationRewardsPercent)) / (100 * 365 days);
201212
}
202213

203214
/// @dev check distributed operationRewards not exceeds the max rewards per

0 commit comments

Comments
 (0)