Skip to content

Adapter execution#144

Open
matteoettam09 wants to merge 160 commits intomainfrom
adapter-execution
Open

Adapter execution#144
matteoettam09 wants to merge 160 commits intomainfrom
adapter-execution

Conversation

@matteoettam09
Copy link
Member

@matteoettam09 matteoettam09 commented Feb 10, 2026

Summary by Sourcery

Introduce a new cross-asset ERC4626 execution and pricing architecture with external swap executors and Chainlink-based price feeds, and update tests and CI to validate cross-asset flows on a mainnet fork.

New Features:

  • Add ERC4626ExecutionAdapter that routes vault operations through token-specific swap executors retrieved from the LiquidityOrchestrator.
  • Add Uniswap V3- and Curve-based swap executors plus a generic ISwapExecutor interface for venue-agnostic token swaps.
  • Add ChainlinkPriceAdapter and ERC4626PriceAdapter contracts (and a mock variant) to compose vault share prices from underlying oracle feeds.
  • Extend LiquidityOrchestrator with helper slippage calculation functions and expose executionAdapterOf via the interface.

Bug Fixes:

  • Fix ERC4626 price precision tests to validate composed cross-asset pricing without truncation.

Enhancements:

  • Refactor tests to use the new ERC4626ExecutionAdapter and price adapters, including support for same-asset and cross-asset vaults.
  • Improve MockPriceAdapter to return realistic ERC4626 exchange rates and pseudo-random prices for non-vault assets.
  • Expand ErrorsLib with swap-, price-, and oracle-related errors for stronger validation and revert reasons.

Build:

  • Add Uniswap V3 core and periphery dependencies for on-chain swap execution.
  • Configure Hardhat to fork mainnet conditionally for cross-asset and coverage test runs.

CI:

  • Split CI test job into standard unit tests and dedicated mainnet-fork cross-asset tests, and ensure coverage runs with appropriate RPC configuration.

Tests:

  • Add comprehensive E2E and coverage tests for ERC4626 execution adapters, price adapters, Chainlink integration, swap executors, and protocol slippage behavior on a mainnet fork.
  • Update existing protocol, orchestrator, strategist, accounting, and pause tests to use the new adapters and mocks.

Summary by CodeRabbit

  • New Features

    • Cross-asset ERC‑4626 vault support, composed ERC‑4626 pricing, Chainlink feeds, and Uniswap V3 execution integration.
    • Centralized slippage management applied to buy/sell flows.
  • Refactor

    • Generalized ERC‑4626 adapters and streamlined execution adapter interface (reduced parameters).
  • Chores

    • Package bumped to 2.1.0; CI split into unit, fork, and coverage steps; added ignore entry.
  • Tests

    • Extensive unit and mainnet‑fork E2E suites and testing mocks added.

ojasarora77 and others added 30 commits January 2, 2026 20:10
… and cross-asset flows

What it does:
Handles buy/sell operations for ERC4626 vaults
Supports both same-asset (USDC vaults) and cross-asset (WETH vaults) flows
Routes through swap executors for cross-asset conversions
Validates all operations before execution
Key features:
Routing parameter support for DEX configuration
Automatic underlying asset detection
Comprehensive slippage protection
Approval hygiene (zero approvals after each operation)
Uniswap: Executes exact-input and exact-output swaps via Uniswap V3
Supports configurable fee tiers (500/3000/10000 bps)
Refunds unused input tokens on exact-output swaps

Curve: Optimized for stablecoin swaps (USDC/USDT/DAI)
Approximates exact-output swaps (1:1 + 0.2% buffer)
Supports both regular and underlying token exchanges
Implements 5 mandatory Chainlink security checks (Euler/Morpho best practices)
Supports inverse feeds (e.g., USDC/ETH → ETH/USDC)
Configurable price bounds and staleness thresholds
…cross-asset pricing

Composes vault share prices from underlying asset prices
Handles both same-asset and cross-asset vaults
Normalizes to protocol standard (14 decimals)
UniswapV3SwapExecutor exact-output and exact-input swaps
CurveSwapExecutor stablecoin swaps
Mock DEX interactions
Error handling
Mainnet fork at latest block
Real contracts: Morpho WETH vault (0x31A5...24f9), Uniswap V3, Chainlink oracles
Impersonated whale accounts for token funding
Test coverage (20 tests):
Buy Flow Tests:
Price estimation accuracy
Buy execution with Uniswap V3 routing
Excess USDC refund
Slippage protection
Sell Flow Tests:
Sell estimation accuracy
Sell execution with Uniswap V3 routing
Expected USDC receipt
Oracle Integration:
Vault price calculation
Chainlink security checks
Stale data handling
Edge Cases:
Vault withdrawal fees
Extreme decimal differences
Swap executor failures
Approval hygiene
Gas Benchmarking:
Buy operation: ~635k gas
Sell operation: ~478k gas
Orchestrator hasn't been changed recently for this cross-asset work. So the Orchestrator is still building orders assuming the old adapter behavior (underlying amounts), but my new adapter expects shares.
- Rename numeraireToken → underlyingAsset throughout
- Rename parameters: estimatedNumeraireAmount → estimatedUnderlyingAmount
- Consolidate return values to executionUnderlyingAmount
- Add vault underlying decimals validation
- Create DRY slippage helper functions
- Remove try-catch blocks around swap execution
- Remove all inline development comments
- Fix mainnet fork test configuration
- Move slippage helper functions from ERC4626ExecutionAdapter to LiquidityOrchestrator
- LiquidityOrchestrator now calculates max/min amounts and approves them
- Adapter reads max amount from LO's allowance instead of calculating internally
- Sell flow passes 0 as minAmount to swap executor (LO validates final amount)
- Remove BASIS_POINTS_FACTOR constant from adapter (no longer needed)
- Update contract documentation to reflect centralized slippage management
- Add UniswapV3TokenSwapExecutor for dedicated token swaps
- Add ERC4626VaultAdapter that delegates to swap executors via LO.executionAdapterOf
- Remove ERC4626ExecutionAdapter (replaced by dynamic architecture)
- Update MockLiquidityOrchestrator with executionAdapterOf mapping
- Add comprehensive E2E tests with mainnet forking
- Architecture: tokens → swap executors, vaults → vault adapters → swap executors
New ERC4626 test includes all the test cases withing Adapters.test.ts -> removed repeated test Adapters.test
Now both buy and sell flows have proper slippage protection:
Buy: Enforces max spending limit via approval amount
Sell: Validates minimum received amount after execution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants