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