Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hyperloop/swaps 2.0 #810

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
77 changes: 77 additions & 0 deletions cmd/loop/hyperloop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"context"

"github.com/lightninglabs/loop/looprpc"
"github.com/urfave/cli"
)

var hyperloopCommand = cli.Command{
Name: "hyperloop",
Usage: "perform a fee optimized off-chain to on-chain swap (hyperloop)",
Description: `

`,
ArgsUsage: "amt",
Flags: []cli.Flag{
cli.Uint64Flag{
Name: "amt",
Usage: "the amount in satoshis to loop out. To check " +
"for the minimum and maximum amounts to loop " +
"out please consult \"loop terms\"",
},
cli.StringFlag{
Name: "addr",
Usage: "the optional address that the looped out funds " +
"should be sent to, if let blank the funds " +
"will go to lnd's wallet",
},
},

Action: hyperloop,
}

func hyperloop(ctx *cli.Context) error {
args := ctx.Args()

var amtStr string
switch {
case ctx.IsSet("amt"):
amtStr = ctx.String("amt")
case ctx.NArg() > 0:
amtStr = args[0]
args = args.Tail()
default:
// Show command help if no arguments and flags were provided.
return cli.ShowCommandHelp(ctx, "hyperloop")
}

amt, err := parseAmt(amtStr)
if err != nil {
return err
}

// First set up the swap client itself.
client, cleanup, err := getClient(ctx)
if err != nil {
return err
}
defer cleanup()
ctxb := context.Background()

hyperloopRes, err := client.HyperLoopOut(
ctxb,
&looprpc.HyperLoopOutRequest{
Amt: uint64(amt),
CustomSweepAddr: ctx.String("addr"),
},
)
if err != nil {
return err
}

printJSON(hyperloopRes)

return nil
}
2 changes: 1 addition & 1 deletion cmd/loop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func main() {
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
getInfoCommand, abandonSwapCommand, reservationsCommands,
instantOutCommand, listInstantOutsCommand,
instantOutCommand, listInstantOutsCommand, hyperloopCommand,
}

err := app.Run(os.Args)
Expand Down
8 changes: 8 additions & 0 deletions fsm/stateparser/stateparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sort"

"github.com/lightninglabs/loop/fsm"
"github.com/lightninglabs/loop/hyperloop"
"github.com/lightninglabs/loop/instantout"
"github.com/lightninglabs/loop/instantout/reservation"
)
Expand Down Expand Up @@ -57,6 +58,13 @@ func run() error {
return err
}

case "hyperloop":
hyperloop := hyperloop.FSM{}
err = writeMermaidFile(fp, hyperloop.GetStateMap())
if err != nil {
return err
}

default:
fmt.Println("Missing or wrong argument: fsm must be one of:")
fmt.Println("\treservations")
Expand Down
Loading
Loading