Documentation ¶
Index ¶
- func CalculatePoolExpectation(reserveA, reserveB, disbursed xdr.Int64, feeBips xdr.Int32, ...) (xdr.Int64, xdr.Int64, bool)
- func CalculatePoolPayout(reserveA, reserveB, received xdr.Int64, feeBips xdr.Int32, ...) (xdr.Int64, xdr.Int64, bool)
- type OBGraph
- type OrderBookGraph
- func (graph *OrderBookGraph) AddLiquidityPools(pools ...xdr.LiquidityPoolEntry)
- func (graph *OrderBookGraph) AddOffers(offers ...xdr.OfferEntry)
- func (graph *OrderBookGraph) Apply(ledger uint32) error
- func (graph *OrderBookGraph) Clear()
- func (graph *OrderBookGraph) Discard()
- func (graph *OrderBookGraph) FindFixedPaths(ctx context.Context, maxPathLength int, sourceAsset xdr.Asset, ...) ([]Path, uint32, error)
- func (graph *OrderBookGraph) FindPaths(ctx context.Context, maxPathLength int, destinationAsset xdr.Asset, ...) ([]Path, uint32, error)
- func (graph *OrderBookGraph) IsEmpty() bool
- func (graph *OrderBookGraph) LiquidityPools() []xdr.LiquidityPoolEntry
- func (graph *OrderBookGraph) Offers() []xdr.OfferEntry
- func (graph *OrderBookGraph) RemoveLiquidityPool(pool xdr.LiquidityPoolEntry) OBGraph
- func (graph *OrderBookGraph) RemoveOffer(offerID xdr.Int64) OBGraph
- func (graph *OrderBookGraph) Verify() ([]xdr.OfferEntry, []xdr.LiquidityPoolEntry, error)
- type Path
- type Venues
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculatePoolExpectation ¶
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 ¶
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 ¶
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 Stellar ledger.
func NewOrderBookGraph ¶
func NewOrderBookGraph() *OrderBookGraph
NewOrderBookGraph constructs an empty OrderBookGraph
func (*OrderBookGraph) AddLiquidityPools ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.