keeper

package
v0.0.0-...-f4c8e74 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMsgServerImpl

func NewMsgServerImpl(keeper types.PerpetualsKeeper) types.MsgServer

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

Types

type Keeper

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

func NewKeeper

func NewKeeper(
	cdc codec.BinaryCodec,
	storeKey storetypes.StoreKey,
	pricesKeeper types.PricesKeeper,
	epochsKeeper types.EpochsKeeper,
	indexerEventsManager indexer_manager.IndexerEventManager,
	authorities []string,
	transientStoreKey storetypes.StoreKey,
) *Keeper

func (Keeper) AcquireNextPerpetualID

func (k Keeper) AcquireNextPerpetualID(ctx sdk.Context) uint32

AcquireNextPerpetualID returns the next perpetual id to be used and increments the next perpetual id

func (Keeper) AddPremiumSamples

func (k Keeper) AddPremiumSamples(
	ctx sdk.Context,
	newSamples []types.FundingPremium,
) error

AddPremiumSamples adds a list of new premium samples to state.

func (Keeper) AddPremiumVotes

func (k Keeper) AddPremiumVotes(
	ctx sdk.Context,
	newVotes []types.FundingPremium,
) error

AddPremiumVotes adds a list of new premium votes to state.

func (Keeper) CreatePerpetual

func (k Keeper) CreatePerpetual(
	ctx sdk.Context,
	id uint32,
	ticker string,
	marketId uint32,
	atomicResolution int32,
	defaultFundingPpm int32,
	liquidityTier uint32,
	marketType types.PerpetualMarketType,
) (types.Perpetual, error)

CreatePerpetual creates a new perpetual in the store. Returns an error if any of the perpetual fields fail validation, or if the `marketId` does not exist.

func (Keeper) GetAddPremiumVotes

func (k Keeper) GetAddPremiumVotes(
	ctx sdk.Context,
) (
	msgAddPremiumVotes *types.MsgAddPremiumVotes,
)

GetAddPremiumVotes returns the newest premiums for all perpetuals, if the current block is the start of a new funding-sample epoch. Otherwise, does nothing and returns an empty message. Does not make any changes to state.

func (Keeper) GetAllLiquidityTiers

func (k Keeper) GetAllLiquidityTiers(ctx sdk.Context) (list []types.LiquidityTier)

`GetAllLiquidityTiers` returns all liquidity tiers, sorted by id.

func (Keeper) GetAllPerpetuals

func (k Keeper) GetAllPerpetuals(ctx sdk.Context) (list []types.Perpetual)

GetAllPerpetuals returns all perpetuals, sorted by perpetual Id.

func (Keeper) GetIndexerEventManager

func (k Keeper) GetIndexerEventManager() indexer_manager.IndexerEventManager

func (Keeper) GetInsuranceFundModuleAddress

func (k Keeper) GetInsuranceFundModuleAddress(ctx sdk.Context, perpetualId uint32) (sdk.AccAddress, error)

GetInsuranceFundModuleAddress returns the address of the insurance fund account for a given perpetual.

func (Keeper) GetInsuranceFundName

func (k Keeper) GetInsuranceFundName(ctx sdk.Context, perpetualId uint32) (string, error)

GetInsuranceFundName returns the name of the insurance fund account for a given perpetual. For isolated markets, the name is "insurance-fund:<perpetualId>". For cross markets, the name is "insurance-fund".

func (Keeper) GetLiquidityTier

func (k Keeper) GetLiquidityTier(ctx sdk.Context, id uint32) (
	liquidityTier types.LiquidityTier,
	err error,
)

`GetLiquidityTier` gets a liquidity tier given its id.

func (Keeper) GetNetCollateral

func (k Keeper) GetNetCollateral(
	ctx sdk.Context,
	id uint32,
	bigQuantums *big.Int,
) (
	bigNetCollateralQuoteQuantums *big.Int,
	err error,
)

GetNetCollateral returns the net collateral in quote quantums. The net collateral is equal to the net open notional, which can be represented by the following equation: `quantums / 10^baseAtomicResolution * marketPrice * 10^marketExponent * 10^quoteAtomicResolution`. Note that longs are positive, and shorts are negative. Returns an error if a perpetual with `id` does not exist or if the `perpetual.Params.MarketId` does not exist.

func (Keeper) GetNetNotional

func (k Keeper) GetNetNotional(
	ctx sdk.Context,
	id uint32,
	bigQuantums *big.Int,
) (
	bigNetNotionalQuoteQuantums *big.Int,
	err error,
)

GetNetNotional returns the net notional in quote quantums, which can be represented by the following equation: `quantums / 10^baseAtomicResolution * marketPrice * 10^marketExponent * 10^quoteAtomicResolution`. Note that longs are positive, and shorts are negative. Returns an error if a perpetual with `id` does not exist or if the `perpetual.Params.MarketId` does not exist.

