dex

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: BlueOak-1.0.0 Imports: 36 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// PreAPIVersion covers all API iterations before versioning started.
	PreAPIVersion  = iota
	BondAPIVersion // when we drop the legacy reg fee proto
	V1APIVersion

	// APIVersion is the current API version.
	APIVersion = V1APIVersion
)

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

func ValidateConfigFile added in v1.0.0

func ValidateConfigFile(cfgPath string, net dex.Network, log dex.Logger) error

ValidateConfigFile validates the market+assets configuration file. ValidateConfigFile prints information to stdout. An error is returned for any configuration errors.

Types

type Asset added in v1.0.0

type Asset struct {
	Symbol      string `json:"bip44symbol"`
	Network     string `json:"network"`
	LotSizeOLD  uint64 `json:"lotSize,omitempty"`
	RateStepOLD uint64 `json:"rateStep,omitempty"`
	MaxFeeRate  uint64 `json:"maxFeeRate"`
	SwapConf    uint32 `json:"swapConf"`
	ConfigPath  string `json:"configPath"`
	RegFee      uint64 `json:"regFee,omitempty"`
	RegConfs    uint32 `json:"regConfs,omitempty"`
	RegXPub     string `json:"regXPub,omitempty"`
	BondAmt     uint64 `json:"bondAmt,omitempty"`
	BondConfs   uint32 `json:"bondConfs,omitempty"`
	Disabled    bool   `json:"disabled"`
	NodeRelayID string `json:"nodeRelayID,omitempty"`
}

Asset represents an asset in the Config file.

func LoadConfig added in v1.0.0

func LoadConfig(net dex.Network, filePath string) ([]*dex.MarketInfo, []*Asset, error)

LoadConfig loads the Config from the specified file.

type Bonder added in v0.6.0

type Bonder interface {
	BondVer() uint16
	BondCoin(ctx context.Context, ver uint16, coinID []byte) (amt, lockTime, confs int64,
		acct account.AccountID, err error)
	ParseBondTx(ver uint16, rawTx []byte) (bondCoinID []byte, amt int64, bondAddr string,
		bondPubKeyHash []byte, lockTime int64, acct account.AccountID, err error)
}

Bonder describes a type that supports parsing raw bond transactions and locating them on-chain via coin ID.

type Config added in v1.0.0

type Config struct {
	Markets []*Market         `json:"markets"`
	Assets  map[string]*Asset `json:"assets"`
}

Config is a market and asset configuration file.

type DBConf

type DBConf struct {
	DBName       string
	User         string
	Pass         string
	Host         string
	Port         uint16
	ShowPGConfig bool
}

DBConf groups the database configuration parameters.

type DEX

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

DEX is the DEX manager, which creates and controls the lifetime of all components of the DEX.

func NewDEX

func NewDEX(ctx context.Context, cfg *DexConf) (*DEX, error)

NewDEX creates the dex manager and starts all subsystems. Use Stop to shutdown cleanly. The Context is used to abort setup.

  1. Validate each specified asset.
  2. Create CoinLockers for each asset.
  3. Create and start asset backends.
  4. Create the archivist and connect to the storage backend.
  5. Create the authentication manager.
  6. Create and start the Swapper.
  7. Create and start the markets.
  8. Create and start the book router, and create the order router.
  9. Create and start the comms server.

func (*DEX) AccountInfo

func (dm *DEX) AccountInfo(aid account.AccountID) (*db.Account, error)

AccountInfo returns data for an account.

func (*DEX) AccountMatchOutcomesN added in v1.0.0

func (dm *DEX) AccountMatchOutcomesN(aid account.AccountID, n int) ([]*auth.MatchOutcome, error)

func (*DEX) Asset

func (dm *DEX) Asset(id uint32) (*asset.BackedAsset, error)

Asset retrieves an asset backend by its ID.

func (*DEX) BookOrders added in v0.2.0

func (dm *DEX) BookOrders(base, quote uint32) ([]*order.LimitOrder, error)

BookOrders returns booked orders for market with base and quote.

func (*DEX) ConfigMsg

func (dm *DEX) ConfigMsg() json.RawMessage

ConfigMsg returns the current dex configuration, marshalled to JSON.

func (*DEX) CreatePrepaidBonds added in v1.0.0

func (dm *DEX) CreatePrepaidBonds(n int, strength uint32, durSecs int64) ([][]byte, error)

func (*DEX) EnableDataAPI added in v0.2.0

func (dm *DEX) EnableDataAPI(yes bool)

EnableDataAPI can be called via admin API to enable or disable the HTTP data API endpoints.

func (*DEX) EpochOrders added in v0.2.0

func (dm *DEX) EpochOrders(base, quote uint32) ([]order.Order, error)

EpochOrders returns epoch orders for market with base and quote.

func (*DEX) ForgiveMatchFail

func (dm *DEX) ForgiveMatchFail(aid account.AccountID, mid order.MatchID) (forgiven, unbanned bool, err error)

ForgiveMatchFail forgives a user for a specific match failure, potentially allowing them to resume trading if their score becomes passing.

func (*DEX) Healthy added in v1.0.0

func (dm *DEX) Healthy() bool

Healthy returns the health status of the DEX. This is true if the storage does not report an error and the BTC backend is synced.

func (*DEX) MarketMatches added in v0.2.0

func (dm *DEX) MarketMatches(base, quote uint32) ([]*MatchData, error)

MarketMatches returns matches for market with base and quote.

func (*DEX) MarketMatchesStreaming added in v0.2.0

