Settling trades via Payment Channel Network Swaps
Before understanding how to use Payment Channel Network swaps are used to settle trades, it's important to know how Payment Channel Network swaps and Payment Channel Network payments work to begin with. Check out Lightning Labs blog post on cross-chain atomic swaps on Lightning Network for some background information.
In order to complete a Payment Channel Network swap, two brokers need to communicate and agree on a few facts:
- which broker will be initiating the swap, and which will be translating (accepting one currency and sending the other)
- how much of one currency will be swapped for the other currency
- how to each each respective broker on their respective Payment Channel Networks
For now, let's consider that communication to be complete and established as it is handled in future layers. The swap proceeds in a series of Acts.
Act 1: Swap Preparation
- The Initiating Broker creates an invoice with the expected amount of currency received on his Payment Channel Network node, generating in the process a preimage and hash for the swap (the swap hash).
- The Initiating Broker communicates the swap hash to the Translating Broker out of band.
- The Translating Broker creates a forwarding entry to associate the swap hash with the amount of currency to be exchanged, whitelisting the swap.
Act 2: Swap Setup
- The Initiating Broker extends an irrevocable promise of payment of the Initial Currency (an HTLC) to the Translating Broker, locked by the swap hash.
- The Translating Broker verifies that the amount of the Initial Currency extended was expected according to the forwarding entry from Act 1: Step 3.
- The Translating Broker extends an irrevocable promise of payment of the Final Currency in the amount specified by the forwarding entry to the Initiating Broker, locked by the swap hash.
- The Initiating Broker verifies that the amount of the Final Currency extended was expected according to the invoice from Act 1: Step 1.
Act 3: Swap Settlement
- The Initiating Broker settles the payment in Final Currency using the preimage from Act 1: Step 1, moving the Final Currency from the Translating Broker to the Initiating Broker.
- The Translating Broker settles the payment in Initial Currency using the preimage revealed in Act 3: Step 1, moving the Initial Currency from the Initiating Broker to the Translating Broker.
For more details on how swap execution proceeds at a technical level with sparkswap Brokers, read the documentation for the Interchain Router.