Giter VIP home page Giter VIP logo

breez-sdk-liquid's Introduction

Breez SDK - Liquid

Overview

The Breez SDK provides developers with a end-to-end solution for integrating self-custodial Lightning payments into their apps and services. It eliminates the need for third-parties, simplifies the complexities of Bitcoin and Lightning, and enables seamless onboarding for billions of users to the future of peer-to-peer payments.

To provide the best experience for their end-users, developers can choose between the following implementations:

The Breez SDK is free for developers.

What Is the Liquid Implementation?

The Liquid implementation is a nodeless Lightning integration. It offers a self-custodial, end-to-end solution for integrating Lightning payments, utilizing the Liquid Network with on-chain interoperability and third-party fiat on-ramps.

Core Functions

  • Sending payments via protocols such as: bolt11, lnurl-pay, lightning address, btc address.
  • Receiving payments via protocols such as: bolt11, lnurl-withdraw, btc address.
  • Interacting with a wallet e.g. balance, max allow to pay, max allow to receive, on-chain balance.

Key Features

  • On-chain interoperability
  • LNURL functionality
  • Multi-app support
  • Multi-device support
  • Real-time state backup
  • Keys are only held by users
  • Fiat on-ramps
  • Open-source

Getting Started

Head over to the Breez SDK - Liquid documentation to start implementing Lightning in your app.

API

API documentation is here.

Command Line

The Breez SDK - Liquid cli is a command line client that allows you to interact with and test the functionality of the SDK.

Support

Have a question for the team? Join our Telegram channel or email us at [email protected]

How Does the Liquid Implementation Work?

The Liquid implementation uses submarine swaps and reverse submarine swaps to send and receive payments, enabling funds to move frictionlessly between the Lightning Network and the Liquid sidechain.

Breez SDK - Liquid

When sending a payment the SDK performs a submarine swap, converting L-BTC from a user’s Liquid wallet into sats on the Lightning Network, and sends them to the recipient.

When receiving a payment, the SDK performs a reverse submarine swap, converting incoming sats into L-BTC, and then deposits them in the user’s Liquid wallet.

Build & Test

  • cli: Contains the Rust command line interface client for the SDK - Liquid.
  • lib: Contains the root Rust cargo workspace.
    • bindings: The ffi bindings for Kotlin, Flutter, Python, React Native, and Swift.
    • core: The core SDK - Liquid rust library.
  • packages: Contains the plugin packages for Dart, Flutter, and React Native.

Within each sub-project readme, there are instructions on how to build, test, and run.

SDK Development Roadmap

  • Send/Receive Lightning payments
  • CLI Interface
  • Foreign languages bindings
  • Export/Import SDK data
  • Pay BTC on-chain
  • Receive via on-chain address
  • LNURL-Pay
  • LNURL-Withdraw
  • Send to a Lightning address
  • Receive via Lightning address
  • Real-time sync
  • Webhook for receiving payments
  • Offline receive via notifications
  • Offline swaps via notifications

breez-sdk-liquid's People

Contributors

ok300 avatar erdemyerebasmaz avatar dangeross avatar roeierez avatar hydra-yse avatar dsbreez avatar kingonly avatar

Stargazers

Darrell avatar Riccardo Casatta avatar nully0x avatar Jijo Bose avatar Marco Argentieri avatar michael1011 avatar Rsync⚡️  avatar  avatar  avatar Bufo avatar 22388o⚡️  avatar  avatar  avatar

Watchers

Yaacov Akiba Slama avatar  avatar  avatar  avatar  avatar

breez-sdk-liquid's Issues

lib: Get wallet information

We should expose a method on the wallet to expose its information. Currently, its balance and public key should be enough, but I'm open to other suggestions.

Use `slip77` blinding variant to derive blinding keys from seed

See specification here: https://github.com/satoshilabs/slips/blob/master/slip-0077.md

We currently set the blinding variant in init_wallet:

    let desc = singlesig_desc(
        &signer,
        Singlesig::Wpkh,
        lwk_common::DescriptorBlindingKey::Elip151,
        false,
    );

If the blinding keys can be derived from the wallet's seed, then we don't have to store it for each tx.


This issue proposes to:

  • create two util methods derive_blinding_private_key and derive_blinding_public_key
  • replace the storing of the blinding key by calling the utils

Reverse swap: allow setting of invoice or onchain amount

Let the user specify which amount he wants to set

  • the invoice amount (e.g. how many sats will be paid by the sender) with CreateSwapRequest::new_lbtc_reverse_invoice_amt
  • the onchain amount (e.g. how many L-sats should arrive in the Liquid wallet) with CreateSwapRequest::new_lbtc_reverse_onchain_amt

lib: Add recovery and set max amount of ongoing sends

As previously discussed, we should:

  • Set a limit to the number of pending sends, 3 seems a good amount
  • Store the necessary information for recovery in the temporary persister
  • Find a way to compress, encrypt and backup this information so it can be persisted in some form of storage provider (e.g. Android/iCloud keychain, Google Drive etc.). Should be handled in #65 mostly.

zero conf send/receive

It seems that on the send case where we initiate the lockup transaction, boltz doesn't wait for confirmation when the payment is less than 100k sats but pays the invoice and broadcast immediately the claim transaction.
So we should return immediately after we detect the claim in the mempool with payment success.
We can do the same for receive case where We don't need to wait for the swapper lockup tx to confirm and we can initiate the claim immediately after we see the lockup in the mempool.

sync/restore

