From a943619cbba09fc03e51e7311b74fac706e9e7e3 Mon Sep 17 00:00:00 2001 From: Florent Tapponnier <160007691+Flotapponnier@users.noreply.github.com> Date: Wed, 26 Aug 2026 21:23:38 +0200 Subject: [PATCH] fix: dYdX drop inaccurate funding, takers-only fills, timeout 50s, Gains 6 pages - Remove perpetualPositions funding fetch (not date-scopable, cumulative all-time) - dYdX fills count = takers only (consistent with fee/notional calc) - maxDuration 30 -> 50 to cover paginated fetches in parallel - Gains MAX_PAGES 10 -> 6 (600 trades, safer budget) - Footnote: note dYdX funding excluded --- src/app/api/fee-compare/route.ts | 29 ++++++--------------------- src/components/fee-compare-client.tsx | 3 +-- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/app/api/fee-compare/route.ts b/src/app/api/fee-compare/route.ts index b1c1c7e1..f13b0730 100644 --- a/src/app/api/fee-compare/route.ts +++ b/src/app/api/fee-compare/route.ts @@ -3,7 +3,7 @@ import { clientKey, rateLimit, tooManyRequests } from "@/lib/rate-limit"; import { keccak256 } from "js-sha3"; export const runtime = "nodejs"; -export const maxDuration = 30; +export const maxDuration = 50; const HL_API = "https://api.hyperliquid.xyz/info"; const GAINS_VARS_URL = "https://backend-arbitrum.gains.trade/trading-variables"; @@ -499,23 +499,7 @@ async function fetchDydxFills(dydxAddress: string, cutoffMs: number): Promise; - }; - for (const p of pfBody.positions ?? []) { - fundingUsd += parseFloat(p.netFunding ?? "0"); - } - } - } catch { /* funding is optional */ } - + // Only count taker fills — maker fees are rebates and distort the comparison const takers = allFills.filter((f) => (f.liquidity ?? "").toUpperCase() !== "MAKER"); let feesUsdc = 0; let notionalUsd = 0; @@ -523,13 +507,12 @@ async function fetchDydxFills(dydxAddress: string, cutoffMs: number): Promise 0 ? (feesUsdc / notionalUsd) * 10000 : 0, }; @@ -540,7 +523,7 @@ async function fetchGainsTrades(wallet: string, cutoffMs: number): Promise - dYdX v4: public indexer with full pagination and date filter. Funding from{" "} - perpetualPositions.netFunding. Address must be{" "} + dYdX v4: public indexer with full pagination and date filter. Taker fills only. Funding excluded (not date-scopable from public API). Address must be{" "} dydx1... Cosmos format.{" "} )}