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"
|
2020-09-30 10:34:05 +00:00
|
|
|
"github.com/lightningnetwork/lnd/clock"
|
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{
|
|
|
|
LoopOutRestrictions: func(ctx context.Context) (
|
|
|
|
*liquidity.Restrictions, error) {
|
|
|
|
|
|
|
|
outTerms, err := client.Server.GetLoopOutTerms(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return liquidity.NewRestrictions(
|
|
|
|
outTerms.MinSwapAmount, outTerms.MaxSwapAmount,
|
|
|
|
), 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,
|
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)
|
|
|
|
}
|