@@ -8,8 +8,8 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
8
8
import {Errors} from "@aztec/core/libraries/Errors.sol " ;
9
9
import {LeonidasLib} from "@aztec/core/libraries/LeonidasLib/LeonidasLib.sol " ;
10
10
import {
11
- Timestamp, Slot, Epoch, SlotLib, EpochLib, TimeFns
12
- } from "@aztec/core/libraries/TimeMath .sol " ;
11
+ Timestamp, Slot, Epoch, SlotLib, EpochLib, TimeLib
12
+ } from "@aztec/core/libraries/TimeLib .sol " ;
13
13
import {Staking} from "@aztec/core/staking/Staking.sol " ;
14
14
import {IERC20 } from "@oz/token/ERC20/IERC20.sol " ;
15
15
import {EnumerableSet} from "@oz/utils/structs/EnumerableSet.sol " ;
@@ -26,19 +26,19 @@ import {EnumerableSet} from "@oz/utils/structs/EnumerableSet.sol";
26
26
* It will be the duty of his successor (Pleistarchus) to optimize the costs with same functionality.
27
27
*
28
28
*/
29
- contract Leonidas is Staking , TimeFns , ILeonidas {
29
+ contract Leonidas is Staking , ILeonidas {
30
30
using EnumerableSet for EnumerableSet.AddressSet;
31
31
32
32
using SlotLib for Slot;
33
33
using EpochLib for Epoch;
34
+ using TimeLib for Timestamp;
35
+ using TimeLib for Slot;
36
+ using TimeLib for Epoch;
34
37
35
38
// The target number of validators in a committee
36
39
// @todo #8021
37
40
uint256 public immutable TARGET_COMMITTEE_SIZE;
38
41
39
- // The time that the contract was deployed
40
- Timestamp public immutable GENESIS_TIME;
41
-
42
42
LeonidasStorage private leonidasStore;
43
43
44
44
constructor (
@@ -49,14 +49,22 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
49
49
uint256 _slotDuration ,
50
50
uint256 _epochDuration ,
51
51
uint256 _targetCommitteeSize
52
- )
53
- Staking (_stakingAsset, _minimumStake, _slashingQuorum, _roundSize)
54
- TimeFns (_slotDuration, _epochDuration)
55
- {
56
- GENESIS_TIME = Timestamp.wrap (block .timestamp );
57
- SLOT_DURATION = _slotDuration;
58
- EPOCH_DURATION = _epochDuration;
52
+ ) Staking (_stakingAsset, _minimumStake, _slashingQuorum, _roundSize) {
59
53
TARGET_COMMITTEE_SIZE = _targetCommitteeSize;
54
+
55
+ TimeLib.initialize (block .timestamp , _slotDuration, _epochDuration);
56
+ }
57
+
58
+ function getGenesisTime () external view override (ILeonidas) returns (Timestamp) {
59
+ return Timestamp.wrap (TimeLib.getGenesisTime ());
60
+ }
61
+
62
+ function getSlotDuration () external view override (ILeonidas) returns (uint256 ) {
63
+ return TimeLib.getSlotDuration ();
64
+ }
65
+
66
+ function getEpochDuration () external view override (ILeonidas) returns (uint256 ) {
67
+ return TimeLib.getEpochDuration ();
60
68
}
61
69
62
70
/**
@@ -212,7 +220,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
212
220
override (ILeonidas)
213
221
returns (Timestamp)
214
222
{
215
- return GENESIS_TIME + toTimestamp (_slotNumber );
223
+ return _slotNumber. toTimestamp ();
216
224
}
217
225
218
226
/**
@@ -263,7 +271,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
263
271
* @return The computed epoch
264
272
*/
265
273
function getEpochAt (Timestamp _ts ) public view override (ILeonidas) returns (Epoch) {
266
- return _ts < GENESIS_TIME ? Epoch. wrap ( 0 ) : epochFromTimestamp (_ts - GENESIS_TIME );
274
+ return _ts. epochFromTimestamp ();
267
275
}
268
276
269
277
/**
@@ -274,7 +282,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
274
282
* @return The computed slot
275
283
*/
276
284
function getSlotAt (Timestamp _ts ) public view override (ILeonidas) returns (Slot) {
277
- return _ts < GENESIS_TIME ? Slot. wrap ( 0 ) : slotFromTimestamp (_ts - GENESIS_TIME );
285
+ return _ts. slotFromTimestamp ();
278
286
}
279
287
280
288
/**
@@ -285,7 +293,7 @@ contract Leonidas is Staking, TimeFns, ILeonidas {
285
293
* @return The computed epoch
286
294
*/
287
295
function getEpochAtSlot (Slot _slotNumber ) public view override (ILeonidas) returns (Epoch) {
288
- return Epoch. wrap ( _slotNumber.unwrap () / EPOCH_DURATION );
296
+ return _slotNumber.epochFromSlot ( );
289
297
}
290
298
291
299
// Can be used to add validators without setting up the epoch, useful for the initial set.
0 commit comments