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