@@ -97,8 +97,9 @@ type Client struct {
9797 executor * executor
9898 assetClient * assets.TapdClient
9999
100- resumeReady chan struct {}
101- wg sync.WaitGroup
100+ resumeReady chan struct {}
101+ wg sync.WaitGroup
102+ assetNameCache map [string ]string
102103
103104 clientConfig
104105}
@@ -342,6 +343,10 @@ func (s *Client) FetchSwaps(ctx context.Context) ([]*SwapInfo, error) {
342343 return nil , swap .ErrInvalidOutputType
343344 }
344345
346+ if swp .Contract .AssetSwapInfo != nil {
347+ swapInfo .AssetSwapInfo = swp .Contract .AssetSwapInfo
348+ }
349+
345350 swaps = append (swaps , swapInfo )
346351 }
347352
@@ -507,43 +512,31 @@ func (s *Client) LoopOut(globalCtx context.Context,
507512 request * OutRequest ) (* LoopOutSwapInfo , error ) {
508513
509514 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" )
515+ if request .AssetPrepayRfqId == nil ||
516+ request .AssetSwapRfqId == nil {
517+
518+ return nil , errors .New ("asset prepay and swap rfq ids " +
519+ "must be set when using an asset id" )
513520 }
521+
514522 // Verify that if we have an asset id set, we have a valid asset
515523 // client to use.
516524 if s .assetClient == nil {
517525 return nil , errors .New ("asset client must be set " +
518526 "when using an asset id" )
519527 }
520528
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-
536529 log .Infof ("LoopOut %v sats to %v (channels: %v) with asset %x" ,
537- satAmt , request .DestAddr , request .OutgoingChanSet ,
538- request .AssetId ,
530+ request .Amount , request .DestAddr ,
531+ request .OutgoingChanSet , request .AssetId ,
532+ )
533+ } else {
534+ log .Infof ("LoopOut %v to %v (channels: %v)" ,
535+ request .Amount , request .DestAddr ,
536+ request .OutgoingChanSet ,
539537 )
540- request .Amount = satAmt
541538 }
542539
543- log .Infof ("LoopOut %v to %v (channels: %v)" ,
544- request .Amount , request .DestAddr , request .OutgoingChanSet ,
545- )
546-
547540 if err := s .waitForInitialized (globalCtx ); err != nil {
548541 return nil , err
549542 }
@@ -563,7 +556,9 @@ func (s *Client) LoopOut(globalCtx context.Context,
563556 }
564557
565558 // Create a new swap object for this swap.
566- swapCfg := newSwapConfig (s .lndServices , s .Store , s .Server , s .assetClient )
559+ swapCfg := newSwapConfig (
560+ s .lndServices , s .Store , s .Server , s .assetClient ,
561+ )
567562
568563 initResult , err := newLoopOutSwap (
569564 globalCtx , swapCfg , initiationHeight , request ,
@@ -609,36 +604,26 @@ func (s *Client) getExpiry(height int32, terms *LoopOutTerms,
609604func (s * Client ) LoopOutQuote (ctx context.Context ,
610605 request * LoopOutQuoteRequest ) (* LoopOutQuote , error ) {
611606
612- terms , err := s . Server . GetLoopOutTerms ( ctx , request .Initiator )
613- if err != nil {
614- return nil , err
607+ if request . AssetId != nil && request .AssetEdgeNode == nil {
608+ return nil , errors . New ( "asset edge node must be set " +
609+ "when using an asset id" )
615610 }
616611
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- }
612+ if request .AssetEdgeNode != nil && request .AssetId == nil {
613+ return nil , errors .New ("asset id must be set " +
614+ "when using an asset edge node" )
615+ }
628616
629- invoiceAmountSat , err = assets .GetSatAmtFromRfq (
630- request .Amount , rfq .BidAssetRate ,
631- )
632- if err != nil {
633- return nil , err
634- }
617+ terms , err := s .Server .GetLoopOutTerms (ctx , request .Initiator )
618+ if err != nil {
619+ return nil , err
635620 }
636621
637- if invoiceAmountSat < terms .MinSwapAmount {
622+ if request . Amount < terms .MinSwapAmount {
638623 return nil , ErrSwapAmountTooLow
639624 }
640625
641- if invoiceAmountSat > terms .MaxSwapAmount {
626+ if request . Amount > terms .MaxSwapAmount {
642627 return nil , ErrSwapAmountTooHigh
643628 }
644629
@@ -649,7 +634,7 @@ func (s *Client) LoopOutQuote(ctx context.Context,
649634 }
650635
651636 quote , err := s .Server .GetLoopOutQuote (
652- ctx , invoiceAmountSat , expiry , request .SwapPublicationDeadline ,
637+ ctx , request . Amount , expiry , request .SwapPublicationDeadline ,
653638 request .Initiator ,
654639 )
655640 if err != nil {
@@ -663,13 +648,56 @@ func (s *Client) LoopOutQuote(ctx context.Context,
663648 return nil , err
664649 }
665650
666- return & LoopOutQuote {
651+ loopOutQuote := & LoopOutQuote {
667652 SwapFee : quote .SwapFee ,
668653 MinerFee : minerFee ,
669654 PrepayAmount : quote .PrepayAmount ,
670655 SwapPaymentDest : quote .SwapPaymentDest ,
671- InvoiceAmtSat : invoiceAmountSat ,
672- }, nil
656+ }
657+
658+ // If we use an Asset we'll rfq to get the asset amounts to use for
659+ // the swap.
660+ if request .AssetId != nil {
661+ // First we'll get the prepay prepayRfq.
662+ prepayRfq , err := s .assetClient .GetRfqForAsset (
663+ ctx , quote .PrepayAmount , request .AssetId ,
664+ request .AssetEdgeNode ,
665+ )
666+ if err != nil {
667+ return nil , err
668+ }
669+ log .Infof ("Prepay RFQ: %v" , prepayRfq )
670+
671+ invoiceAmt := request .Amount + quote .SwapFee -
672+ quote .PrepayAmount
673+
674+ swapRfq , err := s .assetClient .GetRfqForAsset (
675+ ctx , invoiceAmt , request .AssetId , request .AssetEdgeNode ,
676+ )
677+ if err != nil {
678+ return nil , err
679+ }
680+ log .Infof ("Swap RFQ: %v" , swapRfq )
681+
682+ // We'll also want the asset name to verify for the client.
683+ assetName , err := s .assetClient .GetAssetName (
684+ ctx , request .AssetId ,
685+ )
686+ if err != nil {
687+ return nil , err
688+ }
689+
690+ loopOutQuote .LoopOutRfq = & LoopOutRfq {
691+ PrepayRfqId : prepayRfq .Id ,
692+ PrepayAssetAmt : btcutil .Amount (prepayRfq .AssetAmount ),
693+ SwapRfqId : swapRfq .Id ,
694+ SwapAssetAmt : btcutil .Amount (swapRfq .AssetAmount ),
695+ AssetName : assetName ,
696+ }
697+
698+ }
699+
700+ return loopOutQuote , nil
673701}
674702
675703// getLoopOutSweepFee is a helper method to estimate the loop out htlc sweep
0 commit comments