keeper

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: Apache-2.0 Imports: 29 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultBookSize = 200
)

nolint

Variables

This section is empty.

Functions

func GetDealFee

func GetDealFee(order *types.Order, fillAmt sdk.Dec, ctx sdk.Context, keeper GetFeeKeeper,
	feeParams *types.Params) sdk.SysCoins

GetDealFee is used to calculate the handling fee when matching an order

func GetOrderCostFee

func GetOrderCostFee(order *types.Order, ctx sdk.Context) sdk.SysCoins

GetOrderCostFee is used to calculate the handling fee when quiting an order

func GetOrderNewFee

func GetOrderNewFee(order *types.Order) sdk.SysCoins

GetOrderNewFee is used to calculate the handling fee that needs to be locked when placing an order

func GetZeroFee

func GetZeroFee() sdk.SysCoins

GetZeroFee returns zeroFee

func MakeTestCodec

func MakeTestCodec() *codec.Codec

MakeTestCodec creates a codec used only for testing

func ModuleAccountInvariant

func ModuleAccountInvariant(keeper Keeper) sdk.Invariant

ModuleAccountInvariant checks that the module account coins reflects the sum of locks amounts held on store

func NewQuerier

func NewQuerier(keeper Keeper) sdk.Querier

NewQuerier is the module level router for state queries

func RegisterInvariants

func RegisterInvariants(ir sdk.InvariantRegistry, keeper Keeper)

RegisterInvariants registers all order invariants

Types

type BookRes

type BookRes struct {
	Asks []BookResItem `json:"asks"`
	Bids []BookResItem `json:"bids"`
}

BookRes is used to return the result of queryDepthBook

type BookResItem

type BookResItem struct {
	Price    string `json:"price"`
	Quantity string `json:"quantity"`
}

nolint

type Cache

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

Cache stores some caches that will not be written to disk

func NewCache

func NewCache() *Cache

nolint

func (*Cache) DecreaseCancelNum

func (c *Cache) DecreaseCancelNum() int64

nolint

func (*Cache) DecreaseFullFillNum

func (c *Cache) DecreaseFullFillNum() int64

nolint

func (*Cache) DecreasePartialFillNum

func (c *Cache) DecreasePartialFillNum() int64

nolint

func (*Cache) GetCancelNum

func (c *Cache) GetCancelNum() int64

nolint

func (*Cache) GetExpireNum

func (c *Cache) GetExpireNum() int64

nolint

func (*Cache) GetFullFillNum

func (c *Cache) GetFullFillNum() int64

nolint

func (*Cache) GetPartialFillNum

func (c *Cache) GetPartialFillNum() int64

nolint

func (*Cache) IncreaseCancelNum

func (c *Cache) IncreaseCancelNum() int64

nolint

func (*Cache) IncreaseExpireNum

func (c *Cache) IncreaseExpireNum() int64

nolint

func (*Cache) IncreaseFullFillNum

func (c *Cache) IncreaseFullFillNum() int64

nolint

func (*Cache) IncreasePartialFillNum

func (c *Cache) IncreasePartialFillNum() int64

nolint

type DepthBookMap

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

DepthBookMap stores depthBook with map. <product> -> <depthBook>

type DexKeeper

type DexKeeper interface {
	// TokenPair
	GetTokenPair(ctx sdk.Context, product string) *dex.TokenPair
	GetTokenPairs(ctx sdk.Context) []*dex.TokenPair
	SortProducts(ctx sdk.Context, products []string)
	SaveTokenPair(ctx sdk.Context, tokenPair *dex.TokenPair) error
	UpdateTokenPair(ctx sdk.Context, product string, tokenPair *dex.TokenPair)
	CheckTokenPairUnderDexDelist(ctx sdk.Context, product string) (isDelisting bool, err error)
	LockTokenPair(ctx sdk.Context, product string, lock *types.ProductLock)
	UnlockTokenPair(ctx sdk.Context, product string)
	IsTokenPairLocked(ctx sdk.Context, product string) bool
	GetLockedProductsCopy(ctx sdk.Context) *types.ProductLockMap
	IsAnyProductLocked(ctx sdk.Context) bool
	GetOperator(ctx sdk.Context, addr sdk.AccAddress) (operator dex.DEXOperator, isExist bool)
}

DexKeeper : expected dex keeper

type DiskCache

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

DiskCache stores cache that will persist to disk at endBlock.

func (*DiskCache) DecreaseStoreOrderNum

func (c *DiskCache) DecreaseStoreOrderNum(num int64) int64

nolint

func (*DiskCache) GetClosedOrderIDs

func (c *DiskCache) GetClosedOrderIDs() []string

nolint

func (*DiskCache) GetNewDepthbookKeys

func (c *DiskCache) GetNewDepthbookKeys() []string

GetNewDepthbookKeys returns a new copy of NewDepthbookKeys

func (*DiskCache) GetOrderIDsMapCopy

func (c *DiskCache) GetOrderIDsMapCopy() *OrderIDsMap

GetOrderIDsMapCopy returns a new copy of OrderIDsMap

func (*DiskCache) GetUpdatedDepthbookKeys

func (c *DiskCache) GetUpdatedDepthbookKeys() []string

GetUpdatedDepthbookKeys returns a new copy of UpdatedDepthbookKeys

func (*DiskCache) GetUpdatedOrderIDKeys

func (c *DiskCache) GetUpdatedOrderIDKeys() []string

UpdatedOrderIDKeys nolint

type GetFeeKeeper

type GetFeeKeeper interface {
	GetLastPrice(ctx sdk.Context, product string) sdk.Dec
}

GetFeeKeeper is an interface for calculating handling fees

type Keeper

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

Keeper maintains the link to data storage and exposes getter/setter methods for the various parts of the state machine

func NewKeeper

func NewKeeper(tokenKeeper TokenKeeper, supplyKeeper SupplyKeeper, dexKeeper DexKeeper,
	paramSpace params.Subspace, feeCollectorName string, ordersStoreKey sdk.StoreKey,
	cdc *codec.Codec,
	enableBackend bool, metrics *monitor.OrderMetric) Keeper

NewKeeper creates new instances of the nameservice Keeper

func (Keeper) AddCollectedFees

func (k Keeper) AddCollectedFees(ctx sdk.Context, coins sdk.SysCoins, from sdk.AccAddress,
	feeType string, hasFeeDetail bool) error

AddCollectedFees adds fee to the feePool

func (Keeper) AddFeeDetail

func (k Keeper) AddFeeDetail(ctx sdk.Context, from sdk.AccAddress, coins sdk.SysCoins,
	feeType string)

AddFeeDetail adds detail message of fee to tokenKeeper

func (Keeper) AddTxHandlerMsgResult

func (k Keeper) AddTxHandlerMsgResult(resultSet bitset.BitSet)

nolint

func (Keeper) AnyProductLocked

func (k Keeper) AnyProductLocked(ctx sdk.Context) bool

nolint

func (Keeper) BalanceAccount

func (k Keeper) BalanceAccount(ctx sdk.Context, addr sdk.AccAddress,
	outputCoins sdk.SysCoins, inputCoins sdk.SysCoins)

BalanceAccount burns the specified coin and obtains another coin

func (Keeper) Cache2Disk

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

Cache2Disk flushes cached data into KVStore, called in EndBlock

func (Keeper) CancelOrder

func (k Keeper) CancelOrder(ctx sdk.Context, order *types.Order, logger log.Logger) sdk.SysCoins

CancelOrder quits the specified order with the canceled state

func (Keeper) DropBlockOrderNum

func (k Keeper) DropBlockOrderNum(ctx sdk.Context, blockHeight int64)

DropBlockOrderNum deletes OrderNum from keeper

func (Keeper) DropExpireBlockHeight

func (k Keeper) DropExpireBlockHeight(ctx sdk.Context, blockHeight int64)

DropExpireBlockHeight deletes ExpireBlockHeight from keeper

func (Keeper) DropExpiredOrdersByBlockHeight

func (k Keeper) DropExpiredOrdersByBlockHeight(ctx sdk.Context, expiredBlockHeight int64)

func (Keeper) DropOrder

func (k Keeper) DropOrder(ctx sdk.Context, orderID string)

nolint

func (Keeper) DumpStore

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

DumpStore dumps all key-value message from KVStore

func (Keeper) ExpireOrder

func (k Keeper) ExpireOrder(ctx sdk.Context, order *types.Order, logger log.Logger)

