keeper

package
v0.0.0-...-8470daa Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Price Directions
	Increase = 1
	Decrease = 2
	Stay     = 3

	// Match Types
	ExactMatch      = 1
	NoMatch         = 2
	FractionalMatch = 3

	OrderLifeSpanHeight = 0

	DirectionXtoY = 1
	DirectionYtoX = 2

	DefaultSwapType = 0
)

TODO: refactoring, move to types/swap.go

Variables

This section is empty.

Functions

func CheckValidityOrderBook

func CheckValidityOrderBook(orderBook OrderBook, currentPrice sdk.Dec) bool

func ClearOrders

func ClearOrders(XtoY, YtoX []types.BatchPoolSwapMsg) ([]types.BatchPoolSwapMsg, []types.BatchPoolSwapMsg)

func GetExecutableAmt

func GetExecutableAmt(swapPrice sdk.Dec, orderBook OrderBook) (executableBuyAmtX, executableSellAmtY sdk.Int)

func GetPriceDirection

func GetPriceDirection(currentPrice sdk.Dec, orderBook OrderBook) int

func MaxDec

func MaxDec(a, b sdk.Dec) sdk.Dec

func MinDec

func MinDec(a, b sdk.Dec) sdk.Dec

func NewQuerier

func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier

NewQuerier creates a querier for liquidity REST endpoints

Types

type BatchResult

type BatchResult struct {
	MatchType   int
	SwapPrice   sdk.Dec
	EX          sdk.Dec
	EY          sdk.Dec
	OriginalEX  sdk.Int
	OriginalEY  sdk.Int
	PoolX       sdk.Dec
	PoolY       sdk.Dec
	TransactAmt sdk.Dec
}

func CalculateMatch

func CalculateMatch(direction int, X, Y, currentPrice sdk.Dec, orderBook OrderBook) (result BatchResult)

func CalculateMatchStay

func CalculateMatchStay(currentPrice sdk.Dec, orderBook OrderBook) (r BatchResult)

func CalculateSwap

func CalculateSwap(direction int, X, Y, orderPrice, lastOrderPrice sdk.Dec, orderBook OrderBook) (r BatchResult)

TODO: find and fix decimal errors

func CompareTransactAmtX

func CompareTransactAmtX(X, Y, currentPrice sdk.Dec, orderBook OrderBook) (result BatchResult)

func NewBatchResult

func NewBatchResult() BatchResult

type Keeper

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

Keeper of the liquidity store

func NewKeeper

func NewKeeper(cdc codec.Marshaler, key sdk.StoreKey, paramSpace paramstypes.Subspace, bankKeeper types.BankKeeper, accountKeeper types.AccountKeeper) Keeper

NewKeeper returns a liquidity keeper. It handles: - creating new ModuleAccounts for each pool ReserveAccount - sending to and from ModuleAccounts - minting, burning PoolCoins

func (Keeper) CreateLiquidityPool

func (k Keeper) CreateLiquidityPool(ctx sdk.Context, msg *types.MsgCreateLiquidityPool) error

func (Keeper) DeleteAndInitPoolBatch

func (k Keeper) DeleteAndInitPoolBatch(ctx sdk.Context)

func (Keeper) DeleteLiquidityPoolBatch

func (k Keeper) DeleteLiquidityPoolBatch(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch)

func (Keeper) DepositLiquidityPool

func (k Keeper) DepositLiquidityPool(ctx sdk.Context, msg *types.MsgDepositToLiquidityPool) error

func (Keeper) DepositLiquidityPoolToBatch

func (k Keeper) DepositLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgDepositToLiquidityPool) error

func (Keeper) ExecutePoolBatch

func (k Keeper) ExecutePoolBatch(ctx sdk.Context)

func (Keeper) GetAllLiquidityPoolBatchDepositMsgs

func (k Keeper) GetAllLiquidityPoolBatchDepositMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch) (msgs []types.BatchPoolDepositMsg)

GetAllLiquidityPoolBatchDepositMsgs returns all BatchDepositMsgs indexed by the liquidityPoolBatch

func (Keeper) GetAllLiquidityPoolBatchSwapMsgs

func (k Keeper) GetAllLiquidityPoolBatchSwapMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch) (msgs []types.BatchPoolSwapMsg)

GetAllLiquidityPoolBatchSwapMsgs returns all BatchSwapMsgs indexed by the liquidityPoolBatch

