Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: connect to devnet #308

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
57 changes: 57 additions & 0 deletions docker-compose.devnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: '3.9'

networks:
devnet:
name: ${DOCKER_NETWORK_NAME}
external: true

services:
db:
image: postgres:16-alpine
restart: unless-stopped
networks:
- devnet
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
volumes:
- pgdata:/var/lib/postgresql/data

keys_api:
build: ./
platform: linux/amd64
restart: always
networks:
- devnet
environment:
- NODE_ENV=production
- PORT=${PORT}
- CORS_WHITELIST_REGEXP=${CORS_WHITELIST_REGEXP}
- GLOBAL_THROTTLE_TTL=${GLOBAL_THROTTLE_TTL}
- GLOBAL_THROTTLE_LIMIT=${GLOBAL_THROTTLE_LIMIT}
- GLOBAL_CACHE_TTL=${GLOBAL_CACHE_TTL}
- LOG_LEVEL=${LOG_LEVEL}
- LOG_FORMAT=${LOG_FORMAT}
- PROVIDERS_URLS=${PROVIDERS_URLS}
- CL_API_URLS=${CL_API_URLS}
- CHAIN_ID=${CHAIN_ID}
- DB_NAME=${DB_NAME}
- DB_PORT=5432
- DB_HOST=db
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- JOB_INTERVAL_REGISTRY=${JOB_INTERVAL_REGISTRY}
- VALIDATOR_REGISTRY_ENABLE=${VALIDATOR_REGISTRY_ENABLE}
- JOB_INTERVAL_VALIDATORS_REGISTRY=${JOB_INTERVAL_VALIDATORS_REGISTRY}
- LIDO_LOCATOR_DEVNET_ADDRESS=${LIDO_LOCATOR_DEVNET_ADDRESS}
- CURATED_MODULE_DEVNET_ADDRESS=${CURATED_MODULE_DEVNET_ADDRESS}
- CSM_MODULE_DEVNET_ADDRESS=${CSM_MODULE_DEVNET_ADDRESS}
- STAKING_ROUTER_DEVNET_ADDRESS=${STAKING_ROUTER_DEVNET_ADDRESS}
ports:
- '${PORT}:${PORT}'
depends_on:
- db

volumes:
pgdata:
12 changes: 10 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,21 @@ import { CSMKeyRegistryModule } from 'common/registry-csm';
KeyRegistryModule.forRootAsync({
inject: [SimpleFallbackJsonRpcBatchProvider, ConfigService],
async useFactory(provider: SimpleFallbackJsonRpcBatchProvider, configService: ConfigService) {
return { provider, keysBatchSize: configService.get('KEYS_FETCH_BATCH_SIZE') };
return {
provider,
keysBatchSize: configService.get('KEYS_FETCH_BATCH_SIZE'),
registryAddress: configService.get('CURATED_MODULE_DEVNET_ADDRESS'),
};
},
}),
CSMKeyRegistryModule.forRootAsync({
inject: [SimpleFallbackJsonRpcBatchProvider, ConfigService],
async useFactory(provider: SimpleFallbackJsonRpcBatchProvider, configService: ConfigService) {
return { provider, keysBatchSize: configService.get('KEYS_FETCH_BATCH_SIZE') };
return {
provider,
keysBatchSize: configService.get('KEYS_FETCH_BATCH_SIZE'),
registryAddress: configService.get('CSM_MODULE_DEVNET_ADDRESS'),
};
},
}),
StakingRouterModule,
Expand Down
12 changes: 12 additions & 0 deletions src/common/config/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ export class EnvironmentVariables {
@IsOptional()
@IsString()
LIDO_LOCATOR_DEVNET_ADDRESS = '';

@IsOptional()
@IsString()
CURATED_MODULE_DEVNET_ADDRESS = '';

@IsOptional()
@IsString()
CSM_MODULE_DEVNET_ADDRESS = '';

@IsOptional()
@IsString()
STAKING_ROUTER_DEVNET_ADDRESS = '';
}

