File tree Expand file tree Collapse file tree 5 files changed +51
-13
lines changed
jobs/validators/lido-keys Expand file tree Collapse file tree 5 files changed +51
-13
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,10 @@ export class EnvironmentVariables {
105
105
@IsOptional ( )
106
106
@IsString ( )
107
107
LIDO_LOCATOR_CONTRACT_DEVNET_ADDRESS = '' ;
108
+
109
+ @IsOptional ( )
110
+ @IsString ( )
111
+ KEYS_API_BASE_PATH = '' ;
108
112
}
109
113
export const ENV_KEYS = Object . keys ( new EnvironmentVariables ( ) ) ;
110
114
Original file line number Diff line number Diff line change
1
+ import { Inject } from '@nestjs/common' ;
2
+ import { LOGGER_PROVIDER , LoggerService } from '../../../common/logger' ;
3
+ import { ConfigService } from '../../../common/config' ;
4
+ import { KEYS_API_PATHS } from './lido-keys.constants' ;
5
+ import { LidoKeysData } from './lido-keys.types' ;
6
+
7
+ export class LidoKeysClient {
8
+ constructor (
9
+ @Inject ( LOGGER_PROVIDER ) protected readonly logger : LoggerService ,
10
+ protected readonly configService : ConfigService ,
11
+ ) { }
12
+
13
+ protected endpoints : {
14
+ usedKeys : '/v1/keys?used=true' ;
15
+ } ;
16
+
17
+ protected getBasePath ( ) : string {
18
+ const envUrl = this . configService . get ( 'KEYS_API_BASE_PATH' ) ;
19
+
20
+ if ( envUrl ) {
21
+ return envUrl ;
22
+ }
23
+
24
+ const chainId = this . configService . get ( 'CHAIN_ID' ) ;
25
+ return KEYS_API_PATHS [ chainId ] ;
26
+ }
27
+
28
+ public async getUsedKeys ( ) {
29
+ const url = this . getBasePath ( ) + this . endpoints . usedKeys ;
30
+ const lidoKeysResponse = await fetch ( url , {
31
+ method : 'GET' ,
32
+ } ) ;
33
+ const lidoKeys : LidoKeysData = await lidoKeysResponse . json ( ) ;
34
+ return lidoKeys ;
35
+ }
36
+ }
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ import { CHAINS } from '@lido-nestjs/constants';
2
2
3
3
const DEVNET_7 = '7032118028' ;
4
4
5
- export const KEYS_API_ADDRESS = {
6
- [ CHAINS . Mainnet ] : 'https://keys-api.lido.fi/v1/keys?used=true ' ,
7
- [ CHAINS . Goerli ] : 'https://keys-api.testnet.fi/v1/keys?used=true ' ,
8
- [ CHAINS . Holesky ] : 'https://keys-api-holesky.testnet.fi/v1/keys?used=true ' ,
9
- [ DEVNET_7 ] : 'http://hr6vb81d1ndsx-pectra-devnet-7-keys-api.valset-01.testnet.fi/v1/keys?used=true ' ,
5
+ export const KEYS_API_PATHS = {
6
+ [ CHAINS . Mainnet ] : 'https://keys-api.lido.fi' ,
7
+ [ CHAINS . Goerli ] : 'https://keys-api.testnet.fi' ,
8
+ [ CHAINS . Holesky ] : 'https://keys-api-holesky.testnet.fi' ,
9
+ [ DEVNET_7 ] : 'http://hr6vb81d1ndsx-pectra-devnet-7-keys-api.valset-01.testnet.fi' ,
10
10
} ;
Original file line number Diff line number Diff line change 1
1
import { Module } from '@nestjs/common' ;
2
2
import { ValidatorsStorageModule } from 'storage' ;
3
3
import { LidoKeysService } from './lido-keys.service' ;
4
+ import { LidoKeysClient } from './lido-keys.client' ;
4
5
5
6
@Module ( {
6
7
imports : [ ValidatorsStorageModule ] ,
7
- providers : [ LidoKeysService ] ,
8
+ providers : [ LidoKeysService , LidoKeysClient ] ,
8
9
exports : [ LidoKeysService ] ,
9
10
} )
10
11
export class LidoKeysModule { }
Original file line number Diff line number Diff line change @@ -2,21 +2,18 @@ import { Inject } from '@nestjs/common';
2
2
import { LOGGER_PROVIDER , LoggerService } from 'common/logger' ;
3
3
import { IndexedValidator } from 'common/consensus-provider/consensus-provider.types' ;
4
4
import { ConfigService } from 'common/config' ;
5
- import { LidoKey , LidoKeysData } from './lido-keys.types' ;
6
- import { KEYS_API_ADDRESS } from './lido-keys.constants ' ;
5
+ import { LidoKey } from './lido-keys.types' ;
6
+ import { LidoKeysClient } from './lido-keys.client ' ;
7
7
8
8
export class LidoKeysService {
9
9
constructor (
10
10
@Inject ( LOGGER_PROVIDER ) protected readonly logger : LoggerService ,
11
11
protected readonly configService : ConfigService ,
12
+ protected readonly lidoKeysClient : LidoKeysClient ,
12
13
) { }
13
14
14
15
public async fetchLidoKeysData ( ) {
15
- const lidoKeysResponse = await fetch ( KEYS_API_ADDRESS [ this . configService . get ( 'CHAIN_ID' ) ] , {
16
- method : 'GET' ,
17
- } ) ;
18
- const lidoKeys : LidoKeysData = await lidoKeysResponse . json ( ) ;
19
- return lidoKeys ;
16
+ return this . lidoKeysClient . getUsedKeys ( ) ;
20
17
}
21
18
22
19
public async getLidoValidatorsByKeys ( keys : LidoKey [ ] , validators : IndexedValidator [ ] ) {
You can’t perform that action at this time.
0 commit comments