Documentation ¶
Index ¶
- Constants
- func GetDealFee(order *types.Order, fillAmt sdk.Dec, ctx sdk.Context, keeper GetFeeKeeper, ...) sdk.DecCoins
- func GetOrderCostFee(order *types.Order, ctx sdk.Context) sdk.DecCoins
- func GetOrderNewFee(order *types.Order) sdk.DecCoins
- func GetZeroFee() sdk.DecCoins
- func MakeTestCodec() *codec.Codec
- func ModuleAccountInvariant(keeper Keeper) sdk.Invariant
- func NewQuerier(keeper Keeper) sdk.Querier
- func RegisterInvariants(ir sdk.InvariantRegistry, keeper Keeper)
- type BookRes
- type BookResItem
- type Cache
- func (c *Cache) DecreaseCancelNum() int64
- func (c *Cache) DecreaseFullFillNum() int64
- func (c *Cache) DecreasePartialFillNum() int64
- func (c *Cache) GetCancelNum() int64
- func (c *Cache) GetExpireNum() int64
- func (c *Cache) GetFullFillNum() int64
- func (c *Cache) GetParams() *types.Params
- func (c *Cache) GetPartialFillNum() int64
- func (c *Cache) IncreaseCancelNum() int64
- func (c *Cache) IncreaseExpireNum() int64
- func (c *Cache) IncreaseFullFillNum() int64
- func (c *Cache) IncreasePartialFillNum() int64
- func (c *Cache) SetParams(params *types.Params)
- type DepthBookMap
- type DexKeeper
- type DiskCache
- func (c *DiskCache) DecreaseStoreOrderNum(num int64) int64
- func (c *DiskCache) GetClosedOrderIDs() []string
- func (c *DiskCache) GetNewDepthbookKeys() []string
- func (c *DiskCache) GetOrderIDsMapCopy() *OrderIDsMap
- func (c *DiskCache) GetUpdatedDepthbookKeys() []string
- func (c *DiskCache) GetUpdatedOrderIDKeys() []string
- type GetFeeKeeper
- type Keeper
- func (k Keeper) AddCollectedFees(ctx sdk.Context, coins sdk.DecCoins, from sdk.AccAddress, feeType string, ...) error
- func (k Keeper) AddFeeDetail(ctx sdk.Context, from sdk.AccAddress, coins sdk.DecCoins, feeType string)
- func (k Keeper) AddTxHandlerMsgResult(resultSet bitset.BitSet)
- func (k Keeper) AnyProductLocked(ctx sdk.Context) bool
- func (k Keeper) BalanceAccount(ctx sdk.Context, addr sdk.AccAddress, outputCoins sdk.DecCoins, ...)
- func (k Keeper) Cache2Disk(ctx sdk.Context)
- func (k Keeper) CancelOrder(ctx sdk.Context, order *types.Order, logger log.Logger) sdk.DecCoins
- func (k Keeper) DropBlockOrderNum(ctx sdk.Context, blockHeight int64)
- func (k Keeper) DropExpireBlockHeight(ctx sdk.Context, blockHeight int64)
- func (k Keeper) DropExpiredOrdersByBlockHeight(ctx sdk.Context, expiredBlockHeight int64)
- func (k Keeper) DropOrder(ctx sdk.Context, orderID string)
- func (k Keeper) DumpStore(ctx sdk.Context)
- func (k Keeper) ExpireOrder(ctx sdk.Context, order *types.Order, logger log.Logger)
- func (k Keeper) FilterDelistedProducts(ctx sdk.Context, products []string) []string
- func (k Keeper) GetBestBidAndAsk(ctx sdk.Context, product string) (sdk.Dec, sdk.Dec)
- func (k Keeper) GetBlockMatchResult() *types.BlockMatchResult
- func (k Keeper) GetBlockOrderNum(ctx sdk.Context, blockHeight int64) int64
- func (k Keeper) GetCache() *Cache
- func (k Keeper) GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.DecCoins
- func (k Keeper) GetDepthBookCopy(product string) *types.DepthBook
- func (k Keeper) GetDepthBookFromDB(ctx sdk.Context, product string) *types.DepthBook
- func (k Keeper) GetDexKeeper() DexKeeper
- func (k Keeper) GetDiskCache() *DiskCache
- func (k Keeper) GetExpireBlockHeight(ctx sdk.Context, blockHeight int64) []int64
- func (k Keeper) GetLastClosedOrderIDs(ctx sdk.Context) []string
- func (k Keeper) GetLastExpiredBlockHeight(ctx sdk.Context) int64
- func (k Keeper) GetLastPrice(ctx sdk.Context, product string) sdk.Dec
- func (k Keeper) GetMetric() *monitor.OrderMetric
- func (k Keeper) GetOpenOrderNum(ctx sdk.Context) int64
- func (k Keeper) GetOperationMetric() OrderOperationMetric
- func (k Keeper) GetOrder(ctx sdk.Context, orderID string) *types.Order
- func (k Keeper) GetParams(ctx sdk.Context) *types.Params
- func (k Keeper) GetProductFeeReceiver(ctx sdk.Context, product string) (sdk.AccAddress, error)
- func (k Keeper) GetProductPriceOrderIDs(key string) []string
- func (k Keeper) GetProductPriceOrderIDsFromDB(ctx sdk.Context, key string) []string
- func (k Keeper) GetProductsFromDepthBookMap() []string
- func (k Keeper) GetStoreOrderNum(ctx sdk.Context) int64
- func (k Keeper) GetTokenKeeper() TokenKeeper
- func (k Keeper) GetTxHandlerMsgResult() []bitset.BitSet
- func (k Keeper) GetUpdatedDepthbookKeys() []string
- func (k Keeper) GetUpdatedOrderIDs() []string
- func (k Keeper) InsertOrderIntoDepthBook(order *types.Order)
- func (k Keeper) IsProductLocked(ctx sdk.Context, product string) bool
- func (k Keeper) LockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.DecCoins, lockCoinsType int) error
- func (k Keeper) PlaceOrder(ctx sdk.Context, order *types.Order) error
- func (k Keeper) RemoveOrderFromDepthBook(order *types.Order, feeType string)
- func (k Keeper) ResetCache(ctx sdk.Context)
- func (k Keeper) SendFeesToProductOwner(ctx sdk.Context, coins sdk.DecCoins, from sdk.AccAddress, feeType string, ...) (feeReceiver string, err error)
- func (k Keeper) SetBlockMatchResult(result *types.BlockMatchResult)
- func (k Keeper) SetBlockOrderNum(ctx sdk.Context, blockHeight int64, orderNum int64)
- func (k Keeper) SetDepthBook(product string, book *types.DepthBook)
- func (k Keeper) SetExpireBlockHeight(ctx sdk.Context, blockHeight int64, expireBlockHeight []int64)
- func (k Keeper) SetLastClosedOrderIDs(ctx sdk.Context, orderIDs []string)
- func (k Keeper) SetLastExpiredBlockHeight(ctx sdk.Context, expiredBlockHeight int64)
- func (k Keeper) SetLastPrice(ctx sdk.Context, product string, price sdk.Dec)
- func (k Keeper) SetMetric()
- func (k Keeper) SetOrder(ctx sdk.Context, orderID string, order *types.Order)
- func (k Keeper) SetOrderIDs(key string, orderIDs []string)
- func (k Keeper) SetParams(ctx sdk.Context, params *types.Params)
- func (k Keeper) SetProductLock(ctx sdk.Context, product string, lock *types.ProductLock)
- func (k Keeper) StoreDepthBook(ctx sdk.Context, product string, depthBook *types.DepthBook)
- func (k Keeper) StoreOrderIDsMap(ctx sdk.Context, key string, orderIDs []string)
- func (k Keeper) TryPlaceOrder(ctx sdk.Context, order *types.Order) (fee sdk.DecCoins, err error)
- func (k Keeper) UnlockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.DecCoins, lockCoinsType int)
- func (k Keeper) UnlockProduct(ctx sdk.Context, product string)
- func (k Keeper) UpdateOrder(order *types.Order, ctx sdk.Context)
- type OrderIDsMap
- type OrderOperationMetric
- type QueryDepthBookParams
- type StoreStatistic
- type SupplyKeeper
- type TestInput
- type TokenKeeper
Constants ¶
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.DecCoins
GetDealFee is used to calculate the handling fee when matching an order
func GetOrderCostFee ¶
GetOrderCostFee is used to calculate the handling fee when quiting an order
func GetOrderNewFee ¶
GetOrderNewFee is used to calculate the handling fee that needs to be locked when placing an order
func MakeTestCodec ¶
MakeTestCodec creates a codec used only for testing
func ModuleAccountInvariant ¶
ModuleAccountInvariant checks that the module account coins reflects the sum of locks amounts held on store
func NewQuerier ¶
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 ¶
nolint
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores some caches that will not be written to disk
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 ¶
nolint
func (*DiskCache) GetNewDepthbookKeys ¶
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 ¶
GetUpdatedDepthbookKeys returns a new copy of UpdatedDepthbookKeys
func (*DiskCache) GetUpdatedOrderIDKeys ¶
UpdatedOrderIDKeys nolint
type GetFeeKeeper ¶
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.DecCoins, 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.DecCoins, feeType string)
AddFeeDetail adds detail message of fee to tokenKeeper
func (Keeper) AddTxHandlerMsgResult ¶
nolint
func (Keeper) BalanceAccount ¶
func (k Keeper) BalanceAccount(ctx sdk.Context, addr sdk.AccAddress, outputCoins sdk.DecCoins, inputCoins sdk.DecCoins)
BalanceAccount burns the specified coin and obtains another coin
func (Keeper) Cache2Disk ¶
Cache2Disk flushes cached data into KVStore, called in EndBlock
func (Keeper) CancelOrder ¶
CancelOrder quits the specified order with the canceled state
func (Keeper) DropBlockOrderNum ¶
DropBlockOrderNum deletes OrderNum from keeper
func (Keeper) DropExpireBlockHeight ¶
DropExpireBlockHeight deletes ExpireBlockHeight from keeper
func (Keeper) DropExpiredOrdersByBlockHeight ¶
func (Keeper) ExpireOrder ¶
ExpireOrder quits the specified order with the expired state
func (Keeper) FilterDelistedProducts ¶
FilterDelistedProducts deletes non-existent products from the specified products
func (Keeper) GetBestBidAndAsk ¶
GetBestBidAndAsk gets the highest bidPrice and the lowest askPrice from depthBook
func (Keeper) GetBlockMatchResult ¶
func (k Keeper) GetBlockMatchResult() *types.BlockMatchResult
nolint
func (Keeper) GetBlockOrderNum ¶
GetBlockOrderNum gets the num of orders in specific block
func (Keeper) GetDepthBookCopy ¶
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 ¶
GetDepthBookFromDB gets depthBook from KVStore
func (Keeper) GetDiskCache ¶
GetDiskCache returns the diskCache
func (Keeper) GetExpireBlockHeight ¶
GetExpireBlockHeight gets a slice of ExpireBlockHeight from KVStore
func (Keeper) GetLastClosedOrderIDs ¶
GetLastClosedOrderIDs gets closed order ids in last block
func (Keeper) GetLastExpiredBlockHeight ¶
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 ¶
nolint
func (Keeper) GetOpenOrderNum ¶
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) GetProductFeeReceiver ¶
GetProductFeeReceiver gets the fee receiver of specified product from dexKeeper
func (Keeper) GetProductPriceOrderIDs ¶
GetProductPriceOrderIDs gets OrderIDs from diskCache
func (Keeper) GetProductPriceOrderIDsFromDB ¶
GetProductPriceOrderIDsFromDB gets OrderIDs from KVStore
func (Keeper) GetProductsFromDepthBookMap ¶
GetProductsFromDepthBookMap gets products from DepthBookMap in diskCache
func (Keeper) GetStoreOrderNum ¶
StoreOrderNum means the number of orders currently stored nolint
func (Keeper) GetTxHandlerMsgResult ¶
GetTxHandlerMsgResult: be careful, only call by backend module, other module should never use it!
func (Keeper) GetUpdatedDepthbookKeys ¶
GetUpdatedDepthbookKeys gets UpdatedDepthbookKeys from diskCache
func (Keeper) GetUpdatedOrderIDs ¶
GetUpdatedOrderIDs gets UpdatedOrderIDs from memoryCache
func (Keeper) InsertOrderIntoDepthBook ¶
nolint
func (Keeper) IsProductLocked ¶
nolint
func (Keeper) LockCoins ¶
func (k Keeper) LockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.DecCoins, lockCoinsType int) error
LockCoins locks coins from the specified address,
func (Keeper) PlaceOrder ¶
PlaceOrder updates BlockOrderNum, DepthBook, execute TryPlaceOrder, and set the specified order to keeper
func (Keeper) RemoveOrderFromDepthBook ¶
RemoveOrderFromDepthBook removes order from depthBook, and updates cancelNum, expireNum, updatedOrderIDs from cache
func (Keeper) ResetCache ¶
ResetCache is called in BeginBlock
func (Keeper) SendFeesToProductOwner ¶
func (k Keeper) SendFeesToProductOwner(ctx sdk.Context, coins sdk.DecCoins, 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 ¶
SetBlockOrderNum sets BlockOrderNum to keeper BlockOrderNum means OrderNum at a given BlockHeight
func (Keeper) SetDepthBook ¶
SetDepthBook updates depthBook in diskCache
func (Keeper) SetExpireBlockHeight ¶
SetExpireBlockHeight sets ExpireBlockHeight to keeper ExpireBlockHeight means a slice of expired height that need to be solved
func (Keeper) SetLastClosedOrderIDs ¶
SetLastClosedOrderIDs sets closed order ids in this block
func (Keeper) SetLastExpiredBlockHeight ¶
=============================================== LastExpiredBlockHeight means that the block height of his expired height list has been processed by expired recently nolint
func (Keeper) SetLastPrice ¶
=============================================== LastPrice means the latest transaction price of a given Product nolint
func (Keeper) SetOrderIDs ¶
SetOrderIDs sets OrderIDs to diskCache
func (Keeper) SetProductLock ¶
nolint
func (Keeper) StoreDepthBook ¶
=============================================== nolint
func (Keeper) StoreOrderIDsMap ¶
=============================================== nolint
func (Keeper) TryPlaceOrder ¶
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.DecCoins, lockCoinsType int)
nolint
type OrderIDsMap ¶
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 ¶
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 ¶
CreateTestInput creates TestInput with default params
type TokenKeeper ¶
type TokenKeeper interface { // Token balance GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.DecCoins LockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.DecCoins, lockCoinsType int) error UnlockCoins(ctx sdk.Context, addr sdk.AccAddress, coins sdk.DecCoins, lockCoinsType int) error BalanceAccount(ctx sdk.Context, addr sdk.AccAddress, outputCoins sdk.DecCoins, inputCoins sdk.DecCoins) error SendCoinsFromAccountToAccount(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.DecCoins) error // Fee detail AddFeeDetail(ctx sdk.Context, from string, fee sdk.DecCoins, feeType string, receiver string) GetAllLockedCoins(ctx sdk.Context) (locks []token.AccCoins) IterateLockedFees(ctx sdk.Context, cb func(acc sdk.AccAddress, coins sdk.DecCoins) (stop bool)) }
TokenKeeper : expected token keeper