swap

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: BlueOak-1.0.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

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.

Types

type AuthManager

type AuthManager interface {
	Route(string, func(account.AccountID, *msgjson.Message) *msgjson.Error)
	Auth(user account.AccountID, msg, sig []byte) error
	Sign(...msgjson.Signable)
	Send(account.AccountID, *msgjson.Message) error
	Request(account.AccountID, *msgjson.Message, func(comms.Link, *msgjson.Message)) error
	RequestWithTimeout(user account.AccountID, req *msgjson.Message, handlerFunc func(comms.Link, *msgjson.Message),
		expireTimeout time.Duration, expireFunc func()) error
	SwapSuccess(user account.AccountID, mmid db.MarketMatchID, value uint64, refTime time.Time)
	Inaction(user account.AccountID, misstep auth.NoActionStep, mmid db.MarketMatchID, matchValue uint64, refTime time.Time, oid order.OrderID)
}

AuthManager handles client-related actions, including authorization and communications.

type Config

type Config struct {
	// Assets is a map to all the asset information, including the asset backends,
	// used by this Swapper.
	Assets map[uint32]*SwapperAsset
	// AuthManager is the auth manager for client messaging and authentication.
	AuthManager AuthManager
	// A database backend.
	Storage Storage
	// BroadcastTimeout is how long the Swapper will wait for expected swap
	// transactions following new blocks.
	BroadcastTimeout time.Duration
	// TxWaitExpiration is the longest the Swapper will wait for a coin waiter.
	// This could be thought of as the maximum allowable backend latency.
	TxWaitExpiration time.Duration
	// LockTimeTaker is the locktime Swapper will use for auditing taker swaps.
	LockTimeTaker time.Duration
	// LockTimeMaker is the locktime Swapper will use for auditing maker swaps.
	LockTimeMaker time.Duration
	// NoResume indicates that the swapper should not resume active swaps.
	NoResume bool
	// AllowPartialRestore indicates if it is acceptable to load only some of
	// the active swaps if the Swapper's asset configuration lacks assets
	// required to load them all.
	AllowPartialRestore bool
	// SwapDone registers a match with the DEX manager (or other consumer) for a
	// given order as being finished.
	SwapDone func(oid order.Order, match *order.Match, fail bool)
}

Config is the swapper configuration settings. A Config instance is the only argument to the Swapper constructor.

type Storage

type Storage interface {
	db.SwapArchiver
	LastErr() error
	Fatal() <-chan struct{}
	Order(oid order.OrderID, base, quote uint32) (order.Order, order.OrderStatus, error)
	CancelOrder(*order.LimitOrder) error
	InsertMatch(match *order.Match) error
}

Storage updates match data in what is presumably a database.

type Swapper

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

Swapper handles order matches by handling authentication and inter-party communications between clients, or 'users'. The Swapper authenticates users (vua AuthManager) and validates transactions as they are reported.

func NewSwapper

func NewSwapper(cfg *Config) (*Swapper, error)

NewSwapper is a constructor for a Swapper.

func (*Swapper) AccountStats added in v0.5.0

func (s *Swapper) AccountStats(acctAddr string, assetID uint32) (qty, swaps uint64, redeems int)

AccountStats is part of the MatchNegotiator interface to report in-process match information for a asset account address.

func (*Swapper) ChainsSynced

func (s *Swapper) ChainsSynced(base, quote uint32) (bool, error)

ChainsSynced will return true if both specified asset's backends are synced.

func (*Swapper) CheckUnspent

func (s *Swapper) CheckUnspent(ctx context.Context, assetID uint32, coinID []byte) error

CheckUnspent attempts to verify a coin ID for a given asset by retrieving the corresponding asset.Coin. If the coin is not found or spent, an asset.CoinNotFoundError is returned. CheckUnspent returns immediately with no error if the requested asset is not a utxo-based asset.

func (*Swapper) LockCoins

func (s *Swapper) LockCoins(asset uint32, coins map[order.OrderID][]order.CoinID)

LockCoins locks coins of a given asset. The OrderID is used for tracking.

func (*Swapper) LockOrdersCoins

func (s *Swapper) LockOrdersCoins(orders []order.Order)

LockOrdersCoins locks the backing coins for the provided orders.

func (*Swapper) Negotiate

func (s *Swapper) Negotiate(matchSets []*order.MatchSet)

Negotiate takes ownership of the matches and begins swap negotiation. For reliable identification of completed orders when redeem acks are received and processed by processAck, BeginMatchAndNegotiate should be called prior to matching and order status/amount updates, and EndMatchAndNegotiate should be called after Negotiate. This locking sequence allows for orders that may already be involved in active swaps to remain unmodified by the Matcher/Market until new matches are recorded by the Swapper in Negotiate. If this is not done, it is possible that an order may be flagged as completed if a swap A completes after Matching and creation of swap B but before Negotiate has a chance to record the new swap.

func (*Swapper) Run

func (s *Swapper) Run(ctx context.Context)

Run is the main Swapper loop. It's primary purpose is to update transaction confirmations when new blocks are mined, and to trigger inaction checks.

func (*Swapper) UserSwappingAmt

func (s *Swapper) UserSwappingAmt(user account.AccountID, base, quote uint32) (amt, count uint64)

UserSwappingAmt gets the total amount in active swaps for a user in a specified market. This helps the market compute a user's order size limit.

type SwapperAsset added in v0.5.0

type SwapperAsset struct {
	*asset.BackedAsset
	Locker coinlock.CoinLocker // should be *coinlock.AssetCoinLocker
}

SwapperAsset is a BackedAsset with an optional CoinLocker.

Jump to

Keyboard shortcuts

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