Smart Contracts and DeFi

From Fintech Lab Wiki


Summarised by Alireza Aghaee.


Introduction

This is a summary of “Smart Contracts and Decentralized Finance”, a working paper by Kose John, Leonid Kogan, and Fahad Saleh that can be found with this link in SSRN (John, Kogan, and Saleh 2022). This paper describes smart contract mechanics. They highlight smart contracts’ benefits, such as overcoming commitment issues and explore constraints like their inability to access information beyond the blockchain and the difficulties of combining smart contract code with traditional legal enforcement. The paper also shows how blockchain application implementation costs are higher without a trustworthy intermediary. They finish with a study of the most prominent smart contract applications in Decentralized Finance: token issuance, decentralized exchanges, and protocols for loanable funds.

Smart contracts

A smart contract is computer code comprising state variables and functions uploaded to a blockchain. The state variables represent the state of the contract and the functions are used to transition from one state to another. Users interact with smart contracts by creating transactions identifying themselves as senders, the smart contract as the receiver, and the function they wish to execute. Validators, who execute all blockchain transactions, are not obligated to execute any particular transaction, but users can incentivize them with a fee. Once a transaction is executed and recorded on a block of the blockchain, the blockchain state updates to reflect the state transition. Token smart contracts enable payments on a blockchain, as they have a state variable that stores the token holdings of each user, and token transfers are implemented as functions within the contract.

Smart contracts can affect not only their own state but also the states of other smart contracts because a function in a smart contract may initiate the execution of a function within another smart contract. However, smart contracts cannot directly initiate transactions with other smart contracts as they lack agency. This ability to interact with other smart contracts enhances economic exchanges feasible on a blockchain, allowing for contingent payments if a token smart contract interacts with another smart contract that identifies whether particular contingent events have occurred. The difficulties associated with executing contingent payments on a blockchain are discussed later on in the paper.

Benefits and Limitations

A function within a smart contract can be declared as public, which implies that any user may initiate an execution of that function at any time. Once a smart contract is deployed, the entity deploying the smart contract cannot preclude a transition in the blockchain state implied by any function that she declared as public.

The paper brings an economic transaction example to illustrate how a smart contract could enable contingent payments. A user can commit a payment to another user based on a particular contingent event via a smart contract. The smart contract would include a public function examining the relevant contingency condition and then transferring funds to the other user only if the contingency condition is realized. If the contingency condition is realized, the other user could retrieve their payment from the smart contract by creating a transaction that identifies the smart contract as the recipient of the transaction and also identifies the aforementioned public function as the function that the user wishes to have executed. The execution of this transaction would lead to an inspection of whether the contingency condition is true, and if so, then the transfer of funds to the other user would be implemented as a transition in the state of the blockchain. This contractual structure enables the user to overcome their inability to commit credibly to paying the other user.

A smart contract can also serve as a mechanism to overcome the problem of asymmetric information for new entrant firms in a market. By offering a contingent contract executed through a smart contract, the high-quality entrant can signal their type to potential partners or investors, thereby overcoming the lemons problem. This is because the smart contract can be designed to automatically verify that the entrant has successfully delivered their product or service before payment is released, which provides a credible signal of their quality.

The paper then continues by listing the limitations of smart contracts. In particular, they discuss three sorts of limitations that are limitations regarding conditioning events, limitations regarding outcomes, and economic limitations.

Smart contracts are only allowed to use data already part of the blockchain’s state, which ensures an inductive property that validators will continue to agree on the blockchain’s state after processing the same additional transaction. This consensus is crucial for the blockchain’s functionality. The data restriction is necessary to ensure this property. As for the limitations regarding conditioning events, the paper then explains why using an external data source could preclude the necessary inductive property. External data sources can alter the data they store, and two validators querying the same data from the external source may receive different data in response. If different data is received by two validators processing the same transaction, they will disagree on the blockchain state even if they agreed beforehand. This would break the necessary inductive property and compromise the consensus that underlies the blockchain.

The problem that induces the referenced data restriction is called the Oracle Problem. The oracle problem refers to the challenge of obtaining reliable and trustworthy external data for a smart contract on a blockchain. Since a smart contract is limited to invoking data already part of the blockchain’s state, it cannot access external data sources directly. Instead, it must rely on a third-party service or entity, called an oracle, to provide the external data. The oracle problem arises because the oracle may be compromised or provide inaccurate data, which can lead to incorrect or malicious outcomes in the smart contract. Solving the oracle problem is critical for encouraging smart contracts in real-world applications that require reliable and up-to-date external data.

The limitations in achieving outcomes are discussed next in this text, specifically concerning transfers of physical assets and transfers of stable value. It is highlighted that smart contracts alone cannot enforce ownership of physical assets, and they must be integrated with traditional legal structures to ensure recognition of ownership by law enforcement. As a result, smart contracts are not perfect substitutes for traditional legal agreements.

The transfer of stable value on a blockchain is limited by the expediency of ensuring price stability. There is interest in developing a stablecoin that could serve as a stable medium of exchange on a blockchain, but it remains unclear whether there is a theoretical methodology for ensuring such price stability. Some existing stablecoins, such as USDT, claim to maintain par value relative to USD, but the asset holdings supporting them cannot be directly verified from the blockchain. According to a formal examination, even over-collateralization does not ensure price stability. Despite this, stablecoins such as USDT, USDC, and BUSD have maintained large trading volumes and relative stability.

Lastly, the paper discusses the economic limitations associated with implementing economic exchanges through smart contracts. Two such costs are the cost of collateral and the cost arising from redundant behavior across blockchain validators. Collateral is generally required to implement contingent payments between two parties through smart contracts since the funds for the contingent payment must be out of the control of both the sender and the receiver until the contingent event has either occurred or failed. This collateral is held by the smart contract to resolve the commitment problem, which means that the sender forgoes the opportunity to invest the collateral and incurs an associated economic cost. Collateral is also needed to implement purchase agreements, where the buyer pays the seller only upon successful delivery. Both the buyer and the seller face an opportunity cost associated with posting collateral.

Redundant validator behavior is another cost of implementing economic exchanges through smart contracts. Blockchain entails redundant computation because each validator should execute each transaction separately, ensuring that each validator can separately verify that all transactions are executed correctly. The data storage costs for a blockchain are also borne separately by each validator, implying that the overall storage cost for a blockchain is several multiples of the storage cost for a centralized system where the storage cost is borne only once. The excess cost that arises for a blockchain due to redundancy constitutes an economic limitation because it implies that economic exchanges that are technically feasible might not be implemented for economic reasons. This economic limitation has practical implications in restricting the economic applications on blockchains.

Existing Applications

The paper discussed three cases that are the most popular uses of smart contracts: Token Issuance, Decentralized Exchanges, and Protocols for Loanable Funds.

Token Issuance

The smart contract acts as the central authority for issuing and transferring tokens on the blockchain. It contains a state variable that maintains a record of the token balances for each user and various functions that allow modifications to this state variable with the token balances. For instance, a transfer function could be called to transfer tokens from one user to another by reducing the balance of the sender’s account and increasing the balance of the recipient’s account. Ultimately, any change to the state variable corresponds directly to the final settlement of the transfer of units of the token. A fungible token is a type of digital asset on a blockchain that is interchangeable with any other unit of the same token. This means that each token unit has the same value and is indistinguishable from any other unit of the same token. Examples of fungible tokens include cryptocurrencies such as Bitcoin and Ethereum and stablecoins like Tether and USD Coin. On the other hand, a non-fungible token (NFT) is a digital asset on a blockchain that represents a unique item or asset and is not interchangeable with any other unit of the same token. NFTs are often used to represent digital art, collectibles, and other unique items. Each NFT is distinct and unique, often determined by the rarity or uniqueness of the item it represents.

Decentralized Exchange

A decentralized exchange (DEX) consists of smart contracts that enable trading fungible tokens on the same blockchains. Liquidity pools are smart contracts within the DEX that own two types of tokens and allow users to purchase one type of token by paying units of the other type, where the exchange rate is determined by an Automated Market Maker (AMM) function. The AMM function satisfies an equation requiring evaluating the same value before and after a trade, ensuring fair exchange.

A liquidity pool at a DEX generates token supply in equilibrium, which arises from investors transferring ownership of their tokens to the pool in exchange for an ownership share. The ownership share is proportional to the tokens transferred relative to the total tokens in the pool after the transfer and allows the investor to withdraw tokens from the pool. (Capponi and Jia 2021) found that sufficient volatility in the exchange rate between tokens in a liquidity pool can lead to a liquidity freeze, where the equilibrium pool quantity is zero. Therefore, token pairs with high exchange rate volatility are unsuitable for trading through liquidity pools.

The result that high volatility in the exchange rate between two tokens in a liquidity pool leads to a liquidity freeze can be intuitively explained by arbitrage opportunities. When there is a shock to the exchange rate, an arbitrageur can exploit this by trading with the liquidity pool in a way that generates a profit for themselves but a loss for the pool. This expected loss is accounted for ex-ante, meaning investors will not acquire an ownership share of the liquidity pool when the expected arbitrage profit is high enough. As volatility increases, so do expected arbitrage profits, leading to zero token supply of the liquidity pool.

Investors are incentivized to invest in liquidity pools despite the risk of arbitrage trading due to the proportional trading fees charged by the pools, which can increase the overall value of the pool and the value of each investor’s ownership share. (Hasbrouck, Rivera, and Saleh 2022) show that increasing the trading fee level can increase overall investment in the liquidity pool, reduce trading price impact, and increase trading volume.

The sustainability of DEXs as alternatives to CEXs that are centralized exchanges such as Binance remains an open question. (Barbon and Ranaldo 2021) find that while CEX transaction costs are generally lower than DEX transaction costs, the most significant component of DEX trading costs arises due to fees paid to blockchain validators. However, these fees endogenously decline as the blockchain’s throughput increases. Various solutions have been developed to improve blockchain throughput, suggesting that DEXs might become more competitive with CEXs.

Protocols for Loanable Funds

A Protocol for Loanable Funds (PLF) consists of a set of smart contracts that define a loan system where funds hold a single type of cryptocurrency. Investors can invest in a particular fund by selling their units of the associated cryptocurrency to the fund in exchange for a pro-rata equity share. Each fund creates a fungible token representing a pro-rata share of its cryptocurrency, which investors receive in exchange for selling their cryptocurrency to the fund. The cryptocurrency in the fund is then available for borrowing by any borrower at a given interest rate, denominated in terms of the fund’s cryptocurrency. Interest payments must be made in units of the fund’s cryptocurrency, increasing the number of cryptocurrencies held by the fund and, therefore, the value of each investor’s equity stake.

For example, Compound PLF is PLF with multiple cryptoassets, such as DAI, and USDC. The mechanics for investing in and borrowing from these funds are similar to ETH funds. When borrowing from a Compound fund, borrowers must post collateral above the amount they wish to borrow. The amount of collateral required depends on the collateral factor assigned to the particular cryptoasset being used as collateral. For example, if the collateral factor for ETH is 75%, then a borrower would need to post times the amount they wish to borrow in ETH as collateral. If the value of the collateral falls below a certain threshold, called the liquidation threshold, then the borrower’s position may be liquidated to ensure that lenders are protected. When a position is liquidated, the collateral is sold off and used to repay the loan, along with any outstanding interest owed. If the value of the collateral is not enough to repay the loan and interest, then the borrower may be subject to additional fees and penalties.

PLFs, like Compound, provide a decentralized way for investors to earn interest on their cryptoassets by lending them to borrowers. While this can be a lucrative way to earn passive income, investors must also be aware of the risks involved, including price fluctuations of the underlying cryptoassets, borrower default, and the potential for liquidation if the value of the collateral falls below the liquidation threshold. Investors in a PLF fund are not debtholders and do not receive direct interest payments. Instead, they receive interest in appreciating the fund’s fungible token regarding its cryptoasset, assuming borrowers repay their loans. PLFs do not involve human discretion in lending, and borrower interest rates are specified according to an exogenous function that is typically an increasing function of the fund’s utilization rate. Loans in a PLF are generally floating-rate loans, and borrowers can repay them anytime.

The Oracle problem is also present in the context of PLFs. Here, it refers to the difficulty of obtaining accurate pricing data for the collateral used to secure loans, as this data is not directly available on the blockchain. PLFs typically rely on oracles, trusted third-party services that provide off-chain data to smart contracts to obtain pricing data. However, oracles can be subject to manipulation or failure, leading to inaccurate pricing data and potentially compromising the solvency of the PLF. To mitigate this risk, PLFs may use multiple oracles and implement various mechanisms to ensure the accuracy and reliability of the data provided by these oracles.

The limited set of acceptable collateral on a PLF has significant implications for economic activity on the platform. It makes traditional borrowing through physical collateral impossible and instead focuses on leveraged long trading and short selling of risky cryptoassets. These activities are mainly executed with ETH since PLFs operate primarily on the Ethereum blockchain. Leveraged long trading involves purchasing ETH, investing it at the PLF ETH fund, pledging it as collateral, borrowing stablecoin from the PLF stablecoin fund against the collateral, and then selling the borrowed stablecoin at a cryptoasset exchange for more ETH. This results in leveraged gains as ETH appreciates relative to USD. On the other hand, short selling of ETH involves purchasing stablecoin, investing it at the PLF stablecoin fund, pledging it as collateral, borrowing ETH from the PLF ETH fund against the collateral, and then selling the borrowed ETH at a cryptoasset exchange for more stablecoin. As the price of ETH declines, the investor profits since the fall in ETH prices reduces the USD-equivalent value of their borrowings from the PLF.

Conclusion

It is worth noting that the adoption and development of smart contracts have been relatively slow despite their early conceptualization. However, the emergence of Decentralized Finance (DeFi) applications has started unlocking smart contracts’ economic potential. DeFi has attracted large attention and investment recently. Despite challenges, such as regulatory clarity, the potential for smart contracts to integrate with traditional legal structures could lead to further growth in their economic value. Overall, smart contracts and DeFi are still in their early stages of development, and there is significant potential for growth in the future.


References

Barbon, Andrea, and Angelo Ranaldo. 2021. “On the Quality of Cryptocurrency Markets: Centralized Versus Decentralized Exchanges.” arXiv Preprint arXiv:2112.07386.

Capponi, Agostino, and Ruizhe Jia. 2021. “The Adoption of Blockchain-Based Decentralized Exchanges.” arXiv Preprint arXiv:2103.08842.

Hasbrouck, Joel, Thomas J Rivera, and Fahad Saleh. 2022. “The Need for Fees at a Dex: How Increases in Fees Can Increase Dex Trading Volume.” Available at SSRN.

John, Kose, Leonid Kogan, and Fahad Saleh. 2022. “Smart Contracts and Decentralized Finance.” Available at SSRN.