diff --git a/components/day-v3/DayV3Backtest.test.ts b/components/day-v3/DayV3Backtest.test.ts index f04181a..6c9314c 100644 --- a/components/day-v3/DayV3Backtest.test.ts +++ b/components/day-v3/DayV3Backtest.test.ts @@ -1,6 +1,9 @@ import assert from "node:assert/strict"; -import { formatDayV3MonthlyReturn } from "@/components/day-v3/DayV3Backtest"; +import { + buildDayV3BacktestWindows, + formatDayV3MonthlyReturn, +} from "@/components/day-v3/DayV3Backtest"; assert.equal(formatDayV3MonthlyReturn(0.01234), "+1.23%"); assert.equal(formatDayV3MonthlyReturn(-0.01234), "-1.23%"); @@ -8,4 +11,28 @@ assert.equal(formatDayV3MonthlyReturn(Number.POSITIVE_INFINITY), "N/A"); assert.equal(formatDayV3MonthlyReturn(Number.NEGATIVE_INFINITY), "N/A"); assert.equal(formatDayV3MonthlyReturn(Number.NaN), "N/A"); +const windows = buildDayV3BacktestWindows( + [ + { date: "2022-12-30" }, + { date: "2023-01-03" }, + { date: "2023-06-30" }, + { date: "2024-01-02" }, + { date: "2024-12-31" }, + { date: "2025-01-02" }, + ], + { + id: "2023-2024", + label: "2023–2024", + from: "2023-01-01", + to: "2024-12-31", + }, +); +assert.deepEqual(windows[0], { + id: "2023-2024", + label: "2023–2024", + from: 1, + to: 5, +}); +assert.equal(windows[1].id, "full"); + console.log("Day V3 non-finite monthly return presentation: PASS"); diff --git a/components/day-v3/DayV3Backtest.tsx b/components/day-v3/DayV3Backtest.tsx index d63d13c..97e59fb 100644 --- a/components/day-v3/DayV3Backtest.tsx +++ b/components/day-v3/DayV3Backtest.tsx @@ -59,8 +59,60 @@ export const formatDayV3MonthlyReturn = (value: number) => ? `${value < 0 ? "-" : "+"}${Math.abs(value * 100).toFixed(2)}%` : "N/A"; +export type DayV3BacktestWindowPreset = { + id: string; + label: string; + from: string; + to: string; +}; + +type DayV3BacktestWindow = { + id: string; + label: string; + from: number; + to: number; +}; + +/** Resolve display windows against dated source observations only. */ +export function buildDayV3BacktestWindows( + series: readonly { date: string }[], + preset?: DayV3BacktestWindowPreset | null, +): DayV3BacktestWindow[] { + if (series.length < 3) return []; + const lastTime = Date.parse(series[series.length - 1].date); + const rolling = [ + { id: "full", label: "Full history", months: 0 }, + { id: "24m", label: "Last 24 months", months: 24 }, + { id: "12m", label: "Last 12 months", months: 12 }, + { id: "6m", label: "Last 6 months", months: 6 }, + { id: "3m", label: "Last 3 months", months: 3 }, + ] + .map((span) => { + if (span.months === 0) { + return { id: span.id, label: span.label, from: 0, to: series.length }; + } + const cutoff = lastTime - span.months * 30.44 * 86_400_000; + const from = series.findIndex( + (point) => Date.parse(point.date) >= cutoff, + ); + return { id: span.id, label: span.label, from, to: series.length }; + }) + // A window needs enough points to be a run rather than a line between two + // dots, and one that covers the whole series is just "full history" twice. + .filter((span) => span.from >= 0 && span.to - span.from >= 3) + .filter((span, index, all) => index === 0 || span.from !== all[0].from); + + if (!preset) return rolling; + const from = series.findIndex((point) => point.date >= preset.from); + const firstAfter = series.findIndex((point) => point.date > preset.to); + const to = firstAfter < 0 ? series.length : firstAfter; + if (from < 0 || to - from < 3) return rolling; + return [{ id: preset.id, label: preset.label, from, to }, ...rolling]; +} + function DayV3Backtest({ bandPct: bandInput, + windowOption, coveragePct: coverageInput, customSource, liqY0Pct: liqY0Input, @@ -80,6 +132,7 @@ function DayV3Backtest({ sourceApyPct: sourceInput, }: { bandPct: number; + windowOption?: DayV3BacktestWindowPreset | null; coveragePct: number; customSource: boolean; liqY0Pct: number; @@ -159,37 +212,14 @@ function DayV3Backtest({ [market.series, sourceApyPct], ); - const windows = useMemo(() => { - if (series.length < 3) return []; - const last = series[series.length - 1]; - const lastTime = Date.parse(last.date); - const spans: { id: string; label: string; months: number }[] = [ - { id: "full", label: "Full history", months: 0 }, - { id: "24m", label: "Last 24 months", months: 24 }, - { id: "12m", label: "Last 12 months", months: 12 }, - { id: "6m", label: "Last 6 months", months: 6 }, - { id: "3m", label: "Last 3 months", months: 3 }, - ]; - return ( - spans - .map((span) => { - if (span.months === 0) return { ...span, from: 0 }; - const cutoff = lastTime - span.months * 30.44 * 86_400_000; - const from = series.findIndex( - (point) => Date.parse(point.date) >= cutoff, - ); - return { ...span, from: from < 0 ? -1 : from }; - }) - // A window needs enough points to be a run rather than a line between two - // dots, and one that covers the whole series is just "full history" twice. - .filter((span) => span.from >= 0 && series.length - span.from >= 3) - .filter((span, index, all) => index === 0 || span.from !== all[0].from) - ); - }, [series]); + const windows = useMemo( + () => buildDayV3BacktestWindows(series, windowOption), + [series, windowOption], + ); const active = windows.find((span) => span.id === windowId) ?? windows[0]; const view = useMemo( - () => (active ? series.slice(active.from) : series), + () => (active ? series.slice(active.from, active.to) : series), [active, series], ); @@ -555,7 +585,7 @@ function DayV3Backtest({ {windows.map((span) => ( ))} diff --git a/components/day-v3/DayV3PremiumCurveEditor.test.tsx b/components/day-v3/DayV3PremiumCurveEditor.test.tsx index ff78347..176dee2 100644 --- a/components/day-v3/DayV3PremiumCurveEditor.test.tsx +++ b/components/day-v3/DayV3PremiumCurveEditor.test.tsx @@ -12,9 +12,11 @@ const markup = renderToStaticMarkup( liqY100Pct={15} liqYtPct={5} juniorModeledApy={0.085} - onLiqYtPct={ignore} + onLiqY0Pct={ignore} + onLiqY100Pct={ignore} onResetCurve={ignore} - onRiskYtPct={ignore} + onRiskY0Pct={ignore} + onRiskY100Pct={ignore} riskCapPct={80} riskY0Pct={2} riskY100Pct={16} @@ -26,13 +28,22 @@ const markup = renderToStaticMarkup( assert.match(markup, /Yield split/); assert.match(markup, /aria-expanded="false"/); -assert.match(markup, /Jr 13\.0% · SLP 5\.0% at 90\.0% utilization/); +assert.match( + markup, + /Jr 2\.0% \/ 16\.0% · SLP 1\.0% \/ 15\.0% · Y0 \/ Y100/, +); assert.match(markup, /Section status: Set/); assert.doesNotMatch(markup, /See .*impact/i); -assert.match(markup, /Junior yield share/); -assert.match(markup, /SLP yield share/); -assert.match(markup, /Jr share at 90% utilization/); -assert.match(markup, /SLP share at 90% utilization/); +assert.match(markup, /Junior risk yield curve/); +assert.match(markup, /SLP liquidity yield curve/); +for (const label of [ + "Jr Y0 · 0% utilization", + "Jr Y100 · 100% utilization", + "SLP Y0 · 0% utilization", + "SLP Y100 · 100% utilization", +]) { + assert.match(markup, new RegExp(label)); +} assert.match(markup, /Projected Jr APY/); assert.match(markup, /Projected SLP APY/); assert.doesNotMatch(markup, /Exact E-CLP sizing/); @@ -45,18 +56,16 @@ assert.match(markup, /8\.5%/); assert.match(markup, /2\.4%/); assert.match(markup, /Updates from the shared accountant/); assert.match(markup, /Reset yield split/); -assert.equal(markup.match(/type="range"/g)?.length, 2); -assert.equal(markup.match(/aria-valuetext=/g)?.length, 2); -assert.equal(markup.match(/step="0.1"/g)?.length, 2); +assert.equal(markup.match(/type="range"/g)?.length, 4); +assert.equal(markup.match(/aria-valuetext=/g)?.length, 4); +assert.equal(markup.match(/step="0.1"/g)?.length, 4); +assert.doesNotMatch(markup, / YT /); -// The unified editor exposes only the operating-target shares. The parent -// still supplies the derived zero/full anchors so they can bound each target -// slider without moving any curve or accountant math into this component. +// The unified editor exposes only the two endpoints for each curve. The parent +// retains the fixed YT contract anchors and accountant routing. assert.doesNotMatch(markup, /Simple/); assert.doesNotMatch(markup, /Advanced/); assert.doesNotMatch(markup, /Curve shape anchors/); -assert.doesNotMatch(markup, /No coverage used \(Y0\)/); -assert.doesNotMatch(markup, /All liquidity used \(Y100\)/); assert.doesNotMatch(markup, /Confirm suggested curves/); assert.doesNotMatch(markup, /Reset to suggested curves/); assert.doesNotMatch(markup, /Live pool validation/); @@ -70,9 +79,11 @@ const invalidMarkup = renderToStaticMarkup( liqY100Pct={15} liqYtPct={5} juniorModeledApy={0.085} - onLiqYtPct={ignore} + onLiqY0Pct={ignore} + onLiqY100Pct={ignore} onResetCurve={ignore} - onRiskYtPct={ignore} + onRiskY0Pct={ignore} + onRiskY100Pct={ignore} riskCapPct={80} riskY0Pct={2} riskY100Pct={16} @@ -95,9 +106,11 @@ const slpOnlyMarkup = renderToStaticMarkup( liqY100Pct={15} liqYtPct={5} juniorModeledApy={0} - onLiqYtPct={ignore} + onLiqY0Pct={ignore} + onLiqY100Pct={ignore} onResetCurve={ignore} - onRiskYtPct={ignore} + onRiskY0Pct={ignore} + onRiskY100Pct={ignore} riskCapPct={0} riskY0Pct={0} riskY100Pct={0} @@ -107,9 +120,9 @@ const slpOnlyMarkup = renderToStaticMarkup( />, ); assert.match(slpOnlyMarkup, /Compare how source yield is shared with SLP/); -assert.match(slpOnlyMarkup, /SLP yield share/); -assert.doesNotMatch(slpOnlyMarkup, /Junior yield share/); -assert.equal(slpOnlyMarkup.match(/type="range"/g)?.length, 1); +assert.match(slpOnlyMarkup, /SLP liquidity yield curve/); +assert.doesNotMatch(slpOnlyMarkup, /Junior risk yield curve/); +assert.equal(slpOnlyMarkup.match(/type="range"/g)?.length, 2); const juniorOnlyMarkup = renderToStaticMarkup( , ); assert.match(juniorOnlyMarkup, /Compare how source yield is shared with Junior/); -assert.match(juniorOnlyMarkup, /Junior yield share/); -assert.doesNotMatch(juniorOnlyMarkup, /SLP yield share/); -assert.equal(juniorOnlyMarkup.match(/type="range"/g)?.length, 1); +assert.match(juniorOnlyMarkup, /Junior risk yield curve/); +assert.doesNotMatch(juniorOnlyMarkup, /SLP liquidity yield curve/); +assert.equal(juniorOnlyMarkup.match(/type="range"/g)?.length, 2); const bothOffMarkup = renderToStaticMarkup( , ); -assert.match(unresolvedPoolSlpMarkup, /Jr 13\.0% · SLP 5\.0%/); +assert.match( + unresolvedPoolSlpMarkup, + /Jr 2\.0% \/ 16\.0% · SLP 1\.0% \/ 15\.0%/, +); assert.match(unresolvedPoolSlpMarkup, /Section status: Set/); assert.doesNotMatch(unresolvedPoolSlpMarkup, /awaiting exit validation/); -assert.equal(unresolvedPoolSlpMarkup.match(/type="range"/g)?.length, 2); +assert.equal(unresolvedPoolSlpMarkup.match(/type="range"/g)?.length, 4); console.log("Day V3 unified premium-curve editor: PASS"); diff --git a/components/day-v3/DayV3PremiumCurveEditor.tsx b/components/day-v3/DayV3PremiumCurveEditor.tsx index 6f306a1..63cd3cf 100644 --- a/components/day-v3/DayV3PremiumCurveEditor.tsx +++ b/components/day-v3/DayV3PremiumCurveEditor.tsx @@ -19,9 +19,11 @@ export type DayV3PremiumCurveEditorProps = { liqY100Pct: number; liqYtPct: number; juniorModeledApy: number; - onLiqYtPct: (value: number) => void; + onLiqY0Pct: (value: number) => void; + onLiqY100Pct: (value: number) => void; onResetCurve: () => void; - onRiskYtPct: (value: number) => void; + onRiskY0Pct: (value: number) => void; + onRiskY100Pct: (value: number) => void; riskCapPct: number; riskY0Pct: number; riskY100Pct: number; @@ -35,10 +37,10 @@ type CurveCardProps = { capPct: number; description: string; docs: "coverage" | "slpTranche"; - onYtPct: (value: number) => void; + onY0Pct: (value: number) => void; + onY100Pct: (value: number) => void; paidTo: "Jr" | "SLP"; modeledApy: number; - targetUtilization: number; title: string; y0Pct: number; y100Pct: number; @@ -52,23 +54,22 @@ function CurveCard({ capPct, description, docs, - onYtPct, + onY0Pct, + onY100Pct, paidTo, modeledApy, - targetUtilization, title, y0Pct, y100Pct, ytPct, }: CurveCardProps) { const simulationBudgetPct = Math.max(0, capPct); - const targetPct = targetUtilization * 100; - - // These are UI bounds, not a second implementation of the yield model. The - // parent supplies the resolved anchors and the remaining shared simulation - // budget; this component only bounds the displayed target-share slider. - const ytMin = Math.min(simulationBudgetPct, y0Pct); - const ytMax = Math.max(ytMin, Math.min(simulationBudgetPct, y100Pct)); + // These are input bounds, not another curve evaluator. The contract requires + // Y0 <= YT <= Y100. YT remains the contract-configured fixed kink anchor; + // this streamlined editor exposes only the two endpoint controls. Curve + // evaluation stays in the shared Day accountant. + const y0Max = Math.min(simulationBudgetPct, Math.max(0, ytPct)); + const y100Min = Math.min(simulationBudgetPct, Math.max(0, ytPct)); return (
- +
+ + +
Projected {paidTo} APY @@ -117,11 +133,13 @@ function CurveCard({ } /** - * V3's target-share editor for the two static premium curves. + * V3's endpoint editor for the two static premium curves. * * The parent owns every value, bound, callback, and reset decision. This - * component displays only the operating-target shares and accountant-derived - * returns; it does not derive a curve anchor, cap, return, or accountant input. + * component displays the contract's configurable Y0 and Y100 endpoints plus + * accountant-derived returns. The configured YT kink stays in the parent and + * is still passed to the accountant; this component does not evaluate either + * curve or derive a return. */ function DayV3PremiumCurveEditor({ curveOverridden, @@ -133,9 +151,11 @@ function DayV3PremiumCurveEditor({ liqY100Pct, liqYtPct, juniorModeledApy, - onLiqYtPct, + onLiqY0Pct, + onLiqY100Pct, onResetCurve, - onRiskYtPct, + onRiskY0Pct, + onRiskY100Pct, riskCapPct, riskY0Pct, riskY100Pct, @@ -145,50 +165,74 @@ function DayV3PremiumCurveEditor({ targetUtilization, }: DayV3PremiumCurveEditorProps) { const [riskEditor, setRiskEditor] = useState({ - draft: riskYtPct, - source: riskYtPct, + draft: { y0: riskY0Pct, yt: riskYtPct, y100: riskY100Pct }, + source: { y0: riskY0Pct, yt: riskYtPct, y100: riskY100Pct }, }); const [liqEditor, setLiqEditor] = useState({ - draft: liqYtPct, - source: liqYtPct, + draft: { y0: liqY0Pct, yt: liqYtPct, y100: liqY100Pct }, + source: { y0: liqY0Pct, yt: liqYtPct, y100: liqY100Pct }, }); - const onRiskYtPctRef = useRef(onRiskYtPct); - const onLiqYtPctRef = useRef(onLiqYtPct); + const onRiskY0PctRef = useRef(onRiskY0Pct); + const onRiskY100PctRef = useRef(onRiskY100Pct); + const onLiqY0PctRef = useRef(onLiqY0Pct); + const onLiqY100PctRef = useRef(onLiqY100Pct); + useEffect(() => { + onRiskY0PctRef.current = onRiskY0Pct; + }, [onRiskY0Pct]); + useEffect(() => { + onRiskY100PctRef.current = onRiskY100Pct; + }, [onRiskY100Pct]); useEffect(() => { - onRiskYtPctRef.current = onRiskYtPct; - }, [onRiskYtPct]); + onLiqY0PctRef.current = onLiqY0Pct; + }, [onLiqY0Pct]); useEffect(() => { - onLiqYtPctRef.current = onLiqYtPct; - }, [onLiqYtPct]); + onLiqY100PctRef.current = onLiqY100Pct; + }, [onLiqY100Pct]); // Reset actions and linked URLs can replace the parent value. React's // documented adjusted-state pattern keeps the local drag draft in sync // without a second render caused by a setState-in-effect cycle. - if (!Object.is(riskEditor.source, riskYtPct)) { - setRiskEditor({ draft: riskYtPct, source: riskYtPct }); + const riskSource = { y0: riskY0Pct, yt: riskYtPct, y100: riskY100Pct }; + const liqSource = { y0: liqY0Pct, yt: liqYtPct, y100: liqY100Pct }; + if ( + !Object.is(riskEditor.source.y0, riskSource.y0) || + !Object.is(riskEditor.source.yt, riskSource.yt) || + !Object.is(riskEditor.source.y100, riskSource.y100) + ) { + setRiskEditor({ draft: riskSource, source: riskSource }); } - if (!Object.is(liqEditor.source, liqYtPct)) { - setLiqEditor({ draft: liqYtPct, source: liqYtPct }); + if ( + !Object.is(liqEditor.source.y0, liqSource.y0) || + !Object.is(liqEditor.source.yt, liqSource.yt) || + !Object.is(liqEditor.source.y100, liqSource.y100) + ) { + setLiqEditor({ draft: liqSource, source: liqSource }); } - const riskDraftPct = riskEditor.draft; - const liqDraftPct = liqEditor.draft; + const riskDraft = riskEditor.draft; + const liqDraft = liqEditor.draft; useEffect(() => { - if (!juniorEnabled || Object.is(riskDraftPct, riskYtPct)) return; - const timeout = window.setTimeout( - () => onRiskYtPctRef.current(riskDraftPct), - 120, - ); + if (!juniorEnabled || Object.is(riskDraft.y0, riskY0Pct)) return; + const timeout = window.setTimeout(() => onRiskY0PctRef.current(riskDraft.y0), 120); return () => window.clearTimeout(timeout); - }, [juniorEnabled, riskDraftPct, riskYtPct]); + }, [juniorEnabled, riskDraft.y0, riskY0Pct]); useEffect(() => { - if (!slpEnabled || Object.is(liqDraftPct, liqYtPct)) return; - const timeout = window.setTimeout( - () => onLiqYtPctRef.current(liqDraftPct), - 120, - ); + if (!juniorEnabled || Object.is(riskDraft.y100, riskY100Pct)) return; + const timeout = window.setTimeout(() => onRiskY100PctRef.current(riskDraft.y100), 120); return () => window.clearTimeout(timeout); - }, [liqDraftPct, liqYtPct, slpEnabled]); + }, [juniorEnabled, riskDraft.y100, riskY100Pct]); + + useEffect(() => { + if (!slpEnabled || Object.is(liqDraft.y0, liqY0Pct)) return; + const timeout = window.setTimeout(() => onLiqY0PctRef.current(liqDraft.y0), 120); + return () => window.clearTimeout(timeout); + }, [liqDraft.y0, liqY0Pct, slpEnabled]); + + useEffect(() => { + if (!slpEnabled || Object.is(liqDraft.y100, liqY100Pct)) return; + const timeout = window.setTimeout(() => onLiqY100PctRef.current(liqDraft.y100), 120); + return () => window.clearTimeout(timeout); + }, [liqDraft.y100, liqY100Pct, slpEnabled]); if (!juniorEnabled && !slpEnabled) { return null; @@ -199,8 +243,12 @@ function DayV3PremiumCurveEditor({ ...(slpEnabled ? ["SLP"] : []), ]; const activeCurveSummary = [ - ...(juniorEnabled ? [`Jr ${pct(riskDraftPct / 100)}`] : []), - ...(slpEnabled ? [`SLP ${pct(liqDraftPct / 100)}`] : []), + ...(juniorEnabled + ? [`Jr ${pct(riskDraft.y0 / 100)} / ${pct(riskDraft.y100 / 100)}`] + : []), + ...(slpEnabled + ? [`SLP ${pct(liqDraft.y0 / 100)} / ${pct(liqDraft.y100 / 100)}`] + : []), ].join(" · "); return (

- Adjust the share paid at the {pct(targetUtilization)} operating target. - Each position's modeled APY updates beside it. + Set the yield-share endpoints at 0% and 100% utilization. The + contract's fixed {pct(targetUtilization)} kink remains configured in + the market, and each position's modeled APY updates beside the controls.

{validationIssues.length > 0 ? ( @@ -272,16 +321,24 @@ function DayV3PremiumCurveEditor({ capPct={riskCapPct} description="Sets the share of Senior yield paid to Junior as first-loss coverage is used." docs="coverage" - onYtPct={(value) => - setRiskEditor((current) => ({ ...current, draft: value })) + onY0Pct={(value) => + setRiskEditor((current) => ({ + ...current, + draft: { ...current.draft, y0: value }, + })) + } + onY100Pct={(value) => + setRiskEditor((current) => ({ + ...current, + draft: { ...current.draft, y100: value }, + })) } paidTo="Jr" modeledApy={juniorModeledApy} - targetUtilization={targetUtilization} - title="Junior yield share" - y0Pct={riskY0Pct} - y100Pct={riskY100Pct} - ytPct={riskDraftPct} + title="Junior risk yield curve" + y0Pct={riskDraft.y0} + y100Pct={riskDraft.y100} + ytPct={riskDraft.yt} /> ) : null} {slpEnabled ? ( @@ -289,16 +346,24 @@ function DayV3PremiumCurveEditor({ capPct={liqCapPct} description="Sets the share of Senior yield paid to SLP as exit liquidity is used." docs="slpTranche" - onYtPct={(value) => - setLiqEditor((current) => ({ ...current, draft: value })) + onY0Pct={(value) => + setLiqEditor((current) => ({ + ...current, + draft: { ...current.draft, y0: value }, + })) + } + onY100Pct={(value) => + setLiqEditor((current) => ({ + ...current, + draft: { ...current.draft, y100: value }, + })) } paidTo="SLP" modeledApy={slpModeledApy} - targetUtilization={targetUtilization} - title="SLP yield share" - y0Pct={liqY0Pct} - y100Pct={liqY100Pct} - ytPct={liqDraftPct} + title="SLP liquidity yield curve" + y0Pct={liqDraft.y0} + y100Pct={liqDraft.y100} + ytPct={liqDraft.yt} /> ) : null}
diff --git a/components/day-v3/DayV3Summary.tsx b/components/day-v3/DayV3Summary.tsx index 505cb9c..7fc80c4 100644 --- a/components/day-v3/DayV3Summary.tsx +++ b/components/day-v3/DayV3Summary.tsx @@ -61,6 +61,7 @@ import { buildDayV3Query, boundDayV3YieldShareAtTarget, DAY_V3_STARTER_DEFAULTS, + dayV3MarketDefaults, dayV3MinimumLiquidityForPoolFunding, deriveDayV3StartingYieldCurvePolicy, normalizeDayV3Defaults, @@ -169,8 +170,9 @@ export default function DayV3Summary({ }); }; const clearStarterFields = () => setStarterFields(new Set()); - // Only operating-target yield shares remain active. Legacy hidden overrides - // still parse, but cannot change a displayed result. + // Only the six contract YDM anchors remain active from the legacy override + // surface. Pool/deployment-only overrides stay parseable without changing a + // displayed result. const activeManualOverrides = useMemo( () => dayV3ActiveOverrides(manualOverrides), [manualOverrides], @@ -271,8 +273,9 @@ export default function DayV3Summary({ const [maintainCoverage, setMaintainCoverage] = useState( initialMarket.defaults.maintainCoverage, ); - // The merged simulator exposes only target yield shares. Legacy curve-shape - // anchors stay inactive even when an old link contains them. + // The shared yield editor exposes Y0 and Y100 while retaining the configured + // YT kink used by each Day contract YDM. All three values flow into the + // accountant snapshot below; the UI never evaluates either curve itself. const riskShareOverride = activeManualOverrides.jrYieldShareAtTargetPct; const liqShareOverride = activeManualOverrides.slpYieldShareAtTargetPct; const y0Override = activeManualOverrides.jrYieldShareAtZeroPct; @@ -314,22 +317,42 @@ export default function DayV3Summary({ // Switching market adopts that market's own terms, so the sliders describe the // market on screen rather than carrying the previous one's numbers over. const adoptTerms = (next: DayMarket) => { + const marketDefaults = dayV3MarketDefaults(next.id); setSourceApyPct(next.defaults.sourceApy * 100); - setProtectedDrawdownPct(null); - setRecoveryDaysInput(null); - setRecoveryMode(null); - setImmediateExitSharePct(null); - setMinimumProceedsPer100(null); + setProtectedDrawdownPct(marketDefaults?.protectedDrawdownPct ?? null); + setRecoveryDaysInput(marketDefaults?.recoveryDays ?? null); + setRecoveryMode( + marketDefaults + ? marketDefaults.recoveryDays === 0 + ? "none" + : "window" + : null, + ); + setImmediateExitSharePct(marketDefaults?.immediateExitSharePct ?? null); + setMinimumProceedsPer100(marketDefaults?.minimumProceedsPer100 ?? null); // The quote asset belongs to the exit design, not to the source, so it is // cleared with the rest of the exit rather than carried across markets. - setQuoteAssetLabel(DAY_V3_DEFAULT_QUOTE_ASSET); - setQuoteAssetYieldPct(DAY_V3_DEFAULT_QUOTE_ASSET_YIELD_PCT); - setPoolTurnoverPerYear(DAY_V3_DEFAULT_POOL_TURNOVER); + setQuoteAssetLabel( + marketDefaults?.quoteAssetLabel ?? DAY_V3_DEFAULT_QUOTE_ASSET, + ); + setQuoteAssetYieldPct( + marketDefaults?.quoteAssetYieldPct ?? DAY_V3_DEFAULT_QUOTE_ASSET_YIELD_PCT, + ); + setPoolTurnoverPerYear( + marketDefaults?.poolTurnoverPerYear ?? DAY_V3_DEFAULT_POOL_TURNOVER, + ); // A fee is a property of the pool being designed, so it is released with // the rest of the exit rather than carried onto the next market. - setSwapFeeBps(null); + setSwapFeeBps(marketDefaults?.swapFeeBps ?? null); + setMarketMakerCostOfCapitalPct( + marketDefaults?.marketMakerCostOfCapitalPct ?? 12, + ); + setRedemptionDays(marketDefaults?.redemptionDays ?? 7); setImportedMarket(null); - setManualOverrides(EMPTY_DAY_V3_OVERRIDES); + setManualOverrides({ + ...EMPTY_DAY_V3_OVERRIDES, + ...(marketDefaults?.overrides ?? {}), + }); // Adopted with the rest of the market's terms, for the same reason: the // toggle must describe the market on screen, not the previous one. setMaintainCoverage(next.defaults.maintainCoverage); @@ -360,14 +383,21 @@ export default function DayV3Summary({ }; const resetYieldCurveOverrides = () => { + const marketDefaults = dayV3MarketDefaults(market.id); setManualOverrides((current) => ({ ...current, - jrYieldShareAtZeroPct: null, - jrYieldShareAtFullPct: null, - slpYieldShareAtZeroPct: null, - slpYieldShareAtFullPct: null, - jrYieldShareAtTargetPct: null, - slpYieldShareAtTargetPct: null, + jrYieldShareAtZeroPct: + marketDefaults?.overrides.jrYieldShareAtZeroPct ?? null, + jrYieldShareAtFullPct: + marketDefaults?.overrides.jrYieldShareAtFullPct ?? null, + slpYieldShareAtZeroPct: + marketDefaults?.overrides.slpYieldShareAtZeroPct ?? null, + slpYieldShareAtFullPct: + marketDefaults?.overrides.slpYieldShareAtFullPct ?? null, + jrYieldShareAtTargetPct: + marketDefaults?.overrides.jrYieldShareAtTargetPct ?? null, + slpYieldShareAtTargetPct: + marketDefaults?.overrides.slpYieldShareAtTargetPct ?? null, })); }; @@ -1275,6 +1305,23 @@ export default function DayV3Summary({ ) => { setManualOverrides((current) => ({ ...current, + // Endpoint edits must travel as one complete six-anchor policy. Preserve + // any anchor already edited; otherwise materialize the accountant's + // currently resolved curve. This keeps URL reloads and the live model on + // the same valid contract configuration without deriving curve math here. + jrYieldShareAtZeroPct: + current.jrYieldShareAtZeroPct ?? resolved.y0 * 100, + jrYieldShareAtTargetPct: + current.jrYieldShareAtTargetPct ?? resolved.riskYieldShare * 100, + jrYieldShareAtFullPct: + current.jrYieldShareAtFullPct ?? resolved.y100 * 100, + slpYieldShareAtZeroPct: + current.slpYieldShareAtZeroPct ?? resolved.liqY0 * 100, + slpYieldShareAtTargetPct: + current.slpYieldShareAtTargetPct ?? + resolved.liquidityYieldShare * 100, + slpYieldShareAtFullPct: + current.slpYieldShareAtFullPct ?? resolved.liqY100 * 100, [field]: value, })); }; @@ -1575,12 +1622,18 @@ export default function DayV3Summary({ y0Pct: resolved.liqY0 * 100, y100Pct: resolved.liqY100 * 100, })} - onLiqYtPct={(value) => - updateYieldCurveOverride("slpYieldShareAtTargetPct", value) + onLiqY0Pct={(value) => + updateYieldCurveOverride("slpYieldShareAtZeroPct", value) + } + onLiqY100Pct={(value) => + updateYieldCurveOverride("slpYieldShareAtFullPct", value) } onResetCurve={resetYieldCurveOverrides} - onRiskYtPct={(value) => - updateYieldCurveOverride("jrYieldShareAtTargetPct", value) + onRiskY0Pct={(value) => + updateYieldCurveOverride("jrYieldShareAtZeroPct", value) + } + onRiskY100Pct={(value) => + updateYieldCurveOverride("jrYieldShareAtFullPct", value) } riskCapPct={resolved.riskCeiling * 100} riskY0Pct={resolved.y0 * 100} @@ -2387,6 +2440,9 @@ export default function DayV3Summary({ bandPct={inputs.bandPct} coveragePct={inputs.coveragePct} customSource={customSource} + windowOption={ + dayV3MarketDefaults(market.id)?.backtestWindowOption + } liqSharePct={resolved.liquidityYieldShare * 100} liqY0Pct={resolved.liqY0 * 100} liqY100Pct={resolved.liqY100 * 100} diff --git a/components/day-v3/url-state.test.ts b/components/day-v3/url-state.test.ts index 827f19c..9684b82 100644 --- a/components/day-v3/url-state.test.ts +++ b/components/day-v3/url-state.test.ts @@ -105,20 +105,33 @@ assert.equal(listedSource.applied, true); assert.equal(listedSource.state.sourceApyPct, null); assert.equal( listedSource.state.protectedDrawdownPct, - DAY_V3_STARTER_DEFAULTS.protectedDrawdownPct, -); -assert.equal( - listedSource.state.recoveryDays, - DAY_V3_STARTER_DEFAULTS.recoveryDays, -); -assert.equal( - listedSource.state.immediateExitSharePct, - DAY_V3_STARTER_DEFAULTS.immediateExitSharePct, -); -assert.equal( - listedSource.state.minimumProceedsPer100, - DAY_V3_STARTER_DEFAULTS.minimumProceedsPer100, + 15, ); +assert.equal(listedSource.state.recoveryDays, 90); +assert.equal(listedSource.state.immediateExitSharePct, 10); +assert.equal(listedSource.state.minimumProceedsPer100, 95); +assert.equal(listedSource.state.quoteAssetLabel, "sr-srRoyUSDC"); +assert.equal(listedSource.state.quoteAssetYieldPct, 4); +assert.equal(listedSource.state.poolTurnoverPerYear, 2); +assert.equal(listedSource.state.swapFeeBps, 5); +assert.equal(listedSource.state.marketMakerCostOfCapitalPct, 12); +assert.equal(listedSource.state.redemptionDays, 7); +assert.deepEqual(listedSource.state.overrides, { + jrYieldShareAtZeroPct: 7.5, + jrYieldShareAtTargetPct: 19, + jrYieldShareAtFullPct: 45, + slpYieldShareAtZeroPct: 2, + slpYieldShareAtTargetPct: 2.9937, + slpYieldShareAtFullPct: 29.7937, + coveragePct: null, + minimumLiquidityPct: null, + maximumDiscountPct: null, + depthAtNav: null, + maximumPremiumPct: null, + protectedExitThresholdPct: null, + protectedExitBonusPct: null, + poolCapitalPer100: null, +}); assert.equal(listedSource.state.entryPointSettlementDays, null); assert.deepEqual(listedSource.state.target, DAY_V3_STARTER_DEFAULTS.target); assert.deepEqual(listedSource.appliedFields, [ @@ -128,6 +141,41 @@ assert.deepEqual(listedSource.appliedFields, [ "payout", "target", ]); +const listedSourceQuery = buildDayV3Query({ + ...listedSource.state, + starterFields: listedSource.appliedFields, +}); +for (const expected of [ + "m=jbbb", + "protect=15", + "recover=90", + "exit=10", + "receive=95", + "quote=sr-srRoyUSDC", + "quoteApy=4", + "turnover=2", + "fee=5", + "mmCost=12", + "mmDays=7", + "jr0=7.5", + "jr90=19", + "jr100=45", + "slp0=2", + "slp90=2.9937", + "slp100=29.7937", +]) { + assert.equal(listedSourceQuery.includes(expected), true, expected); +} + +const explicitJbbbTerms = applyDayV3StarterDefaults( + readDayV3UrlState("m=jbbb&recover=30&fee=7&jr90=18"), + "m=jbbb&recover=30&fee=7&jr90=18", +); +assert.equal(explicitJbbbTerms.state.recoveryDays, 30); +assert.equal(explicitJbbbTerms.state.swapFeeBps, 7); +assert.equal(explicitJbbbTerms.state.overrides.jrYieldShareAtTargetPct, 18); +assert.equal(explicitJbbbTerms.state.overrides.jrYieldShareAtZeroPct, null); +assert.equal(explicitJbbbTerms.state.overrides.slpYieldShareAtFullPct, null); const query = buildDayV3Query({ market: "custom", @@ -194,6 +242,8 @@ assert.deepEqual( "convertCost", "exit", "fee", + "jr0", + "jr100", "jr90", "m", "mmCost", @@ -204,10 +254,12 @@ assert.deepEqual( "receive", "recover", "settle", + "slp0", + "slp100", "slp90", "turnover", ], - "the canonical writer strips hidden state while retaining visible target shares", + "the canonical writer strips hidden state while retaining all visible curve anchors", ); for (const hidden of [ "mode", @@ -228,10 +280,6 @@ for (const hidden of [ "pexit", "bonus", "pool", - "jr0", - "jr100", - "slp0", - "slp100", "starter", ]) { assert.equal(new URLSearchParams(query).has(hidden), false, hidden); @@ -323,12 +371,16 @@ assert.deepEqual(overridden.overrides, { slpYieldShareAtFullPct: 14, }); const curveRoundTrip = buildDayV3Query(overridden); -for (const field of ["jr90=12", "slp90=5"]) { +for (const field of [ + "jr0=2", + "jr90=12", + "jr100=18", + "slp0=1", + "slp90=5", + "slp100=14", +]) { assert.equal(curveRoundTrip.includes(field), true); } -for (const field of ["jr0=", "jr100=", "slp0=", "slp100="]) { - assert.equal(curveRoundTrip.includes(field), false); -} const simpleYieldSplit = readDayV3UrlState("m=custom&apy=8&jr90=20&slp90=10"); assert.deepEqual( { diff --git a/lib/day-sample-sources/jbbb/v3-defaults.ts b/lib/day-sample-sources/jbbb/v3-defaults.ts new file mode 100644 index 0000000..6396e05 --- /dev/null +++ b/lib/day-sample-sources/jbbb/v3-defaults.ts @@ -0,0 +1,43 @@ +import type { DayV3Overrides } from "@/lib/day-v3/types"; + +/** + * Issuer-design defaults explicitly agreed for the JBBB simulation. + * + * These are inputs to the shared Day runtime, not independently calculated + * tranche outputs. JBBB's source APY continues to come from its total-return + * series rather than being duplicated here. + */ +export const JBBB_V3_DEFAULTS = { + protectedDrawdownPct: 15, + recoveryDays: 90, + immediateExitSharePct: 10, + minimumProceedsPer100: 95, + quoteAssetLabel: "sr-srRoyUSDC", + quoteAssetYieldPct: 4, + poolTurnoverPerYear: 2, + swapFeeBps: 5, + marketMakerCostOfCapitalPct: 12, + redemptionDays: 7, + backtestWindowOption: { + id: "2023-2024", + label: "2023–2024", + from: "2023-01-01", + to: "2024-12-31", + }, + overrides: { + jrYieldShareAtZeroPct: 7.5, + jrYieldShareAtTargetPct: 19, + jrYieldShareAtFullPct: 45, + slpYieldShareAtZeroPct: 2, + slpYieldShareAtTargetPct: 2.9937, + slpYieldShareAtFullPct: 29.7937, + } satisfies Pick< + DayV3Overrides, + | "jrYieldShareAtZeroPct" + | "jrYieldShareAtTargetPct" + | "jrYieldShareAtFullPct" + | "slpYieldShareAtZeroPct" + | "slpYieldShareAtTargetPct" + | "slpYieldShareAtFullPct" + >, +} as const; diff --git a/lib/day-v3/index.ts b/lib/day-v3/index.ts index 73a6d03..a78a37f 100644 --- a/lib/day-v3/index.ts +++ b/lib/day-v3/index.ts @@ -1,5 +1,6 @@ export * from "@/lib/day-v3/types"; export * from "@/lib/day-v3/url-state"; +export * from "@/lib/day-v3/market-defaults"; export * from "@/lib/day-v3/yield-curves"; export * from "@/lib/day-v3/normalization"; export * from "@/lib/day-v3/protection"; diff --git a/lib/day-v3/market-defaults.ts b/lib/day-v3/market-defaults.ts new file mode 100644 index 0000000..8a4a1e8 --- /dev/null +++ b/lib/day-v3/market-defaults.ts @@ -0,0 +1,39 @@ +import { JBBB_V3_DEFAULTS } from "@/lib/day-sample-sources/jbbb/v3-defaults"; +import type { DayV3Overrides } from "@/lib/day-v3/types"; + +type YieldCurveOverrides = Pick< + DayV3Overrides, + | "jrYieldShareAtZeroPct" + | "jrYieldShareAtTargetPct" + | "jrYieldShareAtFullPct" + | "slpYieldShareAtZeroPct" + | "slpYieldShareAtTargetPct" + | "slpYieldShareAtFullPct" +>; + +export type DayV3MarketDefaults = { + protectedDrawdownPct: number; + recoveryDays: number; + immediateExitSharePct: number; + minimumProceedsPer100: number; + quoteAssetLabel: string; + quoteAssetYieldPct: number; + poolTurnoverPerYear: number; + swapFeeBps: number; + marketMakerCostOfCapitalPct: number; + redemptionDays: number; + backtestWindowOption: { + id: string; + label: string; + from: string; + to: string; + }; + overrides: YieldCurveOverrides; +}; + +/** Market-specific issuer inputs. Unlisted markets retain shared starters. */ +export function dayV3MarketDefaults( + marketId: string | null | undefined, +): DayV3MarketDefaults | null { + return marketId === "jbbb" ? JBBB_V3_DEFAULTS : null; +} diff --git a/lib/day-v3/mode-model.ts b/lib/day-v3/mode-model.ts index 3caa13d..f33e9f1 100644 --- a/lib/day-v3/mode-model.ts +++ b/lib/day-v3/mode-model.ts @@ -18,17 +18,20 @@ export const EMPTY_DAY_V3_OVERRIDES: Readonly = Object.freeze({ }); /** - * The simulator exposes only the two yield shares paid at the operating - * target. Legacy curve-shape and deployment overrides stay parseable so old - * links do not break, but invisible fields must never change a displayed - * result. + * The simulator exposes the contract's Y0, YT, and Y100 anchors for both Day + * YDMs. Deployment and pool overrides stay parseable so old links do not + * break, but invisible fields must never change a displayed result. */ export function dayV3ActiveOverrides( overrides: DayV3Overrides, ): Readonly { return { ...EMPTY_DAY_V3_OVERRIDES, + jrYieldShareAtZeroPct: overrides.jrYieldShareAtZeroPct, jrYieldShareAtTargetPct: overrides.jrYieldShareAtTargetPct, + jrYieldShareAtFullPct: overrides.jrYieldShareAtFullPct, + slpYieldShareAtZeroPct: overrides.slpYieldShareAtZeroPct, slpYieldShareAtTargetPct: overrides.slpYieldShareAtTargetPct, + slpYieldShareAtFullPct: overrides.slpYieldShareAtFullPct, }; } diff --git a/lib/day-v3/mode-state.test.ts b/lib/day-v3/mode-state.test.ts index 6393e81..8acafb4 100644 --- a/lib/day-v3/mode-state.test.ts +++ b/lib/day-v3/mode-state.test.ts @@ -119,6 +119,8 @@ const expectedCanonicalKeys = [ "convertCost", "exit", "fee", + "jr0", + "jr100", "jr90", "m", "mmCost", @@ -129,6 +131,8 @@ const expectedCanonicalKeys = [ "receive", "recover", "settle", + "slp0", + "slp100", "slp90", "turnover", ]; @@ -170,10 +174,6 @@ for (const removedKey of [ "pexit", "bonus", "pool", - "jr0", - "jr100", - "slp0", - "slp100", "starter", ]) { assert.equal( @@ -223,12 +223,16 @@ for (const field of [ ); } -// The unified simulator exposes only the two operating-target yield shares. -// Legacy endpoint and pool overrides may parse, but cannot affect any result. +// The unified simulator exposes the six contract curve anchors. Pool and +// deployment overrides may parse, but cannot affect any result. const expectedActiveOverrides = { ...EMPTY_DAY_V3_OVERRIDES, + jrYieldShareAtZeroPct: 2, jrYieldShareAtTargetPct: 12, + jrYieldShareAtFullPct: 18, + slpYieldShareAtZeroPct: 1, slpYieldShareAtTargetPct: 5, + slpYieldShareAtFullPct: 14, }; assert.deepEqual( dayV3ActiveOverrides(canonicalState.overrides), @@ -237,7 +241,7 @@ assert.deepEqual( assert.deepEqual( dayV3ActiveOverrides(legacyState.overrides), expectedActiveOverrides, - "legacy hidden overrides must never reactivate in the unified simulator", + "all six visible contract anchors must remain active after canonicalization", ); // Every visible market-design input feeds one exact deployment-service request. @@ -326,7 +330,7 @@ const editedState = readDayV3UrlState( sourceApyPct: 7, overrides: { ...canonicalState.overrides, - jrYieldShareAtTargetPct: 20, + jrYieldShareAtTargetPct: 15, slpYieldShareAtTargetPct: 10, }, }), @@ -339,7 +343,7 @@ assert.equal(editedState.minimumProceedsPer100, 95); assert.equal(editedState.entryPointSettlementDays, 90); assert.equal(editedState.collateralToExitDays, 0); assert.equal(editedState.collateralToExitCostBps, 50); -assert.equal(editedState.overrides.jrYieldShareAtTargetPct, 20); +assert.equal(editedState.overrides.jrYieldShareAtTargetPct, 15); assert.equal(editedState.overrides.slpYieldShareAtTargetPct, 10); assert.equal(editedState.mode, null); diff --git a/lib/day-v3/url-state.ts b/lib/day-v3/url-state.ts index cd03c8f..f9caba7 100644 --- a/lib/day-v3/url-state.ts +++ b/lib/day-v3/url-state.ts @@ -4,6 +4,7 @@ import type { DayV3GoalDraft, DayV3Overrides, } from "@/lib/day-v3/types"; +import { dayV3MarketDefaults } from "@/lib/day-v3/market-defaults"; import { validateDayV3YieldCurveDesign } from "@/lib/day-v3/yield-curves"; export type DayV3Mode = "simulate" | "deploy"; @@ -123,6 +124,7 @@ export function applyDayV3StarterDefaults( } { const params = new URLSearchParams(search); const customSource = !params.has("m") || state.market === "custom"; + const marketDefaults = dayV3MarketDefaults(state.market); // Legacy links may carry a `starter` marker. Continue honoring it when links // are read, even though the canonical writer no longer serializes UI-only @@ -139,6 +141,19 @@ export function applyDayV3StarterDefaults( if (!appliedFields.includes(field)) appliedFields.push(field); return fallback; }; + const marketValueWhenAbsent = ( + keys: string[], + current: T | null, + fallback: T | undefined, + ): T | null => { + if (keys.some((key) => params.has(key)) || fallback === undefined) { + return current; + } + return current ?? fallback; + }; + const hasCurveParameter = ["jr0", "jr90", "jr100", "slp0", "slp90", "slp100"].some( + (key) => params.has(key), + ); const nextState: DayV3UrlState = { ...state, @@ -153,29 +168,62 @@ export function applyDayV3StarterDefaults( DAY_V3_STARTER_DEFAULTS.sourceApyPct, ) : state.sourceApyPct, + quoteAssetLabel: marketValueWhenAbsent( + ["quote"], + state.quoteAssetLabel, + marketDefaults?.quoteAssetLabel, + ), + quoteAssetYieldPct: marketValueWhenAbsent( + ["quoteApy"], + state.quoteAssetYieldPct, + marketDefaults?.quoteAssetYieldPct, + ), + poolTurnoverPerYear: marketValueWhenAbsent( + ["turnover"], + state.poolTurnoverPerYear, + marketDefaults?.poolTurnoverPerYear, + ), + swapFeeBps: marketValueWhenAbsent( + ["fee"], + state.swapFeeBps, + marketDefaults?.swapFeeBps, + ), + marketMakerCostOfCapitalPct: marketValueWhenAbsent( + ["mmCost"], + state.marketMakerCostOfCapitalPct, + marketDefaults?.marketMakerCostOfCapitalPct, + ), + redemptionDays: marketValueWhenAbsent( + ["mmDays"], + state.redemptionDays, + marketDefaults?.redemptionDays, + ), protectedDrawdownPct: whenAbsent( "drawdown", ["protect"], state.protectedDrawdownPct, - DAY_V3_STARTER_DEFAULTS.protectedDrawdownPct, + marketDefaults?.protectedDrawdownPct ?? + DAY_V3_STARTER_DEFAULTS.protectedDrawdownPct, ), recoveryDays: whenAbsent( "recovery", ["recover"], state.recoveryDays, - DAY_V3_STARTER_DEFAULTS.recoveryDays, + marketDefaults?.recoveryDays ?? DAY_V3_STARTER_DEFAULTS.recoveryDays, ), immediateExitSharePct: whenAbsent( "exit-amount", ["exit"], state.immediateExitSharePct, - DAY_V3_STARTER_DEFAULTS.immediateExitSharePct, + marketDefaults?.immediateExitSharePct ?? + DAY_V3_STARTER_DEFAULTS.immediateExitSharePct, ), minimumProceedsPer100: whenAbsent( "payout", ["receive"], state.minimumProceedsPer100, - DAY_V3_STARTER_DEFAULTS.minimumProceedsPer100, + marketDefaults?.minimumProceedsPer100 ?? + DAY_V3_STARTER_DEFAULTS.minimumProceedsPer100, ), entryPointSettlementDays: customSource ? whenAbsent( @@ -249,6 +297,10 @@ export function applyDayV3StarterDefaults( state.target, DAY_V3_STARTER_DEFAULTS.target, ), + overrides: + marketDefaults && !hasCurveParameter + ? { ...state.overrides, ...marketDefaults.overrides } + : state.overrides, }; return { applied: appliedFields.length > 0, @@ -360,10 +412,10 @@ export function readDayV3UrlState(search: string): DayV3UrlState { y100Pct: curveOverrides.slpYieldShareAtFullPct as number, }, }).valid; - // The unified editor may carry the two visible target shares alone; its - // hidden endpoints are re-derived from the disclosed fixed basis. A legacy - // six-anchor curve is accepted only when the full shape is valid. Every - // other partial, inverted, or over-budget curve is rejected as a unit. + // Older links may carry only the two target shares. The six-anchor editor + // writes a complete curve, which is accepted only when its ordering and + // shared Senior-yield budget are valid. Every other partial, inverted, or + // over-budget curve is rejected as a unit. const acceptedCurveOverrides = !hasAnyCurveOverride || (!validCurveOverride && !hasTargetOnlyCurveOverride) @@ -520,11 +572,32 @@ export function buildDayV3Query(state: DayV3UrlWriteState): string { params.set("recover", "0"); } - if (state.protectedDrawdownPct !== 0) { + const hasCurveShapeOverride = [ + state.overrides.jrYieldShareAtZeroPct, + state.overrides.jrYieldShareAtFullPct, + state.overrides.slpYieldShareAtZeroPct, + state.overrides.slpYieldShareAtFullPct, + ].some((value) => value !== null); + const hasActiveYieldCurve = + state.protectedDrawdownPct !== 0 || state.immediateExitSharePct !== 0; + if (hasCurveShapeOverride && hasActiveYieldCurve) { + // A shaped curve is one atomic contract policy. Serialize all six anchors, + // including zeros for a disabled tranche, so the strict reader can reject + // malformed partial curves instead of silently modeling a different one. + setNumber("jr0", state.overrides.jrYieldShareAtZeroPct); setNumber("jr90", state.overrides.jrYieldShareAtTargetPct); - } - if (state.immediateExitSharePct !== 0) { + setNumber("jr100", state.overrides.jrYieldShareAtFullPct); + setNumber("slp0", state.overrides.slpYieldShareAtZeroPct); setNumber("slp90", state.overrides.slpYieldShareAtTargetPct); + setNumber("slp100", state.overrides.slpYieldShareAtFullPct); + } else { + // Preserve compact target-only links produced by older versions. + if (state.protectedDrawdownPct !== 0) { + setNumber("jr90", state.overrides.jrYieldShareAtTargetPct); + } + if (state.immediateExitSharePct !== 0) { + setNumber("slp90", state.overrides.slpYieldShareAtTargetPct); + } } return params.toString(); } diff --git a/lib/day-v3/yield-curves.ts b/lib/day-v3/yield-curves.ts index 25b9615..6ee4a95 100644 --- a/lib/day-v3/yield-curves.ts +++ b/lib/day-v3/yield-curves.ts @@ -53,13 +53,13 @@ const zeroCurve = (): DayV3YieldCurveAnchors => ({ const formatPct = (value: number) => `${value.toFixed(2)}%`; /** - * Bound the one issuer-editable curve point to the derived curve endpoints. + * Bound a target-only override from an older link to the derived endpoints. * - * V3 intentionally hides Y0 and Y100. Older links can still contain a YT that - * predates those derived bounds, so the visible slider and the accountant must - * agree on the same valid value instead of showing one number and modeling - * another. This only constrains an input; curve evaluation remains in the - * shared Day engine. + * The current editor writes all six anchors as one validated policy. Older + * links can still contain only YT, so the displayed slider and the accountant + * must agree on the same valid value instead of showing one number and + * modeling another. This only constrains an input; curve evaluation remains + * in the shared Day engine. */ export function boundDayV3YieldShareAtTarget({ targetPct, diff --git a/scripts/day-v3/model-output-parity.test.mjs b/scripts/day-v3/model-output-parity.test.mjs index ca188b9..8ce2618 100644 --- a/scripts/day-v3/model-output-parity.test.mjs +++ b/scripts/day-v3/model-output-parity.test.mjs @@ -125,18 +125,18 @@ assert.match( ); assert.doesNotMatch( `${summary}\n${editor}`, - /presentation=|showCurveShapeAnchors|deployOnly|\bsimple\b|\bAdvanced\b|six YDM anchors|deployment handoff|suggestedCurve/, - "The sole yield-split editor must not retain mode-specific or full-curve controls", + /presentation=|showCurveShapeAnchors|deployOnly|\bsimple\b|\bAdvanced\b|deployment handoff|suggestedCurve/, + "The sole yield-split editor must not retain mode-specific controls", ); -assert.doesNotMatch( +assert.match( editor, - /onRiskY0Pct|onRiskY100Pct|onLiqY0Pct|onLiqY100Pct|No coverage used \(Y0\)|Full coverage used \(Y100\)/, - "The unified editor must expose only operating-target yield shares", + /onRiskY0Pct[\s\S]*onRiskY100Pct[\s\S]*onLiqY0Pct[\s\S]*onLiqY100Pct/, + "The unified editor must expose both contract curves' Y0 and Y100 anchors", ); assert.match( modeModel, - /jrYieldShareAtTargetPct:\s*overrides\.jrYieldShareAtTargetPct[\s\S]*slpYieldShareAtTargetPct:\s*overrides\.slpYieldShareAtTargetPct/, - "Only the two visible target yield shares may remain active", + /jrYieldShareAtZeroPct:\s*overrides\.jrYieldShareAtZeroPct[\s\S]*jrYieldShareAtTargetPct:\s*overrides\.jrYieldShareAtTargetPct[\s\S]*jrYieldShareAtFullPct:\s*overrides\.jrYieldShareAtFullPct[\s\S]*slpYieldShareAtZeroPct:\s*overrides\.slpYieldShareAtZeroPct[\s\S]*slpYieldShareAtTargetPct:\s*overrides\.slpYieldShareAtTargetPct[\s\S]*slpYieldShareAtFullPct:\s*overrides\.slpYieldShareAtFullPct/, + "All six visible contract yield anchors must remain active", ); const protectionGroupStart = goals.indexOf( @@ -326,16 +326,17 @@ for (const marker of [ assert.ok(backtest.includes(marker), `Historical model lost: ${marker}`); } -// Hidden legacy curve anchors remain derived and cannot affect the unified UI. +// One reusable curve card renders the two configurable endpoints for each YDM; +// the fixed YT contract kink remains routed through the parent accountant state. assert.equal( editor.match(/