Think 10X Bigger: dYdX Enters the Cosmos
A qualitative analysis of dYdX's decision to deploy v4 as a Cosmos app-chain instead of on StarkEx's L2.
L2 maxis are mad. dYdX, the largest DeFi derivatives platform, is moving from the ETH L2 StarkEx to Cosmos.
Historically, dYdX has been a first mover, willing to deploy on new platforms in search of making the best product possible. Back in 2021, the protocol was among the first to move from ETH mainnet to L2, with the deployment of its cross-margined perpetual swap product on StarkEx. Now, it’s moving again.
Does the decision mean that L2s aren’t all that they are cracked up to be? Is the app-specific chain model that Cosmos is embracing the future of crypto? Or are there other reasons behind the move?
Let’s take a deep dive into dYdX and the rationale behind this decision. If you are familiar with the protocol, skip to Part 4 — dYdX App-Chain for an analysis of the move. Hint — it has a lot to do with regulation and value accrual.
Part 1 — The Vision
“I want to build one of the biggest exchanges in crypto.”
Antonio Juliano, founder of dYdX, has lofty goals. He won’t be satisfied climbing to the top of the DEX rankings — he has his sights set on displacing CEXs, household names like Binance and FTX, as the #1 exchange in crypto.
Antonio’s vision is anchored around two predictions:
DEX’s will ultimately win out over CEX’s
Winning the derivatives market is paramount
Most people in crypto will view the first point as a matter of time. The second point is obvious when you look at the TradFi market. Estimates put the global derivatives market at 10X the size of the spot market.
Derivatives volumes already eclipse spot volumes on centralized exchanges. In June 2022, derivatives volumes were $2.75tn (66.1% of the total crypto market) while total spot volumes were $1.41tn.
On DEXs, derivatives volume is less than half the spot market volume ($84.6B in June) but has been gaining market share quickly. The AMM model, which has had tremendous success in creating liquid on-chain spot markets, has not been applied to derivatives markets with much success.
The depth of liquidity required to facilitate derivatives trading is difficult to bootstrap on decentralized exchanges, which have historically suffered from slow transaction settlement times and high fees. Scaling infrastructure and more efficient pricing models, however, promise a bright future for decentralized, liquid derivatives markets. Led by dYdX and its off-chain order book model, derivative volumes have started to close in on spot volumes.
Unlike the TradFi market, perpetuals dominate crypto derivatives volume. 24-hour volume for perpetuals stands at 20X futures volumes, across centralized and decentralized exchanges. The dominance of perpetuals in DeFi is even more dramatic. Since these synthetic assets have no expiration date, on-chain liquidity is less fragmented than futures or options.
As the popularity of perpetuals rises and pricing models proliferate, we will likely see the DeFi derivatives market eclipse the spot market in the coming years. The exchange that wins this race is poised to dominate DEX market share.
Part 2 — Current State of dYdX (v3)
Brief History
dYdX Protocol is a derivatives exchange on the L2 StarkEx network that offers non-custodial perpetual swaps, which are margin products that provide synthetic exposure to underlying assets. Founded in 2017 by ex-Coinbase engineer, Antoino Juliano, the protocol’s first two products, Expo and Solo, were built for margin trading on Ethereum. After the tremendous success of Bitmex, dYdX pivoted to perpetuals trading.
In February of 2021, dYdX partnered with StarkWare to launch an L2 protocol for cross-margined perpetuals, which massively increased its execution capacity and led to its dominance of the DeFi derivatives market. Currently, dYdX accounts for ~90% of decentralized perpetuals trading volume, with a daily average volume of $1.3B. Competitors GMX and Perpetual Protocol account for $152.5M and $21.6M respectively.
Across all exchanges, dYdX’s trading volume is second only to Uniswap, with a 30-day cumulative volume of $37.7B vs Uniswap’s $42.7B.
Funding
dYdX has raised 4 rounds of funding, most recently raising $65M in a Series C round led by Paradigm. Funding totals $87M across rounds.
Other investors include Polychain Capital, a16Z, and Wintermute, one of the largest liquidity providers on dYdX. StarkWare joined as both an investor and a partner, playing a critical role in the development and operation of v3 of the protocol.
Token
In September of 2021, dYdX launched a governance token, DYDX. 1B tokens have been minted and will be allocated over a 5-year period.
27.7% of the tokens are designated for investors, 15.3% for existing employees, 7% for future employees and 50% for users.
Over the 5-year period, 50% will be distributed through a reward mechanism for staking, liquidity provision, retrospective milestone completion, and trading on the platform. These rewards will become liquid every 28 days.
Issuance will rise sharply in Q1 2023, driven largely by investor and employee vesting unlocks.
After 5-years, issuance will end and token holders will be able to propose an increase in DYDX token supply through governance. The perpetual inflation rate for this proposal is capped at 2% per year, meaning that there is a fixed maximum for the arbitrary inflation adopted by dYdX governance.
Governance
The DYDX token grants holders the right to propose and vote on changes to the protocol. Governance is discussed on the governance forums at forums.dydx.community. The process involves the following steps:
STEP 1 — Forum Discussions, DRC Creation (Off-Chain), and DRC Feedback
Off-chain dYdX Request for Comments (DRCs) creation is the first formal step in the governance improvement process. Anyone can participate in the Governance Forum, create DRCs, and discuss improvements.
STEP 2 — DRC Snapshot Polling (Off-Chain)
After the community achieves a rough consensus, a community member with 10K DYDX can create an off-chain vote for the DRC on Snapshot. The voting period is 5 days in length and voting starts after a 1 day voting delay. To pass, DRC votes must satisfy the following thresholds:
Minimum quorum — at least 1M DYDX/stkDYDX
Minimum vote differential — at least 67% of votes must be in favor of the proposal
STEP 3 — DIP Creation (On-chain)
After DRCs reach quorum, a community member can submit an on-chain dYdX Improvement Proposal (DIP). There are four types of proposals with different parameters which affect the length and execution of a proposal.
Short timelock executor — changes to incentive contracts, token minting, proxy contracts, guardian roles, treasury funds
Starkware priority timelock executor — changes to the configuration of the dYdX exchange
Long timelock executor — changes to governance consensus
Merkle-pauser executor — freezes the Merkle root (which stores user’s reward balances) in case that the proposed root is incorrect or malicious
Depending on type, proposal thresholds range from 0.5–2.0% of total supply. Minimum thresholds range from 1.0–10% of total supply. Long timelock proposals, which are required to change governance rules, require the highest thresholds.
After a DIP has passed, any address can call the queue method to move the proposal into the timelock queue.
Product Offering
Perpetuals
dYdX currently offers perpetuals on ~38 assets using an order book model and a single, cross-margin collateral (USDC).
What are perpetuals?
Perpetual swap contracts, like futures contracts, allow traders to buy or sell the value of an asset without holding the asset. These derivatives provide synthetic exposure to the underlying asset and require a collateral asset to net gains and losses against.
These derivatives are most similar to futures contracts, with a few key differences:
No expiry or settlement
Charges or pays a funding rate
Futures often trade at premiums or discounts to the underlying asset — this price difference is referred to as the futures basis and reflects the market’s forward-looking view of the underlying price at expiry. Futures do not require a price anchoring mechanism due to the expiration date. At expiry, futures and cash prices converge and traders must reopen long or short positions to maintain exposure, realizing loss or gains.
Since perpetual swaps have no expiration date, exchanges implement funding rates to anchor the price by balancing the demand for long and short positions. The funding rate is dynamically adjusted by the protocol in response to market demand. For example, when the funding rate is positive it means long position holders pay to fund short positions. This incentivizes users to take up the short side of the trade, effectively balancing demand for both sides.
In practice, this funding rate means that perpetuals mimic margin-based spot markets and hence trade closely to the underlying asset price.
Let’s take a look at the dYdX’s ETH-USD perpetual contract:
Immediately, you see that there are three contract prices: the mid-market price (largest, unlabeled), the index price and the oracle price.
The mid-market price is determined by the midpoint or average between the lowest ask (sell price) and highest bid (buy price) on the orderbook. If you submit a market order, this price will be closest to your execution price.
The index price is an aggregate price based on price data from multiple exchanges and is used to trigger stop orders. To provide optimal performance, the index price is managed off-chain to ensure minimal delay and slippage in stop order triggering.
The oracle price is also an aggregate price calculated using multiple on-chain price oracles. Collateralization and liquidations on dYdX are determined using the oracle prices of each asset.
For simplicity, the mid-market price is roughly your execution price (where you would open a position) and the index price is the price of the underlying asset. Both index and oracle prices are routed via Chainlink and Maker oracles.
The funding rate is calculated algorithmically based on the index price and sampled mid-market prices for the perpetual. As you can see, the mid-market price ($1,693.7) trades at a premium to the index price ($1,693.1) which results in a positive funding rate (longs pay shorts).
Funding payments are made in USDC and automatically credited or debited at the start of each hour. The dYdX funding rate is represented as a 1-hour rate, which represents the return a position may expect to earn or pay every hour. Occasionally, mid-market prices may be offered at discounts to index markets with a positive funding rate, due to timing.
Collateral
All perpetuals are settled and collateralized in USDC. Since dYdX only offers perpetuals (not spot), the only asset required to open positions is USDC. Cross-margining is used by default, meaning an account can open multiple positions that share the same collateral.
The margin requirement for a single position is calculated as follows:
Initial Margin Requirement = abs (S × P × I)
Maintenance Margin Requirement = abs (S × P × M)
S is the size of the position (positive if long, negative if short), P is the oracle price for the market, I is the initial margin fraction for the market, and M is the maintenance margin fraction for the market.
Let’s look at an example using the ETH-USD contract above.
Contract specifications show an I of 5% and an M of 3%. If a trader wants to go long 1 ETH-USD contract at $1,700, they need to deposit $85 (1 x 1,700 x 5%). The maintenance margin is $51, so at $1,666 they are liquidated. Similar to other protocols, liquidations are performed by bots which receive a liquidation fee (1%).
Staking
dYdX offers two staking pools, a Liquidity Pool (USDC) and a Safety Pool (DYDX).
2.50% of the initial token supply will be distributed to users staking USDC to the Liquidity Pool. Community-approved LPs can use the staked USDC to make markets on the dYdX, increasing the liquidity available across markets.
2.50% of the initial token supply will be distributed to users staking DYDX to the Safety Pool. The Safety Pool acts as a decentralized fund to be used in the case of insolvency or other shortfall event. In these scenarios, token holder balances can be slashed and transferred to another address or contract. A governance vote is required to identify a shortfall event and use pool funds to mitigate the deficit.
In return for depositing into the Safety Pool, DYDX stakers receive a liquid version of their position, stkDYDX, which carries the same governance rights as DYDX.
Liquidity Provider Rewards
7.5% of the initial token supply will be distributed to liquidity providers. dYdX’s orderbook model relies on professional market makers who actively quote two-sided markets on the exchange. LP rewards are based on a formula rewarding a combination of uptime, two-sided depth, bid-ask spreads, and the number of markets supported.
Any Ethereum address can earn these rewards, subject to a minimum maker volume threshold of 0.25% of maker volume in the preceding epoch.
Part 3 — Protocol Design (v3)
Central Limit Order Book Model
dYdX leverages a central limit order book (CLOB) model to price and match trades. Popular amongst CEXs, this pricing model has historically been too costly to run on-chain. However, it offers a number of benefits over the AMM model, which is widely used amongst spot exchanges.
In AMM models, users trade in and out of a liquidity pool that sets token prices based on the changing ratio of tokens supplied. Since trading perpetuals does not require the underlying collateral, AMM-based derivatives exchanges use virtual liquidity pools (vAMMs) that leverage the same popular x*y=k constant product formula. As the name suggests, there is no real asset pool (k) stored inside the vAMM itself. Users deposit collateral in a smart contract vault and trade in and out of these pools, with prices algorithmically adjusting based on supply and demand.
CLOBs are widely considered superior pricing models because they eliminate slippage and more efficiently allow advanced order types. dYdX’s CLOB has two market participants: Makers and Takers:
Makers provide orders at prices that are not currently available on the order book
Takers accepts orders currently on the order book
When a Taker accepts a price, the positions are matched and opened for both sides. As you can imagine, these models require significant liquidity at various prices to facilitate a seamless trading experience. dYdX charges lower fees for Maker orders to encourage users to open limit orders on the order book.
dYdX also approves market makers to use the Liquidity Pool to offer Maker orders and increase order book depth.
dYdX’s order book model allows for more advanced order types compared to the AMM-based platforms. Market orders, limit orders, stop-loss orders, and trailing stop orders are all available in addition to order options of Good-Till-Date, Fill Or Kill, or Post-Only.
Off-Chain Matching Engine
The order book model allows dYdX to offer a comparable trading experience to CEXs. If this model is so superior, why isn’t it widely used in DeFi?
CLOBs require significant order book depth to facilitate trading. Storing these open orders on-chain is prohibitively expensive, even on more scalable L2s. For this reason, dYdX uses a centralized off-chain matching engine, which stores and matches orders, that runs on AWS.
Currently, the matching engine receives and processes ~1,000 orders per second. The hybrid design allows near-instant trade matching of volumes far greater than on-chain solutions (even L2s) can support.
When matched, these trades are sent to the StarkEx ZK-rollup, which we discuss in the next section.
StarkEx L2 Execution
StarkWare operates the StarkEx ZK-rollup which executes and settles dYdX trades. The StarkEx rollup enables lower minimum order size, reduced trading fees, and increased throughput relative to Ethereum L1.
As you can see below, users’ signed trades are matched on the exchange, which is dYdX’s off-chain matching engine. When trades are matched, they are sent to the StarkEx Cloud to be verified and batched. The STARK Prover creates a ZK-proof, which cryptographically proves valid execution of the batch of trades, and submits this proof to the STARK Verifier, which is a smart contract on Ethereum that validates the proof.
StarkEx periodically submits state updates, which include balance changes, to the StarkEx Contract on Ethereum. These state updates allow the L1 to know the current account balances of the L2, which is critical for withdrawing to the mainnet.
dYdX currently executes 10 TPS on StarkEx. For comparison, the entire Ethereum blockchain processes ~15 TPS.
Part 4 — dYdX App-Chain (v4)
dYdX’s hybrid design has allowed it to offer a professional trading experience that rivals centralized exchanges. Despite its dominance of the derivatives space, dYdX announced this June that v4 of the protocol will be deployed on dYdX chain, an app-specific chain in the Cosmos ecosystem.
So, why is dYdX moving to Cosmos?
“We believe it gives us the chance to develop the best possible product.”
I have combed through tweets, blogs, and podcasts and this quote is repeated ad nauseum by Antonio. He offers his definition of the best possible product below:
Antonio’s assessment of dYdX’s current product offering is as follows. Currently, dYdX offers UX on par with CEXs. Try it yourself — the protocol feels sleek and fast with near-instant trade confirmations and gasless transactions.
The features — cross-margin collateral, 25x leverage, advanced trade types — put dYdX close to, but not yet on par with, CEXs. Additional derivative products, like futures and options, are needed to close the gap.
Security is not an apples-to-apples comparison, but is considered top-notch.
Decentralization is where dYdX falls short. The move to a Cosmos app-chain will fulfill dYdX’s goal of full decentralization, while providing a means to achieve other, more nuanced reasons.
Let’s take a look at them in order: 1) Sovereignty, 2) Decentralization, 3) Regulatory Protection, and 4) Value Accrual.
1) Sovereignty
Sovereignty is the means to achieve reasons #2–4 above. As a standalone app-chain, dYdX will be the only application that runs on the dYdX chain, which means that all design choices can be optimized for the protocol.
dYdX Chain Design
Cosmos SDK and Tendermint Consensus
Similar to other Cosmos chains, dYdX will leverage Cosmos SDK and Tendermint Consensus to develop and run the chain.
Tendermint Consensus pseudo-randomly (based on stake) selects validators to propose blocks. Validators vote (and sign) on proposed blocks until a supermajority (2/3 of the validator set votes) is achieved. As opposed to Ethereum, the consensus mechanism prioritizes consistency over availability, which means that blocks can only progress if a supermajority is achieved. While that means that the network can halt if 1/3 of the validator set goes offline, the design results in near-instant finality (1 second) since the network agrees on a decision with absolute certainty. Tendermint has an estimated TPS limit of 10,000, which declines as the number of validators increases due to messaging latency. In comparison to the StarkEx rollup, the app-chain will reach similar, if not higher, execution speeds depending on the number of validators.
While execution capacity may be comparable, the decentralized network of validators will introduce more latency (due to transaction propagation) than StarkEx’s single sequencer model. Fortunately, Tendermint offers dYdX significant flexibility in design and implementation. dYdX is exploring ways to reduce latency by optimistically sending transactions to the next block producer (Tendermint leader schedule is known) to avoid the need to propagate transactions through the entire network.
dYdX chain will launch with 50–100 validators. Native token holders will stake tokens with validators in exchange for a portion of the validator rewards. The inflation schedule has not been revealed and the native token, presumably DYDX, will be determined by the community.
In-Memory Order Book
Remember the centralized off-chain order book? Validators on dYdX chain will run an in-memory orderbook that is never committed to consensus (i.e. off-chain similar to the existing design).
Orders placed and cancellations will be propagated through the network similar to normal blockchain transactions. To increase throughput, orderbooks can be inconsistent from validator to validator depending on propagation speed but will eventually achieve consistency.
On a real time basis, orders will be matched together by the network. The resulting trades are then committed on-chain each block. Antonio estimates that the in-memory orderbook will provide a similar UX experience as the centralized version. Similar to the existing protocol, traders will not pay gas fees to place orders, but rather pay fees based on trades executed.
But what about MEV? The validators, similar to StarkWare sequencers, can extract MEV from the network and degrade the user experience. The sovereignty of the app-chain decision allows dYdX to develop creative methods to mitigate the negative effects of MEV, which are impossible to implement currently.
Since dYdX will be the only protocol on the chain, validators will presumably have a vested interest in creating a good user experience. If that is not sufficient motivation, dYdX is considering tracking individual validator execution prices relative to the median execution price at given times. Stakers can unstake from validators that are clearly front running trades and restake to validators with cleaner records.
While these implementations are hypotheses, the flexibility that sovereignty offers cannot be overstated.
2) Decentralization
What does this sovereignty achieve? You guessed it — decentralization.
Currently, the centralized off-chain matching engine is a black box. The StarkEx rollup is run by a single, StarkWare sequencer that orders and executes transactions. These centralized components result in a protocol that fails to protect against censorship resistance, a critical feature of decentralized exchanges. The orderbook can choose to remove users’ orders. The sequencer can censor or reorder transactions to extract MEV, resulting in worse execution prices for users.
While decentralized sequencers are expected for L2s down the line, the move to a Cosmos app-chain solves both of these issues immediately. The decentralized, in-memory orderbook prevents censorship resistance at the orderbook level. Similarly, the decentralized block production is a significant improvement over the single sequencer execution that StarkEx offers.
As dYdX decentralizes, community governance will assume responsibility for the entire protocol. Unfortunately, concrete details on how the governance process will change is unclear. The community will vote on the native token for the dYdX chain, which will presumably be DYDX. Governance will likely transition to Cosmos but may remain on Ethereum for a period of time, during which voting would occur Ethereum and be reflected on Cosmos.
3) Regulatory Protection
In addition to censorship resistance, what else does decentralization achieve? Regulatory protection.
dYdX has a track record of prioritizing regulatory compliance. The protocol is not available to US traders due to stringent regulatory requirements on derivatives exchanges.
While the US currently has no regulation in place that provides a formal definition of decentralization or the legal implications of satisfying that definition, various legal papers and proposals have largely concluded that sufficiently decentralized networks should be exempted from security registration as defined by the Securities Act of 1933. In fact, decentralized organizations may not fall under the purview of any single jurisdiction and therefore may not need to be regulated.
Take the above with a grain of salt. Regulation is likely in the works and clarity on the matter is not currently available. However, with 100s of validators running the network, dYdX may be able to claim sufficient decentralization to compliantly offer derivatives trading in the US.
Currently, dYdX is the leading choice for institutional investors to trade on-chain. The UX and product design choices — which mimic a professional trading experience — are specifically designed to attract experienced traders. US institutions are a massive untapped market that dYdX hopes to attract if decentralization allows the protocol to circumvent jurisdictional regulations.
4) Value Accrual
Decentralizing the protocol would not only attract volume from restricted regions, but allow dYdX to start passing revenue streams to token holders.
Currently, dYdX generates revenue through the maker-taker fee structure. 30-day and 365-day trailing revenue stands at $28M and $497M, respectively, trailing only Uniswap amongst decentralized exchanges.
This revenue stream is owned by dYdX Trading Inc. Due to the protocol’s centralized components, the company cannot pass this revenue to token holders without risking security designation. The token, of which 50% of the supply is owned by investors and employees, has not performed well after ICO, largely due to a lack of value accrual.
Value accrual is required for dYdX to achieve a viable, long-term business model. dYdX relies heavily on professional market makers that earn LP rewards by providing two-sided markets on the exchange. Sustainable tokenomics are necessary to maintain these rewards that are critical to the liquidity and orderbook depth of the exchange.
By decentralizing the protocol, dYdX can compliantly pass revenue to token holders, increasing value accrual and creating evergreen incentives for market makers. Tokenomics will be further supported by validator supply lockup and a baseline demand for transacting in the native, app-chain token.
These changes pave the way for dYdX to become a self-sufficient, fully decentralized protocol.
Part 5 — The Risks
Despite the expected benefits, the move is certainly risky. Let’s take a look at a few of the risks.
Implementation
The team has to build A LOT. The base level blockchain, chain modules, in-memory orderbook, oracle network, bridges, an indexer, a website, a mobile app…
As a standalone chain, dYdX can no longer reap the benefits of Ethereum’s established infrastructure. For example, dYdX will have to build an indexer from the ground up, which reformats raw blockchain data and serves it to API endpoints on websites and applications in consumable formats.
dYdX has an ambitious timeline of open sourcing the design by the end of 2022. Building everything from scratch, auditing the code, and deploying in that timeframe will be extremely difficult.
Onboarding
dYdX plans to maintain v3 of the protocol on StarkEx through the app-chain launch. The protocol will not automatically migrate liquidity to the new chain. Instead, it will rely on users to bridge over to the new network.
Secure bridging is a major concern. Fortunately, the Cosmos network provides the most secure bridging infrastructure, IBC, which natively integrates with all app-chains. Additionally, dYdX only requires a single, trusted collateral (currently USDC) to facilitate trading, so users will not have to bridge other assets.
dYdX will prioritize onboarding the following user groups, in order:
Transfers from/to CEXs
Transfers from/to Ethereum
Transfers from/to other chains / rollups
dYdX is not terribly concerned with migrating all existing liquidity from StarkEx. dYdX wants to take market share from CEXs — their onboarding priorities and decision to forgo a liquidity migration reflect this goal.
Security
But isn’t Ethereum significantly more secure than a Cosmos app-chain? In reality, the move is a security tradeoff rather than a security downgrade. While dYdX will lose the security guarantees of a chain with 100,000s of validators and full nodes, the protocol gains a critical security feature — social consensus.
Since dYdX will be the only app running on the chain, protecting the protocol will be the top priority for validators and stakers. Thousands of apps run on top of Ethereum, so none (presumably) receive preferential treatment. Forking Ethereum in response to a protocol hack would be considered sacrilegious (we have come a long way since the DAO hack) and, in reality, would create more problems than it solves.
On dYdX chain, validators could realistically roll back transactions or fork the chain in response to a debilitating protocol hack. Of course, these changes would have to be weighed and voted on by the community. With sovereignty, social consensus emerges as a fallback option that mitigates the risk of a lower Nakamoto coefficient.
Importance of Community
Finally, there’s a chance that users value the Ethereum network and community more than anticipated. Dedicated Ethereum users may choose not to transition over to Cosmos and volumes could suffer. Maintaining the v3 protocol (at least initially) is a smart decision that mitigates this risk.
Wrap-Up
Think 10X Bigger is one of dYdX’s core values. Despite dominating the DeFi derivatives market, Antonio Juliano isn’t satisfied. He wants to take the throne from FTX and Binance as the largest crypto exchange in the world.
Currently, dYdX accounts for 1% of all perpetuals trading, across centralized and decentralized exchanges, and has its sights set on 30%. If the move to Cosmos hurts dYdX’s current market share, Antonio isn’t worried: “we should play like we have nothing to lose.”
While the move is certainly risky, dYdX has never shied away from risky decisions in pursuit of this dream. And honestly, I admire it.
Cue Cotton McKnight sendoff.