func (Keeper) GetAllLiquidityPoolBatchWithdrawMsgs

func (k Keeper) GetAllLiquidityPoolBatchWithdrawMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch) (msgs []types.BatchPoolWithdrawMsg)

GetAllLiquidityPoolBatchWithdrawMsgs returns all BatchWithdrawMsgs indexed by the liquidityPoolBatch

func (Keeper) GetAllLiquidityPoolBatches

func (k Keeper) GetAllLiquidityPoolBatches(ctx sdk.Context) (liquidityPoolBatches []types.LiquidityPoolBatch)

func (Keeper) GetAllLiquidityPools

func (k Keeper) GetAllLiquidityPools(ctx sdk.Context) (liquidityPools []types.LiquidityPool)

GetAllLiquidityPools returns all liquidityPools used during genesis dump

func (Keeper) GetLiquidityPool

func (k Keeper) GetLiquidityPool(ctx sdk.Context, poolID uint64) (liquidityPool types.LiquidityPool, found bool)

return a specific liquidityPool

func (Keeper) GetLiquidityPoolBatch

func (k Keeper) GetLiquidityPoolBatch(ctx sdk.Context, poolID, batchIndex uint64) (liquidityPoolBatch types.LiquidityPoolBatch, found bool)

return a specific liquidityPoolBatch

func (Keeper) GetLiquidityPoolBatchIndex

func (k Keeper) GetLiquidityPoolBatchIndex(ctx sdk.Context, poolID uint64) (liquidityPoolBatchIndex uint64)

return a specific GetLiquidityPoolBatchIndexKey

func (Keeper) GetLiquidityPoolByReserveAccIndex

func (k Keeper) GetLiquidityPoolByReserveAccIndex(ctx sdk.Context, reserveAcc sdk.AccAddress) (liquidityPool types.LiquidityPool, found bool)

func (Keeper) GetNextBatchIndexWithUpdate

func (k Keeper) GetNextBatchIndexWithUpdate(ctx sdk.Context, poolID uint64) (batchIndex uint64)

func (Keeper) GetNextLiquidityPoolIDWithUpdate

func (k Keeper) GetNextLiquidityPoolIDWithUpdate(ctx sdk.Context) uint64

GetNextLiquidityID returns and increments the global Liquidity Pool ID counter. If the global account number is not set, it initializes it with value 0.

func (Keeper) GetParams

func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)

GetParams gets the parameters for the liquidity module.

func (Keeper) GetPoolCoinTotalSupply

func (k Keeper) GetPoolCoinTotalSupply(ctx sdk.Context, lp types.LiquidityPool) sdk.Int

func (Keeper) GetReserveCoins

func (k Keeper) GetReserveCoins(ctx sdk.Context, lp types.LiquidityPool) (reserveCoins sdk.Coins)

func (Keeper) IterateAllLiquidityPoolBatchDepositMsgs

func (k Keeper) IterateAllLiquidityPoolBatchDepositMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, cb func(msg types.BatchPoolDepositMsg) (stop bool))

IterateAllLiquidityPoolBatchDepositMsgs iterate through all of the LiquidityPoolBatchDepositMsgs

func (Keeper) IterateAllLiquidityPoolBatchSwapMsgs

func (k Keeper) IterateAllLiquidityPoolBatchSwapMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, cb func(msg types.BatchPoolSwapMsg) (stop bool))

IterateAllLiquidityPoolBatchSwapMsgs iterate through all of the LiquidityPoolBatchSwapMsgs

func (Keeper) IterateAllLiquidityPoolBatchWithdrawMsgs

func (k Keeper) IterateAllLiquidityPoolBatchWithdrawMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, cb func(msg types.BatchPoolWithdrawMsg) (stop bool))

IterateAllLiquidityPoolBatchWithdrawMsgs iterate through all of the LiquidityPoolBatchWithdrawMsgs

func (Keeper) IterateAllLiquidityPoolBatches

func (k Keeper) IterateAllLiquidityPoolBatches(ctx sdk.Context, cb func(liquidityPoolBatch types.LiquidityPoolBatch) (stop bool))

IterateAllLiquidityPoolBatches iterate through all of the liquidityPoolBatches

func (Keeper) IterateAllLiquidityPools

func (k Keeper) IterateAllLiquidityPools(ctx sdk.Context, cb func(liquidityPool types.LiquidityPool) (stop bool))

