keeper

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DenormalizeTickIndex added in v0.3.4

func DenormalizeTickIndex(takerDenom, token0 string, tickIndexNormalized int64) int64

func GetInOutTokens

func GetInOutTokens(tokenIn, tokenA, tokenB string) (_, tokenOut string)

func MustNewPool added in v0.3.4

func MustNewPool(pairID *types.PairID, normalizedCenterTickIndex int64, fee uint64) *types.Pool

Useful for testing

func NewLimitOrderExpiration

func NewLimitOrderExpiration(tranche *types.LimitOrderTranche) *types.LimitOrderExpiration

func NewLimitOrderTranche

func NewLimitOrderTranche(
	limitOrderTrancheKey *types.LimitOrderTrancheKey,
	goodTil *time.Time,
) (*types.LimitOrderTranche, error)

func NewMsgServerImpl

func NewMsgServerImpl(keeper Keeper) types.MsgServer

NewMsgServerImpl returns an implementation of the MsgServer interface for the provided Keeper.

func NewTrancheKey

func NewTrancheKey(sdkCtx sdk.Context) string

func NormalizeAllTickIndexes

func NormalizeAllTickIndexes(takerDenom, token0 string, tickIndexes []int64) []int64

func NormalizeTickIndex

func NormalizeTickIndex(takerDenom, token0 string, tickIndexTakerToMaker int64) int64

func SortAmounts

func SortAmounts(tokenA, token0 string, amountsA, amountsB []sdk.Int) ([]sdk.Int, []sdk.Int)

Types

type Keeper

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

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey,
	memKey storetypes.StoreKey,
	ps paramtypes.Subspace,

	bankKeeper types.BankKeeper,
) *Keeper

func (Keeper) BurnShares

func (k Keeper) BurnShares(
	ctx sdk.Context,
	addr sdk.AccAddress,
	amount sdk.Int,
	sharesID string,
) error

func (Keeper) CancelLimitOrderCore

func (k Keeper) CancelLimitOrderCore(
	goCtx context.Context,
	trancheKey string,
	callerAddr sdk.AccAddress,
) error

Handles MsgCancelLimitOrder, removing a specified number of shares from a limit order and returning the respective amount in terms of the reserve to the user.

func (Keeper) DepositCore

func (k Keeper) DepositCore(
	goCtx context.Context,
	pairID *types.PairID,
	callerAddr sdk.AccAddress,
	receiverAddr sdk.AccAddress,
	amounts0 []sdk.Int,
	amounts1 []sdk.Int,
	tickIndices []int64,
	fees []uint64,
	options []*types.DepositOptions,
) (amounts0Deposit, amounts1Deposit []sdk.Int, sharesIssued sdk.Coins, err error)

Handles core logic for MsgDeposit, checking and initializing data structures (tick, pair), calculating shares based on amount deposited, and sending funds to moduleAddress.

func (Keeper) EstimateMultiHopSwap added in v0.4.0

TODO: This doesn't run ValidateBasic() checks.

func (Keeper) EstimatePlaceLimitOrder added in v0.4.0

TODO: This doesn't run ValidateBasic() checks.

func (Keeper) FindLimitOrderTranche

func (k Keeper) FindLimitOrderTranche(
	ctx sdk.Context,
	limitOrderTrancheKey *types.LimitOrderTrancheKey,
) (val *types.LimitOrderTranche, fromFilled, found bool)

func (Keeper) GetAllDepositsForAddress added in v0.3.4

func (k Keeper) GetAllDepositsForAddress(ctx sdk.Context, addr sdk.AccAddress) []*types.DepositRecord

func (Keeper) GetAllInactiveLimitOrderTranche

func (k Keeper) GetAllInactiveLimitOrderTranche(ctx sdk.Context) (list []*types.LimitOrderTranche)

GetAllInactiveLimitOrderTranche returns all inactiveLimitOrderTranche

func (Keeper) GetAllLimitOrderExpiration

func (k Keeper) GetAllLimitOrderExpiration(ctx sdk.Context) (list []*types.LimitOrderExpiration)

GetAllLimitOrderExpiration returns all goodTilRecord

func (Keeper) GetAllLimitOrderTrancheAtIndex

func (k Keeper) GetAllLimitOrderTrancheAtIndex(
	sdkCtx sdk.Context,
	tradePairID *types.TradePairID,
	tickIndexTakerToMaker int64,
) (trancheList []types.LimitOrderTranche)

func (Keeper) GetAllLimitOrderTrancheUser

func (k Keeper) GetAllLimitOrderTrancheUser(ctx sdk.Context) (list []*types.LimitOrderTrancheUser)

GetAllLimitOrderTrancheUser returns all LimitOrderTrancheUser

func (Keeper) GetAllLimitOrderTrancheUserForAddress

func (k Keeper) GetAllLimitOrderTrancheUserForAddress(
	ctx sdk.Context,
	address sdk.AccAddress,
) (list []*types.LimitOrderTrancheUser)

func (Keeper) GetAllTickLiquidity

func (k Keeper) GetAllTickLiquidity(ctx sdk.Context) (list []*types.TickLiquidity)

GetAllTickLiquidity returns all tickLiquidity

func (Keeper) GetCurrLiq added in v0.3.4

func (k Keeper) GetCurrLiq(ctx sdk.Context, tradePairID *types.TradePairID) *types.TickLiquidity

func (Keeper) GetCurrPrice added in v0.3.4

func (k Keeper) GetCurrPrice(ctx sdk.Context, tradePairID *types.TradePairID) (sdk.Dec, bool)

func (Keeper) GetCurrTickIndexTakerToMaker added in v0.3.4

func (k Keeper) GetCurrTickIndexTakerToMaker(
	ctx sdk.Context,
	tradePairID *types.TradePairID,
) (int64, bool)

Returns a takerToMaker tick index

func (Keeper) GetCurrTickIndexTakerToMakerNormalized added in v0.3.4

func (k Keeper) GetCurrTickIndexTakerToMakerNormalized(
	ctx sdk.Context,
	tradePairID *types.TradePairID,
) (int64, bool)

Returns a takerToMaker tick index

func (Keeper) GetFillTranche

func (k Keeper) GetFillTranche(
	sdkCtx sdk.Context,
	tradePairID *types.TradePairID,
	tickIndexTakerToMaker int64,
) (*types.LimitOrderTranche, bool)

func (Keeper) GetInactiveLimitOrderTranche

func (k Keeper) GetInactiveLimitOrderTranche(
	ctx sdk.Context,
	limitOrderTrancheKey *types.LimitOrderTrancheKey,
) (val *types.LimitOrderTranche, found bool)

GetInactiveLimitOrderTranche returns a inactiveLimitOrderTranche from its index

func (Keeper) GetLimitOrderExpiration

func (k Keeper) GetLimitOrderExpiration(
	ctx sdk.Context,
	goodTilDate time.Time,
	trancheRef []byte,
) (val *types.LimitOrderExpiration, found bool)

GetLimitOrderExpiration returns a goodTilRecord from its index

func (Keeper) GetLimitOrderTranche

func (k Keeper) GetLimitOrderTranche(
	ctx sdk.Context,
	limitOrderTrancheKey *types.LimitOrderTrancheKey,
) (tranche *types.LimitOrderTranche)

func (Keeper) GetLimitOrderTrancheByKey

func (k Keeper) GetLimitOrderTrancheByKey(
	ctx sdk.Context,
	key []byte,
) (tranche *types.LimitOrderTranche, found bool)

func (Keeper) GetLimitOrderTrancheUser

func (k Keeper) GetLimitOrderTrancheUser(
	ctx sdk.Context,
	address string,
	trancheKey string,
) (val *types.LimitOrderTrancheUser, found bool)

GetLimitOrderTrancheUser returns a LimitOrderTrancheUser from its index

func (Keeper) GetOrInitLimitOrderTrancheUser

func (k Keeper) GetOrInitLimitOrderTrancheUser(
	ctx sdk.Context,
	tradePairID *types.TradePairID,
	tickIndex int64,
	trancheKey string,
	orderType types.LimitOrderType,
	receiver string,
) *types.LimitOrderTrancheUser

func (Keeper) GetOrInitPlaceTranche

func (k Keeper) GetOrInitPlaceTranche(ctx sdk.Context,
	tradePairID *types.TradePairID,
	tickIndexTakerToMaker int64,
	goodTil *time.Time,
	orderType types.LimitOrderType,
) (placeTranche *types.LimitOrderTranche, err error)

func (Keeper) GetOrInitPool

func (k Keeper) GetOrInitPool(
	ctx sdk.Context,
	pairID *types.PairID,
	centerTickIndexNormalized int64,
	fee uint64,
) (*types.Pool, error)

func (Keeper) GetParams

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

GetParams get all parameters as types.Params

func (Keeper) GetPlaceTranche

func (k Keeper) GetPlaceTranche(
	sdkCtx sdk.Context,
	tradePairID *types.TradePairID,
	tickIndexTakerToMaker int64,
) *types.LimitOrderTranche

func (Keeper) GetPool added in v0.4.0

func (k Keeper) GetPool(
	ctx sdk.Context,
	pairID *types.PairID,
	centerTickIndexNormalized int64,
	fee uint64,
) (*types.Pool, bool)

func (Keeper) GetPoolReserves

func (k Keeper) GetPoolReserves(
	ctx sdk.Context,
	poolReservesID *types.PoolReservesKey,
) (pool *types.PoolReserves, found bool)

func (Keeper) HopsToRouteData

func (k Keeper) HopsToRouteData(
	ctx sdk.Context,
	hops []string,
	exitLimitPrice sdk.Dec,
) ([]MultihopStep, error)

func (Keeper) LimitOrderTranche

Returns a specific limit order tranche either from the tickLiquidity index or from the FillLimitOrderTranche index

func (Keeper) LimitOrderTrancheAll

Returns all ACTIVE limit order tranches for a given pairID/tokenIn combination Does NOT return inactiveLimitOrderTranches

func (Keeper) Logger

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

func (Keeper) MintShares

func (k Keeper) MintShares(ctx sdk.Context, addr sdk.AccAddress, shareCoin sdk.Coin) error

func (Keeper) MultiHopSwapCore

func (k Keeper) MultiHopSwapCore(
	goCtx context.Context,
	amountIn sdk.Int,
	routes []*types.MultiHopRoute,
	exitLimitPrice sdk.Dec,
	pickBestRoute bool,
	callerAddr sdk.AccAddress,
	receiverAddr sdk.AccAddress,
) (coinOut sdk.Coin, err error)

func (Keeper) MultihopStep

func (k Keeper) MultihopStep(
	bctx *types.BranchableCache,
	step MultihopStep,
	inCoin sdk.Coin,
	exitLimitPrice sdk.Dec,
	currentPrice sdk.Dec,
	remainingSteps []MultihopStep,
	stepCache map[multihopCacheKey]StepResult,
) (sdk.Coin, *types.BranchableCache, error)

func (Keeper) NewLiquidityIterator added in v0.3.4

func (k Keeper) NewLiquidityIterator(
	ctx sdk.Context,
	tradePairID *types.TradePairID,
) *LiquidityIterator

func (Keeper) NewTickIterator

func (k Keeper) NewTickIterator(
	ctx sdk.Context,
	tradePairID *types.TradePairID,
) TickIterator

func (Keeper) Params

func (Keeper) PlaceLimitOrderCore

func (k Keeper) PlaceLimitOrderCore(
	goCtx context.Context,
	tokenIn string,
	tokenOut string,
	amountIn sdk.Int,
	tickIndexInToOut int64,
	orderType types.LimitOrderType,
	goodTil *time.Time,
	maxAmountOut *sdk.Int,
	callerAddr sdk.AccAddress,
	receiverAddr sdk.AccAddress,
) (trancheKey string, totalInCoin sdk.Coin, swapInCoin sdk.Coin, swapOutCoin sdk.Coin, err error)

Handles MsgPlaceLimitOrder, initializing (tick, pair) data structures if needed, calculating and storing information for a new limit order at a specific tick.

func (Keeper) Pool added in v0.4.0

func (Keeper) PurgeExpiredLimitOrders

func (k Keeper) PurgeExpiredLimitOrders(ctx sdk.Context, curTime time.Time)

func (Keeper) RemoveInactiveLimitOrderTranche

func (k Keeper) RemoveInactiveLimitOrderTranche(
	ctx sdk.Context,
	limitOrderTrancheKey *types.LimitOrderTrancheKey,
)

RemoveInactiveLimitOrderTranche removes a inactiveLimitOrderTranche from the store

func (Keeper) RemoveLimitOrderExpiration

func (k Keeper) RemoveLimitOrderExpiration(
	ctx sdk.Context,
	goodTilDate time.Time,
	trancheRef []byte,
)

RemoveLimitOrderExpiration removes a goodTilRecord from the store

func (Keeper) RemoveLimitOrderExpirationByKey

func (k Keeper) RemoveLimitOrderExpirationByKey(ctx sdk.Context, key []byte)

func (Keeper) RemoveLimitOrderTranche

func (k Keeper) RemoveLimitOrderTranche(ctx sdk.Context, trancheKey *types.LimitOrderTrancheKey)

func (Keeper) RemoveLimitOrderTrancheUser

func (k Keeper) RemoveLimitOrderTrancheUser(ctx sdk.Context, trancheUser *types.LimitOrderTrancheUser)

func (Keeper) RemoveLimitOrderTrancheUserByKey

func (k Keeper) RemoveLimitOrderTrancheUserByKey(
	ctx sdk.Context,
	trancheKey string,
	address string,
)

RemoveLimitOrderTrancheUserByKey removes a LimitOrderTrancheUser from the store

func (Keeper) RemovePoolReserves

func (k Keeper) RemovePoolReserves(ctx sdk.Context, poolReservesID *types.PoolReservesKey)

RemoveTickLiquidity removes a tickLiquidity from the store

func (Keeper) RunMultihopRoute

func (k Keeper) RunMultihopRoute(
	ctx sdk.Context,
	route types.MultiHopRoute,
	initialInCoin sdk.Coin,
	exitLimitPrice sdk.Dec,
	stepCache map[multihopCacheKey]StepResult,
) (sdk.Coin, func(), error)

func (Keeper) SaveInactiveTranche

func (k Keeper) SaveInactiveTranche(sdkCtx sdk.Context, tranche *types.LimitOrderTranche)

func (Keeper) SaveLiquidity

func (k Keeper) SaveLiquidity(sdkCtx sdk.Context, liquidityI types.Liquidity)

func (Keeper) SaveTranche

func (k Keeper) SaveTranche(ctx sdk.Context, tranche *types.LimitOrderTranche)

func (Keeper) SaveTrancheUser

func (k Keeper) SaveTrancheUser(ctx sdk.Context, trancheUser *types.LimitOrderTrancheUser)

func (Keeper) SetInactiveLimitOrderTranche

func (k Keeper) SetInactiveLimitOrderTranche(ctx sdk.Context, limitOrderTranche *types.LimitOrderTranche)

SetInactiveLimitOrderTranche set a specific inactiveLimitOrderTranche in the store from its index

func (Keeper) SetLimitOrderExpiration

func (k Keeper) SetLimitOrderExpiration(
	ctx sdk.Context,
	goodTilRecord *types.LimitOrderExpiration,
)

SetLimitOrderExpiration set a specific goodTilRecord in the store from its index

func (Keeper) SetLimitOrderTranche

func (k Keeper) SetLimitOrderTranche(ctx sdk.Context, tranche *types.LimitOrderTranche)

func (Keeper) SetLimitOrderTrancheUser

func (k Keeper) SetLimitOrderTrancheUser(ctx sdk.Context, limitOrderTrancheUser *types.LimitOrderTrancheUser)

SetLimitOrderTrancheUser set a specific LimitOrderTrancheUser in the store from its index

func (Keeper) SetParams

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

SetParams set the params

func (Keeper) SetPool added in v0.3.4

func (k Keeper) SetPool(ctx sdk.Context, pool *types.Pool)

