Learn Center
How LNSwap Bitcoin Swaps Work

How LNSwap Bitcoin Swaps Work

LNSwap is a decentralized swap protocol that provides a fast, direct way of swapping Bitcoin for digital assets on the Stacks layer and vice versa that supports all on-chain and Lightning Bitcoin wallets.‍It also allows users to have full control over their funds during the swap process for a truly trustless experience.‍Let’s dive into how all this works.

An Introduction to LNSwap

LNSwap is a decentralized swap protocol that provides a fast, direct way of swapping Bitcoin for digital assets on the Stacks layer and vice versa that supports all on-chain and Lightning Bitcoin wallets.

It also allows users to have full control over their funds during the swap process for a truly trustless experience.

Let’s dive into how all this works.

Different Types of Exchanges

First, it’s important to understand that the primary types of exchanges for cryptocurrencies right now:

Centralized Exchanges

The vast majority of cryptocurrency exchanges are centralized, with all the rules and fees determined by one central entity. 

To participate in a centralized exchange (CEX), you need to set up an account, verify your identity, and then link a funding source. It is only after onboarding that you can buy, sell, and withdraw crypto, and engage in other transactions. More and more CEXs have also, over the years, introduced financial operations that mirror what you may see at a traditional fiat institution.

But there’s one big component of CEXs to be aware of: they are what we call “custodial” exchanges. While CEXs store and keep track of your digital assets, you don’t actually get the private keys that would give you control over your funds. 

The CEX effectively serves as a custodian on your behalf.

This also means that when you’re looking to exchange your tokens with someone else, you have to actually deposit your assets in a “honey pot” of sorts – a place where all funds are held when an exchange is being made between two parties.

These collections of tokens held in one spot – collections that depend on the CEX – have come under scrutiny. This is because users’ lack of direct control over their funds could put them – and their funds – in a precarious position. 

We’ve seen our fair share of CEX customers who have lost money or been unable to access refunds in light of security breaches, deteriorating market conditions, and other crises.

That’s where decentralized exchanges come into play.

Decentralized Exchanges

Decentralized exchanges have emerged in recent years as an answer to the pitfalls of CEXs and their custodial nature.

Decentralized exchanges (DEXs, for short) operate on on-chain smart contracts – or multisig addresses, and are typically applications. Unlike CEXs, the decentralized nature of DEXs means that there is no central entity who is in control of users’ funds. 

This means that DEXs are non-custodial by nature. The lack of a custodian not only means that users have more control over their funds, it also means that they may see less barriers that often come with custodians, like higher fees.

But since there aren’t any central entities who are monitoring and supplying crypto, DEXs need liquidity. This is why DEXs also operate with liquidity pools – pools of crypto supplied by users (known as liquidity providers) – to enable their operations. 

Here, we need to also mention that DEXs tend to operate as Automated Market Makers (AMMs), which essentially allow trades to be made against liquidity pools. Basically, an algorithm determines and regulates the prices and values of tokens in a pool, while AMMs also incentivize liquidity providers by offering them a share of transaction fees and tokens.

Unfortunately, while DEXs do give back control of funds to users, they are only as secure as their code. If a contract is exploited or the multisig keys are compromised, users can still lose their funds.

Atomic Swaps vs. Submarine Swaps

Now that we have established the custodial and non-custodial nature of today’s financial landscape for cryptocurrencies, it’s also important to distinguish between atomic and submarine swaps as they are important developments in crypto trading.

While a more thorough walkthrough can be found in our blog post, “Decentralized Trading – Atomic Swaps and Submarine Swaps,” here are the basic ideas:

Atomic Swaps

An atomic swap is a token swap between two digital assets across different blockchains without the use of an intermediary. It is non-custodial by nature, and allows users to also keep their identities and personal information private.

Most notably, they operate with a type of Bitcoin smart contract called a hashed time-locked contract (HTLC) that basically allows token swaps to occur off-chain. 

During an atomic swap, the HTLC basically acts like a vault that keeps both parties’ funds locked until the token swap is complete. 

There is also a timelock that sets a deadline for the swap to happen. If the swap doesn’t occur within that timeline, both parties will have their assets returned.

But here’s a catch: during this process, the Lightning Network (LN) needs to be enabled on both networks that are participating in a swap. 

And that takes us to submarine swaps.

Submarine Swaps

A submarine swap specifically addresses one key issue: the incompatibility between on-chain Bitcoin addresses and off-chain Lightning addresses.

When you set up an LN address, you need an on-chain LN transaction and a prefilled amount of BTC that is sent to that channel.

But once that supply of BTC runs out in the channel, there’s no way to refill it, which means that you’ll have to open another channel. This complicates the process.

That’s where submarine swaps come in. A submarine swap basically allows that LN channel to be refilled by facilitating an on-chain transfer from the Bitcoin blockchain to the off-chain LN channel.

They also use an HTLC to ensure that the process is trustless and must be completed by a deadline.

Where Does LNSwap Fit In, and How Does it Work?

Essentially, LNSwap uses submarine swap technology and aspects of non-custodial exchanges to provide fast and secure swaps between Bitcoin and digital assets on the Stacks layer (including STX), and vice versa.

When users want to swap assets, they effectively put their assets in HTLC generated by Clarity smart contracts. 

The entire swap is also conducted without an intermediary, meaning that it is completely trustless and only involves the necessary parties.

LNSwap also makes use of some aspects of DEXs, like liquidity providers, who provide funds to the LNSwap protocol to facilitate swaps on the exchange. Like DEXs, these liquidity providers are also rewarded with fees generated by the swaps happening on the platform.

The Future of LNSwap

A big mission of LNSwap is to continue leveraging Bitcoin layers to build on our currently existing swap protocol.

We have plans to integrate the ever-expanding functionality of Bitcoin layers, with a roadmap to integrate more upgrades even in the next year.

The technology enabling swap protocols and non-custodial digital asset trading has come a long way, and we’re excited to be part of the next step.

LNSwap is a product of Trust Machines.

Posted on: Apr 20, 2023

Updated on: Apr 20, 2023

This is some text inside of a div block.

Start swapping Bitcoin for Stacks

LNSwap is a non custodian crypto currency swap protocol that provides a fast, private way of swapping Bitcoin for Stacks and vice versa.