Sub topic 17
Centralized and on-chain venues
This chapter assumes you know how perpetual swaps, mark price, funding, liquidation, and insurance funds work. It covers where those products trade and how the venue changes your risk. The same contract can sit on a company's servers or in smart contracts on a blockchain, and the two behave differently in ways that matter when you size positions.
Two ways to run the same product
A centralized exchange (CEX) is a company that runs a matching engine on its own servers. You deposit coins, and the exchange records your balance in an internal database. Orders, margin, funding, and liquidations all happen inside that database. Only deposits and withdrawals touch a blockchain.
An on-chain venue (also called a decentralized derivatives exchange) keeps balances and positions in smart contracts. You connect a wallet, deposit collateral into a contract, and sign transactions or messages to trade. Anyone can read the positions and collateral on the chain. Rules such as margin and funding are enforced by code instead of by company policy.
On-chain venues fall into three designs:
- On-chain or app-chain order book. The venue runs a limit order book like a CEX, but its state is replicated across validators on a purpose-built chain. Examples include Hyperliquid and dYdX v4. Matching is fast, and settlement is public.
- Pool-based (oracle-priced). Traders do not trade against other traders' orders. They trade against a shared liquidity pool at a price read from an oracle. GMX is the best-known example. Liquidity providers take the other side of net trader positions.
- Virtual AMM (vAMM). A pricing curve sets the perpetual's price, and no real assets sit in the curve. Early designs used this, and it is now less common.
The details of each protocol change often, so check current documentation before relying on any specific feature.
What changes for the trader
Custody and counterparty risk
On a CEX you hold a claim on the exchange, not the coins. If the exchange fails, gets hacked, or freezes withdrawals, your balance is at risk even when your trading was correct. This is counterparty risk.
On-chain, you keep control of your wallet, but your collateral sits in a contract. The risk shifts from "the company fails" to "the code or its dependencies fail." That includes bugs, upgrade keys held by a small team, and oracle manipulation. Neither option removes counterparty risk. It changes who and what you depend on.
Price source and manipulation
A CEX builds its index price from several spot exchanges and uses a mark price for liquidation. An on-chain venue usually reads an oracle, a service that publishes prices on-chain. The oracle's update speed and sources decide how safe the venue is. A slow oracle lets traders exploit stale prices. A thin or manipulable source can trigger wrongful liquidations, so check which price feed your venue's liquidation logic uses.
Execution and costs
CEXs generally offer lower latency, deeper books, and more order types. On-chain venues add costs that a CEX does not have:
- Network fees (gas) for each transaction, unless the venue is an app-chain that hides them.
- Block-time delays between signing and execution.
- Front-running by other participants who can see pending transactions, often called MEV (maximal extractable value).
- Price impact in pool designs, which depends on pool size and on how skewed open interest is.
Fees also differ in structure. A CEX charges maker and taker fees as a percentage. A pool venue may charge an opening and closing fee, a price-impact fee, and a borrow fee that accrues for as long as the position stays open. Compare total cost for your trade size and holding period, not the headline fee.
Liquidation and loss handling
On a CEX, the exchange's engine closes underwater positions and uses its insurance fund and ADL to cover shortfalls. Rules differ by exchange and are written in its documentation.
On-chain, liquidations are executed by bots or keepers that anyone can run, or by a protocol vault. A congested chain can delay liquidations, which allows bad debt to build up. In pool designs, bad debt falls on liquidity providers, not on other traders through ADL. Always read where losses go when the system is stressed.
Access and transparency
A CEX usually requires identity verification and can restrict regions or freeze accounts. On-chain venues are generally open to any wallet, though front-end websites may block some regions. On-chain venues let you audit total collateral and open interest yourself. With a CEX you rely on the exchange's own reports.
Comparison
| Factor | Centralized exchange | On-chain venue |
|---|---|---|
| Custody | Exchange holds funds | Your wallet and a smart contract |
| Main failure risk | Insolvency, hack, withdrawal freeze | Contract bug, oracle failure, key compromise |
| Speed and depth | Typically highest | Varies, often lower |
| Extra costs | Trading fees | Gas, price impact, MEV, borrow fees |
| Loss handling | Insurance fund, ADL | Keepers, pool or vault absorbs bad debt |
| Transparency | Reported by the exchange | Verifiable on-chain |
| Access | Account and KYC usually required | Wallet only, with front-end limits |
Comparing total cost in code
The model below puts fees, slippage, and fixed network costs into one round-trip figure. It ignores funding and borrow fees, so add those for positions you hold longer.
def round_trip_cost(notional, taker_fee, slippage_bps, fixed_fee_usd=0.0):
"""Cost in USD of opening and closing one position with market orders."""
fee = notional * taker_fee
slippage = notional * slippage_bps / 10_000
one_way = fee + slippage + fixed_fee_usd
return round(2 * one_way, 2)
cex = round_trip_cost(10_000, taker_fee=0.0005, slippage_bps=2)
chain = round_trip_cost(10_000, taker_fee=0.0006, slippage_bps=5, fixed_fee_usd=1.5)
print("CEX round trip:", cex)
print("On-chain round trip:", chain)
print("Difference:", round(chain - cex, 2))With these example inputs the CEX costs 14.0 USD and the on-chain venue costs 25.0 USD. Change notional to see how fixed network fees weigh more on small trades and less on large ones, while slippage grows with size.
Choosing a venue
Use these criteria in order:
- Capital at risk. The larger the balance, the more custody and insolvency risk matter. Do not keep idle collateral on any venue longer than you need.
- Strategy type. Fast strategies, tight stop-losses, and large sizes favor deep, low-latency books. Long-held positions with a small size can tolerate on-chain friction.
- Price and liquidation rules. Read how the mark or oracle price is built, how liquidations run, and who pays for bad debt.
- Total cost. Include fees, slippage, gas, funding, and borrow costs.
- Access and legal constraints. Check what your jurisdiction and the venue allow.
Many traders spread positions across venues, and the same logic applies to basis trades. A cash-and-carry trade has two legs, and one leg on a different venue adds transfer time and margin management between them.
Common errors
- Assuming "decentralized" means "risk-free." Contract and oracle risk are real and are often less well understood than exchange risk.
- Comparing only headline fees and ignoring slippage, gas, and borrow costs.
- Ignoring which price triggers liquidation. A wick on one source can liquidate you on one venue and not on another.
- Forgetting that funding or borrow fees differ by venue for the same asset.
- Leaving large idle collateral on a venue between trades.
Exercise
You plan to hold a 5,000 USD leveraged long for three weeks. Venue A is a CEX with low fees and deep books. Venue B is an on-chain pool venue with a borrow fee that accrues each hour. Name three things you would compare besides the opening fee, and say which risk on Venue B is not present in the same form on Venue A.
Show answer
Compare (1) the funding or borrow cost over three weeks, since it accrues for the whole holding period, (2) slippage or price impact when opening and closing, plus gas on Venue B, and (3) how liquidation price is computed and which price feed triggers it. The risk on Venue B that Venue A does not have in the same form is smart-contract and oracle risk: a code bug or bad price feed could cause wrongful liquidations or loss of collateral, whereas on Venue A the corresponding exposure is the exchange's solvency and custody.