Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/app/api/fee-compare/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@
}

// Estimate GMX borrow fees for a set of position slices.
function estimateGmxBorrowFees(

Check warning on line 1215 in src/app/api/fee-compare/route.ts

View workflow job for this annotation

GitHub Actions / check

'estimateGmxBorrowFees' is defined but never used
positions: PositionSlice[],
borrowPerSecPerCoin: Record<string, number>
): number {
Expand Down Expand Up @@ -1260,7 +1260,8 @@
}

// 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<string, Array<{ time: number; rate: number }>>
Expand All @@ -1270,10 +1271,10 @@
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;
Expand Down Expand Up @@ -1519,7 +1520,7 @@
: fill.notional * otherRate,
}));
} else if (fetchEvmWallet && slug === "gains") {
const CLOSE_ACTIONS = new Set(["TradeClosedMarket", "TradeClosedTP", "TradeClosedSL", "TradeClosedLIQ"]);

Check warning on line 1523 in src/app/api/fee-compare/route.ts

View workflow job for this annotation

GitHub Actions / check

'CLOSE_ACTIONS' is assigned a value but never used
const usdcTrades = gainsTradesData.filter((t) => t.collateralIndex === 3);
const otherSlug = slug === venueA ? venueB : venueA;
const otherRate = slug === venueA ? rateB : rateA;
Expand Down Expand Up @@ -1683,7 +1684,7 @@
borrowFees: 0,
fundingFees: hlFunding,
borrowProjected: false,
fundingProjected: hlFunding > 0.01,
fundingProjected: Math.abs(hlFunding) > 0.01,
};
}

Expand Down Expand Up @@ -1821,9 +1822,9 @@
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,
};
}

Expand Down
18 changes: 12 additions & 6 deletions src/components/fee-compare-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -602,18 +602,24 @@ function WalletSide({
<p className="font-mono text-xs font-semibold text-red-400">+{fmtUsd(carry.borrowFees)}</p>
</div>
)}
{carry && carry.borrowProjected === false && carry.fundingFees < 0.01 && (
{carry && carry.borrowProjected === false && Math.abs(carry.fundingFees) < 0.01 && (
<div className="flex items-center justify-between">
<p className="text-[11px] text-ink-faint">Borrowing fees</p>
<p className="text-[11px] text-ink-faint/50 italic">not applicable</p>
</div>
)}
{carry && carry.fundingFees > 0.01 && (
{carry && carry.fundingProjected && carry.fundingFees > 0.01 && (
<div className="flex items-center justify-between">
<p className="text-[11px] text-ink-faint">Est. funding (projected)</p>
<p className="font-mono text-xs font-semibold text-red-400">+{fmtUsd(carry.fundingFees)}</p>
</div>
)}
{carry && carry.fundingProjected && carry.fundingFees < -0.01 && (
<div className="flex items-center justify-between">
<p className="text-[11px] text-ink-faint">Est. funding (projected)</p>
<p className="font-mono text-xs font-semibold text-emerald-500">−{fmtUsd(Math.abs(carry.fundingFees))} received</p>
</div>
)}
{carry && !carry.fundingProjected && carry.borrowFees > 0.01 && (
<div className="flex items-center justify-between">
<p className="text-[11px] text-ink-faint">Funding</p>
Expand Down Expand Up @@ -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 (
<div className="bg-ink/4 rounded-xl p-3 space-y-2">
<div className="flex items-center justify-between">
<p className="text-[10px] uppercase tracking-[0.14em] text-ink-faint">Volume</p>
<p className="text-[10px] uppercase tracking-[0.14em] text-ink-faint">Total position value</p>
<p className="font-mono text-xs font-semibold text-ink">{fmtUsd(volume)}</p>
</div>
<div className="border-t border-ink/8 pt-2 space-y-1.5">
Expand Down Expand Up @@ -766,7 +772,7 @@ function WalletSide({
)}
{hasBorrowing && (
<div className="flex items-center justify-between">
<p className="text-[11px] text-ink-faint">Borrowing fees</p>
<p className="text-[11px] text-ink-faint">Borrowing fees <span className="text-[9px] text-ink-faint/50">(vault)</span></p>
<p className="font-mono text-xs font-semibold text-red-400">
−{fmtUsd(gW.borrowingFeesUsdc)}
</p>
Expand Down
Loading