2021-04-23 00:51:22 +02:00
|
|
|
#ifndef LIGHTNING_PLUGINS_FUNDER_POLICY_H
|
|
|
|
#define LIGHTNING_PLUGINS_FUNDER_POLICY_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <common/amount.h>
|
|
|
|
|
2023-06-06 02:38:53 +02:00
|
|
|
struct plugin;
|
2021-05-27 01:13:08 +02:00
|
|
|
struct lease_rates;
|
2021-04-23 00:51:22 +02:00
|
|
|
struct node_id;
|
|
|
|
|
|
|
|
/* Policy Options */
|
|
|
|
enum funder_opt {
|
2021-06-08 23:42:45 +02:00
|
|
|
/* Use their_funding/requested_amt as the starting
|
2021-04-23 00:51:22 +02:00
|
|
|
* point for your contribution */
|
|
|
|
MATCH,
|
|
|
|
|
|
|
|
/* Use the 'available_funds' as the starting
|
|
|
|
* point for your contribution */
|
|
|
|
AVAILABLE,
|
|
|
|
|
|
|
|
/* Use a static amount */
|
|
|
|
FIXED,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct funder_policy {
|
|
|
|
/* How to interpret/apply the 'mod' field */
|
|
|
|
enum funder_opt opt;
|
|
|
|
|
|
|
|
/* for MATCH/AVAILABLE, is a percent of base;
|
|
|
|
* for FIXED is the satoshi amount */
|
|
|
|
u64 mod;
|
|
|
|
|
|
|
|
/* `their_funding` must be this much or greater to activate
|
|
|
|
* the policy. Defaults to 10,000 sats */
|
|
|
|
struct amount_sat min_their_funding;
|
|
|
|
|
|
|
|
/* `their_funding` must be this amount or less to activate
|
|
|
|
* the policy. Defaults to MAX_UNITsats */
|
|
|
|
struct amount_sat max_their_funding;
|
|
|
|
|
|
|
|
/* Upper limit on amount to add. Defaults to
|
|
|
|
* `available_funds` */
|
|
|
|
struct amount_sat per_channel_max;
|
|
|
|
|
|
|
|
/* Lower limit on amount to add. Defaults to
|
|
|
|
* 10,000sat */
|
|
|
|
struct amount_sat per_channel_min;
|
|
|
|
|
|
|
|
/* Percent to fuzz by. Default is 5% */
|
|
|
|
u32 fuzz_factor;
|
|
|
|
|
|
|
|
/* Minimum amount to leave unused in `available_funds`.
|
|
|
|
* Note that this is presently best-effort due to concurrency.
|
|
|
|
* Default is 0msat */
|
|
|
|
struct amount_sat reserve_tank;
|
|
|
|
|
|
|
|
/* Percent of open offers we'll consider funding. */
|
|
|
|
u32 fund_probability;
|
2021-05-27 01:13:08 +02:00
|
|
|
|
|
|
|
/* If we're advertising liquidity, only
|
|
|
|
* provide funds for lease requests */
|
|
|
|
bool leases_only;
|
|
|
|
|
|
|
|
/* Rates we're currently charging for channel leases */
|
|
|
|
struct lease_rates *rates;
|
2021-04-23 00:51:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Get a new funder_policy, set to the defaults */
|
2021-05-27 01:10:32 +02:00
|
|
|
struct funder_policy *
|
|
|
|
default_funder_policy(const tal_t *ctx,
|
|
|
|
enum funder_opt policy,
|
2021-04-23 00:51:22 +02:00
|
|
|
u64 policy_mod);
|
|
|
|
|
2021-05-27 01:13:08 +02:00
|
|
|
/* Defaults to use for the lease_rates */
|
|
|
|
struct lease_rates *
|
|
|
|
default_lease_rates(const tal_t *ctx);
|
|
|
|
|
2021-04-23 00:51:22 +02:00
|
|
|
/* Given the policy and this request's details, figure
|
|
|
|
* out how much we should contribute to this channel */
|
2021-05-06 01:03:03 +02:00
|
|
|
const char *
|
2021-05-27 01:10:32 +02:00
|
|
|
calculate_our_funding(struct funder_policy *policy,
|
2021-04-23 00:51:22 +02:00
|
|
|
struct node_id id,
|
|
|
|
struct amount_sat their_funding,
|
2022-10-04 04:18:31 +02:00
|
|
|
struct amount_sat *our_last_funding,
|
2021-04-23 00:51:22 +02:00
|
|
|
struct amount_sat available_funds,
|
2021-05-06 01:03:03 +02:00
|
|
|
struct amount_sat channel_max,
|
2021-06-08 23:42:45 +02:00
|
|
|
struct amount_sat lease_request,
|
2021-05-06 01:03:03 +02:00
|
|
|
struct amount_sat *our_funding);
|
2021-04-23 00:51:22 +02:00
|
|
|
|
|
|
|
/* Get the name of this policy option */
|
|
|
|
const char *funder_opt_name(enum funder_opt opt);
|
|
|
|
|
|
|
|
/* Get a (short, for now) description of the provided policy */
|
|
|
|
const char *funder_policy_desc(const tal_t *ctx,
|
2021-05-27 01:10:32 +02:00
|
|
|
const struct funder_policy *policy);
|
2021-04-23 00:51:22 +02:00
|
|
|
|
|
|
|
/* Convert a cmdline option to a funding_opt */
|
2023-06-06 02:38:53 +02:00
|
|
|
char *funding_option(struct plugin *plugin, const char *arg, enum funder_opt *opt);
|
2021-04-22 23:33:08 +02:00
|
|
|
|
|
|
|
/* Check policy settings, return error if fails */
|
|
|
|
char *funder_check_policy(const struct funder_policy *policy);
|
2021-04-23 00:51:22 +02:00
|
|
|
#endif /* LIGHTNING_PLUGINS_FUNDER_POLICY_H */
|