0 minsPublished on 1/9/2024

What is composability in DeFi? A guide to DeFi composability

Composability is the backbone of decentralized finance (DeFi). But what is it and why is it so beneficial to the growth of the DeFi ecosystem?

By Mrig P

What is composability in DeFi

Decentralized finance (DeFi) aims to create a financial ecosystem in which anyone can participate without the need for a central custodian. 

The cherry on top for users and developers is that the DeFi ecosystem is open and permissionless, ensuring maximum “composability” of DeFi protocols and smart contracts.

But what does that term mean, “composability”?

This article explains the concept of composability, how DeFi composability works, and its benefits and risks.

What is composability?

Composability in software development refers to the ability to freely combine existing applications or their specific codes or components to build new products.

In DeFi, composability refers to the potential to use codes, smart contracts, application programming interfaces (APIs), and software development kits (SDKs) of existing decentralized applications in endless combinations to create new applications or build new services.

A more straightforward way to understand composability is to think of DeFi protocols as Lego blocks that you can combine to build interesting structures. That means each software component has the ability to connect to every other software component like a block so the output of one application can be the input of another.

We can see the potential of composability in decentralized finance due to the open-source nature of most DeFi protocols. Developers can reuse various applications without reinventing the wheel or fearing intellectual property issues.

Types of composability 

Composability exists in three forms: morphological, syntactic, and atomic

Morphological composability 

Morphological composability means the various components, codes, tokens, and functions (the Lego blocks) comprising DeFi applications (dApps) and platforms follow the same overall standards so that they are compatible and interoperable with each other. 

Not having morphological composability would be like Lego creating Lego blocks that do not fit perfectly with each other. While each individual block may serve a certain purpose, no one could actually use multiple blocks to build something unique. 

Achieving morphological composability can be challenging since there needs to be an industry-wide agreement on these standards. This is why the Ethereum ecosystem (like other blockchains) follows Ethereum Request for Comment (ERC) standards for tokens and smart contracts. Developers on the chain can propose new standards, open them for community discussion, and agree to implement them through voting.

Syntactic composability 

Syntactic composability refers to the ability of dApps and decentralized autonomous organizations (DAOs) to effectively integrate with each other to form entirely new systems. This is best achieved in an ecosystem that has effective morphological composability built into it.

A chart listing the types of composability in DeFi.

Ethereum achieves syntactic composability very well — any smart contract on Ethereum can call any other contract in the entire ecosystem. This allows developers to reuse code from existing decentralized applications and create new dApps without spending too much time coding.

For instance, the decentralized exchange Uniswap already developed an effective token swap. Now, if a developer is creating a cryptocurrency wallet, they can integrate Uniswap’s token swap mechanism or smart contract code into their wallet without having to create it from scratch.

Atomic composability 

To understand atomic composability, you must first understand atomicity. 

Atomicity in blockchain means combining multiple actions into one transaction that executes only if every action is legitimate. You can leverage this property to split a transaction across multiple crypto exchanges or vote on several DAO proposals without the risk of a partial failure. 

Atomic composability is the combination of atomicity and composability — a single transaction involves calls to multiple smart contracts and the transaction goes through only if all of its parts succeed. A flash loan is a good example of a DeFi protocol using atomic composability.

How does composability work in the traditional world?

Composability was a huge part of early Web2. It existed in the form of business models called mash-ups that involved bundling existing products to create new ones based on consumer trends. 

Housing Maps was one of the earliest examples of a mash-up. It combined the data from Google Maps and Craigslist’s real estate listings to display apartment and housing listings on a map. 

Like other mash-up services that operated during its time, Housing Maps didn’t control or own the data it used and would compete with other mash-ups. 

In fact, the more data sets a mash-up had, the more problems it could solve, but its usefulness would depend on whether there was a demand for solving these problems. The most popular mash-ups leveraged this principle to build successful companies. 

But by 2010, many centralized platforms started asserting their dominance on the web and shut down access to their APIs, which caused the mash-up business model to fade out. 

Gradually, Meta (previously Facebook), Amazon, Apple, Google, and other tech leaders replaced open-source applications (and composability) with a closed ecosystem of their own applications.

The result was walled gardens that left certain companies in control of all operations and reduced the number of alternate applications for users. 

Take Meta or Google ads, for instance. Advertisers have no choice but to use these companies’ data management platforms to get user data for targeting and the companies control their ads’ transmission. 

Does this mean composability is now non-existent in Web2?

Composability still exists in many forms in Web2. When you use PayPal to pay for your Uber ride or your Meta ID to log in to play a game, you’re leveraging the composability of each application. 

While this type of composability is beneficial, it comes with a caveat: you have to trust centralized third parties who might use the interaction as an opportunity to collect data on you and seek to profit from it.

How does composability work in DeFi?

Composability in Web3 could look something like this: 

A Web3 app consolidates the miles logged on your Peloton and the data from other workouts from different classes to form your on-chain digital fitness identity. 

It then connects to other Web3 applications offering personalized training programs to set up a fitness regimen or modify your existing one based on the progress you’ve made.

Although this may sound futuristic, it is possible that this type of composability could affect DeFi’s various components (the “DeFi Money Legos”) and cause them to evolve and expand across industries to create useful real world applications. 

