amm

package
v3.0.0-...-9661b58 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	MinCoinAmount = sdk.NewInt(100)
	MaxCoinAmount = sdk.NewIntWithDecimal(1, 40)
)

The minimum and maximum coin amount used in the amm package.

View Source
var (
	MinPoolPrice               = sdk.NewDecWithPrec(1, 15)            // 10^-15
	MaxPoolPrice               = sdk.NewIntWithDecimal(1, 20).ToDec() // 10^20
	MinRangedPoolPriceGapRatio = sdk.NewDecWithPrec(1, 3)             // 0.001, 0.1%
)
View Source
var (
	DefaultOrderer = BaseOrderer{}
)

Functions

func Deposit

func Deposit(rx, ry, ps, x, y sdk.Int) (ax, ay, pc sdk.Int)

Deposit returns accepted x and y coin amount and minted pool coin amount when someone deposits x and y coins.

func DeriveTranslation

func DeriveTranslation(rx, ry sdk.Int, minPrice, maxPrice sdk.Dec) (transX, transY sdk.Dec)

func DistributeOrderAmountToOrders

func DistributeOrderAmountToOrders(orders []Order, amt sdk.Int, price sdk.Dec) (quoteCoinDiff sdk.Int)

DistributeOrderAmountToOrders distributes the given order amount to the orders proportional to each order's amount. The caller must sort orders before calling DistributeOrderAmountToOrders. After distributing the amount based on each order's proportion, remaining amount due to the decimal truncation is distributed to the orders again, by priority. This time, the proportion is not considered and each order takes up the amount as much as possible.

func DistributeOrderAmountToTick

func DistributeOrderAmountToTick(tick *orderBookTick, amt sdk.Int, price sdk.Dec) (quoteCoinDiff sdk.Int)

DistributeOrderAmountToTick distributes the given order amount to the orders at the tick. Orders with higher priority(have lower batch id) get matched first, then the remaining amount is distributed to the remaining orders.

func DownTick

func DownTick(price sdk.Dec, prec int) sdk.Dec

DownTick returns the next highest price tick under the price. DownTick doesn't check if the price is the lowest price tick.

func FillOrder

func FillOrder(order Order, amt sdk.Int, price sdk.Dec) (quoteCoinDiff sdk.Int)

FillOrder fills the order by given amount and price.

func FindMatchPrice

func FindMatchPrice(ov OrderView, tickPrec int) (matchPrice sdk.Dec, found bool)

func FulfillOrder

func FulfillOrder(order Order, price sdk.Dec) (quoteCoinDiff sdk.Int)

FulfillOrder fills the order by its remaining open amount at given price.

func FulfillOrders

func FulfillOrders(orders []Order, price sdk.Dec) (quoteCoinDiff sdk.Int)

FulfillOrders fills multiple orders by their remaining open amount at given price.

func HighestTick

func HighestTick(prec int) sdk.Dec

HighestTick returns the highest possible price tick.

func InitialPoolCoinSupply

func InitialPoolCoinSupply(x, y sdk.Int) sdk.Int

InitialPoolCoinSupply returns ideal initial pool coin minting amount.

func LowestTick

func LowestTick(prec int) sdk.Dec

LowestTick returns the lowest possible price tick.

func MatchableAmount

func MatchableAmount(order Order, price sdk.Dec) (matchableAmt sdk.Int)

MatchableAmount returns matchable amount of an order considering remaining offer coin and price.

func OfferCoinAmount

func OfferCoinAmount(dir OrderDirection, price sdk.Dec, amt sdk.Int) sdk.Int

OfferCoinAmount returns the minimum offer coin amount for given order direction, price and order amount.

func PriceToDownTick

func PriceToDownTick(price sdk.Dec, prec int) sdk.Dec

PriceToDownTick returns the highest price tick under(or equal to) the price.

func PriceToUpTick

