Smart Contracts Composability

a-brief-introduction

Smart contracts are public on MAPO-Relay-Chain and can be thought of as open APIs. You don't need to write your own smart contract to become a dapp developer, you just need to know how to interact with them. For example, you can use the existing smart contracts of Uniswap, a decentralized exchange, to handle all the token swap logic in your app – you don't need to start from scratch. Check out some of their v2 and v3 contracts.

The following MAPO-Relay-Chain is collectively referred to as MAPO.

what-is-composability

Composability is combining distinct components to create new systems or outputs. In software development, composability means developers can reuse existing software components to build new applications. A good way to understand composability is to think of composable elements as Lego blocks. Each Lego can be combined with another, allowing you to build complex structures by combining different Legos.

Every smart contract is a Lego of sorts—you can use smart contracts from other projects as building blocks for your project. This means you don't have to spend time reinventing the wheel or building from scratch.

how-does-composability-work

smart contracts are like public APIs, so anyone can interact with the contract or integrate them into dapps for added functionality. Smart contract composability generally works off three principles: modularity, autonomy, and discoverability:

1. Modularity: This is the ability of individual components to perform a specific task. In Ethereum, every smart contract has a specific use case (as shown in the Uniswap example).

2. Autonomy: Composable components must be able to operate independently. Each smart contract is self-executing and can function without relying on other parts of the system.

3. Discoverability: Developers cannot call external contracts or integrate software libraries into applications if the former are not publicly available. By design, smart contracts are open-source; anyone can call a smart contract or fork a codebase.

benefits-of-composability

horter-development-cycle

Composability reduces the work that developers have to do when creating dapps. As Naval Ravikant puts it: "Open source means every problem has to be solved once."

If there is a smart contract that solves one problem, other developers can reuse it, so they don’t have to solve the same problem. This way, developers can take existing software libraries and add extra functionality to create new dapps.

greater-innovation

Composability encourages innovation and experimentation because developers are free to reuse, modify, duplicate, or integrate open-source code to create desired results. As a result, development teams spend less time on basic functionality and can allocate more time experimenting with new features.

better-user-experience

Interoperability between components of the MAPO ecosystem improves the user experience. Users can access greater functionality when dapps integrate external smart contracts than in a fragmented ecosystem where applications cannot communicate.

We'll use an example from arbitrage trading to illustrate the benefits of interoperability:

If a token is trading higher on exchange A than exchange B, you can take advantage of the price difference to make profit. However, you can only do that if you have enough capital to fund the transaction (i.e., buying the token from exchange B and selling it on exchange A).

In a scenario where you don't have enough funds to cover the trade, a flash loan might be ideal. Flash loans are highly technical, but the basic idea is that you can borrow assets (without collateral) and return same within one transaction.

Going back to our initial example, an arbitrage trader can take out a large flash loan, buy tokens from exchange B, sell them on exchange A, pay back the capital + interest, and keep the profit, within the same transaction. This complex logic requires combining calls to multiple contracts, which wouldn't be possible if smart contracts lacked interoperability.

further-reading

Last updated