Understanding Celer cross-chain message framework in one article: a new model for developing and using multi-chain applications
CelerNetwork
2022-01-14 10:48
本文约5195字,阅读全文需要约21分钟
The Celer cross-chain message framework is now officially launched and launched on the test network.

The Celer Inter-chain Message framework (Celer Inter-chain Message, hereinafter referred to as Celer IM) is now officially launched and launched on the test network!

andto developanduse paradigm. Developers can now develop dApps that share liquidity and program state across multiple chains through Celer IM. Users can enjoy liquidity and applications on multiple blockchain ecosystems with one click through Celer IM without having to manually cross and switch between multiple blockchains for complex interactions.

Celer IM letsCross-chain composability possible, resulting in a series of new models"Native cross-chain dApp". Examples are as follows:

  • DEXyield aggregator

  • yield aggregatorloan agreement

  • loan agreementCan allow users to provide collateral on one chain and lend assets on a completely different chain

  • DAO Governance ProtocolAllows for a unified multi-chain governance mechanism without the need to move assets between different chains

  • In the NFT market, users from one chain can bid on NFT auctions on a completely different chain

  • Metaverse Games, users can seamlessly interact with virtual items of various chains in the game

  • New cross-chain asset bridge, in fact cBridge can be seen as an asset bridge built on Celer IM

Almost every dApp deployed on multiple chains can benefit from using the Celer IM framework.

The Celer IM framework is very easy to use, allowing"Plug and play"plugin contractplugin contractIt can be transformed into a native cross-chain DEX.

Demo demo video

In this demonstration, users of Sushiswap can exchange ETH on Arbitrum for BNB of BSC with just one operation. In the entire Celer IM system, the following steps are automatically and decentralized:

  • Exchange ETH on Arbitrum for USDT in Sushiswap

  • Bridge USDT from Arbitrum to BSC

  • Exchange bridged USDT for BNB on BSC

Celer IM has been launched on the testnet and releasedanddevelopment documentationSmart Contract Frameworkandsample application code. We are actively looking for developer partners to jointly create powerful and user-friendly native cross-chain dApps. If you are interested in collaborating,first level title

A new model of "multi-chain native dApp"

The current common practice of developing multi-chain dApps is to simply completeDuplicate the same code on multiple chains, the liquidity, application logic and state of these dApps on different chains arecompletely isolated. In fact, apart from UI and assets, there is nothing shared between these dApps.

This approach usually suffers from low liquidity efficiency, state fragmentation, and user experience degradation. Celer IM enables users to enjoy higher liquidity efficiency and unified application logic through "one-click operation" by realizing cross-chain contract calls and messaging, so that these dApps based on Celer IM can mine the true value of the multi-chain blockchain world. potential.

secondary title

DEX

Today, a multi-chain DEX must build liquidity pools for the same key asset pairs on each chain it is deployed on. Therefore, the DEX has to create liquidity incentives for these asset pairs on all these different chains. While the aggregate liquidity across all chains may be quite high, the depth of liquidity per pool on each chain is actually quite fragmented. Unfortunately, this creates high slippage, which affects the overall trading experience. Also, if a user wants to trade an asset that has deep liquidity on a different chain, he has to manually convert it on the original chain, use a separate fund bridge application, and then switch to another chain for the final swap.

loan agreement

loan agreement

Today, if users provide collateral in a lending protocol on one chain, they can only borrow assets on that same chain. In order to lend assets from a different chain, they must withdraw liquidity, manually move it to a different chain, and then provide liquidity in the new chain's collateral pool.

NFT market

NFT market

Today, if users want to participate in NFT auctions, they must have funds on the blockchain where the NFT is hosted. But often there are people who want to participate in the auction but don't have the funds on that particular chain. Take OpenSea as an example, because it is currently an NFT market only deployed on Ethereum, the complex bridging operation and high gas costs exclude many users on other chains from participating in NFT transactions on OpenSea.

first level title

Celer IM Architecture and Design Patterns

So, how do these native cross-chain dApps come about, and what do developers need to build?

secondary title

Cross-chain logic accompanying fund transfer

For many native cross-chain applications, the core process usually involves sending funds to one or more chains, and using those cross-chain funds to "do other tasks" on the target chain. The DEX demo given above actually uses this design pattern. In the following introduction, we will also provide specific code links for DEX demos.

Although the above flow chart looks a bit complicated, most of the process is actually completed by Celer IM. dApp developers only need to buildIM architecture application templateTwo simple functions in .

Step 1: The user initiates a transaction to the dApp

In Celer IM, users no longer directly interact with dApp’s existing smart contracts, but interact with a new dApp Plug-in contract (marked A) to express the cross-chain logic they want to execute. This dApp Plug-in becomes part of the entire dApp business logic and can interact with the existing smart contracts of the dApp on the source chain. The interaction with the dApp Plug-in contract is usually the only transaction issued by the user to interact with this cross-chain dApp.

In the DEX example shown,transferWithSwapThe function is the starting point of the whole process, which allows users to express cross-chain logical requests, such as "first exchange Token A for Token B on the X chain, and then exchange the changed Token B for Token C on the Y chain".

Of course, it is often the case that users do not specify these requests manually, and dApps using the Celer IM framework should build more abstract user targets for calling such functions.

Step 2: dApp Plug-in sends the message and related funds cross-chain request

After completing the necessary operations on the source chain, the dApp Plug-in will send the converted funds and related messages to the target chain (marked B and C). The message explains what needs to be done on the target chain. at thisDEX exampleIn , the message is "Swap the cross-chain Token B for Token C, and then send Token C to the user". just callsendMessageWithTransfer, messages and funds transfers willautomatically linked together. The message is then sent toMessage BusNotice:

