DeFi Adapters

The src/lib/defi/ directory contains 71 files that handle all client-side DeFi protocol interactions. These adapters are the bridge between the UI and the smart contracts.

What Adapters Do

Each adapter knows how to:

  1. Encode transactions — build the calldata for a DeFi action (deposit, withdraw, swap)
  2. Fetch protocol data — get pool info, user positions, APYs from APIs
  3. Decode results — parse on-chain data into usable formats

Adapter Structure

Each protocol adapter follows a consistent structure:

lib/defi/{protocol}/
├── abi/           # Contract ABIs (Application Binary Interface)
├── actions.ts     # Functions to encode transactions for the bundler
├── data.ts        # Data fetching (pool info, positions, APYs)
├── types.ts       # TypeScript types for the protocol
└── utils.ts       # Helper functions (math, formatting)

Available Adapters

Uniswap (lib/defi/uniswap/)

Covers V2, V3, and V4. The most complex adapter because of concentrated liquidity math.

Sub-adapter Purpose
v2/ Basic AMM — add/remove liquidity, swap
v3/ Concentrated liquidity — mint, burn, collect, adjust ranges
v4/ Hooks-based pools — newer Uniswap architecture

Aave (lib/defi/aave/)

Lending and borrowing operations.

Function What It Encodes
supply() Deposit collateral into Aave
borrow() Borrow against collateral
repay() Repay borrowed amount
withdraw() Withdraw collateral

Morpho (lib/defi/morpho/)

MetaMorpho vault interactions using the ERC-4626 standard.

Yearn (lib/defi/yearn/)

Yearn vault deposits and withdrawals, also ERC-4626.

Aerodrome (lib/defi/aerodrome/)

Base chain DEX operations. Separate adapters for standard pools and Slipstream (concentrated liquidity).

Krystal (lib/defi/krystal/)

DEX data aggregation client. Used to fetch pool data across protocols.

Internal market trend analysis utilities.

Positions (lib/defi/positions/)

Position management helpers — aggregation, formatting, P&L calculations.

Web3 Libraries

The frontend uses multiple Ethereum libraries:

Library Version Primary Use
Viem 2.31.7 Lightweight reads, transaction encoding
Ethers v6 6.x Contract interaction, Safe SDK compatibility
Ethers v5 5.7.2 (aliased) Legacy Safe SDK compatibility
Safe Protocol Kit 6.1.1 Safe transaction building
Safe Relay Kit 4.1.0 Gasless transaction submission
Wagmi (via Dynamic) React hooks for Ethereum

Note: Running both Ethers v5 and v6 is a known technical debt item. The v5 dependency exists for backward compatibility with some Safe SDK components.

results matching ""

    No results matching ""