Documentation
¶
Index ¶
- func NewMsgServerImpl(keeper types.PerpetualsKeeper) types.MsgServer
- type Keeper
- func (k Keeper) AcquireNextPerpetualID(ctx sdk.Context) uint32
- func (k Keeper) AddPremiumSamples(ctx sdk.Context, newSamples []types.FundingPremium) error
- func (k Keeper) AddPremiumVotes(ctx sdk.Context, newVotes []types.FundingPremium) error
- func (k Keeper) AllLiquidityTiers(c context.Context, req *types.QueryAllLiquidityTiersRequest) (*types.QueryAllLiquidityTiersResponse, error)
- func (k Keeper) AllPerpetuals(c context.Context, req *types.QueryAllPerpetualsRequest) (*types.QueryAllPerpetualsResponse, error)
- func (k Keeper) CreatePerpetual(ctx sdk.Context, id uint32, ticker string, marketId uint32, ...) (types.Perpetual, error)
- func (k Keeper) GetAddPremiumVotes(ctx sdk.Context) (msgAddPremiumVotes *types.MsgAddPremiumVotes)
- func (k Keeper) GetAllLiquidityTiers(ctx sdk.Context) (list []types.LiquidityTier)
- func (k Keeper) GetAllPerpetuals(ctx sdk.Context) (list []types.Perpetual)
- func (k Keeper) GetIndexerEventManager() indexer_manager.IndexerEventManager
- func (k Keeper) GetInsuranceFundModuleAddress(ctx sdk.Context, perpetualId uint32) (sdk.AccAddress, error)
- func (k Keeper) GetInsuranceFundName(ctx sdk.Context, perpetualId uint32) (string, error)
- func (k Keeper) GetLiquidityTier(ctx sdk.Context, id uint32) (liquidityTier types.LiquidityTier, err error)
- func (k Keeper) GetNetCollateral(ctx sdk.Context, id uint32, bigQuantums *big.Int) (bigNetCollateralQuoteQuantums *big.Int, err error)
- func (k Keeper) GetNetNotional(ctx sdk.Context, id uint32, bigQuantums *big.Int) (bigNetNotionalQuoteQuantums *big.Int, err error)
- func (k Keeper) GetNextPerpetualID(ctx sdk.Context) uint32
- func (k Keeper) GetNotionalInBaseQuantums(ctx sdk.Context, id uint32, bigQuoteQuantums *big.Int) (bigBaseQuantums *big.Int, err error)
- func (k Keeper) GetParams(ctx sdk.Context) (params types.Params)
- func (k Keeper) GetPerpetual(ctx sdk.Context, id uint32) (val types.Perpetual, err error)
- func (k Keeper) GetPerpetualAndMarketPrice(ctx sdk.Context, perpetualId uint32) (types.Perpetual, pricestypes.MarketPrice, error)
- func (k Keeper) GetPerpetualAndMarketPriceAndLiquidityTier(ctx sdk.Context, perpetualId uint32) (types.Perpetual, pricestypes.MarketPrice, types.LiquidityTier, error)
- func (k Keeper) GetPremiumSamples(ctx sdk.Context) (premiumStore types.PremiumStore)
- func (k Keeper) GetPremiumVotes(ctx sdk.Context) (premiumStore types.PremiumStore)
- func (k Keeper) GetRemoveSampleTailsFunc(ctx sdk.Context, tailRemovalRatePpm uint32) func(input []int32) (output []int32)
- func (k Keeper) HasAuthority(authority string) bool
- func (k Keeper) HasLiquidityTier(ctx sdk.Context, id uint32) (found bool)
- func (k Keeper) HasPerpetual(ctx sdk.Context, id uint32) (found bool)
- func (k Keeper) InitializeForGenesis(ctx sdk.Context)
- func (k Keeper) IsIsolatedPerpetual(ctx sdk.Context, perpetualId uint32) (bool, error)
- func (k Keeper) IsPositionUpdatable(ctx sdk.Context, perpetualId uint32) (updatable bool, err error)
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) MaybeProcessNewFundingSampleEpoch(ctx sdk.Context)
- func (k Keeper) MaybeProcessNewFundingTickEpoch(ctx sdk.Context)
- func (k Keeper) ModifyFundingIndex(ctx sdk.Context, perpetualId uint32, bigFundingIndexDelta *big.Int) (err error)
- func (k Keeper) ModifyOpenInterest(ctx sdk.Context, perpetualId uint32, openInterestDeltaBaseQuantums *big.Int) (err error)
- func (k Keeper) ModifyPerpetual(ctx sdk.Context, id uint32, ticker string, marketId uint32, ...) (types.Perpetual, error)
- func (k Keeper) NextPerpetualId(c context.Context, req *types.QueryNextPerpetualIdRequest) (*types.QueryNextPerpetualIdResponse, error)
- func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error)
- func (k Keeper) PerformStatefulPremiumVotesValidation(ctx sdk.Context, msg *types.MsgAddPremiumVotes) (err error)
- func (k Keeper) Perpetual(c context.Context, req *types.QueryPerpetualRequest) (*types.QueryPerpetualResponse, error)
- func (k Keeper) PremiumSamples(c context.Context, req *types.QueryPremiumSamplesRequest) (*types.QueryPremiumSamplesResponse, error)
- func (k Keeper) PremiumVotes(c context.Context, req *types.QueryPremiumVotesRequest) (*types.QueryPremiumVotesResponse, error)
- func (k *Keeper) SetClobKeeper(getter types.PerpetualsClobKeeper)
- func (k Keeper) SetEmptyPremiumSamples(ctx sdk.Context)
- func (k Keeper) SetEmptyPremiumVotes(ctx sdk.Context)
- func (k Keeper) SetLiquidityTier(ctx sdk.Context, id uint32, name string, initialMarginPpm uint32, ...) (liquidityTier types.LiquidityTier, err error)
- func (k Keeper) SetNextPerpetualID(ctx sdk.Context, nextID uint32)
- func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error
- func (k Keeper) SetPerpetualForTest(ctx sdk.Context, perpetual types.Perpetual)
- func (k Keeper) SetPerpetualMarketType(ctx sdk.Context, perpetualId uint32, marketType types.PerpetualMarketType) (types.Perpetual, error)
- func (k Keeper) SetPremiumSamples(ctx sdk.Context, premiumStore types.PremiumStore)
- func (k Keeper) SetPremiumVotes(ctx sdk.Context, premiumStore types.PremiumStore)
- func (k Keeper) ValidateAndSetPerpetual(ctx sdk.Context, perpetual types.Perpetual) error
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 ¶
AcquireNextPerpetualID returns the next perpetual id to be used and increments the next perpetual id
func (Keeper) AddPremiumSamples ¶
AddPremiumSamples adds a list of new premium samples to state.
func (Keeper) AddPremiumVotes ¶
AddPremiumVotes adds a list of new premium votes to state.
func (Keeper) AllLiquidityTiers ¶
func (k Keeper) AllLiquidityTiers( c context.Context, req *types.QueryAllLiquidityTiersRequest, ) (*types.QueryAllLiquidityTiersResponse, error)
func (Keeper) AllPerpetuals ¶
func (k Keeper) AllPerpetuals( c context.Context, req *types.QueryAllPerpetualsRequest, ) (*types.QueryAllPerpetualsResponse, error)
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 ¶
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 ¶
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 ¶
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 ¶
=== PARAMETERS FUNCTIONS ===
`GetParams` returns perpetuals module parameters as a `Params` object from store.
func (Keeper) GetPerpetual ¶
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 (Keeper) HasLiquidityTier ¶
HasLiquidityTier checks if a liquidity tier exists in the store.
func (Keeper) HasPerpetual ¶
HasPerpetual checks if a perpetual exists in the store.
func (Keeper) InitializeForGenesis ¶
func (Keeper) IsIsolatedPerpetual ¶
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) MaybeProcessNewFundingSampleEpoch ¶
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 ¶
MaybeProcessNewFundingTickEpoch processes funding ticks if the current block is the start of a new funding-tick epoch. Otherwise, do nothing.
func (Keeper) ModifyFundingIndex ¶
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) NextPerpetualId ¶
func (k Keeper) NextPerpetualId( c context.Context, req *types.QueryNextPerpetualIdRequest, ) ( *types.QueryNextPerpetualIdResponse, error, )
func (Keeper) Params ¶
func (k Keeper) Params( c context.Context, req *types.QueryParamsRequest, ) (*types.QueryParamsResponse, error)
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) Perpetual ¶
func (k Keeper) Perpetual(c context.Context, req *types.QueryPerpetualRequest) (*types.QueryPerpetualResponse, error)
func (Keeper) PremiumSamples ¶
func (k Keeper) PremiumSamples( c context.Context, req *types.QueryPremiumSamplesRequest, ) (*types.QueryPremiumSamplesResponse, error)
func (Keeper) PremiumVotes ¶
func (k Keeper) PremiumVotes( c context.Context, req *types.QueryPremiumVotesRequest, ) (*types.QueryPremiumVotesResponse, error)
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 ¶
SetEmptyPremiumSamples initializes empty premium samples for all perpetuals
func (Keeper) SetEmptyPremiumVotes ¶
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 ¶
SetNextPerpetualID sets the next perpetual id to be used
func (Keeper) SetPerpetualForTest ¶
func (Keeper) SetPerpetualMarketType ¶
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, )
Source Files
¶
- grpc_query.go
- grpc_query_liquidity_tiers.go
- grpc_query_params.go
- grpc_query_perpetual.go
- grpc_query_premiums.go
- keeper.go
- msg_server.go
- msg_server_add_premium_votes.go
- msg_server_create_perpetual.go
- msg_server_set_liquidity_tier.go
- msg_server_update_params.go
- msg_server_update_perpetual_params.go
- perpetual.go