@@ -27,8 +27,8 @@ use lightning_liquidity::lsps1::client::LSPS1ClientConfig;
2727use lightning_liquidity:: lsps1:: event:: LSPS1ClientEvent ;
2828use lightning_liquidity:: lsps1:: msgs:: { ChannelInfo , LSPS1Options , OrderId , OrderParameters } ;
2929use lightning_liquidity:: lsps2:: client:: LSPS2ClientConfig ;
30- use lightning_liquidity:: lsps2:: event:: LSPS2ClientEvent ;
31- use lightning_liquidity:: lsps2:: msgs:: OpeningFeeParams ;
30+ use lightning_liquidity:: lsps2:: event:: { LSPS2ClientEvent , LSPS2ServiceEvent } ;
31+ use lightning_liquidity:: lsps2:: msgs:: { OpeningFeeParams , RawOpeningFeeParams } ;
3232use lightning_liquidity:: lsps2:: service:: LSPS2ServiceConfig ;
3333use lightning_liquidity:: lsps2:: utils:: compute_opening_fee;
3434use lightning_liquidity:: { LiquidityClientConfig , LiquidityServiceConfig } ;
@@ -40,6 +40,8 @@ use bitcoin::secp256k1::{PublicKey, Secp256k1};
4040
4141use tokio:: sync:: oneshot;
4242
43+ use chrono:: { DateTime , Utc } ;
44+
4345use std:: collections:: HashMap ;
4446use std:: ops:: Deref ;
4547use std:: sync:: { Arc , Mutex , RwLock } ;
@@ -396,6 +398,111 @@ where
396398 log_error ! ( self . logger, "Received unexpected LSPS1Client::OrderStatus event!" ) ;
397399 }
398400 } ,
401+ Event :: LSPS2Service ( LSPS2ServiceEvent :: GetInfo {
402+ request_id,
403+ counterparty_node_id,
404+ token : _,
405+ } ) => {
406+ if let Some ( lsps2_service_handler) =
407+ self . liquidity_manager . lsps2_service_handler ( ) . as_ref ( )
408+ {
409+ let min_fee_msat = 0 ;
410+ let proportional = 0 ;
411+ let mut valid_until: DateTime < Utc > = Utc :: now ( ) ;
412+ valid_until += chrono:: Duration :: minutes ( 10 ) ;
413+ let min_lifetime = 1008 ;
414+ let max_client_to_self_delay = 144 ;
415+ let min_payment_size_msat = 1000 ;
416+ let max_payment_size_msat = 10_000_000_000 ;
417+
418+ let opening_fee_params = RawOpeningFeeParams {
419+ min_fee_msat,
420+ proportional,
421+ valid_until,
422+ min_lifetime,
423+ max_client_to_self_delay,
424+ min_payment_size_msat,
425+ max_payment_size_msat,
426+ } ;
427+
428+ let opening_fee_params_menu = vec ! [ opening_fee_params] ;
429+
430+ if let Err ( e) = lsps2_service_handler. opening_fee_params_generated (
431+ & counterparty_node_id,
432+ request_id,
433+ opening_fee_params_menu,
434+ ) {
435+ log_error ! (
436+ self . logger,
437+ "Failed to handle generated opening fee params: {:?}" ,
438+ e
439+ ) ;
440+ }
441+ } else {
442+ log_error ! ( self . logger, "Failed to handle LSPS2ServiceEvent as LSPS2 liquidity service was not configured." , ) ;
443+ return ;
444+ }
445+ } ,
446+ Event :: LSPS2Service ( LSPS2ServiceEvent :: BuyRequest {
447+ request_id,
448+ counterparty_node_id,
449+ opening_fee_params : _,
450+ payment_size_msat : _,
451+ } ) => {
452+ if let Some ( lsps2_service_handler) =
453+ self . liquidity_manager . lsps2_service_handler ( ) . as_ref ( )
454+ {
455+ let user_channel_id = 0 ;
456+ let scid = self . channel_manager . get_intercept_scid ( ) ;
457+ let cltv_expiry_delta = 72 ;
458+ let client_trusts_lsp = true ;
459+
460+ if let Err ( e) = lsps2_service_handler. invoice_parameters_generated (
461+ & counterparty_node_id,
462+ request_id,
463+ scid,
464+ cltv_expiry_delta,
465+ client_trusts_lsp,
466+ user_channel_id,
467+ ) {
468+ log_error ! ( self . logger, "Failed to provide invoice parameters: {:?}" , e) ;
469+ }
470+ } else {
471+ log_error ! ( self . logger, "Failed to handle LSPS2ServiceEvent as LSPS2 liquidity service was not configured." , ) ;
472+ return ;
473+ }
474+ } ,
475+ Event :: LSPS2Service ( LSPS2ServiceEvent :: OpenChannel {
476+ their_network_key,
477+ amt_to_forward_msat,
478+ opening_fee_msat : _,
479+ user_channel_id,
480+ intercept_scid : _,
481+ } ) => {
482+ if self . liquidity_manager . lsps2_service_handler ( ) . is_none ( ) {
483+ log_error ! ( self . logger, "Failed to handle LSPS2ServiceEvent as LSPS2 liquidity service was not configured." , ) ;
484+ return ;
485+ } ;
486+
487+ let channel_size_sats = ( amt_to_forward_msat / 1000 ) * 4 ;
488+ let mut config = * self . channel_manager . get_current_default_configuration ( ) ;
489+ config
490+ . channel_handshake_config
491+ . max_inbound_htlc_value_in_flight_percent_of_channel = 100 ;
492+ config. channel_config . forwarding_fee_base_msat = 0 ;
493+ config. channel_config . forwarding_fee_proportional_millionths = 0 ;
494+
495+ if let Err ( e) = self . channel_manager . create_channel (
496+ their_network_key,
497+ channel_size_sats,
498+ 0 ,
499+ user_channel_id,
500+ None ,
501+ Some ( config) ,
502+ ) {
503+ log_error ! ( self . logger, "Failed to open jit channel: {:?}" , e) ;
504+ }
505+ } ,
399506 Event :: LSPS2Client ( LSPS2ClientEvent :: OpeningParametersReady {
400507 request_id,
401508 counterparty_node_id,
0 commit comments