- Project Overview
- Core Concepts: HTLC
- Architecture & Flow Diagrams
- Contract Details
- Setup & Deployment
- Manual Testing Guide
- Future Work & Enhancements
- Contributing & License
This repository demonstrates a cross-chain atomic swap between the Sui blockchain (Move) and Ethereum (Solidity) using Hashed Timelock Contracts (HTLCs). It includes:
- On-Chain Components: Sui
escrow_factory
Move module (simple swap and partial fills); EthereumTestEscrowFactory
,Resolver
, and predeployed mainnet contracts for 1inch LOP and ERC20. - Off-Chain Relayer: A conceptual service to monitor events, propagate secrets, and manage timelock-based redemption/refund across chains.
HTLCs ensure atomicity via two primitives:
- Hashlock: Locks funds behind a cryptographic hash (
secret_hash
). Revealing the preimage (secret
) redeems the funds. - Timelock: Allows refunding locked funds after a deadline if the secret is not revealed.
Swap Flow:
For SUI -> ETH swap
- Maker announces his/her signed order with the secret to the relayer , which in turn the relayer annouces to all resolvers.
- Resolver locks maker Sui tokens → HTLC-A with
timelock_A
. - Relayer locks Ethereum → HTLC-B with
timelock_B < timelock_A
. - Relayer redeems HTLC-A (reveals
secret
). - Realayer redeems HTLC-B for maker using revealed
secret
.
If either party misses the window, they can refund their own HTLC after expiry. Similarly for ETH -> SUI swap
flowchart TB
subgraph Sui Chain
A(Maker) -->|create_src_escrow| B[escrow_factory]
B --> C[SrcEscrowCreated Event]
end
subgraph Off-Chain Relayer
C --> D[Event Listener]
D --> E[Relayer Logic]
end
subgraph Ethereum Chain
E -->|initiateDstSwap| F[Resolver.sol]
F --> G[TestEscrowFactory]
G --> H[DstEscrowCreated Event]
end
H --> D
D -->|secret| B
B -->|redeem| A
timeline
title HTLC Timelock Sequence
2025-08-03 : Maker sets Sui timelock T_A = now + 60m
2025-08-03 : Relayer sets ETH timelock T_B = now + 30m
2025-08-03 : Relayer redeems on Sui (secret revealed by relayer)
2025-08-03 : Relayer redeems on Ethereum
This ensures Relayer always has time to reveal before their own funds unlock.
escrow_factory for single fill swap
: Handlescreate_src_escrow
,create_dst_escrow
,redeem
, andrefund
. Emits events and enforces timelocks.escrow_factory for partial fill swap
: Handlescreate_src_escrow
,place_order
,fill_order
,create_dst_escrow
,redeem
, andrefund
. Emits events and enforces timelocks.
TestEscrowFactory.sol
: Factory for per-swapTestEscrow
contracts.Resolver.sol
: OrchestratesinitiateDstSwap
,redeem
, andrefund
. Integrates mock 1inch LOP viaIOrderMixin
.
- Git, Rust, Cargo (for move and sui tools)
- Sui CLI
- Foundry (
forge
,anvil
) - Node.js & pnpm/npm/yarn (optional for frontend)
-
Start Sui:
To connect with the devnet: 1) sui client new-env --alias devnet --rpc https://fullnode.devnet.sui.io:443 2) sui client switch -env devnet
-
Start Ethereum:
1) Create account on Tenderly 2) fork the chain on which you want to work on 3) save the RPC URL in env 4) Fund the wallets
cd sui_contracts/fusion_contracts
sui client publish --gas-budget 10000000 # escrow_factory
cd ethereum_contracts
forge install
# Set PRIVATE_KEY & INITIAL_OWNER env vars
forge script script/Deploy.s.sol --rpc-url <RPC_URL> --broadcast
create table if not exists "Relayer_Data" (
secret_hash text primary key,
secret text not null,
intent_announcer text not null,
chain_src text not null,
chain_dst text not null,
token_src text not null,
token_dst text not null,
amount_src text not null,
min_swap_amount text not null,
timelock bigint not null,
escrow_creator text,
src_escrow_id text,
dst_escrow_id text,
src_escrow_status text not null,
dst_escrow_status text not null,
status text not null,
created_at timestamp with time zone default now(),
updated_at timestamp with time zone default now()
);
create table if not exists "Adv_Relayer_Data" (
secret_hash text primary key,
secret text not null,
intent_announcer text not null,
chain_src text not null,
chain_dst text not null,
token_src text not null,
token_dst text not null,
amount_src text not null,
swap_amount text not null,
timelock bigint not null,
escrow_creator text,
src_escrow_id text,
dst_order_id text,
resolvers text[],
resolvers_balance integer[],
src_escrow_status text not null,
dst_order_status text not null,
status text not null,
created_at timestamp with time zone default now(),
updated_at timestamp with time zone default now()
);
-
cross_chain_resolver_example folder (tests)
- pnpm i
- forge install
- pnpm test <TEST_PATH>
-
sui_contracts folder
- sui publish
-
x_susion (Frontend)
- pnpm i
- pnpm run dev
- Automated Relayer Service (Node.js)
- Support additional Sui tokens (e.g., Coin)
- Decentralized relayer network with staking
- Complete Frontend UI & UX
Licensed under MIT. See LICENSE for details.