SUN Network DAppChain Developer Documents: Cross-chain Details
4.1 Overview
DAppChain contains 3 main components for cross-chain interaction: MainChain gateway contract, Oracle service, and Side-chain gateway contract.
Oracle listens to the messages from the main-chain gateway contract and the side-chain gateway contract, and realizes the interactive communication between the main-chains and side-chains. When more than 2/3 of the oracle nodes confirmed an cross-chain transaction, the transaction can be considered to be valid.
Cross-chain interaction can be classified as 3 main type: TRC20/TRC721 contract mapping, asset deposit, and asset withdraw.
4.2 TRC20/TRC721 contract mapping
Asset owner need to trigger TRC20/TRC721 mapping function to approve access for the asset to migrate to side-chain. The asset can be mapping to side-chain automatically, and no one need to deploy by themselves.
Steps:
- Deployer should own(deployed) an TRC20/TRC721 contract on main-chain.
- Asset Deployer should trigger mapping function in gateway contract for owned TRC20/TRC721 contract. Gateway contract will verified the ownership. If verified, an deploy event will be event.
- Oracle catches the deploy event.
- Oracle trigger side-chain gateway contract to create TRON standard side-chain TRC20/TRC721 contract, and do a cross-chain mapping.
4.3 Deposit
User uses deposit function in gateway contract for asset migration to side-chain purpose.
Steps:
- When migrate TRC20/TRC721 token, user need to trigger an approve function in TRC20/TRC721 contract on main-chain.
- User triggers deposit function in MainChain gateway contract.
- Oracle catches deposit event.
- Oracle call function in SideChain gateway for asset migration.
- For TRC20/TRC7212 token, side-chain will mint specific amount of token in the mapped contract, while TRX/TRC10 token will be added directly on user account.
4.4 Withdraw
User uses withdraw function in gateway contract for asset migration to main-chain purpose.
Steps:
- When migrate TRC20/TRC721 token, user need to trigger an approve function in TRC20/TRC721 contract on side-chain. Gateway contract would call TRC20/TRC721 contract directly due to our customization.
- Oracle catches the withdraw event.
- User calls the withdraw function on main-chain.
- MainChain gateway contract calls TRC20/TRC721 contract for withdraw operation, while TRX/TRC10 would be able to send directly to user account.