Penumbra is a layer 1, Tendermint consensus appchain built on the Rust programming language. It comes with a zero-knowledge shielded pool allowing Penumbra to offer services like multi-asset shielded transfers, staking, and governance. We have recently introduced Penumbra on our blog.
In this article, we take a deep dive into the functionalities of and the technology behind the Penumbra DEX.
Who Needs Private DeFi?
Traders need to protect their financial strategies, also known as alpha. However because most DeFi activities are visible and traceable on-chain, traders are faced with the risk if leaking their alpha and losing their competitive edge. As a sub-optimal solution to this problem, traders turn to centralised exchanges (CEXs) like Binance and Kraken since individual CEX activity is not publicly visible.
Despite CEX trading offering a greater level of privacy, unfortunately, traders sacrifice control over their capital since their liquidity is put into the custody of a third party. Such a tradeoff is associate with long-term risks exemplified by the collapse of FTX and alike.
On the other hand, traders, market makers, and liquidity providers who want to preserve their custody to avoid centralisation risks, use existing DEXs. However, these DEXs are often transparent, bringing the risk of disclosing alpha back into the equation.
At the end of the day, traders are presented with a problematic market environment where custody and privacy in DEXs seem to be two conflicting needs… but Penumbra’s shielded DEX is here to remove this conflict.
A Shielded DEX
Penumbra’s Shielded DEX is fully private and decentralised to safeguard the alpha and move full control over the capital to the user’s hands.
The idea behind the nexus of privacy and decentralisation is that these two components are complementary and yield greater total welfare to the Penumbra DEX participants when put together. Specifically, market makers use privacy to protect their alpha, this in turn creates more market competition due to the exclusive information held by individual market makers. Amplified competition leads to better prices offered by market makers to the traders, who in turn also benefit from the privacy of their trades. Furthermore, if prices are consistently optimised, traders are more likely to relocate their capital from other DEXs into Penumbra, therefore increasing the volume of trades based on which market makers can offer even better prices on trading pairs. Overall, the process that we have just described creates a positive feedback look, translating into consistent growth in the Total Value Locked (TVL) of Penumbra DEX.
(Source: Plaidfinch)
The fact that Penumbra DEX is built with privacy as a priority, allows for DEX-specific privacy-enabled features to be built and brought to DeFi, including:
- Fully batched execution with no intra-block ordering
- In-protocol arbitrage to auto-fill orders and internalise the MEV
- Oder-book style concentrated liquidity with arbitrary fees
- Private trading strategies with discrete positions and Profit & Loss (PnL)
- On-chain routing across all trading asset pairs
We decompose each of the above-mentioned features in the rest of this article.
Batch Swaps
Batch swaps refer to the process of executing all swap orders received within a specific time period in a single group, or batch, at a uniform price, instead of processing each order individually as it arrives. Such an approach helps reduce arbitrage opportunities and can improve the efficiency and fairness of the market.
Traditional DEX types like Constant Function Market Makers (CFMMs) have shown to work well for decentralised liquidity, but they have also exposed arbitrage opportunities due to the mismatch between continuous-time markets and the blockchain’s discrete batch processing. Each state update is broadcast to all participants and queued in the mempool before being included in the next block, allowing others to bid and potentially manipulate the order of transactions (e.g., front-running trades).
The above manipulation is enabled by two features:
- Although trades are always committed in a batch (a block), they are performed individually, making them dependent on miners’ choices of the ordering of trades within a block;
- Because traders disclose the trade amount in advance of execution, all other participants have the information necessary to manipulate them.
Penumbra DEX addresses the first problem by executing all swaps in each block as a single batch, aggregating the amounts in each swap, and then processing them as one trade against the CFMM. Let’s break the batching process down into steps:
- In each block, first all of the positions that have been submitted by anyone in the block at any point are opened
- Secondly, every swap that has been submitted is batched together
- Third, the batched swap intents are executed against all of the opened liquidity
- After, Internal arbitrage is performed against Penumbra’s staking token
- As a fifth step, the results of the arbitrage are burnet and all of the positions that were supposed to be closed, are closed
As a consequence of batching, there is no competition for intra-block ordering, allowing market makers to focus on competing in price rather than speed. Additionally, active LPs are given the opportunity to adjust prices per block and offer specific prices for each block.
Block-based pricing enables LPs to provide juts-in-time liquidity that is opened and closed per block, since when open and closed positions are submitted in the same transaction, then the position is opened ahead fi the block and closed by the end of the block.
As a cherry on top, all internal arbitrage is captured and burnt to eliminate the possibility of mechanical arbitrage within the DEX. Hence, the role of arbitrageurs is to keep prices consistent between the Penumbra DEX and the rest of the interchain, leaving room for profit-making for intra-chain arbitrage.
Going back to the second issue of traders disclosing their positions before the execution, Penumbra plans to address this by having users encrypt their swap amounts with an encryption key managed by validators, who will aggregate and decrypt only the batch trade. This will prevent front-running before block inclusion and provide privacy for individual trades within the batch.
Liquidity
An important part of any one DEX is how well and creatively it can manage available liquidity, whether it’s concentrating, positioning, transitioning, or composing it. Let’s take a deeper dive into each of these areas of liquidity management.
Concentrated Liquidity
Penumbra uses a hybrid model combining the features of order-book-like automated market makers (AMMs) with automatic trade routing. The liquidity in Penumbra is managed through individual concentrated liquidity positions, functioning similarly to an order book. Each liquidity position operates as an independent AMM, featuring its own fee tier and employing a constant-sum (fixed-price) market-making mechanism. These individual AMMs are integrated into a global AMM by the DEX engine, which in turn optimises trade routes across the entire liquidity graph. Therefore, global AMM integration simplifies the optimisation problem, reducing it to a graph traversal task.
(Source: Plaidfinch)
Liquidity Positions
A liquidity position on Penumbra is characterised by reserving amounts of one or both assets in a trading pair and establishing a fixed exchange rate between them. These reserves and asset valuations determine the constant-price pool’s trading function, where the combined value of the reserves remains constant.
In practical terms, a liquidity position includes:
- A Trading Pair: Identified by the asset IDs of the two assets involved, with the IDs structured to be order-independent. For example ETH/USDT
- Trading Function: Defined by the prices of the two assets and a fee component, such as $1 for 1 USDT and $3,160 for 1 ETH, plus DEX trading fee as a % of the transaction
- Unique Identifier: A 32-byte nonce ensuring each position is unique
The unique identifier is used to manage and track the reserves, which fluctuate as trades occur against the position. The position ID functions like a temporary user account (ephemeral), with the reserves representing its assets, and is automatically created and deleted.
Position States and Transitions
Liquidity positions can exist in one of four states, transitioning sequentially:
- Opened Position: Active and available for trading
- Closed Position: Inactive but still holding reserves
- Withdrawn Position: Reserves have been removed
- Claimed Position: Any associated liquidity incentives have been claimed
Control over these positions is maintained via a liquidity position NFT (LPNFT), which records both the position ID and state. State transitions are enforced through the transaction value balance mechanism:
- Open: Converts initial reserves to an open position NFT
- Close: Converts an opened position NFT to a closed position NFT
- Withdraw: Converts a closed position NFT to a withdrawn position NFT and releases the final reserves.
- Claim Reward: Converts a withdrawn position NFT to a claimed position NFT and allocates any liquidity incentives.
Separating the closed and withdrawn states is crucial for phased execution, therefore allowing market makers to update prices block-by-block without disrupting capital availability by stacking position transitions within a single block (as explained in the Batching section).
The distinction between withdrawn and claimed states is important as it allows for potentially retroactive liquidity incentives. Such distinction can be used for future implementation and permissionless funding by any entity wishing to subsidise liquidity for a particular trading pair.
Private Trading Strategies
The LPNFT technology allows for the deployment of private trading strategies, where each liquidity position has its own shielded NFT. Therefore, while the set of open positions on the DEX is public, to make the offered liquidity visible and allow supply and demand matching, the positions themselves are anonymous. Anonymous positions, in turn, support the main aim of Penumbra – that is support market-makers in protecting their alpha.
What shielded LPNFTs mean in practice, is that while the whole set of open positions can be seen in the market, therefore disclosing how much liquidity is offered between any asset pair, the owners behind these positions can not be de-anonymised. For example, the owner of all ETH<>ATOM pairs could be 1 market maker or 1000 of them.
Liquidity Composition
The entirety of liquidity positions for a trading pair forms a market, resembling an order book in terms of capital availability at different price levels. During trade execution, a graph of assets and liquidity positions is traversed to identify optimal routes, therefore synthesising liquidity positions across intersecting assets (assets pairs with similar prices and/or ratios) to create unified synthetic positions (combining liquidity positions from different but related asset pairs for trading), facilitating seamless trading between indirectly connected asset pairs.
(Source: Plaidfinch)
For instance, combining liquidity positions for pairs USDT<>ETH and ETH<>ATOM can form a synthetic position for USDT<>ATOM. This composition allows for efficient routing and trading by leveraging the interconnected liquidity across multiple assets.
Put differently, synthetic position represents a simplified trading function encompassing the combined liquidity and fees from the individual positions.
On-chain Routing
The shielded DEX design, coupled with aforementioned liquidity and batching features, lays a fundament for optimal on-chain routing,which is the process of finding the optimal path for trading tokens directly on the blockchain.
On a high level, routing a trade on Penumbra is about finding the best way to swap a source asset (S) for a target asset (T) at the lowest cost. This process can be thought of as a special kind of pathfinding strategy, wih we break down below.
Liquidity Structure
Before the DEX starts to route, liquidity should be in place. Penumbra’s liquidity (availability of assets for trading) is organized in two ways:
- Macro-Scale: A broad view showing trading pairs between different assets.
- Micro-Scale: A detailed view showing individual trading positions within each pair, each with a set price and a limited amount of assets available.
Routing Phases
After the liquidity is supplied and the Micro scale is distinguished from Macro scale, the routing’s first phase called Spill-ing can start, before moving to Fill-ing.
Spill Phase:
- Graph Traversal: The routing system looks through the broad network of trading pairs to find the best path from the source asset to the target asset, ignoring the limits on how much can be traded.
- Path Selection: After screening the broad network, the best path (P) and a backup path (P’) based are identified, based on the best available prices.
Fill Phase:
- Increase Capacity: Trading is started along the best path (P) until the price becomes less favorable.
- Re-Evaluation: If the path becomes less optimal, switch back to the spill phase to find a new path or choose the backup patch (P’).
Routing Execution
Once the filling phases are completed, they are ready to be executed. The filled trades are executed along selected route, with the best available positions at each step being prioritised.
Execution is complemented wby a process called Frontier Managemet, where the best trading positions for each step in the path are tracked and adjusted as these positions are used up.
Termination
As a last stage of execution, trades need to be terminated, which happens on two different occasions. The trade is terminated either after a full completion of the trade, of after partial completion. Partial competition occurs when the price has reached a point where it is no longer optimal to continue, meaning that the cost of continuing the trade has become too high compared to the benefit.
Overall, Penumbra’s routing strategy involves switching between a broad and detailed view to find and execute the best trade paths, including looking for the best routes, managing trading positions during execution, and adjusting routes based on capacity and price changes.
Conclusion
Penumbra DEX integrates privacy and decentralization to safeguard traders’ financial strategies (alpha) while ensuring they retain control over their capital. CEXs offer privacy but at the cost of centralization risks, while existing DEXs expose trading activities to the public, risking alpha leakage. Penumbra’s shielded DEX addresses these issues by providing a fully private, decentralized platform that enhances market competition and efficiency through features like batch swaps, in-protocol arbitrage, and concentrated liquidity positions.
By executing trades in batches and employing encrypted trade amounts, Penumbra mitigates front-running risks and arbitrage manipulation. Its liquidity management strategies ensure optimal trading routes and efficient liquidity utilization, fostering a positive feedback loop that increases Total Value Locked (TVL) and benefits both traders and market makers. All in all, a combination of privacy, control, and efficiency positions Penumbra DEX as a secure and effective trading platform for its users.
Simply Stake and Secure your assets with the Ledger wallet.
Disclaimer: This article contains affiliate links. If you click on these links and make a purchase, we may receive a small commission at no additional cost to you. These commissions help support our work and allow us to continue providing valuable content. Thank you for your support!
This article is provided for informational purposes only and is not intended as investment advice. Investing in cryptocurrencies carries significant risks and is highly speculative. The opinions and analyses presented do not reflect the official stance of any company or entity. We strongly advise consulting with a qualified financial professional before making any investment decisions. The author and publisher assume no liability for any actions taken based on the content of this article. Always conduct your own due diligence before investing.