Skip to content

Commit cf65529

Browse files
committed
cmd: add instantout quote
1 parent b3fe9a9 commit cf65529

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

cmd/loop/instantout.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"strconv"
78
"strings"
@@ -97,14 +98,18 @@ func instantOut(ctx *cli.Context) error {
9798
fmt.Scanln(&answer)
9899

99100
// Parse
100-
var selectedReservations [][]byte
101+
var (
102+
selectedReservations [][]byte
103+
selectedAmt uint64
104+
)
101105
switch answer {
102106
case "ALL":
103107
for _, res := range confirmedReservations {
104108
selectedReservations = append(
105109
selectedReservations,
106110
res.ReservationId,
107111
)
112+
selectedAmt += res.Amount
108113
}
109114

110115
case "":
@@ -135,9 +140,33 @@ func instantOut(ctx *cli.Context) error {
135140
)
136141

137142
selectedIndexMap[idx] = struct{}{}
143+
selectedAmt += confirmedReservations[idx-1].Amount
138144
}
139145
}
140146

147+
// Now that we have the selected reservations we can estimate the
148+
// fee-rates.
149+
quote, err := client.InstantOutQuote(
150+
context.Background(), &looprpc.InstantOutQuoteRequest{
151+
Amt: selectedAmt,
152+
NumReservations: int32(len(selectedReservations)),
153+
},
154+
)
155+
if err != nil {
156+
return err
157+
}
158+
fmt.Println()
159+
fmt.Printf(satAmtFmt, "Estimated on-chain fee:", quote.SweepFeeSat)
160+
fmt.Printf(satAmtFmt, "Service fee:", quote.ServiceFeeSat)
161+
fmt.Println()
162+
163+
fmt.Printf("CONTINUE SWAP? (y/n): ")
164+
165+
fmt.Scanln(&answer)
166+
if answer != "y" {
167+
return errors.New("swap canceled")
168+
}
169+
141170
fmt.Println("Starting instant swap out")
142171

143172
// Now we can request the instant out swap.

0 commit comments

Comments
 (0)