Skip to content

Commit

Permalink
fix: don't throw when a liquidity position doesn't match a vault
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jackmellis committed Feb 12, 2024
1 parent 29ec500 commit 030c3ed
Showing 1 changed file with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,22 +16,16 @@ import getManager from './getManager';

const getVaultByTokens = <V extends Pick<Vault, 'id'>>({
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 =
Expand Down Expand Up @@ -71,25 +64,31 @@ export const makeFetchPositionsSet =
tokenIds,
});

const positions = await Promise.all(
data.positions.map(async (position): Promise<LiquidityPosition> => {
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,
})
);
})
);

Expand Down

0 comments on commit 030c3ed

Please sign in to comment.