application

package
v0.8.8-rc.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InitWallet = iota
	UnlockWallet
	ChangePassphrase
)

Passphrase msg type

View Source
const (
	TradeBuy = iota
	TradeSell
)

trade type

View Source
const (
	Processing = iota
	Done
)

restore status

View Source
const (
	TradeSettled = iota
	AccountLowBalance
	AccountWithdraw
)

Topics to be published

Variables

View Source
var (
	ErrMarketInvalidBaseAsset  = domain.ErrMarketInvalidBaseAsset
	ErrMarketInvalidQuoteAsset = domain.ErrMarketInvalidQuoteAsset
	// ErrFeeAccountNotFunded ...
	ErrFeeAccountNotFunded = errors.New("fee account not funded")
	// ErrUnknownStrategy ...
	ErrUnknownStrategy = errors.New("strategy not supported")
	// ErrMarketAlreadyExist ...
	ErrMarketAlreadyExist = errors.New("market already exists")
	// ErrMarketNotExist ...
	ErrMarketNotExist = errors.New("market does not exist")
	// ErrMarketNotFunded ...
	ErrMarketNotFunded = errors.New("market account not funded")
	// ErrInvalidOutpoint ...
	ErrInvalidOutpoint = errors.New("outpoint refers to inexistent tx output")
	// ErrInvalidOutpoints ...
	ErrInvalidOutpoints = errors.New("all outpoints must be funded for the same account")
	// ErrServiceUnavailable is the error returned by the trade service in case of
	// internal errors
	ErrServiceUnavailable = errors.New("service is unavailable, try again later")
	// ErrPubSubServiceNotInitialized is returned when attempting to use
	// AddWebhook or RemoveWebhook RPCs without having initialized the pubsub
	// service at the start up.
	ErrPubSubServiceNotInitialized = errors.New("pubsub service is not initialized")
	// ErrInvalidActionType is returned if the attempting to register a webhook
	// for an invalid action type.
	ErrInvalidActionType = errors.New("action type is unknown")
	// ErrMarketBalanceTooLow is returned when the balance of the base or quote
	// asset of a market is below its fixed fee.
	ErrMarketBalanceTooLow = errors.New("market base or quote balance too low")
	// ErrWithdrawBaseAmountTooBig is returned when attempting to withdraw more
	// than the total amount of base asset of a market.
	ErrWithdrawBaseAmountTooBig = errors.New(
		"base amount to withdraw exceeds the market base balance",
	)
	// ErrWithdrawQuoteAmountTooBig is returned when attempting to withdraw more
	// than the total amount of quote asset of a market.
	ErrWithdrawQuoteAmountTooBig = errors.New(
		"quote amount to withdraw is too big",
	)
	// ErrWithdrawAmountTooBig is returned when attempting to withdraw more
	// than the total amount of LBTC asset of the fee account.
	ErrWithdrawAmountTooBig = errors.New(
		"amount to withdraw is too big",
	)
	// ErrInvalidAccountIndex returned if provided account index is invalid
	ErrInvalidAccountIndex = errors.New("invalid account index")
	// ErrMissingMarketBalanceToWithdraw is returned in case none of the base or
	// quote amounts to withdraw for a market are defined.
	ErrMissingMarketBalanceToWithdraw = errors.New(
		"either base or quote amount to withdraw must be specified",
	)
	// ErrMissingWithdrawAddress is returned if the receiving address to is not
	// set for a withdrawal.
	ErrMissingWithdrawAddress = errors.New("address must not be null")
	// ErrMarketNonZeroBalance is returned when trying to drop a market that still
	// owns some base or quote asset funds.
	ErrMarketNonZeroBalance = errors.New("withdraw funds from market before deleting")
	// ErrInvalidTime used when validating if time is valid time.Time
	ErrInvalidTime = errors.New("must be a valid time.Time")
	// ErrInvalidTimeFormat used to validate time format
	ErrInvalidTimeFormat = errors.New("fromTime must be valid RFC3339 format")
	// ErrInvalidTimeFrame
	ErrInvalidTimeFrame = errors.New("timeFrame must be smaller than timePeriod")
)
View Source
var (
	DefaultFeeFragmenterFragments = uint32(50)
	DefaultFeeFragmenterAmount    = uint64(5000)
	FragmentationMap              = map[int]int{
		1: 30,
		2: 15,
		3: 10,
		5: 2,
	}
	PollInterval              = 1 * time.Second
	MinFeeFragmenterAmount    = 5000
	MinMarketFragmenterAmount = 100000
)
View Source
var (
	BlinderManager     Blinder
	TradeManager       TradeHandler
	TransactionManager TransactionHandler
)
View Source
var (
	// ErrWalletNotFunded ...
	ErrWalletNotFunded = fmt.Errorf("wallet not funded")
)
View Source
var (
	// ErrWalletNotInitialized is returned when attempting to unlock or change
	// the password of a not initialized wallet.
	ErrWalletNotInitialized = fmt.Errorf("wallet not initialized")
)

