Skip to content

Commit b36744b

Browse files
committed
added: keys api config path
1 parent 6f36449 commit b36744b

File tree

5 files changed

+51
-13
lines changed

5 files changed

+51
-13
lines changed

src/common/config/env.validation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export class EnvironmentVariables {
105105
@IsOptional()
106106
@IsString()
107107
LIDO_LOCATOR_CONTRACT_DEVNET_ADDRESS = '';
108+
109+
@IsOptional()
110+
@IsString()
111+
KEYS_API_BASE_PATH = '';
108112
}
109113
export const ENV_KEYS = Object.keys(new EnvironmentVariables());
110114

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

src/jobs/validators/lido-keys/lido-keys.constants.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { CHAINS } from '@lido-nestjs/constants';
22

33
const DEVNET_7 = '7032118028';
44

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',
1010
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Module } from '@nestjs/common';
22
import { ValidatorsStorageModule } from 'storage';
33
import { LidoKeysService } from './lido-keys.service';
4+
import { LidoKeysClient } from './lido-keys.client';
45

56
@Module({
67
imports: [ValidatorsStorageModule],
7-
providers: [LidoKeysService],
8+
providers: [LidoKeysService, LidoKeysClient],
89
exports: [LidoKeysService],
910
})
1011
export class LidoKeysModule {}

src/jobs/validators/lido-keys/lido-keys.service.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@ import { Inject } from '@nestjs/common';
22
import { LOGGER_PROVIDER, LoggerService } from 'common/logger';
33
import { IndexedValidator } from 'common/consensus-provider/consensus-provider.types';
44
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';
77

88
export class LidoKeysService {
99
constructor(
1010
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService,
1111
protected readonly configService: ConfigService,
12+
protected readonly lidoKeysClient: LidoKeysClient,
1213
) {}
1314

1415
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();
2017
}
2118

2219
public async getLidoValidatorsByKeys(keys: LidoKey[], validators: IndexedValidator[]) {

0 commit comments

Comments
 (0)