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.
pull/75/head
Johan T. Halseth 5 years ago
parent ea1f9ff8ba
commit 7ea0e35299
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -68,7 +68,7 @@ func loopIn(ctx *cli.Context) error {
} }
limits := getInLimits(amt, quote) limits := getInLimits(amt, quote)
err = displayLimits(swap.TypeIn, amt, limits, external) err = displayLimits(swap.TypeIn, amt, limits, external, "")
if err != nil { if err != nil {
return err return err
} }

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"time"
"github.com/lightninglabs/loop" "github.com/lightninglabs/loop"
"github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/looprpc"
@ -44,6 +45,16 @@ var loopOutCommand = cli.Command{
"should be swept within", "should be swept within",
Value: uint64(loop.DefaultSweepConfTarget), Value: uint64(loop.DefaultSweepConfTarget),
}, },
cli.BoolFlag{
Name: "fast",
Usage: "Indicate you want to swap immediately, " +
"paying potentially a higher fee. If not " +
"set the swap server might choose to wait up " +
"to 30 minutes before publishing the swap " +
"HTLC on-chain, to save on chain fees. Not " +
"setting this flag might result in a lower " +
"swap fee.",
},
}, },
Action: loopOut, Action: loopOut,
} }
@ -92,9 +103,19 @@ func loopOut(ctx *cli.Context) error {
return err return err
} }
limits := getLimits(amt, quote) // Show a warning if a slow swap was requested.
fast := ctx.Bool("fast")
warning := ""
if fast {
warning = "Fast swap requested."
} else {
warning = fmt.Sprintf("Regular swap speed requested, it "+
"might take up to %v for the swap to be executed.",
defaultSwapWaitTime)
}
err = displayLimits(swap.TypeOut, amt, limits, false) limits := getLimits(amt, quote)
err = displayLimits(swap.TypeOut, amt, limits, false, warning)
if err != nil { if err != nil {
return err return err
} }
@ -104,16 +125,24 @@ func loopOut(ctx *cli.Context) error {
unchargeChannel = ctx.Uint64("channel") unchargeChannel = ctx.Uint64("channel")
} }
// Set our maximum swap wait time. If a fast swap is requested we set
// it to now, otherwise to 30 minutes in the future.
swapDeadline := time.Now()
if !fast {
swapDeadline = time.Now().Add(defaultSwapWaitTime)
}
resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{ resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
Amt: int64(amt), Amt: int64(amt),
Dest: destAddr, Dest: destAddr,
MaxMinerFee: int64(limits.maxMinerFee), MaxMinerFee: int64(limits.maxMinerFee),
MaxPrepayAmt: int64(*limits.maxPrepayAmt), MaxPrepayAmt: int64(*limits.maxPrepayAmt),
MaxSwapFee: int64(limits.maxSwapFee), MaxSwapFee: int64(limits.maxSwapFee),
MaxPrepayRoutingFee: int64(*limits.maxPrepayRoutingFee), MaxPrepayRoutingFee: int64(*limits.maxPrepayRoutingFee),
MaxSwapRoutingFee: int64(*limits.maxSwapRoutingFee), MaxSwapRoutingFee: int64(*limits.maxSwapRoutingFee),
LoopOutChannel: unchargeChannel, LoopOutChannel: unchargeChannel,
SweepConfTarget: sweepConfTarget, SweepConfTarget: sweepConfTarget,
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
}) })
if err != nil { if err != nil {
return err return err

@ -26,6 +26,8 @@ var (
maxRoutingFeeBase = btcutil.Amount(10) maxRoutingFeeBase = btcutil.Amount(10)
maxRoutingFeeRate = int64(20000) maxRoutingFeeRate = int64(20000)
defaultSwapWaitTime = 30 * time.Minute
) )
func printRespJSON(resp proto.Message) { func printRespJSON(resp proto.Message) {
@ -117,7 +119,7 @@ func getLimits(amt btcutil.Amount, quote *looprpc.QuoteResponse) *limits {
} }
func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits, func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
externalHtlc bool) error { externalHtlc bool, warning string) error {
totalSuccessMax := l.maxMinerFee + l.maxSwapFee totalSuccessMax := l.maxMinerFee + l.maxSwapFee
if l.maxSwapRoutingFee != nil { if l.maxSwapRoutingFee != nil {
@ -138,6 +140,10 @@ func displayLimits(swapType swap.Type, amt btcutil.Amount, l *limits,
amt, swapType, totalSuccessMax, amt, swapType, totalSuccessMax,
) )
if warning != "" {
fmt.Println(warning)
}
fmt.Printf("CONTINUE SWAP? (y/n), expand fee detail (x): ") fmt.Printf("CONTINUE SWAP? (y/n), expand fee detail (x): ")
var answer string var answer string

Loading…
Cancel
Save