func (dm *DEX) MarketMatchesStreaming(base, quote uint32, includeInactive bool, N int64, f func(*MatchData) error) (int, error)

MarketMatchesStreaming streams all matches for market with base and quote.

func (*DEX) MarketRunning

func (dm *DEX) MarketRunning(mktName string) (found, running bool)

TODO: for just market running status, the DEX manager should use its knowledge of Market subsystem state.

func (*DEX) MarketStatus

func (dm *DEX) MarketStatus(mktName string) *market.Status

MarketStatus returns the market.Status for the named market. If the market is unknown to the DEX, nil is returned.

func (*DEX) MarketStatuses

func (dm *DEX) MarketStatuses() map[string]*market.Status

MarketStatuses returns a map of market names to market.Status for all known markets.

func (*DEX) Notify

func (dm *DEX) Notify(acctID account.AccountID, msg *msgjson.Message)

Notify sends a text notification to a connected client.

func (*DEX) NotifyAll

func (dm *DEX) NotifyAll(msg *msgjson.Message)

NotifyAll sends a text notification to all connected clients.

func (*DEX) ResumeMarket

func (dm *DEX) ResumeMarket(name string, asSoonAs time.Time) (startEpoch int64, startTime time.Time, err error)

ResumeMarket launches a stopped market subsystem as early as the given time. The actual time the market will resume depends on the configure epoch duration, as the market only starts at the beginning of an epoch.

func (*DEX) ScaleFeeRate

func (dm *DEX) ScaleFeeRate(assetID uint32, rate uint64) uint64

ScaleFeeRate scales the provided fee rate with the given asset's swap fee rate scale factor, which is 1.0 by default.

func (*DEX) SetFeeRateScale

func (dm *DEX) SetFeeRateScale(assetID uint32, scale float64)

SetFeeRateScale specifies a scale factor that the Swapper should use to scale the optimal fee rates for new swaps for for the specified asset. That is, values above 1 increase the fee rate, while values below 1 decrease it.

func (*DEX) Stop

func (dm *DEX) Stop()

Stop shuts down the DEX. Stop returns only after all components have completed their shutdown.

func (*DEX) SuspendMarket

func (dm *DEX) SuspendMarket(name string, tSusp time.Time, persistBooks bool) (suspEpoch *market.SuspendEpoch, err error)

SuspendMarket schedules a suspension of a given market, with the option to persist the orders on the book (or purge the book automatically on market shutdown). The scheduled final epoch and suspend time are returned. This is a passthrough to the OrderRouter. A TradeSuspension notification is broadcasted to all connected clients.

func (*DEX) UserMatchFails added in v1.0.0

func (dm *DEX) UserMatchFails(aid account.AccountID, n int) ([]*auth.MatchFail, error)

type DexConf

type DexConf struct {
	DataDir          string
	LogBackend       *dex.LoggerMaker
	Markets          []*dex.MarketInfo
	Assets           []*Asset
	Network          dex.Network
	DBConf           *DBConf
	BroadcastTimeout time.Duration
	TxWaitExpiration time.Duration
	CancelThreshold  float64
	FreeCancels      bool
	PenaltyThreshold uint32
	DEXPrivKey       *secp256k1.PrivateKey
	CommsCfg         *RPCConfig
	NoResumeSwaps    bool
	NodeRelayAddr    string
}

DexConf is the configuration data required to create a new DEX.

type FeeCoiner added in v0.4.0

type FeeCoiner interface {
	FeeCoin(coinID []byte) (addr string, val uint64, confs int64, err error)
}

FeeCoiner describes a type that can check a transaction output, namely a fee payment, for a particular asset.

type FeeManager added in v0.2.0

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

FeeManager manages fee fetchers and a fee cache.

func NewFeeManager added in v0.2.0

func NewFeeManager() *FeeManager

NewFeeManager is the constructor for a FeeManager.

func (*FeeManager) AddFetcher added in v0.2.0

func (m *FeeManager) AddFetcher(asset *asset.BackedAsset)

AddFetcher adds a fee fetcher (a *BackedAsset) and primes the cache. The asset's MaxFeeRate are used to limit the rates returned by the LastRate method as well as the rates returned by child FeeFetchers.

func (*FeeManager) FeeFetcher added in v0.2.0

func (m *FeeManager) FeeFetcher(assetID uint32) market.FeeFetcher

FeeFetcher creates and returns an asset-specific fetcher that satisfies market.FeeFetcher, implemented by *feeFetcher.

func (*FeeManager) LastRate added in v0.2.0

func (m *FeeManager) LastRate(assetID uint32) uint64

LastRate is the last rate cached for the specified asset.

type Market added in v1.0.0

type Market struct {
	Base       string  `json:"base"`
	Quote      string  `json:"quote"`
	LotSize    uint64  `json:"lotSize"`
	ParcelSize uint32  `json:"parcelSize"`
	RateStep   uint64  `json:"rateStep"`
	Duration   uint64  `json:"epochDuration"`
	MBBuffer   float64 `json:"marketBuyBuffer"`
	Disabled   bool    `json:"disabled"`
}

Market represents the markets specified in the Config file.

type MatchData added in v0.2.0

type MatchData struct {
	db.MatchData
	MakerSwap   string
	TakerSwap   string
	MakerRedeem string
	TakerRedeem string
}

MatchData embeds db.MatchData with decoded swap transaction coin IDs.

type RPCConfig

type RPCConfig = comms.RPCConfig

RPCConfig is an alias for the comms Server's RPC config struct.

Jump to

Keyboard shortcuts

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