diff --git a/src/utils/cache.ts b/src/utils/cache.ts index 91cdec47..de1cd92d 100644 --- a/src/utils/cache.ts +++ b/src/utils/cache.ts @@ -1,14 +1,14 @@ import { LRUCache } from "lru-cache"; import hash from "object-hash"; -const MAX_SIZE_BYTES = 100 * 1024 * 1024; +const MAX_SIZE_BYTES = 300 * 1024 * 1024; export const cache = new LRUCache({ maxSize: MAX_SIZE_BYTES, sizeCalculation: (value: any) => { return Buffer.byteLength(JSON.stringify(value), "utf8"); }, - ttl: 1000 * 600, + ttl: 100 * 60 * 12, }); interface APIEvent { diff --git a/src/utils/wrappa/postgres/query.ts b/src/utils/wrappa/postgres/query.ts index 5a734f35..2ade0749 100644 --- a/src/utils/wrappa/postgres/query.ts +++ b/src/utils/wrappa/postgres/query.ts @@ -366,19 +366,17 @@ const getNetflows = async (period: TimePeriod) => { return await sql<{ chain: string; net_flow: string }[]>` WITH period_flows AS ( SELECT - c.chain, + hv.chain, SUM(CASE - -- Deposits are outflows (-), withdrawals are inflows (+) - WHEN c.destination_chain IS NULL THEN (ha.total_withdrawn_usd - ha.total_deposited_usd) - -- For bridges with fixed destination chains, count flows on destination chain (inverted) - ELSE (ha.total_deposited_usd - ha.total_withdrawn_usd) + WHEN c.destination_chain IS NULL THEN (hv.total_withdrawn_usd - hv.total_deposited_usd) + ELSE (hv.total_deposited_usd - hv.total_withdrawn_usd) END) as net_flow - FROM bridges.hourly_aggregated ha - JOIN bridges.config c ON ha.bridge_id = c.id - WHERE ha.ts >= date_trunc(${period}, NOW() AT TIME ZONE 'UTC') - ${intervalPeriod} - AND ha.ts < date_trunc(${period}, NOW() AT TIME ZONE 'UTC') - AND LOWER(c.chain) NOT LIKE '%dydx%' - GROUP BY c.chain + FROM bridges.hourly_volume hv + JOIN bridges.config c ON hv.bridge_id = c.id + WHERE hv.ts >= date_trunc(${period}, NOW() AT TIME ZONE 'UTC') - ${intervalPeriod} + AND hv.ts < date_trunc(${period}, NOW() AT TIME ZONE 'UTC') + AND LOWER(hv.chain) NOT LIKE '%dydx%' + GROUP BY hv.chain ) SELECT chain,