Skip to content

Commit 299a0a4

Browse files
committed
loop: add fee ppm to autoloop cli
1 parent 90561f8 commit 299a0a4

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

cmd/loop/liquidity.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ var setParamsCommand = cli.Command{
212212
Usage: "the limit placed on our estimated sweep fee " +
213213
"in sat/vByte.",
214214
},
215+
cli.IntFlag{
216+
Name: "feepercent",
217+
Usage: "the maximum percentage of swap amount to be " +
218+
"used across all fee categories",
219+
},
215220
cli.Float64Flag{
216221
Name: "maxswapfee",
217222
Usage: "the maximum percentage of swap volume we are " +
@@ -307,8 +312,11 @@ func setParams(ctx *cli.Context) error {
307312
return err
308313
}
309314

310-
var flagSet bool
315+
var flagSet, categoriesSet, feePercentSet bool
311316

317+
// Update our existing parameters with the values provided by cli flags.
318+
// Our fee categories and fee percentage are exclusive, so track which
319+
// flags are set to ensure that we don't have nonsensical overlap.
312320
if ctx.IsSet("maxswapfee") {
313321
feeRate := ctx.Float64("maxswapfee")
314322
params.MaxSwapFeePpm, err = ppmFromPercentage(feeRate)
@@ -317,13 +325,26 @@ func setParams(ctx *cli.Context) error {
317325
}
318326

319327
flagSet = true
328+
categoriesSet = true
320329
}
321330

322331
if ctx.IsSet("sweeplimit") {
323332
satPerVByte := ctx.Int("sweeplimit")
324333
params.SweepFeeRateSatPerVbyte = uint64(satPerVByte)
325334

326335
flagSet = true
336+
categoriesSet = true
337+
}
338+
339+
if ctx.IsSet("feepercent") {
340+
feeRate := ctx.Float64("feepercent")
341+
params.FeePpm, err = ppmFromPercentage(feeRate)
342+
if err != nil {
343+
return err
344+
}
345+
346+
flagSet = true
347+
feePercentSet = true
327348
}
328349

329350
if ctx.IsSet("maxroutingfee") {
@@ -334,6 +355,7 @@ func setParams(ctx *cli.Context) error {
334355
}
335356

336357
flagSet = true
358+
categoriesSet = true
337359
}
338360

339361
if ctx.IsSet("maxprepayfee") {
@@ -344,16 +366,19 @@ func setParams(ctx *cli.Context) error {
344366
}
345367

346368
flagSet = true
369+
categoriesSet = true
347370
}
348371

349372
if ctx.IsSet("maxprepay") {
350373
params.MaxPrepaySat = ctx.Uint64("maxprepay")
351374
flagSet = true
375+
categoriesSet = true
352376
}
353377

354378
if ctx.IsSet("maxminer") {
355379
params.MaxMinerFeeSat = ctx.Uint64("maxminer")
356380
flagSet = true
381+
categoriesSet = true
357382
}
358383

359384
if ctx.IsSet("sweepconf") {
@@ -400,6 +425,29 @@ func setParams(ctx *cli.Context) error {
400425
return fmt.Errorf("at least one flag required to set params")
401426
}
402427

428+
switch {
429+
// Fail if fee params for both types of fee limit are set, since they
430+
// cannot be used in conjunction.
431+
case feePercentSet && categoriesSet:
432+
return fmt.Errorf("feepercent cannot be set with specific " +
433+
"fee category flags")
434+
435+
// If we are updating to fee percentage, we unset all other fee related
436+
// params so that users do not need to manually unset them.
437+
case feePercentSet:
438+
params.SweepFeeRateSatPerVbyte = 0
439+
params.MaxMinerFeeSat = 0
440+
params.MaxPrepayRoutingFeePpm = 0
441+
params.MaxPrepaySat = 0
442+
params.MaxRoutingFeePpm = 0
443+
params.MaxSwapFeePpm = 0
444+
445+
// If we are setting any of our fee categories, unset fee percentage
446+
// so that it does not need to be manually updated.
447+
case categoriesSet:
448+
params.FeePpm = 0
449+
450+
}
403451
// Update our parameters to our mutated values.
404452
_, err = client.SetLiquidityParams(
405453
context.Background(), &looprpc.SetLiquidityParamsRequest{

0 commit comments

Comments
 (0)