diff --git a/src/api/api.module.ts b/src/api/api.module.ts new file mode 100644 index 0000000..140dd07 --- /dev/null +++ b/src/api/api.module.ts @@ -0,0 +1,19 @@ +import { Module } from '@nestjs/common'; +import { DatabaseModule } from '../database/database.module'; +import { PairLiquidityInfoHistoryController } from './pair-liquidity-info-history/pair-liquidity-info-history.controller'; +import { PairLiquidityInfoHistoryService } from './pair-liquidity-info-history/pair-liquidity-info-history.service'; +import { PairsController } from './pairs/pairs.controller'; +import { TokensController } from './tokens/tokens.controller'; +import { PairsService } from './pairs/pairs.service'; +import { TokensService } from './tokens/tokens.service'; + +@Module({ + imports: [DatabaseModule], + controllers: [ + PairLiquidityInfoHistoryController, + PairsController, + TokensController, + ], + providers: [PairLiquidityInfoHistoryService, PairsService, TokensService], +}) +export class ApiModule {} diff --git a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.module.ts b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.module.ts deleted file mode 100644 index b885608..0000000 --- a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.module.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Module } from '@nestjs/common'; -import { PairLiquidityInfoHistoryService } from './pair-liquidity-info-history.service'; -import { PairLiquidityInfoHistoryController } from './pair-liquidity-info-history.controller'; -import { DatabaseModule } from '../../database/database.module'; - -@Module({ - imports: [DatabaseModule], - controllers: [PairLiquidityInfoHistoryController], - providers: [PairLiquidityInfoHistoryService], -}) -export class PairLiquidityInfoHistoryModule {} diff --git a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.service.ts b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.service.ts index 0231391..fe56750 100644 --- a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.service.ts +++ b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { PairLiquidityInfoHistoryDbService } from '../../database/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryDbService } from '../../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; import { Pair, PairLiquidityInfoHistory } from '@prisma/client'; import { OrderQueryEnum } from '../../dto'; import { ContractAddress } from '../../lib/utils'; diff --git a/src/api/pairs/pairs.module.ts b/src/api/pairs/pairs.module.ts deleted file mode 100644 index 2e97984..0000000 --- a/src/api/pairs/pairs.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Module } from '@nestjs/common'; -import { PairsController } from './pairs.controller'; -import { PairsService } from './pairs.service'; - -@Module({ - imports: [], - controllers: [PairsController], - providers: [PairsService], -}) -export class PairsModule {} diff --git a/src/api/pairs/pairs.service.ts b/src/api/pairs/pairs.service.ts index 054656d..490f93e 100644 --- a/src/api/pairs/pairs.service.ts +++ b/src/api/pairs/pairs.service.ts @@ -1,30 +1,40 @@ import { Injectable } from '@nestjs/common'; -import * as dal from '../../dal'; import { presentInvalidTokens } from '../../lib/utils'; +import { PairDbService } from '../../database/pair/pair-db.service'; @Injectable() export class PairsService { + constructor(private readonly pairDbService: PairDbService) {} async getAllPairs(onlyListed?: boolean) { - return dal.pair.getAll(presentInvalidTokens, onlyListed); + return this.pairDbService.getAllWithCondition( + presentInvalidTokens, + onlyListed, + ); } async getAllPairsWithLiquidityInfo(onlyListed?: boolean) { - return dal.pair.getAllWithLiquidityInfo(presentInvalidTokens, onlyListed); + return this.pairDbService.getAllWithLiquidityInfo( + presentInvalidTokens, + onlyListed, + ); } async getCountStats() { return { - all: await dal.pair.count(presentInvalidTokens), - synced: await dal.pair.count(presentInvalidTokens, 'synchronized'), - listed: await dal.pair.count(presentInvalidTokens, 'listed'), + all: await this.pairDbService.count(presentInvalidTokens), + synced: await this.pairDbService.count( + presentInvalidTokens, + 'synchronized', + ), + listed: await this.pairDbService.count(presentInvalidTokens, 'listed'), }; } async getPair(address: string) { - return dal.pair.getOne(address); + return this.pairDbService.getOne(address); } async getTopHeight() { - return dal.pair.getTopHeight(); + return this.pairDbService.getTopHeight(); } } diff --git a/src/api/tokens/tokens.module.ts b/src/api/tokens/tokens.module.ts deleted file mode 100644 index 7695f41..0000000 --- a/src/api/tokens/tokens.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Module } from '@nestjs/common'; -import { TokensController } from './tokens.controller'; -import { TokensService } from './tokens.service'; - -@Module({ - imports: [], - controllers: [TokensController], - providers: [TokensService], -}) -export class TokensModule {} diff --git a/src/api/tokens/tokens.service.ts b/src/api/tokens/tokens.service.ts index 8aa17bb..5fd0151 100644 --- a/src/api/tokens/tokens.service.ts +++ b/src/api/tokens/tokens.service.ts @@ -1,26 +1,27 @@ import { Injectable } from '@nestjs/common'; -import * as dal from '../../dal'; -import { Pair, Token, PairLiquidityInfo } from '@prisma/client'; +import { Pair, PairLiquidityInfo, Token } from '@prisma/client'; import { ContractAddress, presentInvalidTokens } from '../../lib/utils'; +import { TokenDbService } from '../../database/token/token-db.service'; @Injectable() export class TokensService { + constructor(private readonly tokenDbService: TokenDbService) {} async getCount(onlyListed?: boolean) { - return dal.token.count(presentInvalidTokens, onlyListed); + return this.tokenDbService.count(presentInvalidTokens, onlyListed); } async getAllTokens(): Promise { - return dal.token.getAll(presentInvalidTokens); + return this.tokenDbService.getAll(presentInvalidTokens); } async getListedTokens(): Promise { - return dal.token.getListed(); + return this.tokenDbService.getListed(); } async listToken(address: ContractAddress) { - return dal.token.updateListedValue(address, true); + return this.tokenDbService.updateListedValue(address, true); } async unlistToken(address: ContractAddress) { - return dal.token.updateListedValue(address, false); + return this.tokenDbService.updateListedValue(address, false); } async getToken(address: ContractAddress): Promise< @@ -30,7 +31,7 @@ export class TokensService { }) | null > { - return dal.token.getByAddressWithPairs(address); + return this.tokenDbService.getByAddressWithPairs(address); } async getTokenWithPairsInfo(address: ContractAddress): Promise< @@ -46,6 +47,6 @@ export class TokensService { }) | null > { - return dal.token.getByAddressWithPairsAndLiquidity(address); + return this.tokenDbService.getByAddressWithPairsAndLiquidity(address); } } diff --git a/src/app.module.ts b/src/app.module.ts index f03e420..73855d5 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,23 +1,13 @@ import { Module } from '@nestjs/common'; -import { PairsModule } from './api/pairs/pairs.module'; -import { TokensModule } from './api/tokens/tokens.module'; import { AppController } from './app.controller'; import { DatabaseModule } from './database/database.module'; -import { TasksModule } from './tasks/tasks.module'; import { TokensService } from './api/tokens/tokens.service'; import { PairsService } from './api/pairs/pairs.service'; import { ClientsModule } from './clients/clients.module'; -import { PairLiquidityInfoHistoryModule } from './api/pair-liquidity-info-history/pair-liquidity-info-history.module'; +import { ApiModule } from './api/api.module'; @Module({ - imports: [ - PairsModule, - TokensModule, - ClientsModule, - DatabaseModule, - TasksModule, - PairLiquidityInfoHistoryModule, - ], + imports: [ApiModule, ClientsModule, DatabaseModule], controllers: [AppController], providers: [TokensService, PairsService], }) diff --git a/src/database/database.module.ts b/src/database/database.module.ts index 77f4c30..c763164 100644 --- a/src/database/database.module.ts +++ b/src/database/database.module.ts @@ -1,8 +1,9 @@ import { Module } from '@nestjs/common'; import { PrismaService } from './prisma.service'; -import { PairDbService } from './pair-db.service'; -import { PairLiquidityInfoHistoryDbService } from './pair-liquidity-info-history-db.service'; -import { PairLiquidityInfoHistoryErrorDbService } from './pair-liquidity-info-history-error-db.service'; +import { PairDbService } from './pair/pair-db.service'; +import { PairLiquidityInfoHistoryDbService } from './pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryErrorDbService } from './pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; +import { TokenDbService } from './token/token-db.service'; @Module({ providers: [ @@ -10,11 +11,13 @@ import { PairLiquidityInfoHistoryErrorDbService } from './pair-liquidity-info-hi PairDbService, PairLiquidityInfoHistoryDbService, PairLiquidityInfoHistoryErrorDbService, + TokenDbService, ], exports: [ PairDbService, PairLiquidityInfoHistoryDbService, PairLiquidityInfoHistoryErrorDbService, + TokenDbService, ], }) export class DatabaseModule {} diff --git a/src/database/pair-db.service.ts b/src/database/pair-db.service.ts deleted file mode 100644 index 86bc450..0000000 --- a/src/database/pair-db.service.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { Pair, Token } from '@prisma/client'; -import { PrismaService } from './prisma.service'; - -export type PairWithTokens = { token0: Token; token1: Token } & Pair; - -@Injectable() -export class PairDbService { - constructor(private prisma: PrismaService) {} - getAll(): Promise { - return this.prisma.pair.findMany({ - orderBy: [{ id: 'asc' }], - include: { - token0: true, - token1: true, - }, - }); - } -} diff --git a/src/database/pair-liquidity-info-history-error-db.service.e2e-spec.ts b/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.e2e-spec.ts similarity index 98% rename from src/database/pair-liquidity-info-history-error-db.service.e2e-spec.ts rename to src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.e2e-spec.ts index fe6269a..bcb71af 100644 --- a/src/database/pair-liquidity-info-history-error-db.service.e2e-spec.ts +++ b/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.e2e-spec.ts @@ -1,5 +1,5 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { PrismaService } from './prisma.service'; +import { PrismaService } from '../prisma.service'; import { Pair, PairLiquidityInfoHistoryError, Token } from '@prisma/client'; import { PairLiquidityInfoHistoryErrorDbService } from './pair-liquidity-info-history-error-db.service'; diff --git a/src/database/pair-liquidity-info-history-error-db.service.ts b/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.ts similarity index 96% rename from src/database/pair-liquidity-info-history-error-db.service.ts rename to src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.ts index 9582993..b1c8b9f 100644 --- a/src/database/pair-liquidity-info-history-error-db.service.ts +++ b/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { PrismaService } from './prisma.service'; +import { PrismaService } from '../prisma.service'; import { PairLiquidityInfoHistoryError } from '@prisma/client'; @Injectable() diff --git a/src/database/pair-liquidity-info-history-db.service.e2e-spec.ts b/src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.e2e-spec.ts similarity index 97% rename from src/database/pair-liquidity-info-history-db.service.e2e-spec.ts rename to src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.e2e-spec.ts index acec1c7..9c63ddd 100644 --- a/src/database/pair-liquidity-info-history-db.service.e2e-spec.ts +++ b/src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.e2e-spec.ts @@ -1,9 +1,9 @@ import { PairLiquidityInfoHistoryDbService } from './pair-liquidity-info-history-db.service'; import { Test, TestingModule } from '@nestjs/testing'; -import { PrismaService } from './prisma.service'; +import { PrismaService } from '../prisma.service'; import { Pair, PairLiquidityInfoHistory, Token } from '@prisma/client'; -import { OrderQueryEnum } from '../dto'; -import { ContractAddress } from '../lib/utils'; +import { OrderQueryEnum } from '../../dto'; +import { ContractAddress } from '../../lib/utils'; const token1: Token = { id: 1, diff --git a/src/database/pair-liquidity-info-history-db.service.ts b/src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.ts similarity index 93% rename from src/database/pair-liquidity-info-history-db.service.ts rename to src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.ts index df441c3..5741447 100644 --- a/src/database/pair-liquidity-info-history-db.service.ts +++ b/src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.ts @@ -1,8 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { PrismaService } from './prisma.service'; +import { PrismaService } from '../prisma.service'; import { PairLiquidityInfoHistory } from '@prisma/client'; -import { OrderQueryEnum } from '../dto'; -import { ContractAddress } from '../lib/utils'; +import { OrderQueryEnum } from '../../dto'; +import { ContractAddress } from '../../lib/utils'; @Injectable() export class PairLiquidityInfoHistoryDbService { diff --git a/src/database/pair/pair-db.service.ts b/src/database/pair/pair-db.service.ts new file mode 100644 index 0000000..b725f50 --- /dev/null +++ b/src/database/pair/pair-db.service.ts @@ -0,0 +1,176 @@ +import { Injectable } from '@nestjs/common'; +import { Pair, Token } from '@prisma/client'; +import { PrismaService } from '../prisma.service'; +import { validTokenCondition } from '../../dal/token'; +import { ContractAddress } from '../../lib/utils'; + +export type PairWithTokens = { token0: Token; token1: Token } & Pair; +export type CountMode = 'all' | 'listed' | 'synchronized'; + +@Injectable() +export class PairDbService { + constructor(private prisma: PrismaService) {} + getAll(): Promise { + return this.prisma.pair.findMany({ + orderBy: [{ id: 'asc' }], + include: { + token0: true, + token1: true, + }, + }); + } + + getAllWithCondition(showInvalidTokens: boolean, onlyListed?: boolean) { + return this.prisma.pair.findMany({ + where: this.tokensCondition(showInvalidTokens, onlyListed), + include: { + token0: true, + token1: true, + }, + }); + } + + async getAllAddresses() { + return ( + await this.prisma.pair.findMany({ + select: { + address: true, + }, + }) + ).map((x) => x.address as ContractAddress); + } + + async getTopHeight() { + return ( + await this.prisma.pairLiquidityInfo.aggregate({ + _max: { height: true }, + }) + )._max.height; + } + + getAllWithLiquidityInfo(showInvalidTokens: boolean, onlyListed?: boolean) { + return this.prisma.pair.findMany({ + where: this.tokensCondition(showInvalidTokens, onlyListed), + include: { + token0: true, + token1: true, + liquidityInfo: true, + }, + }); + } + + getOne(address: string) { + return this.prisma.pair.findUnique({ + where: { address }, + include: { token0: true, token1: true, liquidityInfo: true }, + }); + } + + getOneLite(address: string) { + return this.prisma.pair.findUnique({ + where: { address }, + }); + } + + count(showInvalidTokens: boolean, mode?: CountMode) { + return this.prisma.pair.count({ + where: { + ...this.tokensCondition(showInvalidTokens, mode === 'listed'), + ...(mode === 'synchronized' ? { synchronized: true } : {}), + }, + }); + } + + insert(address: string, token0: number, token1: number) { + return this.prisma.pair.create({ + data: { + address, + t0: token0, + t1: token1, + liquidityInfo: undefined, + synchronized: false, + }, + }); + } + + insertByTokenAddresses( + address: string, + token0: ContractAddress, + token1: ContractAddress, + ) { + return this.prisma.pair.create({ + select: { + id: true, + address: true, + token0: true, + token1: true, + liquidityInfo: false, + synchronized: false, + }, + data: { + address, + token0: { connect: { address: token0 } }, + token1: { connect: { address: token1 } }, + liquidityInfo: undefined, + synchronized: false, + }, + }); + } + + synchronise( + pairId: number, + totalSupply: bigint, + reserve0: bigint, + reserve1: bigint, + height: number, + ) { + const update = { + totalSupply: totalSupply.toString(), + reserve0: reserve0.toString(), + reserve1: reserve1.toString(), + height, + }; + return this.prisma.pair.update({ + where: { id: pairId }, + select: { + id: true, + address: true, + token0: true, + token1: true, + liquidityInfo: true, + synchronized: true, + }, + data: { + liquidityInfo: { upsert: { update, create: update } }, + synchronized: true, + }, + }); + } + + unsyncAllPairs() { + return this.prisma.pair.updateMany({ + data: { synchronized: false }, + }); + } + + private tokenCondition = ( + showInvalidTokens: boolean, + onlyListed?: boolean, + ) => ({ + is: { + ...(onlyListed ? { listed: true } : {}), + ...(showInvalidTokens ? {} : validTokenCondition), + }, + }); + + private tokensCondition = ( + showInvalidTokens: boolean, + onlyListed?: boolean, + ) => { + const condition = this.tokenCondition(showInvalidTokens, !!onlyListed); + return { + token0: condition, + token1: condition, + }; + }; +} diff --git a/src/database/token/token-db.service.ts b/src/database/token/token-db.service.ts new file mode 100644 index 0000000..2acd3da --- /dev/null +++ b/src/database/token/token-db.service.ts @@ -0,0 +1,122 @@ +import { Injectable } from '@nestjs/common'; +import { PrismaService } from '../prisma.service'; +import { Token } from '@prisma/client'; +import { ContractAddress } from '../../lib/utils'; + +@Injectable() +export class TokenDbService { + constructor(private prisma: PrismaService) {} + + getAll(showInvalidTokens: boolean): Promise { + return this.prisma.token.findMany({ + where: showInvalidTokens ? {} : this.validTokenCondition, + }); + } + + getListed(): Promise { + //there is no reason to list invalid tokens + return this.prisma.token.findMany({ + where: { ...this.validTokenCondition, listed: true }, + }); + } + + getByAddress(address: string) { + return this.prisma.token.findFirst({ + where: { address }, + }); + } + + async updateListedValue(address: string, listed: boolean) { + //ensure the token is valid in order to be listed + if (listed) { + const exists = await this.prisma.token.findFirst({ + where: { address }, + select: { malformed: true, noContract: true }, + }); + if (exists?.malformed || exists?.noContract) { + throw new Error("An invalid token can't be listed"); + } + } + return this.prisma.token.update({ + //we don't want to list invalid tokens + where: { address }, + data: { listed }, + }); + } + + getByAddressWithPairs(address: string) { + return this.prisma.token.findFirst({ + where: { address }, + include: { pairs0: true, pairs1: true }, + }); + } + + count(showInvalidTokens: boolean, onlyListed?: boolean) { + return this.prisma.token.count({ + where: { + ...(onlyListed ? { listed: true } : {}), + ...(() => (showInvalidTokens ? {} : this.validTokenCondition))(), + }, + }); + } + + getByAddressWithPairsAndLiquidity(address: string) { + return this.prisma.token.findFirst({ + where: { address }, + include: { + pairs0: { include: { token1: true, liquidityInfo: true } }, + pairs1: { include: { token0: true, liquidityInfo: true } }, + }, + }); + } + + async getAllAddresses( + showInvalidTokens: boolean, + ): Promise { + return ( + await this.prisma.token.findMany({ + where: showInvalidTokens ? {} : this.validTokenCondition, + select: { + address: true, + }, + }) + ).map((x) => x.address as ContractAddress); + } + + upsertToken( + address: string, + symbol: string, + name: string, + decimals: number, + ): Promise { + return this.commonUpsert(address, { + symbol, + name, + decimals, + noContract: false, + malformed: false, + }); + } + upsertMalformedToken(address: string): Promise { + return this.commonUpsert(address, { malformed: true, noContract: false }); + } + + upsertNoContractForToken(address: string): Promise { + return this.commonUpsert(address, { malformed: false, noContract: true }); + } + + private commonUpsert( + address: string, + common: Partial, + ): Promise { + return this.prisma.token.upsert({ + where: { + address, + }, + update: common, + create: { address, ...common }, + }); + } + + private validTokenCondition = { malformed: false, noContract: false }; +} diff --git a/src/tasks/pair-liquidity-info-history-importer.service.spec.ts b/src/tasks/pair-liquidity-info-history-importer.service.spec.ts index 7dafb7b..fb70e16 100644 --- a/src/tasks/pair-liquidity-info-history-importer.service.spec.ts +++ b/src/tasks/pair-liquidity-info-history-importer.service.spec.ts @@ -1,9 +1,9 @@ import { PairLiquidityInfoHistoryImporterService } from './pair-liquidity-info-history-importer.service'; import { Test, TestingModule } from '@nestjs/testing'; import { MdwClientService } from '../clients/mdw-client.service'; -import { PairDbService } from '../database/pair-db.service'; -import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history-db.service'; -import { PairLiquidityInfoHistoryErrorDbService } from '../database/pair-liquidity-info-history-error-db.service'; +import { PairDbService } from '../database/pair/pair-db.service'; +import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryErrorDbService } from '../database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; import { ContractAddress } from '../lib/utils'; import { Contract } from '../clients/mdw-client.model'; diff --git a/src/tasks/pair-liquidity-info-history-importer.service.ts b/src/tasks/pair-liquidity-info-history-importer.service.ts index 57cdada..a3c9042 100644 --- a/src/tasks/pair-liquidity-info-history-importer.service.ts +++ b/src/tasks/pair-liquidity-info-history-importer.service.ts @@ -1,14 +1,17 @@ import { Injectable, Logger } from '@nestjs/common'; import { MdwClientService } from '../clients/mdw-client.service'; -import { PairDbService, PairWithTokens } from '../database/pair-db.service'; +import { + PairDbService, + PairWithTokens, +} from '../database/pair/pair-db.service'; import { isEqual, orderBy, uniqWith } from 'lodash'; -import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; import { ContractAddress, contractAddrToAccountAddr, MicroBlockHash, } from '../lib/utils'; -import { PairLiquidityInfoHistoryErrorDbService } from '../database/pair-liquidity-info-history-error-db.service'; +import { PairLiquidityInfoHistoryErrorDbService } from '../database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; import { getClient } from '../lib/contracts'; import { ContractLog } from '../clients/mdw-client.model'; diff --git a/src/tasks/pair-liquidity-info-history-validator.service.spec.ts b/src/tasks/pair-liquidity-info-history-validator.service.spec.ts index 17039d7..0cbd0fb 100644 --- a/src/tasks/pair-liquidity-info-history-validator.service.spec.ts +++ b/src/tasks/pair-liquidity-info-history-validator.service.spec.ts @@ -1,7 +1,7 @@ import { PairLiquidityInfoHistoryValidatorService } from './pair-liquidity-info-history-validator.service'; import { Test, TestingModule } from '@nestjs/testing'; import { MdwClientService } from '../clients/mdw-client.service'; -import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; const mockMdwClientService = { getKeyBlockMicroBlocks: jest.fn(), diff --git a/src/tasks/pair-liquidity-info-history-validator.service.ts b/src/tasks/pair-liquidity-info-history-validator.service.ts index b81d36f..b254cf7 100644 --- a/src/tasks/pair-liquidity-info-history-validator.service.ts +++ b/src/tasks/pair-liquidity-info-history-validator.service.ts @@ -1,5 +1,5 @@ import { MdwClientService } from '../clients/mdw-client.service'; -import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; import { Injectable, Logger } from '@nestjs/common'; import { uniq } from 'lodash'; import { getClient } from '../lib/contracts'; diff --git a/src/tasks/tasks.service.spec.ts b/src/tasks/tasks.service.spec.ts index c8068dc..8d316fc 100644 --- a/src/tasks/tasks.service.spec.ts +++ b/src/tasks/tasks.service.spec.ts @@ -3,9 +3,9 @@ import { TasksService } from './tasks.service'; import { PairLiquidityInfoHistoryImporterService } from './pair-liquidity-info-history-importer.service'; import { PairLiquidityInfoHistoryValidatorService } from './pair-liquidity-info-history-validator.service'; import { MdwClientService } from '../clients/mdw-client.service'; -import { PairDbService } from '../database/pair-db.service'; -import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history-db.service'; -import { PairLiquidityInfoHistoryErrorDbService } from '../database/pair-liquidity-info-history-error-db.service'; +import { PairDbService } from '../database/pair/pair-db.service'; +import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryErrorDbService } from '../database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; import { PrismaService } from '../database/prisma.service'; describe('TasksService', () => { diff --git a/test/pairs.e2e-spec.ts b/test/pairs.e2e-spec.ts index 567d68d..2cef85b 100644 --- a/test/pairs.e2e-spec.ts +++ b/test/pairs.e2e-spec.ts @@ -5,8 +5,7 @@ import { listToken, mockContext, sortByAddress } from './utils'; import createWorkerMethods from '../src/worker'; import * as data from './data/context-mockups'; import * as db from './utils/db'; -import { TokensModule } from '../src/api/tokens/tokens.module'; -import { PairsModule } from '../src/api/pairs/pairs.module'; +import { ApiModule } from '../src/api/api.module'; type WorkerMethods = ReturnType; let activeWorker: WorkerMethods; @@ -30,7 +29,7 @@ describe('pairs fetching (e2e)', () => { beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [TokensModule, PairsModule], + imports: [ApiModule], }).compile(); app = moduleFixture.createNestApplication(); diff --git a/test/swap-routes.e2e-spec.ts b/test/swap-routes.e2e-spec.ts index 1f92ccf..0c6fb4a 100644 --- a/test/swap-routes.e2e-spec.ts +++ b/test/swap-routes.e2e-spec.ts @@ -6,8 +6,7 @@ import { listToken, mockContext } from './utils'; import worker from '../src/worker'; import * as db from './utils/db'; import * as data from './data/context-mockups'; -import { TokensModule } from '../src/api/tokens/tokens.module'; -import { PairsModule } from '../src/api/pairs/pairs.module'; +import { ApiModule } from '../src/api/api.module'; type WorkerMethods = ReturnType; let activeWorker: WorkerMethods; @@ -29,7 +28,7 @@ const initWorker = async (dataCtx: any) => { const initApp = async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [TokensModule, PairsModule], + imports: [ApiModule], }).compile(); app = moduleFixture.createNestApplication(); diff --git a/test/tokens.e2e-spec.ts b/test/tokens.e2e-spec.ts index e04c4ef..8af3189 100644 --- a/test/tokens.e2e-spec.ts +++ b/test/tokens.e2e-spec.ts @@ -8,8 +8,7 @@ import * as data from './data/context-mockups'; import * as dto from '../src/dto'; import * as utils from './utils'; import { nonNullable } from '../src/lib/utils'; -import { TokensModule } from '../src/api/tokens/tokens.module'; -import { PairsModule } from '../src/api/pairs/pairs.module'; +import { ApiModule } from '../src/api/api.module'; type WorkerMethods = ReturnType; let activeWorker: WorkerMethods; @@ -33,7 +32,7 @@ describe('tokens fetching (e2e)', () => { beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [TokensModule, PairsModule], + imports: [ApiModule], }).compile(); app = moduleFixture.createNestApplication(); @@ -487,7 +486,7 @@ describe('listed tokens management (e2e)', () => { beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [TokensModule, PairsModule], + imports: [ApiModule], }).compile(); app = moduleFixture.createNestApplication();