2020-01-03 14:01:31 +01:00
|
|
|
package loopd
|
2019-03-06 21:13:50 +01:00
|
|
|
|
|
|
|
|
import (
|
2020-09-01 09:58:08 +02:00
|
|
|
"context"
|
|
|
|
|
|
2020-01-10 12:13:39 +01:00
|
|
|
"github.com/btcsuite/btcutil"
|
2020-06-17 22:25:57 +02:00
|
|
|
"github.com/lightninglabs/lndclient"
|
2019-03-06 20:32:24 -08:00
|
|
|
"github.com/lightninglabs/loop"
|
2020-09-01 09:58:08 +02:00
|
|
|
"github.com/lightninglabs/loop/liquidity"
|
2021-02-03 08:54:50 +02:00
|
|
|
"github.com/lightninglabs/loop/swap"
|
2020-09-30 12:34:05 +02:00
|
|
|
"github.com/lightningnetwork/lnd/clock"
|
2020-10-12 13:34:55 +02:00
|
|
|
"github.com/lightningnetwork/lnd/ticker"
|
2019-03-06 21:13:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// getClient returns an instance of the swap client.
|
2020-05-15 12:17:57 +02:00
|
|
|
func getClient(config *Config, lnd *lndclient.LndServices) (*loop.Client,
|
2020-01-10 12:13:39 +01:00
|
|
|
func(), error) {
|
2019-03-06 20:32:24 -08:00
|
|
|
|
2020-04-27 14:03:23 +02:00
|
|
|
clientConfig := &loop.ClientConfig{
|
2020-06-15 11:04:37 +02:00
|
|
|
ServerAddress: config.Server.Host,
|
|
|
|
|
ProxyAddress: config.Server.Proxy,
|
|
|
|
|
SwapServerNoTLS: config.Server.NoTLS,
|
|
|
|
|
TLSPathServer: config.Server.TLSPath,
|
2020-05-12 09:31:50 +02:00
|
|
|
Lnd: lnd,
|
|
|
|
|
MaxLsatCost: btcutil.Amount(config.MaxLSATCost),
|
|
|
|
|
MaxLsatFee: btcutil.Amount(config.MaxLSATFee),
|
|
|
|
|
LoopOutMaxParts: config.LoopOutMaxParts,
|
2020-04-27 14:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-12 16:28:11 +02:00
|
|
|
swapClient, cleanUp, err := loop.NewClient(config.DataDir, clientConfig)
|
2019-03-06 21:13:50 +01:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return swapClient, cleanUp, nil
|
|
|
|
|
}
|
2020-09-01 09:58:08 +02:00
|
|
|
|
|
|
|
|
func getLiquidityManager(client *loop.Client) *liquidity.Manager {
|
|
|
|
|
mngrCfg := &liquidity.Config{
|
2021-02-03 08:54:49 +02:00
|
|
|
AutoloopTicker: ticker.NewForce(liquidity.DefaultAutoloopTicker),
|
|
|
|
|
LoopOut: client.LoopOut,
|
2021-02-03 08:54:50 +02:00
|
|
|
Restrictions: func(ctx context.Context,
|
|
|
|
|
swapType swap.Type) (*liquidity.Restrictions, error) {
|
2020-09-01 09:58:08 +02:00
|
|
|
|
2021-02-03 08:54:50 +02:00
|
|
|
if swapType == swap.TypeOut {
|
|
|
|
|
outTerms, err := client.Server.GetLoopOutTerms(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return liquidity.NewRestrictions(
|
|
|
|
|
outTerms.MinSwapAmount, outTerms.MaxSwapAmount,
|
|
|
|
|
), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inTerms, err := client.Server.GetLoopInTerms(ctx)
|
2020-09-01 09:58:08 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return liquidity.NewRestrictions(
|
2021-02-03 08:54:50 +02:00
|
|
|
inTerms.MinSwapAmount, inTerms.MaxSwapAmount,
|
2020-09-01 09:58:08 +02:00
|
|
|
), nil
|
|
|
|
|
},
|
2020-09-30 12:34:08 +02:00
|
|
|
Lnd: client.LndServices,
|
|
|
|
|
Clock: clock.NewDefaultClock(),
|
2020-09-30 12:34:09 +02:00
|
|
|
LoopOutQuote: client.LoopOutQuote,
|
2020-09-30 12:34:08 +02:00
|
|
|
ListLoopOut: client.Store.FetchLoopOutSwaps,
|
|
|
|
|
ListLoopIn: client.Store.FetchLoopInSwaps,
|
|
|
|
|
MinimumConfirmations: minConfTarget,
|
2020-09-01 09:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return liquidity.NewManager(mngrCfg)
|
|
|
|
|
}
|