All articles

What is composability in DeFi?

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

1/10/2023by Mrig P

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?

In software development, composability refers to the ability to freely combine existing applications or their specific codes or components to build new products.

In DeFi, composability offers developers 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 on top of existing apps.

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 maximum 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 patent infringement 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 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 ones 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 code 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 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 the best example of a DeFi protocol requiring atomic composability.

How does composability work in the traditional world?

Surprisingly, 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 with a better user interface or data. 

In fact, the more data sets a mash-up had, the more problems it could solve, as long as there was a demand for 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 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 the companies in control of all operations and reduced the number of alternate applications for users. 

Take Facebook or Google ads, for instance. Advertisers have no choice but to use the company’s data management platform to get user data for targeting, and the company controls the ads’ transmission. 

Does this mean composability is non-existent in web2?

Composability still exists in many forms in web2. When you use PayPal to pay for your Uber ride or your Facebook ID to log in to 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 are most likely to use the interaction as an opportunity to collect data on you and profit from it through its ad platforms. 

In short, web2 composability, although very negligible, largely favors a handful of companies and helps them create monopolies. 

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, there’s a good chance that DeFi’s money legos will evolve and expand across industries to create such applications in the real world. 

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 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.

The best money legos in DeFi 

The DeFi ecosystem has a vast array of components, and anyone can interact with them in different combinations. Thus, companies achieve more capital efficiency than they would by being part of a traditional financial system. 

Here are examples of some of the best money legos in the decentralized finance space that developers can use:

MakerDAO

An image of the MakerDAO logo.

MakerDAO is the Ethereum-based DeFi protocol that mints DAI — the decentralized stablecoin soft-pegged to the U.S. dollar. It lets anyone create a vault and get DAI as a debt against crypto asset collateral like ETH, USDC, BAT, etc. DAI is highly composable and works with more than 400 services and apps, including popular ones like Uniswap and Curve.

Compound

An image of the Compound logo.

Compound is a decentralized and permissionless lending and borrowing protocol where anyone can lend and borrow cryptocurrencies. It integrates with exchanges, portfolio managers, and wallets to enable its users to earn interest, secure their funds, and track their earnings easily. 

Curve

An image of the Curve logo.

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 wBTC and tBTC. It integrates with protocols like yearn.finance and Synthetix to maximize incentives for liquidity providers. 

Aave

An image of the Aave logo.

Aave is a decentralized lending platform primarily based on the Ethereum blockchain. It integrates with several DeFi platforms like exchanges, but the best example of Aave’s use of composability is its ability to give users flash loans. 

Synthetix

An image of the Synthetix logo.

Synthetix is a derivatives liquidity protocol that creates synths (synthetic assets) of cryptocurrencies and real-world assets by staking its native token $SNX as collateral. As synths have zero slippage, traders use them to swap large quantities of $ETH or $BTC via Curve and route the trades via 1inch, thereby making use of the composable nature of DeFi. 

RenVM

An image of the RenVM logo.

RenVM is a decentralized protocol that converts non-native Ethereum assets like Bitcoin into Ethereum-based ERC-20 tokens. It has a high level of composability and can integrate with many blockchains to exchange assets with them. 

Sushi

An image of the Sushi logo.

Sushi is a Uniswap clone that allows you to swap, earn, lend, and borrow ERC-20 tokens. It can easily integrate with exchanges and lending platforms across multiple chains.

Yearn

An image of the Yearn.finance logo.

Yearn is a yield aggregator protocol that automatically deposits tokens across different DeFi platforms like Curve, MakerDAO, etc. so their users can earn maximum yield from lending, trading, and liquidity incentives. 

Up-and-coming DeFi money legos 

Alchemix

Eth symbol

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. Once you start earning yield, Alchemix will use it to start repaying the principal and interest of the loan. 

HydraDX

An image of the HydraDX logo.

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

Risks associated with DeFi composability

DeFi’s composability is often seen as a double-edged sword as it can create endless combinations with its money legos and 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.

Take the yearn.finance’s DAI vault attack, for instance. The protocol suffered an exploit on one of its DAI lending pools, causing a dent 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 a bunch of DAI into Curve’s 3Pool which had 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’s DAI vault. 

Despite some potential risks, composability in DeFi gives developers the edge that traditional finance systems do not have. It opens doors for developers to create a myriad of dApps with various use cases and improve their interoperability.

As a result, despite the risks of composability, the entire ecosystem benefits from derivative gains, and more end-users benefit from a seamless DeFi experience. 

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.