lightningdevkit.org icon indicating copy to clipboard operation
lightningdevkit.org copied to clipboard

Add instructions on how to use lightning-liquidity crate

Open ConorOkus opened this issue 8 months ago • 1 comments

  1. To allow 0-conf channels, set UserConfig::manually_accept_inbound_channel and start handling OpenChannelRequest events via the ChannelManager::accept_inbound_channel_from_trusted_peer_0conf call
  2. Configure LiquidityManager by setting the LSPS2ClientConfig and set it as your CustomMessageHandler in MessagHandler that you give to PeerManager
  3. Set ChannelConfig:: accept_underpaying_htlcs to true and ChannelHandshakeConfig::max_inbound_value_in_flight_percent_of_channel to 100.
  4. Start handling LiquidityManager events (returned via next_event, next_event_async, or wait_next_event)
  5. Connect to the LSP
  6. Call LiquidityManager::lsps2_client_handler to get an LSPS2ClientHandler
  7. Call LSPS2ClientHandler::request_opening_params, you'll get an OpeningParametersReady event when the LSP responds
  8. Pick one of the opening parameters and remember them (to later check if the LSP just takes the fee you agreed on)
  9. Call LSPS2ClientHandler::select_opening_parameters, you'll get an InvoiceParametersReady event when the LSP responds
  10. Create a JIT invoice with the information given in said InvoiceParametersReady event
  11. Hand out that invoice, once it's paid, the LSP will open a channel to you and forward the HTLC
  12. In your event handling logic for the PaymentClaimable event, check that the LSP only withheld what you agreed upon above (you can use the compute_opening_fee util for that)
  13. Claim the payment if the LSP didn't cheat you

Note: This is for LSPS2

ConorOkus avatar Apr 07 '25 09:04 ConorOkus

For LSPS1 the steps are roughly:

  1. Configure LiquidityManager by setting the LSPS1ClientConfig and set it as your CustomMessageHandler in MessagHandler that you give to PeerManager
  2. Start handling LiquidityManager events (returned via next_event, next_event_async, or wait_next_event)
  3. Connect to the LSP
  4. Call LiquidityManager::lsps1_client_handler to get an LSPS1ClientHandler
  5. Call LSPS1ClientHandler::request_supported_options, you'll get a SupportedOptionsReady event
  6. Check params for your order against the LSPS1Options limits returned by the LSP
  7. If all is clear, call LSPS1ClientHandler::create_order, you'll get a OrderCreated event in response
  8. Choose one of the payment methods as given in OrderCreated::payment, pay for the channel open
  9. The LSP will open the channel to you
  10. (Optionally) Check order status inbetween via LSPS1ClientHandler::check_order_status

tnull avatar Apr 07 '25 09:04 tnull