orderbook

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0, Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculatePoolExpectation added in v1.11.1

func CalculatePoolExpectation(
	reserveA, reserveB, disbursed xdr.Int64, feeBips xdr.Int32, calculateRoundingSlippage bool,
) (xdr.Int64, xdr.Int64, bool)

CalculatePoolExpectation determines how much of `reserveA` you would need to put into a pool to get the `disbursed` amount of `reserveB`.

x = ceil[Xy / ((Y - y)(1 - F))]

It returns false if the calculation overflows.

func CalculatePoolPayout added in v1.11.1

func CalculatePoolPayout(reserveA, reserveB, received xdr.Int64, feeBips xdr.Int32, calculateRoundingSlippage bool) (xdr.Int64, xdr.Int64, bool)

CalculatePoolPayout calculates the amount of `reserveB` disbursed from the pool for a `received` amount of `reserveA` . From CAP-38:

y = floor[(1 - F) Yx / (X + x - Fx)]

It returns false if the calculation overflows.

Types

type OBGraph added in v1.11.1

type OBGraph interface {
	AddOffers(offer ...xdr.OfferEntry)
	AddLiquidityPools(liquidityPool ...xdr.LiquidityPoolEntry)
	Apply(ledger uint32) error
	Discard()
	Offers() []xdr.OfferEntry
	LiquidityPools() []xdr.LiquidityPoolEntry
	RemoveOffer(xdr.Int64) OBGraph
	RemoveLiquidityPool(pool xdr.LiquidityPoolEntry) OBGraph
	Verify() ([]xdr.OfferEntry, []xdr.LiquidityPoolEntry, error)
	Clear()
}

OBGraph is an interface for orderbook graphs

type OrderBookGraph

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

OrderBookGraph is an in-memory graph representation of all the offers in the Hcnet ledger.

func NewOrderBookGraph

func NewOrderBookGraph() *OrderBookGraph

NewOrderBookGraph constructs an empty OrderBookGraph

func (*OrderBookGraph) AddLiquidityPools added in v1.11.1

func (graph *OrderBookGraph) AddLiquidityPools(pools ...xdr.LiquidityPoolEntry)

AddLiquidityPools will queue an operation to add the given liquidity pool(s) to the order book graph in the internal batch.

You need to run Apply() to apply all enqueued operations.

func (*OrderBookGraph) AddOffers added in v1.11.1

func (graph *OrderBookGraph) AddOffers(offers ...xdr.OfferEntry)

AddOffers will queue an operation to add the given offer(s) to the order book in the internal batch.

You need to run Apply() to apply all enqueued operations.

func (*OrderBookGraph) Apply

func (graph *OrderBookGraph) Apply(ledger uint32) error

Apply will attempt to apply all the updates in the internal batch to the order book. When Apply is successful, a new empty, instance of internal batch will be created.

func (*OrderBookGraph) Clear added in v1.11.1

func (graph *OrderBookGraph) Clear()

Clear removes all offers from the graph.

func (*OrderBookGraph) Discard

func (graph *OrderBookGraph) Discard()

Discard removes all operations which have been queued but not yet applied to the OrderBookGraph

func (*OrderBookGraph) FindFixedPaths

func (graph *OrderBookGraph) FindFixedPaths(
	ctx context.Context,
	maxPathLength int,
	sourceAsset xdr.Asset,
	amountToSpend xdr.Int64,
	destinationAssets []xdr.Asset,
	maxAssetsPerPath int,
	includePools bool,
) ([]Path, uint32, error)

FindFixedPaths returns a list of payment paths where the source and destination assets are fixed.

All returned payment paths will start by spending `amountToSpend` of `sourceAsset` and will end with some positive balance of `destinationAsset`.

`sourceAccountID` is optional, but if it's provided, then no offers created by `sourceAccountID` will be considered when evaluating payment paths.

func (*OrderBookGraph) FindPaths

func (graph *OrderBookGraph) FindPaths(
	ctx context.Context,
	maxPathLength int,
	destinationAsset xdr.Asset,
	destinationAmount xdr.Int64,
	sourceAccountID *xdr.AccountId,
	sourceAssets []xdr.Asset,
	sourceAssetBalances []xdr.Int64,
	validateSourceBalance bool,
	maxAssetsPerPath int,
	includePools bool,
) ([]Path, uint32, error)

FindPaths returns a list of payment paths originating from a source account and ending with a given destinaton asset and amount.

func (*OrderBookGraph) IsEmpty

func (graph *OrderBookGraph) IsEmpty() bool

IsEmpty returns true if the orderbook graph is not populated

func (*OrderBookGraph) LiquidityPools added in v1.11.1

func (graph *OrderBookGraph) LiquidityPools() []xdr.LiquidityPoolEntry

LiquidityPools returns a list of unique liquidity pools contained in the order book graph

func (*OrderBookGraph) Offers

func (graph *OrderBookGraph) Offers() []xdr.OfferEntry

Offers returns a list of offers contained in the order book

func (*OrderBookGraph) RemoveLiquidityPool added in v1.11.1

func (graph *OrderBookGraph) RemoveLiquidityPool(pool xdr.LiquidityPoolEntry) OBGraph

RemoveLiquidityPool will queue an operation to remove any liquidity pool (if any) that matches the given pool, based exclusively on the pool ID.

You need to run Apply() to apply all enqueued operations.

func (*OrderBookGraph) RemoveOffer

func (graph *OrderBookGraph) RemoveOffer(offerID xdr.Int64) OBGraph

RemoveOffer will queue an operation to remove the given offer from the order book in the internal batch.

You need to run Apply() to apply all enqueued operations.

func (*OrderBookGraph) Verify added in v1.11.1

func (graph *OrderBookGraph) Verify() ([]xdr.OfferEntry, []xdr.LiquidityPoolEntry, error)

Verify checks the internal consistency of the OrderBookGraph data structures and returns all the offers and pools contained in the graph.

type Path

type Path struct {
	SourceAsset       string
	SourceAmount      xdr.Int64
	DestinationAsset  string
	DestinationAmount xdr.Int64

	InteriorNodes []string
}

Path represents a payment path from a source asset to some destination asset

type Venues added in v1.11.1

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

Jump to

Keyboard shortcuts

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