Skip to content

Commit 7a59f27

Browse files
committed
feat: added custom contracts addresses, added using lidoLocator instead of constants
1 parent 8b1bab2 commit 7a59f27

File tree

6 files changed

+63
-22
lines changed

6 files changed

+63
-22
lines changed

src/common/config/config.service.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { ConfigService as ConfigServiceSource } from '@nestjs/config';
22
import { EnvironmentVariables } from './env.validation';
3+
import {
4+
AccountingOracleHashConsensusModule,
5+
LidoContractModule,
6+
LidoLocatorContractModule,
7+
OracleReportSanityCheckerModule,
8+
ValidatorsExitBusOracleHashConsensusModule,
9+
WithdrawalQueueContractModule,
10+
} from '@lido-nestjs/contracts';
311

412
export class ConfigService extends ConfigServiceSource<EnvironmentVariables> {
513
/**
@@ -18,4 +26,18 @@ export class ConfigService extends ConfigServiceSource<EnvironmentVariables> {
1826
public get<T extends keyof EnvironmentVariables>(key: T): EnvironmentVariables[T] {
1927
return super.get(key, { infer: true }) as EnvironmentVariables[T];
2028
}
29+
30+
public getCustomConfigContractsAddressMap() {
31+
return new Map<symbol, string>([
32+
[WithdrawalQueueContractModule.contractToken, this.get('WITHDRAWAL_QUEUE_CONTRACT_DEVNET_ADDRESS')],
33+
[LidoContractModule.contractToken, this.get('LIDO_CONTRACT_DEVNET_ADDRESS')],
34+
[OracleReportSanityCheckerModule.contractToken, this.get('ORACLE_REPORT_SANITY_CHECKER_DEVNET_ADDRESS')],
35+
[AccountingOracleHashConsensusModule.contractToken, this.get('ACCOUNTING_ORACLE_HASH_CONSENSUS_DEVNET_ADDRESS')],
36+
[
37+
ValidatorsExitBusOracleHashConsensusModule.contractToken,
38+
this.get('VALIDATORS_EXIT_BUS_ORACLE_HASH_CONSENSUS_DEVNET_ADDRESS'),
39+
],
40+
[LidoLocatorContractModule.contractToken, this.get('LIDO_LOCATOR_CONTRACT_DEVNET_ADDRESS')],
41+
]);
42+
}
2143
}

src/common/config/env.validation.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CronExpression } from '@nestjs/schedule';
22
import { plainToClass, Transform } from 'class-transformer';
3-
import { IsEnum, IsNumber, IsString, IsOptional, validateSync, Min, IsArray, ArrayMinSize } from 'class-validator';
4-
import { Environment, LogLevel, LogFormat } from './interfaces';
3+
import { ArrayMinSize, IsArray, IsEnum, IsNumber, IsOptional, IsString, Min, validateSync } from 'class-validator';
4+
import { Environment, LogFormat, LogLevel } from './interfaces';
55

66
const toNumber =
77
({ defaultValue }) =>
@@ -81,6 +81,30 @@ export class EnvironmentVariables {
8181
@IsNumber()
8282
@Transform(({ value }) => Number(value))
8383
CHAIN_ID: number = null;
84+
85+
@IsOptional()
86+
@IsString()
87+
WITHDRAWAL_QUEUE_CONTRACT_DEVNET_ADDRESS = '';
88+
89+
@IsOptional()
90+
@IsString()
91+
LIDO_CONTRACT_DEVNET_ADDRESS = '';
92+
93+
@IsOptional()
94+
@IsString()
95+
ORACLE_REPORT_SANITY_CHECKER_DEVNET_ADDRESS = '';
96+
97+
@IsOptional()
98+
@IsString()
99+
ACCOUNTING_ORACLE_HASH_CONSENSUS_DEVNET_ADDRESS = '';
100+
101+
@IsOptional()
102+
@IsString()
103+
VALIDATORS_EXIT_BUS_ORACLE_HASH_CONSENSUS_DEVNET_ADDRESS = '';
104+
105+
@IsOptional()
106+
@IsString()
107+
LIDO_LOCATOR_CONTRACT_DEVNET_ADDRESS = '';
84108
}
85109
export const ENV_KEYS = Object.keys(new EnvironmentVariables());
86110

src/common/contracts/contracts.module.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@lido-nestjs/contracts';
99
import { Global, Module } from '@nestjs/common';
1010
import { ExecutionProvider } from 'common/execution-provider';
11+
import { ConfigService } from 'common/config';
1112

1213
@Global()
1314
@Module({
@@ -20,10 +21,11 @@ import { ExecutionProvider } from 'common/execution-provider';
2021
LidoLocatorContractModule,
2122
].map((module) =>
2223
module.forRootAsync({
23-
async useFactory(provider: ExecutionProvider) {
24-
return { provider };
24+
async useFactory(provider: ExecutionProvider, config: ConfigService) {
25+
const addressMap = config.getCustomConfigContractsAddressMap();
26+
return { provider, address: addressMap.get(module.contractToken) };
2527
},
26-
inject: [ExecutionProvider],
28+
inject: [ExecutionProvider, ConfigService],
2729
}),
2830
),
2931
})

src/common/sweep/sweep.service.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ethers } from 'ethers';
22
import { Inject, Injectable, LoggerService } from '@nestjs/common';
33
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
4-
import { SimpleFallbackJsonRpcBatchProvider } from '@lido-nestjs/execution';
54
import { ConfigService } from 'common/config';
65
import {
76
isFullyWithdrawableValidator,
@@ -14,32 +13,32 @@ import { bigNumberMin } from 'common/utils/big-number-min';
1413
import { OracleV2__factory } from 'common/contracts/generated';
1514
import { FAR_FUTURE_EPOCH } from 'jobs/validators';
1615
import { SLOTS_PER_EPOCH } from 'common/genesis-time';
17-
import { VALIDATORS_EXIT_BUS_ORACLE_CONTRACT_ADDRESSES } from 'common/contracts/modules/validators-exit-bus-oracle/validators-exit-bus-oracle.constants';
1816
import {
1917
MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP,
2018
MAX_WITHDRAWALS_PER_PAYLOAD,
2119
MIN_ACTIVATION_BALANCE,
2220
} from 'waiting-time/waiting-time.constants';
2321
import { Withdrawal } from './sweep.types';
22+
import { LIDO_LOCATOR_CONTRACT_TOKEN, LidoLocator } from '@lido-nestjs/contracts';
2423

2524
@Injectable()
2625
export class SweepService {
2726
static SERVICE_LOG_NAME = 'sweep';
2827

2928
constructor(
3029
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService,
30+
@Inject(LIDO_LOCATOR_CONTRACT_TOKEN) protected readonly lidoLocator: LidoLocator,
3131
protected readonly consensusClientService: ConsensusClientService,
32-
protected readonly provider: SimpleFallbackJsonRpcBatchProvider,
3332
protected readonly configService: ConfigService,
3433
) {}
3534

3635
async getConsensusVersion() {
37-
const chainId = this.configService.get('CHAIN_ID');
3836
const provider = new ethers.JsonRpcProvider(this.configService.get('EL_RPC_URLS')[0]);
39-
const address: string = VALIDATORS_EXIT_BUS_ORACLE_CONTRACT_ADDRESSES[chainId];
37+
const address = await this.lidoLocator.validatorsExitBusOracle();
4038
const validatorExitBusOracle = OracleV2__factory.connect(address, {
4139
provider,
4240
});
41+
4342
return await validatorExitBusOracle.getConsensusVersion();
4443
}
4544

src/events/rewards/rewards.service.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { Inject, Injectable } from '@nestjs/common';
22
import { SECONDS_PER_SLOT, SLOTS_PER_EPOCH } from '../../common/genesis-time';
33
import { SimpleFallbackJsonRpcBatchProvider } from '@lido-nestjs/execution';
4-
import {
5-
Lido,
6-
LIDO_CONTRACT_TOKEN,
7-
EXECUTION_REWARDS_VAULT_CONTRACT_ADDRESSES,
8-
LIDO_LOCATOR_CONTRACT_TOKEN,
9-
LidoLocator,
10-
} from '@lido-nestjs/contracts';
4+
import { Lido, LIDO_CONTRACT_TOKEN, LIDO_LOCATOR_CONTRACT_TOKEN, LidoLocator } from '@lido-nestjs/contracts';
115
import { Interface } from 'ethers';
126
import {
137
LIDO_EL_REWARDS_RECEIVED_EVENT,
@@ -299,13 +293,10 @@ export class RewardsService {
299293

300294
// it includes WithdrawalVault balance and diff between rewards and cached rewards from previous report
301295
async getVaultsBalance(blockNumber: number) {
302-
const chainId = this.configService.get('CHAIN_ID');
303296
const withdrawalVaultAddress = await this.lidoLocator.withdrawalVault({ blockTag: blockNumber });
304297
const withdrawalVaultBalance = await this.provider.getBalance(withdrawalVaultAddress, blockNumber);
305-
const rewardsVaultBalance = await this.provider.getBalance(
306-
EXECUTION_REWARDS_VAULT_CONTRACT_ADDRESSES[chainId],
307-
blockNumber,
308-
);
298+
const rewardsVaultAddress = await this.lidoLocator.elRewardsVault();
299+
const rewardsVaultBalance = await this.provider.getBalance(rewardsVaultAddress, blockNumber);
309300
const elRewards = this.rewardsStorage.getElRewardsPerFrame();
310301
const clRewards = this.rewardsStorage.getClRewardsPerFrame();
311302

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { CHAINS } from '@lido-nestjs/constants';
22

3+
const DEVNET_7 = '7032118028';
4+
35
export const KEYS_API_ADDRESS = {
46
[CHAINS.Mainnet]: 'https://keys-api.lido.fi/v1/keys?used=true',
57
[CHAINS.Goerli]: 'https://keys-api.testnet.fi/v1/keys?used=true',
68
[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',
710
};

0 commit comments

Comments
 (0)