Skip to content

Commit 9847f3a

Browse files
authored
Merge pull request #595 from GeorgeTsagk/easy-autoloop-feeppm-param
Easy autoloop feeppm parameter
2 parents 319a519 + 13da224 commit 9847f3a

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

docs/autoloop.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ channel balance of 1M sats. Keep in mind that on first time use this will use
2525
the default budget parameters. If you wish to configure a custom budget you can
2626
find more info in the [Budget](#budget) section.
2727

28+
In addition, if you want to control the maximum amount of fees you're willing to
29+
spend per swap, as a percentage of the total swap amount, you can use the
30+
`feepercent` parameter as explained in the [Fees](#fees) section.
31+
2832
## Liquidity Rules
2933

3034
At present, autoloop can be configured to either acquire incoming liquidity
@@ -89,10 +93,11 @@ to a percentage of the swap amount using the fee percentage parameter:
8993
loop setparams --feepercent={percentage of swap amount}
9094
```
9195

92-
If you would like finer grained control over swap fees, there are multiple fee
93-
related settings which can be used to tune the autolooper to your preference.
94-
The sections that follow explain these settings in detail. Note that these fees
95-
are expressed on a per-swap basis, rather than as an overall budget.
96+
If you are not using easyautoloop and you would like finer grained control over
97+
swap fees, there are multiple fee related settings which can be used to tune the
98+
autolooper to your preference. The sections that follow explain these settings
99+
in detail. Note that these fees are expressed on a per-swap basis, rather than
100+
as an overall budget.
96101

97102
### On-Chain Fees
98103
When performing a successful loop out swap, the loop client needs to sweep the

liquidity/autoloop_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,33 @@ func TestEasyAutoloop(t *testing.T) {
14191419

14201420
c.easyautoloop(step, true)
14211421
c.stop()
1422+
1423+
// Restore the local balance to a higher value that will trigger a swap.
1424+
easyChannel2.LocalBalance = btcutil.Amount(95000)
1425+
channels = []lndclient.ChannelInfo{
1426+
easyChannel1, easyChannel2,
1427+
}
1428+
1429+
// Override the feeppm with a lower one.
1430+
params.FeeLimit = NewFeePortion(5)
1431+
1432+
c = newAutoloopTestCtx(t, params, channels, testRestrictions)
1433+
c.start()
1434+
1435+
// Even though there should be a swap dispatched in order to meet the
1436+
// local balance target, we expect no action as the user defined feeppm
1437+
// should not be sufficient for the swap to be dispatched.
1438+
step = &easyAutoloopStep{
1439+
minAmt: 1,
1440+
maxAmt: 50000,
1441+
// Since we have the exact same balance as the first step, we
1442+
// can reuse the quoteOut1 for the expected loop out quote.
1443+
quotesOut: quotesOut1,
1444+
expectedOut: nil,
1445+
}
1446+
1447+
c.easyautoloop(step, false)
1448+
c.stop()
14221449
}
14231450

14241451
// existingSwapFromRequest is a helper function which returns the db

liquidity/liquidity.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,21 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
600600
return err
601601
}
602602

603-
// Override our current parameters in order to use the const percent
604-
// limit of easy-autoloop.
603+
// If no fee is set, override our current parameters in order to use the
604+
// default percent limit of easy-autoloop.
605605
easyParams := m.params
606-
easyParams.FeeLimit = &FeePortion{
607-
PartsPerMillion: defaultFeePPM,
606+
607+
switch feeLimit := easyParams.FeeLimit.(type) {
608+
case *FeePortion:
609+
if feeLimit.PartsPerMillion == 0 {
610+
feeLimit = &FeePortion{
611+
PartsPerMillion: defaultFeePPM,
612+
}
613+
}
614+
default:
615+
feeLimit = &FeePortion{
616+
PartsPerMillion: defaultFeePPM,
617+
}
608618
}
609619

610620
// Set the swap outgoing channel to the chosen channel.

0 commit comments

Comments
 (0)