Skip to content

Commit 67af997

Browse files
committed
liquidity: add asset swap info to swap builder
1 parent cd8a014 commit 67af997

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

liquidity/interface.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ type swapBuilder interface {
6262
// is just for a dry run.
6363
buildSwap(ctx context.Context, peer route.Vertex,
6464
channels []lnwire.ShortChannelID, amount btcutil.Amount,
65-
params Parameters) (swapSuggestion, error)
65+
params Parameters, assetInfo *assetSwapInfo) (swapSuggestion,
66+
error)
6667
}
6768

6869
// swapSuggestion is an interface implemented by suggested swaps for our

liquidity/liquidity.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
641641

642642
suggestion, err := builder.buildSwap(
643643
ctx, channel.PubKeyBytes, outgoing, swapAmt, easyParams,
644+
nil,
644645
)
645646
if err != nil {
646647
return err
@@ -1004,6 +1005,7 @@ func (m *Manager) suggestSwap(ctx context.Context, traffic *swapTraffic,
10041005

10051006
return builder.buildSwap(
10061007
ctx, balance.pubkey, balance.channels, amount, m.params,
1008+
nil,
10071009
)
10081010
}
10091011

liquidity/loopin_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (b *loopInBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
8484
// For loop in, we do not add the autoloop label for dry runs.
8585
func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
8686
_ []lnwire.ShortChannelID, amount btcutil.Amount,
87-
params Parameters) (swapSuggestion, error) {
87+
params Parameters, assetInfo *assetSwapInfo) (swapSuggestion, error) {
8888

8989
quote, err := b.cfg.LoopInQuote(ctx, &loop.LoopInQuoteRequest{
9090
Amount: amount,

liquidity/loopin_builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestLoopinBuildSwap(t *testing.T) {
184184
swap, err := builder.buildSwap(
185185
context.Background(), peer1, []lnwire.ShortChannelID{
186186
chan1,
187-
}, swapAmt, params,
187+
}, swapAmt, params, nil,
188188
)
189189
assert.Equal(t, testCase.expectedSwap, swap)
190190
assert.Equal(t, testCase.expectedErr, err)

liquidity/loopout_builder.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package liquidity
22

33
import (
44
"context"
5+
"encoding/hex"
56

67
"github.com/btcsuite/btcd/btcutil"
78
"github.com/lightninglabs/loop"
@@ -84,6 +85,11 @@ func (b *loopOutBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
8485
return nil
8586
}
8687

88+
type assetSwapInfo struct {
89+
assetId string
90+
peerPubkey []byte
91+
}
92+
8793
// buildSwap creates a swap for the target peer/channels provided. The autoloop
8894
// boolean indicates whether this swap will actually be executed, because there
8995
// are some calls we can leave out if this swap is just for a dry run (ie, when
@@ -94,14 +100,35 @@ func (b *loopOutBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
94100
// dry-run, and we do not add the autoloop label to the recommended swap.
95101
func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
96102
channels []lnwire.ShortChannelID, amount btcutil.Amount,
97-
params Parameters) (swapSuggestion, error) {
103+
params Parameters, assetSwap *assetSwapInfo) (swapSuggestion, error) {
104+
105+
var (
106+
assetRfqRequest *loop.AssetRFQRequest
107+
assetIdBytes []byte
108+
err error
109+
)
110+
111+
initatior := getInitiator(params)
112+
113+
if assetSwap != nil {
114+
assetIdBytes, err = hex.DecodeString(assetSwap.assetId)
115+
if err != nil {
116+
return nil, err
117+
}
118+
assetRfqRequest = &loop.AssetRFQRequest{
119+
AssetId: assetIdBytes,
120+
AssetEdgeNode: assetSwap.peerPubkey,
121+
}
122+
initatior += "-" + assetSwap.assetId
123+
}
98124

99125
quote, err := b.cfg.LoopOutQuote(
100126
ctx, &loop.LoopOutQuoteRequest{
101127
Amount: amount,
102128
SweepConfTarget: params.SweepConfTarget,
103129
SwapPublicationDeadline: b.cfg.Clock.Now(),
104-
Initiator: getInitiator(params),
130+
Initiator: initatior,
131+
AssetRFQRequest: assetRfqRequest,
105132
},
106133
)
107134
if err != nil {
@@ -146,7 +173,13 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
146173
MaxSwapFee: quote.SwapFee,
147174
MaxPrepayAmount: quote.PrepayAmount,
148175
SweepConfTarget: params.SweepConfTarget,
149-
Initiator: getInitiator(params),
176+
Initiator: initatior,
177+
}
178+
179+
if assetSwap != nil {
180+
request.AssetId = assetIdBytes
181+
request.AssetPrepayRfqId = quote.LoopOutRfq.PrepayRfqId
182+
request.AssetSwapRfqId = quote.LoopOutRfq.SwapRfqId
150183
}
151184

152185
if params.Autoloop {

0 commit comments

Comments
 (0)