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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ When touching transaction and position flows, validation MUST include all releva
26. **Deterministic ERC4626 quote/execution matching**: when a no-swap ERC4626 leverage leg uses vault previews, the execute-time operation must match the preview semantics exactly: `previewDeposit` should map to exact-asset deposit with the quoted share floor, and `previewMint` should map to exact-share mint with the quoted asset cap. Do not reuse swap-style slippage floors on either path.
27. **Transaction-tracking preflight integrity**: do not call `tracking.start(...)` until all synchronous preflight validation for the flow has passed (account, route, quote, input, fee viability). Once tracking has started, execution helpers must either complete successfully or throw so the caller can finish the lifecycle with exactly one `tracking.complete()` or `tracking.fail()`.
28. **Close-route collateral handoff integrity**: when a deleverage projection derives an exact close-bound collateral amount for full-repay-by-shares, route-specific executors must receive and use that quote-derived close bound explicitly for withdraw/redeem steps instead of relying on the raw user input amount. Any remaining collateral must be returned through the dedicated post-close withdraw/sweep path.
29. **Preview prop integrity**: any position/risk preview component that separates current and projected props must receive quote- or input-derived projected balances through dedicated `projected*` props while preserving live balances in `current*` props, so amount rows, LTV deltas, and liquidation metrics stay synchronized instead of mixing current and projected states.


### REQUIRED: Regression Rule Capture
Expand Down
7 changes: 5 additions & 2 deletions src/modals/borrow/components/add-collateral-and-borrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function AddCollateralAndBorrow({
const currentCollateralAssets = BigInt(currentPosition?.state.collateral ?? 0);
const currentBorrowAssets = BigInt(currentPosition?.state.borrowAssets ?? 0);
const projectedCollateralAssets = currentCollateralAssets + collateralAmount;
const projectedBorrowAssets = currentBorrowAssets + borrowAmount;
const hasChanges = collateralAmount > 0n || borrowAmount > 0n;

const extraLiquidity = liquiditySourcing?.totalAvailableExtraLiquidity ?? 0n;
Expand Down Expand Up @@ -99,11 +100,11 @@ export function AddCollateralAndBorrow({
const projectedLTV = useMemo(
() =>
computeLtv({
borrowAssets: currentBorrowAssets + borrowAmount,
borrowAssets: projectedBorrowAssets,
collateralAssets: projectedCollateralAssets,
oraclePrice,
}),
[currentBorrowAssets, borrowAmount, projectedCollateralAssets, oraclePrice],
[projectedBorrowAssets, projectedCollateralAssets, oraclePrice],
);

const maxTargetLtvPercent = useMemo(() => Math.min(100, ltvWadToPercent(clampTargetLtv(lltv, lltv))), [lltv]);
Expand Down Expand Up @@ -207,6 +208,8 @@ export function AddCollateralAndBorrow({
oraclePrice={oraclePrice}
currentCollateral={currentCollateralAssets}
currentBorrow={currentBorrowAssets}
projectedCollateral={projectedCollateralAssets}
projectedBorrow={projectedBorrowAssets}
currentLtv={currentLTV}
projectedLtv={projectedLTV}
lltv={lltv}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export function WithdrawCollateralAndRepay({
oraclePrice={oraclePrice}
currentCollateral={currentCollateralAssets}
currentBorrow={currentBorrowAssets}
projectedCollateral={projectedCollateralAssets}
projectedBorrow={projectedBorrowAssets}
currentLtv={currentLTV}
projectedLtv={projectedLTV}
lltv={lltv}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ export function RemoveCollateralAndDeleverage({
oraclePrice={oraclePrice}
currentCollateral={currentCollateralAssets}
currentBorrow={currentBorrowAssets}
projectedCollateral={projection.projectedCollateralAssets}
projectedBorrow={projection.projectedBorrowAssets}
currentLtv={currentLTV}
projectedLtv={displayProjectedLTV}
lltv={lltv}
Expand Down