diff --git a/AGENTS.md b/AGENTS.md index eb3f13b3..25ad3f79 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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 diff --git a/src/modals/borrow/components/add-collateral-and-borrow.tsx b/src/modals/borrow/components/add-collateral-and-borrow.tsx index c07133ea..eb8fafdf 100644 --- a/src/modals/borrow/components/add-collateral-and-borrow.tsx +++ b/src/modals/borrow/components/add-collateral-and-borrow.tsx @@ -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; @@ -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]); @@ -207,6 +208,8 @@ export function AddCollateralAndBorrow({ oraclePrice={oraclePrice} currentCollateral={currentCollateralAssets} currentBorrow={currentBorrowAssets} + projectedCollateral={projectedCollateralAssets} + projectedBorrow={projectedBorrowAssets} currentLtv={currentLTV} projectedLtv={projectedLTV} lltv={lltv} diff --git a/src/modals/borrow/components/withdraw-collateral-and-repay.tsx b/src/modals/borrow/components/withdraw-collateral-and-repay.tsx index 24ef94c6..15d96188 100644 --- a/src/modals/borrow/components/withdraw-collateral-and-repay.tsx +++ b/src/modals/borrow/components/withdraw-collateral-and-repay.tsx @@ -213,6 +213,8 @@ export function WithdrawCollateralAndRepay({ oraclePrice={oraclePrice} currentCollateral={currentCollateralAssets} currentBorrow={currentBorrowAssets} + projectedCollateral={projectedCollateralAssets} + projectedBorrow={projectedBorrowAssets} currentLtv={currentLTV} projectedLtv={projectedLTV} lltv={lltv} diff --git a/src/modals/leverage/components/remove-collateral-and-deleverage.tsx b/src/modals/leverage/components/remove-collateral-and-deleverage.tsx index b7e1c40f..6df74154 100644 --- a/src/modals/leverage/components/remove-collateral-and-deleverage.tsx +++ b/src/modals/leverage/components/remove-collateral-and-deleverage.tsx @@ -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}