IterateAllLiquidityPools iterate through all of the liquidityPools

func (Keeper) Logger

func (k Keeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger.

func (Keeper) SetLiquidityPool

func (k Keeper) SetLiquidityPool(ctx sdk.Context, liquidityPool types.LiquidityPool)

func (Keeper) SetLiquidityPoolAtomic

func (k Keeper) SetLiquidityPoolAtomic(ctx sdk.Context, liquidityPool types.LiquidityPool)

func (Keeper) SetLiquidityPoolBatch

func (k Keeper) SetLiquidityPoolBatch(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch)

func (Keeper) SetLiquidityPoolBatchDepositMsg

func (k Keeper) SetLiquidityPoolBatchDepositMsg(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, msgIndex uint64, msg types.BatchPoolDepositMsg)

func (Keeper) SetLiquidityPoolBatchIndex

func (k Keeper) SetLiquidityPoolBatchIndex(ctx sdk.Context, poolID, batchIndex uint64)

func (Keeper) SetLiquidityPoolBatchSwapMsg

func (k Keeper) SetLiquidityPoolBatchSwapMsg(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, msgIndex uint64, msg types.BatchPoolSwapMsg)

func (Keeper) SetLiquidityPoolBatchWithdrawMsg

func (k Keeper) SetLiquidityPoolBatchWithdrawMsg(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, msgIndex uint64, msg types.BatchPoolWithdrawMsg)

func (Keeper) SetLiquidityPoolByReserveAccIndex

func (k Keeper) SetLiquidityPoolByReserveAccIndex(ctx sdk.Context, liquidityPool types.LiquidityPool)

func (Keeper) SetParams

func (k Keeper) SetParams(ctx sdk.Context, params types.Params)

SetParams sets the parameters for the liquidity module.

func (Keeper) SwapExecution

func (k Keeper) SwapExecution(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch) error

func (Keeper) SwapLiquidityPoolToBatch

func (k Keeper) SwapLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgSwap) error

TODO: need to fix, not added msgs

func (Keeper) WithdrawLiquidityPool

func (k Keeper) WithdrawLiquidityPool(ctx sdk.Context, msg *types.MsgWithdrawFromLiquidityPool) error

func (Keeper) WithdrawLiquidityPoolToBatch

func (k Keeper) WithdrawLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgWithdrawFromLiquidityPool) error

type MatchResult

type MatchResult struct {
	OrderHeight       int64
	OrderCancelHeight int64
	OrderMsgIndex     uint64
	OrderPrice        sdk.Dec
	OrderAmt          sdk.Int
	MatchedAmt        sdk.Int
	RefundAmt         sdk.Int
	ResidualAmt       sdk.Int
	ReceiveAmt        sdk.Int
	FeeAmt            sdk.Int
}

func FindOrderMatch

func FindOrderMatch(direction int, swapList []types.BatchPoolSwapMsg, executableAmt, swapPrice, swapFeeRate sdk.Dec, height int64) (matchResultList []MatchResult, swapListExecuted []types.BatchPoolSwapMsg, poolXdelta, poolYdelta sdk.Int)

TODO: need to debugging

type OrderBook

type OrderBook []OrderByPrice

func (OrderBook) Len

func (orderBook OrderBook) Len() int

Len implements sort.Interface for OrderBook

func (OrderBook) Less

func (orderBook OrderBook) Less(i, j int) bool

Less implements sort.Interface for OrderBook

func (OrderBook) Reverse

func (orderBook OrderBook) Reverse()

func (OrderBook) Sort

func (orderBook OrderBook) Sort()

func (OrderBook) Swap

func (orderBook OrderBook) Swap(i, j int)

Swap implements sort.Interface for OrderBook

type OrderByPrice

type OrderByPrice struct {
	OrderPrice   sdk.Dec
	BuyOrderAmt  sdk.Int
	SellOrderAmt sdk.Int
}

type OrderMap

type OrderMap map[sdk.Dec]OrderByPrice

func GetOrderMap

func GetOrderMap(swapMsgs []types.BatchPoolSwapMsg, denomX, denomY string) (OrderMap, []types.BatchPoolSwapMsg, []types.BatchPoolSwapMsg)

func (OrderMap) SortOrderBook

func (orderMap OrderMap) SortOrderBook() (orderBook OrderBook)

Jump to

Keyboard shortcuts

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