How Submarine Swaps Power REDSHIFT Cross-chain Payments
REDSHIFT and Submarine Swaps explained
What is REDSHIFT?
RADAR launched REDSHIFT in November to allow people to use on-chain assets like Bitcoin, Ethereum, and ERC-20 tokens for Lightning Bitcoin payments without signing up for an account or giving up custody of their assets to a third party.
REDSHIFT provides a new way for people, businesses, and developers to use the Lightning Network via trustless transactions across tokens and blockchains. See our Introducing REDSHIFT article for more high-level context on what REDSHIFT is and how it works. One thing that we haven’t yet covered is the mechanism that enables the on-chain to off-chain payment; the submarine swap.
What is a submarine swap?
Submarine swaps are a relatively new technology that has been ushered into the cryptocurrency space with the advent of Bitcoin’s Lightning Network. At their core, submarine swaps are a trustless way for two parties to exchange an on-chain asset such as Bitcoin for an off-chain asset like Lightning Bitcoin.
The on-chain/off-chain characteristic of the swap is similar to a submarine’s periscope — where part of the submarine exists above the water’s surface while the other half remains hidden in the sea — hence the name Submarine Swap.
Submarine swaps utilize a type of smart contract called a Hash Time Lock Contract (HTLC).
HTLCs have been used in the past to atomically swap assets that exist on different blockchains at the base layer. The first one happened between Decred and Litecoin in 2017. On the Bitcoin Lightning Network, HTLCs are essentially programmable escrows that lock up funds on-chain until either:
(1) they are claimed using the secret returned from paying the specified lightning invoice
(2) a specified amount of time or blocks has passed.
In case (1), the payment secret to unlock the funds is only revealed after the corresponding Lightning invoice has been paid. This means that in order to take control of the on-chain funds, the counterparty must pay the Lightning Network invoice that contains the payment hash used in the hashlock.
If the counterparty does not pay the Lightning Network invoice, then case (2) happens and the funds remain in escrow until the timelock expires. Once the timelock expires, if there are still funds in the escrow, the original sender of the funds can withdraw them by creating another transaction to send them back to themselves.
The value of Submarine Swaps
Submarine swaps are a powerful tool that enables digital assets on different protocol layers and blockchains to be exchanged without a middleman. These cross-chain swaps don’t require another party to custody assets while a trade is taking place, which eliminates the risk of bad actors stealing funds before trades have completed, delays in service due to exchange outages, or third-party limits and fees.
More importantly in the context of Bitcoin, submarine swaps improve the liquidity of Bitcoin’s Lightning Network by allowing nodes to increase their outgoing capacity without having to close and re-open channels with peers; nodes can request more outgoing or incoming capacity from others on the Lightning Network in exchange for an on-chain or off-chain payment respectively. This reduces the total amount of fees spent by 50% since only one transaction is required to participate in a submarine swap instead of two transactions to close and re-open a channel.
While traditional exchanges are beginning to roll out features that allow users to withdraw their Bitcoin via the Lightning Network, centralized exchanges still have their downsides:
- Account setup and KYC/AML requirements
- Limits and delays on withdrawals
- Deposit/Withdrawal fees
- Risk of hacks or stolen funds
Remember: Not your keys, not your Bitcoin!
REDSHIFT is the plumbing that connects users looking to exchange their on-chain assets for liquidity on the Lightning Network.
REDSHIFT receives Lightning invoices from users and pays them in exchange for an on-chain asset. By going through REDSHIFT users are able to:
- Make a Lightning payment without setting up Lightning infrastructure
- Rebalance their existing channels without closing and reopening
- Pay a merchant/app that only accepts Lightning payments with other assets
Because these two use cases likely have different types of users participating in them, we designed REDSHIFT as a Developer SDK and built a standalone widget which can be embedded into any website or existing checkout flow.
Once an invoice is submitted through the SDK or widget, REDSHIFT alerts our network of liquidity providers who respond with a price quote of how much they will charge to pay the invoice. REDSHIFT collects these quote responses, selects the one with the lowest rate, and constructs an HTLC transaction with parameters from the user and liquidity provider which is returned to the user for inspection.
After the user signs and broadcasts the HTLC transaction, REDSHIFT monitors the transaction and alerts the selected liquidity provider that the HTLC has been fully funded, therefore fulfilling their quoted amount. The liquidity provider then pays the Lightning invoice revealing the invoice payment secret (preimage). With the newly acquired preimage returned from the successful payment, the liquidity provider constructs a transaction to claim the funds held in the HTLC.
If the liquidity provider can’t pay the Lightning invoice, then the original user can get their funds in the HTLC back after the timelock expires. While invoices are able to be paid in most cases, sometimes a route cannot be found or the receiving party doesn’t have enough inbound capacity.
As the Lightning Network continues to gain adoption and stabilize, we believe submarine swaps will continue to be a critical tool for moving liquidity around the network and allowing invoices to be paid with on-chain assets.
REDSHIFT connects those looking to sell liquidity on the Lightning Network (liquidity providers) and those with on-chain digital assets (users) by providing: an easy-to-use Developer SDK, standalone widget, and a liquidity marketplace that coordinates the execution of submarine swaps. In contrast to other exchanges and services, the non-custodial nature of submarine swaps allow users to execute trade without compromising their identity while increasing the privacy of the entire network.