ExpireOrder quits the specified order with the expired state

func (Keeper) FilterDelistedProducts

func (k Keeper) FilterDelistedProducts(ctx sdk.Context, products []string) []string

FilterDelistedProducts deletes non-existent products from the specified products

func (Keeper) GetBestBidAndAsk

func (k Keeper) GetBestBidAndAsk(ctx sdk.Context, product string) (sdk.Dec, sdk.Dec)

GetBestBidAndAsk gets the highest bidPrice and the lowest askPrice from depthBook

func (Keeper) GetBlockMatchResult

func (k Keeper) GetBlockMatchResult() *types.BlockMatchResult

nolint

func (Keeper) GetBlockOrderNum

func (k Keeper) GetBlockOrderNum(ctx sdk.Context, blockHeight int64) int64

GetBlockOrderNum gets the num of orders in specific block

func (Keeper) GetCache

func (k Keeper) GetCache() *Cache

GetCache returns the memoryCache

func (Keeper) GetCoins

func (k Keeper) GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.SysCoins

nolint

func (Keeper) GetDepthBookCopy

func (k Keeper) GetDepthBookCopy(product string) *types.DepthBook

GetDepthBookCopy gets depth book copy from cache, you are supposed to update the Depthbook if you change it create if not exist

func (Keeper) GetDepthBookFromDB

func (k Keeper) GetDepthBookFromDB(ctx sdk.Context, product string) *types.DepthBook

GetDepthBookFromDB gets depthBook from KVStore

func (Keeper) GetDexKeeper

func (k Keeper) GetDexKeeper() DexKeeper

nolint

func (Keeper) GetDiskCache

func (k Keeper) GetDiskCache() *DiskCache

GetDiskCache returns the diskCache

func (Keeper) GetExpireBlockHeight

func (k Keeper) GetExpireBlockHeight(ctx sdk.Context, blockHeight int64) []int64

GetExpireBlockHeight gets a slice of ExpireBlockHeight from KVStore

func (Keeper) GetLastClosedOrderIDs

func (k Keeper) GetLastClosedOrderIDs(ctx sdk.Context) []string

GetLastClosedOrderIDs gets closed order ids in last block

func (Keeper) GetLastExpiredBlockHeight

func (k Keeper) GetLastExpiredBlockHeight(ctx sdk.Context) int64

GetLastExpiredBlockHeight gets LastExpiredBlockHeight from KVStore LastExpiredBlockHeight means that the block height of his expired height list has been processed by expired recently

func (Keeper) GetLastPrice

func (k Keeper) GetLastPrice(ctx sdk.Context, product string) sdk.Dec

nolint

func (Keeper) GetMetric

func (k Keeper) GetMetric() *monitor.OrderMetric

nolint

func (Keeper) GetOpenOrderNum

func (k Keeper) GetOpenOrderNum(ctx sdk.Context) int64

GetOpenOrderNum gets OpenOrderNum from KVStore OpenOrderNum means the number of orders currently in the open state

func (Keeper) GetOperationMetric

func (k Keeper) GetOperationMetric() OrderOperationMetric

GetOperationMetric gets OperationMetric from keeper

func (Keeper) GetOrder

func (k Keeper) GetOrder(ctx sdk.Context, orderID string) *types.Order

GetOrder gets order from KVStore

func (Keeper) GetParams

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

GetParams gets inflation params from the global param store

func (Keeper) GetProductFeeReceiver

func (k Keeper) GetProductFeeReceiver(ctx sdk.Context, product string) (sdk.AccAddress, error)

GetProductFeeReceiver gets the fee receiver of specified product from dexKeeper

func (Keeper) GetProductPriceOrderIDs

func (k Keeper) GetProductPriceOrderIDs(key string) []string

GetProductPriceOrderIDs gets OrderIDs from diskCache

func (Keeper) GetProductPriceOrderIDsFromDB

func (k Keeper) GetProductPriceOrderIDsFromDB(ctx sdk.Context, key string) []string

GetProductPriceOrderIDsFromDB gets OrderIDs from KVStore

func (Keeper) GetProductsFromDepthBookMap

func (k Keeper) GetProductsFromDepthBookMap() []string

GetProductsFromDepthBookMap gets products from DepthBookMap in diskCache

