Exploring Alternative DEX Architecture Through ArtexSwap

Jul 11, 2024

Technical

Originally published by ArtexSwap.

ArtexSwap is a decentralized exchange that addresses MEV risks and Rug Pull issues by utilizing Artela EVM++ and Aspect technology. It enhances transaction security and efficiency, making it suitable for decentralized trading scenarios that require high security and flexibility.

Since its inception, Ethereum has been a technological home for digital currencies, global payments, and applications. DEXs (Decentralized Exchanges) are the cornerstone of decentralized finance (DeFi); after all, without DEXs, DeFi would be merely an empty promise. As a platform operating on the blockchain, it enables direct transactions between users and is not regulated by any third-party institution, which allows for the creation of more advanced financial products.

Working Principle

In the current Ethereum ecosystem, DEXs (Decentralized Exchanges) are flourishing with a variety of design models, each having its own strengths and weaknesses in terms of functionality, scalability, and decentralization. Based on different trading mechanisms, DEXs can be divided into two categories (as shown in the figure below).

  1. Order Book-Based DEX

An order book uses matching algorithms similar to pathfinding to automatically search for unmatched buy and sell orders in the market. The trading platform’s system automatically matches these buy and sell orders. This model is suitable for scenarios requiring efficient price matching and flexible trading strategies. In short, the liquidity of an order book comes from two sources: traders and market makers.

Further reading: “Analysis: Order Book Model and Automated Market Maker (AMM)

2. Automated Market Maker (AMM)

An Automated Market Maker (AMM) is a pricing and liquidity mechanism in DEXs. In simple terms, market makers provide liquidity assets (two types of assets) to a liquidity pool. The product of the reserve amounts in the liquidity pool is maintained at a constant k value. When a user takes one token, they need to provide another token to the liquidity pool to maintain this k value. Essentially, this mechanism ensures the relative balance of the liquidity pool.

For a detailed understanding of AMMs, further reading is available: “UniswapX Research Report (Part 1): Summarizing the Development Path from V1 to V3, and Explaining the Innovations and Challenges of the Next-Generation DEX.

What are the values of DEX?

[Data Sources:THE BLOCK]

According to statistics from CoinGecko, as of July 9, 2024, there are approximately 835 known DEX exchanges, with a total 24-hour trading volume of $8.35 billion and a monthly visit count of 320 million. The three largest decentralized exchanges by trading volume are BabyDogeSwap, Uniswap V3 (Ethereum), and Orca.

Based on the 24-hour trading volume of the top three DEXs and CEXs, DEXs account for 16% of the daily trading liquidity. Compared to the same period in 2023, the 24-hour trading volume of DEXs has increased by 315% (from $2 billion in 2023), and the trading volume has increased by 166% (from 120 million visits in 2023). Clearly, there is a significant market demand for decentralized trading platforms.

Since decentralized exchanges (DEXs) use deterministic smart contracts for transactions, there is no intervention from centralized third parties. This transparent operation contrasts sharply with traditional financial markets. For example, in 2022, FTX, one of the largest cryptocurrency exchanges at the time, went bankrupt during a series of declines due to the misuse of user funds, causing widespread market turmoil.

Additionally, DEXs enhance financial inclusivity through decentralization. Although some DEXs may restrict user access based on geographic location or other factors, overall, users only need internet access and a compatible self-custody wallet to use DEX services. This model, which does not require cumbersome registration and verification, allows new users to quickly and easily join the platform, improving the user experience.

Key Risks of DEXs

Decentralized exchanges (DEXs) can ensure the execution of trades, enhance transparency, and offer permissionless access. These characteristics significantly lower the barriers to trading and providing liquidity. However, DEXs also come with several risks, including but not limited to the following aspects:

  1. Smart Contract Risk: Although blockchain technology can securely execute financial transactions, the security of smart contracts depends on the technical proficiency and experience of the development team.

  2. Front-Running Risk: Due to the public and transparent nature of on-chain transactions, arbitrageurs or MEV bots may front-run trades, capturing value from regular users. These bots operate similarly to high-frequency traders in traditional financial markets, profiting from regular users’ transactions by paying higher transaction fees and exploiting network delays.

  3. Network Risk: Since transactions occur on-chain, the transaction costs on DEXs can be high. When the network is congested or experiences downtime, these costs can become even higher, making users more susceptible to market volatility.

  4. Rug Pull Risk: A common and serious problem in the decentralized finance (DeFi) space, where many projects attract substantial investor funds only to suddenly withdraw liquidity and abscond with the funds. Rug pull risks can be broadly categorized into three types:

    1. Liquidity withdrawal.

    2. Developers holding a large number of tokens or issuing more tokens.

    3. Fraudulent projects.

