This project is a DEX aggregator and SDK that leverages LayerZero's cross-chain communication capabilities to enable swapping of tokens across multiple chains using preferred synth routes.
The core swap process consists of three components:
- Swap into the synthetic asset (syAsset) on the source chain
- Cross-chain or same-chain SYNTH SWAP
- Swap out of the synthetic asset on the destination chain
The project consists of two main smart contracts:
SourceChainUA.sol
- Handles the swap on the source chain, converting the input token into its synthetic counterpart (syAsset).DestinationChainUA.sol
- Handles the swap on the destination chain, converting the synthetic asset back into the desired token.
Both contracts inherit from NonblockingLzApp
, which facilitates cross-chain communication using LayerZero.
The cross-chain communication is handled using LayerZero's _lzSend
and _nonblockingLzReceive
functions, enabling the swap to be executed across different blockchains seamlessly.
- Install dependencies:
npm install
- Compile the smart contracts:
npx hardhat compile
- Run tests (if any):
npx hardhat test
-
Modify the
hardhat.config.js
file with the appropriate network configurations and API keys. -
Deploy the contracts using Hardhat:
npx hardhat run --network <network_name> scripts/deploy.js
To interact with the deployed contracts, you can use any Ethereum-compatible library (e.g., Web3.js or Ethers.js).
-
Connect to the appropriate network using a provider (e.g., MetaMask or Infura).
-
Create a contract instance for both
SourceChainUA
andDestinationChainUA
using their respective ABI and deployed addresses. -
Call the
swapToSyAsset
function in theSourceChainUA
contract to initiate the swap on the source chain. -
Call the
crossChainSwap
function in theSourceChainUA
contract to send cross-chain messages. -
The
_nonblockingLzReceive
function in theDestinationChainUA
contract will automatically handle the received message, and the contract will initiate the swap on the destination chain. -
Call the
swapSyAssetToBaseAsset
function in theDestinationChainUA
contract to complete the swap process on the destination chain.
This project is licensed under the MIT License.