Skip to content

Commit

Permalink
fix: move sr contracts to sstakingrouter-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Amuhar committed Aug 3, 2023
1 parent ded9c31 commit 6de1573
Show file tree
Hide file tree
Showing 36 changed files with 87 additions and 98 deletions.
8 changes: 0 additions & 8 deletions src/common/contracts/i-staking-module/i-staking-module.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/common/contracts/i-staking-module/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/common/contracts/staking-router/staking-router-fetch.module.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/common/registry/storage/key.storage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { QueryOrder } from '@mikro-orm/core';
import { FilterQuery, FindOptions } from '@mikro-orm/core';
import { Injectable } from '@nestjs/common';
import { KeyField } from 'staking-router-modules/interfaces/key-fields';
import { RegistryKey } from './key.entity';
import { RegistryKeyRepository } from './key.repository';

Expand Down
2 changes: 1 addition & 1 deletion src/http/sr-modules-keys/sr-modules-keys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GroupedByModuleKeyListResponse, SRModuleKeyListResponse } from './entit
import { ModuleId, KeyQuery, Key, ELBlockSnapshot, SRModule } from 'http/common/entities';
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
import { StakingRouterService } from 'staking-router-modules/staking-router.service';
import { KeyEntity } from 'staking-router-modules/interfaces';
import { KeyEntity } from 'staking-router-modules/interfaces/staking-module.interface';

@Injectable()
export class SRModulesKeysService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ConfigService } from 'common/config';
import { SRModuleOperatorsKeysResponse } from './entities';
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
import { StakingRouterService } from 'staking-router-modules/staking-router.service';
import { KeyEntity, OperatorEntity } from 'staking-router-modules/interfaces';
import { KeyEntity, OperatorEntity } from 'staking-router-modules/interfaces/staking-module.interface';

@Injectable()
export class SRModulesOperatorsKeysService {
Expand Down
3 changes: 1 addition & 2 deletions src/jobs/keys-update/keys-update.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import { Module } from '@nestjs/common';
import { KeysUpdateService } from './keys-update.service';
import { LoggerModule } from 'common/logger';
import { JobModule } from 'common/job';
import { StakingRouterFetchModule } from 'common/contracts';

@Module({
imports: [LoggerModule, JobModule, StakingRouterFetchModule],
imports: [LoggerModule, JobModule],
providers: [KeysUpdateService],
exports: [KeysUpdateService],
})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './staking-module-interface.module';
export * from './staking-module-interface.service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { StakingModuleInterfaceService } from './staking-module-interface.service';

@Module({
providers: [StakingModuleInterfaceService],
exports: [StakingModuleInterfaceService],
})
export class StakingModuleInterfaceModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ethers } from 'ethers';
import { BlockTag } from '../interfaces';

