2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-04 06:00:21 +00:00
Go to file
2019-12-03 13:39:32 +01:00
cmd cmd/loop: delay swap by 30 minutes by default, add --fast to loopout command 2019-11-21 18:47:01 +01:00
docs docs: move out architecture diagram 2019-03-13 16:11:04 -07:00
lndclient lndclient: use old value field for backward compatibility 2019-12-03 13:39:32 +01:00
loopdb loopdb/loopout: add field SwapPublicationDeadline to LoopOutContract 2019-11-21 18:47:00 +01:00
looprpc looprpc: add SwapPublicationDeadline to client proto 2019-11-21 18:47:01 +01:00
lsat lsat: introduce LSAT related utilities 2019-11-25 13:16:04 -08:00
swap loop+cmd: extract types into swap module 2019-10-09 16:14:06 +02:00
sweep multi: fix most obvious linter errors 2019-10-09 14:35:41 +02:00
test lndclient: fix Value/ValueMsat conversion problem 2019-12-03 10:42:01 +01:00
.gitignore git: update gitignore to include new loop related binaries 2019-03-06 15:57:55 -08:00
.golangci.yml lint: allow init functions 2019-10-28 17:09:23 +01:00
.travis.yml only lint new issues, add linting to travis run 2019-10-09 14:36:35 +02:00
client_test.go loopdb: replace swap state enum by state data object 2019-05-20 13:57:09 +02:00
client.go multi: add persistent logger 2019-10-28 17:09:23 +01:00
config.go multi: finalize rename from uncharge to loop out 2019-03-06 20:34:04 -08:00
DOCKER.md loop: introduce docker integration (#46) 2019-05-17 18:40:43 -07:00
Dockerfile loop: introduce docker integration (#46) 2019-05-17 18:40:43 -07:00
executor.go multi: add persistent logger 2019-10-28 17:09:23 +01:00
go.mod dep+looping: update to latest lnd master 2019-12-02 13:49:38 +01:00
go.sum dep+looping: update to latest lnd master 2019-12-02 13:49:38 +01:00
interface.go swap_server_client: let the SwapPublicationDeadline be set during LoopOuts 2019-11-21 18:47:01 +01:00
LICENSE Initial commit 2019-02-15 17:57:58 -08:00
log.go multi: add persistent logger 2019-10-28 17:09:23 +01:00
loopin_test.go multi: add persistent logger 2019-10-28 17:09:23 +01:00
loopin_testcontext_test.go multi: loop in swap 2019-03-28 11:56:49 +01:00
loopin.go dep+looping: update to latest lnd master 2019-12-02 13:49:38 +01:00
loopout_test.go multi: add persistent logger 2019-10-28 17:09:23 +01:00
loopout.go swap_server_client: let the SwapPublicationDeadline be set during LoopOuts 2019-11-21 18:47:01 +01:00
Makefile add lint command to Makefile 2019-10-09 09:03:31 +02:00
README.md readme: update slack link 2019-11-02 08:46:43 -07:00
release.sh release: add release script 2019-03-07 21:49:59 -08:00
server_mock_test.go swap_server_client: let the SwapPublicationDeadline be set during LoopOuts 2019-11-21 18:47:01 +01:00
store_mock_test.go multi: fix most obvious linter errors 2019-10-09 14:35:41 +02:00
swap_server_client.go swap_server_client: let the SwapPublicationDeadline be set during LoopOuts 2019-11-21 18:47:01 +01:00
swap.go multi: add persistent logger 2019-10-28 17:09:23 +01:00
testcontext_test.go multi: add persistent logger 2019-10-28 17:09:23 +01:00
uncharge_state.go loop: extract code from client package into new loop primary package 2019-03-06 20:34:01 -08:00
version.go version: bump version to 0.3.0 2019-11-21 10:51:35 -08:00

Lightning Loop

Lightning Loop is a non-custodial service offered by Lightning Labs to bridge on-chain and off-chain Bitcoin using submarine swaps. This repository is home to the Loop client and depends on the Lightning Network daemon lnd. All of lnds supported chain backends are fully supported when using the Loop client: Neutrino, Bitcoin Core, and btcd.

In the current iteration of the Loop software, two swap types are supported:

  • off-chain to on-chain, where the Loop client sends funds off-chain in
  • on-chain to off-chain, where the Loop client sends funds to an on-chain address using an off-chain channel

We call off-chain to on-chain swaps, a Loop Out. The service can be used in various situations:

  • Acquiring inbound channel liquidity from arbitrary nodes on the Lightning network
  • Depositing funds to a Bitcoin on-chain address without closing active channels
  • Paying to on-chain fallback addresses in the case of insufficient route liquidity

We call our on-chain to off-chain swaps, a Loop In. This allows you to use on-chain funds to increase the local balance of a channel, effectively "refilling" an existing channel.

Potential uses for Loop In:

  • Refilling depleted channels with funds from cold-wallets or exchange withdrawals
  • Servicing off-chain Lightning withdrawals using on-chain payments, with no funds in channels required
  • As a failsafe payment method that can be used when channel liquidity along a route is insufficient

Development and Support

The Loop client is currently in an early beta state, and offers a simple command line application. Future APIs will be added to support implementation or use of the Loop service.

The Loop daemon exposes a gRPC API (defaults to port 11010) and a REST API (defaults to port 8081).

The GitHub issue tracker can be used to request specific improvements or register and get help with any problems. Community support is also available in the LND Slack .

Setup and Install

LND and the loop client are using Go modules. Make sure that the GO111MODULE env variable is set to on.

In order to execute a swap, You need to run lnd 0.7.1+, or master built with sub-servers enabled.

LND

If you are building from source, and not using a 0.7.1 or higher release of lnd, make sure that you are using the master branch of lnd. You can get this by git cloning the repository

git clone https://github.com/lightningnetwork/lnd.git

Once the lnd repository is cloned, it will need to be built with special build tags that enable the swap. This enables the required lnd rpc services.

cd lnd
make install tags="signrpc walletrpc chainrpc invoicesrpc routerrpc"

Check to see if you have already installed lnd. If you have, you will need to delete the .macaroon files from your lnd directory and restart lnd.

Do not delete any other files other than the .macaroon files

// Example on Linux to see macaroons in the default directory:
ls ~/.lnd/data/chain/bitcoin/mainnet

This should show no .macaroon files. If it does? Stop lnd, delete macaroons, restart lnd.

lncli stop

Now delete the .macaroon files and restart lnd. (don't delete any other files)

Loopd

After lnd is installed, you will need to clone the Lightning Loop repo and install the command line interface and swap client service.

git clone https://github.com/lightninglabs/loop.git
cd loop/cmd
go install ./...

Execute a Swap

After you have lnd and the Loop client installed, you can execute a Loop swap.

The Loop client needs its own short-lived daemon which will deal with the swaps in progress.

Command to start loopd::

loopd

// Or if you want to do everything in the same terminal and background loopd
loopd &

// For testnet mode, you'll need to specify the network as mainnet is the
default:
loopd --network=testnet

By default loopd attempts to connect to the lnd instance running on localhost:10009 and reads the macaroon and tls certificate from ~/.lnd. This can be altered using command line flags. See loopd --help.

loopd only listens on localhost and uses an unencrypted and unauthenticated connection.

Loop Out Swaps

Now that loopd is running, you can initiate a simple Loop Out. This will pay out Lightning off-chain funds and you will receive Bitcoin on-chain funds in return. There will be some chain and routing fees associated with this swap.

NAME:
   loop out - perform an off-chain to on-chain swap (looping out)

USAGE:
   loop out [command options] amt [addr]

DESCRIPTION:

  Attempts loop out the target amount into either the backing lnd's
  wallet, or a targeted address.

  The amount is to be specified in satoshis.

  Optionally a BASE58/bech32 encoded bitcoin destination address may be
  specified. If not specified, a new wallet address will be generated.

OPTIONS:
   --channel value  the 8-byte compact channel ID of the channel to loop out (default: 0)
   --addr value     the optional address that the looped out funds should be sent to, if left blank the funds will go to lnd's wallet
   --amt value      the amount in satoshis to loop out (default: 0)

It's possible to receive more inbound capacity on a particular channel (--channel), and also have the loop daemon send the coins to a target address (addr). The latter option allows ones to effectively send on-chain from their existing channels!

loop out <amt_in_satoshis>

This will take some time, as it requires an on-chain confirmation. When the swap is initiated successfully, loopd will see the process through.

To query in-flight swap statuses, run loop monitor.

Loop In Swaps

Additionally, Loop In is now also supported for mainnet as well. A Loop In swap lets one refill their channel (ability to send more coins) by sending to a special script on-chain.

NAME:
   loop in - perform an on-chain to off-chain swap (loop in)

USAGE:
   loop in [command options] amt

DESCRIPTION:

    Send the amount in satoshis specified by the amt argument off-chain.

OPTIONS:
   --amt value  the amount in satoshis to loop in (default: 0)
   --external   expect htlc to be published externally

The --external argument allows the on-chain HTLC transacting to be published externally. This allows for a number of use cases like using this address to withdraw from an exchange into your Lightning channel!

A Loop In swap can be executed a follows:

loop in <amt_in_satoshis>

Resume

When loopd is terminated (or killed) for whatever reason, it will pickup pending swaps after a restart.

Information about pending swaps is stored persistently in the swap database. Its location is ~/.loopd/<network>/loop.db.

Multiple Simultaneous Swaps

It is possible to execute multiple swaps simultaneously. Just keep loopd running.