func PriceToUpTick(price sdk.Dec, prec int) sdk.Dec

PriceToUpTick returns the lowest price tick greater or equal than the price.

func RandomTick

func RandomTick(r *rand.Rand, minPrice, maxPrice sdk.Dec, prec int) sdk.Dec

RandomTick returns a random tick within range [minPrice, maxPrice]. If prices are not on ticks, then prices are adjusted to the nearest ticks.

func RoundPrice

func RoundPrice(price sdk.Dec, prec int) sdk.Dec

RoundPrice returns rounded price using banker's rounding.

func RoundTickIndex

func RoundTickIndex(i int) int

RoundTickIndex returns rounded tick index using banker's rounding.

func SortOrders

func SortOrders(orders []Order)

SortOrders sorts orders using its HasPriority condition.

func TickFromIndex

func TickFromIndex(i, prec int) sdk.Dec

TickFromIndex returns a price for given tick index. See TickToIndex for more details about tick indices.

func TickGap

func TickGap(price sdk.Dec, prec int) sdk.Dec

TickGap returns tick gap at given price.

func TickToIndex

func TickToIndex(price sdk.Dec, prec int) int

TickToIndex returns a tick index for given price. Tick index 0 means the lowest possible price fit in ticks.

func TotalAmount

func TotalAmount(orders []Order) sdk.Int

TotalAmount returns total amount of orders.

func TotalMatchableAmount

func TotalMatchableAmount(orders []Order, price sdk.Dec) (amt sdk.Int)

TotalMatchableAmount returns total matchable amount of orders.

func UpTick

func UpTick(price sdk.Dec, prec int) sdk.Dec

UpTick returns the next lowest price tick above the price.

func ValidateRangedPoolParams

func ValidateRangedPoolParams(minPrice, maxPrice, initialPrice sdk.Dec) error

func Withdraw

func Withdraw(rx, ry, ps, pc sdk.Int, feeRate sdk.Dec) (x, y sdk.Int)

Withdraw returns withdrawn x and y coin amount when someone withdraws pc pool coin. Withdraw also takes care of the fee rate.

Types

type BaseOrder

type BaseOrder struct {
	Direction       OrderDirection
	Price           sdk.Dec
	Amount          sdk.Int
	OfferCoinAmount sdk.Int

	// Match info
	OpenAmount               sdk.Int
	PaidOfferCoinAmount      sdk.Int
	ReceivedDemandCoinAmount sdk.Int
}

BaseOrder is the base struct for an Order.

func NewBaseOrder

func NewBaseOrder(dir OrderDirection, price sdk.Dec, amt, offerCoinAmt sdk.Int) *BaseOrder

NewBaseOrder returns a new BaseOrder.

func (*BaseOrder) GetAmount

func (order *BaseOrder) GetAmount() sdk.Int

GetAmount returns the order amount.

func (*BaseOrder) GetBatchId

func (order *BaseOrder) GetBatchId() uint64

func (*BaseOrder) GetDirection

func (order *BaseOrder) GetDirection() OrderDirection

GetDirection returns the order direction.

func (*BaseOrder) GetOfferCoinAmount

func (order *BaseOrder) GetOfferCoinAmount() sdk.Int

func (*BaseOrder) GetOpenAmount

func (order *BaseOrder) GetOpenAmount() sdk.Int

func (*BaseOrder) GetPaidOfferCoinAmount

func (order *BaseOrder) GetPaidOfferCoinAmount() sdk.Int

func (*BaseOrder) GetPrice

func (order *BaseOrder) GetPrice() sdk.Dec

GetPrice returns the order price.

func (*BaseOrder) GetReceivedDemandCoinAmount

func (order *BaseOrder) GetReceivedDemandCoinAmount() sdk.Int

func (*BaseOrder) HasPriority

func (order *BaseOrder) HasPriority(other Order) bool

HasPriority returns whether the order has higher priority than the other order.

func (*BaseOrder) IsMatched

func (order *BaseOrder) IsMatched() bool

func (*BaseOrder) SetOpenAmount

func (order *BaseOrder) SetOpenAmount(amt sdk.Int)

func (*BaseOrder) SetPaidOfferCoinAmount

func (order *BaseOrder) SetPaidOfferCoinAmount(amt sdk.Int)

func (*BaseOrder) SetReceivedDemandCoinAmount

func (order *BaseOrder) SetReceivedDemandCoinAmount(amt sdk.Int)

func (*BaseOrder) String

func (order *BaseOrder) String() string

type BaseOrderer

type BaseOrderer struct{}

BaseOrderer creates new BaseOrder with sufficient offer coin amount considering price and amount.

func (BaseOrderer) Order

func (orderer BaseOrderer) Order(dir OrderDirection, price sdk.Dec, amt sdk.Int) Order

type BasicPool

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

BasicPool is the basic pool type.

func CreateBasicPool

func CreateBasicPool(rx, ry sdk.Int) (*BasicPool, error)

func NewBasicPool

func NewBasicPool(rx, ry, ps sdk.Int) *BasicPool

NewBasicPool returns a new BasicPool. It is OK to pass an empty sdk.Int to ps when ps is not going to be used.

func (*BasicPool) Balances

func (pool *BasicPool) Balances() (rx, ry sdk.Int)

Balances returns the balances of the pool.

func (*BasicPool) BuyAmountOver

func (pool *BasicPool) BuyAmountOver(price sdk.Dec, _ bool) (amt sdk.Int)

BuyAmountOver returns the amount of buy orders for price greater than or equal to given price. amt = (X - P*Y)/P

func (*BasicPool) BuyAmountTo

func (pool *BasicPool) BuyAmountTo(price sdk.Dec) (amt sdk.Int)

BuyAmountTo returns the amount of buy orders of the pool for price, where BuyAmountTo is used when the pool price is higher than the highest price of the order book.

func (*BasicPool) Clone

func (pool *BasicPool) Clone() Pool

func (*BasicPool) HighestBuyPrice

func (pool *BasicPool) HighestBuyPrice() (price sdk.Dec, found bool)

HighestBuyPrice returns the highest buy price of the pool.

func (*BasicPool) IsDepleted

func (pool *BasicPool) IsDepleted() bool

IsDepleted returns whether the pool is depleted or not.

func (*BasicPool) LowestSellPrice

func (pool *BasicPool) LowestSellPrice() (price sdk.Dec, found bool)

LowestSellPrice returns the lowest sell price of the pool.

func (*BasicPool) PoolCoinSupply

func (pool *BasicPool) PoolCoinSupply() sdk.Int

PoolCoinSupply returns the pool coin supply.

func (*BasicPool) Price

func (pool *BasicPool) Price() sdk.Dec

Price returns the pool price.

func (*BasicPool) SellAmountTo

func (pool *BasicPool) SellAmountTo(price sdk.Dec) (amt sdk.Int)

SellAmountTo returns the amount of sell orders of the pool for price, where SellAmountTo is used when the pool price is lower than the lowest price of the order book.

func (*BasicPool) SellAmountUnder

func (pool *BasicPool) SellAmountUnder(price sdk.Dec, _ bool) (amt sdk.Int)

func (*BasicPool) SetBalances

func (pool *BasicPool) SetBalances(rx, ry sdk.Int, _ bool)

type MultipleOrderViews

type MultipleOrderViews []OrderView

func (MultipleOrderViews) BuyAmountOver

func (views MultipleOrderViews) BuyAmountOver(price sdk.Dec, inclusive bool) sdk.Int

func (MultipleOrderViews) HighestBuyPrice

func (views MultipleOrderViews) HighestBuyPrice() (price sdk.Dec, found bool)

func (MultipleOrderViews) LowestSellPrice

