project screenshot 1
project screenshot 2
project screenshot 3

FusionLink

Atomic swaps, cross-chain and trustless: Fusion Link connects decentralized liquidity across EVMs.

FusionLink

Created At

Unite Defi

Project Description

Fusion Link is an innovative prototype that acts as a trustless liquidity bridge between two EVM-compatible networks: Etherlink and Optimism. It leverages the Fusion+ atomic swap architecture from 1inch to bring key benefits—such as gasless transactions and MEV protection—to Etherlink, a functionality not natively available on the network.

⚙️ How Atomic Swap Magic Works

The system follows a three-step flow orchestrated by smart contracts and a relay service:

Swap Initiation (on Etherlink):

The user begins the process via the DApp.

First, they approve the smart contract to manage a specific amount of tokens.

The DApp then generates a cryptographic pair: a secret (a unique key) and a hashlock (a digital lock derived from the secret).

The user calls createSwap on Etherlink’s SwapFactory contract, which deploys a new smart contract (FusionSwapIntentERC20) acting as a vault that locks their tokens.

Swap Signing (Off-Chain):

Before tokens are sent, the user signs an off-chain message following the EIP712 standard. This signature contains all swap details (amounts, addresses, networks).

The signature is not an on-chain transaction—it’s a cryptographic authorization that gives the relayer permission to execute the swap on their behalf, enabling a gasless experience on the destination chain.

Swap Execution (by the Relayer):

The DApp frontend sends the signature, secret, and swap details to a relayer endpoint (a Next.js server).

The relayer, who holds its own tokens, proceeds quickly:

It sends the corresponding tokens to the user on the Optimism network.

Once the Optimism transaction is confirmed, it returns to Etherlink.

The relayer calls revealSecret on the FusionSwapIntentERC20 contract, publishing the key to unlock the funds.

Finally, it calls executeSwap, which verifies both the secret and signature, and releases the locked funds originally held on Etherlink.

🧱 Key Components of the Architecture

Smart Contracts (Solidity):

SwapFactory: Factory that creates new swap contracts.

FusionSwapIntentERC20: Individual contract managing each swap using hashlocks to ensure atomicity.

Relayer (Next.js API): Backend service linking both networks. It monitors swaps, pays gas on Optimism, and completes the transaction on Etherlink.

Frontend (Next.js, wagmi): User interface allowing simple, secure interaction with the system—guiding users through approval, signature, and swap creation.

🎯 Why It Matters

Fusion Link presents a viable method for connecting liquidity between EVM networks like Optimism and Etherlink. By leveraging atomic swap architecture, it ensures transactions are trustless and secure, while delivering a seamless user experience similar to 1inch Fusion+—without requiring users to manually manage activity across multiple chains.

How it's Made

Smart Contracts: The Foundation of Trust The core logic of our project lives in two Solidity smart contracts deployed on the Etherlink testnet:

SwapFactory.sol: This is the entry point for all swaps. Its primary function is to deploy a new instance of our FusionSwapIntentERC20 contract for every new swap request. We used the CREATE2 opcode to pre-calculate the address of the new swap contract, which is a clever way to ensure the frontend and relayer know exactly where to interact even before the transaction is mined.

FusionSwapIntentERC20.sol: This is the heart of the project. It's an atomic swap contract based on a Hashed Timelock Contract (HTLC) model. It's responsible for:

Locking the user's tokens using a cryptographic hashlock.

Setting a timelock to allow the user to reclaim their funds if the swap isn't completed in time.

Verifying the user's off-chain signature using EIP712, which is crucial for the "gasless" part of the Fusion+ model.

The security of the entire system relies on the fact that these smart contracts, running on the EVM of Etherlink, enforce the rules.

Frontend: The User's Command Center Our user interface is a modern Next.js application, using wagmi and viem to interact seamlessly with the blockchain.

Generating the Secret: The user's journey begins with the frontend generating a cryptographic secreto and its corresponding hashlock. The hashlock is immediately sent to the SwapFactory to create the swap, while the secreto is kept securely in the frontend's state, waiting for the right moment.

EIP712 Signing: After the user approves the tokens and creates the swap, the frontend uses wagmi's useSignTypedData hook to prompt the user to sign an off-chain message. This message contains all the swap details and is the key that authorizes our relayer to act.

Coordinating the Swap: The frontend's role is to guide the user and, once the signature is obtained, it calls our Relayer API, passing along all the critical information, including the user's signature and the secreto.

The Relayer: The Cross-Chain Maestro The relayer is the service that ties both blockchains together. For this hackathon, we built it as a Next.js API route, which was a pragmatic decision given the time constraints.

The Hacky Part: A traditional relayer is a service that constantly listens for events on a blockchain. However, our relayer is an API endpoint that only activates when the frontend sends a POST request. This approach is "hacky" but perfectly suitable for a demo, as it allows us to showcase the entire process without the overhead of running a dedicated server.

The Workflow:

The relayer API receives the user's signature, the secreto, and other swap details from the frontend.

It uses a viem client to connect to Optimism and a viem client for Etherlink.

It first pays a small amount of gas on Optimism to transfer the tokens to the user.

Once that transaction is successful, it uses the secreto to call revealSecret and executeSwap on the Etherlink contract, finalizing the swap.

How We Leveraged Partner Technologies Our project would not have been possible without these key technologies:

Etherlink: Provided us with a fast, low-cost EVM Layer 2 to deploy our core smart contracts. The compatibility with standard Ethereum tooling allowed us to build the project quickly using familiar libraries like viem and wagmi.

1inch Fusion+: This architecture served as our primary inspiration. By implementing a system with a relayer, off-chain signing, and atomic swap logic, we replicated the core principles of Fusion+ to deliver a "gasless" and secure cross-chain experience.

background image mobile

Join the mailing list

Get the latest news and updates