Skip to content

fix: liquidity#417

Closed
antoncoding wants to merge 4 commits intomasterfrom
fix/liquidity-sort
Closed

fix: liquidity#417
antoncoding wants to merge 4 commits intomasterfrom
fix/liquidity-sort

Conversation

@antoncoding
Copy link
Copy Markdown
Owner

@antoncoding antoncoding commented Feb 27, 2026

Summary by CodeRabbit

  • New Features

    • Added swap-based leverage and deleverage routes using Bundler3 and Paraswap adapters
    • Added leverage route availability detection and UI selection between ERC4626 and swap paths
    • Added Bundler3 encoding utilities and adapter ABIs for multicall support
  • Bug Fixes

    • Fixed liquidity column sorting to use correct asset denomination
    • Corrected non-compact market table layout sizing
  • Refactoring

    • Restructured leverage route types to support multiple route kinds
    • Removed deprecated leverage support hook in favor of new availability system
  • Documentation

    • Updated guidelines with Bundler3 callback integrity, quote completeness, and route consistency requirements
  • Chores

    • Added const enforcement linter rule
    • Updated column visibility defaults

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 27, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9dd6bb3 and 7cc34c7.

📒 Files selected for processing (23)
  • AGENTS.md
  • biome.jsonc
  • src/abis/bundlerV3.ts
  • src/abis/morphoGeneralAdapterV1.ts
  • src/abis/paraswapAdapter.ts
  • src/features/markets/components/column-visibility.ts
  • src/features/markets/components/markets-table-same-loan.tsx
  • src/features/markets/markets-view.tsx
  • src/features/swap/components/SwapModal.tsx
  • src/hooks/leverage/bundler3.ts
  • src/hooks/leverage/types.ts
  • src/hooks/leverage/useLeverageRouteAvailability.ts
  • src/hooks/useDeleverageQuote.ts
  • src/hooks/useDeleverageTransaction.ts
  • src/hooks/useFilteredMarkets.ts
  • src/hooks/useLeverageQuote.ts
  • src/hooks/useLeverageSupport.ts
  • src/hooks/useLeverageTransaction.ts
  • src/hooks/useMultiMarketSupply.ts
  • src/modals/borrow/borrow-modal.tsx
  • src/modals/leverage/components/add-collateral-and-leverage.tsx
  • src/modals/leverage/components/remove-collateral-and-deleverage.tsx
  • src/modals/leverage/leverage-modal.tsx

📝 Walkthrough

Walkthrough

Adds swap-backed leverage and deleverage flows using Bundler V3 and Velora adapters alongside existing ERC4626 paths. Introduces new ABI definitions for Bundler3, Morpho GeneralAdapter, and Paraswap. Extends leverage and deleverage hooks to support dual-path flows with route selection and safety checks. Updates modal components for route selection.

Changes

