Skip to content

Commit 0023d1a

Browse files
committed
looprpc: update to new server protos
We update to new set of server protos where new Terms calls are added. Here static information will be returned from the server. We no longer have a feebase+feerate, but get a final fee directly returned by the server.
1 parent 0cff92d commit 0023d1a

File tree

8 files changed

+470
-139
lines changed

8 files changed

+470
-139
lines changed

client.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,14 @@ func (s *Client) LoopOutQuote(ctx context.Context,
353353
return nil, ErrSwapAmountTooHigh
354354
}
355355

356-
logger.Infof("Offchain swap destination: %x", terms.SwapPaymentDest)
356+
quote, err := s.Server.GetLoopOutQuote(ctx, request.Amount)
357+
if err != nil {
358+
return nil, err
359+
}
357360

358-
swapFee := swap.CalcFee(
359-
request.Amount, terms.SwapFeeBase, terms.SwapFeeRate,
360-
)
361+
logger.Infof("Offchain swap destination: %x", quote.SwapPaymentDest)
362+
363+
swapFee := quote.SwapFee
361364

362365
// Generate dummy p2wsh address for fee estimation. The p2wsh address
363366
// type is chosen because it adds the most weight of all output types
@@ -379,9 +382,11 @@ func (s *Client) LoopOutQuote(ctx context.Context,
379382
}
380383

381384
return &LoopOutQuote{
382-
SwapFee: swapFee,
383-
MinerFee: minerFee,
384-
PrepayAmount: btcutil.Amount(terms.PrepayAmt),
385+
SwapFee: swapFee,
386+
MinerFee: minerFee,
387+
PrepayAmount: btcutil.Amount(quote.PrepayAmount),
388+
SwapPaymentDest: quote.SwapPaymentDest,
389+
CltvDelta: quote.CltvDelta,
385390
}, nil
386391
}
387392

@@ -465,10 +470,12 @@ func (s *Client) LoopInQuote(ctx context.Context,
465470
return nil, ErrSwapAmountTooHigh
466471
}
467472

468-
// Calculate swap fee.
469-
swapFee := terms.SwapFeeBase +
470-
request.Amount*btcutil.Amount(terms.SwapFeeRate)/
471-
btcutil.Amount(swap.FeeRateTotalParts)
473+
quote, err := s.Server.GetLoopInQuote(ctx, request.Amount)
474+
if err != nil {
475+
return nil, err
476+
}
477+
478+
swapFee := quote.SwapFee
472479

473480
// We don't calculate the on-chain fee if the HTLC is going to be
474481
// published externally.
@@ -478,7 +485,7 @@ func (s *Client) LoopInQuote(ctx context.Context,
478485
MinerFee: 0,
479486
}, nil
480487
}
481-
488+
482489
// Get estimate for miner fee.
483490
minerFee, err := s.lndServices.Client.EstimateFeeToP2WSH(
484491
ctx, request.Amount, request.HtlcConfTarget,
@@ -488,8 +495,9 @@ func (s *Client) LoopInQuote(ctx context.Context,
488495
}
489496

490497
return &LoopInQuote{
491-
SwapFee: swapFee,
492-
MinerFee: minerFee,
498+
SwapFee: swapFee,
499+
MinerFee: minerFee,
500+
CltvDelta: quote.CltvDelta,
493501
}, nil
494502
}
495503

cmd/loopd/swapclient_server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@ func (s *swapClientServer) LoopOutQuote(ctx context.Context,
267267
}
268268

269269
return &looprpc.QuoteResponse{
270-
MinerFee: int64(quote.MinerFee),
271-
PrepayAmt: int64(quote.PrepayAmount),
272-
SwapFee: int64(quote.SwapFee),
270+
MinerFee: int64(quote.MinerFee),
271+
PrepayAmt: int64(quote.PrepayAmount),
272+
SwapFee: int64(quote.SwapFee),
273+
SwapPaymentDest: quote.SwapPaymentDest[:],
274+
CltvDelta: quote.CltvDelta,
273275
}, nil
274276
}
275277