But for now, let’s look at a practical example of how composability works in DeFi by understanding flash loans. 

Flash loans are uncollateralized loans that enable users to borrow and return funds in the same transaction. They’re commonly used to try to create an instant profit via arbitrage opportunities.

A picture that shows how flash loans work.
How flash loans work

To get started with a flash loan, you first create a set of pre-designated operations on flash loan providers like Aave. Then, you run the transaction to execute the operations and repay the loan. 

To understand this, we’ll break down this transaction from January 2020 made by the Arbitrage DAO. They take a flash loan of 3137 DAI from Aave, swap it for SAI on MakerDAO, and swap it back to DAI using Uniswap. Once these operations are complete, they repay the flash loan and are left with a profit of 3 DAI. 

Here, the DAO uses three platforms in a single transaction to make a small profit, and these profits can be easily scaled by increasing the size of the transactions.

Examples of highly composable components in DeFi 

The DeFi ecosystem has a vast array of components, and anyone can interact with them in different combinations. 

Here are examples of some highly composable components in the decentralized finance (DeFi) space that developers can use:

MakerDAO

MakerDAO is the Ethereum-based DeFi protocol that mints DAI — the decentralized stablecoin that attempts to maintain a stable value by being soft-pegged to the US dollar.

An image of the MakerDAO logo.

DAI is highly composable and works with more than 400 services and apps, including popular ones like Uniswap and Curve.

Compound

Compound (COMP) is a decentralized and permissionless lending and borrowing protocol where anyone can lend and borrow cryptocurrencies.

An image of the Compound logo.

Compound integrates with exchanges, portfolio managers, and wallets to enable its users to earn interest, secure their funds, and track their earnings and losses easily. 

Curve

Curve is an automated market maker (AMM) that only accommodates liquidity pools made of similarly behaving assets like stablecoins or wrapped versions of the same assets such as wrapped Bitcoin (WBTC) and wrapped Ether (wETH).

An image of the Curve logo.

Curve integrates with protocols like yearn.finance and Synthetix to try to maximize incentives for liquidity providers

Aave

Aave (AAVE) is a decentralized lending platform primarily based on the Ethereum blockchain, though it also offers markets for Avalanche, Polygon, Optimism, Arbitrum, and more. 

An image of the Aave logo.

Aave can integrate with several types of DeFi platforms, like decentralized exchanges. A good example of Aave’s use of composability is its ability to give users flash loans.

Sushi

Sushi is a Uniswap clone that allows you to swap, earn, lend, and borrow ERC-20 tokens.

An image of the Sushi logo.

Sushi can easily integrate with exchanges and lending platforms across multiple chains.

Yearn

Yearn is a yield aggregator protocol that automatically deposits tokens across different DeFi platforms like Curve, MakerDAO, etc.

An image of the Yearn.finance logo.

Yearn uses a broad range of platforms so their users can attempt to earn maximum yield from lending, trading, and liquidity incentives. 

Additional DeFi components 

Alchemix

Alchemix is a DeFi platform that auto-repays your loans. It places money into yearn.finance and allows you to take out a loan against the capital you provided.

Alchemix logo

Once you start earning yield, Alchemix will use it to start repaying the principal and interest of the loan.

HydraDX

HydraDX is a cross-chain token swap solution that enables users to transfer tokens between the Ethereum and Polkadot ecosystems.

An image of the HydraDX logo.

HydraDX allows users to trade many assets in a single pool, establishing a comprehensive ecosystem for things like liquidity and yield farming.

Risks associated with DeFi composability

DeFi’s composability is often seen as a double-edged sword as it can create endless combinations with its various components but also open the door to more risks

For starters, while composability facilitates sophisticated transactions, it also increases the number of interactions with external, untrusted code. This is potentially dangerous as the exploitation of a vulnerability within a single smart contract can have a devastating impact on multiple DeFi protocols in the space and your cryptocurrencies.

Take the 2021 yearn.finance’s DAI vault attack, for instance. The protocol suffered an exploit on one of its DAI lending pools, causing a loss of $11.1 million. 

According to an Ethereum address that was presumed to be associated with the exploit, an Aave flash loan triggered the attack. The attacker’s strategy was to deposit DAI into Curve’s 3Pool which held DAI, USDC, and USDT, to manipulate DAI’s price, as the 3Pool was responsible for calculating the value of the stablecoins

After cashing out the funds, the attacker withdrew the contract and repeated the same process a few times to drain the funds from the vault.

In short, the attacker exploited a vulnerability on Curve to drain funds from yearn.finance’s DAI vault.

Begin your DeFi journey with MoonPay

DeFi can help you earn interest and grow your crypto portfolio. To get started, simply buy cryptocurrency via MoonPay using your credit card or any other preferred payment method.

MoonPay's widget offers a fast and easy way to buy Bitcoin, Ethereum, and more than 50 other cryptocurrencies.

MoonPay also makes it easy to sell crypto when you decide it's time to cash out, including several tokens mentioned in this article like ETH, USDT, and USDC. Simply enter the amount of the token you'd like to sell and enter the details where you want to receive your funds.

Mrig P
Written byMrig P

You might also like