@@ -506,6 +506,40 @@ func (s *Client) resumeSwaps(ctx context.Context,
506506func (s * Client ) LoopOut (globalCtx context.Context ,
507507 request * OutRequest ) (* LoopOutSwapInfo , error ) {
508508
509+ if request .AssetId != nil {
510+ if request .AssetEdgeNode == nil {
511+ return nil , errors .New ("asset edge node must be set " +
512+ "when using an asset id" )
513+ }
514+ // Verify that if we have an asset id set, we have a valid asset
515+ // client to use.
516+ if s .assetClient == nil {
517+ return nil , errors .New ("asset client must be set " +
518+ "when using an asset id" )
519+ }
520+
521+ rfq , err := s .assetClient .GetRfqForAsset (
522+ globalCtx , request .AssetAmount , request .AssetId ,
523+ request .AssetEdgeNode ,
524+ )
525+ if err != nil {
526+ return nil , err
527+ }
528+
529+ satAmt , err := assets .GetSatAmtFromRfq (
530+ request .AssetAmount , rfq .BidAssetRate ,
531+ )
532+ if err != nil {
533+ return nil , err
534+ }
535+
536+ log .Infof ("LoopOut %v sats to %v (channels: %v) with asset %x" ,
537+ satAmt , request .DestAddr , request .OutgoingChanSet ,
538+ request .AssetId ,
539+ )
540+ request .Amount = satAmt
541+ }
542+
509543 log .Infof ("LoopOut %v to %v (channels: %v)" ,
510544 request .Amount , request .DestAddr , request .OutgoingChanSet ,
511545 )
@@ -530,6 +564,7 @@ func (s *Client) LoopOut(globalCtx context.Context,
530564
531565 // Create a new swap object for this swap.
532566 swapCfg := newSwapConfig (s .lndServices , s .Store , s .Server , s .assetClient )
567+
533568 initResult , err := newLoopOutSwap (
534569 globalCtx , swapCfg , initiationHeight , request ,
535570 )
@@ -579,11 +614,31 @@ func (s *Client) LoopOutQuote(ctx context.Context,
579614 return nil , err
580615 }
581616
582- if request .Amount < terms .MinSwapAmount {
617+ invoiceAmountSat := request .Amount
618+ // If we use an Asset we'll rfq to check if the sat amount meets the
619+ // min swap amount criteria.
620+ if request .AssetId != nil {
621+ rfq , err := s .assetClient .GetRfqForAsset (
622+ ctx , request .Amount , request .AssetId ,
623+ request .AssetEdgeNode ,
624+ )
625+ if err != nil {
626+ return nil , err
627+ }
628+
629+ invoiceAmountSat , err = assets .GetSatAmtFromRfq (
630+ request .Amount , rfq .BidAssetRate ,
631+ )
632+ if err != nil {
633+ return nil , err
634+ }
635+ }
636+
637+ if invoiceAmountSat < terms .MinSwapAmount {
583638 return nil , ErrSwapAmountTooLow
584639 }
585640
586- if request . Amount > terms .MaxSwapAmount {
641+ if invoiceAmountSat > terms .MaxSwapAmount {
587642 return nil , ErrSwapAmountTooHigh
588643 }
589644
@@ -594,7 +649,7 @@ func (s *Client) LoopOutQuote(ctx context.Context,
594649 }
595650
596651 quote , err := s .Server .GetLoopOutQuote (
597- ctx , request . Amount , expiry , request .SwapPublicationDeadline ,
652+ ctx , invoiceAmountSat , expiry , request .SwapPublicationDeadline ,
598653 request .Initiator ,
599654 )
600655 if err != nil {
@@ -613,6 +668,7 @@ func (s *Client) LoopOutQuote(ctx context.Context,
613668 MinerFee : minerFee ,
614669 PrepayAmount : quote .PrepayAmount ,
615670 SwapPaymentDest : quote .SwapPaymentDest ,
671+ InvoiceAmtSat : invoiceAmountSat ,
616672 }, nil
617673}
618674
0 commit comments