Money Legos And Composability
As DeFi Building Blocks
The DeFi (Decentralized Finance) space would not be complete without a discussion on money legos. These are the building blocks for programmable money, performed by smart contracts and executed on a blockchain. The proliferation of decentralized applications is due to the infrastructure provided by the Ethereum blockchain network. It is one large decentralized network of nodes that has a world state, that checks the consistency and finality of a transaction.
Connecting these components together is the main concept of composability. In a way, it is a “middleware” that binds various protocols through an interoperability layer. In DeFi, these protocols are responsible for transferring value, swapping tokens, fetching external feeds, and providing liquidity. These consist of components that interoperate to provide solutions as financial instruments for users. Popular examples of these protocols include Curve, Yearn, Bancor, and Compound. These protocols, unlike banks and other financial institutions, are also permissionless and trustless entities. They just provide an infrastructure for users, and they cannot censor or block users from using their protocol.
Ethereum As A Platform
DeFi’s base layer is the Ethereum blockchain network. Ethereum provides an operating system layer that supports DApps (Decentralized Applications) are used in DeFi. It began early on with decentralized exchanges (DEX), and now it also provides a platform for AMM (Automated Market Makers). Ethereum, for the most part, is the blockchain where transaction data is immutably stored as proof or verification.
Use of the Ethereum blockchain as a platform for DApps requires the use of Ethereum’s native token Ether (ETH). A smaller denomination of Ether called Gwei (0.000000001 ETH) is used to pay for units of computation on the network called gas. The gas costs are part of the fees paid in order to process transactions that are validated by nodes called miners (or stakers in ETH2). Most DeFi tokens run on top of the Ethereum network because they were issued as ERC20 tokens. These are standards that allow tokens to be created as digital assets on the Ethereum blockchain.
The most important component of the architecture is the use of smart contracts. These contain the code that make up the logic functions used in DApps. A smart contract performs conditional tasks that are executed by the EVM (Ethereum Virtual Machine) across the nodes in the network as part of the consensus mechanism that processes transactions to the blockchain. Without smart contracts there would be no other way to program conditions into logic, so the network would be similar to the Bitcoin blockchain in terms of accounting. With Ethereum, the accounting system is based on state, which checks the current and most recent updates while saving all changes which can be tracked by a block explorer.
In the end, the Ethereum blockchain provides the settlement layer for all transactions. While some protocols take the computation to a separate layer, they will return the result to the main network that stores the data on the blockchain. Certain protocols may use sidechains, but other protocols remain on-chain without the complexity of another layer. Having Ethereum is also less of a hassle than building another database or blockchain from scratch, since it is already available.
Developers can create DApps that are smart contract-based. The purpose of money legos is to be able to allow various ERC20 tokens to be swapped by nodes in a direct peer-to-peer (P2P) manner. While a DEX still provides most exchanges for users, they can also use their wallets to make direct payments. What money legos provide are solutions to more complex transactions which require more steps than the usual.
In DeFi, there are various protocols. A simple P2P transaction can be considered as one transaction using a single protocol (e.g., Transferring DAI tokens from one wallet address to another). What if you wanted to execute logic that requires borrowing and paying for a loan (i.e., flash loan) in a single smart contract? This is where money legos come into play. In this example, let us say you borrowed the money by depositing a collateral for DAI tokens. You then put that DAI to a leveraged position to earn yields and then withdraw it. With the funds, you repay the loan and interest to take your collateral out and keep the yields returned from a leverage position. All that can be done using a single smart contract.
What the smart contract did was play money legos. It connected various DeFi protocols to interoperate to process the flash loan. Some flash loans can be conducted in a single transaction to save users on costs. These are like putting the pieces together to solve a puzzle, only in this case it is putting the components together to provide a solution.
Let’s take a traditional financial example like refinancing debts, and apply DeFi to it using money legos. Our aim here is to develop a composable solution for refinancing debt or loans. Assuming that a user just wants to refinance their debt at the best rate offered in the DeFi market.
The debt was taken from a Compound protocol at a 9.5% interest rate as an example. Now let’s say there is another protocol that offers debt at 7% interest. The smart contract contains logic that can explore these rates and refinance your debt at 7%.
This can be accomplished using these money lego components:
- Take out a flash loan using the Aave protocol
- Pay the debt on the Compound protocol
- Borrow from the 7% debt offer
- Payback the flash loan on the Aave protocol
This is just one type of scenario. A user can even involve other protocols like UniSwap to contribute to a liquidity pool or exchange for DAI and deposit to an interest-bearing account. There are many possibilities, so there is no one way of doing things. There will also be some combinations being more cost-effective than others. It all depends on which money legos were used.
One other example is building a solution to hedge against market volatility. This is through the use of stablecoins. Protocols like DAI and USDC, store value that is pegged to fiat in order to preserve the tokens value after a transaction. Supposed that a payment had to be made that was ETH valued at $1,000. If the ETH changed value during the trade, it could suddenly increase > $1,000 if the price of ETH goes up or decrease < $1,000 if the price of ETH goes down. To solve this, the smart contract could be programmed to use a protocol to first convert the ETH to the stablecoin DAI and preserve its value of $1,000. Then the payment can be made to the other user.
Synopsis And Takeaways
There is always an element of managing risk when it comes to financial instruments. Whether it is traditional finance or DeFi, there are certain things that can affect the market. Very common problems are slippage and divergence (i.e. impermanent loss). The volatility in the markets is also something to watch out for. That is why stablecoins are very much needed as protocols for helping to preserve value from yields or returns.
Certain algorithms have also improved upon swaps and exchanges. This helps to minimize divergence in protocols like Bancor. The use of another component that helps money legos, called oracles, can help. Oracles provide smart contracts with external feeds to get up to the minute data on prices. A more algorithmic type of interaction among the protocols not only automates the process but makes it more efficient. It not only helps users get the best trades and swaps but the best yields when it comes to earning from DeFi protocols. That is the whole concept behind the idea of composability. Good interoperability among components helps to build the best solutions.
First published in The Capital (2/16/21)