project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4
project screenshot 5
project screenshot 6

tuna+

Intent based atomic cross chain swaps for Ethereum, Aptos and Bitcoin

tuna+

Created At

Unite Defi

Project Description

We implemented an intent-based cross-chain atomic swap between Aptos, Bitcoin, and Ethereum
 while preserving timelock and hashlock functionalities in non-EVM environments.


It is cryptographically secure, which means funds will remain locked until the secret is released.
It is also fault-proof thanks to timelock functionality, which ensures funds can be refunded after the expiration of the timelock by the maker.

We followed a similar pattern with Fusion+, utilizing resolver and implementing limit order functionality in our contracts. 
To make it more clear, intents of executing a cross-chain swap will be signed by a maker through the UI, and this intent will be submitted as a
meta transaction to the contract by a resolver. After swaps are initiated on source and destination chains, the user releases the secret and the resolver 
completes swaps.

We also developed a seamless frontend submitting cross-chain swaps and tracking them. All combined, we achieved similar user experience with Fusion+ in non-EVM chains.

Aptos

In Aptos, we utilized fungible assets with a limit order contract.

1- Maker signs an intent of a swap using their fungible assets through the UI 
2- This swap intent is accepted by a resolver
 3- Resolver submits the meta transaction, generates the source Escrow, and fills the user's order by exchanging APT with a fungible asset 
4- Resolver initiates a counter swap and generates the destination Escrow 
5- Maker shares the secret after both Escrows are created
 6- Resolver completes the swap on source and destination chains

Bitcoin

In Bitcoin, we used HTLCs. With hashlock and timelock, it ensures the security of the UTXO.
 To execute cross-chain swaps with Bitcoin, we developed Node.js scripts instead of using the UI. In Bitcoin, the resolver accepts the swaps after the locking transaction is submitted on-chain. 1- Maker submits an HTLC on-chain 
2- Maker shares their intent of swap with the resolver, sending hashlock, timelock, amount, and destination information 
3- Resolver verifies the HTLC and creates a destination escrow, shares it with the maker 
4- Maker shares the secret with the resolver 
5- Resolver unlocks the UTXO with a correct script and completes the destination escrow

How it's Made

In Aptos, Move language is used to develop contracts and tests, which ensures the security and bug-free functionality. Aptos CLI is used to deploy contracts to local environment and testnet for manual testing. Move Events allowed our services to keep track of pending/completed/refunded swaps.

Fungible assets are used with limit order-like protocol to mimic Fusion+ functionality. In order to achieve intent-based cross-chain swap, we implemented meta transaction functionality. Users can also give allowance to contract to spend fungible assets on behalf of them. All these functionalities allow users to experience fully intent-based swap without ever needing to pay for gas and tokens upfront.

Hardhat is used for deploying/testing and debugging EVM smart contracts in local and testnet environment. We used ethers library to generate secret, hash pairs, interact with contracts, sign intents, and send transactions. For secure interactions, reentrancy guard and prechecks are implemented. Custom errors are used to give end users more insightful responses. Solidity Events are used for tracking Escrow’s statuses.

The contract uses meta transactions for generating new Escrows in order to achieve a true intent-based cross-chain swap functionality. To also implement limit order protocol functionality, the main contract uses ERC20 standard and allows resolvers to fill orders.

The frontend is developed using React, MUI. Aptos SDK and ethers library are used for signing meta transactions and tracking contract events for displaying Escrows to end users. A set of functions is developed for interacting with resolvers via API calls.

Secret-hashlock pair generation is executed with ethers library. Secret is stored in memory for security concerns and shared with the resolver when both Escrows are generated.

Node.js is used for developing a Resolver application. A set of API endpoints are available for informing swap intents, submitting signed meta transactions, and sharing secrets, which is followed by completing Escrows.

For local Bitcoin development environment, bitcoind, bitcoin-cli is used. The project uses bitcoinjs-lib for building transactions, managing wallets, funding, building, and spending HTLCs.

These functionalities implement a POC for intent-based cross-chain swaps.

background image mobile

Join the mailing list

Get the latest news and updates