Cohort / File(s) Summary
Guidelines and Configuration
AGENTS.md, biome.jsonc
Added four new safety guidelines for Bundler3 swap handling (flashloan callback, multi-leg quote completeness, aggregator build integrity, route consistency) and enabled useConst lint rule.
ABI Definitions
src/abis/bundlerV3.ts, src/abis/morphoGeneralAdapterV1.ts, src/abis/paraswapAdapter.ts
New ABI constant exports for Bundler3 (multicall, callback, reentry), Morpho GeneralAdapter1 (seven functions for leverage operations), and Paraswap adapter (sell function with offsets).
Leverage Type System
src/hooks/leverage/types.ts
Replaced single LeverageRoute alias with union supporting both Erc4626LeverageRoute and new SwapLeverageRoute (with bundler3, generalAdapter, paraswap addresses). Removed LeverageSupport type. Added LEVERAGE_MAX_MULTIPLIER_BPS constant.
Leverage Utilities
src/hooks/leverage/bundler3.ts, src/hooks/leverage/useLeverageRouteAvailability.ts
New bundler3 utilities for encoding calls and parsing Paraswap offsets. New hook to probe ERC4626 asset compatibility and return available route modes with memoized swap and ERC4626 availability.
Leverage and Deleverage Hooks
src/hooks/useLeverageQuote.ts, src/hooks/useDeleverageQuote.ts, src/hooks/useLeverageTransaction.ts, src/hooks/useDeleverageTransaction.ts, src/hooks/useLeverageSupport.ts
Extended quote hooks with token params and Velora swap queries. Replaced transaction hooks with dual-path orchestration: ERC4626 via Bundler V2 or swap via Bundler V3 with callback validation, swap payload verification, and slippage enforcement. Removed obsolete useLeverageSupport.
Leverage Modal Components
src/modals/leverage/leverage-modal.tsx, src/modals/leverage/components/add-collateral-and-leverage.tsx, src/modals/leverage/components/remove-collateral-and-deleverage.tsx
Updated modal to use route availability and route mode selection. Replaced support prop with route across child components. Added route-aware branching, conditional Velora/Bundler3 flows, swap preview calculations, and UI labels reflecting route type.
Modal and Borrow Integration
src/modals/borrow/borrow-modal.tsx
Replaced useLeverageSupport with useLeverageRouteAvailability to determine leverage modal availability via hasAnyRoute.
Markets Table and Sorting
src/features/markets/components/column-visibility.ts, src/features/markets/components/markets-table-same-loan.tsx, src/features/markets/markets-view.tsx, src/hooks/useFilteredMarkets.ts
Updated Liquidity sort to use liquidityAssetsUsd instead of liquidityAssets. Changed default column visibility (borrowAPY, rateAtTarget now visible). Applied w-fit class to non-compact market table layout.
Minor Formatting and Cleanup
src/features/swap/components/SwapModal.tsx, src/hooks/useMultiMarketSupply.ts
Condensed multi-line expressions to single lines; no logic changes.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Modal as Leverage Modal
    participant Hook as useLeverageQuote
    participant Velora as Velora API
    participant Bundler3 as Bundler3 Contract
    participant Morpho as Morpho Protocol

    User->>Modal: Select swap route & input collateral
    Modal->>Hook: Call useLeverageQuote with swap route
    Hook->>Velora: Fetch BUY route (collateral → loan token)
    Velora-->>Hook: Price route + amounts
    Hook->>Velora: Fetch SELL route (loan token → collateral)
    Velora-->>Hook: Sell route for flashLoanAmount
    Hook-->>Modal: flashCollateralAmount, flashLoanAmount, swapPriceRoute
    Modal->>User: Display quote & preview
    User->>Modal: Execute leverage
    Modal->>Hook: Call useLeverageTransaction
    Hook->>Bundler3: Build & validate callback bundle
    Bundler3-->>Hook: Callback hash
    Hook->>Bundler3: Execute multicall (callback + Velora swap + Morpho operations)
    Bundler3->>Morpho: Flash borrow via callback
    Bundler3->>Velora: Execute swap (loan token → collateral)
    Bundler3->>Morpho: Supply collateral & borrow
    Bundler3-->>Hook: Transaction confirmed
    Hook-->>Modal: Success
    Modal-->>User: Leverage complete
Loading
sequenceDiagram
    actor User
    participant Modal as Deleverage Modal
    participant Hook as useDeleverageQuote
    participant Velora as Velora API
    participant Bundler3 as Bundler3 Contract
    participant Morpho as Morpho Protocol

    User->>Modal: Enter repay amount with swap route
    Modal->>Hook: Call useDeleverageQuote with swap route & tokens
    Hook->>Velora: Fetch SELL route (collateral → loan token)
    Velora-->>Hook: Swap price route & amounts
    Hook->>Velora: Fetch BUY route (repayAmount → collateral)
    Velora-->>Hook: Max collateral for debt repay
    Hook-->>Modal: repayAmount, maxCollateralForDebt, swapPriceRoute
    Modal->>User: Display quote & collateral needed
    User->>Modal: Execute deleverage
    Modal->>Hook: Call useDeleverageTransaction
    Hook->>Bundler3: Validate swap payload & Velora targets
    Hook->>Bundler3: Execute multicall (withdraw + repay + swap collateral back)
    Bundler3->>Morpho: Withdraw collateral
    Bundler3->>Morpho: Repay debt
    Bundler3->>Velora: Execute swap (freed collateral → loan token buffer)
    Bundler3-->>Hook: Transaction confirmed
    Hook-->>Modal: Success
    Modal-->>User: Deleverage complete
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • feat: ERC4626 looping #415 — Extended ERC4626 leverage hooks that this PR builds upon by adding parallel swap-backed paths and refactoring route selection.
  • feat: velora swap #416 — Parallel work adding Velora and Paraswap integration; shares new adapter ABIs and swap validation logic.
  • refactor: context #262 — Modified the same useFilteredMarkets.ts file to adjust liquidity sort property.

Suggested labels

feature request, ui

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/liquidity-sort

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
monarch Building Building Preview, Comment Feb 27, 2026 4:22pm

Request Review

@coderabbitai coderabbitai Bot added feature request Specific feature ready to be implemented ui User interface labels Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request Specific feature ready to be implemented ui User interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant