From 64d2cbe5d6b1763616cc344f47252a8a356dd291 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Wed, 14 Jun 2023 14:12:17 +0300 Subject: [PATCH 1/3] liquidity: respect feeppm if set for easyautoloop --- liquidity/liquidity.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/liquidity/liquidity.go b/liquidity/liquidity.go index 9efd526..97da8ad 100644 --- a/liquidity/liquidity.go +++ b/liquidity/liquidity.go @@ -600,11 +600,21 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error { return err } - // Override our current parameters in order to use the const percent - // limit of easy-autoloop. + // If no fee is set, override our current parameters in order to use the + // default percent limit of easy-autoloop. easyParams := m.params - easyParams.FeeLimit = &FeePortion{ - PartsPerMillion: defaultFeePPM, + + switch feeLimit := easyParams.FeeLimit.(type) { + case *FeePortion: + if feeLimit.PartsPerMillion == 0 { + feeLimit = &FeePortion{ + PartsPerMillion: defaultFeePPM, + } + } + default: + feeLimit = &FeePortion{ + PartsPerMillion: defaultFeePPM, + } } // Set the swap outgoing channel to the chosen channel. From dbb49cfa0519ac8c2c66f7ff39525992548cd072 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Wed, 14 Jun 2023 14:12:44 +0300 Subject: [PATCH 2/3] liquidity: test low feeppm case for easyautoloop --- liquidity/autoloop_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/liquidity/autoloop_test.go b/liquidity/autoloop_test.go index ff7777f..4c63ead 100644 --- a/liquidity/autoloop_test.go +++ b/liquidity/autoloop_test.go @@ -1419,6 +1419,33 @@ func TestEasyAutoloop(t *testing.T) { c.easyautoloop(step, true) c.stop() + + // Restore the local balance to a higher value that will trigger a swap. + easyChannel2.LocalBalance = btcutil.Amount(95000) + channels = []lndclient.ChannelInfo{ + easyChannel1, easyChannel2, + } + + // Override the feeppm with a lower one. + params.FeeLimit = NewFeePortion(5) + + c = newAutoloopTestCtx(t, params, channels, testRestrictions) + c.start() + + // Even though there should be a swap dispatched in order to meet the + // local balance target, we expect no action as the user defined feeppm + // should not be sufficient for the swap to be dispatched. + step = &easyAutoloopStep{ + minAmt: 1, + maxAmt: 50000, + // Since we have the exact same balance as the first step, we + // can reuse the quoteOut1 for the expected loop out quote. + quotesOut: quotesOut1, + expectedOut: nil, + } + + c.easyautoloop(step, false) + c.stop() } // existingSwapFromRequest is a helper function which returns the db From 13da22428c2891c54dec519df62c680d1d07424c Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Wed, 14 Jun 2023 14:13:16 +0300 Subject: [PATCH 3/3] docs: add easyautoloop comment for custom feeppm --- docs/autoloop.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/autoloop.md b/docs/autoloop.md index b8d8abe..7bfecad 100644 --- a/docs/autoloop.md +++ b/docs/autoloop.md @@ -25,6 +25,10 @@ channel balance of 1M sats. Keep in mind that on first time use this will use the default budget parameters. If you wish to configure a custom budget you can find more info in the [Budget](#budget) section. +In addition, if you want to control the maximum amount of fees you're willing to +spend per swap, as a percentage of the total swap amount, you can use the +`feepercent` parameter as explained in the [Fees](#fees) section. + ## Liquidity Rules 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: loop setparams --feepercent={percentage of swap amount} ``` -If you would like finer grained control over swap fees, there are multiple fee -related settings which can be used to tune the autolooper to your preference. -The sections that follow explain these settings in detail. Note that these fees -are expressed on a per-swap basis, rather than as an overall budget. +If you are not using easyautoloop and you would like finer grained control over +swap fees, there are multiple fee related settings which can be used to tune the +autolooper to your preference. The sections that follow explain these settings +in detail. Note that these fees are expressed on a per-swap basis, rather than +as an overall budget. ### On-Chain Fees When performing a successful loop out swap, the loop client needs to sweep the