-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from lidofinance/feature/si-1580-add-validato…
…r-info-log-and-endpoint Feature/si 1580 add validator info log and endpoint
- Loading branch information
Showing
13 changed files
with
153 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
|
||
export function stringifyFrameBalances(frameBalances: Record<string, BigNumber>) { | ||
return JSON.stringify( | ||
Object.keys(frameBalances).reduce((acc, key) => { | ||
return { ...acc, [key]: frameBalances[key].toString() }; | ||
}, {}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './validators.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class ValidatorsDto { | ||
@ApiProperty({ | ||
example: 1658650005, | ||
description: 'ms time when data was last updated at', | ||
}) | ||
lastUpdatedAt: number; | ||
|
||
@ApiProperty({ | ||
example: 1724856617, | ||
description: 'max exit epoch over all CL network', | ||
}) | ||
maxExitEpoch: number; | ||
|
||
@ApiProperty({ | ||
example: '{}', | ||
description: 'sum of balances Lido validators with withdrawable_epoch by frame', | ||
}) | ||
frameBalances: Record<string, string>; | ||
|
||
@ApiProperty({ | ||
example: 100000, | ||
description: 'total number of validators in network', | ||
}) | ||
totalValidators: number; | ||
|
||
@ApiProperty({ | ||
example: 100000, | ||
description: 'current frame', | ||
}) | ||
currentFrame: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './validators.controller'; | ||
export * from './validators.module'; | ||
export * from './validators.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
ClassSerializerInterceptor, | ||
Controller, | ||
Get, | ||
HttpStatus, | ||
UseInterceptors, | ||
Version, | ||
CacheTTL, | ||
} from '@nestjs/common'; | ||
import { ApiResponse, ApiTags } from '@nestjs/swagger'; | ||
import { HTTP_PATHS } from 'http/http.constants'; | ||
import { ValidatorsService } from './validators.service'; | ||
import { ValidatorsDto } from './dto'; | ||
|
||
@Controller() | ||
@ApiTags('Validators') | ||
@UseInterceptors(ClassSerializerInterceptor) | ||
export class ValidatorsController { | ||
constructor(protected readonly validatorsService: ValidatorsService) {} | ||
|
||
@Version('1') | ||
@Get(HTTP_PATHS[1]['validators-info']) | ||
@CacheTTL(20 * 1000) | ||
@ApiResponse({ status: HttpStatus.OK, type: ValidatorsDto }) | ||
async validatorsV1(): Promise<ValidatorsDto> { | ||
return this.validatorsService.getValidatorsInfo(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule } from 'common/config'; | ||
import { ValidatorsController } from './validators.controller'; | ||
import { ValidatorsService } from './validators.service'; | ||
import { ValidatorsStorageModule } from '../../storage'; | ||
import { GenesisTimeModule } from '../../common/genesis-time'; | ||
|
||
@Module({ | ||
imports: [ConfigModule, ValidatorsStorageModule, GenesisTimeModule], | ||
controllers: [ValidatorsController], | ||
providers: [ValidatorsService], | ||
}) | ||
export class ValidatorsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ConfigService } from 'common/config'; | ||
import { ValidatorsStorageService } from '../../storage'; | ||
import { GenesisTimeService } from '../../common/genesis-time'; | ||
|
||
@Injectable() | ||
export class ValidatorsService { | ||
constructor( | ||
protected readonly configService: ConfigService, | ||
protected readonly validatorsServiceStorage: ValidatorsStorageService, | ||
protected readonly genesisTimeService: GenesisTimeService, | ||
) {} | ||
|
||
getValidatorsInfo() { | ||
const lastUpdatedAt = this.validatorsServiceStorage.getLastUpdate(); | ||
const maxExitEpoch = Number(this.validatorsServiceStorage.getMaxExitEpoch()); | ||
const frameBalancesBigNumber = this.validatorsServiceStorage.getFrameBalances(); | ||
const totalValidators = this.validatorsServiceStorage.getTotal(); | ||
const currentFrame = this.genesisTimeService.getFrameOfEpoch(this.genesisTimeService.getCurrentEpoch()); | ||
|
||
const frameBalances = Object.keys(frameBalancesBigNumber).reduce((acc, item) => { | ||
acc[item] = frameBalancesBigNumber[item].toString(); | ||
return acc; | ||
}, {} as Record<string, string>); | ||
|
||
return { | ||
lastUpdatedAt, | ||
maxExitEpoch, | ||
frameBalances, | ||
totalValidators, | ||
currentFrame, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters