Written by LayerPixel

Compiled by: Vernacular Blockchain

In the past few months, we have witnessed the explosive growth of the TON ecosystem, including the listing of Notcoin, Dogs, Hamster Kombat and Catizen on Binance. It is said that this has brought millions of new KYC users to major trading platforms. Whether we admit it or not, this is actually the largest application of blockchain in recent years. But the question is, what should we do next?

Despite the large number of users, TON’s total locked value (TVL) is still relatively low, and we have not seen many DeFi protocols emerge. This has also sparked concerns and debates about the low user value on the TON chain and its incomplete infrastructure.

However, in this article, we would like to briefly discuss an important concept behind DeFi - "atomic swaps" and the problems that LayerPixel (PixelSwap) is solving. On the one hand, the initial success of DeFi can be traced back to Ethereum, which became the cornerstone of DeFi applications and smart contracts. On the other hand, the rise of asynchronous blockchains, such as TON, has also brought new opportunities and challenges to DeFi applications, especially in terms of composability.

1. A brief history of DeFi

The DeFi ecosystem flourished during the "DeFi Summer", mainly on Ethereum. Developers took advantage of the Ethereum ecosystem, with smart contracts as basic building blocks that can be combined like Lego blocks. This composability provided the necessary network effects for the rapid spread of decentralized financial applications and services.

Ethereum’s composability paradigm enables various DeFi protocols to interact with each other in innovative ways. Key financial primitives such as atomic swaps, flash loans, rehypothecation, and borrowing platforms demonstrate how different applications can be layered on top of each other to create complex, versatile financial products.

As DeFi matures, the limitations of Ethereum’s synchronous model — primarily regarding scalability and high transaction fees — have become increasingly apparent. This has spurred interest in exploring new blockchain architectures, such as asynchronous blockchains, which promise to address some of these inherent limitations.

从小游戏到DeFi,TON上还缺少什么?

2. Asynchronous blockchain: a new paradigm

The traditional Ethereum model is synchronous and maintains a monolithic state where each transaction is processed sequentially. On the other hand, asynchronous blockchains like TON adopt an actor model approach. This shift leads to several fundamental structural differences:

Ethereum — Synchronous blockchain (monopoly state):

  • Atomic operations: Direct atomic transactions are possible because each transaction (even if it modifies the state of multiple smart contracts) can be treated as a single unit operation. The Ethereum Virtual Machine (EVM), for example, securely isolates all steps in a transaction, ensuring that either all or none of them are executed.

  • Sequential processing: Each transaction must wait for the previous one to complete, which naturally limits throughput and scalability.

  • Global state: All transactions operate on a shared global state, simplifying state management but increasing contention.

TON — Asynchronous Blockchain (Actor Model):

  • Parallel processing: Transactions can be processed concurrently across multiple actors or smart contracts, enhancing overall scalability and throughput. For example, smart contracts on TON are units or actors that can run independently and can use one-way messages to update state between actors.

  • Distributed state: Different actors hold isolated states, they can interact with other actors but do not share a single global state.

  • Coordination Complexity: Implementing atomic operations in this model is complex due to its distributed nature.

While asynchronous blockchains are quite significant in terms of scalability (in theory), the lack of atomic swaps makes TON quite difficult for DeFi development, no matter how difficult the FunC/Tact language is to use. Think about it, without atomic operations and sequential processing, liquidity in the lending protocol becomes very difficult, no matter how challenging the DeFi Lego is.

At LayerPixel and PixelSwap (PixelSwap is using LayerPixel’s infrastructure and is part of LayerPixel), we’ve come up with a new approach to this problem, making atomic swaps possible and working towards a safer, better solution for swaps and DeFi.

从小游戏到DeFi,TON上还缺少什么?

3. Challenges of DeFi composability on asynchronous blockchains

Maintaining composability on asynchronous blockchains introduces complex challenges for DeFi applications, primarily due to the nature of distributed state and parallelism:

Transaction coordination:

  • Synchronization: Coordinating multiple actors to agree on a state at a specific point in time is complex. Unlike synchronizing global state, which simplifies atomic operations, ensuring that multiple independent actors can operate in sync is a huge hurdle.

  • Consistency model: Asynchronous systems often rely on weaker consistency models, such as eventual consistency. Ensuring that all related actors reach a common state without diverging becomes a logistical task.

State consistency:

  • Concurrency control: In a distributed environment, race conditions can arise if multiple transactions attempt to update overlapping states. This requires complex mechanisms to ensure that transactions are properly serialized and do not become a bottleneck in the system.

  • State reconciliation: Different states between actors need to be reconciled, and the rollback mechanism (if some part of the transaction fails) must be strong enough to gracefully undo changes without creating inconsistencies.

Failure handling:

  • Atomicity: In an environment where state is distributed and operations are non-atomic by default, it is challenging to ensure that all parts of a transaction either succeed or all fail.

  • Rollback mechanisms: Efficiently rolling back partial transaction state changes without leaving residual inconsistencies requires advanced techniques.

从小游戏到DeFi,TON上还缺少什么?

4. Pixelswap: Bridging the Combinatorial Gap

Pixelswap's innovative design addresses these challenges by introducing a distributed transaction framework designed specifically for the TON blockchain. The architecture follows the BASE principle (BASE: an ACID alternative) and includes two main components: a 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, and is suitable for long-running distributed transactions:

  • Lifecycle management: Manage the entire transaction lifecycle, breaking it down into a series of smaller, independently executable steps, each with its own compensating actions in case of failure.

  • Task allocation: Break down the main transaction into discrete, isolated tasks and delegate them to appropriate transaction executors.

  • Compensating operations: Ensure that each saga has a corresponding compensating transaction that can be triggered to undo some of the changes and maintain consistency.

Transaction Executor

The transaction executor is responsible for executing the assigned tasks within the transaction lifecycle:

  • Parallel processing: Executors operate simultaneously, maximizing throughput and balancing system load.

  • Modular design for functional expansion: Each transaction executor is designed to be modular, allowing for a variety of functions to be implemented. These functions can include various financial operations such as different swap curves, flash loans, borrowing agreements, etc. This modularity ensures that these functions can be seamlessly coordinated with the Saga transaction manager, maintaining the core principle of DeFi composability.

  • Eventual consistency: ensuring that the local state of the executor is synchronized and reconciled with the overall distributed state of the transaction.

Through these features, Pixelswap’s transaction executor ensures robust, scalable, and asynchronous transaction execution, making it possible to create complex and composable DeFi applications on TON.

5. Conclusion

In summary, the future of DeFi needs to adapt to the paradigm shift from synchronous to asynchronous blockchains while maintaining and enhancing key principles like composability. Pixelswap emerged on the TON blockchain as a groundbreaking solution that elegantly combines robustness, scalability, and composability. By ensuring seamless interoperability and powerful transaction management, Pixelswap paves the way for a more dynamic, scalable, and innovative DeFi ecosystem.