func (views MultipleOrderViews) LowestSellPrice() (price sdk.Dec, found bool)

func (MultipleOrderViews) SellAmountUnder

func (views MultipleOrderViews) SellAmountUnder(price sdk.Dec, inclusive bool) sdk.Int

type Order

type Order interface {
	GetDirection() OrderDirection
	// GetBatchId returns the batch id where the order was created.
	// Batch id of 0 means the current batch.
	GetBatchId() uint64
	GetPrice() sdk.Dec
	GetAmount() sdk.Int // The original order amount
	GetOfferCoinAmount() sdk.Int
	GetPaidOfferCoinAmount() sdk.Int
	SetPaidOfferCoinAmount(amt sdk.Int)
	GetReceivedDemandCoinAmount() sdk.Int
	SetReceivedDemandCoinAmount(amt sdk.Int)
	GetOpenAmount() sdk.Int
	SetOpenAmount(amt sdk.Int)
	IsMatched() bool
	// HasPriority returns true if the order has higher priority
	// than the other order.
	HasPriority(other Order) bool
	String() string
}

Order is the universal interface of an order.

func PoolBuyOrders

func PoolBuyOrders(pool Pool, orderer Orderer, lowestPrice, highestPrice sdk.Dec, tickPrec int) (orders []Order)

func PoolOrders

func PoolOrders(pool Pool, orderer Orderer, lowestPrice, highestPrice sdk.Dec, tickPrec int) []Order

func PoolSellOrders

func PoolSellOrders(pool Pool, orderer Orderer, lowestPrice, highestPrice sdk.Dec, tickPrec int) (orders []Order)

type OrderBook

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

OrderBook is an order book.

func NewOrderBook

func NewOrderBook(orders ...Order) *OrderBook

NewOrderBook returns a new OrderBook.

func (*OrderBook) AddOrder

func (ob *OrderBook) AddOrder(orders ...Order)

AddOrder adds orders to the order book.

func (*OrderBook) BuyOrdersAt

func (ob *OrderBook) BuyOrdersAt(price sdk.Dec) []Order

BuyOrdersAt returns buy orders at given price in the order book. Note that the orders are not sorted.

func (*OrderBook) FindMatchableAmountAtSinglePrice

func (ob *OrderBook) FindMatchableAmountAtSinglePrice(matchPrice sdk.Dec) (matchableAmt sdk.Int, found bool)

FindMatchableAmountAtSinglePrice returns the largest matchable amount of orders when matching orders at single price(batch auction).

func (*OrderBook) FullString

func (ob *OrderBook) FullString(tickPrec int) string

FullString returns a full string representation of the order book. FullString includes all possible price ticks from the order book's highest price to the lowest price.

Example
ob := amm.NewOrderBook(
	newOrder(amm.Sell, utils.ParseDec("1.2"), sdk.NewInt(10000)),
	newOrder(amm.Buy, utils.ParseDec("1.17"), sdk.NewInt(10000)),
	newOrder(amm.Sell, utils.ParseDec("1.15"), sdk.NewInt(5000)),
	newOrder(amm.Sell, utils.ParseDec("1.1"), sdk.NewInt(3000)),
	newOrder(amm.Buy, utils.ParseDec("1.1"), sdk.NewInt(5000)),
	newOrder(amm.Buy, utils.ParseDec("1.1"), sdk.NewInt(1000)),
	newOrder(amm.Sell, utils.ParseDec("1.09"), sdk.NewInt(6000)),
	newOrder(amm.Sell, utils.ParseDec("1.09"), sdk.NewInt(4000)),
	newOrder(amm.Buy, utils.ParseDec("1.06"), sdk.NewInt(15000)),
)
fmt.Println(ob.FullString(2))
Output:

+--------sell--------+------------price-------------+--------buy---------+
|              10000 |         1.200000000000000000 | 0                  |
|                  0 |         1.190000000000000000 | 0                  |
|                  0 |         1.180000000000000000 | 0                  |
|                  0 |         1.170000000000000000 | 10000              |
|                  0 |         1.160000000000000000 | 0                  |
|               5000 |         1.150000000000000000 | 0                  |
|                  0 |         1.140000000000000000 | 0                  |
|                  0 |         1.130000000000000000 | 0                  |
|                  0 |         1.120000000000000000 | 0                  |
|                  0 |         1.110000000000000000 | 0                  |
|               3000 |         1.100000000000000000 | 6000               |
|              10000 |         1.090000000000000000 | 0                  |
|                  0 |         1.080000000000000000 | 0                  |
|                  0 |         1.070000000000000000 | 0                  |
|                  0 |         1.060000000000000000 | 15000              |
+--------------------+------------------------------+--------------------+

func (*OrderBook) HighestPrice

func (ob *OrderBook) HighestPrice() (sdk.Dec, bool)

func (*OrderBook) LowestPrice

func (ob *OrderBook) LowestPrice() (sdk.Dec, bool)

func (*OrderBook) MakeView

func (ob *OrderBook) MakeView() *OrderBookView

func (*OrderBook) Match

func (ob *OrderBook) Match(lastPrice sdk.Dec) (matchPrice sdk.Dec, quoteCoinDiff sdk.Int, matched bool)

Match matches orders sequentially, starting from buy orders with the highest price and sell orders with the lowest price. The matching continues until there's no more matchable orders.

func (*OrderBook) MatchAtSinglePrice

func (ob *OrderBook) MatchAtSinglePrice(matchPrice sdk.Dec) (quoteCoinDiff sdk.Int, matched bool)

MatchAtSinglePrice matches all matchable orders(buy orders with higher(or equal) price than the price and sell orders with lower(or equal) price than the price) at the price.

func (*OrderBook) Orders

func (ob *OrderBook) Orders() []Order

Orders returns all orders in the order book.

func (*OrderBook) PriceDirection

func (ob *OrderBook) PriceDirection(lastPrice sdk.Dec) PriceDirection

PriceDirection returns the estimated price direction within this batch considering the last price.

func (*OrderBook) SellOrdersAt

func (ob *OrderBook) SellOrdersAt(price sdk.Dec) []Order

SellOrdersAt returns sell orders at given price in the order book. Note that the orders are not sorted.

func (*OrderBook) String

func (ob *OrderBook) String() string

String returns a compact string representation of the order book. String includes a tick only when there is at least one order on it.

Example
ob := amm.NewOrderBook(
	newOrder(amm.Sell, utils.ParseDec("1.2"), sdk.NewInt(10000)),
	newOrder(amm.Buy, utils.ParseDec("1.17"), sdk.NewInt(10000)),
	newOrder(amm.Sell, utils.ParseDec("1.15"), sdk.NewInt(5000)),
	newOrder(amm.Sell, utils.ParseDec("1.1"), sdk.NewInt(3000)),
	newOrder(amm.Buy, utils.ParseDec("1.1"), sdk.NewInt(5000)),
	newOrder(amm.Buy, utils.ParseDec("1.1"), sdk.NewInt(1000)),
	newOrder(amm.Sell, utils.ParseDec("1.09"), sdk.NewInt(6000)),
	newOrder(amm.Sell, utils.ParseDec("1.09"), sdk.NewInt(4000)),
	newOrder(amm.Buy, utils.ParseDec("1.06"), sdk.NewInt(15000)),
)
fmt.Println(ob.String())
Output:

+--------sell--------+------------price-------------+--------buy---------+
|              10000 |         1.200000000000000000 | 0                  |
|                  0 |         1.170000000000000000 | 10000              |
|               5000 |         1.150000000000000000 | 0                  |
|               3000 |         1.100000000000000000 | 6000               |
|              10000 |         1.090000000000000000 | 0                  |
|                  0 |         1.060000000000000000 | 15000              |
+--------------------+------------------------------+--------------------+