@Injectable()
export class IStakingModuleService {
export class StakingModuleInterfaceService {
constructor(protected readonly provider: ExecutionProvider) {}

public async getType(contractAddress: string, blockTag: BlockTag): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { StakingRouterFetchService } from './staking-router-fetch.service';
import { StakingModuleInterfaceModule } from 'staking-router-modules/contracts/staking-module-interface';
import { LidoLocatorModule } from 'staking-router-modules/contracts/lido-locator/lido-locator.module';

@Module({
imports: [StakingModuleInterfaceModule, LidoLocatorModule],
providers: [StakingRouterFetchService],
exports: [StakingRouterFetchService],
})
export class StakingRouterFetchModule {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Injectable, Inject, LoggerService } from '@nestjs/common';
// TODO: move to staking-router-service
import { StakingModule } from '../../../staking-router-modules/interfaces/staking-module';
import { StakingModule } from '../../interfaces/staking-module.interface';
import { STAKING_MODULE_TYPE } from '../../constants';
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
import { IStakingModuleService } from 'common/contracts/i-staking-module';
// TODO: instead of separate file and index create one module with all contants
import { STAKING_MODULE_TYPE } from 'staking-router-modules/interfaces/staking-module-type';
import { LidoLocatorService } from 'common/contracts/lido-locator';
import { StakingModuleInterfaceService } from '../staking-module-interface';
import { LidoLocatorService } from '../lido-locator';
import { StakingRouter__factory } from 'generated';
import { ExecutionProvider } from 'common/execution-provider';
import { BlockTag } from '../interfaces';
Expand All @@ -14,11 +12,10 @@ import { Trace } from 'common/decorators/trace';
const TRACE_TIMEOUT = 30 * 1000;

@Injectable()
// TODO: move to staking-router-service
export class StakingRouterFetchService {
constructor(
@Inject(LOGGER_PROVIDER) protected readonly logger: LoggerService,
protected readonly iStakingModule: IStakingModuleService,
protected readonly stakingModuleInterface: StakingModuleInterfaceService,
protected readonly lidoLocatorService: LidoLocatorService,
protected readonly provider: ExecutionProvider,
) {}
Expand Down Expand Up @@ -47,7 +44,7 @@ export class StakingRouterFetchService {
modules.map(async (stakingModule) => {
const isActive = await srContract.getStakingModuleIsActive(stakingModule.id, { blockTag } as any);

const stakingModuleType = (await this.iStakingModule.getType(
const stakingModuleType = (await this.stakingModuleInterface.getType(
stakingModule.stakingModuleAddress,
blockTag,
)) as STAKING_MODULE_TYPE;
Expand Down
4 changes: 1 addition & 3 deletions src/staking-router-modules/curated-module.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import { Trace } from 'common/decorators/trace';
import { LOGGER_PROVIDER, LoggerService } from 'common/logger';
import { QueryOrder } from '@mikro-orm/core';
import { StakingModuleInterface } from './interfaces/staking-module.interface';
import { KeysFilter } from './interfaces/keys-filter';
import { OperatorsFilter } from './interfaces';
import { KeyField } from './interfaces/key-fields';
import { KeyField, KeysFilter, OperatorsFilter } from './interfaces/filters';

const TRACE_TIMEOUT = 15 * 60 * 1000;

Expand Down
1 change: 0 additions & 1 deletion src/staking-router-modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './staking-router.module';
export * from './curated-module.service';
export * from './interfaces/staking-module-type';
15 changes: 15 additions & 0 deletions src/staking-router-modules/interfaces/filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// TODO: here should be general type for key
// will be used in /v1/keys and /v1/modules/keys

export type KeyField = 'key' | 'depositSignature' | 'operatorIndex' | 'used' | 'moduleAddress';

//TODO: KeysFilter HTTP query
// should staking router service import this type from http/entities
export interface KeysFilter {
used?: boolean;
operatorIndex?: number;
}

export interface OperatorsFilter {
index?: number;
}
5 changes: 0 additions & 5 deletions src/staking-router-modules/interfaces/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/staking-router-modules/interfaces/key-fields.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/staking-router-modules/interfaces/keys-filter.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/staking-router-modules/interfaces/operators-filter.ts

This file was deleted.

33 changes: 30 additions & 3 deletions src/staking-router-modules/interfaces/staking-module.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import { RegistryKey, RegistryOperator } from 'common/registry';
import { KeyField } from './key-fields';
import { KeysFilter } from './keys-filter';
import { OperatorsFilter } from './operators-filter';
import { KeyField, KeysFilter, OperatorsFilter } from './filters';
import { STAKING_MODULE_TYPE } from '../constants';

// interface of modules we get from SR contract
export interface StakingModule {
// unique id of the staking module
id: number;
// address of staking module
stakingModuleAddress: string;
// part of the fee taken from staking rewards that goes to the staking module
stakingModuleFee: number;
// part of the fee taken from staking rewards that goes to the treasury
treasuryFee: number;
// target percent of total validators in protocol, in BP
targetShare: number;
// staking module status if staking module can not accept the deposits or can participate in further reward distribution
status: number;
// name of staking module
name: string;
// block.timestamp of the last deposit of the staking module
lastDepositAt: number;
// block.number of the last deposit of the staking module
lastDepositBlock: number;
// number of exited validators
exitedValidatorsCount: number;
// type of staking router module
type: STAKING_MODULE_TYPE;
// is module active
active: boolean;
}

// TODO: in future Keys = CuratedKey (RegistryKey) | CommunityKey
export type KeyEntity = RegistryKey;
Expand Down
29 changes: 0 additions & 29 deletions src/staking-router-modules/interfaces/staking-module.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/staking-router-modules/staking-module-impl-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CuratedModuleService } from './curated-module.service';
import { STAKING_MODULE_TYPE } from './interfaces/staking-module-type';
import { STAKING_MODULE_TYPE } from './constants';

type StakingModuleImpl = typeof CuratedModuleService;

Expand Down
2 changes: 2 additions & 0 deletions src/staking-router-modules/staking-router.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ExecutionProvider } from 'common/execution-provider';
import { KeyRegistryModule } from 'common/registry';
import { StorageModule } from 'storage/storage.module';
import { ValidatorsModule } from 'validators';
import { StakingRouterFetchModule } from './contracts';
import { CuratedModuleService } from './curated-module.service';
import { StakingRouterService } from './staking-router.service';

Expand All @@ -17,6 +18,7 @@ import { StakingRouterService } from './staking-router.service';
}),
StorageModule,
ValidatorsModule,
StakingRouterFetchModule,
],
providers: [CuratedModuleService, StakingRouterService],
exports: [CuratedModuleService, StakingRouterService],
Expand Down
7 changes: 4 additions & 3 deletions src/staking-router-modules/staking-router.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { EntityManager } from '@mikro-orm/knex';
import { Inject, Injectable, InternalServerErrorException, LoggerService, NotFoundException } from '@nestjs/common';
import { LOGGER_PROVIDER } from '@lido-nestjs/logger';
import { ModuleRef } from '@nestjs/core';
import { StakingRouterFetchService } from 'common/contracts';
import { StakingRouterFetchService } from 'staking-router-modules/contracts';
import { ExecutionProviderService } from 'common/execution-provider';
import { KeysFilter } from './interfaces/keys-filter';

import { KeyEntity, OperatorEntity, StakingModuleInterface } from './interfaces/staking-module.interface';
import { httpExceptionTooEarlyResp } from 'http/common/entities/http-exceptions';
import { KeyWithModuleAddress } from 'http/keys/entities';
Expand All @@ -24,8 +24,9 @@ import {
VALIDATORS_REGISTRY_DISABLED_ERROR,
} from 'validators/validators.constants';
import { ValidatorsService } from 'validators';
import { KeyField } from './interfaces/key-fields';

import { PrometheusService } from 'common/prometheus';
import { KeyField, KeysFilter } from './interfaces/filters';

@Injectable()
export class StakingRouterService {
Expand Down
4 changes: 2 additions & 2 deletions src/storage/sr-module.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, EntityRepositoryType, PrimaryKey, PrimaryKeyType, Property, Unique } from '@mikro-orm/core';
import { StakingModule } from '../staking-router-modules/interfaces';
import { Entity, EntityRepositoryType, PrimaryKey, PrimaryKeyType, Property } from '@mikro-orm/core';
import { StakingModule } from '../staking-router-modules/interfaces/staking-module.interface';
import { SRModuleRepository } from './sr-module.repository';

@Entity({ customRepository: () => SRModuleRepository })
Expand Down
2 changes: 1 addition & 1 deletion src/storage/sr-module.storage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { QueryOrder } from '@mikro-orm/core';
import { FilterQuery, FindOptions } from '@mikro-orm/core';
import { Injectable } from '@nestjs/common';
import { StakingModule } from 'staking-router-modules/interfaces';
import { StakingModule } from '../staking-router-modules/interfaces/staking-module.interface';
import { SrModuleEntity } from './sr-module.entity';
import { SRModuleRepository } from './sr-module.repository';

Expand Down

0 comments on commit 6de1573

Please sign in to comment.