diff --git a/apps/whale-api/src/module.indexer/model/dftx/composite.swap.ts b/apps/whale-api/src/module.indexer/model/dftx/composite.swap.ts index e8358b973a..29306bc03d 100644 --- a/apps/whale-api/src/module.indexer/model/dftx/composite.swap.ts +++ b/apps/whale-api/src/module.indexer/model/dftx/composite.swap.ts @@ -4,7 +4,6 @@ import { RawBlock } from '../_abstract' import { Inject, Injectable } from '@nestjs/common' import { NetworkName } from '@defichain/jellyfish-network' import BigNumber from 'bignumber.js' -import { IndexerError } from '../../error' import { PoolPairPathMapping } from './pool.pair.path.mapping' import { PoolSwapIndexer } from './pool.swap' @@ -51,10 +50,6 @@ export class CompositeSwapIndexer extends DfTxIndexer { const poolSwap = compositeSwap.poolSwap const pair = await this.poolPairPathMapping.findPair(poolSwap.fromTokenId, poolSwap.toTokenId) - if (pair !== undefined) { - return [{ id: Number(pair.id) }] - } - - throw new IndexerError(`Pool for pair ${poolSwap.fromTokenId}, ${poolSwap.toTokenId} not found in PoolPairPathMapping`) + return [{ id: Number(pair.id) }] } } diff --git a/apps/whale-api/src/module.indexer/model/dftx/pool.pair.path.mapping.ts b/apps/whale-api/src/module.indexer/model/dftx/pool.pair.path.mapping.ts index 050c52b94f..e32506b4b1 100644 --- a/apps/whale-api/src/module.indexer/model/dftx/pool.pair.path.mapping.ts +++ b/apps/whale-api/src/module.indexer/model/dftx/pool.pair.path.mapping.ts @@ -1,8 +1,9 @@ -import { Injectable } from '@nestjs/common' +import { Injectable, Logger } from '@nestjs/common' import { DeFiDCache, PoolPairInfoWithId } from '../../../module.api/cache/defid.cache' @Injectable() export class PoolPairPathMapping { + private readonly logger = new Logger(PoolPairPathMapping.name) private readonly paths: Record = {} constructor ( @@ -10,13 +11,17 @@ export class PoolPairPathMapping { ) { } - async findPair (tokenA: number, tokenB: number): Promise { + async findPair (tokenA: number, tokenB: number): Promise { const pair = this.paths[`${tokenA}-${tokenB}`] if (pair !== undefined) { return pair } await this.updateMapping() + if (this.paths[`${tokenA}-${tokenB}`] === undefined) { + this.logger.error(`Pool for pair ${tokenA}, ${tokenB} not found in PoolPairPathMapping`) + await this.findPair(tokenA, tokenB) + } return this.paths[`${tokenA}-${tokenB}`] } diff --git a/apps/whale-api/src/module.indexer/model/dftx/pool.swap.ts b/apps/whale-api/src/module.indexer/model/dftx/pool.swap.ts index 881ff707b4..c7b91afcb9 100644 --- a/apps/whale-api/src/module.indexer/model/dftx/pool.swap.ts +++ b/apps/whale-api/src/module.indexer/model/dftx/pool.swap.ts @@ -9,7 +9,6 @@ import { HexEncoder } from '../../../module.model/_hex.encoder' import { PoolSwapAggregatedMapper } from '../../../module.model/pool.swap.aggregated' import { AggregatedIntervals } from './pool.swap.aggregated' import { PoolPairInfoWithId } from '../../../module.api/cache/defid.cache' -import { IndexerError } from '../../error' import { PoolPairPathMapping } from './pool.pair.path.mapping' @Injectable() @@ -89,11 +88,6 @@ export class PoolSwapIndexer extends DfTxIndexer { } async getPair (tokenA: number, tokenB: number): Promise { - const pair = await this.poolPairPathMapping.findPair(tokenA, tokenB) - if (pair !== undefined) { - return pair - } - - throw new IndexerError(`Pool for pair ${tokenA}, ${tokenB} not found in PoolPairPathMapping`) + return await this.poolPairPathMapping.findPair(tokenA, tokenB) } }