Functions

This section is empty.

Types

type AccountInfo added in v0.6.0

type AccountInfo struct {
	Index               uint32
	DerivationPath      string
	Xpub                string
	LastExternalDerived uint32
	LastInternalDerived uint32
}

AccountInfo contains info about a wallet account.

type AddressAndBlindingKey added in v0.1.2

type AddressAndBlindingKey struct {
	Address     string
	BlindingKey string
}

type Balance

type Balance struct {
	BaseAmount  uint64
	QuoteAmount uint64
}

type BalanceInfo added in v0.3.0

type BalanceInfo struct {
	TotalBalance       uint64
	ConfirmedBalance   uint64
	UnconfirmedBalance uint64
}

type BalanceWithFee

type BalanceWithFee struct {
	Balance Balance
	Fee     Fee
}

type Blinder added in v0.3.1

type Blinder interface {
	UnblindOutput(txout *transaction.TxOutput, key []byte) (UnblindedResult, bool)
}

type BlindingData added in v0.3.2

type BlindingData wallet.BlindingData

type BlockchainListener

type BlockchainListener interface {
	StartObservation()
	StopObservation()

	StartObserveAddress(accountIndex int, addr string, blindKey []byte)
	StopObserveAddress(addr string)

	StartObserveTx(txid string, market Market)
	StopObserveTx(txid string)

	StartObserveOutpoints(outpoints []explorer.Utxo, tradeID string)
	StopObserveOutpoints(outpoints interface{})

	PubSubService() ports.SecurePubSub
}

BlockchainListener defines the needed method sto start and stop a blockchain listener

func NewBlockchainListener

func NewBlockchainListener(
	crawlerSvc crawler.Service,
	repoManager ports.RepoManager,
	pubsubSvc ports.SecurePubSub,
	net *network.Network,
) BlockchainListener

NewBlockchainListener returns a BlockchainListener with all the needed services

type BuildInfo added in v0.8.6

type BuildInfo struct {
	Version string
	Commit  string
	Date    string
}

type CustomPeriod added in v0.8.3

type CustomPeriod struct {
	StartDate string
	EndDate   string
}

type Deposits added in v0.6.0

type Deposits []domain.Deposit

type Fee

type Fee struct {
	BasisPoint    int64
	FixedBaseFee  int64
	FixedQuoteFee int64
}

type FeeInfo added in v0.2.0

type FeeInfo struct {
	TradeID             string
	BasisPoint          int64
	Asset               string
	PercentageFeeAmount uint64
	FixedFeeAmount      uint64
	MarketPrice         decimal.Decimal
}

type FillProposalOpts added in v0.3.2

type FillProposalOpts struct {
	Mnemonic         []string
	SwapRequest      domain.SwapRequest
	MarketUtxos      []explorer.Utxo
	FeeUtxos         []explorer.Utxo
	MarketInfo       domain.AddressesInfo
	FeeInfo          domain.AddressesInfo
	OutputInfo       domain.AddressInfo
	ChangeInfo       domain.AddressInfo
	FeeChangeInfo    domain.AddressInfo
	Network          *network.Network
	MilliSatsPerByte int
}

type FillProposalResult added in v0.3.2

type FillProposalResult struct {
	PsetBase64         string
	SelectedUnspents   []explorer.Utxo
	InputBlindingKeys  map[string][]byte
	OutputBlindingKeys map[string][]byte
}

type FragmenterSplitFundsReply added in v0.8.0

type FragmenterSplitFundsReply struct {
	Msg string
	Err error
}

type HDWalletInfo added in v0.6.0

type HDWalletInfo struct {
	RootPath          string
	MasterBlindingKey string
	Accounts          []AccountInfo
	Network           string
	BuildInfo         BuildInfo
	BaseAsset         string
	QuoteAsset        string
}

HDWalletInfo contains info about the internal wallet of the daemon and its sub-accounts.

type HDWalletStatus added in v0.6.0

type HDWalletStatus struct {
	Initialized bool
	Unlocked    bool
	Synced      bool
}

type InitWalletReply added in v0.3.0

type InitWalletReply struct {
	AccountIndex int32
	Status       int
	Data         string
	Err          error
}

type Market

type Market struct {
	BaseAsset  string
	QuoteAsset string
}

