The Benefits of Stableswap
Stableswap AMMs allow the lifeblood of DeFi – stablecoins – to be traded with minimal price impact. This means that, in a healthy stableswap pool, even large trades do not greatly move asset prices because the stableswap curve concentrates the majority of pool liquidity in the range of expected correlation.
The most obvious beneficiary of stableswap pools is the trader, who receives substantially better pricing. But DEXs, their liquidity providers, and entire Defi ecosystems benefit as well.
- DEXs save on incentives since stableswap liquidity is more efficient than classic, non-concentrated AMM liquidity.
- Liquidity providers are perennially attracted to stableswap pools despite their typically reduced incentives both because they offer a safe haven from impermanent loss and (for stablecoins) market volatility, and also because they can be entered and exited single-sidedly, that is, without having to swap into the pool’s other asset(s). As an added benefit, single-sided exit also allows at least some liquidity to exit the pool even if one of the assets is frozen.
- Defi ecosystems, i.e. not just DEXs but lending apps, strategy vaults, derivatives protocols, and their users, enjoy access to cheaper, more effective stablecoin liquidity. In turn, protocols are able to offer better pricing without having to spend as much on incentives, a virtuous circle that benefits all participants.
A further potential ecosystem benefit is that, in addition to handling stablecoins, stableswap also allows quasi-pegged assets like liquid staking derivatives to be traded with their corresponding native assets with similar efficiency. This increased ease of trading boosts the appeal of an asset class already attractive to investors in its ability to rehypothecate the value locked into staking tokens.
Though its benefits are real, liquid staking remains controversial. There is serious concern that encouraging users to circumvent staking token unbonding periods by depositing their ETH or ATOM in exchange for stETH or stATOM will centralize blockchains with liquid staking custodians and their preferred validators, undermining the very foundation of proof-of-stake security. Indeed, Osmosis Labs developed superfluid staking as an alternative to liquid staking. Superfluid lets users actually stake the staking tokens underlying their bonded LP positions. These reverse liquid staked assets, so to speak, thus help to secure the network while still participating in Defi, making superfluid a more secure, decentralized form of rehypothecation than liquid staking derivatives.
However, while superfluid staking is popular on Osmosis, it has not yet been adopted by other Cosmos ecosystem protocols. And with the recent arrival of liquid staking to the Cosmos ecosystem, it would be Canutish to deny users the ability to permissionlessly trade an asset class that has been extremely popular on Ethereum. With stableswap, as with other mechanisms on Osmosis and similarly decentralized ecosystems, the developers are building the playground, while governance sets the rules, and users decide how they want to play. Persuasion about the viability of alternative approaches takes place in the market and in the public square.
Osmosis Stableswap in Context
Classic AMMs like Uniswap v2 use the x * y = k (const in the graph below) constant-product market-maker curve. CPMMs hold a substantial amount of liquidity toward the ends of their curves, allowing for trades of virtually any size. However, in normal conditions, this tail-end liquidity tends to be less useful, and it thins out the liquidity in the middle of the curve, causing increased price impact.
Stableswap curves, first developed by Curve Finance’s Michael Egorov in 2019, are able to flatten this curve out toward a 1/1 constant price because the two assets are expected to stay closely correlated within a tight range of the curve. This results in much more liquidity in the middle of the curve, allowing trades of great size to occur with minimal price impact, while still maintaining sufficient price elasticity to account for regular volatility.
From the Curve Whitepaper
If Osmosis Labs had simply implemented Curve Finance's invariant, as many other DEXs have done, stableswap’s most important feature, its semi-concentrated liquidity and minimized-price-impact trading, would have been roughly equivalent to what they will be with the new Osmosis stableswap curve.
However, copying Curve would not have been in the spirit of the lab, and building a new stableswap from scratch has produced three significant advantages.
- Osmosis stableswap is more computationally efficient because of the curve itself and because of the newly written solving algorithms (described at a high level below).
- The design process has given developers a deeper familiarity with the code. Moreover, the entire AMM codebase has been generalized as part of the v13 upgrade, something that would have been harder and less fulfilling to accomplish with a foreign curve. Both generalization and developer familiarity make the entire codebase more testable and auditable going forward, promoting long-term code hygiene and quality assurance as the Osmosis DEX ecosystem expands.
- Building a new stableswap enabled “scaling factors” to be included. These allow for tokens with different precisions (e.g. 1 ATOM is 1 million uATOM (106, while 1 ETH is 1018 Wei) to be properly converted for the pool math. A different application of scaling factors enables the expected price of the curve to drift programmatically in order to account for the gradual accrual of value within a liquid staking derivative. For example, as stATOM collects its underlying ATOM staking rewards and distributes them to the token, 1 stATOM should (barring perceived peg risk) start to be worth 1.01 ATOM, then 1.02 ATOM, and so on. The scaling factor can take this predictably shifting peg into account.
Technical Features in Brief
Osmosis stableswap is built using a generalization of Andre Cronje’s (abandoned and open-sourced) Solidly curve, which works similarly to Curve’s stableswap invariant in the chart above, but with a more elegant equation:f(x, y) = xy(x^2 + y^2) = k.
Having a simpler equation allows for the more efficient on-chain computation of prices, swaps, tokens in/out, and so forth. Those who have suffered the gas fees on Curve understand how much they eat into stableswap’s price impact savings, particularly for smaller trades. Gas efficiency is less immediately important on Osmosis, since it is a sovereign, interoperating appchain without the bloat of a fat protocol, but as its trading suite expands and transaction volume increases, this sort of computational efficiency will continue to keep transaction fees low.
The streamlined nature of the new curve does not mean that writing the stableswap code was simply a matter of plugging it into the existing AMM code. First, the curve equation had to be generalized to include multiple pooled assets, which will allow for the creation of stablecoin tri-pools (or quad-pools, etc.). This generalization complicates the curve from f(x, y) = xy(x^2 + y^2) = k to f(a1,...an) = a1*...*an(a1^2+...+an^2) = k, for an indefinite number of assets (a) from a1 to an.
Even when only reasoning about 2 assets in the pool at a time, as is true for most transactions (e.g. swapping from one token to another), solving the equation directly can become quite computationally expensive, since it would involve crunching multiple cubic roots per transaction.
Instead, the developers had to find the best means of approximating transaction solutions to an appropriate level of precision by iteratively guessing and checking. This is known as a convex optimization “solver,” an algorithm that lives in the blockchain code. Many generic solvers exist, but Osmosis Labs wrote its own in order to get the best mix of speed, precision, and computational efficiency.
The math of all this gets quite complex.
These details and more can be found in the technical write-up.
With the work on the curve and the solving algorithm complete, all that math still had to be converted to working, error-free code, with appropriate rounding and precision rules, for example, so that the pools can never violate safety by making a wrong transaction, but only liveness, by causing an otherwise buggy transaction to fail.
As mentioned above, the developers retrofitted the AMM codebase such that both stableswap and non-stableswap pools could be included in the same testing framework. Many new testing features, such as mutation and fuzz tests were added to the usual battery of unit tests after the June exploit. Unlike many feature updates in a fast-moving industry, Osmosis stableswap is erasing rather than adding technical debt to the protocol, allowing future development to occur with greater speed and safety.
The Osmosis Stablecoin Playground
From the Axelar Explorer
Stablecoin liquidity on Osmosis has been rejuvenated in the months since the Terra collapse, and while it has not returned to the heights of the bull-market, UST-only days, it has continued to grow, this time upon a firmer foundation. As various bridging solutions have come online, including Axelar and Gravity Bridge, Ethereum-based stablecoin liquidity has poured into Cosmos. This continually increasing adoption in the depths of the bear suggests that the new Osmosis stableswap pools will get a great deal of use, especially as the Osmosis and Cosmos ecosystems mature.
The composition of stablecoin liquidity on Osmosis will continue to change as it grows. What path this growth takes will primarily be driven by the stablecoin projects themselves, as well as the bridges that mint synthetic stablecoins. Each protocol wants its assets to win, and the place to compete for Cosmos market share is on Osmosis.
In the near-term, there will likely be multiple winners in different categories. The centralized issuers will continue to dominate unless and until a viable decentralized coin starts to win at scale. Among decentralized coins, there are many models. With respect to backing, there are the various flavors of on-chain collateralized coins (DAI, IST, USK, IOU), algo-stables (unlikely to be out of favor forever), as well as the semi-algorithmic FRAX. And with respect to what peg (if any) to hold, there are many theories. So far, non-dollar-pegged stables have constituted only a niche market. World currencies, especially, have not yet seen much adoption. More ambitious is the floating peg model of RAI, since it sets out in the steps of Bitcoin to be the money of the internet. While Bitcoin is almost fully digital gold at this point, it could make a comeback as a native electronic currency. And it would be unwise to discount Doge, the (still cheap!) coin that makes everyone smile.
There are several tools available or in development on Osmosis that teams can use to advance their stable asset projects. The first and primary method is by funding external incentive gauges, popular in regular Osmosis pools since the early days of the DEX. Additionally, a module called the “Transmuter” is being developed to allow free one-to-one swaps between stablecoins. When this goes live, an external team will be able to fill an instance of the Transmuter with its own stablecoin and set it to accept whichever stablecoins it is willing to accept in return. For example, when Circle launches natively in Cosmos Q1 2023, it could load a Transmuter with native USDC and set it to accept axlUSDC, gravDAI, IST, and whatever other stablecoins it wants. Users could then deposit the accepted stablecoins and receive native USDC one-to-one.
Creating tripools (similar to Curve’s 3pool), quadpools, and more will be permissionless, but DAO governance will likely find it most efficient to incentivize one main multi-asset pool with OSMO. Naturally, as the ecosystem begins to converge around the most popular stables, the assets in the pool might change (or liquidity would follow OSMO incentives to a new pool).
Beyond establishing one main pool for deep stablecoin liquidity, choosing an initial tripool for incentives would also allow the Osmosis DAO to create its own version of 3Crv, the fungifying LP token that represents a claim on Curve Finance’s 3pool of DAI, USDC, and USDT, and which is then itself used as a paired asset against other stables. This 3osmo token (however named) could help stabilize the stables, and might perhaps become the meta-stable of the interchain.
No one knows who will ultimately be crowned king of the Osmosis stablecoin playground. It will come down to a number of factors: the coin’s usefulness in Osmosis and Cosmos Defi, its perceived stability versus its risk (a matter as much of popularity as of design and code). The winner’s incentives model will likely have to incentivize enough to attract somewhat mercenary capital, while not offering, say, the insane returns of Terra’s Anchor protocol. And, of course, the ever-changing regulatory environment is a wildcard lurking beneath the playground slide, a constant threat to upend the rules of the game.
Whichever of the various stablecoins and liquid staking derivatives carry the day, it will be a win for the Osmosis and interchain ecosystems. Trading will be better, providing liquidity will be better, and interchain DeFi will run more smoothly and with greater capital efficiency. And not just in Cosmos! As more ecosystems connect to IBC and as non-IBC bridges adopt safer strategies like rate limiting, apps in other ecosystems can use Osmosis stableswap as well, tapping into the power of sovereign, interoperating appchains to provide inexpensive cross-chain swaps over IBC.
Interchain Defi summer is coming, made possible by the relentless advance of interchain infrastructure and fueled by stable asset liquidity. The smooth engine at the heart of it all will be Osmosis stableswap.