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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Changes to `lib/try/engine.ts`, `lib/try/backtest.ts`, `components/simulator/`,
5. Pareto FalconX v3 is the grounded default. Fonts, colors, borders, spacing, charts, diagrams, and behavior remain shared and byte-locked; an authorized market may use supported section-visibility or copy overrides without forking the component.
6. Never guess provenance, price type, fee treatment, desired yield ranges, hidden parameters, or customization authority. Incomplete intake must remain `unknown` and fail verification.
7. Calibrate with `npm run day-sim:calibrate -- <market-id>`; never calculate tranche outputs independently.
8. Run `npm run day-sim:verify -- <market-id>` and `npm run day-sim:certify -- <market-id>` before requesting publication. Certification must pass all 74 Solidity vectors, tests, lint, and build.
8. Run `npm run day-sim:verify -- <market-id>` and `npm run day-sim:certify -- <market-id>` before requesting publication. Certification must pass all 78 Solidity vectors, tests, lint, and build.
9. If an explicitly authorized customization is not yet supported, extend the shared manifest-driven customization schema with tests; do not create a one-off market component. Updating the template lock is a maintainer action after full certification.
10. Do not create or merge a PR until verification and certification pass and the user approves the browser preview.
11. Erasure annotations consume the accountant's structured erased amount and pre-refill Junior valuation. Never parse event copy or size erasure against a same-timestamp refill.
12 changes: 6 additions & 6 deletions app/api/day-v3/pool-design/simulation/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
import { resetDayV3SimulationProxyForTests } from "@/lib/day-v3/pool-proxy-cache";

const requestBody = JSON.stringify({
schemaVersion: "1.0",
schemaVersion: "1.1",
goals: {
protectedDrawdownPct: 15,
recoveryDays: 20,
immediateExitSharePct: 10,
minimumProceedsPer100: 95,
},
context: { sourceApyPct: 6 },
context: { sourceApyPct: 6, swapFeeBps: 10 },
});

