Inspiration

Interoperability is considered complex and presents significant challenges, especially in allowing assets and data to move freely and securely across different blockchains. In addition to Chainlink's CCIP providing limited asset transfer of tokens such as USDC or GHO, the inspiration for cross-chain token transfers stems from the vision of interconnected token and asset transfers across multiple networks catering to an expansive token ecosystem. LinkSwap is able to create a protocol/service that leverages purely on Chainlink's services such as Cross-Chain Interoperability Protocol (CCIP), Functions, Automation, and Data Feeds to provide a robust solution for cross-chain token transfers of any tokens.

What it does

LinkSwap functions as a token transfer mechanism. At its core, it's a straightforward user interface enabling token-swapping interactions. However, it operates by utilizing Chainlink Functions and consuming validation endpoints provided by LinkSwap. These functions perform various checks, including compatibility, token validations, liquidity, and user transactions with the tokens. This computational process enables on-chain swaps that utilize Chainlink messaging. By leveraging Chainlink Functions, we can conduct these computations off-chain, providing secure and manageable validation for the CCIP on-chain.

Currently in the testnet, we have mimicked some tokens on various chains. To showcase LinkSwap, not all tokens will be available on every chain. You can interact with and obtain these tokens using our faucet and use them to perform cross-chain transfers to see how LinkSwap works. **Please note that these tokens are NOT representations of any real assets. You can access the faucet here:**

LinkSwap Faucet

img

Throughout token transfer/swap process, important messages are generated to pass information across chains. The purpose is to encode necessary data in a gas-efficient manner and relay these messages from Chainlink Functions to Source CCIP and Destination CCIP without issues.

Note: The following are helper contracts used for development purposes to encode and decode. LinkSwap utilizes the library version available on GitHub.

The CCIP Parser library encodes and decodes token transfer information into a uint256 format. This includes details such as the token address, amount, and receiver.

To make it easier for developers, there is a page that explains how these parsers work. You can specify a chain, its supported tokens, the sender, and the amount. This data will be the underlying data sent to CCIP: CCIP Data Builder.

The Function Parser helps with Function Bytes conversion on-chain. Since Chainlink Functions store off-chain data as bytes, the Function Parser unpacks the byte information into a struct, allowing CCIP to use this information on-chain and initiate the cross-chain transaction.

Similarly, there is a page where developers can simulate the validation process to see if the CCIP will be successful when performing the token transfer. Users can pass the CCIP data packed by the CCIP Builder and process it via the validation API. If successful, the result will be displayed and passed to the Functions: Functions Simulation.

Essentially, the data can be encoded and decoded from uint256 to struct and vice versa allowing LinkSwap to pass data. The goal is to ensure LinkSwap is transparent and to help users understand the token transfer process.

For more information on using LinkSwap, it's best to watch the provided demo video: LinkSwap Demo Video.

LinkSwap integrates into a single, straightforward web page, abstracting the process as a swap-like interface. Here, we utilize WalletConnect to enable users to easily interact with supported CCIP chains via MetaMask. Through the provided page, users can send tokens either to themselves or to another individual on a different chain by entering the recipient's address.

img

Then, we can select a destination chain. Choosing a destination chain will display all compatible tokens that exist on both the selected source chain (determined via the browser) and the chosen destination chain (that the user just selected).

img img

Afterwards, the user can input a value based on the token balance available and confirm it using the summary displayed at the bottom of the transfer component. The image below illustrates that the user is sending 100 BAT from Ethereum Sepolia to the receiver address on Optimism Sepolia.

img

Once the user is content with the transaction details, they must approve the exact amount before initiating the token transfer through the LinkSwap contracts. This action triggers the cross-chain transfer process. The subsequent section will detail the steps to complete this transfer.

img img

Upon completion of the process, the user should observe a message ID or transaction hash displayed at the top of the page, indicating that the transfer is currently undergoing CCIP.

img

They can monitor the transaction on the CCIP Explorer and wait for the confirmation to verify that the BAT tokens have been successfully sent to the receiver's address on Optimism Sepolia.

img

How we built it

So with the basics covered in LinkSwap, the entire flow is as follows:

  1. User Starts Transaction:

    • πŸ—ΊοΈ Select the source and destination chains.
    • πŸ’° Approve the amount to send for the selected token using Chainlink Data Feeds.
    • βš™οΈ Call the Functions if the source chain supports Chainlink Functions.
    • πŸ› οΈ Otherwise, perform off-chain validation and call CCIP directly.
  2. Chainlink Functions Validation:

    • πŸ” Chainlink Functions call the LinkSwap validation API.
    • βœ… If successful, return the byte result containing information about the destination chain.
    • πŸ“’ Emit an event to trigger Chainlink Automation to start the CCIP contract.
    • ❌ If unsuccessful, revert the transaction in Functions, and the transfer will not be made.
  3. Chainlink Automation:

    • πŸš€ Triggered via log event and processes the data from the event, including results from the Functions and the CCIP message sent to the Functions.
    • πŸ“¦ The Upkeeper unpacks any necessary data for the CCIP.
  4. Chainlink CCIP:

    • πŸ”— Called to begin the token transfer.
    • πŸ†” Returns a message ID for the Upkeeper to emit, which developers and LinkSwap can use to provide users with transaction status updates.

Challenges we ran into

While I have experience with Chainlink on a previous hackathon, it was completely different and utilized AnyAPI. Hence we had to learning the other services which was challenging but a very rewarding experience. We were able to learn and create so much in just a few weeks. There were technical challenges when creating LinkSwap, such as hitting the gas limit for Functions. Our initial implementation involved creating a direct connection from Chainlink Functions to the CCIP service. However, when calling the CCIP contracts from Functions, we hit the maximum 300_000 gas limit. Increasing this limit was not an option, and Discord suggested contacting Chainlink to increase it. Instead, we took the opportunity to learn about another Chainlink service called Automation, which supports log-based triggers. Consequently, the LinkSwap contracts were refactored to support this.

Another challenge was the lack of testnet tokens and a faucet, which led us to create mock tokens to mimic mainnet assets. These included BAT and Uniswap tokens that had Chainlink Data Feeds, used to calculate the amount of tokens for transfers. Understanding this was important when implementing swaps.

Additionally, the lack of support for blockchain across different services was another issue. For example, GNOSIS and WEMIX are not supported in Functions, and BASE Sepolia and ARBITRUM Sepolia are not supported in Automation. Though we don't think this will be an issue when moving to mainnet, we had to develop new strategies to support these chains in the meantime.

What's next for LinkSwap

LinkSwap has significant potential to be more. While we only implemented supporting same-token transfers, our smart contracts are designed to enable different token transfers, enabling cross-chain swaps. By leveraging Functions and Price Data, we can validate swaps, ensuring that all tokens are supported, liquid, and approved and calculated correctly from source to destination. This allows us to generate the necessary data off-chain and on-chain for CCIP to initiate on-chain swaps.

In addition, while creating LinkSwap we also came up with the idea of leveraging LinkSwap as a P2P cross-chain token service. An example of this is that User 1 on Chain 1 can request 100 X from Chain 2, while User 2 on Chain 2 may wish to transfer 100 X to Chain 1. LinkSwap can be adapted to support such transactions, creating a decentralized cross-chain P2P platform where users can seamlessly exchange tokens. While this idea is currently in the conceptual, it was an opportunity for further exploration that could work with LinkSwap.

Thanks for visiting and reading this hackathon project! πŸ”—πŸ”„

Built With

  • automation
  • ccip
  • data
  • evm
  • functions
Share this project:

Updates