This type of scam results in significant investor losses, causing the project’s value to plummet to zero almost instantly. It severely impacts the overall trust in the DeFi market. For example, the 2021 SushiSwap incident is a typical case. SushiSwap’s anonymous founder, Chef Nomi, sold $13 million worth of SUSHI tokens from the developer fund after raising substantial funds for the project, causing market panic and a sharp drop in the token’s price. Although Chef Nomi later returned the funds and the project was taken over by the community, the incident caused significant financial losses and psychological distress to investors.

Issues with Mainstream DEXs

If we talk about the first project to venture into the Automated Market Maker (AMM) space, Bancor cannot be overlooked. It’s somewhat unfortunate that it did not gain widespread attention before the DeFi boom, leading many to mistakenly believe that AMM was invented by Uniswap. However, with the anticipated launch of Bancor V2, the price of BNT has surged rapidly over the past two months.

Despite V2 introducing innovative features such as oracles providing up-to-date prices and updating token pool weights based on oracle prices, it still has some drawbacks:

  • Oracle Integration: While oracles can provide more accurate price information, their implementation brings challenges. For instance, if there is no corresponding trading pair price on a centralized exchange, it creates a chicken-and-egg problem. Additionally, the reliability and security of oracles are concerning, as they can become targets for attacks, leading to price manipulation and other security issues.

  • Dynamic Pool Model: Although the dynamic pool model can update token pool weights based on oracle prices, liquidity providers (LPs) may face higher risks of loss in highly volatile markets. The greater the market volatility, the more severe the impermanent loss for LPs, which may lead to liquidity providers withdrawing their funds, affecting the stability and trading efficiency of the liquidity pool.

  • Counterparty Risk: Bancor’s design may also face counterparty risk. Even with the oracle mechanism, if market prices fluctuate sharply and oracles fail to update prices promptly, LPs could still face significant risks. Delays or inaccuracies in oracle price updates could result in LP losses during price swings.

Despite Bancor V2 introducing many innovative designs, its complexity also raises the learning and usage barriers for users. Compared to other simpler and more user-friendly AMM models, Bancor might require users to have more specialized knowledge and technical background to fully understand and utilize its new features. This could limit its user growth and market acceptance.

ArtexSwap’s DEX Implementation

ArtexSwap is supported by Artela EVM++. The operation of the ArtexSwap platform is similar to Uniswap but enhances security through the use of EVM++ functionalities.

Scalability Mechanism of Artela

First, to better understand the underlying environment of ArtexSwap, let’s briefly discuss the underlying operating mechanism of Artela. Scalability here actually encompasses two aspects: the extensibility of the EVM and its performance.

For extensibility, Artela implements the Aspect technology, which allows developers to create on-chain custom programs in the WebAssembly (WASM) environment. These programs can collaborate with the EVM, providing high-performance, customized application-specific extensions for dApps.

Further reading: “Vitalik’s Full Interpretation: Is the Next Step in Web3.0 Infrastructure ‘Encapsulation or Extension’?

From a performance perspective, it is about improving the execution efficiency of the EVM. We all know that the EVM is a serial virtual machine environment, which is very inefficient compared to modern hardware. Therefore, parallel processing becomes particularly important.

To achieve parallel execution, how to solve the following problems:

  1. How to resolve conflicts in transactions executed simultaneously?

By adopting a speculative optimistic execution strategy, it assumes that there are no conflicts between transactions initially, records modifications for each transaction but does not finalize them immediately. After transaction execution, it verifies and checks for conflicts, and if any are found, re-executes the transactions. The speculative nature is achieved through AI models analyzing historical transaction data, predicting transaction dependencies, optimizing execution order, and reducing conflicts and re-execution.

Compared to this, Sei and Monad rely on predefined transaction dependency files, lacking Artela’s AI-based dynamic prediction model’s adaptability, making Artela more advantageous in reducing execution conflicts.

2. How to improve IO speed and reduce transaction execution wait times?

Using asynchronous preloading technology to address input/output (I/O) bottlenecks caused by state access. Artela, before transaction execution, uses predictive models to preload required state data from slow storage (like hard drives) to fast storage (like memory). This technique of preloading and caching data allows multiple processors or execution threads to access data simultaneously, improving parallelism and efficiency.

3. How to address data bloat and increased database pressure during data writes?

Artela combines various traditional data processing techniques to develop a parallel storage system that improves parallel processing efficiency. The parallel storage system addresses two main issues: parallelizing storage processing and enhancing the ability to efficiently record state data into the database. Common problems in data storage include data bloat and increased database pressure during data writes. To address this, Artela employs a strategy of separating state commitment (SC) from state storage (SS). This strategy divides storage tasks into two parts: one part handles operations quickly without retaining complex data structures to save space and reduce data duplication; the other records all detailed data information. Additionally, Artela reduces the complexity of data storage by merging small data chunks into larger ones, ensuring performance is not compromised when handling large volumes of data.