function request(body = requestBody, declaredLength?: number) {
Expand Down Expand Up @@ -99,8 +99,8 @@ async function main() {
);
return new Response(
JSON.stringify({
schemaVersion: "1.0",
modelVersion: "day-v3-eclp-goal-solver-1.1.0",
schemaVersion: "1.1",
modelVersion: "day-v3-eclp-goal-solver-1.2.0",
mode: "simulation",
status: "infeasible",
recommendation: null,
Expand Down Expand Up @@ -131,8 +131,8 @@ async function main() {
await heldUpstream;
return new Response(
JSON.stringify({
schemaVersion: "1.0",
modelVersion: "day-v3-eclp-goal-solver-1.1.0",
schemaVersion: "1.1",
modelVersion: "day-v3-eclp-goal-solver-1.2.0",
mode: "simulation",
status: "infeasible",
recommendation: null,
Expand Down
10 changes: 4 additions & 6 deletions components/day-v3/DayV3Backtest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,10 @@ function DayV3Backtest({
);

// The engine is template code under the byte lock, so a pool assumption it
// cannot integrate is caught here rather than fixed there. Modeled fee income
// is `turnover x fee`, compounded every step: JBBB at 100x turnover and a
// 100% swap fee runs `pool.stable` to Infinity and the run throws
// `cannot convert non-finite number to WAD`, which took the page down. The
// fee bound below keeps real inputs well clear of that; this makes it
// impossible to reach by any route at all.
// cannot integrate is caught here rather than fixed there. Contract-valid
// fees can still be economically extreme when combined with high turnover;
// surface a bounded backtest error instead of letting the history take down
// the page.
const [result, resultError] = useMemo<
[DayBacktestResult | null, string | null]
>(() => {
Expand Down
2 changes: 1 addition & 1 deletion components/day-v3/DayV3Deployment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ function DayV3Deployment({
</div>
<CardNote>
One relative design, normalized to $100 Senior. Deployment must
revalidate it against the live template; absolute funding stays open
revalidate it against the selected market pool; absolute funding stays open
until deployment has a notional and initialization policy.
</CardNote>
</CardHeader>
Expand Down
4 changes: 2 additions & 2 deletions components/day-v3/DayV3DeploymentTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export default function DayV3DeploymentTarget({
className="text-[10.5px] leading-relaxed text-[var(--tertiary)]"
id="day-v3-deployment-target-message"
>
{message} Selecting a target resolves its live swap fee and validates
the pool design. No fallback fee is used.
{message} Selecting a target resolves the canonical market-pool fee
and validates the pool design. No fallback fee is used.
</span>
</label>
</section>
Expand Down
33 changes: 16 additions & 17 deletions components/day-v3/DayV3ExitModel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ assert.match(resolvedMarkup, /Maximum discount the pool has/);
assert.match(resolvedMarkup, /1000 bps/);
assert.match(resolvedMarkup, /500 bps/);
assert.match(resolvedMarkup, /380 bps/);
assert.match(resolvedMarkup, /Proceeds: \$9\.62 after the live swap fee/);
assert.match(resolvedMarkup, /Proceeds: \$9\.62 after the canonical pool swap fee/);
// The swap fee, minimum liquidity and maximum discount are pool terms, not
// results of this comparison, and the cards that depend on them state them.
assert.doesNotMatch(resolvedMarkup, /Swap fee: /);
Expand Down Expand Up @@ -108,7 +108,7 @@ const unresolvedMarkup = renderToStaticMarkup(
assert.match(unresolvedMarkup, /data-model-state="resolving"/);
assert.match(
unresolvedMarkup,
/Refreshing the live template and recalculating this model/,
/Refreshing the canonical pool and recalculating this model/,
);
assert.doesNotMatch(unresolvedMarkup, /Proceeds:/);

Expand Down Expand Up @@ -367,14 +367,14 @@ assert.match(
assert.doesNotMatch(goalsMarkup, /of \$100/);
assert.doesNotMatch(goalsMarkup, /See .*impact/i);

// The pool's swap fee is the issuer's to set, with an inherited default. An
// The pool's swap fee is the issuer's to set, with a market-declared default. An
// empty field is labelled for what it is — the fee the model is assuming — and
// a typed one is never presented as the template's own policy.
assert.match(
goalsMarkup,
/What swap fee should the pool charge on a sale\?/,
);
assert.match(goalsMarkup, /Use the live fee/);
assert.match(goalsMarkup, /Use the market fee/);
assert.match(goalsMarkup, /Model assumption/);
assert.doesNotMatch(goalsMarkup, /Manual override/);

Expand All @@ -383,13 +383,10 @@ const handSetFeeMarkup = renderToStaticMarkup(
);
assert.match(handSetFeeMarkup, /Manual override/);
assert.doesNotMatch(handSetFeeMarkup, /Live template|Product policy/);
// These two bounds are the only guard against `previewSecondarySell` throwing
// INVALID_SWAP_FEE inside a render-time memo with no error boundary above it.
// The field mirrors Gyro's inclusive contract bounds; render-time engine errors
// remain surfaced by the model/backtest error paths.
assert.match(handSetFeeMarkup, /min="0\.01"/);
// 10% is an order of magnitude above any pool anyone runs, and well clear of
// the corner where turnover x fee compounds modeled income past what the engine
// can hold — measured: JBBB threw at 100x turnover and a 100% fee.
assert.match(handSetFeeMarkup, /max="1000"/);
assert.match(handSetFeeMarkup, /max="10000"/);

const protectionStart = goalsMarkup.indexOf('id="day-v3-protection-inputs"');
const observationMode = goalsMarkup.indexOf('aria-label="Observation mode"');
Expand Down Expand Up @@ -514,8 +511,8 @@ assert.match(restockMarkup, /Margin above restock hurdle/);
assert.doesNotMatch(restockMarkup, /cost of capital/i);
assert.doesNotMatch(restockMarkup, /break[- ]even/i);

// A live template solved its own band; saying the payout floor set it named the
// wrong pool, and it was named beside quotes taken off the template's curve.
// A canonical pool solved its own band; saying the payout floor set it named the
// wrong pool, and it was named beside quotes taken off the canonical curve.
assert.match(
renderToStaticMarkup(
<DayV3RestockCheck
Expand All @@ -526,11 +523,11 @@ assert.match(
view={{ ...restockView, maximumDiscountSource: "live-template" }}
/>,
),
/the live template solved for/,
/the canonical pool solved for/,
);

// A sale the pool cannot absorb is priced for the slice that fills, so it is
// described as that slice rather than as the exit the issuer promised.
// A sale the pool cannot absorb is shown at its capacity boundary, while the
// copy makes clear that the requested exact-input trade would revert atomically.
const partialMarkup = renderToStaticMarkup(
<DayV3RestockCheck
costOfCapitalPct={20}
Expand All @@ -544,8 +541,10 @@ const partialMarkup = renderToStaticMarkup(
}}
/>,
);
assert.match(partialMarkup, /the part that fills/);
assert.match(partialMarkup, /only \$4\.00 fits in the pool/);
assert.match(partialMarkup, /maximum atomic order below NAV/);
assert.match(partialMarkup, /requested \$10\.00 exit is too large/);
assert.match(partialMarkup, /largest order this pool can accept is \$4\.00/);
assert.match(partialMarkup, /not partially filled/);

// A market quoted in ETH never gets a dollar sign in front of a number of ETH.
const ethMarkup = renderToStaticMarkup(
Expand Down
4 changes: 2 additions & 2 deletions components/day-v3/DayV3ExitModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default function DayV3ExitModel({
) : exit.status === "resolving" || exit.message ? (
<p className="rounded-lg border border-dashed border-[var(--border-subtle)] px-3 py-3 text-[11.5px] leading-relaxed text-[var(--secondary)]">
{exit.status === "resolving"
? "Refreshing the live template and recalculating this model…"
? "Refreshing the canonical pool and recalculating this model…"
: exit.message}
</p>
) : null}
Expand All @@ -222,7 +222,7 @@ export default function DayV3ExitModel({
Proceeds: {dollars(exit.proceeds, 2)}{" "}
{illustrative
? "after the modeled swap fee"
: "after the live swap fee"}
: "after the canonical pool swap fee"}
</span>
) : null}
{/*
Expand Down
7 changes: 5 additions & 2 deletions components/day-v3/DayV3Goals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type DayV3ExitView = {
lowestPayoutPer100: MaybeNumber;
slpPer100: MaybeNumber;
restockPoint: MaybeNumber;
/** Time/carry and external-conversion hurdle before the live pool fee. */
/** Time/carry and external-conversion hurdle before the market pool fee. */
restockOperationalHurdleBps: MaybeNumber;
/** All-in hurdle used by the canonical pool-design calculation. */
restockHurdleBps: MaybeNumber;
Expand Down Expand Up @@ -130,6 +130,7 @@ export default function DayV3Goals({
poolPremiumEdited = false,
poolTurnoverPerYear,
defaultPremiumBps,
defaultSwapFeeBps,
onPoolPremiumBps,
poolPremiumBps,
restingSeniorWeight,
Expand Down Expand Up @@ -169,9 +170,10 @@ export default function DayV3Goals({
quoteAssetYieldPct: MaybeNumber;
recoveryDays: MaybeNumber;
recoveryMode: "none" | "window" | null;
/** The issuer's own pool fee. `null` inherits the live template's. */
/** The issuer's per-market pool fee. `null` uses the market declaration. */
swapFeeBps: MaybeNumber;
defaultPremiumBps: MaybeNumber;
defaultSwapFeeBps?: number;
onPoolPremiumBps: (value: number | null) => void;
poolPremiumEdited?: boolean;
poolPremiumBps: MaybeNumber;
Expand Down Expand Up @@ -510,6 +512,7 @@ export default function DayV3Goals({
label={quoteAssetLabel}
onLabel={onQuoteAssetLabel}
defaultPremiumBps={defaultPremiumBps}
defaultSwapFeeBps={defaultSwapFeeBps}
onPoolPremiumBps={onPoolPremiumBps}
poolPremiumEdited={poolPremiumEdited}
poolPremiumBps={poolPremiumBps}
Expand Down
23 changes: 13 additions & 10 deletions components/day-v3/DayV3QuoteAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useState } from "react";
import DayV3Button from "@/components/day-v3/DayV3Button";
import DayV3NumberField from "@/components/day-v3/DayV3NumberField";
import { DAY_V3_POOL_PREMIUM_BPS_RANGE } from "@/lib/day-v3/pool-curve";
import { DAY_V3_POOL_SWAP_FEE_BPS_RANGE } from "@/lib/day-v3/pool-design";
import DayV3Origin, {
type DayV3VisibleOrigin,
} from "@/components/day-v3/DayV3Origin";
Expand Down Expand Up @@ -41,6 +42,7 @@ export default function DayV3QuoteAsset({
label,
onLabel,
defaultPremiumBps,
defaultSwapFeeBps,
onPoolPremiumBps,
poolPremiumEdited,
poolPremiumBps,
Expand All @@ -57,6 +59,8 @@ export default function DayV3QuoteAsset({
onLabel: (value: string) => void;
/** What the pool rests on today, in bps, so an empty field can say so. */
defaultPremiumBps: number | null;
/** The selected market's declared fee, used to distinguish a default from an edit. */
defaultSwapFeeBps?: number;
onPoolPremiumBps: (value: number | null) => void;
/** Whether the displayed premium is an issuer edit or a loaded default. */
poolPremiumEdited: boolean;
Expand All @@ -77,7 +81,10 @@ export default function DayV3QuoteAsset({
// either until one resolves, so it is labelled for what it is: the fee the
// model is assuming. A hand-set fee is always the issuer's own override.
const feeOrigin: DayV3VisibleOrigin =
swapFeeBps === null ? "model-assumption" : "manual-override";
swapFeeBps === null ||
(defaultSwapFeeBps !== undefined && swapFeeBps === defaultSwapFeeBps)
? "model-assumption"
: "manual-override";
// A parent reset (switching source, clearing the exit) replaces the label.
// React's adjusted-state pattern re-seeds the draft without a second render.
if (!Object.is(draft.source, label)) {
Expand Down Expand Up @@ -195,8 +202,7 @@ export default function DayV3QuoteAsset({
onChange={onPoolPremiumBps}
origin={poolPremiumEdited ? "manual-override" : "model-assumption"}
// The premium actually in force, whatever set it — the market's own
// declared curve, a live template, or the modeled default. Calling it
// "the market's own" was false whenever it was not.
// declared curve, a canonical pool, or the modeled default.
placeholder={
defaultPremiumBps === null
? "Use the modeled premium"
Expand All @@ -216,15 +222,12 @@ export default function DayV3QuoteAsset({
<div className="flex min-w-0 flex-col gap-2">
<DayV3NumberField
label="What swap fee should the pool charge on a sale?"
// 1000 bps is 10%, an order of magnitude above any pool anyone runs
// and well clear of the corner where modeled fee income compounds
// past what the engine can hold.
max={1000}
min={0.01}
note="Empty uses the live template's fee. A fee set here prices every quote and withholds the canonical pool result, which was solved at the template's own fee. From 100 bps no positive trade can clear it."
max={DAY_V3_POOL_SWAP_FEE_BPS_RANGE.max}
min={DAY_V3_POOL_SWAP_FEE_BPS_RANGE.min}
note="Empty uses the selected market's declared fee. A value here is the per-market Gyro pool fee used in every quote; the contract accepts 0.01–10,000 bps. Higher fees reduce proceeds but do not make every trade impossible."
onChange={onSwapFeeBps}
origin={feeOrigin}
placeholder="Use the live fee"
placeholder="Use the market fee"
presets={[
{ label: "1 bps", value: 1 },
{ label: "5 bps", value: 5 },
Expand Down
Loading
Loading