diff --git a/packages/asset-swapper/CHANGELOG.json b/packages/asset-swapper/CHANGELOG.json index 40a40ac97e..d535beb6eb 100644 --- a/packages/asset-swapper/CHANGELOG.json +++ b/packages/asset-swapper/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "16.63.1", + "changes": [ + { + "note": "Better error handling for balancer cache", + "pr": 515 + } + ] + }, { "version": "16.63.0", "changes": [ diff --git a/packages/asset-swapper/src/utils/market_operation_utils/pools_cache/balancer_utils.ts b/packages/asset-swapper/src/utils/market_operation_utils/pools_cache/balancer_utils.ts index 6493da644f..fac25ea671 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/pools_cache/balancer_utils.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/pools_cache/balancer_utils.ts @@ -2,6 +2,8 @@ import { getPoolsWithTokens, parsePoolData } from 'balancer-labs-sor-v1'; import { Pool } from 'balancer-labs-sor-v1/dist/types'; import { gql, request } from 'graphql-request'; +import { DEFAULT_WARNING_LOGGER } from '../../../constants'; +import { LogFunction } from '../../../types'; import { BALANCER_MAX_POOLS_FETCHED, BALANCER_SUBGRAPH_URL, BALANCER_TOP_POOLS_FETCHED } from '../constants'; import { CacheValue, PoolsCache } from './pools_cache'; @@ -24,6 +26,7 @@ export class BalancerPoolsCache extends PoolsCache { cache: { [key: string]: CacheValue } = {}, private readonly maxPoolsFetched: number = BALANCER_MAX_POOLS_FETCHED, private readonly _topPoolsFetched: number = BALANCER_TOP_POOLS_FETCHED, + private readonly _warningLogger: LogFunction = DEFAULT_WARNING_LOGGER, ) { super(cache); void this._loadTopPoolsAsync(); @@ -49,7 +52,14 @@ export class BalancerPoolsCache extends PoolsCache { [from: string]: { [to: string]: Pool[] }; } = {}; - const pools = await this._fetchTopPoolsAsync(); + let pools: BalancerPoolResponse[]; + try { + pools = await this._fetchTopPoolsAsync(); + } catch (err) { + this._warningLogger(err, 'Failed to fetch top pools for Balancer V1'); + return; + } + for (const pool of pools) { const { tokensList } = pool; for (const from of tokensList) { diff --git a/packages/asset-swapper/src/utils/market_operation_utils/pools_cache/balancer_v2_utils.ts b/packages/asset-swapper/src/utils/market_operation_utils/pools_cache/balancer_v2_utils.ts index 017e86aab0..2a406ed501 100644 --- a/packages/asset-swapper/src/utils/market_operation_utils/pools_cache/balancer_v2_utils.ts +++ b/packages/asset-swapper/src/utils/market_operation_utils/pools_cache/balancer_v2_utils.ts @@ -114,7 +114,14 @@ export class BalancerV2PoolsCache extends PoolsCache { [from: string]: { [to: string]: Pool[] }; } = {}; - const pools = await this._fetchTopPoolsAsync(); + let pools: BalancerPoolResponse[]; + try { + pools = await this._fetchTopPoolsAsync(); + } catch (err) { + this._warningLogger(err, 'Failed to fetch top pools for Balancer V2'); + return; + } + for (const pool of pools) { const { tokensList } = pool; for (const from of tokensList) {