export function validate(config: Record<string, unknown>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const REGISTRY_FETCH_OPTIONS_TOKEN = Symbol('registryFetchOptionsToken');

export interface RegistryFetchOptions {
registryAddress?: string;
lidoAddress?: string;
provider?: Provider | Signer;
keysBatchSize?: number;
}
Expand Down
19 changes: 3 additions & 16 deletions src/common/registry-csm/fetch/registry-fetch.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DynamicModule, Module } from '@nestjs/common';
import { LidoContractModule, RegistryContractModule } from '@lido-nestjs/contracts';
import { RegistryContractModule } from '@lido-nestjs/contracts';
import {
RegistryFetchModuleSyncOptions,
RegistryFetchModuleAsyncOptions,
Expand Down Expand Up @@ -39,10 +39,6 @@ export class RegistryFetchModule {
module: RegistryFetchModule,
imports: [
...(options?.imports || []),
LidoContractModule.forFeature({
address: options?.lidoAddress,
provider: options?.provider,
}),
RegistryContractModule.forFeature({
address: options?.registryAddress,
provider: options?.provider,
Expand All @@ -54,7 +50,7 @@ export class RegistryFetchModule {
useValue: options?.keysBatchSize ? { keysBatchSize: options.keysBatchSize } : {},
},
],
exports: [LidoContractModule, RegistryContractModule],
exports: [RegistryContractModule],
};
}

Expand All @@ -63,15 +59,6 @@ export class RegistryFetchModule {
module: RegistryFetchModule,
imports: [
...(options.imports || []),
LidoContractModule.forFeatureAsync({
async useFactory(...args) {
const config = await options.useFactory(...args);
const { provider, lidoAddress } = config;

return { provider, address: lidoAddress };
},
inject: options.inject,
}),
RegistryContractModule.forFeatureAsync({
async useFactory(...args) {
const config = await options.useFactory(...args);
Expand All @@ -89,7 +76,7 @@ export class RegistryFetchModule {
inject: options.inject,
},
],
exports: [LidoContractModule, RegistryContractModule],
exports: [RegistryContractModule],
};
}
}
1 change: 0 additions & 1 deletion src/common/registry/fetch/interfaces/module.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const REGISTRY_FETCH_OPTIONS_TOKEN = Symbol('registryFetchOptionsToken');

export interface RegistryFetchOptions {
registryAddress?: string;
lidoAddress?: string;
provider?: Provider | Signer;
keysBatchSize?: number;
}
Expand Down
19 changes: 3 additions & 16 deletions src/common/registry/fetch/registry-fetch.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DynamicModule, Module } from '@nestjs/common';
import { LidoContractModule, RegistryContractModule } from '@lido-nestjs/contracts';
import { RegistryContractModule } from '@lido-nestjs/contracts';
import {
RegistryFetchModuleSyncOptions,
RegistryFetchModuleAsyncOptions,
Expand Down Expand Up @@ -47,10 +47,6 @@ export class RegistryFetchModule {
module: RegistryFetchModule,
imports: [
...(options?.imports || []),
LidoContractModule.forFeature({
address: options?.lidoAddress,
provider: options?.provider,
}),
RegistryContractModule.forFeature({
address: options?.registryAddress,
provider: options?.provider,
Expand All @@ -62,7 +58,7 @@ export class RegistryFetchModule {
useValue: options?.keysBatchSize ? { keysBatchSize: options.keysBatchSize } : {},
},
],
exports: [LidoContractModule, RegistryContractModule],
exports: [RegistryContractModule],
};
}

Expand All @@ -71,15 +67,6 @@ export class RegistryFetchModule {
module: RegistryFetchModule,
imports: [
...(options.imports || []),
LidoContractModule.forFeatureAsync({
async useFactory(...args) {
const config = await options.useFactory(...args);
const { provider, lidoAddress } = config;

return { provider, address: lidoAddress };
},
inject: options.inject,
}),
RegistryContractModule.forFeatureAsync({
async useFactory(...args) {
const config = await options.useFactory(...args);
Expand All @@ -97,7 +84,7 @@ export class RegistryFetchModule {
inject: options.inject,
},
],
exports: [LidoContractModule, RegistryContractModule],
exports: [RegistryContractModule],
};
}
}
5 changes: 0 additions & 5 deletions src/common/registry/test/fetch/sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { hexZeroPad } from '@ethersproject/bytes';
import { getDefaultProvider, Provider } from '@ethersproject/providers';
import { RegistryFetchModule, RegistryFetchService } from '../../';
import { LIDO_CONTRACT_TOKEN, Lido } from '@lido-nestjs/contracts';

Check warning on line 7 in src/common/registry/test/fetch/sync.spec.ts

View workflow job for this annotation

GitHub Actions / test

'LIDO_CONTRACT_TOKEN' is defined but never used

Check warning on line 7 in src/common/registry/test/fetch/sync.spec.ts

View workflow job for this annotation

GitHub Actions / test

'Lido' is defined but never used
import { REGISTRY_CONTRACT_TOKEN, Registry } from '@lido-nestjs/contracts';
import { LoggerModule, nullTransport } from '@lido-nestjs/logger';

Expand Down Expand Up @@ -47,23 +47,18 @@
});

test('forFeature addresses', async () => {
const lidoAddress = hexZeroPad('0x01', 20);
const registryAddress = hexZeroPad('0x02', 20);

const imports = [
RegistryFetchModule.forFeature({
provider,
lidoAddress,
registryAddress,
}),
LoggerModule.forRoot({ transports: [nullTransport()] }),
];

const moduleRef = await testModules({ imports });

const lidoContract: Lido = moduleRef.get(LIDO_CONTRACT_TOKEN);
expect(lidoContract.address).toBe(lidoAddress);

const registryContract: Registry = moduleRef.get(REGISTRY_CONTRACT_TOKEN);
expect(registryContract.address).toBe(registryAddress);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Global, Module } from '@nestjs/common';
import { LidoLocatorService } from './lido-locator.service';
import { LidoLocatorContractModule } from '@lido-nestjs/contracts';
// TODO: maybe ../../../ shows us that we need to move execution-provider on level up
import { ExecutionProvider } from '../../../common/execution-provider';
import { ConfigModule, ConfigService } from 'common/config';

@Global()
@Module({
imports: [
ConfigModule,
LidoLocatorContractModule.forRootAsync({
inject: [ExecutionProvider],
async useFactory(provider) {
return { provider };
inject: [ExecutionProvider, ConfigService],
async useFactory(provider, configService: ConfigService) {
return { provider, address: configService.get('LIDO_LOCATOR_DEVNET_ADDRESS') };
},
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { StakingModuleInterfaceModule } from '../staking-module-interface';
import { LidoLocatorModule } from '../lido-locator/lido-locator.module';
import { StakingRouterContractModule } from '@lido-nestjs/contracts';
import { ExecutionProvider } from '../../../common/execution-provider';
import { ConfigService } from 'common/config';

@Module({
imports: [
StakingModuleInterfaceModule,
LidoLocatorModule,
StakingRouterContractModule.forRootAsync({
inject: [ExecutionProvider],
async useFactory(provider) {
return { provider };
inject: [ExecutionProvider, ConfigService],
async useFactory(provider, configService: ConfigService) {
return { provider, address: configService.get('STAKING_ROUTER_DEVNET_ADDRESS') };
},
}),
],
Expand Down
Loading