55 "fmt"
66 "strconv"
77
8+ "github.com/lightninglabs/loop/liquidity"
89 "github.com/lightninglabs/loop/looprpc"
910 "github.com/urfave/cli"
1011)
@@ -36,8 +37,8 @@ func getParams(ctx *cli.Context) error {
3637 return nil
3738}
3839
39- var setLiquidityParamCommand = cli.Command {
40- Name : "setparam " ,
40+ var setLiquidityRuleCommand = cli.Command {
41+ Name : "setrule " ,
4142 Usage : "set liquidity manager rule for a channel" ,
4243 Description : "Update or remove the liquidity rule for a channel." ,
4344 ArgsUsage : "shortchanid" ,
@@ -58,10 +59,10 @@ var setLiquidityParamCommand = cli.Command{
5859 Usage : "remove the rule currently set for the channel." ,
5960 },
6061 },
61- Action : setParam ,
62+ Action : setRule ,
6263}
6364
64- func setParam (ctx * cli.Context ) error {
65+ func setRule (ctx * cli.Context ) error {
6566 // We require that a channel ID is set for this rule update.
6667 if ctx .NArg () != 1 {
6768 return fmt .Errorf ("please set a channel id for the rule " +
@@ -122,12 +123,11 @@ func setParam(ctx *cli.Context) error {
122123 "flag" )
123124 }
124125
126+ params .Rules = otherRules
125127 _ , err = client .SetLiquidityParams (
126128 context .Background (),
127129 & looprpc.SetLiquidityParamsRequest {
128- Parameters : & looprpc.LiquidityParameters {
129- Rules : otherRules ,
130- },
130+ Parameters : params ,
131131 },
132132 )
133133 return err
@@ -158,19 +158,176 @@ func setParam(ctx *cli.Context) error {
158158 )
159159 }
160160
161+ // Just set the rules on our current set of parameters and leave the
162+ // other values untouched.
163+ otherRules = append (otherRules , newRule )
164+ params .Rules = otherRules
165+
161166 // Update our parameters to the existing set, plus our new rule.
162167 _ , err = client .SetLiquidityParams (
163168 context .Background (),
164169 & looprpc.SetLiquidityParamsRequest {
165- Parameters : & looprpc.LiquidityParameters {
166- Rules : append (otherRules , newRule ),
167- },
170+ Parameters : params ,
168171 },
169172 )
170173
171174 return err
172175}
173176
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+
174331var suggestSwapCommand = cli.Command {
175332 Name : "suggestswaps" ,
176333 Usage : "show a list of suggested swaps" ,
0 commit comments