func (Keeper) GetStoreOrderNum

func (k Keeper) GetStoreOrderNum(ctx sdk.Context) int64

StoreOrderNum means the number of orders currently stored nolint

func (Keeper) GetTokenKeeper

func (k Keeper) GetTokenKeeper() TokenKeeper

nolint

func (Keeper) GetTxHandlerMsgResult

func (k Keeper) GetTxHandlerMsgResult() []bitset.BitSet

GetTxHandlerMsgResult: be careful, only call by backend module, other module should never use it!

func (Keeper) GetUpdatedDepthbookKeys

func (k Keeper) GetUpdatedDepthbookKeys() []string

GetUpdatedDepthbookKeys gets UpdatedDepthbookKeys from diskCache

func (Keeper) GetUpdatedOrderIDs

func (k Keeper) GetUpdatedOrderIDs() []string

GetUpdatedOrderIDs gets UpdatedOrderIDs from memoryCache

func (Keeper) InsertOrderIntoDepthBook

func (k Keeper) InsertOrderIntoDepthBook(order *types.Order)

nolint

func (Keeper) IsProductLocked

func (k Keeper) IsProductLocked(ctx sdk.Context, product string) bool

nolint

func (Keeper) LockCoins

func (k Keeper) LockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.SysCoins, lockCoinsType int) error

LockCoins locks coins from the specified address,

func (Keeper) PlaceOrder

func (k Keeper) PlaceOrder(ctx sdk.Context, order *types.Order) error

PlaceOrder updates BlockOrderNum, DepthBook, execute TryPlaceOrder, and set the specified order to keeper

func (Keeper) RemoveOrderFromDepthBook

func (k Keeper) RemoveOrderFromDepthBook(order *types.Order, feeType string)

RemoveOrderFromDepthBook removes order from depthBook, and updates cancelNum, expireNum, updatedOrderIDs from cache

func (Keeper) ResetCache

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

ResetCache is called in BeginBlock

func (Keeper) SendFeesToProductOwner

func (k Keeper) SendFeesToProductOwner(ctx sdk.Context, coins sdk.SysCoins, from sdk.AccAddress,
	feeType string, product string) (feeReceiver string, err error)

SendFeesToProductOwner sends fees from the specified address to productOwner

func (Keeper) SetBlockMatchResult

func (k Keeper) SetBlockMatchResult(result *types.BlockMatchResult)

nolint

func (Keeper) SetBlockOrderNum

func (k Keeper) SetBlockOrderNum(ctx sdk.Context, blockHeight int64, orderNum int64)

SetBlockOrderNum sets BlockOrderNum to keeper BlockOrderNum means OrderNum at a given BlockHeight

func (Keeper) SetDepthBook

func (k Keeper) SetDepthBook(product string, book *types.DepthBook)

SetDepthBook updates depthBook in diskCache

func (Keeper) SetExpireBlockHeight

func (k Keeper) SetExpireBlockHeight(ctx sdk.Context, blockHeight int64, expireBlockHeight []int64)

SetExpireBlockHeight sets ExpireBlockHeight to keeper ExpireBlockHeight means a slice of expired height that need to be solved

func (Keeper) SetLastClosedOrderIDs

func (k Keeper) SetLastClosedOrderIDs(ctx sdk.Context, orderIDs []string)

SetLastClosedOrderIDs sets closed order ids in this block

func (Keeper) SetLastExpiredBlockHeight

func (k Keeper) SetLastExpiredBlockHeight(ctx sdk.Context, expiredBlockHeight int64)

=============================================== LastExpiredBlockHeight means that the block height of his expired height list has been processed by expired recently nolint

func (Keeper) SetLastPrice

func (k Keeper) SetLastPrice(ctx sdk.Context, product string, price sdk.Dec)

=============================================== LastPrice means the latest transaction price of a given Product nolint

func (Keeper) SetMetric

func (k Keeper) SetMetric()

nolint

func (Keeper) SetOrder

func (k Keeper) SetOrder(ctx sdk.Context, orderID string, order *types.Order)

=============================================== nolint

func (Keeper) SetOrderIDs

func (k Keeper) SetOrderIDs(key string, orderIDs []string)

SetOrderIDs sets OrderIDs to diskCache

