autoswap

package
v2.3.5-0...-2fac4e2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2025 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonMaxFeePercent     = "fee exceeds maximum percentage"
	ReasonAmountBelowMin    = "amount below minimal"
	ReasonBudgetExceeded    = "budget exceeded"
	ReasonPendingSwap       = "pending swap"
	ReasonFailedSwap        = "failed swap"
	ReasonInsufficientFunds = "insufficient funds"
)
View Source
const DefaultReserve = boltz.Percentage(10)
View Source
const MinReserve = uint64(10000)

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoSwap

type AutoSwap struct {
	// contains filtered or unexported fields
}

func (*AutoSwap) Error

func (autoSwap *AutoSwap) Error() string

func (*AutoSwap) GetChainSwapper

func (autoSwap *AutoSwap) GetChainSwapper(tenantId database.Id) *ChainSwapper

func (*AutoSwap) GetConfig

func (autoSwap *AutoSwap) GetConfig(tenantId *database.Id) *Config

func (*AutoSwap) GetCurrentBudget

func (c *AutoSwap) GetCurrentBudget(
	createIfMissing bool,
	swapperType SwapperType,
	cfg budgetConfig,
	tenantId database.Id,
) (*Budget, error)

func (*AutoSwap) GetLnSwapper

func (autoSwap *AutoSwap) GetLnSwapper() *LightningSwapper

func (*AutoSwap) Init

func (autoSwap *AutoSwap) Init(db *database.Database, onchain *onchain.Onchain, configPath string, rpc RpcProvider)

func (*AutoSwap) LoadConfig

func (autoSwap *AutoSwap) LoadConfig() error

func (*AutoSwap) UpdateChainConfig

func (autoSwap *AutoSwap) UpdateChainConfig(request *autoswaprpc.UpdateChainConfigRequest, tenant database.Tenant) error

func (*AutoSwap) UpdateLightningConfig

func (autoSwap *AutoSwap) UpdateLightningConfig(request *autoswaprpc.UpdateLightningConfigRequest) error

func (*AutoSwap) WalletUsed

func (autoSwap *AutoSwap) WalletUsed(id database.Id) bool

type Balance

type Balance struct {
	Absolute uint64
	Relative boltz.Percentage
}

func (Balance) Get

func (b Balance) Get(capacity uint64) uint64

func (Balance) IsAbsolute

func (b Balance) IsAbsolute() bool

func (Balance) IsZero

func (b Balance) IsZero() bool

func (Balance) String

func (b Balance) String() string

type Budget

type Budget struct {
	database.BudgetInterval
	Amount uint64
	Total  uint64
	Stats  *boltzrpc.SwapStats
}

type ChainConfig

type ChainConfig struct {
	*SerializedChainConfig
	// contains filtered or unexported fields
}

func NewChainConfig

func NewChainConfig(serialized *SerializedChainConfig, shared shared) *ChainConfig

func (*ChainConfig) CheckAndExecute

func (cfg *ChainConfig) CheckAndExecute(accepted *autoswaprpc.ChainSwap, force bool) error

func (*ChainConfig) Description

func (cfg *ChainConfig) Description() string

func (*ChainConfig) GetCurrentBudget

func (cfg *ChainConfig) GetCurrentBudget(createIfMissing bool) (*Budget, error)

func (*ChainConfig) GetRecommendation

func (cfg *ChainConfig) GetRecommendation() (*autoswaprpc.ChainRecommendation, error)

func (*ChainConfig) GetTenantId

func (cfg *ChainConfig) GetTenantId() database.Id

func (*ChainConfig) Init

func (cfg *ChainConfig) Init() (err error)

type ChainRecommendation

type ChainRecommendation struct {
	Swap        *ChainSwap
	FromBalance *onchain.Balance
}

type ChainSwap

type ChainSwap = checks

type ChainSwapper

type ChainSwapper = swapper[*ChainConfig]

type Config

type Config = autoswaprpc.Config

type DismissedChannels

type DismissedChannels map[lightning.ChanId][]string

type LightningConfig

type LightningConfig struct {
	*SerializedLnConfig
	// contains filtered or unexported fields
}

func NewLightningConfig

func NewLightningConfig(serialized *SerializedLnConfig, shared shared) *LightningConfig

func (*LightningConfig) AllowNormalSwaps

func (cfg *LightningConfig) AllowNormalSwaps() bool

func (*LightningConfig) AllowReverseSwaps

func (cfg *LightningConfig) AllowReverseSwaps() bool

func (*LightningConfig) Allowed

func (cfg *LightningConfig) Allowed(swapType boltz.SwapType) bool

func (*LightningConfig) CheckAndExecute

func (cfg *LightningConfig) CheckAndExecute(accepted []*autoswaprpc.LightningRecommendation, force bool) error

func (*LightningConfig) Description

func (cfg *LightningConfig) Description() string

func (*LightningConfig) GetCurrentBudget

func (cfg *LightningConfig) GetCurrentBudget(createIfMissing bool) (*Budget, error)

func (*LightningConfig) GetPair

func (cfg *LightningConfig) GetPair(swapType boltzrpc.SwapType) *boltzrpc.Pair