Notice:In this application mode, Celer IM is compatible with other asset bridges. Take cBridge as an example because cBridge is the first asset bridge supported by IM.

Step 3: State Guardian Network (SGN) passes messages and funds cross-chain requests

To help you understand this step, we first introduce a core component in Celer IM: the State Guardian Network (SGN). SGN itself is a proof-of-stake (PoS) blockchain built on Tendermint. Under the IM architecture, it is anmessage router. Node providers must pledge CELR to become validators and join the consensus process of SGN. SGN uses the same security mechanism as L1 blockchains such as Cosmos and Polygon PoS chains. SGN's CELR pledge and penalty mechanisms are implemented on the Ethereum L1 smart contract.

SGN pledged nodes will continuously monitor the transactions that occur on all connected chains. When a transaction triggers a message containing a scheduledheader-payload formatWhen a cross-chain message event occurs (mark D), the verification node will first reach a consensus on "whether the message exists" and generate a weighted multi-signature certificate at the same time. Then, this proof is stored on the SGN chain, waiting for the Executor subscribing to the message to be relayed to the target chain (marked H).

For asset cross-chain, we can regard the cBridge contract as a Message Bus with asset cross-chain optimization. SGN will carry out a consensus and proof process similar to message cross-chain (mark E). However, when assets cross-chain, the SGN verifier will not relay the built-in asset cross-chain proof to an Executor under the chain, but directly send the on-chain transaction to the cBridge contract (marked F) on the target chain, and trigger Fund transfer, sent to the dApp Plug-in contract (marked G) on the target chain. Once again, I want to emphasize to everyone that Celer IM can be connected to any asset cross-chain bridge, but first of all, Celer's cBridge is supported by default.

Step 4: Executor executes cross-chain application logic

The task of the Executor is to read the weighted multi-signature certificate from the SGN blockchain and simply relay it to the Message Bus (mark I) on the target chain. Anyone can run an Executor for any application, since its function is only to relay messages. Of course, dApps should consider giving incentives to Executors, because Executors are responsible for sending transactions and paying gas fees on the target chain.

The role of the Message Bus on the target chain is to check the validity of the proof message and confirm that the dApp Plug-in has indeed received the relevant payment (mark J). Afterwards, the Message Bus will pass the message (logic execution instruction) to the dApp Plug-in contract (marked K) that carries the cross-chain business logic of the dApp on the target chain.

The dApp Plug-in on the target chain only needs to implementexecuteMessageWithTransferinterface. In our DEX example given,this functionThe logic of "exchanging Token B for Token C" will be executed on the target chain.

Cross-chain logic without fund transfer

Of course, sending cross-chain messages or logically executing instructions does not necessarily accompany the transfer of funds. For example, in the NFT market, if users participate in auctions on other chains, they do not need to actually transfer funds to the target chain, but only need to lock funds in the source chain, and then they can bid to participate in the auction. Only after winning the auction, users need to transfer funds across chains.


This flow is just a simplified version of the first pattern. dApp Plug-in only needs to implement logic calls on the source chainsendMessage, and then implemented in the dApp Plug-in contract on the target chainexecuteMessage

Troubleshooting

Due to the asynchronous nature of the above-mentioned cross-chain message pattern, the application logic should include fault handling considerations. In these application modes, failures can occur in the following three steps, which should be handled accordingly:

  1. The source chain dApp logic execution failed. This has nothing to do with Celer IM and should be handled by the dApp business logic itself. Fault example: DEX Token exchange exceeds the time limit.

  2. Cross-chain bridge asset cross-chain failure. The source chain dApp will be notified through a common interface and should process the returned asset by retrying the asset cross-chain or sending the asset back to the user.

  3. The target chain dApp logic execution failed. When user funds reach the target chain, there is still a possibility that the dApp logic execution on the target chain may fail. dApp developers should be prepared to implement some fallback functions in case of such failures. Common ways to deal with such failures are: stop executing logic and send funds to users on the target chain; or transfer funds back to the source chain. But what kind of fallback function logic to implement is entirely up to the dApp developer.

development documentationdevelopment documentationfirst level title

On-chain value accumulation and fees

From the above two models, it can be clearly seen that if Celer IM is to run smoothly, CELR stakers and verifiers in SGN are essential.

first level title

It is very simple to use Celer IM to build a native cross-chain dApp

In the Celer IM architecture, whether it is to expand the market size of an existing dApp or build a brand new dApp, it is very simple to implement, and only needs to follow the following three steps:

orsendMessageorsendMessageWithTransferorexecuteMessageorexecuteMessageWithTransferfunction.

The second step is to run the Executor. This step requires no coding. Both dApp development or community members can run an Executor and subscribe to relevant message certificates generated on SGN.

The final step is to make UI/UX tweaks. Since the cross-chain logic that the application now has may involve multiple transactions, it is naturally very important for users to understand the different states of a cross-chain behavior. The specific display of the UI depends on the application itself of course, but Celer IM provides an easy-to-query gateway service that allows dApps to obtain information and cross-chain status of funds, allowing dApp developers to build a complete life cycle of a cross-chain transaction.

We are looking for dApp partners to build the Celer IM ecosystem together. Celer will provide technical support for partners, and we are also setting up special funding support, and will provide more details later. If you are interested in joining the Celer IM ecosystem,Please contact us

CelerNetwork
作者文库