Furthermore, validator nodes support horizontal scaling, allowing the network to automatically adjust the scale of computing nodes based on current load or demand. This scaling process is coordinated by an elastic protocol to ensure sufficient computing resources in the consensus network. With elastic computing, the computational power of network nodes is scalable, achieving elastic block space that allows for the request of independent block space as needed. This satisfies the demand for public block space expansion while ensuring performance and stability, enabling DEXs to handle peak trading periods as seamlessly as Web2 elastic scaling.

It’s worth noting that the premise of elastic block space as a horizontal scaling solution for blockchain performance is that “transactions must be parallelizable.” Only after achieving transaction parallelism does it become necessary to horizontally expand node resources to improve transaction throughput.

Exploring DEX Security in ArtexSwap

ArtexSwap has now been updated to version 2.0. From the architecture of ArtexSwap, it is clear that the team’s development efforts are primarily focused on three main security aspects:

  • How can a DEX identify and prevent malicious behavior?

  • How can users be protected from Rug Pull scams during transactions?

  • How can high slippage situations be prevented?

Blacklist Mechanism

The blacklist mechanism is a strategy that emphasizes preemptive security. From a behavioral perspective, addresses and users who have previously engaged in “bad activities” are highly likely to reoffend. By labeling accounts, addresses, and contracts that are deemed risky, the ArtexSwap platform can perform a priori checks on both parties and the environment of a transaction before it occurs. The Blacklist mechanism continuously monitors trading activities, checking each transaction for any “dangerous elements” listed on the blacklist. When an operation request from a blacklisted account is detected, it automatically blocks these requests to prevent malicious activities.

For example, if an account is blacklisted for participating in a Rug Pull or other fraudulent activities, that account will be unable to trade or add liquidity on the DEX, thereby protecting other users from potential losses.

Essentially, ArtexSwap provides a passive defense system with a focus on C-end (customer) security.

Anti-Rug Mechanism

Rug Pull refers to developers or major holders suddenly increasing the token supply or withdrawing a large portion of funds from the liquidity pool, causing the token price to plummet and resulting in significant losses for investors. This often occurs when contracts have backdoors. Generally, these situations involve contracts that have escaped the Blacklist mechanism due to the lag in blacklist information. There are typically two scenarios: 1. The contract vulnerability has not been discovered. 2. It has been discovered, but the blacklist has not been updated.

For the first scenario, where there is no direct evidence that the token contract is problematic, ArtexSwap adopts an optimistic mechanism, assuming the contract is safe. However, the ArtexSwap platform continuously monitors any attempts to significantly increase the token supply. If such an attempt is detected, it will be blocked, and trading of the related tokens by other users will be prevented to avoid losses.

For the second scenario, which relies on off-chain communication, Aspect enables interaction and data exchange outside the blockchain when off-chain communication is activated. This allows ArtexSwap to obtain real-time information about malicious contract addresses from third-party sources and conduct security checks on all token contracts on the DEX. If a malicious contract is detected, all related operations will be immediately blocked.

Slippage Mechanism

It is important to clarify that under the AMM liquidity mechanism, the occurrence of high slippage resulting in losses is highly likely. Simply put, slippage refers to the difference between the executed price and the expected price of a trade. When the market is volatile or there is insufficient liquidity, slippage can become significant.

Preventing slippage is a “predictive” issue. Addressing insufficient liquidity is relatively straightforward; the ArtexSwap platform’s contracts can achieve this goal by monitoring the liquidity pool in real-time. The challenge lies in market volatility, as the market is influenced by external events. The initial approach would be to integrate an oracle to obtain market status. To achieve this, ArtexSwap leverages its underlying environment, Artela, which supports Aspect technology. By utilizing this, ArtexSwap creates a dApp on the chain that can interact with third-party oracles to obtain market volatility information.

Furthermore, Artela supports AI agents. By using market state data and AI, it predicts high slippage for transactions at any given time. Combined with the previously mentioned liquidity monitoring, it arrives at a comprehensive estimate. If this estimate exceeds a threshold (30%), the transaction is prevented from executing, thus protecting traders from losses due to significant price fluctuations.

Conclusion

Although we are uncertain whether the current DEX model can support long-term growth and institutional adoption, it is foreseeable that DEXs will continue to be indispensable infrastructure within the cryptocurrency ecosystem. At the same time, security is not only a perpetual topic in the Web3 world but also the lifeline for the development of DEXs.

As the saying goes, every successful scam could result in a user abandoning Web3, and without any new users, the DEX ecosystem would have nowhere to go. Therefore, for DEXs, losing security means losing everything.

Currently, despite the hot market for DEXs, the narrative around derivatives seems to remain enduring. However, in the long term, if DEX security can truly achieve ToC, it may lead DEXs into the next era of growth.

Build

Explore