func (*LightningConfig) GetSwapRecommendations

func (cfg *LightningConfig) GetSwapRecommendations(includeAll bool) ([]*autoswaprpc.LightningRecommendation, error)

func (*LightningConfig) Init

func (cfg *LightningConfig) Init() error

func (*LightningConfig) InitWallet

func (cfg *LightningConfig) InitWallet() (err error)

type LightningRecommendation

type LightningRecommendation struct {
	Swap       *LightningSwap
	Channel    *lightning.LightningChannel
	Thresholds *autoswaprpc.LightningThresholds
}

type LightningSwap

type LightningSwap struct {
	Type boltz.SwapType
	// contains filtered or unexported fields
}

func (*LightningSwap) Dismiss

func (recommendation *LightningSwap) Dismiss(reason string)

func (*LightningSwap) Dismissed

func (recommendation *LightningSwap) Dismissed() bool

func (*LightningSwap) GetAmount

func (lightningSwap *LightningSwap) GetAmount() uint64

type LightningSwapper

type LightningSwapper = swapper[*LightningConfig]

type MockRpcProvider

type MockRpcProvider struct {
	mock.Mock
}

MockRpcProvider is an autogenerated mock type for the RpcProvider type

func NewMockRpcProvider

func NewMockRpcProvider(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockRpcProvider

NewMockRpcProvider creates a new instance of MockRpcProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockRpcProvider) CreateAutoChainSwap

func (_m *MockRpcProvider) CreateAutoChainSwap(tenant *database.Tenant, request *boltzrpc.CreateChainSwapRequest) error

CreateAutoChainSwap provides a mock function with given fields: tenant, request

func (*MockRpcProvider) CreateAutoReverseSwap

func (_m *MockRpcProvider) CreateAutoReverseSwap(tenant *database.Tenant, request *boltzrpc.CreateReverseSwapRequest) error

CreateAutoReverseSwap provides a mock function with given fields: tenant, request

func (*MockRpcProvider) CreateAutoSwap

func (_m *MockRpcProvider) CreateAutoSwap(tenant *database.Tenant, request *boltzrpc.CreateSwapRequest) error

CreateAutoSwap provides a mock function with given fields: tenant, request

func (*MockRpcProvider) EXPECT

func (*MockRpcProvider) GetAutoSwapPairInfo

func (_m *MockRpcProvider) GetAutoSwapPairInfo(swapType boltzrpc.SwapType, pair *boltzrpc.Pair) (*boltzrpc.PairInfo, error)

GetAutoSwapPairInfo provides a mock function with given fields: swapType, pair

func (*MockRpcProvider) GetBlockUpdates

func (_m *MockRpcProvider) GetBlockUpdates(currency boltz.Currency) (<-chan *onchain.BlockEpoch, func())

GetBlockUpdates provides a mock function with given fields: currency

func (*MockRpcProvider) GetLightningChannels

func (_m *MockRpcProvider) GetLightningChannels() ([]*lightning.LightningChannel, error)

GetLightningChannels provides a mock function with given fields:

func (*MockRpcProvider) WalletSendFee

func (_m *MockRpcProvider) WalletSendFee(request *boltzrpc.WalletSendRequest) (*boltzrpc.WalletSendFee, error)

WalletSendFee provides a mock function with given fields: request

type MockRpcProvider_CreateAutoChainSwap_Call

type MockRpcProvider_CreateAutoChainSwap_Call struct {
	*mock.Call
}

MockRpcProvider_CreateAutoChainSwap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateAutoChainSwap'

func (*MockRpcProvider_CreateAutoChainSwap_Call) Return

func (*MockRpcProvider_CreateAutoChainSwap_Call) Run

func (*MockRpcProvider_CreateAutoChainSwap_Call) RunAndReturn

type MockRpcProvider_CreateAutoReverseSwap_Call

type MockRpcProvider_CreateAutoReverseSwap_Call struct {
	*mock.Call
}

MockRpcProvider_CreateAutoReverseSwap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateAutoReverseSwap'

func (*MockRpcProvider_CreateAutoReverseSwap_Call) Return

func (*MockRpcProvider_CreateAutoReverseSwap_Call) Run

func (*MockRpcProvider_CreateAutoReverseSwap_Call) RunAndReturn

type MockRpcProvider_CreateAutoSwap_Call

type MockRpcProvider_CreateAutoSwap_Call struct {
	*mock.Call
}

MockRpcProvider_CreateAutoSwap_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateAutoSwap'

func (*MockRpcProvider_CreateAutoSwap_Call) Return

func (*MockRpcProvider_CreateAutoSwap_Call) Run

func (*MockRpcProvider_CreateAutoSwap_Call) RunAndReturn

type MockRpcProvider_Expecter

type MockRpcProvider_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockRpcProvider_Expecter) CreateAutoChainSwap

func (_e *MockRpcProvider_Expecter) CreateAutoChainSwap(tenant interface{}, request interface{}) *MockRpcProvider_CreateAutoChainSwap_Call

CreateAutoChainSwap is a helper method to define mock.On call

  • tenant *database.Tenant
  • request *boltzrpc.CreateChainSwapRequest