func (Keeper) SetParams

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

SetParams sets inflation params from the global param store

func (Keeper) SetProductLock

func (k Keeper) SetProductLock(ctx sdk.Context, product string, lock *types.ProductLock)

nolint

func (Keeper) StoreDepthBook

func (k Keeper) StoreDepthBook(ctx sdk.Context, product string, depthBook *types.DepthBook)

=============================================== nolint

func (Keeper) StoreOrderIDsMap

func (k Keeper) StoreOrderIDsMap(ctx sdk.Context, key string, orderIDs []string)

=============================================== nolint

func (Keeper) TryPlaceOrder

func (k Keeper) TryPlaceOrder(ctx sdk.Context, order *types.Order) (fee sdk.SysCoins, err error)

TryPlaceOrder tries to charge fee & lock coins for a new order

func (Keeper) UnlockCoins

func (k Keeper) UnlockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.SysCoins, lockCoinsType int)

nolint

func (Keeper) UnlockProduct

func (k Keeper) UnlockProduct(ctx sdk.Context, product string)

nolint

func (Keeper) UpdateOrder

func (k Keeper) UpdateOrder(order *types.Order, ctx sdk.Context)

nolint

type OrderIDsMap

type OrderIDsMap struct {
	Data map[string][]string
	// contains filtered or unexported fields
}

OrderIDsMap stores orderIDSlice with map. <product:price:side> -> <orderIDs>

type OrderOperationMetric

type OrderOperationMetric struct {
	FullFillNum    int64
	OpenNum        int64
	CancelNum      int64
	ExpireNum      int64
	PartialFillNum int64
}

OrderOperationMetric records the order information in the depthBook

type QueryDepthBookParams

type QueryDepthBookParams struct {
	Product string
	Size    uint
}

QueryDepthBookParams as input parameters when querying the depthBook

func NewQueryDepthBookParams

func NewQueryDepthBookParams(product string, size uint) QueryDepthBookParams

NewQueryDepthBookParams creates a new instance of QueryProposalParams

type StoreStatistic

type StoreStatistic struct {
	StoreOrderNum   int64
	DepthBookNum    map[string]int64
	BookOrderIDsNum map[string]int64
}

StoreStatistic is used to store the state of depthBook

type SupplyKeeper

type SupplyKeeper interface {
	SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string,
		amt sdk.Coins) sdk.Error
	SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress,
		amt sdk.Coins) sdk.Error
	GetModuleAccount(ctx sdk.Context, moduleName string) exported.ModuleAccountI
	GetModuleAddress(moduleName string) sdk.AccAddress
	MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) sdk.Error
}

SupplyKeeper : expected supply keeper

type TestInput

type TestInput struct {
	Ctx       sdk.Context
	Cdc       *codec.Codec
	TestAddrs []sdk.AccAddress

	OrderKeeper   Keeper
	TokenKeeper   token.Keeper
	AccountKeeper auth.AccountKeeper
	SupplyKeeper  supply.Keeper
	DexKeeper     dex.Keeper
}

TestInput stores some variables for testing

func CreateTestInput

func CreateTestInput(t *testing.T) TestInput

CreateTestInput creates TestInput with default params

func CreateTestInputWithBalance

func CreateTestInputWithBalance(t *testing.T, numAddrs, initQuantity int64) TestInput

CreateTestInputWithBalance creates TestInput with the number of account and the quantity

type TokenKeeper

type TokenKeeper interface {
	// Token balance
	GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.SysCoins
	LockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.SysCoins, lockCoinsType int) error
	UnlockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.SysCoins, lockCoinsType int) error
	BalanceAccount(ctx sdk.Context, addr sdk.AccAddress, outputCoins sdk.SysCoins, inputCoins sdk.SysCoins) error
	SendCoinsFromAccountToAccount(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.SysCoins) error
	// Fee detail
	AddFeeDetail(ctx sdk.Context, from string, fee sdk.SysCoins, feeType string, receiver string)
	GetAllLockedCoins(ctx sdk.Context) (locks []token.AccCoins)
	IterateLockedFees(ctx sdk.Context, cb func(acc sdk.AccAddress, coins sdk.SysCoins) (stop bool))
}

TokenKeeper : expected token keeper

Jump to

Keyboard shortcuts

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