@@ -90,14 +90,14 @@ export class WaitingTimeService {
90
90
const additionalStETH = parseEther ( amount || '0' ) ;
91
91
const queueStETH = unfinalized . add ( additionalStETH ) ;
92
92
93
- const latestEpoch = this . validators . getMaxExitEpoch ( ) ;
93
+ const maxExitEpoch = this . getMaxExitEpoch ( ) ;
94
94
95
95
const { frame, type } = await this . calculateWithdrawalFrame ( {
96
96
unfinalized : queueStETH ,
97
97
vaultsBalance,
98
98
buffer,
99
99
requestTimestamp : Date . now ( ) ,
100
- latestEpoch,
100
+ latestEpoch : maxExitEpoch . toString ( ) ,
101
101
} ) ;
102
102
const ms = this . genesisTimeService . timeToWithdrawalFrame ( frame , Date . now ( ) ) ;
103
103
const finalizationIn = validateTimeResponseWithFallback ( ms ) + GAP_AFTER_REPORT ;
@@ -132,7 +132,7 @@ export class WaitingTimeService {
132
132
const nextCalculationAt = this . queueInfo . getNextUpdate ( ) . toISOString ( ) ;
133
133
const request = requests . find ( ( item ) => item . id . eq ( BigNumber . from ( requestId ) ) ) ;
134
134
135
- const maxExitEpoch = this . validators . getMaxExitEpoch ( ) ;
135
+ const maxExitEpoch = this . getMaxExitEpoch ( ) ;
136
136
const currentEpoch = this . genesisTimeService . getCurrentEpoch ( ) ;
137
137
138
138
const queueStETH = calculateUnfinalizedEthToRequestId ( requests , request ) ;
@@ -325,7 +325,7 @@ export class WaitingTimeService {
325
325
private async checkInPastCase ( args : CheckInPastCaseArgs ) {
326
326
const { request, vaultsBalance, buffer, type, frame } = args ;
327
327
328
- const maxExitEpoch = this . validators . getMaxExitEpoch ( ) ;
328
+ const maxExitEpoch = this . getMaxExitEpoch ( ) ;
329
329
const requests = this . queueInfo . getRequests ( ) ;
330
330
const requestTimestamp = request . timestamp . toNumber ( ) * 1000 ;
331
331
const queueStETH = calculateUnfinalizedEthToRequestId ( requests , request ) ;
@@ -477,14 +477,14 @@ export class WaitingTimeService {
477
477
478
478
public calculateRequestTimeSimple ( unfinalizedETH : BigNumber ) : number {
479
479
const currentEpoch = this . genesisTimeService . getCurrentEpoch ( ) ;
480
- const latestEpoch = this . validators . getMaxExitEpoch ( ) ;
480
+ const maxExitEpoch = this . getMaxExitEpoch ( ) ;
481
481
const totalValidators = this . validators . getActiveValidatorsCount ( ) ;
482
482
483
483
const churnLimit = Math . max ( MIN_PER_EPOCH_CHURN_LIMIT , totalValidators / CHURN_LIMIT_QUOTIENT ) ;
484
484
485
485
const lidoQueueInEpoch = unfinalizedETH . div ( MIN_ACTIVATION_BALANCE . mul ( Math . floor ( churnLimit ) ) ) ;
486
486
const sweepingMean = this . validators . getSweepMeanEpochs ( ) ;
487
- const potentialExitEpoch = BigNumber . from ( latestEpoch ) . add ( lidoQueueInEpoch ) . add ( sweepingMean ) ;
487
+ const potentialExitEpoch = BigNumber . from ( maxExitEpoch ) . add ( lidoQueueInEpoch ) . add ( sweepingMean ) ;
488
488
489
489
const waitingTime = potentialExitEpoch
490
490
. sub ( currentEpoch )
@@ -494,4 +494,12 @@ export class WaitingTimeService {
494
494
495
495
return Math . round ( waitingTime . toNumber ( ) ) ;
496
496
}
497
+
498
+ // returns max exit epoch of validators with fallback to current epoch if max exit epoch already passed
499
+ public getMaxExitEpoch ( ) {
500
+ const maxExitEpoch = this . validators . getMaxExitEpoch ( ) ;
501
+ const currentEpoch = this . genesisTimeService . getCurrentEpoch ( ) ;
502
+
503
+ return Math . max ( + maxExitEpoch , currentEpoch + MAX_SEED_LOOKAHEAD + 1 ) ;
504
+ }
497
505
}
0 commit comments