From 0a4ad9c5dc9612d6933e61a4f5e51aa754bb6663 Mon Sep 17 00:00:00 2001 From: gmbronco <83549293+gmbronco@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:36:20 +0100 Subject: [PATCH] filter out balances for pools missing from the DB --- .changeset/wicked-moose-fold.md | 5 +++++ modules/actions/user/upsert-bpt-balances-v3.ts | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/wicked-moose-fold.md diff --git a/.changeset/wicked-moose-fold.md b/.changeset/wicked-moose-fold.md new file mode 100644 index 000000000..115680569 --- /dev/null +++ b/.changeset/wicked-moose-fold.md @@ -0,0 +1,5 @@ +--- +'backend': patch +--- + +filter out balances for missing pools diff --git a/modules/actions/user/upsert-bpt-balances-v3.ts b/modules/actions/user/upsert-bpt-balances-v3.ts index 5915d9f9d..852252527 100644 --- a/modules/actions/user/upsert-bpt-balances-v3.ts +++ b/modules/actions/user/upsert-bpt-balances-v3.ts @@ -6,7 +6,23 @@ import { poolShareToUserBalance } from '../../sources/transformers/pool-share-to export const upsertBptBalancesV3 = async (vaultSubgraphClient: V3VaultSubgraphClient, chain: Chain) => { const poolShares = await vaultSubgraphClient.getAllPoolShares(); - const dbEntries = poolShares.map((poolShare) => poolShareToUserBalance(poolShare, chain)); + let dbEntries = poolShares.map((poolShare) => poolShareToUserBalance(poolShare, chain)); + + // Temporary filter out balances that dont exist in the DB yet + await prisma.prismaPool + .findMany({ + where: { + chain, + protocolVersion: 3, + }, + select: { + id: true, + }, + }) + .then((pools) => pools.map(({ id }) => id)) + .then((ids) => { + dbEntries = dbEntries.filter((entry) => ids.includes(entry.poolId!)); + }); // wallet balances are related to users table, so we need to create all users records first await prisma.prismaUser.createMany({