Skip to content

Commit

Permalink
swaps sync cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Mar 8, 2024
1 parent 7802a85 commit c296f11
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions modules/actions/pool/sync-swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function syncSwaps(
const since = daysAgo(daysToSync);
const where =
latestEvent?.blockTimestamp && latestEvent?.blockTimestamp > since
? { blockNumber_gte: String(latestEvent.blockNumber) }
? { blockNumber_gt: String(latestEvent.blockNumber) }
: { blockTimestamp_gte: String(since) };

// Get events
Expand All @@ -49,19 +49,7 @@ export async function syncSwaps(
orderDirection: OrderDirection.Asc,
});

// Store only the events that are not already in the DB
const existingEvents = await prisma.poolEvent.findMany({
where: {
id: { in: swaps.map((event) => event.id) },
type: 'SWAP',
chain: chain,
vaultVersion,
},
});

const newSwaps = swaps.filter((event) => !existingEvents.some((existing) => existing.id === event.id));

const dbSwaps = newSwaps.map((swap) => swapTransformer(swap, chain));
const dbSwaps = swaps.map((swap) => swapTransformer(swap, chain));

// Enrich with USD values
const dbEntries = await swapsUsd(dbSwaps, chain);
Expand Down

0 comments on commit c296f11

Please sign in to comment.