From 030c3edac1e5fa0d62ca8b65d30a8fcc6e55abad Mon Sep 17 00:00:00 2001 From: Jack Ellis Date: Mon, 12 Feb 2024 15:01:31 +0000 Subject: [PATCH] fix: don't throw when a liquidity position doesn't match a vault some of the positions returned by the subgraph don't match any vaults, e.g. there's a USDC/WETH pair owned by several wallets so if a vault can't be found, rathe than throw an error (and fail to return any positions) we should just ignore those positions and continue --- .../fetchPositionsSet.ts | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/core/src/positions/fetchLiquidityPositions/fetchPositionsSet.ts b/packages/core/src/positions/fetchLiquidityPositions/fetchPositionsSet.ts index f78df56..bf694a7 100644 --- a/packages/core/src/positions/fetchLiquidityPositions/fetchPositionsSet.ts +++ b/packages/core/src/positions/fetchLiquidityPositions/fetchPositionsSet.ts @@ -8,7 +8,6 @@ import type { import queryPositionData from './queryPositionData'; import { addressEqual } from '@nftx/utils'; import transformPosition from './transformPosition'; -import { NotFoundError } from '@nftx/errors'; import fetchClaimableAmount from './fetchClaimableAmount'; type QueryPositionData = typeof queryPositionData; @@ -17,22 +16,16 @@ import getManager from './getManager'; const getVaultByTokens = >({ inputTokens, - position, vaults, }: { vaults: V[]; inputTokens: { id: string }[]; - position: { id: string }; }) => { - const vault = vaults.find((vault) => { + return vaults.find((vault) => { return inputTokens.some((inputToken) => { return addressEqual(inputToken.id, vault.id); }); }); - if (vault == null) { - throw new NotFoundError('vault for position', position.id); - } - return vault; }; export const makeFetchPositionsSet = @@ -71,25 +64,31 @@ export const makeFetchPositionsSet = tokenIds, }); - const positions = await Promise.all( - data.positions.map(async (position): Promise => { + const positions: LiquidityPosition[] = []; + + await Promise.all( + data.positions.map(async (position) => { const vault = getVaultByTokens({ inputTokens: position.pool.inputTokens, - position, vaults, }); + if (!vault) { + return; + } const [claimable0, claimable1] = await fetchClaimableAmount({ tokenId: position.tokenId as TokenId, provider, manager: getManager(network, position).manager, }); - return transformPosition({ - network, - position, - vault, - claimable0, - claimable1, - }); + positions.push( + transformPosition({ + network, + position, + vault, + claimable0, + claimable1, + }) + ); }) );