func (Market) Validate added in v0.6.0

func (m Market) Validate() error

type MarketCollectedFees added in v0.8.3

type MarketCollectedFees struct {
	BaseAmount  uint64
	QuoteAmount uint64
	StartTime   time.Time
	EndTime     time.Time
}

type MarketInfo

type MarketInfo struct {
	AccountIndex uint64
	Market       Market
	Fee          Fee
	Tradable     bool
	StrategyType int
	Price        domain.Prices
	Balance      Balance
}

MarketInfo is the data struct returned by ListMarket RPC.

type MarketReport added in v0.8.3

type MarketReport struct {
	CollectedFees MarketCollectedFees
	Volume        MarketVolume
	GroupedVolume []MarketVolume
}

type MarketStrategy

type MarketStrategy struct {
	Market
	Strategy domain.StrategyType
}

type MarketVolume added in v0.8.3

type MarketVolume struct {
	BaseVolume  uint64
	QuoteVolume uint64
	StartTime   time.Time
	EndTime     time.Time
}

type MarketWithFee

type MarketWithFee struct {
	Market
	Fee
}

type MarketWithPrice

type MarketWithPrice struct {
	Market
	Price
}

type OperatorService

type OperatorService interface {
	GetInfo(ctx context.Context) (*HDWalletInfo, error)
	// Fee account
	GetFeeAddress(
		ctx context.Context, numOfAddresses int,
	) ([]AddressAndBlindingKey, error)
	ListFeeExternalAddresses(
		ctx context.Context,
	) ([]AddressAndBlindingKey, error)
	GetFeeBalance(ctx context.Context) (int64, int64, error)
	ClaimFeeDeposits(ctx context.Context, outpoints []TxOutpoint) error
	WithdrawFeeFunds(
		ctx context.Context, req WithdrawFeeReq,
	) ([]byte, []byte, error)
	// Market account
	NewMarket(ctx context.Context, market Market) error
	GetMarketInfo(ctx context.Context, market Market) (*MarketInfo, error)
	GetMarketAddress(
		ctx context.Context, market Market, numOfAddresses int,
	) ([]AddressAndBlindingKey, error)
	ListMarketExternalAddresses(
		ctx context.Context, req Market,
	) ([]AddressAndBlindingKey, error)
	GetMarketBalance(ctx context.Context, market Market) (*Balance, *Balance, error)
	ClaimMarketDeposits(
		ctx context.Context, market Market, outpoints []TxOutpoint,
	) error
	OpenMarket(ctx context.Context, market Market) error
	CloseMarket(ctx context.Context, market Market) error
	DropMarket(ctx context.Context, market Market) error
	GetMarketCollectedFee(
		ctx context.Context, market Market, page *Page,
	) (*ReportMarketFee, error)
	WithdrawMarketFunds(
		ctx context.Context, req WithdrawMarketReq,
	) ([]byte, []byte, error)
	UpdateMarketPercentageFee(
		ctx context.Context, req MarketWithFee,
	) (*MarketWithFee, error)
	UpdateMarketFixedFee(
		ctx context.Context, req MarketWithFee,
	) (*MarketWithFee, error)
	UpdateMarketPrice(ctx context.Context, req MarketWithPrice) error
	UpdateMarketStrategy(ctx context.Context, req MarketStrategy) error
	// Fee Fragmenter account
	GetFeeFragmenterAddress(
		ctx context.Context, numOfAddresses int,
	) ([]AddressAndBlindingKey, error)
	ListFeeFragmenterExternalAddresses(
		ctx context.Context,
	) ([]AddressAndBlindingKey, error)
	GetFeeFragmenterBalance(ctx context.Context) (map[string]BalanceInfo, error)
	FeeFragmenterSplitFunds(
		ctx context.Context, maxFragments uint32, millisatsPerByte uint64,
		chRes chan FragmenterSplitFundsReply,
	)
	WithdrawFeeFragmenterFunds(
		ctx context.Context, address string, millisatsPerByte uint64,
	) (string, error)
	// Market fragmenter account
	GetMarketFragmenterAddress(
		ctx context.Context, numOfAddresses int,
	) ([]AddressAndBlindingKey, error)
	ListMarketFragmenterExternalAddresses(
		ctx context.Context,
	) ([]AddressAndBlindingKey, error)
	GetMarketFragmenterBalance(
		ctx context.Context,
	) (map[string]BalanceInfo, error)
	MarketFragmenterSplitFunds(
		ctx context.Context, market Market, millisatsPerByte uint64,
		chRes chan FragmenterSplitFundsReply,
	)
	WithdrawMarketFragmenterFunds(
		ctx context.Context, address string, millisatsPerByte uint64,
	) (string, error)
	// List methods
	ListMarkets(ctx context.Context) ([]MarketInfo, error)
	ListTrades(ctx context.Context, page *Page) ([]TradeInfo, error)
	ListTradesForMarket(
		ctx context.Context, market Market, page *Page,
	) ([]TradeInfo, error)
	ListUtxos(
		ctx context.Context, accountIndex int, page *Page,
	) (*UtxoInfoList, error)
	ListDeposits(
		ctx context.Context, accountIndex int, page *Page,
	) (Deposits, error)
	ListWithdrawals(
		ctx context.Context, accountIndex int, page *Page,
	) (Withdrawals, error)
	// Reload utxo set
	ReloadUtxos(ctx context.Context) error
	// Webhook
	AddWebhook(ctx context.Context, hook Webhook) (string, error)
	RemoveWebhook(ctx context.Context, id string) error
	ListWebhooks(ctx context.Context, actionType int) ([]WebhookInfo, error)
	GetMarketReport(
		ctx context.Context,
		market Market,
		timeRange TimeRange,
		groupByHours int,
	) (*MarketReport, error)
}