interface.go

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ type LoopOutQuoteRequest struct {
105105
// final cltv delta values for the off-chain payments.
106106
}
107107

108+
// LoopOutTerms are the server terms on which it executes swaps.
109+
type LoopOutTerms struct {
110+
// MinSwapAmount is the minimum amount that the server requires for a
111+
// swap.
112+
MinSwapAmount btcutil.Amount
113+
114+
// MaxSwapAmount is the maximum amount that the server accepts for a
115+
// swap.
116+
MaxSwapAmount btcutil.Amount
117+
}
118+
108119
// LoopOutQuote contains estimates for the fees making up the total swap cost
109120
// for the client.
110121
type LoopOutQuote struct {
@@ -118,27 +129,6 @@ type LoopOutQuote struct {
118129
// MinerFee is an estimate of the on-chain fee that needs to be paid to
119130
// sweep the htlc.
120131
MinerFee btcutil.Amount
121-
}
122-
123-
// LoopOutTerms are the server terms on which it executes swaps.
124-
type LoopOutTerms struct {
125-
// SwapFeeBase is the fixed per-swap base fee.
126-
SwapFeeBase btcutil.Amount
127-
128-
// SwapFeeRate is the variable fee in parts per million.
129-
SwapFeeRate int64
130-
131-
// PrepayAmt is the fixed part of the swap fee that needs to be
132-
// prepaid.
133-
PrepayAmt btcutil.Amount
134-
135-
// MinSwapAmount is the minimum amount that the server requires for a
136-
// swap.
137-
MinSwapAmount btcutil.Amount
138-
139-
// MaxSwapAmount is the maximum amount that the server accepts for a
140-
// swap.
141-
MaxSwapAmount btcutil.Amount
142132

143133
// Time lock delta relative to current block height that swap server
144134
// will accept on the swap initiation call.
@@ -185,23 +175,13 @@ type LoopInRequest struct {
185175

186176
// LoopInTerms are the server terms on which it executes charge swaps.
187177
type LoopInTerms struct {
188-
// SwapFeeBase is the fixed per-swap base fee.
189-
SwapFeeBase btcutil.Amount
190-
191-
// SwapFeeRate is the variable fee in parts per million.
192-
SwapFeeRate int64
193-
194178
// MinSwapAmount is the minimum amount that the server requires for a
195179
// swap.
196180
MinSwapAmount btcutil.Amount
197181

198182
// MaxSwapAmount is the maximum amount that the server accepts for a
199183
// swap.
200184
MaxSwapAmount btcutil.Amount
201-
202-
// Time lock delta relative to current block height that swap server
203-
// will accept on the swap initiation call.
204-
CltvDelta int32
205185
}
206186

207187
// In contains status information for a loop in swap.
@@ -239,6 +219,10 @@ type LoopInQuote struct {
239219
// MinerFee is an estimate of the on-chain fee that needs to be paid to
240220
// sweep the htlc.
241221
MinerFee btcutil.Amount
222+
223+
// Time lock delta relative to current block height that swap server
224+
// will accept on the swap initiation call.
225+
CltvDelta int32
242226
}
243227

244228
// SwapInfoKit contains common swap info fields.

loopin.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
6060
// Request current server loop in terms and use these to calculate the
6161
// swap fee that we should subtract from the swap amount in the payment
6262
// request that we send to the server.
63-
quote, err := cfg.server.GetLoopInTerms(globalCtx)
63+
quote, err := cfg.server.GetLoopInQuote(globalCtx, request.Amount)
6464
if err != nil {
6565
return nil, fmt.Errorf("loop in terms: %v", err)
6666
}
6767

68-
swapFee := swap.CalcFee(
69-
request.Amount, quote.SwapFeeBase, quote.SwapFeeRate,
70-
)
68+
swapFee := quote.SwapFee
7169

7270
if swapFee > request.MaxSwapFee {
7371
logger.Warnf("Swap fee %v exceeding maximum of %v",

0 commit comments

Comments
 (0)