Repost from From Mini Game to DeFi — What are we lacking on TON? | by LayerPixel | Sep, 2024 | Medium
In the past few months, we have seen a surge in the TON ecosystem, including Notcoin, Dogs, Hamster Kombat, and Catizen listings on Binance. Rumors suggest it has brought millions of new KYC users to the exchanges. Whether or not we admit it, this is actually the largest mass adoption of blockchain in the past few years. But the problem is, what’s next?
Behind the huge number of users, the TVL is still relatively low, and we don’t see many DeFi protocols emerging. This also raises concerns about the low user value on TON and the debate over the incomplete infrastructure of the TON blockchain.
However, in this article, we would like to briefly discuss an important concept behind DeFi — “Atomic Swap” and the problem LayerPixel (PixelSwap) is addressing. On the one hand, the initial success of DeFi can be traced back to Ethereum, which became the bedrock for DeFi DApps and smart contracts. On the other hand, the emergence of asynchronous blockchains such as TON brings forth new opportunities and challenges for DeFi applications, notably in terms of composability.
A brief history of DeFi
The DeFi ecosystem blossomed during the “DeFi Summer”, largely centered on Ethereum. Developers leveraged the Ethereum ecosystem where smart contracts serve as foundational building blocks that can be combined like Lego bricks. This composability provided the network effect necessary for the rapid proliferation of decentralized financial applications and services.
Ethereum’s paradigm of composability allowed various DeFi protocols to interact with each other in innovative ways. Key financial primitives like atomic swaps, flash loans, restaking, and lending platforms exemplified how different applications could be layered together to create complex, multi-functional financial products.
As DeFi matured, the limitations of Ethereum’s synchronous model — mainly concerning scalability and high transaction fees — became increasingly apparent. This spurred interest in exploring new blockchain architectures, such as asynchronous blockchains, which promise to resolve some of these inherent limitations.
Asynchronous Blockchains: A New Paradigm
Ethereum’s traditional model is synchronous, maintaining a monolithic state where each transaction is processed sequentially. Asynchronous blockchains like TON, on the other hand, employ an actor-model approach. This shift results in several fundamental structural differences:
Ethereum — Synchronous Blockchains (Monolithic State) :
- Atomic Operations: Straightforward atomic transactions are possible because each transaction (even one that modifies states across multiple smart contracts) can be treated as a single-unit operation. Ethereum Virtual Machine (EVM), for example, safely sandboxes all steps in a transaction, ensuring either full execution or no execution at all.
- Sequential Processing: Each transaction must wait for the previous one to complete, which naturally limits throughput and scalability.
- Global State: All transactions operate over a single, shared global state, simplifying state management but exacerbating contention.
TON — Asynchronous Blockchains (Actor Model) :
- Parallel Processing: Transactions can be handled concurrently across multiple actors or smart contracts, enhancing overall scalability and throughput. Smart contracts on TON, for example, are cells or actors that can operate independently, and one-way messages are used to update states between actors.
- Distributed State: Different actors hold isolated states, which can interact with other actors but do not share a single global state.
- Coordination Complexity: Achieving atomic operations in this model is complex due to its distributed nature.
While asynchronous blockchains are quite significant in scalability (theoretically), the lack of atomic swaps makes TON significantly difficult for DeFi to develop on, regardless of the hard-to-use FunC / Tact language. Think about it, without atomic operations and sequential processing, the liquidity of lending protocols is quite difficult, regardless of the challenging DeFi Lego.
At LayerPixel and PixelSwap (PixelSwap is using LayerPixel’s infrastructure and is part of LayerPixel), we propose a new way to solve this problem, making atomic swaps possible and trying to provide a safer and better solution for swapping and DeFi.
Challenges of DeFi Composability on Asynchronous Blockchains
For DeFi applications, maintaining composability on asynchronous blockchains introduces intricate challenges, primarily due to the nature of distributed states and parallelism:
Transaction Coordination:
- Synchronization: Coordinating multiple actors to agree on the state at a given point in time is complex. Unlike a synchronized global state, which simplifies atomic operations, ensuring multiple independent actors can operate in lockstep presents significant hurdles.
- Consistency Models: Asynchronous systems often rely on weaker consistency models like eventual consistency. Ensuring that all involved actors reach a common state without diverging becomes a logistical endeavor.
State Consistency:
- Concurrency Control: In distributed settings, race conditions can arise if multiple transactions try to update overlapping states. This requires sophisticated mechanisms to ensure that transactions are serialized correctly without bottlenecking the system.
- State Reconciliation: Divergent states across actors need to be reconciled, and rollback mechanisms (if some part of the transaction fails) must be robust enough to revert changes gracefully without creating inconsistencies.
Failure Handling:
- Atomicity: Guaranteeing that either all parts of a transaction succeed or none do is challenging in an environment where states are distributed and operations are non-atomic by default.
- Rollback Mechanisms: Efficiently rolling back partial transaction state changes without leaving residual inconsistencies requires advanced techniques.
Pixelswap: Bridging the Composability Gap
Pixelswap’s innovative design addresses these challenges by introducing a distributed transaction framework specifically designed for the TON blockchain. The architecture, guided by BASE principles (BASE: An ACID Alternative), comprises two primary components: the Transaction Manager and multiple Transaction Executors.
Saga Transaction Manager
The Saga Transaction Manager orchestrates complex multi-step transactions, overcoming the limitations of 2PC by applying the Saga pattern, which is better suited for long-running, distributed transactions:
- Lifecycle Management: Manages the entire transaction lifecycle, broken down into a series of smaller, independently executable steps, each with its own compensating action in case of a failure.
- Task Assignment: Decomposes the primary transaction into discrete, isolated tasks and delegates them to the appropriate Transaction Executors.
- Compensating Actions: Ensures that each saga has a corresponding compensating transaction that can be triggered to undo partial changes if any step fails, maintaining consistency.
Transaction Executors
Transaction Executors are responsible for executing assigned tasks within the transaction lifecycle:
- Parallel Processing: Executors operate concurrently, maximizing throughput and balancing system load.
- Modular Design for Functional Extensibility: Each Transaction Executor is designed to be modular, allowing for the implementation of various functionalities. These can include diverse financial operations such as different swap curves, flash loans, lending protocols, and more. This modularity ensures that these functionalities can seamlessly coordinate with the Saga Transaction Manager, maintaining the core principles of DeFi composability.
- Eventual Consistency: Ensures that local states of executors remain synchronized and reconciled with the overall distributed state of the transaction.
Through these features, Pixelswap’s Transaction Executors ensure robust, scalable, and asynchronous transaction execution, enabling the creation of complex and composable DeFi applications on TON.
Conclusion
In conclusion, DeFi’s future requires adapting to the shifting paradigms from synchronous to asynchronous blockchains while preserving and enhancing key principles like composability. Pixelswap emerges as a pioneering solution for the TON blockchain, elegantly combining robustness, scalability, and composability. By ensuring seamless interaction capabilities and robust transaction management, Pixelswap paves the way for a more dynamic, scalable, and innovative DeFi ecosystem.
The PixelSwap Beta v0.8 is on the TON mainnet now, and you can try it at PixelSwap.io. This version is meant to provide a basic demo with simple swap functions. You can try swapping, adding liquidity, and funding wallet features right now. As you might notice, the gas fee for PixelSwap is slightly higher than others, and we hope this article can guide you better to understand it.
About LayerPixel
LayerPixel is an all-in-one DeFi protocol designed specifically for the TON blockchain and seamlessly integrated with Telegram Mini Apps. Leveraging a modular architecture, LayerPixel overcomes the asynchronous limitations of TON while harnessing its sharding benefits.
At the core of the LayerPixel ecosystem are several innovative components:
- PixelWallet — An SMC wallet with Account Abstraction (AA) features, enabling users to interact with dApps and the LayerPixel ecosystem with ease.
- PixelSwap — The first modular DEX on TON, supporting advanced trading models like weighted pools and LBP.
- Pixacle — A decentralized oracle solution delivering fast and accurate price data to dApps and smart contracts.
LayerPixel’s future plans include becoming a cross-chain solution to power DeFi experiences across all Telegram Mini Apps. By providing an all-in-one platform, LayerPixel aims to make blockchain-powered finance accessible to everyone within the TON ecosystem.