crypto

Atomic on-chain LTC to off-chain BTC swap

Atomic on-chain LTC to off-chain BTC swap

Bitcoin lightning has been enabled for some time and has more than two thousand nodes.

A BTC user who wants to use lightning applications like Satoshi’s Place need to be a participant of the lightning network that requires the user to setup a BTC full node and run a lightning daemon. For non-BTC users, they have to convert their coins into BTC, setup a BTC full node and run a lightning daemon. It would be very convenient if there is a swap service that can take their on-chain coins and pay their lightning invoice.

Submarine Swaps

Submarine Swaps are an atomic on-chain to off-chain swap service created by Alex Bosworth. It receives your on-chain BTC and pays for your off-chain BTC lightning invoice. It’s an atomic swap which means if your invoice is not paid within a specified time period you can get back the on-chain BTC that you sent.crypto

You can try the on-chain tBTC to off-chain tBTC swap at https://submarineswaps.org/. The atomic swaps rely on a script contract that is similar to the following:

The “paymentHash” is the hash of the preimage and is presented in the lightning invoice. The preimage will be revealed to the payer of the lightning invoice after payment. The swap service provider pays the invoice to get the preimage and use it as a proof of payment to claim the fund at swap address. If the invoice is not paid the swap service provider will not have the preimage and cannot move the fund at swap address. After a specified time, the user can move the fund at swap address back to the refund address which is controlled by the user.

Cross-chain submarine swap

Same chain swap is good but cross-chain swap is even better. I forked the submarine swaps project and make it able to swap on-chain LTC to off-chain BTC. Now users can pay BTC lightning invoice with on-chain LTC.

Here is how the cross-chain swap works:

  1. A user presents a valid BTC lightning invoice and on-chain LTC refund address (if not using “refund paper wallet”).
  2. Swap service provider creates the contract(as discussed above) and gives a P2SH LTC address(a.k.a. swap address) that encoded the hash of the contract script.
  3. The user pays the amount specified by swap service provide to the swap address.
  4. After funds transfer to the swap address are confirmed, swap service provider pays the LN invoice and then claim the funds at swap address.
  5. If the lightning invoice is not paid, the user moves the fund at swap address to the refund address that is controlled by the user.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.