Architecture Overview
Composer transforms a user’s intent (e.g., “deposit USDC into Morpho on Base”) into an optimised, executable onchain transaction. The system has three layers:
Core Components
1. Onchain VM (Execution Engine)
The Onchain VM is a smart contract deployed on supported EVM chains. It acts as a general-purpose execution engine that can:- Call any other onchain protocol or series of protocols
- Pass outputs from one step as inputs to the next
- Handle token approvals, transfers, and balance checks between steps
- Execute the entire sequence atomically (same-chain)
0xD214A2eB3799076791A4Cde4F0AB184A49dB832d
2. eDSL and Compiler
The embedded Domain-Specific Language (eDSL) is a purpose-built language for expressing contract interactions in TypeScript. When a Composer route is requested:- The routing engine identifies which protocols and actions are needed
- The eDSL expresses these interactions as a typed program
- The compiler transforms this program into bytecode the Onchain VM can execute
3. Dynamic Calldata Injection
Many DeFi operations require data from a previous step. For example, depositing into a vault requires knowing the exact token amount received from a preceding swap. Composer handles this through dynamic calldata injection:- The compiler identifies dependencies between steps
- At execution time, the VM automatically intercepts outputs from completed steps
- These outputs are injected as inputs into subsequent steps
- This happens entirely onchain, within the same transaction
Transaction Lifecycle
Here is the full lifecycle of a Composer transaction, from user request to onchain execution:
Step-by-Step Breakdown
| Step | What Happens | Where |
|---|---|---|
| 1. Quote request | Developer requests a quote with a vault token as toToken | Client → API |
| 2. Route optimisation | LI.FI’s routing engine finds the optimal path across DEXs, bridges, and protocols | API backend |
| 3. eDSL compilation | The Composer compiler generates bytecode for the Onchain VM | API backend |
| 4. Pre-execution simulation | The full execution path is simulated to verify it will succeed and estimate outputs | API backend |
| 5. Quote response | API returns transactionRequest (ready-to-sign tx) plus estimated amounts | API → Client |
| 6. Transaction submission | User signs and submits the transaction to the blockchain | Client → Chain |
| 7. Onchain execution | The Onchain VM executes the compiled bytecode, performing all steps atomically | Onchain |
| 8. Confirmation | Transaction is confirmed; vault tokens are in the user’s wallet | Chain → Client |
| 9. Status check | Optionally poll /status for cross-chain transfers | Client → API |
Same-Chain vs. Cross-Chain
Composer behaves differently depending on whether the source and destination are on the same chain.Same-Chain Composition

- Atomic execution — all steps succeed or none do
- Single gas payment — one transaction fee
- Instant completion — confirmed in one block
- Simulation guarantee — if simulation passes, execution will succeed (barring extreme edge cases like mempool front-running)
Cross-Chain Composition

- Two-phase execution — source chain transaction triggers a bridge, then destination chain actions execute
- Per-phase atomicity — each phase is atomic within its chain, but the overall flow is eventually consistent
- Bridge latency — total time depends on the bridge used (seconds to minutes)
- Status tracking required — use
/statusendpoint to monitor cross-chain progress
Composer itself operates on a single chain. Cross-chain flows are achieved by combining LI.FI’s bridge routing with Composer’s onchain execution on the destination chain. This is seamless from the developer’s perspective — you make the same API call regardless of whether it’s same-chain or cross-chain.
Pre-Execution Simulation
One of Composer’s key safety features is pre-execution simulation. Before returning a quote, the backend:- Simulates the full execution path using a fork of the current chain state
- Verifies all steps succeed — token swaps, approvals, deposits
- Calculates exact output amounts — the estimated vault tokens the user will receive
- Detects potential failures — insufficient liquidity, incompatible tokens, protocol-specific issues
Composer as a LI.FI Tool
In the LI.FI architecture, Composer is classified as a tool — similar to how bridges and DEX aggregators are tools. This means:- Composer routes appear alongside bridge and swap routes in API responses
- The routing engine automatically selects Composer when it’s the optimal path
- As with any LI.FI tool, integrators can use
allowTools/denyToolsto include or exclude Composer from their routing preferences

