diff --git a/src/app/api/fee-compare/route.ts b/src/app/api/fee-compare/route.ts index d6d53301..dde1e296 100644 --- a/src/app/api/fee-compare/route.ts +++ b/src/app/api/fee-compare/route.ts @@ -1260,7 +1260,8 @@ async function fetchHlFundingHistory( } // Compute projected HL funding cost for a set of position slices. -// Uses absolute funding rates so direction doesn't matter for the projection. +// Returns signed net: positive = wallet pays, negative = wallet receives. +// Rate > 0 = longs pay; < 0 = shorts pay (HL convention). function computeHlFunding( positions: PositionSlice[], history: Map> @@ -1270,10 +1271,10 @@ function computeHlFunding( const rates = (history.get(pos.coin) ?? []).filter( (r) => r.time >= pos.openMs && r.time <= pos.closeMs ); - // Each HL funding entry = one 8h interval. Rate > 0 = longs pay; < 0 = shorts pay. for (const r of rates) { + // positive cost = this position is on the paying side const cost = pos.isLong ? r.rate : -r.rate; - total += pos.notionalUsd * Math.max(0, cost); + total += pos.notionalUsd * cost; } } return total; @@ -1683,7 +1684,7 @@ export async function GET(req: Request) { borrowFees: 0, fundingFees: hlFunding, borrowProjected: false, - fundingProjected: hlFunding > 0.01, + fundingProjected: Math.abs(hlFunding) > 0.01, }; } @@ -1821,9 +1822,9 @@ export async function GET(req: Request) { projectedCarry = { takerFees, borrowFees: 0, - fundingFees: hlFunding, + fundingFees: hlFunding, // signed: positive = pays, negative = receives borrowProjected: false, - fundingProjected: hlFunding > 0.01, + fundingProjected: Math.abs(hlFunding) > 0.01, }; } diff --git a/src/components/fee-compare-client.tsx b/src/components/fee-compare-client.tsx index be240467..ce765c3f 100644 --- a/src/components/fee-compare-client.tsx +++ b/src/components/fee-compare-client.tsx @@ -560,7 +560,7 @@ function WalletSide({ if (crossSim) { const carry = crossSim.projectedCarry; const takerFees = carry ? carry.takerFees : crossSim.equivFees; - const hasCarry = carry && (carry.borrowFees > 0.01 || carry.fundingFees > 0.01); + const hasCarry = carry && (carry.borrowFees > 0.01 || Math.abs(carry.fundingFees) > 0.01); const netLabel = hasCarry ? "incl. est. carry" : carry @@ -602,18 +602,24 @@ function WalletSide({

+{fmtUsd(carry.borrowFees)}

)} - {carry && carry.borrowProjected === false && carry.fundingFees < 0.01 && ( + {carry && carry.borrowProjected === false && Math.abs(carry.fundingFees) < 0.01 && (

Borrowing fees

not applicable

)} - {carry && carry.fundingFees > 0.01 && ( + {carry && carry.fundingProjected && carry.fundingFees > 0.01 && (

Est. funding (projected)

+{fmtUsd(carry.fundingFees)}

)} + {carry && carry.fundingProjected && carry.fundingFees < -0.01 && ( +
+

Est. funding (projected)

+

−{fmtUsd(Math.abs(carry.fundingFees))} received

+
+ )} {carry && !carry.fundingProjected && carry.borrowFees > 0.01 && (

Funding

@@ -691,11 +697,11 @@ function WalletSide({ {/* Venue-specific extra stats */} {venue.slug === "hyperliquid" && (() => { const hlW = w as HlWalletData; - const hasFunding = Math.abs(hlW.fundingUsd) > 0.5; + const hasFunding = Math.abs(hlW.fundingUsd) > 0.01; return (
-

Volume

+

Total position value

{fmtUsd(volume)}

@@ -766,7 +772,7 @@ function WalletSide({ )} {hasBorrowing && (
-

Borrowing fees

+

Borrowing fees (vault)

−{fmtUsd(gW.borrowingFeesUsdc)}