Unified Interface for Cross-Chain Functionality
More and more protocols and chains have been releasing functionality around cross-chain messaging and token transfers. With Modular Contracts being released in beta, we saw this as an opportunity to partner up and create modules around these functionalities.
However, as we explored deeper into each protocol's cross-chain mechanisms, we noticed a significant amount of overlap across all functionalities, including:
- A function to handle sending cross-chain payloads and tokens
- A function to handle receiving cross-chain payloads and tokens
- Setter and getter functions for their version of a router
With that in mind, we decided to create CrossChain.sol, an abstract contract that provides a unified interface to implement cross-chain functionality across any protocol.
Inside the contract CrossChain.sol, there are three main functions:
sendCrossChainTransaction
As the name suggests, this is the primary function responsible for sending cross-chain transactions from the protocol.
onCrossChainTransactionSent
This callback function is used within the context of the sendCrossChainTransaction
function.
onCrossChainTransactionReceived
This callback function is used within the context of the receive function for the specified cross-chain protocol.
With these two callback functions, the user’s application logic can be separated from the cross-chain functionality logic, making it easier to differentiate between the two.
And there you have it—an abstract contract to create a unified interface for cross-chain functionality.
If you want to find out more, check out the code here:
https://github.com/thirdweb-dev/modular-contracts