func (Keeper) SetPoolReserves

func (k Keeper) SetPoolReserves(ctx sdk.Context, poolReserves *types.PoolReserves)

func (Keeper) Swap

func (k Keeper) Swap(
	ctx sdk.Context,
	tradePairID *types.TradePairID,
	maxAmountTakerDenom sdk.Int,
	maxAmountMakerDenom *sdk.Int,
	limitPrice *sdk.Dec,
) (totalTakerCoin, totalMakerCoin sdk.Coin, orderFilled bool, err error)

func (Keeper) SwapExactAmountIn

func (k Keeper) SwapExactAmountIn(ctx sdk.Context,
	tradePairID *types.TradePairID,
	amountIn sdk.Int,
) (totalOut sdk.Coin, err error)

func (Keeper) SwapWithCache

func (k Keeper) SwapWithCache(
	ctx sdk.Context,
	tradePairID *types.TradePairID,
	maxAmountIn sdk.Int,
	maxAmountOut *sdk.Int,
	limitPrice *sdk.Dec,
) (totalIn, totalOut sdk.Coin, orderFilled bool, err error)

func (Keeper) WithdrawCore

func (k Keeper) WithdrawCore(
	goCtx context.Context,
	pairID *types.PairID,
	callerAddr sdk.AccAddress,
	receiverAddr sdk.AccAddress,
	sharesToRemoveList []sdk.Int,
	tickIndicesNormalized []int64,
	fees []uint64,
) error

Handles core logic for MsgWithdrawal; calculating and withdrawing reserve0,reserve1 from a specified tick given a specfied number of shares to remove. Calculates the amount of reserve0, reserve1 to withdraw based on the percentage of the desired number of shares to remove compared to the total number of shares at the given tick.

func (Keeper) WithdrawFilledLimitOrderCore

func (k Keeper) WithdrawFilledLimitOrderCore(
	goCtx context.Context,
	trancheKey string,
	callerAddr sdk.AccAddress,
) error

Handles MsgWithdrawFilledLimitOrder, calculates and sends filled liqudity from module to user for a limit order based on amount wished to receive.

type LiquidityIterator

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

func (*LiquidityIterator) Close

func (s *LiquidityIterator) Close()

func (*LiquidityIterator) Next

func (s *LiquidityIterator) Next() types.Liquidity

func (*LiquidityIterator) WrapTickLiquidity added in v0.3.4

func (s *LiquidityIterator) WrapTickLiquidity(tick types.TickLiquidity) types.Liquidity

type MsgServer added in v0.4.0

type MsgServer struct {
	Keeper
}

func (MsgServer) CancelLimitOrder added in v0.4.0

func (MsgServer) Deposit added in v0.4.0

func (k MsgServer) Deposit(
	goCtx context.Context,
	msg *types.MsgDeposit,
) (*types.MsgDepositResponse, error)

func (MsgServer) MultiHopSwap added in v0.4.0

func (k MsgServer) MultiHopSwap(
	goCtx context.Context,
	msg *types.MsgMultiHopSwap,
) (*types.MsgMultiHopSwapResponse, error)

func (MsgServer) PlaceLimitOrder added in v0.4.0

func (MsgServer) WithdrawFilledLimitOrder added in v0.4.0

func (MsgServer) Withdrawal added in v0.4.0

func (k MsgServer) Withdrawal(
	goCtx context.Context,
	msg *types.MsgWithdrawal,
) (*types.MsgWithdrawalResponse, error)

type MultihopStep

type MultihopStep struct {
	RemainingBestPrice sdk.Dec
	// contains filtered or unexported fields
}

type StepResult

type StepResult struct {
	Ctx     *types.BranchableCache
	CoinOut sdk.Coin
	CoinIn  sdk.Coin
	Err     error
}

type TickIterator

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

func (TickIterator) Close

func (ti TickIterator) Close() error

func (TickIterator) Next

func (ti TickIterator) Next()

func (TickIterator) Valid

func (ti TickIterator) Valid() bool

func (TickIterator) Value

func (ti TickIterator) Value() (tick types.TickLiquidity)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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