type OrderBookView

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

func (*OrderBookView) BuyAmountOver

func (view *OrderBookView) BuyAmountOver(price sdk.Dec, inclusive bool) sdk.Int

func (*OrderBookView) BuyAmountUnder

func (view *OrderBookView) BuyAmountUnder(price sdk.Dec, inclusive bool) sdk.Int

func (*OrderBookView) HighestBuyPrice

func (view *OrderBookView) HighestBuyPrice() (sdk.Dec, bool)

func (*OrderBookView) LowestSellPrice

func (view *OrderBookView) LowestSellPrice() (sdk.Dec, bool)

func (*OrderBookView) Match

func (view *OrderBookView) Match()

func (*OrderBookView) SellAmountOver

func (view *OrderBookView) SellAmountOver(price sdk.Dec, inclusive bool) sdk.Int

func (*OrderBookView) SellAmountUnder

func (view *OrderBookView) SellAmountUnder(price sdk.Dec, inclusive bool) sdk.Int

type OrderDirection

type OrderDirection int

OrderDirection specifies an order direction, either buy or sell.

const (
	Buy OrderDirection = iota + 1
	Sell
)

OrderDirection enumerations.

func (OrderDirection) String

func (dir OrderDirection) String() string

type OrderGroup

type OrderGroup struct {
	BatchId uint64
	Orders  []Order
}

OrderGroup represents a group of orders with same batch id.

func GroupOrdersByBatchId

func GroupOrdersByBatchId(orders []Order) (groups []*OrderGroup)

GroupOrdersByBatchId groups orders by their batch id and returns a slice of OrderGroup.

type OrderView

type OrderView interface {
	HighestBuyPrice() (sdk.Dec, bool)
	LowestSellPrice() (sdk.Dec, bool)
	BuyAmountOver(price sdk.Dec, inclusive bool) sdk.Int
	SellAmountUnder(price sdk.Dec, inclusive bool) sdk.Int
}

type Orderer

type Orderer interface {
	Order(dir OrderDirection, price sdk.Dec, amt sdk.Int) Order
}

type Pool

type Pool interface {
	Balances() (rx, ry sdk.Int)
	SetBalances(rx, ry sdk.Int, derive bool)
	PoolCoinSupply() sdk.Int
	Price() sdk.Dec
	IsDepleted() bool

	HighestBuyPrice() (sdk.Dec, bool)
	LowestSellPrice() (sdk.Dec, bool)
	BuyAmountOver(price sdk.Dec, inclusive bool) sdk.Int
	SellAmountUnder(price sdk.Dec, inclusive bool) sdk.Int
	BuyAmountTo(price sdk.Dec) sdk.Int
	SellAmountTo(price sdk.Dec) sdk.Int

	Clone() Pool
}

Pool is the interface of a pool.

type PriceDirection

type PriceDirection int

PriceDirection specifies estimated price direction within this batch.

const (
	PriceStaying PriceDirection = iota + 1
	PriceIncreasing
	PriceDecreasing
)

func (PriceDirection) String

func (dir PriceDirection) String() string

type RangedPool

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

func CreateRangedPool

func CreateRangedPool(x, y sdk.Int, minPrice, maxPrice, initialPrice sdk.Dec) (pool *RangedPool, err error)

CreateRangedPool creates new RangedPool from given inputs, while validating the inputs and using only needed amount of x/y coins(the rest should be refunded).

func NewRangedPool

func NewRangedPool(rx, ry, ps sdk.Int, minPrice, maxPrice sdk.Dec) *RangedPool

NewRangedPool returns a new RangedPool.

func (*RangedPool) Balances

func (pool *RangedPool) Balances() (rx, ry sdk.Int)

Balances returns the balances of the pool.

func (*RangedPool) BuyAmountOver