func (*MockRpcProvider_Expecter) CreateAutoReverseSwap

func (_e *MockRpcProvider_Expecter) CreateAutoReverseSwap(tenant interface{}, request interface{}) *MockRpcProvider_CreateAutoReverseSwap_Call

CreateAutoReverseSwap is a helper method to define mock.On call

  • tenant *database.Tenant
  • request *boltzrpc.CreateReverseSwapRequest

func (*MockRpcProvider_Expecter) CreateAutoSwap

func (_e *MockRpcProvider_Expecter) CreateAutoSwap(tenant interface{}, request interface{}) *MockRpcProvider_CreateAutoSwap_Call

CreateAutoSwap is a helper method to define mock.On call

  • tenant *database.Tenant
  • request *boltzrpc.CreateSwapRequest

func (*MockRpcProvider_Expecter) GetAutoSwapPairInfo

func (_e *MockRpcProvider_Expecter) GetAutoSwapPairInfo(swapType interface{}, pair interface{}) *MockRpcProvider_GetAutoSwapPairInfo_Call

GetAutoSwapPairInfo is a helper method to define mock.On call

  • swapType boltzrpc.SwapType
  • pair *boltzrpc.Pair

func (*MockRpcProvider_Expecter) GetBlockUpdates

func (_e *MockRpcProvider_Expecter) GetBlockUpdates(currency interface{}) *MockRpcProvider_GetBlockUpdates_Call

GetBlockUpdates is a helper method to define mock.On call

  • currency boltz.Currency

func (*MockRpcProvider_Expecter) GetLightningChannels

GetLightningChannels is a helper method to define mock.On call

func (*MockRpcProvider_Expecter) WalletSendFee

func (_e *MockRpcProvider_Expecter) WalletSendFee(request interface{}) *MockRpcProvider_WalletSendFee_Call

WalletSendFee is a helper method to define mock.On call

  • request *boltzrpc.WalletSendRequest

type MockRpcProvider_GetAutoSwapPairInfo_Call

type MockRpcProvider_GetAutoSwapPairInfo_Call struct {
	*mock.Call
}

MockRpcProvider_GetAutoSwapPairInfo_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAutoSwapPairInfo'

func (*MockRpcProvider_GetAutoSwapPairInfo_Call) Return

func (*MockRpcProvider_GetAutoSwapPairInfo_Call) Run

func (*MockRpcProvider_GetAutoSwapPairInfo_Call) RunAndReturn

type MockRpcProvider_GetBlockUpdates_Call

type MockRpcProvider_GetBlockUpdates_Call struct {
	*mock.Call
}

MockRpcProvider_GetBlockUpdates_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBlockUpdates'

func (*MockRpcProvider_GetBlockUpdates_Call) Return

func (*MockRpcProvider_GetBlockUpdates_Call) Run

func (*MockRpcProvider_GetBlockUpdates_Call) RunAndReturn

type MockRpcProvider_GetLightningChannels_Call

type MockRpcProvider_GetLightningChannels_Call struct {
	*mock.Call
}

MockRpcProvider_GetLightningChannels_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLightningChannels'

func (*MockRpcProvider_GetLightningChannels_Call) Return

func (*MockRpcProvider_GetLightningChannels_Call) Run

func (*MockRpcProvider_GetLightningChannels_Call) RunAndReturn

type MockRpcProvider_WalletSendFee_Call

type MockRpcProvider_WalletSendFee_Call struct {
	*mock.Call
}

MockRpcProvider_WalletSendFee_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WalletSendFee'

func (*MockRpcProvider_WalletSendFee_Call) Return

func (*MockRpcProvider_WalletSendFee_Call) Run

func (*MockRpcProvider_WalletSendFee_Call) RunAndReturn

type RpcProvider

type RpcProvider interface {
	GetAutoSwapPairInfo(swapType boltzrpc.SwapType, pair *boltzrpc.Pair) (*boltzrpc.PairInfo, error)
	GetLightningChannels() ([]*lightning.LightningChannel, error)
	GetBlockUpdates(currency boltz.Currency) (<-chan *onchain.BlockEpoch, func())
	WalletSendFee(request *boltzrpc.WalletSendRequest) (*boltzrpc.WalletSendFee, error)

	CreateAutoSwap(tenant *database.Tenant, request *boltzrpc.CreateSwapRequest) error
	CreateAutoReverseSwap(tenant *database.Tenant, request *boltzrpc.CreateReverseSwapRequest) error
	CreateAutoChainSwap(tenant *database.Tenant, request *boltzrpc.CreateChainSwapRequest) error
}

type SerializedChainConfig

type SerializedChainConfig = autoswaprpc.ChainConfig

type SerializedLnConfig

type SerializedLnConfig = autoswaprpc.LightningConfig

func DefaultLightningConfig

func DefaultLightningConfig() *SerializedLnConfig

type Strategy

type Strategy = func(channels []*lightning.LightningChannel) []*LightningRecommendation

type SwapperType

type SwapperType string
const (
	Lightning SwapperType = "lightning"
	Chain     SwapperType = "chain"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL