Documentation ¶
Index ¶
- Constants
- func CheckValidityOrderBook(orderBook OrderBook, currentPrice sdk.Dec) bool
- func ClearOrders(XtoY, YtoX []types.BatchPoolSwapMsg) ([]types.BatchPoolSwapMsg, []types.BatchPoolSwapMsg)
- func GetExecutableAmt(swapPrice sdk.Dec, orderBook OrderBook) (executableBuyAmtX, executableSellAmtY sdk.Int)
- func GetPriceDirection(currentPrice sdk.Dec, orderBook OrderBook) int
- func MaxDec(a, b sdk.Dec) sdk.Dec
- func MinDec(a, b sdk.Dec) sdk.Dec
- func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier
- type BatchResult
- func CalculateMatch(direction int, X, Y, currentPrice sdk.Dec, orderBook OrderBook) (result BatchResult)
- func CalculateMatchStay(currentPrice sdk.Dec, orderBook OrderBook) (r BatchResult)
- func CalculateSwap(direction int, X, Y, orderPrice, lastOrderPrice sdk.Dec, orderBook OrderBook) (r BatchResult)
- func CompareTransactAmtX(X, Y, currentPrice sdk.Dec, orderBook OrderBook) (result BatchResult)
- func NewBatchResult() BatchResult
- type Keeper
- func (k Keeper) CreateLiquidityPool(ctx sdk.Context, msg *types.MsgCreateLiquidityPool) error
- func (k Keeper) DeleteAndInitPoolBatch(ctx sdk.Context)
- func (k Keeper) DeleteLiquidityPoolBatch(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch)
- func (k Keeper) DepositLiquidityPool(ctx sdk.Context, msg *types.MsgDepositToLiquidityPool) error
- func (k Keeper) DepositLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgDepositToLiquidityPool) error
- func (k Keeper) ExecutePoolBatch(ctx sdk.Context)
- func (k Keeper) GetAllLiquidityPoolBatchDepositMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch) (msgs []types.BatchPoolDepositMsg)
- func (k Keeper) GetAllLiquidityPoolBatchSwapMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch) (msgs []types.BatchPoolSwapMsg)
- func (k Keeper) GetAllLiquidityPoolBatchWithdrawMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch) (msgs []types.BatchPoolWithdrawMsg)
- func (k Keeper) GetAllLiquidityPoolBatches(ctx sdk.Context) (liquidityPoolBatches []types.LiquidityPoolBatch)
- func (k Keeper) GetAllLiquidityPools(ctx sdk.Context) (liquidityPools []types.LiquidityPool)
- func (k Keeper) GetLiquidityPool(ctx sdk.Context, poolID uint64) (liquidityPool types.LiquidityPool, found bool)
- func (k Keeper) GetLiquidityPoolBatch(ctx sdk.Context, poolID, batchIndex uint64) (liquidityPoolBatch types.LiquidityPoolBatch, found bool)
- func (k Keeper) GetLiquidityPoolBatchIndex(ctx sdk.Context, poolID uint64) (liquidityPoolBatchIndex uint64)
- func (k Keeper) GetLiquidityPoolByReserveAccIndex(ctx sdk.Context, reserveAcc sdk.AccAddress) (liquidityPool types.LiquidityPool, found bool)
- func (k Keeper) GetNextBatchIndexWithUpdate(ctx sdk.Context, poolID uint64) (batchIndex uint64)
- func (k Keeper) GetNextLiquidityPoolIDWithUpdate(ctx sdk.Context) uint64
- func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)
- func (k Keeper) GetPoolCoinTotalSupply(ctx sdk.Context, lp types.LiquidityPool) sdk.Int
- func (k Keeper) GetReserveCoins(ctx sdk.Context, lp types.LiquidityPool) (reserveCoins sdk.Coins)
- func (k Keeper) IterateAllLiquidityPoolBatchDepositMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, ...)
- func (k Keeper) IterateAllLiquidityPoolBatchSwapMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, ...)
- func (k Keeper) IterateAllLiquidityPoolBatchWithdrawMsgs(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, ...)
- func (k Keeper) IterateAllLiquidityPoolBatches(ctx sdk.Context, ...)
- func (k Keeper) IterateAllLiquidityPools(ctx sdk.Context, cb func(liquidityPool types.LiquidityPool) (stop bool))
- func (k Keeper) LiquidityPool(c context.Context, req *types.QueryLiquidityPoolRequest) (*types.QueryLiquidityPoolResponse, error)
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) SetLiquidityPool(ctx sdk.Context, liquidityPool types.LiquidityPool)
- func (k Keeper) SetLiquidityPoolAtomic(ctx sdk.Context, liquidityPool types.LiquidityPool)
- func (k Keeper) SetLiquidityPoolBatch(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch)
- func (k Keeper) SetLiquidityPoolBatchDepositMsg(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, msgIndex uint64, ...)
- func (k Keeper) SetLiquidityPoolBatchIndex(ctx sdk.Context, poolID, batchIndex uint64)
- func (k Keeper) SetLiquidityPoolBatchSwapMsg(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, msgIndex uint64, ...)
- func (k Keeper) SetLiquidityPoolBatchWithdrawMsg(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch, msgIndex uint64, ...)
- func (k Keeper) SetLiquidityPoolByReserveAccIndex(ctx sdk.Context, liquidityPool types.LiquidityPool)
- func (k Keeper) SetParams(ctx sdk.Context, params types.Params)
- func (k Keeper) SwapExecution(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch) error
- func (k Keeper) SwapLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgSwap) error
- func (k Keeper) WithdrawLiquidityPool(ctx sdk.Context, msg *types.MsgWithdrawFromLiquidityPool) error
- func (k Keeper) WithdrawLiquidityPoolToBatch(ctx sdk.Context, msg *types.MsgWithdrawFromLiquidityPool) error
- type MatchResult
- type OrderBook
- type OrderByPrice
- type OrderMap
Constants ¶
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 ClearOrders ¶
func ClearOrders(XtoY, YtoX []types.BatchPoolSwapMsg) ([]types.BatchPoolSwapMsg, []types.BatchPoolSwapMsg)
func GetExecutableAmt ¶
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 (Keeper) DeleteAndInitPoolBatch ¶
func (Keeper) DeleteLiquidityPoolBatch ¶
func (k Keeper) DeleteLiquidityPoolBatch(ctx sdk.Context, liquidityPoolBatch types.LiquidityPoolBatch)
func (Keeper) DepositLiquidityPool ¶
func (Keeper) DepositLiquidityPoolToBatch ¶
func (Keeper) ExecutePoolBatch ¶
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 (Keeper) GetNextLiquidityPoolIDWithUpdate ¶
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) GetPoolCoinTotalSupply ¶
func (Keeper) GetReserveCoins ¶
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) LiquidityPool ¶
func (k Keeper) LiquidityPool(c context.Context, req *types.QueryLiquidityPoolRequest) (*types.QueryLiquidityPoolResponse, error)
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 (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) SwapExecution ¶
func (Keeper) SwapLiquidityPoolToBatch ¶
TODO: need to fix, not added msgs
func (Keeper) WithdrawLiquidityPool ¶
func (Keeper) WithdrawLiquidityPoolToBatch ¶
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
type OrderByPrice ¶
type OrderMap ¶
type OrderMap map[sdk.Dec]OrderByPrice
func GetOrderMap ¶
func GetOrderMap(swapMsgs []types.BatchPoolSwapMsg, denomX, denomY string) (OrderMap, []types.BatchPoolSwapMsg, []types.BatchPoolSwapMsg)