Skip to content

Commit c5ee984

Browse files
authored
Merge pull request #340 from carlaKC/autoloop-feepercentage
liquidity: flat fee percentage for autoloop
2 parents 9ce7fe4 + 34726a4 commit c5ee984

File tree

14 files changed

+1156
-501
lines changed

14 files changed

+1156
-501
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{

docs/autoloop.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ loop setrule {short channel id/ peer pubkey} --clear
5555
```
5656

5757
## Fees
58-
Fee control is one of the most important features of the autolooper, so we expose
59-
multiple fee related settings which can be used to tune the autolooper to your
60-
preference. Note that these fees are expressed on a per-swap basis, rather than
61-
as an overall budget.
58+
The amount of fees that an automatically dispatched swap consumes can be limited
59+
to a percentage of the swap amount using the fee percentage parameter:
60+
```
61+
loop setparams --feepercent={percentage of swap amount}
62+
```
63+
64+
If you would like finer grained control over swap fees, there are multiple fee
65+
related settings which can be used to tune the autolooper to your preference.
66+
The sections that follow explain these settings in detail. Note that these fees
67+
are expressed on a per-swap basis, rather than as an overall budget.
6268

6369
### On-Chain Fees
6470
When performing a successful loop out swap, the loop client needs to sweep the
@@ -277,6 +283,10 @@ following reasons will be displayed:
277283
* Liquidity ok: if a channel's current liquidity balance is within the bound set
278284
by the rule that it applies to, then a liquidity ok reason will be displayed
279285
to indicate that no action is required for that channel.
286+
* Fee insufficient: if the fees that a swap will cost are more than the
287+
percentage of total swap amount that we allow, this reason will be displayed.
288+
See [fees](#fees) to update this value.
289+
280290

281291
Further details for all of these reasons can be found in loopd's debug level
282292
logs.

0 commit comments

Comments
 (0)