DeFi integration models are reusable architectural approaches for combining multiple protocols into a single application. Each of the five main models — Adapter, Proxy, Strategy, Vault, and Oracle Adapter — addresses specific challenges in integrating with different balances of gas, complexity, and risk. Choosing the right model will determine whether your combined position is capital-efficient or a potentially damaging trap.
The Composability Spectrum — From Basic Principles to Strategies
The “Money Lego” concept remains a unique value of DeFi: composability without permission allows developers to stack protocols like building blocks. However, in 2024-2026, it’s important to understand the models, not just the protocols. The explosion of protocols – Uniswap V4 hooks, ERC-4626 implementations, EigenLayer AVS – means that every integration decision today is architecturally critical. A saying sums up the principle: every DeFi protocol you integrate increases your attack surface – models are your risk management framework.
Diagram - DeFi composability stack: base layer (EVM) → primitives (ERC20, AMM, lending) → composable
Layer 0: EVM Execution environment
The call-based contracts via CALL, DELEGATECALL, and STATICCALL form the foundation. DELEGATECALL specifically supports proxy patterns – it executes code outside the caller’s memory context, a mechanism that lies behind the logic of upgradeable.
Level 1: Token standard
- ERC-20: replaceable token database
Level 2: basic units
| Rough | Main protocols | Combined capability interface |
|---|---|---|
| AMM | Uniswap V3/V4, Curve, Balancer | the functions swap, mint, burn, and flash |
| Cho vay | Aave V3, Compound V3, Morpho Blue | 'supply', 'borrow', 'flashLoan', 'liquidationCall' |
| Cryptocurrencies are stable | USDC, DAI, LUSD, VNDC | mint, redeem, oracle price data sources |
Level 3: Protocols may be composed
The DEX aggregator (1inch, Paraswap, Matcha) operates through the basic units of Layer 2. Optimization tools (Yearn, Beefy, Sommelier) combine lending + AMM + strategy logic. Leverage protocols (Gearbox, Euler, Contango) combine lending + DEX + oracles for positions without fully collateralized assets.
Level 4: User Strategy
Leveraged yield, basis trade (spot + perp), delta neutral (LP + hedge), cross-chain arb (bridge + arb + bridge). Each strategy is a specific structure of the Layer 2-3 primitives.
Main integrated model classification
These five models form a decision framework. Start with the simplest model that solves your problem – each layer adds additional attack surface.
Flowchart - Core DeFi integration patterns: Adapter, Proxy, Strategy, Vault, Oracle Adapter, each wi
| Template | You've solved the problem. | Main Mechanism | Air Ceiling | Complex | Surface inspection table |
|---|---|---|---|---|---|
| Adapter | Enclosing the external interface | The Wrapper contract translates calls | +20-50k | Low | Only the Wrapper |
| Proxy (EIP-2535) | Logic can be upgraded | Diamond standard / flat pattern | +50-100k | High | Bezel + diamond |
| Strategic (ERC-4626) | Performance theory can be structured | Standardized storage interface and strategy | +30-80k | Middle level | Vault + Strategy |
| Vault (ERC-4626) | Standardized accounting | Share account, deposit/withdraw funds | +40-90k | Middle level | Vault contract |
| Oracle Adapter | Data outside the string on the string | Aggregator + age check | +100-200k | High | Oracle + adapter |
Gas demand: Ethereum Q3 2024 mainnet. L2 (Arbitrum/Optimism) decreases by 80-90%. Data may vary depending on the complexity of the deployment.
Decision-making format: which sample do I need?
- Do you need to integrate an external protocol with a non-standard interface? → Adapter
Form 1 - Adapter: Surrounding external protocols
Diagram - Adapter pattern: Your Contract → Adapter Wrapper → External Protocol (Uniswap/Aave/Curve)
When to use
Use Uniswap V3/V4, Aave V3, Curve, or any protocol with a non-standard or version-dependent interface. The adapter converts your internal interface into their external one.
Perform
`solidity // Your internal interface interface IUniswapV3Adapter { function swapExactInputSingle( address tokenIn, address tokenOut, uint24 fee, uint256 amountIn, uint160 sqrtPriceLimitX96 ) external returns (uint256 amountOut); }
// Immutable wrapper - no upgradeability, minimal trust
constructor(address _router) { router = ISwapRouter(_router); }
function swapExactInputSingle(...) external override returns (uint256) {
Gas Optimization Techniques
- Call by group via multicall: single transaction for multiple changes
Example: Yearn Adapter architecture
Yearn V3 uses adapters for Curve, Convex, Aave, Balancer, and Uniswap. Each adapter:
Risk Profile
| Risk | Minor reduction |
|---|---|
| Wrapper = the only point of failure | Settings are non-editable; no administrative password |
| Interaction between upgrade capabilities | Install a new adapter; switch to the timelock management method |
| Interface discrepancy | Automated testing for mainnet forks in each protocol upgrade |
Form 2 – Proxy (EIP-2535): Upgradeable Logic that can be structured
Diagram - Diamond proxy: Diamond (storage) → Facets (logic: Strategy, Risk, Oracle, Rewards) → Exter
When to use
The strategy logic must be developed: yield optimization algorithms, risk parameters, reward distribution, oracle sources. The diamond convention distinguishes each logical domain into separate facets, sharing the same memory.
Diamond Common vs Simple Proxy
| Aspect | Intelligent Proxy (OZ) | EIP-2535 Diamond |
|---|---|---|
| Logical contract | Single deployment tasks | Many aspects |
| Provide memory | Shared (risk of collision) | Provide diamond storage (with name) |
| Upgrade level | All or nothing | From the perspective of |
| Compatibility | There are limits | Native — facets = module |
Diamond Storage Model
// Each facet uses a unique storage namespace
// Facet reads/writes via assembly to specific slot
Deployments in the real world
- Euler V2: Diamond for computer-based risk assessment, oracles, liquidation, and rewards for facets
Risk Profile
| Risk | Minor reduction |
|---|---|
| Attack vectors in administration | Timelock + multisig; defer facet upgrade |
| Facet upgrade time | Atomic's multi-dimensional improvement through 'diamondCut' |
| Memory layout error | Test automatic memory allocation; named frames |
delegatecall reusability | 'nonReentrant' on all external facet functions |
Form 3 – Strategy & Vault (ERC-4626): Product that can be tokenized
Diagram - ERC-4626 Vault + Strategy: User → Vault (shares) → Strategy (allocation) → Underlying Prot
ERC-4626 is the Composability layer
The standards define: deposit, withdraw, mint, redeem, totalAssets, asset, decimals. This interface allows any vault to connect to any aggregator — Yearn, Beefy, 1inch, Paraswap all recognize ERC-4626 vaults.
Strategy Model: Separate concerns
Vault (ERC-4626) Strategy (Custom) ├── Share accounting ├── Allocation logic ├── Deposit/withdraw ├── Rebalance triggers ├── Fee collection ├── Risk checks └── Asset custody └── Protocol interactions
Multiple Strategy Vaults
A Allocator contract distributes vault assets across multiple strategies:
function rebalance() external { // 1. Withdraw from overallocated strategies // 2. Deposit into underallocated strategies // 3. Update allocation tracking // Gas: ~150-300k depending on strategy count }
Chemical gases
Each rebalance = call strategy + vault calculation. Number of units to amortize:
Form 4 - Oracle Adapter: Non-string data with minimum reliability
Diagram - Oracle Adapter: Price Feeds → Aggregator → Adapter (validation) → Consumer Contract
When to use
Any structure needs price, rate, or status from outside the EVM. Architecture: Aggregator (Chainlink/RedStone/Pyth) → Adapter (verifier) → User.
Adapter Tape tester
contract OracleAdapter { AggregatorV3Interface public immutable aggregator; uint256 public immutable heartbeat; // Max age (e.g., 3600s) uint256 public immutable deviationBps; // Max deviation (e.g., 100 bps) int256 public immutable minPrice; // Circuit breaker floor int256 public immutable maxPrice; // Circuit breaker ceiling
function getPrice() external view returns (int256) { (, int256 price, , uint256 updatedAt, ) = aggregator.latestRoundData();
// Staleness check
// Deviation check (requires previous price tracking)
return price;
Staleness Threshold: Heartbeat versus deviation
| Approach | Advantages | Disadvantages | Used by |
|---|---|---|---|
| Heartbeat-based | Simple, predictable | Slow to detect risk | Chainlink standard data sources |
| Guarantee based on deviation | Notice sudden movements | Request a price quote | RedStone, Pyth, custom adapters |
| Hybrid (both) | The best of both | There's more gas | Aave V3, Euler V2, Morpho Blue |
Examples in practice
- Aave V3 Price Oracle: Chainlink aggregator + backup selection check + error margin
Risk: Oracle Creates Condition = Liquidation Propagation Impact
A controlled source of supply in a position that is structured (e.g., a leveraged vault that uses an oracle to price the underlying asset) can result in:
Cross-sectional model of the protocols
These are the "menus" that developers actually build. Each menu combines multiple templates.
Diagram - Cross-protocol looping: deposit collateral → borrow stable → swap to collateral → redeposi
1. Leverage Yield
Model: Set collateral → Secure loan → Switch to collateral → Re-set collateral (recursive)
Mathematics:
- Leverage efficiency ratio = 1 / (1 - LTV)
Risk: Level liquidation. Each loop has a compound gas cost. Optimal: 3-5 loops (increasing thereafter).
2. Basis Trade (Spot + Perpetual)
Model: Long point (asset being tokenized) + Short point (individual raising capital)
Works with: stETH + ETH perpetual, T-bill tokenized + future interest rate, VNDC + VND/USD forward
Math: Annual capitalization rate = (Funding Rate × 8760) / Position size
3. Delta Neutral
Model: LP position (Uniswap V3 focused) + Hedge (short or options)
Eliminate directional exposure; charge + capital. Risk: Residual impermanent loss, gamma risk, complexity of dynamic hedging
4. Cross-Chain Arbitrage
Pattern: Bridge → Arb on destination chain → Bridge back (compute atomically via callback)
Requirements: fast settlement, low bridge fees, MEV protection
Positional risk matrix
Two-axis model: Smart Contract Risk (state TERM_2__, code age, TERM_3__) × Oracle/Market Risk (diversity, volatility, fraud history).
Comparison - Risk matrix for composed DeFi positions: smart contract risk × oracle risk × liquidity
| Quadrant | Risks of smart contracts | Oracle's risks | Examples | Allocation guide |
|---|---|---|---|---|
| Q1: Basic Objects | Low (audited, combat-tested, high TVL) | Low (multiple data sources, low variability) | Simple deposits from Aave, stable Uniswap V3, ERC-4626 vault (audited) | Centralized liquidity – 60-80% of the DeFi portfolio |
| Q2: Depending on Oracle | Low | Good (simple input, volatility, adjustment history) | Repeat with leverage, financial arbitrage, bridges between chains + profit | Close monitoring - 15-30%, price data alert |
| Q3: Risk of code | Good (un-audited, new, low TVL) | Low | Un-audited strategic keys, integration of new protocols, custom adapters | Audit Required - 5-15%, only after audit |
| Q4: Hazardous area | High | High | Max leverage on new protocol, cross-chain leveraged yield, synthetic + oracle | Expert Only - <10%, by location size for total damage |
Aggregate evaluation formula
Composite Score = (SC_Risk_Weight × SC_Score) + (Oracle_Risk_Weight × Oracle_Score) Weights: SC_Risk = 0.6, Oracle_Risk = 0.4 (code risk compounds faster) Thresholds: <30 = Q1, 30-50 = Q2, 50-70 = Q3, >70 = Q4
Diversification rule
There were never more than 10% of the portfolio in Q4. The positions created in Q4 had correlated failure modes – an oracle failure + a bug in the smart contract = total loss of capital.**
Vietnam context of the building tool – DeFi integrated in VN
Vietnamese builders face unique constraints and opportunities that affect their choice of integrated model.
VN DeFi Infrastructure Projects are Configurable
- Kyber Network: KyberSwap aggregator + flexible groups (model adapter for multi-DEX routing)
Regulation: Decree 13/2023 on Sandbox
The sandbox regulations on fintech allow for the testing of DeFi protocols in a controlled manner. The implications are as follows: - Protocols that may be combined must undergo more rigorous scrutiny (the interactions of multiple protocols = complex risk) - KYC/AML must be performed at the limits of the combination process (ramp-up/tear-down of fiat currency) - Reporting obligations for monitoring traffic between protocols
Oracle's local needs
- VND/USD feed: Important for VNDC, Vietnamese assets are tokenized, local lending market
Accessibility: Mobile-first, energy-optimized
- 90%+ use mobile → UX must hide the complexity of the structure
Biography of a Talent
- Strong foundation in EVM/Solidity (outsource history)
Decision Framework - Select your integration model
Flowchart - Decision framework: Upgrade need? → Proxy. External protocol? → Adapter. Yield product?
Checklist for selection
- Is there a need for an upgrade? → Proxy (EIP-2535 diamond for multi-facet; OZ Transparent for simplicity)
Change the gas cost model
| Network | Is a proxy feasible? | Adapter cost | Warehouse costs | Recommendation Statement |
|---|---|---|---|---|
| Ethereum Mainnet | Riyadh (~100k) | Low (~30k) | Average (~80k) | Avoid using proxies; use immutable adapters |
| Arbitrum/Optimism | Yes (~10k) | Very low (~3k) | Low (~8k) | Proxy diamond for logic can be upgraded |
| BSC/Polygon | Yes (~5k) | Very low (~1k) | Low (~5k) | Proxies can be used; optimized for UX |
| TomoChain | Yes (<$0.01) | Not significant | Not significant | Any model; developer's speed priority |
The capabilities of the group determine the maximum level of complexity
- No audit budget: only Adapter + Vault (non-configurable, default)
FAQ
1. What is the difference between the Adapter and Proxy models? An Adapter includes external calls (your interface → their interface); a Proxy allows for upgradable logic through shared memory of the facet. Adapter = translation layer; Proxy = development layer.
2. When should I use the ERC-4626 vault instead of a custom accounting? ERC-4626 provides composability – any aggregator recognizes it. Custom is only used when the standard doesn’t fit (e.g., non-swappable positions, complex fee structures).
3. What is the price of a flash loan arbitrage? ~300-500k on mainnet (2024); ~50-100k on Arbitrum/Optimism. Depends on the number of hops and the complexity of the DEX.
4. What is the biggest risk in DeFi positions? Smart contract risk compounds – a widespread issue across all integrated protocols. A bug in the Adapter + Oracle can lead to the loss of an entire position.
5. Can I create processes without writing Solidity? Yes — use Yearn/Beefy (ERC-4626 vaults) strategies, 1inch Fusion (aggregation of changes), or non-code tools like DeFi Saver (formula builder).
6. How do you audit a composed position? Audit each integration point + logic composition. Check: reentrancy (callback functions), access control (enhanced facets), oracle staleness (heartbeat/difference), enhanced security (storage collision).
7. What is the difference between Strategy and Vault in ERC-4626? Vault = accounting/tokenization (spending, sending, withdrawing); Strategy = allocation logic (where assets go, when to rebalance). They are separated for composability – one vault, multiple strategies.
8. How does EIP-2535 Diamond differ from OpenZeppelin Transparent Proxy? Diamond supports multiple memory-sharing logic contracts; Transparent Proxy = single deployment contract. Diamond allows for modular upgrades – upgrading the system without changing the logic of the oracle.
Refer and read more
Main sources
- EIP-2535: Diamond Standard — https://eips.ethereum.org/EIPS/eip-2535
Refer to implementation
- Yearn V3 Adapters - https://github.com/yearn/yearn-v3
Vietnam context
- Decree 13/2023 Sandbox - https://thuvienphapluat.vn/van-ban/The-thao/Decree-13-2023-ND-CP-sandbox-fintech
* Last updated: 2026-09-02 | Author: 4+ years of experience in DeFi protocol development, contributing to the integration of Yearn/Euler/Morpho
