Skip to content

Commit 7ea0e35

Browse files
committed
cmd/loop: delay swap by 30 minutes by default, add --fast to loopout command
We now delay the swap by up to 30 minutes by deafult. To keep the current imemdiate swap, --fast flag is added.
1 parent ea1f9ff commit 7ea0e35

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

cmd/loop/loopin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func loopIn(ctx *cli.Context) error {
6868
}
6969

7070
limits := getInLimits(amt, quote)
71-
err = displayLimits(swap.TypeIn, amt, limits, external)
71+
err = displayLimits(swap.TypeIn, amt, limits, external, "")
7272
if err != nil {
7373
return err
7474
}

cmd/loop/loopout.go

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"time"
67

78
"github.com/lightninglabs/loop"
89
"github.com/lightninglabs/loop/looprpc"
@@ -44,6 +45,16 @@ var loopOutCommand = cli.Command{
4445
"should be swept within",
4546
Value: uint64(loop.DefaultSweepConfTarget),
4647
},
48+
cli.BoolFlag{
49+
Name: "fast",
50+
Usage: "Indicate you want to swap immediately, " +
51+
"paying potentially a higher fee. If not " +
52+
"set the swap server might choose to wait up " +
53+
"to 30 minutes before publishing the swap " +
54+
"HTLC on-chain, to save on chain fees. Not " +
55+
"setting this flag might result in a lower " +
56+
"swap fee.",
57+
},
4758
},
4859
Action: loopOut,
4960
}
@@ -92,9 +103,19 @@ func loopOut(ctx *cli.Context) error {
92103
return err
93104
}
94105

95-
limits := getLimits(amt, quote)
106+
// Show a warning if a slow swap was requested.
107+
fast := ctx.Bool("fast")
108+
warning := ""
109+
if fast {
110+
warning = "Fast swap requested."
111+
} else {
112+
warning = fmt.Sprintf("Regular swap speed requested, it "+
113+
"might take up to %v for the swap to be executed.",
114+
defaultSwapWaitTime)
115+
}
96116

97-
err = displayLimits(swap.TypeOut, amt, limits, false)
117+
limits := getLimits(amt, quote)
118+
err = displayLimits(swap.TypeOut, amt, limits, false, warning)
98119
if err != nil {
99120
return err
100121
}
@@ -104,16 +125,24 @@ func loopOut(ctx *cli.Context) error {
104125
unchargeChannel = ctx.Uint64("channel")
105126
}
106127

128+
// Set our maximum swap wait time. If a fast swap is requested we set
129+
// it to now, otherwise to 30 minutes in the future.
130+
swapDeadline := time.Now()
131+
if !fast {
132+
swapDeadline = time.Now().Add(defaultSwapWaitTime)
133+
}
134+
107135
resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
108-
Amt: int64(amt),
109-
Dest: destAddr,
110-
MaxMinerFee: int64(limits.maxMinerFee),
111-
MaxPrepayAmt: int64(*limits.maxPrepayAmt),
112-
MaxSwapFee: int64(limits.maxSwapFee),
113-
MaxPrepayRoutingFee: int64(*limits.maxPrepayRoutingFee),
114-
MaxSwapRoutingFee: int64(*limits.maxSwapRoutingFee),
115-
LoopOutChannel: unchargeChannel,
116-
SweepConfTarget: sweepConfTarget,
136+
Amt: int64(amt),
137+
Dest: destAddr,
138+
MaxMinerFee: int64(limits.maxMinerFee),
139+
MaxPrepayAmt: int64(*limits.maxPrepayAmt),
140+
MaxSwapFee: int64(limits.maxSwapFee),
141+
MaxPrepayRoutingFee: int64(*limits.maxPrepayRoutingFee),
142+
MaxSwapRoutingFee: int64(*limits.maxSwapRoutingFee),
143+
LoopOutChannel: unchargeChannel,
144+
SweepConfTarget: sweepConfTarget,
145+
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
117146
})
118147
if err != nil {
119148
return err

cmd/loop/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var (
2626
maxRoutingFeeBase = btcutil.Amount(10)
2727

2828
maxRoutingFeeRate = int64(20000)
29+
30+
defaultSwapWaitTime = 30 * time.Minute
2931
)
3032

3133
func printRespJSON(resp proto.Message) {
@@ -117,7 +119,7 @@ func getLimits(amt btcutil.Amount, quote *looprpc.QuoteResponse) *limits {
117119
}
118120

119121
func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
120-
externalHtlc bool) error {
122+
externalHtlc bool, warning string) error {
121123

122124
totalSuccessMax := l.maxMinerFee + l.maxSwapFee
123125
if l.maxSwapRoutingFee != nil {
@@ -138,6 +140,10 @@ func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
138140
amt, swapType, totalSuccessMax,
139141
)
140142

143+
if warning != "" {
144+
fmt.Println(warning)
145+
}
146+
141147
fmt.Printf("CONTINUE SWAP? (y/n), expand fee detail (x): ")
142148

143149
var answer string

0 commit comments

Comments
 (0)