formula

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package formula defines the formulas that implements the MarketFormula interface

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidBalancedReservesOptsType ...
	ErrInvalidBalancedReservesOptsType = errors.New(
		"opts must be of type BalancedReservesOpts",
	)
	// ErrAmountTooLow ...
	ErrAmountTooLow = errors.New("provided amount is too low")
	// ErrAmountTooBig ...
	ErrAmountTooBig = errors.New("provided amount is too big")
	// ErrBalanceTooLow ...
	ErrBalanceTooLow = errors.New("reserve balance amount is too low")
)
View Source
var (
	ErrInvalidPluggableOptsType = fmt.Errorf("opts must be of type PluggableOpts")
)

Functions

This section is empty.

Types

type BalancedReserves

type BalancedReserves struct{}

BalancedReserves defines an AMM strategy with fixed 50/50 reserves

func (BalancedReserves) InGivenOut

func (BalancedReserves) InGivenOut(
	_opts interface{}, amountOut decimal.Decimal,
) (amountIn decimal.Decimal, err error)

InGivenOut returns the amountIn of assets that will be needed for having the desired amountOut in return.

func (BalancedReserves) OutGivenIn

func (BalancedReserves) OutGivenIn(
	_opts interface{}, amountIn decimal.Decimal,
) (amountOut decimal.Decimal, err error)

OutGivenIn returns the amountOut of asset that will be exchanged for the given amountIn.

func (BalancedReserves) SpotPrice

func (BalancedReserves) SpotPrice(_opts interface{}) (spotPrice decimal.Decimal, err error)

SpotPrice calculates the spot price (without fees) given the balances fo the two reserves. The weight reserve ratio is fixed at 50/50

type BalancedReservesOpts added in v0.4.4

type BalancedReservesOpts struct {
	BalanceIn  decimal.Decimal
	BalanceOut decimal.Decimal
	WeightIn   uint64
	WeightOut  uint64
}

BalancedReservesOpts defines the parameters needed to calculate the spot price

type Pluggable added in v1.0.0

type Pluggable struct{}

func (Pluggable) InGivenOut added in v1.0.0

func (s Pluggable) InGivenOut(
	_opts interface{}, amountOut decimal.Decimal,
) (amountIn decimal.Decimal, err error)

func (Pluggable) OutGivenIn added in v1.0.0

func (s Pluggable) OutGivenIn(
	_opts interface{}, amountIn decimal.Decimal,
) (amountOut decimal.Decimal, err error)

func (Pluggable) SpotPrice added in v1.0.0

func (s Pluggable) SpotPrice(
	_ interface{},
) (spotPrice decimal.Decimal, err error)

type PluggableOpts added in v1.0.0

type PluggableOpts struct {
	BalanceIn  decimal.Decimal
	BalanceOut decimal.Decimal
	Price      decimal.Decimal
}

Jump to

Keyboard shortcuts

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