Since we have the requirement of working on multiple devices simultaneously we need some sort of sync mechanism.
Best would be to use the chain as single source of truth if possible.
Since the onchain wallet has the ability to recover confirmed transactions, we only need to handle pending transactions for the send use-case (our lockup that are not claimed).
Since we generate the keys to be able to refund (we send the pubkey to boltz to include in the script) we can generate them in a recoverable way (using a derivation path of our wallet master key).
So For every lockup that is not spend (claimed) we need to recover its corresponding refund key and create the refund tx.

Let's discuss that option.

Have a single thread that processes pending swaps

The more swaps were created and failed to complete, the more threads are opened, even after restarting the app.

[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:25Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:30Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:30Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:30Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:30Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:30Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:30Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:31Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:31Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:31Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:31Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:31Z INFO  electrum_client::raw_client] Trying to connect to 35.201.74.156:465 (attempt 1/1) with timeout 100s
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers
[2024-03-22T21:41:31Z WARN  breez_sdk_liquid::wallet] Could not claim yet. Err: Wrong response received from Boltz servers

There should ideally be a single thread that iterates over pending or ongoing swaps.

Liquid To Lightning Swaps POC

This is a tracking issue describing the necessary features for the Liquid to Lightning swaps POC.
The implementation should be split into two phases, ideally:

(FINISHED) PHASE 1 - Using Boltz Testnet Exchange:

  • Add support for lwk, generate wallets and fund them
  • Add lightning node management (single-node)
  • Implement normal_submarine_swap
  • Implement reverse_submarine_swap

PHASE 2 - Creating our own Swapper:

  • Adding lightning node management (multiple-nodes)
  • Remove Boltz client and implement custom swapper
  • Fix swap methods to use the custom swapper

Reliably determine minimum possible claim tx fee

Right now, the claim tx absolute fee is hardcoded to 134 sats.

However, we need a more reliable way to determine this dynamically.

For example, the minimum fee on Liquid is 0.1 sat/vB. One solution could be to calculate the absolute fee based on this feerate.

Another idea is to use the claim tx fee returned by Boltz in the swap creation response.

Got bad request error when sending 1000 sats invoice

send-payment lnbc10u1pnp8fa5pp5metdkaj36l7ntaglv5tqvazw26czrpnxclx4xcwda8kq2r7wmkyscqpjsp5g8dnxtytte5y20p8a0h3vnxxkh4cztculp6currjsa9sj4a3j0as9q7sqqqqqqqqqqqqqqqqqqqsqqqqqysgqdqqmqz9gxqyjw5qrzjqwryaup9lh50kkranzgcdnn2fgvx390wgj5jd07rwr3vxeje0glcll69wq3zjrksrqqqqqlgqqqqqeqqjqxgav46y0vue50zhsl46kjln38agnfnxhtym3xrv47fx2vq75vxhhehq9l5el8kre5flfq6gtnf3wehjmf2zf3hzfh682hdwue3ecuvcpvqrh4r

Error: Generic boltz error: HTTP(Status(400, Response[status: 400, status_text: Bad Request, url: https://api.boltz.exchange/createswap]))

lib: Add restore functionality

This issue should follow after #4. The idea is to be able to backup/sync/restore data throughout different wallet instances. Ideally, we should restore:

  • A list of pending/completed transactions
  • Optional wallet settings (if any)

Moreover, we should keep in mind to which degree a local storage is really necessary, as there should be ways to fetch the transaction history directly from the Liquid chain with a scan (could be optimized by only fetching the utxo set history pertaining to a certain (saved) txid, though there is some investigation to be done, we can start with scanning the whole chain and checking the history one by one)

CLI commands shouldn't contain onchain terminology

For example receive-payment has --onchain-amount-sat and --invoice-amount-sat.
I would also not give the option to have two options here, I think invoice paying is always about how much the payer pays so I suggest to remove the options here. The fee is included in the response anyway.

lib: Fix lwk_wollet persistence

Currently the lwk_wollet persists all its cache in the .wollet directory, but it seems like the data is getting written at every launch rather than being added when necessary

Use different DB files for mainnet and testnet

Depending on the network used, a different DB file should be used.

One way to solve this is to have a different subfolder under data_dir, then store the respective DB file under the correct path.

Receive fails on mainnet

Trying to receive on mainnet in CLI fails to complete. The output shows

[2024-04-23T16:22:28Z ERROR ls_sdk::wallet] [Ongoing Receive] Could not contact Boltz servers for claim status                                                    
[2024-04-23T16:22:33Z ERROR ls_sdk::wallet] [Ongoing Receive] Could not contact Boltz servers for claim status                                                                  
[2024-04-23T16:22:38Z ERROR ls_sdk::wallet] [Ongoing Receive] Could not contact Boltz servers for claim status 

In the sending LN wallet, the outgoing payment appears as pending or queued.

This happens only on mainnet. It works well on testnet.

Add fault-tolerant way of getting swap status

In this project, we're always fetching it from Boltz with BoltzApiClient::swap_status. This can leave us exposed to issues like BoltzExchange/boltz-backend#537 , causing us to fail to fetch the swap status and therefore fail to complete the swap (#104).

In contrast, in Breez SDK we're calculating the swap status ourselves: https://github.com/breez/breez-sdk/blob/2c1bcfced2cf36fa9f7baee5de8bbb1c81838c1e/libs/sdk-core/src/models.rs#L1450

We should fallbacks and redundancies, to make us resilient to the error above.

A few possible ideas:

  • instead of BoltzApiClient::swap_status we calculate the status ourselves
  • we first try BoltzApiClient::swap_status, then if it fails, we fallback to our own calculation
  • we first try the v2 Boltz API (fastest), then if it fails the v1 BoltzApiClient::swap_status, then our calculation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.