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