5.2. Lightning Network swap

Order packages can be integrated into the functionality of a Sequentia wallet to trigger Lightning Network transactions. When a user wants to execute a trade, their wallet recognizes the Lightning Network swap’s specific request, thanks to a specific parameter lightningSwap. It also automatically produces payment invoices and HTLC transactions according to that order request (detailing the exchange rate, amount of tokens, and expiration time).

This solution can be used for directly trading BTC against RAS tokens or trading RAS tokens against each other.

The swap can be executed only if both parties have already established a channel in both exchange pairs. However, these channels do not need to be established directly if there is a Lightning route between them, allowing “assets at the edges” payments (§4.3).

  1. Bob produces an order package asking for an amount (valueB) of tokenB in exchange for an amount (valueA) of tokenA and sends it to Alice.

  2. Alice receives the order package, produces a Lightning Network payment invoice (A) for tokenA, and passes the invoice to Bob.

  3. Bob creates an invoice (B) for tokenB, whose output can be redeemed only by revealing a secret (HTLC contract).

  4. Bob creates a conditional payment to Alice’s invoice (A), hash-locked with the same secret required to redeem the tokenB output paid to invoice B.

  5. Alice pays the invoice (B) by passing the amount (valueB) of tokenB to Bob, as he requested in the order package.

  6. Bob redeems the payment executed by Alice, revealing the secret.

  7. Alice can now redeem the conditional payment sent to invoice A.

The benefits of Lightning Network DEX transactions are speed, privacy, near-zero fees, and no on-chain pollution, with the only limitation that it requires the existence of two different channels (for both the tokens exchanged).

Atomic swaps and Lightning swaps are trading engines that can be coupled with a peer-to-peer communication system that allows swaps between parties that are unknown to each other and have had no prior contact. It is also possible to create multiple swaps splitting a single order into multiple sub-orders, increasing the possibility of finding a match in terms of the amount and price for the pair requested.

Last updated