OperatorService defines the methods of the application layer for the operator service.

func NewOperatorService

func NewOperatorService(
	repoManager ports.RepoManager,
	explorerSvc explorer.Service,
	bcListener BlockchainListener,
	marketBaseAsset, marketQuoteAsset string,
	marketFee int64,
	net *network.Network,
	feeAccountBalanceThreshold uint64,
	buildInfo BuildInfo,
) OperatorService

NewOperatorService is a constructor function for OperatorService.

type Page added in v0.6.0

type Page domain.Page

func (*Page) ToDomain added in v0.6.0

func (p *Page) ToDomain() domain.Page

type PassphraseMsg added in v0.4.0

type PassphraseMsg struct {
	Method     int
	CurrentPwd string
	NewPwd     string
}

type PredefinedPeriod added in v0.8.3

type PredefinedPeriod int
const (
	// NIL is added in proto file to recognised when predefined period is passed
	NIL PredefinedPeriod = iota
	LastHour
	LastDay
	LastWeek
	LastMonth
	LastThreeMonths
	YearToDate
	All
	LastYear

	StartYear = 2021
)

type Price

type Price struct {
	BasePrice  decimal.Decimal
	QuotePrice decimal.Decimal
}

func (Price) Validate added in v0.6.0

func (p Price) Validate() error

type PriceWithFee

type PriceWithFee struct {
	Price   Price
	Fee     Fee
	Amount  uint64
	Asset   string
	Balance Balance
}

type ReportMarketFee

type ReportMarketFee struct {
	CollectedFees              []FeeInfo
	TotalCollectedFeesPerAsset map[string]int64
}

type SendToManyRequest

type SendToManyRequest struct {
	Outputs         []TxOut
	MillisatPerByte int64
	Push            bool
}

type SwapFailInfo added in v0.3.7

type SwapFailInfo struct {
	Code    int
	Message string
}

type SwapInfo

type SwapInfo struct {
	AmountP uint64
	AssetP  string
	AmountR uint64
	AssetR  string
}

SwapInfo contains info about a swap

type TimeRange added in v0.8.3

type TimeRange struct {
	PredefinedPeriod *PredefinedPeriod
	CustomPeriod     *CustomPeriod
}

func (*TimeRange) Validate added in v0.8.3

func (t *TimeRange) Validate() error

type TradeHandler added in v0.3.2

type TradeHandler interface {
	FillProposal(FillProposalOpts) (*FillProposalResult, error)
}

type TradeInfo added in v0.3.7

type TradeInfo struct {
	ID               string
	Status           domain.Status
	SwapInfo         SwapInfo
	SwapFailInfo     SwapFailInfo
	MarketWithFee    MarketWithFee
	Price            Price
	TxURL            string
	RequestTimeUnix  uint64
	AcceptTimeUnix   uint64
	CompleteTimeUnix uint64
	SettleTimeUnix   uint64
	ExpiryTimeUnix   uint64
}

TradeInfo contains info about a trade.

type TradeService

type TradeService interface {
	GetTradableMarkets(ctx context.Context) ([]MarketWithFee, error)
	GetMarketPrice(
		ctx context.Context,
		market Market,
		tradeType int,
		amount uint64,
		asset string,
	) (*PriceWithFee, error)
	TradePropose(
		ctx context.Context,
		market Market,
		tradeType int,
		swapRequest domain.SwapRequest,
	) (domain.SwapAccept, domain.SwapFail, uint64, error)
	TradeComplete(
		ctx context.Context,
		swapComplete domain.SwapComplete,
		swapFail domain.SwapFail,
	) (string, domain.SwapFail, error)
	GetMarketBalance(
		ctx context.Context,
		market Market,
	) (*BalanceWithFee, error)
}

func NewTradeService

func NewTradeService(
	repoManager ports.RepoManager,
	explorerSvc explorer.Service,
	bcListener BlockchainListener,
	expiryDuration time.Duration,
	satsPerByte float64,
	priceSlippage decimal.Decimal,
	net *network.Network,
	feeAccountBalanceThreshold uint64,
) TradeService

type TransactionHandler added in v0.3.4

type TransactionHandler interface {
	ExtractUnspents(
		txhex string,
		infoByScript map[string]domain.AddressInfo,
		network *network.Network,
	) ([]domain.Unspent, []domain.UnspentKey, error)
	ExtractBlindingData(
		psetBase64 string,
		inBlindingKeys, outBlidningKeys map[string][]byte,
	) (map[int]BlindingData, map[int]BlindingData, error)
}

type TxOut

type TxOut struct {
	Asset   string
	Value   int64
	Address string
}

func NewTxOut added in v0.7.0

func NewTxOut(address, asset string, value int64) TxOut

type TxOutpoint added in v0.3.0

type TxOutpoint struct {
	Hash  string
	Index int
}

type UnblindedResult added in v0.3.1

type UnblindedResult *transactionutil.UnblindedResult

type Unspents added in v0.3.2

type Unspents []domain.Unspent

func (Unspents) ToUtxos added in v0.3.2

func (u Unspents) ToUtxos() []explorer.Utxo

type UtxoInfo added in v0.3.0

type UtxoInfo struct {
	Outpoint *TxOutpoint
	Value    uint64
	Asset    string
}

type UtxoInfoList added in v0.3.0

type UtxoInfoList struct {
	Unspents []UtxoInfo
	Spents   []UtxoInfo
	Locks    []UtxoInfo
}

type WalletService

type WalletService interface {
	GenerateAddressAndBlindingKey(
		ctx context.Context,
	) (address string, blindingKey string, err error)
	GetWalletBalance(
		ctx context.Context,
	) (map[string]BalanceInfo, error)
	SendToMany(
		ctx context.Context,
		req SendToManyRequest,
	) ([]byte, []byte, error)
}

func NewWalletService

func NewWalletService(
	repoManager ports.RepoManager,
	explorerService explorer.Service,
	blockchainListener BlockchainListener,
	net *network.Network,
	marketFee int64,
) WalletService

type WalletUnlockerService added in v0.5.0

type WalletUnlockerService interface {
	GenSeed(ctx context.Context) ([]string, error)
	InitWallet(
		ctx context.Context,
		mnemonic []string,
		passphrase string,
		restore bool,
		chRes chan InitWalletReply,
	)
	UnlockWallet(
		ctx context.Context,
		passphrase string,
	) error
	ChangePassword(
		ctx context.Context,
		currentPassphrase string,
		newPassphrase string,
	) error
	IsReady(ctx context.Context) HDWalletStatus
	PassphraseChan() chan PassphraseMsg
	ReadyChan() chan bool
}

func NewWalletUnlockerService added in v0.5.0

func NewWalletUnlockerService(
	repoManager ports.RepoManager,
	explorerService explorer.Service,
	blockchainListener BlockchainListener,
	net *network.Network,
	marketFee int64,
	marketBaseAsset string,
	marketQuoteAsset string,
	rescanRangeStart, rescanRangeEnd int,
) WalletUnlockerService

type Webhook added in v0.3.11

type Webhook struct {
	ActionType int
	Endpoint   string
	Secret     string
}

type WebhookInfo added in v0.3.11

type WebhookInfo struct {
	Id         string
	ActionType int
	Endpoint   string
	IsSecured  bool
}

type WithdrawFeeReq added in v0.6.0

type WithdrawFeeReq struct {
	Amount          uint64
	MillisatPerByte uint64
	Address         string
	Asset           string
	Push            bool
}

func (WithdrawFeeReq) Validate added in v0.6.0

func (r WithdrawFeeReq) Validate() error

type WithdrawMarketReq

type WithdrawMarketReq struct {
	Market
	BalanceToWithdraw Balance
	MillisatPerByte   int64
	Address           string
	Push              bool
}

func (WithdrawMarketReq) Validate added in v0.6.0

func (r WithdrawMarketReq) Validate() error

type Withdrawals added in v0.6.0

type Withdrawals []domain.Withdrawal

Jump to

Keyboard shortcuts

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