<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Arbnom on Medium]]></title>
        <description><![CDATA[Stories by Arbnom on Medium]]></description>
        <link>https://medium.com/@arbnom?source=rss-4f848cc211e3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8DhZC6iC5sxvlPg71lQflQ.jpeg</url>
            <title>Stories by Arbnom on Medium</title>
            <link>https://medium.com/@arbnom?source=rss-4f848cc211e3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 10:06:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arbnom/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Comprehensive Deep Dive to Liquity]]></title>
            <link>https://medium.com/@arbnom/a-comprehensive-deep-dive-to-liquity-b6bc93d37a54?source=rss-4f848cc211e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6bc93d37a54</guid>
            <category><![CDATA[liquity]]></category>
            <category><![CDATA[cdp]]></category>
            <category><![CDATA[borrowing]]></category>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[stable-coin]]></category>
            <dc:creator><![CDATA[Arbnom]]></dc:creator>
            <pubDate>Sat, 11 Nov 2023 22:21:34 GMT</pubDate>
            <atom:updated>2023-11-11T22:21:34.737Z</atom:updated>
            <content:encoded><![CDATA[<p>Decentralized stablecoins that operate on decentralized networks are essential for the success of decentralized finance (DeFi) protocols. In this blog post, we deep dive into the most decentralized stablecoin, LUSD. In the previous blog post, <a href="https://medium.com/@arbnom/navigating-the-defi-landscape-a-comprehensive-deep-dive-to-stablecoins-e53976215511">“A Comprehensive Deep Dive into Stablecoins,”</a> I mentioned Liquity’s LUSD in the section related to CDP-backed stablecoins. However, LUSD deserves a dedicated discussion about itself, which is why we are here. In this blog post, we will cover these topics:</p><ol><li>What is CDP</li><li>Liquidation through the stability pool</li><li>Redistribution Mechanism</li><li>Recovery Mode</li><li>Redemption Mechanism</li><li>Decentralization — no proxy, no governance</li><li>Fees</li><li>Oracle</li><li>Front-end operations</li></ol><p>The Liquity protocol is an interest-free borrowing platform. Essentially, Liquity allows users to borrow a USD-pegged stablecoin, LUSD, in exchange for creating a collateralized debt position (CDP) by providing their ETH. Every CDP is represented by a trove which maintains two balances: one in the asset ETH — the collateral, and the other is a debt denominated in LUSD.</p><p>In the previous blog post about stablecoins, we observed the importance of initial arbitrage mechanisms. These mechanisms play a critical role in protecting the price by incentivizing arbitrageurs. For instance, centralized stablecoins hold a reserve that covers the total market cap of the stablecoin, and in the case of a depeg scenario, that reserve provides an arbitrage opportunity. For example, if a centralized stablecoin loses its peg, arbitrageurs can purchase the stablecoin at a price lower than a dollar and redeem it for a dollar. Thus, they help to correct the price by increasing demand while making a profit through buying cheap and selling at a slightly higher price. For more details, don’t forget to read the stablecoin post. CDPs are key for crypto-backed stablecoins by facilitating internal arbitrage opportunities.</p><p>A CDP, or Collateralized Debt Position, is a financial instrument that enables users to borrow funds by providing collateral. Liquity’s CDP module is a system that allows users, like Alice, to create a debt position by locking in their collateral and requesting a certain amount of LUSD to borrow. The value of the collateral is determined by an oracle, and the collateralization ratio is calculated by dividing the value of the collateral by the amount of LUSD requested for borrowing. If the collateralization ratio exceeds the liquidation ratio, set at 110% in the Liquity Protocol, Alice’s request will be approved; the requested LUSD will be minted and sent to her. When she repays her debt, the ETH she provided as collateral can be reclaimed. Contrary to many CDP platforms, Liquity does not charge interest fees for borrowers. The protocol imposes a one-time borrowing fee that algorithmically adjusts based on the time since the last redemption. This makes Liquity particularly attractive for long-term borrowing plans. Later, we will delve into the algorithm that determines the fee structure.</p><p>One might wonder what occurs if the collateralization ratio drops below the threshold due to a decrease in the collateral asset’s value — in other words, what if the collateral can no longer cover the debt? This situation poses a risk to LUSD’s security since some tokens would lack backing by any asset. To prevent such an occurrence, if the collateralization ratio falls back to the minimum collateralization ratio — also known as the liquidation ratio — then the user’s collateral is sold to mitigate the protocol’s potential losses. Many CDP protocols dispose of liquidated assets through on-chain auctions. However, since auctions take time, they typically set the liquidation ratio above 130% to account for potential price drops during the auction. Liquity offers a novel solution by expediting the liquidation process, which allows for a significantly lower minimum collateralization ratio of 110% compared to other protocols.</p><p>Liquity employs a direct method to liquidate assets by selling them to stability providers. These providers are akin to on-chain auction bidders but are constantly ready to purchase liquidated assets. They contribute LUSD to the stability pool, and if a trove’s liquidation is triggered, the smart contract removes LUSD from the pool and burns it. In return, stability providers can claim the collateral from the liquidated pool proportional to their share in the stability pool. This means they receive ETH equivalent to 110% of their LUSD that the contract burned, presenting an opportunity to profit by up to 10% if they sell the collateral promptly. For example, let’s say Alice uses 10 ETH as collateral to take out a 10,000 LUSD loan when the ETH price is $1150. Should the ETH price drop to $1100, her collateral would be liquidated via the stability pool. The borrowed 10,000 LUSD would be removed and burned, and the collateral is then distributed to stability pool contributors. If Bob has a 10% stake in the pool, he effectively receives 1 ETH for 1,000 LUSD, which he could sell at the current price of $1100 for a $100 gain.</p><p>Initiating liquidation incurs a gas fee, like all other transactions. For liquidations, the system allocates a reserve of 200 LUSD for these costs. This means if you request 35,000 LUSD, the system actually produces 35,200 LUSD, setting aside 200 LUSD for potential liquidation expenses. This Liquidation Reserve is refundable; it’s returned when you close your Trove by settling your debt. Moreover, it’s considered part of the debt in the Trove’s collateral ratio calculation, marginally raising the actual collateral required.</p><p>The efficiency of quick liquidations allows for a lower liquidation ratio, enhancing safety by minimizing the risk of price decline during the process. Yet, this efficiency hinges on the stability pool’s liquidity. What if the pool runs low? Then, the debt and collateral from liquidated CDPs are spread among all remaining CDPs, proportional to each user’s share of system-wide collateral. For instance, if Alice has a 10% share of the system’s total collateral, she would acquire 10% of both the collateral and debt from any liquidated CDP, impacting her assets and liabilities.</p><p>However, this kind of redistribution almost never occurs as the LUSD in the stability pool generally exceeds 50% of all LUSD in circulation. The graph below depicts LUSD’s utilization across protocols. For additional insights, you can visit the <a href="https://dune.com/liquity/liquity">Dune dashboard</a> of Liquity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6rt903jl5mXFCMjG" /></figure><p>Although it’s unlikely to occur, let’s examine the redistribution mechanism with a concrete example. Suppose 1 ETH is valued at $1000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_O56f1Qlo0UGMd_TyVPq0A.png" /></figure><p>Once Daniel’s position is liquidated through redistribution, the updated positions are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HnmMaQbf6OCgBYdFCiF2tw.png" /></figure><p>As the charts above show, the redistribution mechanism does not change the total liability of the protocol when liquidating a trove without the stability pool. Through redistribution, every trove holder acts like a stability provider and has the potential to profit by selling the liquidated collateral quickly. However, if they do not act swiftly and the price of ETH falls after the distribution, their increasing debt may be overcompensated, which can cause some loss and decrease their collateralization ratio. Given that the LUSD in the stability pool exceeds half of the total circulation and there are numerous troves, a borrower should not worry about the risks associated with the redistribution method. Nevertheless, the Liquity protocol has a backup plan to ensure robustness — Recovery Mode.</p><p>Before delving into Recovery Mode, let’s introduce a new concept: the Total Collateralization Ratio (TCR), calculated by dividing the worth of total collateral in the system by the total debt issued. This ratio is a good indicator of the system’s health. For instance, when the TCR is relatively high — let’s say 270% — there is no need to worry about the system’s overall health. Even if the stability pool is depleted, the system can sustain itself through the redistribution method. However, if the TCR drops, the effectiveness of redistribution may diminish. Consider a TCR of 111%; how could it protect itself if the price falls even slightly?</p><p>To maintain the overall health of the system, Liquity activates Recovery Mode when the TCR falls to or below 150%. In Recovery Mode, new LUSD can only be issued by adjusting existing Troves to improve their collateral ratio or by opening a new Trove with a collateral ratio of at least 150%. CDPs with a lower collateralization ratio may be liquidated unless the stability pool is empty. This process prioritizes the riskiest CDP and continues until the TCR is restored to 150%. The goal of Recovery Mode is not to penalize trove holders. Notably, in this type of liquidation, a CDP is not entirely sold off. For example, if Alice has the riskiest position with a collateral ratio of 140% and Recovery Mode is triggered (assuming the Stability Pool can cover her), then 110/140 of her collateral would be liquidated. She could then claim the remaining 30/140 portion. As a result, she effectively loses only 10/140 of her collateral, given she had borrowed LUSD equivalent to 100/140 of her collateral and manages to reclaim 30/140 of it.</p><p>A special case arises when the collateralization ratio of a trove drops so rapidly that it falls below 100% before liquidation occurs. In such a scenario, liquidating the collateral through the stability pool would lead to losses for the stability providers. To prevent stability providers from incurring losses, which would deter them from participating, this type of liquidation is also managed through redistribution, rather than imposing costs on the stability providers. Here is a helpful table from the <a href="https://docs.liquity.org/">Liquity Docs</a> summarizing the types of liquidations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/0*_YQRRzw129p9nqZR" /></figure><p>Where;</p><ul><li>ICR = Individual Collateral Ratio</li><li>MCR = Minimum Collateral Ratio</li><li>TCR = Total Collateral Ratio</li><li>SP = Stability Pool</li></ul><p>Now, let’s turn our attention to another mechanism that contributes to LUSD’s robustness — the redemption mechanism. Redemptions are crucial for reinforcing the LUSD’s price stability. Through this process, users can exchange 1 LUSD for an equivalent value of $1 in ETH, taken from the most vulnerable position, identified by the lowest collateralization ratio. As a result, the debt in these positions is reduced in proportion to the amount of ETH redeemed. Essentially, redeeming LUSD equates to settling the debt of the riskiest position and acquiring its collateral. Since the value of the redeemed ETH is equal to the LUSD debt paid at the moment of redemption, the balance of the most vulnerable trove remains unchanged. For example, imagine the price of ETH is $1000, and Bob’s position is the most vulnerable, having secured a loan of 800 LUSD with 1 ETH as collateral. When Alice redeems 100 LUSD, she’s effectively repaying 100 LUSD of Bob’s debt and, in exchange, she claims ETH worth $100 from his collateral. Post-redemption, Alice holds 0.1 ETH, and Bob’s remaining loan is 700 LUSD against 0.9 ETH. Bob’s balance remains the same after redemption; he still owes $200, and his collateralization ratio increases from 125% to 129%. Thus, the redemption mechanism not only helps maintain the peg but also discourages the creation of risky positions that could cause issues for both the trove owner and the wider system.</p><p>Moving on to Liquity’s level of decentralization, many of you are familiar with DAOs that govern protocols through user voting, where the number of tokens dictates voting power. It seems democratic, doesn’t it? However, let’s be honest — many DAOs are dominated by insiders such as protocol developers and investors. With insiders sometimes holding large token amounts (occasionally over 50% of the total supply), these DAOs can resemble puppet regimes. The Liquity team stands against such self-serving governance systems, hence there is no DAO overseeing Liquity. You might wonder if the team then makes unilateral decisions about the platform and its parameters. The answer is a definitive no. Liquity lacks any proxy contract that would allow for updates or an admin key, ensuring the protocol operates without the possibility of censorship or alterations. The system is designed to function autonomously.</p><p>All of the logic mentioned above illustrates why LUSD is by far my favorite stablecoin. It operates independently, free from any DAO or team influence, making it the most decentralized option. It’s also the most robust stablecoin, with over half of the LUSD supply poised to instantly liquidate risky positions. Should the LUSD in the stability pool prove insufficient for liquidations, the redistribution system steps in to safeguard the protocol. Additionally, to maintain the efficiency of the redistribution system, the protocol is programmed to keep the Total Collateralization Ratio (TCR) above 150%. The redemption mechanism further strengthens the peg and discourages the creation of precarious positions. It’s a testament to elegance. I recall describing Liquity to a friend as a protocol that’s akin to a poem.</p><p>Regarding fees, Liquity does not impose ongoing interest charges. Nevertheless, two types of fees are present. The first is a one-time borrowing fee incurred when creating a trove. The second is a redemption fee, pivotal for fending off potential attacks. Without the redemption fee, attackers could exploit the system through incessant redemptions. This fee mechanism thus renders such attacks unprofitable, effectively deterring unnecessary redemptions.</p><p>Both these fees are governed by an algorithm that raises the fees in response to increased redemptions. Both fees derive from a function known as the base rate, denoted by <em>b(t)</em>. The base rate functions recursively, meaning it uses its previous value to calculate the current rate. Initially, the base rate was set to 0. The base rate at any given time<em> b(t)</em> is calculated by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*bsh243_RFxMX4RBBgR1CAQ.png" /></figure><p>where:</p><ul><li><em>b(t-1)</em> is the base rate at the time<em> t-1,</em></li><li>is a constant parameter set to 0.5,</li><li><em>m </em>is the amount of redeemed LUSD,</li><li><em>n</em> is the amount of current supply of LUSD.</li></ul><p>The formula above calculates the base rate before redemption occurs. If no redemption occurs for a certain period, the base rate gradually decreases, calculated by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*Vq4sL0BumnDWRhhnD9Pl5A.png" /></figure><p>where:</p><ul><li><em>beta </em>is the decay factor setted as 0.94,</li><li><em>delta-t </em>is the time elapsed since the last redemption or loan issuance.</li></ul><p>The choice of <em>beta=0.94</em> ensures that the base rate’s half-life is 12 hours. For redemptions, the base rate equals the redemption fee. To understand the redemption fee mechanism, let’s consider an example from the whitepaper.</p><p>Assume LUSD currently trades at $0.95 and the current base rate is 1.4%. An arbitrageur redeems 150,000 LUSD from a total supply of 10 million LUSD. The last redemption occurred 2 hours ago, and no loans have been issued since. With an hourly decay factor of 0.94, the system first applies the decay rate to the last base rate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*6LLADDxp1JcA5RtDO4Dfgg.png" /></figure><p>Then, it increases the base rate according to the redemption amount:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*dmdSdKfGX3SHTCMsio7wnQ.png" /></figure><p>As a result, the redeemer receives ETH worth $147,019.44 for their redeemed 150,000 LUSD. Considering the LUSD is currently valued at $142,500, the arbitrageur gains $4,519.44.</p><p>Note that the minimum redemption fee is set at 0.5%.</p><p>Now, let’s look at the borrowing fee. The borrowing fee is also calculated through the base rate, but it’s assessed as the base rate plus an additional 0.5%. Using the whitepaper example again, if the base rate is 0.5%, the one-time borrowing fee is 1% (0.5% + 0.5%). In this case, a borrower who deposits 4 ETH and withdraws 4,000 LUSD will encounter a Liquidation Reserve of 200 LUSD and a 1% fee on the withdrawn amount. Thus, the borrower receives 4,000 LUSD but incurs a debt of 4,240 LUSD (accounting for the initial loan, the Liquidation Reserve, and the fee). To reclaim the deposited 4 ETH, the borrower must repay 4,040 LUSD since the Liquidation Reserve is refundable.</p><p>Note that the minimum borrowing fee is set at 0.5%, and the maximum is at 5%.</p><p>Having an algorithmic fee structure is advantageous, especially during times of negative depeg when redemptions increase, leading to higher borrowing fees as they’re calculated via the base rate. This discourages the creation of new positions. As I’ve mentioned before, the protocol is elegantly designed.</p><p>The price of ETH is critical for the system because it directly affects collateralization ratios. For the system to function properly, accurate price information is non-negotiable. Liquity relies primarily on Chainlink’s ETH:USD price feed. However, they also have access to Tellor’s ETH:USD price feed under extreme conditions:</p><ul><li>Chainlink price has not been updated for more than 4 hours,</li><li>Chainlink response call reverts, returns an invalid price, or an invalid timestamp,</li><li>The price change between two consecutive Chainlink price updates is greater than 50%.</li></ul><p>By incorporating these measures, they safeguard their price feed to prevent unexpected outcomes.</p><p>You might now share the same inspiration I felt when I first read the Liquity documentation. If you decide to use Liquity for borrowing USD-pegged stablecoin and visit their website, you won’t find a “Launch App” button or its equivalent. This is because Liquity does not provide a frontend service. In their commitment to decentralization, they encourage developers to create and operate frontends, enhancing the system’s resistance to censorship. Currently, there are over 15 different frontend options for users to access Liquity. Frontend operators set a kickback rate, which is a fee charged to their users. However, borrowing LUSD and staking LQTY are not subject to the kickback rate. LQTY rewards distributed to stability providers are subject to this rate.</p><p>Staking LQTY, the native token of the protocol, is also possible. LQTY is not a governance token, LQTY is designed to incentivize users to act as stability providers, operate frontends, and provide liquidity to the LUSD:ETH Uniswap pool. LQTY staking allows for immediate rewards without any lock-in period, unlike veTokens. Stakers earn a pro-rata share of borrowing and redemption fees in LUSD and ETH.</p><p>With this exploration of staking mechanisms, we’ve touched upon the core features of Liquity. There are additional topics worth exploring in depth, such as the math behind chicken bonds, Liquity V2, and the LUSD price fluctuations between $1.01 and $0.99. To maintain readability, I’ll discuss these topics in future blog posts. Thank you for investing your time in this discussion; I sincerely value your interest and am open to any feedback you might offer. Also, feel free to connect with me on <a href="https://twitter.com/arbnom">Twitter.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6bc93d37a54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Deep Dive to Balancer]]></title>
            <link>https://medium.com/@arbnom/a-comprehensive-deep-dive-to-balancer-86f19afb9d31?source=rss-4f848cc211e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/86f19afb9d31</guid>
            <category><![CDATA[amm]]></category>
            <category><![CDATA[liquidity-pool]]></category>
            <category><![CDATA[balancer]]></category>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[automated-market-maker]]></category>
            <dc:creator><![CDATA[Arbnom]]></dc:creator>
            <pubDate>Fri, 10 Nov 2023 14:31:18 GMT</pubDate>
            <atom:updated>2023-11-10T14:31:18.937Z</atom:updated>
            <content:encoded><![CDATA[<p>Uniswap’s XY=K formula has been a game-changer for DeFi. In our previous blog post “<a href="https://medium.com/@arbnom/navigating-the-defi-landscape-a-comprehensive-deep-dive-to-amms-954020ec23b">A Comprehensive Deep Dive into AMMs</a>,” we noted that Uniswap’s formula isn’t the only one employed by Automated Market Makers (AMMs). Different pool types offer distinct benefits, such as reducing slippage rates or facilitating more efficient trades for swappers, and some even assist liquidity providers (LPs) who hold LP tokens as a tool for portfolio balancing. Today, we’re exploring Balancer’s customized pools, which are an extension of the XY=K formula, allowing for the creation of pools with various asset compositions. Our discussion draws from the Balancer whitepaper, and we’ve organized our findings into several key topics:</p><ol><li>What was innovative about Balancer</li><li>Definition of the value function</li><li>Examples of customized pools</li><li>How to calculate the price in a customized pool</li><li>Proof of constant value distribution</li><li>How providing liquidity can balance a portfolio</li><li>Efficiency and slippage comparison</li></ol><p>Balancer’s formula enables the creation of customized pools, which is a functionality not available with Uniswap’s standard model. For instance, a Uniswap pool is restricted to containing two assets with identical balances. However, Balancer’s formula allows for the creation of pools that can include three, four, five, or more assets, without requiring equal balances. This means that the weights of the assets in the pool are at our discretion. For example, one could design a pool with Ethereum (ETH) and DAI, allocating 80% of the pool’s value to ETH and 20% to DAI.</p><p>In contrast, the Uniswap model operates on the <em>XY=K</em> formula, ensuring that the weight balances of assets remain equal. But how does this work? Let’s imagine we have a pool with tokens A and B following the <em>XY=K</em> formula, where <em>X</em> represents the quantity of token A, and y is the quantity of token B. From our calculations in the blog post about Uniswap V2, we know that when Alice wants to purchase an amount p of token A with token B, the unit price approaches <em>Y/X</em> as p approaches zero. Without any slippage, the price would stabilize at <em>Y/X</em>. Thus, we can define the theoretical price of token A in relation to token B as <em>Y/X</em>. Consequently, since token A’s quantity in the pool is <em>X</em>, its total balance compared to token B is <em>Y</em>. With token B priced at 1 relative to itself, its total balance in the pool is also <em>Y</em>, resulting in the pool’s total value being <em>2Y</em> when measured against token B. Conversely, the total value is <em>2X</em> when measured against token A, establishing that the weights of tokens A and B are inherently equal. We will now turn our attention to how Balancer’s formula might alter these weight distributions.Balancer’s value function diverges from the simplicity of Uniswap’s formula. It is expressed as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*xV_MU1lX_xfeOZ_PtF5enw.png" /></figure><p>where</p><ul><li><strong><em>t</em></strong> ranges over the tokens in the pool;</li><li><strong><em>Bt</em> </strong>is the balance (or amount) of token <em>t </em>in the pool;</li><li><strong><em>Wt</em></strong> is the normalized weight of the token, such that the sum of all normalized weights is 1.</li></ul><p>The logic behind trades is simple with Uniswap’s formula, keeping V constant. Let’s consider some pools generated by the value function:</p><blockquote><strong>Two assets with 50–50 weight balance:</strong></blockquote><p>Suppose that we want to create a pool consisting of two tokens, namely <em>t1</em> and <em>t2</em>, with the same weighted balance. Then our formula becomes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*3kPeZOiNSndC4BWTwRRbyQ.png" /></figure><p>It seems familiar right? If we take the square of the two sides we reach</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/125/1*rSDH4SqA5U7h-T16mlmmuw.png" /></figure><p>and if we define</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/83/1*SX5izElz562sU6T0VwLPWg.png" /></figure><p>we will have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*UT49e4EqRFWj30MVI3-Yug.png" /></figure><p>which is the classical constant product formula.</p><p>Let’s assume Alice wants to buy p many token 1 (which is t1) and by the formula</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*3kPeZOiNSndC4BWTwRRbyQ.png" /></figure><p>she needs q many token 2 (i.e, t2). Which means</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*Q1KwGQhgSCR8wN3AmaNY0Q.png" /></figure><p>however, from this, we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*h2l0PY1y7wjRCYF_afaEkg.png" /></figure><p>As a result we have same (p,q) pair working with the both equations effectively. Therefore we can say that Balancer’s value function allows us to create classical pools introduced by Uniswap V2. However we have more pool options.</p><blockquote><strong>Three assets with equal weight balance:</strong></blockquote><p>Similar to above, if we create a pool consisting of three tokens, namely t1, t2 and t3 with the same weighted balance, then our formula becomes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*wHd7pfHwuw6lYlI8KOU-9Q.png" /></figure><p>By defining</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/120/1*l7kndzx-lS60QqtJljTbCw.png" /></figure><p>we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/1*F44v4lj--WA-aWly_QZIjw.png" /></figure><p>which is quite similar to our classical formula. But if we change the weights, our formula becomes slightly different.</p><blockquote><strong>Two assets with 80–20 weight balance:</strong></blockquote><p>Let’s say we create a pool with an 80–20 weight balance between two assets such that the balance of t1 is 80% where t2’s 20%. Then our formula would be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*lEu9tWvAgUPvVxYpjCjJ1A.png" /></figure><p>Similar to above if we define</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/107/1*aw-xChyBwUaYLwbC9Cth3Q.png" /></figure><p>then we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*K-jabZ1B_ywT8Hi4qgzEHA.png" /></figure><p>The logic is quite easy to understand, but let’s check one more example.</p><blockquote><strong>Three assets with 40–40–20 weight balance:</strong></blockquote><p>Just like the above examples we have three tokens namely t1, t2 and t3 and their balance is 40–40–20 respectively. If we put in these in to the formula we have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*YT531NTMYR5UiEMg0NuHVA.png" /></figure><p>the move is same: we define</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/97/1*-RbB_hy8bixEgfo7kKsgOA.png" /></figure><p>As a result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*FjIjoGg7mZe6weg1ZRjsyQ.png" /></figure><p>All of the pool types above have different aspects in terms of their slippage rates. We will investigate all of them in the next paragraphs, however first we need to examine how to calculate the price of an asset in a customized pool with respect to other assets in the pool. As we discussed in the blog <a href="https://medium.com/@arbnom/navigating-the-defi-landscape-a-comprehensive-deep-dive-to-amms-954020ec23b">post about AMM’s,</a> the price of tokens is highly dependent on the amount of the trade and the liquidity of the pool, see the section related slippage.</p><p>Now assume we have a generic pool with created the equation of value function. Let’s say that Alice buys <em>A0</em> unit token 0 in exchange for <em>Ai</em> unit token i, then the price is <em>Ai/A0</em>. To maintain consistency with the notation used in the whitepaper, let’s define</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*aBprP2ne_6kXd-IGagbAGw.png" /></figure><p>We call it the effective price. As we know it’s dependent on the values A0, A1 and if these values become smaller, the slippage rate decreases. Then let’s recall our calculus classes and take the limit of the effective price as <em>A0, A1</em> approach 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*1sDTd_o87xWnMB89Sr3YQg.png" /></figure><p>where <em>ddeltaB</em>’s representing the change of token amounts of the pool. This limit is simply</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/134/1*X8wqV_NaeuYU-uZhPGfIsg.png" /></figure><p>In order to handle with this derivative let’s express <em>Bi</em> in the form of <em>B0</em>. In order to do that we need to focus on the value function, which is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*kd-2R9JdetJDi4rZQGo5sQ.png" /></figure><p>Therefore;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*idDh9oWnJveSzUA_WsuOYQ.png" /></figure><p>We can use it to handle our partial derivative:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*MJzj28hNWrvpV1LqQL6Daw.png" /></figure><p>and this is equal to</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RC9RDMJR_sJd2x23wtt6dg.png" /></figure><p>Since</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*0oClF5KgcqFyOmUU1pJwTg.png" /></figure><p>is simply a coefficient, we can factor it out of the derivative.</p><p>From now on our task is to just take a basic derivative and calculate the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-_sFv-GDhPwh5ViDMe0Kw.png" /></figure><p>And that’s all, this is our price formula, seems disgusting huh? Don’t worry, we still have some moves to manipulate it. Let’s multiply both the dividend and divisor of the first division with a magical number:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/58/1*D52sjEgOAtbDNB3AqIIZFg.png" /></figure><p>Then we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FxtoO1fF3JnZk0xjEi8bQ.png" /></figure><p>Also by using the definition of <em>V</em> we can manipulate the first division:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IMj9zPpHaduvVjuKIXp77A.png" /></figure><p>Finally, we’ve reached a nice expression. This limit is defined as the spot price and denoted as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/55/1*rH9L0w_zU4DLbQnt-YO5IA.png" /></figure><p>So we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*AikWz77ROvicrr2OrNuFAg.png" /></figure><p>That means for the relatively small trades with respect to the pool’s liquidity, you can expect the price around that value (excluding the fees).</p><p>From now on, we understand the pricing of a token within a pool relative to other tokens. Let’s focus on the weight distributions. At the beginning, we said Balancer’s formula allows us to create specific pools such that 80% of the total value in the pool is of the form ETH and 20% is DAI. In fact, <em>Wt</em> , the normalized weight of the token means the total value of the pool. Let’s say</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/45/1*NmjAAcA3A_TWKuwfV5T29Q.png" /></figure><p>represents the total value of pool in terms of token <em>t</em>, and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/67/1*x3pES3wcKC54_0s2BEkUQw.png" /></figure><p>represents the total value of tokens n in terms of <em>t</em>, i.e., how many tokens <em>t</em> the balance of token <em>n</em> is worth it. Our claim is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/168/1*7tIyDfBa4I_R8QluLQz7Ww.png" /></figure><p>Let’s begin with the total value of the pool in terms of <em>t</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*fGeFZ7xmA6QlWggTLYNRLg.png" /></figure><p>It is evident that the total value of the pool in terms of <em>t</em> equals the sum of the total values of all tokens in the pool in terms of <em>t</em>. We need to focus on the</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/67/1*x3pES3wcKC54_0s2BEkUQw.png" /></figure><p>Recall that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/62/1*37Tr2mNIZaWHSYjwNTPxMQ.png" /></figure><p>is the price of token <em>n</em> with respect to token <em>t</em>. Therefore</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*jQv6YRgESnbVYWKDmxWcYg.png" /></figure><p>If we take out <em>Bt</em>, and plug the value of</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/67/1*x3pES3wcKC54_0s2BEkUQw.png" /></figure><p>into the summation above we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0p6kTyl3PSyLsbIZgFvh7w.png" /></figure><p><em>Bt</em> and <em>Wt</em> are constant so we can take them out. Hence,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*g7DEjJ7YuMHGlENLBloKpA.png" /></figure><p>by the definition of <em>Wn</em>’s. Therefore, the total value of the pool in terms of <em>t</em> is equal to <em>Bt/Wt. </em>We are almost done. Let’s define <em>Sn</em> as the share of token <em>n</em> in the pool. In order to calculate <em>Sn</em> we need to divide the total value of token <em>n</em> by the total value of the pool. This is given by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*-l9yKboRMbJmZC060EsnKw.png" /></figure><p>Therefore, the weight balances of tokens in the formula really represent their shares in the pool.</p><p>Let’s focus on the practical implications of this fact. Many hedge funds employ a balancing strategy within their portfolio. As the price of one asset increases relative to others, they sell it in exchange for less expensive ones, and vice versa. This tactic prevents any single asset from either dominating or being dominated by the others in the portfolio. Through this process, they capitalize on the gains from the higher-performing assets and bolster their positions in others. Also, maintaining a diverse asset portfolio mitigates the risk associated with reliance on a single asset. In essence, this is an efficient investment strategy.</p><p>But how can we apply this strategy to cryptocurrency assets? By becoming a Liquidity Provider (LP) on Balancer. As we have demonstrated, Balancer’s custom pools help maintain asset ratios in line with their prices. For instance, if you wish to balance your holdings of ETH, LQTY, and LUSD equally, providing liquidity to Balancer’s 33LUSD-33LQTY-33WETH pool ensures that each asset in your portfolio maintains equal value. Additionally, you profit from trading fees and potentially from BAL token incentives while maintaining balance in your portfolio.</p><p>What if there isn’t a pool that matches your portfolio? There’s no need for concern. With <a href="https://app.balancer.fi/#/ethereum/pool/create">Balancer’s pool creation page</a>, you can easily set up your own pool. The liquidity might start off low. If someone manipulates your pool and it is not re-balanced, you can purchase the necessary assets from the open market to correct it. Essentially, you’ll be engaging in arbitrage with your pool, profiting from the adjustments you make.</p><p>Balancer offers significant advantages for liquidity providers. But what about traders? To evaluate swap efficiency in terms of slippage, consider two pools: one follows Uniswap’s constant product model, and the other is a customized pool with two assets weighted at 66.6% and 33.3% such that token A’s weight is 66.6%. We have two formulas:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*RO2x3E8Fy9zGJRFZV4gHwQ.png" /></figure><p>for the constant product pool, and</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/1*AFHyF7LENOILT5YYvdbp8w.png" /></figure><p>for the customized pool. Where, <em>X,Z</em> corresponds the amount of token <em>A</em> and <em>Y,T</em> are of token <em>B</em>. Now let’s assume the price of token <em>A</em> in terms of token <em>B</em> is the same in both pools and the total value of pools are the same. Using these two pieces of information we can write <em>Z,T</em> in terms of <em>X,Y</em>. As we proved above, the value of the first pool is <em>2X</em> and the second one’s value is <em>3Z/2</em> in terms of token <em>A</em>. So,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*-HokIz1FoCTyQP1CCuCBKw.png" /></figure><p>And similarly,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/167/1*guIMLVglW58hMpvKfOQ6XA.png" /></figure><p>Therefore our value function becomes;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*0u0jUuN9TLpDdGlilIvTZw.png" /></figure><p>Now suppose that Alice buys the same amount of token A from both pools. Therefore, slippage — the difference between the real and theoretical price of these trades — is calculated by.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*crFvvth6ug9Ng4iJf02YWA.png" /></figure><p>where;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*VjvXFXJUN5JqivenUNdwqw.png" /></figure><p>And,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*K-J3zPG65euuHvCBX6yT8Q.png" /></figure><p>where;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*rIeGlAQOsN-21T27OSajUQ.png" /></figure><p>Now we will prove that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/132/1*wRr8ljxvO7mqHqgJzfrx8Q.png" /></figure><p>which means the Balancer pool containing two weighted assets such that weights are 33.3% and 66.6% is less efficient than the Uniswap’s pool in terms of slippage. In fact, this is not special to 33.3%-66.6% weights. The optimum pool is the 50–50 one. Since the other terms are equal, it’s enough to show that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/161/1*v6dodFyav9SJAReJAMvLbA.png" /></figure><p>in order to prove</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/134/1*1CTPUquPqHbFGk8DZx56ww.png" /></figure><p>Let’s begin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*ikFmM5SLwPKGe0y1oFPNVQ.png" /></figure><p>coming from the definition directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zL7ttQ447S9NgkSO19zkxw.png" /></figure><p>since</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*LUfGyr1nNvOM1OpDv85B6g.png" /></figure><p>we can say that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*lmCVopJnMIZNdf0LrW1D2A.png" /></figure><p>Thus we have;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*zt5dGBUyl4kJ4dvLl1Ll-A.png" /></figure><p>By the same argument above,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*atDg4nbclKUoaTpVEBo_vw.png" /></figure><p>implies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/251/1*5Q-C_GSCb-CpboKTuGYCdA.png" /></figure><p>Therefore, we get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*cAXdnPqnDrzWQHcCpY9Z0g.png" /></figure><p>which means</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/151/1*ngRR3xYLdlq7sTSMZGzqOw.png" /></figure><p>Thus, we have proved that buying token <em>A</em> from the customized pool is inefficient in terms of slippage. Similarly, it can be shown that buying token <em>B</em> is also inefficient regarding slippage. Furthermore, for other customized pools with varying weight balances, the outcome remains consistent. The Uniswap formula, or a customized Balancer pool with equal balances, proves to be more efficient than other configurations. The chart below illustrates the percentage of slippage incurred by a pool with $200,000 worth of assets, composed of tokens <em>A</em> and <em>B</em>, for a trade amount of $1,000 across varying weights of token A. The symmetry around the 50% mark reflects the constant total weight, where the sum of weights for A and B always equals 100%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fWK___Uqu3F2l2qu" /></figure><p>The graph demonstrates that the slippage rate escalates more rapidly as the weight of one asset approaches zero. For this reason, in pools with two assets, it is uncommon for one asset to have a weight less than 20%. Consequently, based on the pool statistics provided, we can assert that the maximum slippage difference between a traditional Uniswap pool and a Balancer pool is approximately 0.5%. It’s important to note that this graph assumes a trade equivalent to 1% of one of the pool’s assets, a significant amount for the average daily trade, given that most pools are valued in the millions. If we consider a smaller trade, say 0.1% of one of the assets — which is still considerable for many pools — the slippage in a traditional Uniswap pool would be around 0.1%, compared to a maximum of 0.15% in Balancer’s. Thus, while transactions in a pool with 50–50 weights are always superior to those in other customized pools, the difference is generally negligible.</p><p>We have established that classic Uniswap pools are more efficient, even if the difference is minor for practical purposes. However, Balancer facilitates the creation of pools with more than two assets, which can result in more efficient trading. For example, consider three tokens — token A, token B, and token C — each with a balance of 20,000. If we create three separate pools using the traditional formula, we would have three pools, each with two assets amounting to 10,000 each. In this scenario, when Alice buys 100 units of token A in exchange for token B (the pair is irrelevant since the assets are equally distributed), she would incur a slippage of 1.01%. Now, imagine we create a single pool containing all three assets with equal weights, with each asset contributing 20,000 units. If Bob performs the same transaction as Alice, attempting to buy 100 units of token A in exchange for token B, he would encounter only 0.50% slippage — half that of Alice’s. This reduction is due to the increased liquidity; in essence, Bob’s trade is the same as trading in a classical pool where each asset’s quantity is 20,000. Let’s validate this claim.</p><p>We want to show that buying</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/43/1*4mCmheCfSd6s72Gi-Xwt7w.png" /></figure><p>amount of token <em>A</em> in exchange for token <em>B</em> from both pools that first one is formulated as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/140/1*p-91Uz4JZQt2fhc7xxmiaA.png" /></figure><p>and the second one is formulated as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/174/1*4bz-e5Zwh54Q7-Rjmd531g.png" /></figure><p>where <em>X,Y,Z</em> represents the balance of token <em>A</em>, token <em>B</em>, token <em>C</em> respectively. Let’s say that</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/102/1*gXmQL9JWZRaWN0csy5AHkA.png" /></figure><p>are the price to be paid to the first and second pool respectively. We need to show that they are equal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*EeoLz1GBTwZjpVkXb9i7Zg.png" /></figure><p>Therefore, pools containing more than two assets with equal balances effectively function the same as classical pools with corresponding assets and identical liquidity levels. Thus, it can be said that diversifying the number of assets in a pool, while maintaining equal weights, does not impact slippage, yet the cost of creating such pools decreases significantly. This is evident from the total liquidity not being divided among pools containing only two assets, as illustrated in the earlier comparison between Alice and Bob.</p><p>One might question why not simply create a pool with as many assets as possible, given that Balancer V1 allows for up to 8, and V2 allows for 16. Such a pool would presumably concentrate liquidity and facilitate more efficient trades. The overlooked detail in this argument is that liquidity providers cannot contribute liquidity partially. This means that a liquidity provider must own a proportional share of all asset types in the pool. For example, if a liquidity provider holds 0.1% of the LP tokens, they own 0.1% of each of the 16 assets in the pool. Consequently, achieving substantial liquidity is challenging with this approach, as it’s unlikely that LPs will coordinate their actions. Thus, while increasing the number of assets in a pool can bring about some efficiency by tapping into more liquidity, the difficulty of finding liquidity providers with a complete set of tokens increases with the number of asset types.</p><p>Numerous interesting outcomes can arise from various pool configurations. For those interested in exploring different scenarios, there is a <a href="https://github.com/arbnom/Balancer-UniV2-comparison">GitHub repository</a> available. Briefly, I have programmed four JavaScript functions to simulate different swap scenarios. These functions model swaps on a classic Uniswap pool, a customized Balancer pool with two assets at 80–20 weights, a Balancer pool with three assets at equal weights, and another pool with a 40–40–20 weight distribution. The code can be easily modified to examine other scenarios. If you discover something counterintuitive or intriguing, please share it with me so I can include it in this post.</p><p>In conclusion, Balancer’s value function lets us set up various types of pools to suit different needs for traders and liquidity providers. This post went into detail about what Balancer offers and how its math works, especially when compared to Uniswap. Thanks for taking the time to read; your engagement with the content is highly valued, and I invite any feedback you might have. Also, don’t forget to follow me on <a href="https://twitter.com/arbnom">Twitter.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86f19afb9d31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Deep Dive to Stablecoins]]></title>
            <link>https://medium.com/@arbnom/navigating-the-defi-landscape-a-comprehensive-deep-dive-to-stablecoins-e53976215511?source=rss-4f848cc211e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e53976215511</guid>
            <category><![CDATA[ust]]></category>
            <category><![CDATA[dai]]></category>
            <category><![CDATA[stablecoin-cryptocurrency]]></category>
            <category><![CDATA[stable-coin]]></category>
            <category><![CDATA[usdt]]></category>
            <dc:creator><![CDATA[Arbnom]]></dc:creator>
            <pubDate>Thu, 14 Sep 2023 15:52:09 GMT</pubDate>
            <atom:updated>2023-11-10T08:15:01.048Z</atom:updated>
            <content:encoded><![CDATA[<p>Cryptocurrencies are well-known for their volatility, often resembling a rollercoaster for investors and traders. Unlike most cryptocurrencies, stablecoins aim to maintain a constant price, although some have lost their pegs over time. These stablecoins come in various forms. Some peg their value to the US dollar, others to the Euro. But it’s not only fiat currencies they mimic; a stablecoin might also be pegged to the price of Brent crude oil or an ounce of gold. The core idea is to tie the coin’s value to a tangible asset. In this Medium post, we’ll explore:</p><blockquote>1)The necessity of stablecoins</blockquote><blockquote>2)What we expect from stablecoins</blockquote><blockquote>3)The rationale to protect the peg</blockquote><blockquote>4)Fiat backed stablecoins</blockquote><blockquote>— USDT, USDC, BUSD, TUSD</blockquote><blockquote>— USDC depeg</blockquote><blockquote>5)CDP backed stablecoins</blockquote><blockquote>— DAI /MakerDAO</blockquote><blockquote>— Black Thursday of DAI</blockquote><blockquote>— DAI depeg (caused by USDC)</blockquote><blockquote>— LUSD /Liquity</blockquote><blockquote>6)Algorithmic stablecoins</blockquote><blockquote>— UST collapse</blockquote><blockquote>— USDD</blockquote><blockquote>7)Hybrid stablecoins</blockquote><blockquote>— UXD &amp; delta-neutral positions</blockquote><blockquote>— Mango Market exploitation</blockquote><blockquote>— FRAX &amp; Curve wars</blockquote><blockquote>8)Stablecoin trilemma</blockquote><p>Many wonder about the necessity of stablecoins. If we trust banks to safeguard our money, why would someone exchange USD for a USD-pegged stablecoin? The primary motivation is the “trustless philosophy.” We’ll delve deeper into this concept in a subsequent post. Stablecoins simplify trading, especially in the DeFi realm. Without them, DeFi would struggle to gain efficiency. For example, imagine an ETH holder wanting to cash out some of their investment. What cryptocurrency would they choose in exchange for ETH? Simply trading ETH for another cryptocurrency doesn’t really equate to cashing out — it’s more like changing investment strategies. Without stablecoins, DeFi would be limited in its usefulness, pushing users back to centralized exchanges (CEXs). Transferring USD between CEXs would be out of the question. But beyond facilitating trade, stablecoins also provide opportunities to earn real returns, insulated to some extent from broader market fluctuations. The Curve’s 3pool (USDC/USDT/DAI) is a prime example of this.</p><p>Stablecoins must meet several essential criteria. First and foremost, they need to be stable, which means they should be pegged to a specific asset. There also needs to be a mechanism to protect this peg, which we’ll discuss in the next paragraph. It should also have high liquidity, as this provides a strong defense for the peg. One key reason is that increasing liquidity on DEX decreases slippage rates, which in turn reduces the chance of depegging during large trades.</p><p>For instance, consider two stablecoins: one with a supply of 10,000,000,000 and the other with just 10,000. Even if the slippage rates are the same for Alice, she would certainly prefer the first one. More liquidity enhances arbitrage opportunities, which can be a safeguard during unexpected market events. Moreover, volume is also one of the crucial aspects for a stablecoin. Consider a stablecoin with significant liquidity but almost no trading volume. Since the volume is low, selling (or buying) it from a CEX becomes challenging. Due to this limited volume, not many people want to become an LP, leading to high slippages on DEXs (see <a href="https://medium.com/@arbnom/navigating-the-defi-landscape-a-comprehensive-deep-dive-to-amms-954020ec23b">https://medium.com/@arbnom/navigating-the-defi-landscape-a-comprehensive-deep-dive-to-amms-954020ec23b</a>). These are the essential aspects that stablecoins compete on.</p><p>Let’s discuss the concept of pegging. As previously mentioned, a stablecoin’s price should match the price of its pegged asset. However, maintaining this is challenging due to the open market’s dynamics. For example, if we consider a stablecoin pegged to the USD, there should be a small margin within which the coin’s price can fluctuate. Many believe a ±0.001 margin is negligible, implying the stablecoin’s price ranges between $0.999 and $1.001. Achieving this is possible with the right tools.</p><p>The price of a stablecoin largely depends on traders’ expectations. For instance, if everyone believes that our stablecoin should be priced at $1 with a fluctuation margin of ±0.001, then no one would try to buy or sell it outside of that range. However, this belief shouldn’t be taken at face value. There needs to be a reliable mechanism that ensures the price stability, reinforcing people’s trust. Beyond instilling trust, the mechanism should also fortify the stablecoin against unexpected market events. A primary way to protect the peg is by offering arbitrage opportunities during depegging. If our stablecoin is priced at $0.98 on one platform (DEX or CEX) and $1.13 on another, arbitrageurs can help stabilize the price by buying the cheaper one and selling it where it’s more expensive. But what if the price drops across all platforms? It’s essential to note that not only a price drop (negative depeg) is detrimental to stablecoins; a price increase (positive depeg) can also pose challenges. Given that in the DeFi realm, one can borrow stablecoins using other crypto assets as collateral, a rise in the stablecoin’s price can heighten the risk for that position, potentially triggering liquidations. To guard against both forms of depegging and to restore order after any disruption, there needs to be an internal arbitrage opportunity. This goes beyond mere inter-exchange arbitrage. An effective method is having collateral backing the stablecoin. If the value of our stablecoin drops by 5%, arbitrageurs would step in, leveraging the collateral to profit. Similarly, if the stablecoin becomes overpriced, arbitrageurs can offer collateral to mint the stablecoin and gain profit.</p><p>While the core idea behind protecting the peg centers on arbitrage opportunities, various stablecoins have unique mechanisms to create these opportunities. Let’s delve into the different types of stablecoins.</p><h3><strong>Fiat-Backed Stablecoins</strong></h3><p><strong>USDT, USDC, BUSD, TUSD:</strong> These stablecoins are minted and regulated by centralized institutions. They claim to hold fiat money (or other tangible assets) valued more than the minted stablecoins. This type of stablecoin is currently the most prevalent in the market. As of September, 2023, the market share of fiat-backed and USD stablecoins stands at approximately 93.5%. Despite the existence of over 15 fiat-backed and USD-pegged coins, four primary players — USDT, USDC, BUSD, and TUSD — hold 98.9% of the total market share for fiat-backed USD stablecoins. Although they command the largest market share, they face significant issues concerning decentralization. These stablecoins incorporate “malicious functions” in their smart contracts, which allow the companies behind them to control all user assets. One glaring instance of this is the blacklist feature, the name of which might vary between contracts, but its function remains constant: it blocks transfers from specified wallet addresses. Furthermore, these companies can confiscate funds from blacklisted accounts and have the authority to mint an unlimited supply due to their contract structures. This presents a risk for crypto users because, without visibility into the collateral held, it’s challenging to gauge the safety of these stablecoins.</p><p><strong>USDC depeg:</strong> Discussing centralized stablecoins necessitates mentioning the recent USDC depegging, triggered by the bankruptcy of Silicon Valley Bank (SVB) on March 12, 2023. Predominantly servicing startups, Circle, the company overseeing USDC, was among SVB’s clientele. SVB held Treasury bonds and other long-term debts, traditionally regarded as safe havens for investors. However, the value of these bonds plummeted after the Federal Reserve hiked interest rates to combat high inflation, making these bonds less profitable compared to newer, higher-interest offerings. Around the same time, several of SVB’s clients, primarily in the technology sector, faced financial difficulties, prompting many to withdraw their assets. Consequently, SVB had to sell their bonds at a $1.8 billion loss. This sale prompted credit agencies like Moody’s to downgrade SVB’s ratings, alarming customers about the bank’s liquidity crisis, which spurred a bank run culminating in SVB’s bankruptcy. Circle claimed to back each minted USDC with one dollar and had deposited over $3.3 billion in collateral with SVB. Amid these events, USDC lost its peg, with its value dropping to $0.88. After U.S. banking authorities assured full coverage for Silicon Valley Bank’s uninsured depositors, USDC’s price gradually recovered to $1, illustrating the inherent risks of centralized stablecoins.</p><h3><strong>Crypto-Backed Stablecoins</strong></h3><p>Crypto-backed stablecoins are generated using Collateralized Debt Positions (CDPs). Unlike fiat-backed stablecoins, the contracts of these stablecoins permit users to mint and burn them. As of September 2023, there are over 75 crypto-backed stablecoins with a combined market cap of 5.817B. However, DAI, LUSD, eUSD, and MIM account for more than 83% of this. It’s also noteworthy that crvUSD is steadily gaining traction and is poised to challenge the dominant players in the future, particularly due to its unique deliquidation mechanism (a topic we’ll explore in a future post).</p><p>To mint CDP-backed stablecoins, a user must lock their assets in a position. They can then mint stablecoins valued less than their locked assets. Given the highly volatile nature of cryptocurrencies, it’s crucial not to mint at a 1:1 ratio. The collateralization ratio, defined as the value of collateral divided by the borrowed amount, indicates the risk associated with positions. The minimum required collateralization ratio varies across protocols, but they all operate similarly. If a position’s collateralization ratio falls below the required minimum, the assets associated with that position are sold or liquidated. The methods of liquidation differ: some protocols liquidate through on-chain auctions, some sell at the current market price without an auction, and others utilize AMM pools for sales. Users with a CDP must remain vigilant to safeguard their funds. To close a position, the user must repay the borrowed stablecoin amount along with any accrued interest. One might wonder why someone, like Alice, would lock up and essentially undervalue her assets. Several reasons can explain this. Perhaps Alice owns ETH (or another asset) and, while she doesn’t want to sell them, she needs liquid assets. She might borrow some DAI and later pay back her debt to retrieve her original assets. Alternatively, she might see an opportunity in DeFi, becoming a liquidity provider in an AMM pool using her stablecoins to earn profits, or she might pursue riskier, high-reward strategies. There are numerous motivations behind such actions.</p><p><strong>DAI MakerDAO:</strong> While CDP-backed stablecoins offer more security than their centralized counterparts, they aren’t as scalable. Take DAI, the largest among them, as an example. DAI hit its all-time high with around a 10.3B market supply in February 2022. According to makerburn.com, the maximum supply of DAI, backed by non-stablecoins, peaked at about 5.7B in November 2021. This is significantly lower than USDT’s supply. The disparity isn’t due to MakerDAO being any less secure than Tether (the company behind USDT). The primary constraint is overcollateralization. While overcollateralization strengthens the system’s security, it hampers scalability since minting a $1 asset requires collateral worth more than $1.</p><p><strong>Black Thursday of DAI:</strong> Following “Black Thursday” on March 12, 2020, MakerDAO permitted the minting of 1 DAI in exchange for 1 USDC. This move addressed DAI’s liquidity issues. On that day, ETH’s value plummeted, going from $196 to $101. This dramatic decrease led to a significant spike in network fees. The average gas price exceeded 78 gwei on March 12 and rose further to over 84 gwei on March 13, compared to an average of around 10 gwei prior to that. This surge in fees was primarily due to people rushing to sell their ETH and other assets on various DEXs, while others tried to transfer assets to centralized exchanges. The heightened fees and transaction demands caused network congestion. During this congestion, MakerDAO’s system couldn’t access price information from its oracle. Additionally, ETH’s price drop liquidated numerous positions, leaving many vulnerable. To close or safeguard these positions on MakerDAO, users needed DAI. This increased demand for DAI, causing its price to surge to $1.26. This price hike created an added 26% debt for borrowers. As ETH’s price continued to drop, more positions were liquidated, and due to network congestion, many could not bid on these liquidations. Malicious actors, dubbed “zero bidders,” placed almost null bids and won the auctions, extracting ETH worth $8.32M. To address this, MakerDAO urgently allowed USDC as collateral to mint DAI, facilitating an arbitrage opportunity and increasing DAI’s liquidity, bringing its price closer to $1. As the network congestion resolved, most of MakerDAO’s issues were addressed. However, the aftermath of Black Thursday cost MakerDAO 5.67M DAI. To cover this shortfall, they minted MKR, their governance token, and auctioned it for DAI.</p><p>In early 2021, MakerDAO introduced the Peg Stability Module, enabling users to exchange DAI with USDC and GUSD at a 1:1 ratio. Unlike the CDP Module, users directly swapped their asset for DAI without retaining ownership. This system protected the peg and spurred DAI’s growth. By July 2022, the DAI supply exceeded 7B, but notably, over 85% of it (almost 6B) was backed by stablecoins. The Maker community was concerned about this centralization and the vulnerabilities it introduced. They initiated a transition, replacing stablecoins with Real World Assets (RWA) — primarily T-bills. However, on March 12, 2023, three years after Black Thursday, DAI deviated from its peg, trading around $0.95. This was largely due to USDC’s issues, leading to DAI’s depegging. After USDC regained its peg, DAI stabilized. In response to this event, MakerDAO sped up the collateral conversion process, and by September 14, 2023, only 23% of DAI was backed by stablecoins.</p><p><strong>LUSD — Liquity:</strong> The USDC depegging didn’t solely impact DAI. Liquity’s stablecoin, LUSD, also deviated from its peg around the same time. Interestingly, there was no concrete reason for this. As both DAI and LUSD are backed by CDPs, the market panic that affected DAI influenced perceptions of LUSD. However, since LUSD is exclusively backed by ETH, it quickly regained its peg. This illustrates the market’s sometimes irrational behavior.</p><p>LUSD, like DAI, is backed by CDP positions. Yet, their liquidation processes differ slightly. When the collateral in a CDP position drops in value, Maker initiates an on-chain auction to mitigate losses. This auction involves two stages. The first stage’s objective is to recover the amount lent by the protocol. If a keeper bids an amount equal to or more than the DAI initially minted for the CDP, the second stage begins. The goal here is to retrieve as much of the position owner’s assets as possible. This stage is a reverse auction: keepers bid on accepting a smaller fraction of the collateral in exchange for a fixed amount of DAI that covers the outstanding debt. This entire process spans between 6 and 24 hours, making DAI liquidations relatively inefficient. Enter Liquity, which offers an innovative solution for expedited liquidations. Speedier liquidations mean reduced minimum collateralization ratios. For instance, Maker has three vault types for borrowing DAI using ETH, each with distinct collateralization ratios and interest rates. The ETH-B vault, which has the lowest collateralization threshold, requires a ratio of 130%. Meanwhile, Liquity mandates a mere 110%. But how is this achieved?</p><p>Rather than auctioning liquidated assets, Liquity sells them within a Stability Pool. Unlike AMM pools, this Stability Pool only contains LUSD. Here, the counterpart to Maker’s keepers are the Stability Providers, who supply liquidity to the Stability Pool. When a CDP faces liquidation, the LUSD equivalent to the debt is extracted from the Stability Pool to be burnt, and the collateral gets allocated amongst Stability Providers based on their pool share. Since the base collateralization ratio is 110%, if Stability Providers immediately offload their newly acquired collateral, they secure a 10% premium. Consider this: If the prevailing ETH price is $1150 and Alice borrows 10,000 LUSD by pledging 10 ETH. Should the ETH price drop to $1100, her position would be liquidated via the Stability Pool, meaning the 10,000 LUSD she borrowed would be taken from the pool and eliminated. This collateral would then be divided amongst the Stability Providers. If Bob, for example, has a 10% stake in the Stability Pool, he effectively pays 1,000 LUSD for 1 ETH. Selling this ETH at its current price of $1100, he’d gain a $100 profit.</p><p>Having a Stability Pool for swift liquidations is ingenious. But what happens if it runs out? The system then treats every CDP holder as a Stability Provider. As such, the debt and collateral from liquidated CDPs are spread across all remaining CDPs relative to each user’s share of collateral in the system. For instance, if Alice owns 10% of all collateral, she’d inherit 10% of both the collateral and the debt from any liquidated CDP. She could then earn a 10% profit by selling the acquired collateral for LUSD.</p><p>While it’s feasible to establish a CDP at a 110% collateralization ratio, Liquity has a Recovery Mode to ensure the system’s stability. This mode activates when the overall collateralization ratio (the total value of collateral divided by the total loan amount) dips to 150% or lower. In this mode, new CDPs must have a collateralization ratio of at least 150%. Furthermore, CDPs below this threshold can face liquidation unless the Stability Pool is exhausted. This begins with the riskiest CDP and continues until the system’s overall ratio is back to 150%. Notably, this kind of liquidation doesn’t offload an entire CDP’s collateral. For example, if Alice has the most vulnerable position at 140% and Recovery Mode kicks in (assuming enough LUSD in the Stability Pool to cover her position), then 110/140 of her collateral is sold. She can reclaim the remaining 30/140. Therefore, she only loses 10/140 of her collateral, having borrowed LUSD equivalent to 100/140 and retrieved 30/140 of her collateral.</p><p>Liquity’s model excels with its handling of CDPs, and it has an exceptional feature to safeguard its price: redemptions. Redemptions are a crucial feature that strengthens the LUSD price. Users can redeem $1 worth of ETH for 1 LUSD. The redeemed ETH is sourced from the riskiest position — the one with the lowest collateralization ratio. As a result, the debt of the redeemed positions diminishes proportionate to the redeemed amount. Essentially, a redemption means settling the debt of the riskiest position and claiming its collateral. For a redemption to be worthwhile, the LUSD price must be below $1. This way, Alice can purchase LUSD on the open market and redeem it for ETH. For instance, if the ETH price is $1000 and Bob has the riskiest position, having borrowed 800 LUSD for 1 ETH. If Alice initiates a redemption with 100 LUSD, she essentially covers 100 LUSD of Bob’s debt and claims $100 worth of Bob’s collateral. In this scenario, after the redemption, Alice obtains 0.1 ETH. Bob’s remaining position is 700 LUSD borrowed against 0.9 ETH. To simplify, this example omits the redemption fee. Typically, there’s a flexible fee structure based on the last redemption date and the amount to be redeemed. This structure aims to deter unnecessary redemptions, protecting CDP owners from potential redemption-based attacks. Moreover, Liquity doesn’t have a governance mechanism steered by its founders or investors. It doesn’t possess an admin key, ensuring no one can modify the system’s rules. The smart contract code is entirely immutable. These features position LUSD as a prime example of a resilient and decentralized stablecoin.</p><h3><strong>Algorithmic Stablecoins</strong></h3><p>Unlike other types, algorithmic stablecoins aren’t backed by an asset. Instead, they achieve stability through smart contracts and algorithms. Rather than being directly tied to a reserve of assets, they balance supply and demand.</p><p><strong>UST collapse:</strong> A prime example of this type was TerraUSD, or UST for short. UST’s strength derived from its sister coin, LUNA, which was the Terra Blockchain’s native token. Note that after a certain crash, their names changed to USTC and LUNC respectively. The system’s smart contract allowed for natural arbitrage. A user could mint $1 worth of LUNA by burning a UST and vice versa. This mechanism ensured the peg’s stability. For example, if UST was trading at $0.90, arbitrageurs could buy UST and convert it to $1 worth of LUNA, thus reducing supply and restoring the peg. Conversely, if the peg increased in value, arbitrageurs could buy LUNA, convert it to UST at a profit, and thus increase UST supply, reducing its price. Sounds perfect, doesn’t it?</p><p>However, things took a turn. Both UST and LUNA experienced rapid growth and then a sudden crash. At the start of 2021, LUNA’s price was around $0.65, which soared to $119 by April 2022. Likewise, the total supply of UST increased from about 180 million at the start of 2021 to 18.8 billion by May 2022. To comprehend this, we must discuss some key players.</p><p>First, the Anchor protocol was a lending/borrowing platform for UST, offering around 20% APR to UST lenders. By May 2022, it held 17 billion UST in total value locked (TVL), with UST’s total supply at about 18.8 billion. This meant that 90% of all UST was stored in Anchor to earn 20% APR. However, only 3 billion UST was borrowed from Anchor. It became evident that the interest rates paid by borrowers wouldn’t cover the yields meant for lenders. On March 13th, Bybit predicted that Anchor’s yield reserves would deplete in approximately 13 days, given its current reserves and borrowing/lending rates. Still, the decline didn’t commence with this Bybit assessment.</p><p>The second player, Luna Foundation Guard (LFG), aimed to nurture the Terra Ecosystem by providing grants to new projects. LFG also maintained a reserve to safeguard UST during depegging events, holding assets primarily in Bitcoin, with some in AVAX and LUNA. Now familiar with these actors, we can delve into the crash.</p><p>On the evening of May 7th, Terraform Labs withdrew 150 million UST from the UST-3pool on Curve, which comprises stablecoins like USDC, USDT, and DAI. They intended to relocate these funds to another pool, inadvertently increasing the pool’s volatility. Within an hour, two traders took advantage of this change, selling 185 million UST via the UST-3pool. Terraform Labs then removed another 100 million UST, hoping to realign the UST balance with other stablecoins. However, several transactions had already disrupted UST’s peg by this point. To counteract this, three anonymous UST supporters traded a combined $480 million USDT for UST between May 7th and 9th. On May 9th, LFG liquidated a significant portion of its Bitcoin reserves for UST. But by May 10th, LFG’s reserves were depleted, and UST’s peg was again threatened.</p><p>UST’s main liquidity pool was quickly running low. In the 3pool, the ratio of UST to 3CRV was approaching a 95% to 5% split, a far cry from the ideal 50–50 balance. A final method remained for maintaining value: a UST owner could convert one UST into an equal value of LUNA. This led to a vast amount of UST being burned, resulting in a spike in LUNA’s supply. Consequently, LUNA’s value tanked, its supply reached the trillions, and its price fell to fractions of a penny. Once LUNA’s market capitalization dipped below UST’s, the irreversible harm was clear. Later, investors dumped their assets at constantly lower values, pushing UST’s worth down to just above one cent. In the end, the algorithmic stablecoin collapsed.</p><p>The market cap of UST had seen significant growth, rising from 180M to 18B in just 16 months. This surge was made possible due to the UST-LUNA relationship. However, the continuous minting of UST added to the system’s liabilities. If the only way users could convert assets was from UST to LUNA, the situation would have surely been different. As Terraform labs were the only entity permitted to mint UST, their growth would have been incremental, based on LFG’s funds.</p><p><strong>USDD: </strong>The system underlying USDD changed in a particular manner. USDD was an algorithmic stablecoin that operates on the Tron network. The relationship between TRX, Tron’s native token, and USDD mirrored that of LUNA-UST. However, after the collapse of UST, only Tron DAO members retained the rights to mint and burn USDD. Furthermore, after certain modifications, TRX tokens used to mint USDD are no longer burned. Instead, they are sent to the DAO wallet. This change is questionable. Notably, unlike other DAOs, members of the Tron DAO are not TRX holders but are instead seven blockchain companies. With all that changes USDD is now backed by a reserve held by the Tron DAO, termed the Tron DAO Reserve (TDR). This reserve holds both TRX and BTC, with a collateralization ratio currently around 170%. However, if USDD deviates from its peg, TRX could also lose its value, similar to the LUNA crash. If you exclude TRX from the TDR, the collateralization ratio drops to about 50%, which is alarming. The presence of BTC in the reserve is also contentious. Justin Sun, the founder of the Tron network, is also the owner of Huobi, a centralized exchange. The wallet that Tron DAO claims holds the BTC from the reserve is also claimed by Huobi. This situation is unclear, as it’s uncertain if those assets belong to the reserve or to Huobi’s customers. In my view, USDD stands in stark contrast to LUSD; it’s significantly centralized and lacks robustness.</p><h3><strong>Hybrid Stablecoins</strong></h3><p>So far, we have explored three types of stablecoins: fiat-backed, crypto-backed, and algorithmic. There are hybrid stablecoins that combine elements from these types to create more resilient systems. UXD is such a hybrid stablecoin. While the first version of UXD might be seen as algorithmic, the current version is undeniably hybrid.</p><p><strong>UXD &amp; delta-neutral positions:</strong> UXD operates on the principle of delta-neutral positions. These positions remain unaffected by price fluctuations, making them commonly used in hedging strategies. A classic example of a delta-neutral position involves holding a spot asset while simultaneously holding a short position in perpetual futures. For instance, if you possess 1 spot ETH priced at 1500 USD and you establish a short perpetual futures position for the same amount, your balance remains stable in terms of USD value. If the ETH price jumps from 1500 to 1650, your spot balance would increase by 10%, but your short position would decrease by the same percentage. Thus, the total remains 1650–150 = 1500. If ETH’s price drops, the spot balance’s value declines, but profits from the short position offset this loss. It’s essential to recognize that there’s a fee system, often termed “funding rates,” for maintaining futures positions. Sometimes, short position holders pay long position holders, and other times, the reverse is true. The purpose behind this is to align future prices with spot prices. If the future price surpasses the spot price, those with long positions pay those with short positions. Conversely, if the future price is less than the spot price, those with short positions pay those with long positions. Generally, these payment intervals are set at 8 hours, though this can vary across exchanges.</p><p>The UXD Protocol issues its stablecoin, UXD, using delta-neutral positions. For example, if a user provides the protocol with $500 worth of SOL, the protocol holds onto that and creates a corresponding short perpetual futures position. The protocol then mints 500 UXD to give to the user, ensuring that this 500 UXD is always backed by a delta-neutral position valued at $500.</p><p>While the underlying position’s value remains stable, there are challenges to consider. For instance, scalability is contingent on the trading volume of decentralized exchanges (DEXs). To maintain decentralization, any exchange used to hold short positions must be decentralized. These DEXs must have sufficient volume to ensure that the protocol’s perpetual short positions don’t dominate the market. During significant market downturns or “black swan” events, long position holders may wish to close out. However, these positions are held until users choose to burn their UXD and claim the underlying collateral. If the protocol’s positions dominate the perpetual market, this could lead to a large number of forced liquidations. Another point of consideration is that the system is dependent on the DEXs it uses, which come with inherent risks like potential hacks.</p><p>For several reasons, the UXD Protocol introduced the Asset Liability Management Module (ALMM) on the 21st of September 2021. ALMM permits the minting of UXD by offering USDC, similar to MakerDAO’s Peg Stability Module. The ALMM also facilitates the creation of CDP positions to produce UXD. Additionally, they allocate UXD to various lending platforms and invest in real-world assets (RWA). Through CDPs, loaned assets, and RWAs, they generate revenue that is then used to repurchase their governance tokens.</p><p><strong>Mango Market exploitation:</strong> Three weeks after the ALMM was announced, Mango Markets, which the UXD Protocol utilized, lost assets valued at $116M due to an exploit. The story goes like this: Mango Markets is a decentralized exchange (DEX) with an order book, but it also features a borrowing module. The entire incident took place within minutes, orchestrated through two accounts. With account “A”, the attacker used 5 million USDC to buy 483 million MNGO tokens, subsequently taking a short position on them. With account “B”, the same amount was spent on an identical quantity of MNGO, resulting in a total expenditure of 10 million USDC. This essentially set up a delta-neutral position. The trader then further invested in spot MNGO tokens, pushing its price from a mere 2 cents to an astonishing 91 cents in just ten minutes. This manipulation was feasible due to MNGO’s low trading volume and liquidity. With the value of spot MNGO skyrocketing, nearly $420 million in unrealized gains accrued in the trader’s “B” account. Using this $420M worth of MNGO as collateral, the attacker subsequently withdrew over $116 million from Mango’s liquidity pool.</p><p>Despite this exploit at Mango Markets, the UXD Protocol wasn’t severely impacted and managed to recover their funds post-incident. Even if they hadn’t been able to retrieve the funds, their insurance pool had ample capital to cover the losses. After the event, the UXD Protocol ceased creating delta-neutral positions on Mango. Now, UXD coins are solely backed by ALMM strategies. The UXD Protocol has also announced its expansion into the Ethereum ecosystem through both Arbitrum and Optimism. UXD coins minted on these networks will be supported by delta-neutral positions and other ALMM strategies.</p><p><strong>FRAX &amp; Curve wars: </strong>Another example of a hybrid stablecoin is FRAX. While some view Frax as fully algorithmic, I see its structure as somewhat hybrid. It’s important to recognize that the Frax ecosystem goes beyond just a USD-pegged stablecoin. The ecosystem includes a suite of DeFi tools:</p><ul><li>Fraxbridge: Allows FRAX and FXS tokens to move between chains where FRAX Finance operates.</li><li>Fraxswap: An AMM with a constant product formula.</li><li>Fraxlend: A lending market developed by Frax Finance.</li><li>Frax Ether: A Liquid Staking Derivative (LSD) product for ETH.</li><li>Frax Ferry: A slower, but more secure way to bridge tokens.</li></ul><p>Frax also played a role in the Curve wars, a contest to control Curve. Curve rewards LPs with CRV tokens in addition to trading fees. But not all LPs receive these inflationary CRVs equally. veCRV holders, who lock in their CRV tokens for up to four years to obtain voting rights, determine which pools receive CRV tokens as incentives. Protocols that collaborate with Curve aim to incentivize pools containing their tokens, as increased incentives generally lead to greater liquidity. Thus, several protocols, including Convex, Yearn, Frax, Redacted Cartel, Olympus DAO, and StakeDAO, vied for these CRV tokens. We’ll delve deeper into the Curve Wars when discussing the Curve-Convex structure later in the post.</p><p>Despite these aspects, Frax Finance’s primary aim is the stablecoin. The platform has three distinct stablecoins: FRAX, FPI, and frxETH. FRAX is pegged to the USD. FPI (FRAX Price Index) corresponds to a basket of real-world consumer items, defined by the US CPI-U average. frxETH is pegged to 1 ETH, similar to wETH. Though the foundations of FPI and frxETH are intriguing, our focus here is on the FRAX token.</p><p>FRAX is a fractional-algorithmic stablecoin, meaning it’s partially collateralized. USDC is the collateral used to mint FRAX. Its structure seems to combine elements of the UST-LUNA system and Maker’s Peg Stability Module (PSM). The Collateralization Ratio (CR) is crucial in determining the blend. For example, if the CR is at 100%, to mint 1 FRAX, Alice would require USDC equivalent to 1 dollar. At an 80% CR, Alice needs $0.8 in USDC and FXS worth $0.2. When Alice offers these assets to produce FRAX, USDC tokens are held as a reserve and FXS tokens are burned. The redemption process mirrors this. For a 1 FRAX token, Alice would receive a combination of USDC and freshly minted FXS, totaling $1 based on the current CR. The provided FRAX token is then destroyed. In an extreme scenario where the CR hits 0%, the mechanism mirrors the Terra UST-LUNA system. The crux is the CR value, which shifts algorithmically. If the FRAX token’s value rises, say to $1.04, the smart contract automatically decreases the CR, essentially relaxing the supply. If FRAX’s value dips, the CR rises, bolstering the system. When FRAX was initially introduced, its CR stood at 100%, and then market conditions decided the value.</p><p>The explanation provided above pertains to Frax Finance v1. In v2, Frax Finance introduced a new concept: Algorithmic Market Operations (AMOs). Traditionally, central banks use “Open Market Operations” to mint currency and intervene in the market when necessary, much like the Fed’s actions during the COVID crisis. Frax, in a similar vein, offers flexibility. Anyone can propose an AMO strategy via its governance system. If the strategy proves beneficial to the Frax community, it can be adopted.</p><p>One such strategy involves minting FRAX for a Curve pool to stabilize its value. This is akin to a central bank printing money without backing it with reserves to ensure market equilibrium. Another tactic might be to mint FRAX to boost liquidity on platforms like Compound. If a strategy is financially robust or addresses a particular societal need, FRAX can be minted as needed through an AMO. But, if an AMO results in diminished trust in FRAX (indicated by a decline in its value), the strategy can be automatically reverted based on the established algorithm.</p><p>Previously, Frax Finance was wary regarding the algorithmic support behind FRAX. The lowest CR they accepted was 82%. However, after witnessing challenges encountered by the Luna-Terra ecosystem and other similar crypto projects, they revised their strategy. The Frax team sought to instill greater confidence in users holding FRAX over extended periods. The primary goal was to strengthen FRAX’s financial properties, aiming specifically for a 100% CR. To achieve this, they suggested reinvesting a more significant chunk of the protocol’s profits as it expanded. This would increase the protocol’s assets and eliminate the need for FXS emissions for locked liquidity. Additionally, the protocol’s overseers were permitted to swap up to $3 million of protocol assets for frxETH every month. Consequently, on February 23rd, 2023, a vote cemented the full collateralization of their primary stablecoin, terminating their previous partial collateralization system.</p><p>Setting the CR at 100% diminishes the potential for under-collateralization. However, it does heighten the risks tied to USDC dependency. Recent insights have revealed that the Frax team is devising ways to counter these risks in v3. As of September 2023, no official announcement regarding v3 has been made. But it’s known that with v3, the FRAX token won’t rely on any fiat-backed tokens. Kazemian informed The Defiant, “FRAX v3 possesses a novel approach to managing its off-chain risks, a system never before implemented. Our RWA (Real World Asset) strategy, combined with our exclusive BAMM (Borrow AMM) loans and debt structure, means that continual redemptions of real-world fiat or treasuries aren’t essential to maintain FRAX v3’s stability.” This revelation is indeed intriguing, and I’m keenly anticipating the official declaration. For now, Frax continues to employ USDC through AMOs. Before the DAO’s decision to fix the CR at 100%, the FRAX token was moving on the triangle of stablecoin trilemma. But the question remains: what exactly is the stablecoin trilemma?</p><h3><strong>Stablecoin Trilemma</strong></h3><p>The Stablecoin Trilemma states that a stablecoin cannot simultaneously be decentralized, capital efficient, and maintain a stable price. The design of a stablecoin determines which of these elements it prioritizes and which it lets go. For instance, centralized stablecoins opt for price stability and capital efficiency at the cost of decentralization.</p><p>Now, you might wonder, what does “capital efficiency” mean? Capital efficiency is crucial for a stablecoin’s scalability. A stablecoin is considered capital efficient if the value of the capital required to produce one unit of the stablecoin is less than or equal to $1. For example, to create 1 USDT, you need $1, making USDT capital efficient. However, producing 1 DAI requires more than $1 because of DAI’s overcollateralized design. This means that DAI, along with other CDP-backed stablecoins, is capital inefficient.</p><p>To better understand this concept, let’s visualize the trilemma using the stablecoins we’ve discussed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HlCIk-pC7PSN_VasgxG3JA.jpeg" /></figure><p>As mentioned earlier, centralized stablecoins such as USDT, USDC, BUSD, and TUSD prioritize price stability and capital efficiency. They achieve this because each unit is typically minted in exchange for 1 USD. However, it’s worth noting that their processes might not be fully transparent. CDP-backed stablecoins, on the other hand, are decentralized and maintain price stability, but they lack capital efficiency. Algorithmic stablecoins often face challenges in ensuring price stability.</p><p>FRAX is unique among stablecoins because it’s positioned inside the trilemma triangle. Its design allows it to sit between UST and USDC. This means FRAX can function as a fully algorithmic stablecoin (i.e., CR = 0%) but at the risk of losing its peg. Conversely, it can also be fully centralized (i.e., CR = 100%), thus protecting itself from that risk.</p><p>UXD is another noteworthy stablecoin. It’s both capital efficient and decentralized. However, it grapples with price stability, primarily because it relies on other DEXs to establish a delta-neutral position. If any of these platforms are compromised, UXD’s price could be significantly impacted. A prime example is the Mango Markets exploit. Yet, this isn’t UXD’s sole challenge. Given current market conditions, it’s nearly impossible to scale a stablecoin based on delta-neutral positions. For context, GMX, the largest DEX on Arbitrum that allows users to create perpetual positions, has a total short position value of around $17M. Scaling UXD would require considerably more volume on DEXs.</p><p>In conclusion, there’s no one-size-fits-all solution when it comes to stablecoins. Each has its advantages and drawbacks. Ultimately, users bear the responsibility of deciding which stablecoin best fits their needs. In this post, we’ve touched on the importance of stablecoins, what’s expected from them, and mechanisms that protect their pegs. We also delved into the different types of stablecoins, key players in each category, and noteworthy events in the stablecoin realm. We wrapped up our discussion by examining the stablecoin trilemma, underscoring the point that no stablecoin is without flaws. Stay tuned for our upcoming posts, where we delve deeper into these complex, yet fascinating aspects of the DeFi world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e53976215511" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Comprehensive Deep Dive to AMMs]]></title>
            <link>https://medium.com/@arbnom/navigating-the-defi-landscape-a-comprehensive-deep-dive-to-amms-954020ec23b?source=rss-4f848cc211e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/954020ec23b</guid>
            <category><![CDATA[constant-product]]></category>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[decentralized-finance]]></category>
            <category><![CDATA[amm]]></category>
            <dc:creator><![CDATA[Arbnom]]></dc:creator>
            <pubDate>Thu, 06 Jul 2023 12:53:12 GMT</pubDate>
            <atom:updated>2023-11-10T08:15:29.784Z</atom:updated>
            <content:encoded><![CDATA[<p>This exhaustive Medium post delves into the intricacies of an Automated Market Maker (AMM) pool created with the constant product formula. In our deep dive, we’ll unravel a series of critical aspects, addressing a variety of questions that hold significant relevance to understanding AMMs, their design, and their functionality in the ever-evolving landscape of digital asset exchange. We will address:</p><ol><li>The necessity of AMMs</li><li>What we expect from AMMs</li><li>The formula used to determine the price and the rationale behind it</li><li>How to ensure price consistency</li><li>What is slippage and why does it exist</li><li>How to improve the efficiency of an AMM</li><li>The role of liquidity providers and the nature of LP tokens</li><li>The concept of impermanent loss</li></ol><p>Automated market makers (AMMs) were developed to enable trades to occur anytime we desire. In traditional exchange setups, purchasing asset A with asset B requires finding a trader who wants to exchange asset B for asset A at a mutually agreeable price. However, smart contracts have paved the way for a system that permits trades without the need for a counterparty.</p><p>The core idea revolves around creating a pool containing both assets A and B. Whenever we want to buy asset A in exchange for asset B, the system executes the transaction using a predetermined formula. But how do we settle on the right formula? This formula must adhere to certain rules. For instance, the quantity of assets A and B in the pool should be inversely proportional, implying that purchasing asset A necessitates a corresponding increase in asset B. Additionally, the price and quantity of an asset must be inversely proportional, signifying that if the quantity of an asset diminishes, its value increases. Let’s examine some possible formulas.</p><blockquote>Formula 1: X — Y = K</blockquote><p>Here, <em>X</em> denotes the quantity of asset A in the pool, <em>Y</em> denotes the quantity of asset B in the pool, and K is a constant derived from these quantities. The system enables trades through the pool while keeping K constant. For example, if Alice wishes to buy ‘<em>p</em>’ units of asset A from the pool, the quantity of asset B she has to give, ‘<em>q</em>’, is calculated using the equation <em>(X — p) — (Y + q) = K</em>. This equation implies that <em>q=-p</em>, which is nonsensical because if <em>q</em> is negative, once Alice buys ‘<em>p</em>’ units of asset A from the pool, she would also receive ‘<em>p</em>’ units of asset B from the pool. Thus, we should certainly avoid this formula!</p><blockquote>Formula 2: X + Y = K</blockquote><p>As before, <em>X</em> and <em>Y</em> represent the quantities of assets A and B in the pool, respectively, while K is a constant. The system’s primary objective is to maintain <em>K </em>as constant while <em>X</em> and <em>Y</em> fluctuate. For example, if Alice wants to buy ‘<em>p</em>’ units of asset A from the pool, the quantity of asset B she has to give, <em>‘q’</em>, is calculated using the equation <em>(X — p) + (Y + q) = K</em>. As we can easily see, <em>q</em> has to equal <em>p</em> to maintain the constant <em>K</em>. Let’s say Alice wants to buy 1 ETH from our pool which contains 10 ETH and 10,000 DAI. Since <em>K</em>=10+10,000=10,010=(10–1)+(10,000+<em>q</em>), the amount of DAI she has to give is <em>q</em>=1.</p><p>As we’ve observed, in this formula, ‘<em>p</em>’ (the quantity of taken assets) always equals ‘<em>q</em>’ (the quantity of given assets). However, this approach is inefficient as the price would remain constant, which is not ideal. We require a dynamic pricing system that can adapt to market conditions.</p><blockquote>Formula 3: X * Y = K</blockquote><p>Once again, <em>X</em> and <em>Y</em> denote the quantities of assets A and B in the pool, respectively, and <em>K</em> is a constant. The system’s main goal is to keep <em>K</em> constant while <em>X</em> and <em>Y</em> vary. For example, if Alice desires to buy ‘<em>p</em>’ units of asset A from the pool, the quantity of asset B she has to give, ‘<em>q</em>’, is calculated using the equation <em>(X — p) * (Y + q) = K</em>. Thus, <em>q=(K/X-p)-Y</em>, which is a positive value since <em>X-p&lt;X</em>, implying that <em>K/X-p &gt; K/X = Y</em>. Therefore, we don’t encounter a problem like in <em>Formula 1</em>. Also, the quantity of q per p, i.e., the price, is calculated by <em>q/p=(K/X-p)/p-Y/p=K/(p*(X–p))-Y*(X-p)/p*(X-p)=(K-YX+Yp)/p*(X-p)=Yp/p*(X-p)=Y/X-p</em>. Hence, as <em>p</em> increases, the price also increases. This results in a dynamic system capable of adapting to market conditions and prevents the complete draining of one of the assets from the pool. Thus, this formula meets our needs.</p><p>As we discussed above, the price of a pool depends solely on the amount of the desired asset to be bought and the rates of the assets in the pool. One might wonder how we can ensure price consistency between such a pool and other pools created with the same pairs, as well as with centralized exchanges. The answer is simple: we don’t do anything. However, this doesn’t mean that price fluctuations are inevitable. The key mechanism at work here is arbitrage.</p><p>Arbitrageurs perform arbitrage by buying an asset from a cheaper pool (or exchange) and selling it to a more expensive one. This process has the effect of increasing the price in the cheaper pool by reducing its supply, while simultaneously decreasing the price in the more expensive pool by increasing its supply. By the end of this process, the arbitrageur is guaranteed a profit as a result of their actions.</p><p>From the above discussion, we can infer that <em>Formula 3 </em>could be adopted as the rule of exchange. It’s important to note, however, that this isn’t the only formula that works (see the StableSwap formula of Curve, for example). Let’s take a look at the graph for it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yWHTQ8mT-bHHv4Gv.png" /></figure><p>This is a generic graph for the formula <em>x*y=k</em>, where k is a constant. The <em>x</em> and <em>y</em> axes represent the quantities of tokens A and B, respectively. Upon close observation, it is evident that the correlation between tokens spent and tokens gained is non-linear.</p><p>Hence, if the quantity of tokens spent is doubled, the quantity of tokens gained does not correspondingly double; in fact, the gain is less than twice the original amount. The table below illustrates the substantial increase in the cost per token gained as the pool depletes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jXR1hdGxoOiL1Fox" /></figure><p>The table above demonstrates how the prices change in an ETH/DAI pool, initially set up with 100 ETH and 100,000 DAI. The premium indicated in the table is a natural consequence of the constant product formula and is known as slippage. While slippage can create inefficiencies, it also serves to protect the pool from potential attacks. However, it’s important to note that slippage is directly related to the total liquidity of the pool; greater liquidity results in more efficient swaps.</p><p>For instance, as we saw above, if Alice attempts to buy 5 ETH from a pool that contains 100 ETH and 100,000 DAI, she would face a slippage of 5.26%. But what if she attempted the same swap on a pool that was ten times more liquid, containing 1000 ETH and 1,000,000 DAI? In this scenario, the constant product is 1000*1,000,000 = 1,000,000,000. So, if she wants to buy 5 ETH, she would have to pay (1,000,000,000/995)-1,000,000=5025.13, resulting in a slippage rate of approximately 0.5%.</p><p>As demonstrated above, enhancing the liquidity in the pool leads to more efficient trades. Therefore, we need to devise a method to increase the liquidity of the pool. While we could add more assets at the beginning, a more effective approach would be to encourage individuals to contribute liquidity to the pool. The question then arises: “Why would they do this?” Naturally, they wouldn’t lock up their tokens purely out of goodwill. However, if they see a potentially profitable situation, they might be inclined to do so. To facilitate this, we could introduce a fee mechanism to the pool, where all fees are distributed to liquidity providers (or LPs). Some protocols even distribute their tokens to LPs as an additional incentive. It’s important to note that when Alice adds liquidity to a pool, she must contribute an equal amount of both assets to maintain the balance of the pool. If she only has one of the assets, she would need to sell half of it for the other asset before becoming an LP. Fortunately, many platforms can handle this step on behalf of Alice, enhancing the user experience.</p><p>When Alice becomes an LP of a pool, newly minted LP tokens are sent to her. These tokens represent her share in the pool. For instance, if Alice holds 3% of the pool’s total liquidity, i.e., 3% of both assets in the pool, she possesses 3% of the total circulation of LP tokens. Thus, owning 3% of LP tokens gives her a right to 3% of the fees generated by the pool. It’s worth noting that some protocols operate without an LP token system and distribute fees regularly without any claim process.</p><p>However, LP tokens serve functions beyond claiming fees. They represent the holder’s share in the pool, so transferring them to another address confers the rights of those tokens to the new address. This offers flexibility for the assets in the pool, rather than simply being locked. For example, a user could borrow an asset by using their LP tokens as collateral or stake them in another protocol to earn additional incentives (see Curve-Convex relationship).</p><p>The revenue of Liquidity Providers (LPs) is directly correlated with the volume of the pool. This means that during periods of high trading volume, LPs can reap significant profits. A prime example of this can be observed in the ARB/ETH pool of Uniswap on the Arbitrum network. After the ARB airdrop became available for claiming, people hurried to swap their ARB tokens for ETH. In just three days, one of the ARB/ETH pools processed over $378.5M in volume, and the total fee generated during this period exceeded $1.135M. The screenshot below was taken a day after a position was created on the first day the airdrop was available for claim. A user established a position worth approximately $5k and earned more than $6.3k in fees in a single day.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*diRW6J0QTmZR5X2Z" /></figure><p>Being a Liquidity Provider (LP) might seem like the best gig in the DeFi world, but is it as good as it sounds? Despite the many advantages, being an LP does come with its own risk, known as “impermanent loss”. To understand what impermanent loss is, we need to examine the swap mechanism in an Automated Market Maker (AMM) pool.</p><p>Essentially, when a trader buys Asset A in exchange for Asset B, they take Asset A from the pool and contribute an equivalent value of Asset B. Since LPs provide the liquidity for the pool, one could view this as the trader selling their Asset A to the LPs in exchange for Asset B. If the price of Asset A increases relative to Asset B after this trade, the LPs would have incurred a loss compared to simply holding the same amount of assets instead of providing liquidity.</p><p>Let’s illustrate this with an example. Consider a standard ETH/DAI pool that starts with 90 ETH and 90,000 DAI. Let’s say Alice and Bob each have 10 ETH and 10,000 DAI. Alice decides to add all of her assets to the pool, while Bob holds onto his. Now, imagine someone buys 10 ETH from the pool. They would have to pay 11,111.11 DAI (as per the table above), leaving the pool with 90 ETH and 111,111.11 DAI.</p><p>Alice’s share of the pool is now 9 ETH and 11,111.11 DAI, meaning she effectively sold 1 ETH for 1,111.11 DAI. If the price of ETH were to rise after this point, Alice would make less profit than Bob because she sold one of her ETH. Moreover, as the price of ETH rises, arbitrageurs would continue buying ETH from the pool, decreasing Alice’s ETH balance over time.</p><p>However, this loss isn’t permanent. If the price of ETH falls back to 1,000 DAI, Alice would regain all her ETH, and in the meantime, she would also earn some trading fees. But there is no guarantee that the price of ETH will fall back to its original level. This is the risk that LPs assume.</p><p>In upcoming posts, we will delve into the mathematics behind impermanent loss. Meanwhile, you can utilize tools like <a href="https://www.coingecko.com/en/impermanent-loss-calculator">CoinGecko’s impermanent loss calculator</a> to test strategies for being a Liquidity Provider (LP). Additionally, UniSwap’s version 3 introduces a clever solution to limit impermanent loss, but we’ll explore that in another blog post.</p><p>To summarize, this blog post dissected the anatomy of Automated Market Makers (AMMs), focusing on elements like the constant product rule pioneered by UniSwap (with a future discussion on Curve’s stableswap formula), the LP token mechanism, slippage, and impermanent loss.By better understanding these principles and mechanics, we can navigate the landscape of decentralized finance more effectively, making informed decisions about providing liquidity, managing risk, and optimizing returns. Stay tuned for our upcoming posts, where we delve deeper into these complex, yet fascinating aspects of the DeFi world.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=954020ec23b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>