Note that this function is getting called very frequently; metrics in this function should be sampled to reduce CPU time.

func (Keeper) GetNextPerpetualID

func (k Keeper) GetNextPerpetualID(ctx sdk.Context) uint32

GetNextPerpetualID returns the next perpetual id to be used from the module store

func (Keeper) GetNotionalInBaseQuantums

func (k Keeper) GetNotionalInBaseQuantums(
	ctx sdk.Context,
	id uint32,
	bigQuoteQuantums *big.Int,
) (
	bigBaseQuantums *big.Int,
	err error,
)

GetNotionalInBaseQuantums returns the net notional in base quantums, which can be represented by the following equation: `quoteQuantums * 10^baseAtomicResolution / (marketPrice * 10^marketExponent * 10^quoteAtomicResolution)`. Note that longs are positive, and shorts are negative. Returns an error if a perpetual with `id` does not exist or if the `perpetual.Params.MarketId` does not exist.

func (Keeper) GetParams

func (k Keeper) GetParams(
	ctx sdk.Context,
) (params types.Params)
=== PARAMETERS FUNCTIONS ===

`GetParams` returns perpetuals module parameters as a `Params` object from store.

func (Keeper) GetPerpetual

func (k Keeper) GetPerpetual(
	ctx sdk.Context,
	id uint32,
) (val types.Perpetual, err error)

GetPerpetual returns a perpetual from its id.

func (Keeper) GetPerpetualAndMarketPrice

func (k Keeper) GetPerpetualAndMarketPrice(
	ctx sdk.Context,
	perpetualId uint32,
) (types.Perpetual, pricestypes.MarketPrice, error)

GetPerpetualAndMarketPrice retrieves a Perpetual by its id and its corresponding MarketPrice.

Note that this function is getting called very frequently; metrics in this function should be sampled to reduce CPU time.

func (Keeper) GetPerpetualAndMarketPriceAndLiquidityTier

func (k Keeper) GetPerpetualAndMarketPriceAndLiquidityTier(
	ctx sdk.Context,
	perpetualId uint32,
) (
	types.Perpetual,
	pricestypes.MarketPrice,
	types.LiquidityTier,
	error,
)

GetPerpetualAndMarketPriceAndLiquidityTier retrieves a Perpetual by its id, its corresponding MarketPrice, and its corresponding LiquidityTier.

func (Keeper) GetPremiumSamples

func (k Keeper) GetPremiumSamples(ctx sdk.Context) (
	premiumStore types.PremiumStore,
)

GetPremiumSamples reads premium samples from the current `funding-tick` epoch, stored in a `PremiumStore` struct.

func (Keeper) GetPremiumVotes

func (k Keeper) GetPremiumVotes(ctx sdk.Context) (
	premiumStore types.PremiumStore,
)

GetPremiumVotes premium sample votes from the current `funding-sample` epoch, stored in a `PremiumStore` struct.

func (Keeper) GetRemoveSampleTailsFunc

func (k Keeper) GetRemoveSampleTailsFunc(
	ctx sdk.Context,
	tailRemovalRatePpm uint32,
) func(input []int32) (output []int32)

GetRemoveSampleTailsFunc returns a function that sorts the input samples (in place) and returns the sub-slice from the original slice, which removes `tailRemovalRatePpm` from top and bottom from the samples. Note the returned sub-slice is not a copy but references a sub-sequence of the original slice.

func (Keeper) HasAuthority

func (k Keeper) HasAuthority(authority string) bool

func (Keeper) HasLiquidityTier

func (k Keeper) HasLiquidityTier(
	ctx sdk.Context,
	id uint32,
) (found bool)

HasLiquidityTier checks if a liquidity tier exists in the store.

func (Keeper) HasPerpetual

func (k Keeper) HasPerpetual(
	ctx sdk.Context,
	id uint32,
) (found bool)

HasPerpetual checks if a perpetual exists in the store.

func (Keeper) InitializeForGenesis

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

func (Keeper) IsIsolatedPerpetual

func (k Keeper) IsIsolatedPerpetual(ctx sdk.Context, perpetualId uint32) (bool, error)

func (Keeper) IsPositionUpdatable

func (k Keeper) IsPositionUpdatable(
	ctx sdk.Context,
	perpetualId uint32,
) (
	updatable bool,
	err error,
)

IsPositionUpdatable returns whether position of a perptual is updatable. A perpetual is not updatable if it satisfies:

  • Perpetual has zero oracle price. Since new oracle prices are created at zero by default and valid oracle priceupdates are non-zero, this indicates the absence of a valid oracle price update.

func (Keeper) Logger

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

func (Keeper) MaybeProcessNewFundingSampleEpoch

func (k Keeper) MaybeProcessNewFundingSampleEpoch(
	ctx sdk.Context,
)

MaybeProcessNewFundingSampleEpoch summarizes premium votes stored in application states into new funding samples, if the current block is the start of a new `funding-sample` epoch. Otherwise, does nothing.

func (Keeper) MaybeProcessNewFundingTickEpoch

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

MaybeProcessNewFundingTickEpoch processes funding ticks if the current block is the start of a new funding-tick epoch. Otherwise, do nothing.

func (Keeper) ModifyFundingIndex

func (k Keeper) ModifyFundingIndex(
	ctx sdk.Context,
	perpetualId uint32,
	bigFundingIndexDelta *big.Int,
) (
	err error,
)

func (Keeper) ModifyOpenInterest

func (k Keeper) ModifyOpenInterest(
	ctx sdk.Context,
	perpetualId uint32,
	openInterestDeltaBaseQuantums *big.Int,
) (
	err error,
)

Modify the open interest of a perpetual in state.

func (Keeper) ModifyPerpetual

func (k Keeper) ModifyPerpetual(
	ctx sdk.Context,
	id uint32,
	ticker string,
	marketId uint32,
	defaultFundingPpm int32,
	liquidityTier uint32,
) (types.Perpetual, error)

ModifyPerpetual modifies an existing perpetual in the store. The new perpetual object must pass stateful and stateless validations. Upon successful modification, send an indexer event.

func (Keeper) Params

func (Keeper) PerformStatefulPremiumVotesValidation

func (k Keeper) PerformStatefulPremiumVotesValidation(
	ctx sdk.Context,
	msg *types.MsgAddPremiumVotes,
) (
	err error,
)

PerformStatefulPremiumVotesValidation performs stateful validation on `MsgAddPremiumVotes`. For each vote, it checks that: - The perpetual Id is valid. - The premium vote value is correctly clamped. This function throws an error if the associated clob pair cannot be found or is not active.

func (*Keeper) SetClobKeeper

func (k *Keeper) SetClobKeeper(getter types.PerpetualsClobKeeper)

SetClobKeeper sets the `PerpetualsClobKeeper` reference, which is a Clob Keeper, for this Perpetuals Keeper. This method is called after the Perpetuals Keeper struct is initialized. This reference is set with an explicit method call rather than during `NewKeeper` due to the bidirectional dependency between the Perpetuals Keeper and the Clob Keeper.

func (Keeper) SetEmptyPremiumSamples

func (k Keeper) SetEmptyPremiumSamples(
	ctx sdk.Context,
)

SetEmptyPremiumSamples initializes empty premium samples for all perpetuals

func (Keeper) SetEmptyPremiumVotes

func (k Keeper) SetEmptyPremiumVotes(
	ctx sdk.Context,
)

SetEmptyPremiumSamples initializes empty premium sample votes for all perpetuals

func (Keeper) SetLiquidityTier

func (k Keeper) SetLiquidityTier(
	ctx sdk.Context,
	id uint32,
	name string,
	initialMarginPpm uint32,
	maintenanceFractionPpm uint32,
	impactNotional uint64,
	openInterestLowerCap uint64,
	openInterestUpperCap uint64,
) (
	liquidityTier types.LiquidityTier,
	err error,
)

`SetLiquidityTier` sets a liquidity tier in the store (i.e. updates if `id` exists and creates otherwise). Returns an error if any of its fields fails validation.

func (Keeper) SetNextPerpetualID

func (k Keeper) SetNextPerpetualID(ctx sdk.Context, nextID uint32)

SetNextPerpetualID sets the next perpetual id to be used

func (Keeper) SetParams

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

`SetParams` sets perpetuals module parameters in store.

func (Keeper) SetPerpetualForTest

func (k Keeper) SetPerpetualForTest(
	ctx sdk.Context,
	perpetual types.Perpetual,
)

func (Keeper) SetPerpetualMarketType

func (k Keeper) SetPerpetualMarketType(
	ctx sdk.Context,
	perpetualId uint32,
	marketType types.PerpetualMarketType,
) (types.Perpetual, error)

func (Keeper) SetPremiumSamples

func (k Keeper) SetPremiumSamples(
	ctx sdk.Context,
	premiumStore types.PremiumStore,
)

func (Keeper) SetPremiumVotes

func (k Keeper) SetPremiumVotes(
	ctx sdk.Context,
	premiumStore types.PremiumStore,
)

func (Keeper) ValidateAndSetPerpetual

func (k Keeper) ValidateAndSetPerpetual(
	ctx sdk.Context,
	perpetual types.Perpetual,
) error

SetPerpetual validates the perpetual object and sets it in state.

Jump to

Keyboard shortcuts

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