func (pool *RangedPool) BuyAmountOver(price sdk.Dec, _ bool) (amt sdk.Int)

BuyAmountOver returns the amount of buy orders for price greater than or equal to given price.

func (*RangedPool) BuyAmountTo

func (pool *RangedPool) BuyAmountTo(price sdk.Dec) (amt sdk.Int)

BuyAmountTo returns the amount of buy orders of the pool for price, where BuyAmountTo is used when the pool price is higher than the highest price of the order book.

func (*RangedPool) Clone

func (pool *RangedPool) Clone() Pool

func (*RangedPool) HighestBuyPrice

func (pool *RangedPool) HighestBuyPrice() (price sdk.Dec, found bool)

HighestBuyPrice returns the highest buy price of the pool.

func (*RangedPool) IsDepleted

func (pool *RangedPool) IsDepleted() bool

IsDepleted returns whether the pool is depleted or not.

func (*RangedPool) LowestSellPrice

func (pool *RangedPool) LowestSellPrice() (price sdk.Dec, found bool)

LowestSellPrice returns the lowest sell price of the pool.

func (*RangedPool) MaxPrice

func (pool *RangedPool) MaxPrice() sdk.Dec

func (*RangedPool) MinPrice

func (pool *RangedPool) MinPrice() sdk.Dec

func (*RangedPool) PoolCoinSupply

func (pool *RangedPool) PoolCoinSupply() sdk.Int

PoolCoinSupply returns the pool coin supply.

func (*RangedPool) Price

func (pool *RangedPool) Price() sdk.Dec

Price returns the pool price.

func (*RangedPool) SellAmountTo

func (pool *RangedPool) SellAmountTo(price sdk.Dec) (amt sdk.Int)

SellAmountTo returns the amount of sell orders of the pool for price, where SellAmountTo is used when the pool price is lower than the lowest price of the order book.

func (*RangedPool) SellAmountUnder

func (pool *RangedPool) SellAmountUnder(price sdk.Dec, _ bool) (amt sdk.Int)

SellAmountUnder returns the amount of sell orders for price less than or equal to given price.

func (*RangedPool) SetBalances

func (pool *RangedPool) SetBalances(rx, ry sdk.Int, derive bool)

SetBalances sets RangedPool's balances without recalculating transX and transY.

func (*RangedPool) Translation

func (pool *RangedPool) Translation() (transX, transY sdk.Dec)

type TickPrecision

type TickPrecision int

TickPrecision represents a tick precision.

func (TickPrecision) DownTick

func (prec TickPrecision) DownTick(price sdk.Dec) sdk.Dec

func (TickPrecision) HighestTick

func (prec TickPrecision) HighestTick() sdk.Dec

func (TickPrecision) LowestTick

func (prec TickPrecision) LowestTick() sdk.Dec

func (TickPrecision) PriceToDownTick

func (prec TickPrecision) PriceToDownTick(price sdk.Dec) sdk.Dec

func (TickPrecision) PriceToUpTick

func (prec TickPrecision) PriceToUpTick(price sdk.Dec) sdk.Dec

func (TickPrecision) RandomTick

func (prec TickPrecision) RandomTick(r *rand.Rand, minPrice, maxPrice sdk.Dec) sdk.Dec

func (TickPrecision) RoundPrice

func (prec TickPrecision) RoundPrice(price sdk.Dec) sdk.Dec

func (TickPrecision) TickFromIndex

func (prec TickPrecision) TickFromIndex(i int) sdk.Dec

func (TickPrecision) TickGap

func (prec TickPrecision) TickGap(price sdk.Dec) sdk.Dec

func (TickPrecision) TickToIndex

func (prec TickPrecision) TickToIndex(tick sdk.Dec) int

func (TickPrecision) UpTick

func (prec TickPrecision) UpTick(price sdk.Dec) sdk.Dec

Jump to

Keyboard shortcuts

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