Skip to content

Commit ed95c16

Browse files
committed
loop: add set params command
1 parent 8931fd3 commit ed95c16

File tree

2 files changed

+156
-1
lines changed

2 files changed

+156
-1
lines changed

cmd/loop/liquidity.go

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"strconv"
77

8+
"github.com/lightninglabs/loop/liquidity"
89
"github.com/lightninglabs/loop/looprpc"
910
"github.com/urfave/cli"
1011
)
@@ -173,6 +174,160 @@ func setRule(ctx *cli.Context) error {
173174
return err
174175
}
175176

177+
var setParamsCommand = cli.Command{
178+
Name: "setparams",
179+
Usage: "update the parameters set for the liquidity manager",
180+
Description: "Updates the parameters set for the liquidity manager.",
181+
Flags: []cli.Flag{
182+
cli.IntFlag{
183+
Name: "sweeplimit",
184+
Usage: "the limit placed on our estimated sweep fee " +
185+
"in sat/vByte.",
186+
},
187+
cli.Float64Flag{
188+
Name: "maxswapfee",
189+
Usage: "the maximum percentage of swap volume we are " +
190+
"willing to pay in server fees.",
191+
},
192+
cli.Float64Flag{
193+
Name: "maxroutingfee",
194+
Usage: "the maximum percentage of off-chain payment " +
195+
"volume that are are willing to pay in " +
196+
"routing fees.",
197+
},
198+
cli.Float64Flag{
199+
Name: "maxprepayfee",
200+
Usage: "the maximum percentage of off-chain prepay " +
201+
"volume that are are willing to pay in " +
202+
"routing fees.",
203+
},
204+
cli.Uint64Flag{
205+
Name: "maxprepay",
206+
Usage: "the maximum no-show (prepay) in satoshis that " +
207+
"swap suggestions should be limited to.",
208+
},
209+
cli.Uint64Flag{
210+
Name: "maxminer",
211+
Usage: "the maximum miner fee in satoshis that swap " +
212+
"suggestions should be limited to.",
213+
},
214+
cli.IntFlag{
215+
Name: "sweepconf",
216+
Usage: "the number of blocks from htlc height that " +
217+
"swap suggestion sweeps should target, used " +
218+
"to estimate max miner fee.",
219+
},
220+
cli.Uint64Flag{
221+
Name: "failurebackoff",
222+
Usage: "the amount of time, in seconds, that " +
223+
"should pass before a channel that " +
224+
"previously had a failed swap will be " +
225+
"included in suggestions.",
226+
},
227+
},
228+
Action: setParams,
229+
}
230+
231+
func setParams(ctx *cli.Context) error {
232+
client, cleanup, err := getClient(ctx)
233+
if err != nil {
234+
return err
235+
}
236+
defer cleanup()
237+
238+
// We need to set the full set of current parameters every time we call
239+
// SetParameters. To allow users to set only individual fields on the
240+
// cli, we lookup our current params, then update individual values.
241+
params, err := client.GetLiquidityParams(
242+
context.Background(), &looprpc.GetLiquidityParamsRequest{},
243+
)
244+
if err != nil {
245+
return err
246+
}
247+
248+
var flagSet bool
249+
250+
if ctx.IsSet("maxswapfee") {
251+
feeRate := ctx.Float64("maxswapfee")
252+
params.MaxSwapFeePpm, err = ppmFromPercentage(feeRate)
253+
if err != nil {
254+
return err
255+
}
256+
257+
flagSet = true
258+
}
259+
260+
if ctx.IsSet("sweeplimit") {
261+
satPerVByte := ctx.Int("sweeplimit")
262+
params.SweepFeeRateSatPerVbyte = uint64(satPerVByte)
263+
264+
flagSet = true
265+
}
266+
267+
if ctx.IsSet("maxroutingfee") {
268+
feeRate := ctx.Float64("maxroutingfee")
269+
params.MaxRoutingFeePpm, err = ppmFromPercentage(feeRate)
270+
if err != nil {
271+
return err
272+
}
273+
274+
flagSet = true
275+
}
276+
277+
if ctx.IsSet("maxprepayfee") {
278+
feeRate := ctx.Float64("maxprepayfee")
279+
params.MaxPrepayRoutingFeePpm, err = ppmFromPercentage(feeRate)
280+
if err != nil {
281+
return err
282+
}
283+
284+
flagSet = true
285+
}
286+
287+
if ctx.IsSet("maxprepay") {
288+
params.MaxPrepaySat = ctx.Uint64("maxprepay")
289+
flagSet = true
290+
}
291+
292+
if ctx.IsSet("maxminer") {
293+
params.MaxMinerFeeSat = ctx.Uint64("maxminer")
294+
flagSet = true
295+
}
296+
297+
if ctx.IsSet("sweepconf") {
298+
params.SweepConfTarget = int32(ctx.Int("sweepconf"))
299+
flagSet = true
300+
}
301+
302+
if ctx.IsSet("failurebackoff") {
303+
params.FailureBackoffSec = ctx.Uint64("failurebackoff")
304+
flagSet = true
305+
}
306+
307+
if !flagSet {
308+
return fmt.Errorf("at least one flag required to set params")
309+
}
310+
311+
// Update our parameters to our mutated values.
312+
_, err = client.SetLiquidityParams(
313+
context.Background(), &looprpc.SetLiquidityParamsRequest{
314+
Parameters: params,
315+
},
316+
)
317+
318+
return err
319+
}
320+
321+
// ppmFromPercentage converts a percentage, expressed as a float, to parts
322+
// per million.
323+
func ppmFromPercentage(percentage float64) (uint64, error) {
324+
if percentage <= 0 || percentage >= 100 {
325+
return 0, fmt.Errorf("fee percentage must be in (0;100)")
326+
}
327+
328+
return uint64(percentage / 100 * liquidity.FeeBase), nil
329+
}
330+
176331
var suggestSwapCommand = cli.Command{
177332
Name: "suggestswaps",
178333
Usage: "show a list of suggested swaps",

cmd/loop/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func main() {
129129
loopOutCommand, loopInCommand, termsCommand,
130130
monitorCommand, quoteCommand, listAuthCommand,
131131
listSwapsCommand, swapInfoCommand, getLiquidityParamsCommand,
132-
setLiquidityRuleCommand, suggestSwapCommand,
132+
setLiquidityRuleCommand, suggestSwapCommand, setParamsCommand,
133133
}
134134

135135
err := app.Run(os.Args)

0 commit comments

Comments
 (0)