Documentation
¶
Index ¶
- func GenerateStreamSubaccountUpdate(settledUpdate types.SettledUpdate, ...) types.StreamSubaccountUpdate
- func GetIsolatedPerpetualStateTransition(settledUpdateWithUpdatedSubaccount types.SettledUpdate, ...) (*types.IsolatedPerpetualPositionStateTransition, error)
- func GetMarginedUpdates(settledUpdates []types.SettledUpdate, perpInfos perptypes.PerpInfos) (marginedUpdates []types.SettledUpdate)
- type Keeper
- func (k Keeper) AddSubaccountToSafetyHeap(ctx sdk.Context, subaccountId types.SubaccountId, perpetualId uint32, ...)
- func (k Keeper) CanUpdateSubaccounts(ctx sdk.Context, updates []types.Update, updateType types.UpdateType) (success bool, successPerUpdate []types.UpdateResult, err error)
- func (k Keeper) CollateralPoolAddress(c context.Context, req *types.QueryCollateralPoolAddressRequest) (*types.QueryCollateralPoolAddressResponse, error)
- func (k Keeper) DeleteSubaccountAtIndex(store prefix.Store, heapIndex uint32)
- func (k Keeper) DeleteSubaccountHeapIndex(store prefix.Store, subaccountId types.SubaccountId)
- func (k Keeper) DepositFundsFromAccountToSubaccount(ctx sdk.Context, fromAccount sdk.AccAddress, toSubaccountId types.SubaccountId, ...) error
- func (k Keeper) DistributeFees(ctx sdk.Context, assetId uint32, ...) error
- func (k Keeper) ForEachSubaccount(ctx sdk.Context, callback func(types.Subaccount) (finished bool))
- func (k Keeper) GetAllRelevantPerpetuals(ctx sdk.Context, updates []types.Update) (perptypes.PerpInfos, error)
- func (k Keeper) GetAllSubaccount(ctx sdk.Context) (list []types.Subaccount)
- func (k Keeper) GetCollateralPoolForSubaccount(ctx sdk.Context, subaccountId types.SubaccountId) (sdk.AccAddress, error)
- func (k Keeper) GetCollateralPoolFromPerpetualId(ctx sdk.Context, perpetualId uint32) (sdk.AccAddress, error)
- func (k Keeper) GetCrossInsuranceFundBalance(ctx sdk.Context) (balance *big.Int)
- func (k Keeper) GetFullNodeStreamingManager() streamingtypes.FullNodeStreamingManager
- func (k Keeper) GetIndexerEventManager() indexer_manager.IndexerEventManager
- func (k Keeper) GetInsuranceFundBalance(ctx sdk.Context, perpetualId uint32) (balance *big.Int)
- func (k Keeper) GetNegativeTncSubaccountSeenAtBlock(ctx sdk.Context, perpetualId uint32) (uint32, bool, error)
- func (k Keeper) GetNetCollateralAndMarginRequirements(ctx sdk.Context, update types.Update) (risk margin.Risk, err error)
- func (k Keeper) GetRandomSubaccount(ctx sdk.Context, rand *rand.Rand) (types.Subaccount, error)
- func (k Keeper) GetSafetyHeapKeyPrefix(perpetualId uint32, side types.SafetyHeapPositionSide) []byte
- func (k Keeper) GetSafetyHeapLength(store prefix.Store) (length uint32)
- func (k Keeper) GetSafetyHeapStore(ctx sdk.Context, perpetualId uint32, side types.SafetyHeapPositionSide) prefix.Store
- func (k Keeper) GetStreamSubaccountUpdate(ctx sdk.Context, id types.SubaccountId, snapshot bool) (val types.StreamSubaccountUpdate)
- func (k Keeper) GetSubaccount(ctx sdk.Context, id types.SubaccountId) (val types.Subaccount)
- func (k Keeper) GetSubaccountAtIndex(store prefix.Store, heapIndex uint32) (subaccountId types.SubaccountId, found bool)
- func (k Keeper) GetSubaccountHeapIndex(store prefix.Store, subaccountId types.SubaccountId) (heapIndex uint32, found bool)
- func (k Keeper) GetWithdrawalAndTransfersBlockedInfo(c context.Context, req *types.QueryGetWithdrawalAndTransfersBlockedInfoRequest) (*types.QueryGetWithdrawalAndTransfersBlockedInfoResponse, error)
- func (k Keeper) HeapifyDown(ctx sdk.Context, store prefix.Store, index uint32)
- func (k Keeper) HeapifyUp(ctx sdk.Context, store prefix.Store, index uint32)
- func (k Keeper) InitializeForGenesis(ctx sdk.Context)
- func (k Keeper) Insert(ctx sdk.Context, store prefix.Store, subaccountId types.SubaccountId)
- func (k Keeper) LegacyGetNegativeTncSubaccountSeenAtBlock(ctx sdk.Context) (uint32, bool)
- func (k Keeper) Less(ctx sdk.Context, store prefix.Store, first uint32, second uint32) bool
- func (k Keeper) Logger(ctx sdk.Context) log.Logger
- func (k Keeper) MustGetSubaccountAtIndex(store prefix.Store, heapIndex uint32) (subaccountId types.SubaccountId)
- func (k Keeper) MustGetSubaccountHeapIndex(store prefix.Store, subaccountId types.SubaccountId) (heapIndex uint32)
- func (k Keeper) MustRemoveElementAtIndex(ctx sdk.Context, store prefix.Store, index uint32)
- func (k Keeper) RemoveSubaccountFromSafetyHeap(ctx sdk.Context, subaccountId types.SubaccountId, perpetualId uint32, ...)
- func (k Keeper) SetNegativeTncSubaccountSeenAtBlock(ctx sdk.Context, perpetualId uint32, blockHeight uint32) error
- func (k Keeper) SetSafetyHeapLength(store prefix.Store, length uint32)
- func (k Keeper) SetSubaccount(ctx sdk.Context, subaccount types.Subaccount)
- func (k Keeper) SetSubaccountAtIndex(store prefix.Store, subaccountId types.SubaccountId, heapIndex uint32)
- func (k Keeper) SetSubaccountHeapIndex(store prefix.Store, subaccountId types.SubaccountId, heapIndex uint32)
- func (k Keeper) Subaccount(c context.Context, req *types.QueryGetSubaccountRequest) (*types.QuerySubaccountResponse, error)
- func (k Keeper) SubaccountAll(c context.Context, req *types.QueryAllSubaccountRequest) (*types.QuerySubaccountAllResponse, error)
- func (k Keeper) Swap(store prefix.Store, index1 uint32, index2 uint32)
- func (k Keeper) TransferFees(ctx sdk.Context, assetId uint32, fromAddr sdk.AccAddress, ...) error
- func (k Keeper) TransferFundsFromSubaccountToSubaccount(ctx sdk.Context, senderSubaccountId types.SubaccountId, ...) error
- func (k Keeper) TransferInsuranceFundPayments(ctx sdk.Context, insuranceFundDelta *big.Int, perpetualId uint32) error
- func (k Keeper) TransferIsolatedCollateralToCross(ctx sdk.Context, perpetualId uint32) error
- func (k Keeper) TransferIsolatedInsuranceFundToCross(ctx sdk.Context, perpetualId uint32) error
- func (k Keeper) UpdateSubaccounts(ctx sdk.Context, updates []types.Update, updateType types.UpdateType) (success bool, successPerUpdate []types.UpdateResult, err error)
- func (k Keeper) WithdrawFundsFromSubaccountToAccount(ctx sdk.Context, fromSubaccountId types.SubaccountId, toAccount sdk.AccAddress, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateStreamSubaccountUpdate ¶
func GenerateStreamSubaccountUpdate( settledUpdate types.SettledUpdate, fundingPayments map[uint32]dtypes.SerializableInt, ) types.StreamSubaccountUpdate
func GetIsolatedPerpetualStateTransition ¶
func GetIsolatedPerpetualStateTransition( settledUpdateWithUpdatedSubaccount types.SettledUpdate, perpInfos perptypes.PerpInfos, ) (*types.IsolatedPerpetualPositionStateTransition, error)
GetIsolatedPerpetualStateTransition computes whether an isolated perpetual position will be opened or closed for a subaccount. This function assumes that the subaccount is valid under isolated perpetual constraints. The input `settledUpdate` must have an updated subaccount (`settledUpdate.SettledSubaccount`), so all the updates must have been applied already to the subaccount.
func GetMarginedUpdates ¶
func GetMarginedUpdates( settledUpdates []types.SettledUpdate, perpInfos perptypes.PerpInfos, ) ( marginedUpdates []types.SettledUpdate, )
GetMarginedUpdates calculates the quote balance updates needed for the given settled updates.
Types ¶
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
func NewKeeper ¶
func NewKeeper( cdc codec.BinaryCodec, storeKey storetypes.StoreKey, assetsKeeper types.AssetsKeeper, bankKeeper types.BankKeeper, perpetualsKeeper types.PerpetualsKeeper, blocktimeKeeper types.BlocktimeKeeper, indexerEventManager indexer_manager.IndexerEventManager, streamingManager streamingtypes.FullNodeStreamingManager, ) *Keeper
func (Keeper) AddSubaccountToSafetyHeap ¶
func (k Keeper) AddSubaccountToSafetyHeap( ctx sdk.Context, subaccountId types.SubaccountId, perpetualId uint32, side types.SafetyHeapPositionSide, )
AddSubaccountToSafetyHeap adds a subaccount to the safety heap given a perpetual and side.
func (Keeper) CanUpdateSubaccounts ¶
func (k Keeper) CanUpdateSubaccounts( ctx sdk.Context, updates []types.Update, updateType types.UpdateType, ) ( success bool, successPerUpdate []types.UpdateResult, err error, )
CanUpdateSubaccounts will validate all `updates` to the relevant subaccounts. The `updates` do not have to contain unique `SubaccountIds`. Each update is considered in isolation. Thus if two updates are provided with the same `SubaccountId`, they are validated without respect to each other.
Returns a `success` value of `true` if all updates are valid. Returns a `successPerUpdates` value, which is a slice of `UpdateResult`. These map to the updates and are used to indicate which of the updates caused a failure, if any.
func (Keeper) CollateralPoolAddress ¶
func (k Keeper) CollateralPoolAddress( c context.Context, req *types.QueryCollateralPoolAddressRequest, ) (*types.QueryCollateralPoolAddressResponse, error)
func (Keeper) DeleteSubaccountAtIndex ¶
DeleteSubaccountAtIndex deletes the subaccount at the given index. Panics if the heap index is not found.
func (Keeper) DeleteSubaccountHeapIndex ¶
func (k Keeper) DeleteSubaccountHeapIndex( store prefix.Store, subaccountId types.SubaccountId, )
DeleteSubaccountHeapIndex deletes the heap index of the subaccount.
func (Keeper) DepositFundsFromAccountToSubaccount ¶
func (k Keeper) DepositFundsFromAccountToSubaccount( ctx sdk.Context, fromAccount sdk.AccAddress, toSubaccountId types.SubaccountId, assetId uint32, quantums *big.Int, ) error
DepositFundsFromAccountToSubaccount returns an error if the call to `k.CanUpdateSubaccounts()` fails. Otherwise, increases the asset quantums in the subaccount, translates the `assetId` and `quantums` into a `sdk.Coin`, and calls `bankKeeper.SendCoinsFromAccountToModule()`. TODO(CORE-168): Change function interface to accept `denom` and `amount` instead of `assetId` and `quantums`.
func (Keeper) DistributeFees ¶
func (k Keeper) DistributeFees( ctx sdk.Context, assetId uint32, revSharesForFill revsharetypes.RevSharesForFill, fill clobtypes.FillForProcess, ) error
DistributeFees calculates the market mapper revenue share and fee collector share based on the quantums and perpetual parameters, and transfers the fees to the market mapper and fee collector.
func (Keeper) ForEachSubaccount ¶
ForEachSubaccount performs a callback across all subaccounts. The callback function should return a boolean if we should end iteration or not. This is more performant than GetAllSubaccount because it does not fetch all at once. and you do not need to iterate through all the subaccounts.
func (Keeper) GetAllRelevantPerpetuals ¶
func (k Keeper) GetAllRelevantPerpetuals( ctx sdk.Context, updates []types.Update, ) ( perptypes.PerpInfos, error, )
GetAllRelevantPerpetuals returns all relevant perpetual information for a given set of updates. This includes all perpetuals that exist on the accounts already and all perpetuals that are being updated in the input updates.
func (Keeper) GetAllSubaccount ¶
func (k Keeper) GetAllSubaccount(ctx sdk.Context) (list []types.Subaccount)
GetAllSubaccount returns all subaccount. For more performant searching and iteration, use `ForEachSubaccount`.
func (Keeper) GetCollateralPoolForSubaccount ¶
func (k Keeper) GetCollateralPoolForSubaccount(ctx sdk.Context, subaccountId types.SubaccountId) ( sdk.AccAddress, error, )
GetCollateralPoolForSubaccount returns the collateral pool address for a subaccount based on the subaccount's perpetual positions. If the subaccount holds a position in an isolated market, the collateral pool address will be the isolated market's pool address. Otherwise, the collateral pool address will be the module's pool address.
func (Keeper) GetCollateralPoolFromPerpetualId ¶
func (k Keeper) GetCollateralPoolFromPerpetualId(ctx sdk.Context, perpetualId uint32) (sdk.AccAddress, error)
GetCollateralPoolForSubaccountWithPerpetuals returns the collateral pool address based on the perpetual passed in as an argument.
func (Keeper) GetCrossInsuranceFundBalance ¶
func (Keeper) GetFullNodeStreamingManager ¶
func (k Keeper) GetFullNodeStreamingManager() streamingtypes.FullNodeStreamingManager
func (Keeper) GetIndexerEventManager ¶
func (k Keeper) GetIndexerEventManager() indexer_manager.IndexerEventManager
func (Keeper) GetInsuranceFundBalance ¶
GetInsuranceFundBalance returns the current balance of the specific insurance fund based on the perpetual (in quote quantums). This calls the Bank Keeper’s GetBalance() function for the Module Address of the insurance fund.
func (Keeper) GetNegativeTncSubaccountSeenAtBlock ¶
func (k Keeper) GetNegativeTncSubaccountSeenAtBlock( ctx sdk.Context, perpetualId uint32, ) (uint32, bool, error)
GetNegativeTncSubaccountSeenAtBlock gets the last block height a negative TNC subaccount was seen in state for the given collateral pool address and a boolean for whether it exists in state.
func (Keeper) GetNetCollateralAndMarginRequirements ¶
func (k Keeper) GetNetCollateralAndMarginRequirements( ctx sdk.Context, update types.Update, ) ( risk margin.Risk, err error, )
GetNetCollateralAndMarginRequirements returns the total net collateral, total initial margin requirement, and total maintenance margin requirement for the subaccount as if the `update` was applied. It is used to get information about speculative changes to the subaccount.
The provided update can also be "zeroed" in order to get information about the current state of the subaccount (i.e. with no changes).
If two position updates reference the same position, an error is returned.
All return values are denoted in quote quantums.
func (Keeper) GetRandomSubaccount ¶
GetRandomSubaccount returns a random subaccount. Will return an error if there are no subaccounts.
func (Keeper) GetSafetyHeapKeyPrefix ¶
func (k Keeper) GetSafetyHeapKeyPrefix( perpetualId uint32, side types.SafetyHeapPositionSide, ) []byte
GetSafetyHeapKeyPrefix returns the prefix for the safety heap store.
func (Keeper) GetSafetyHeapLength ¶
GetSafetyHeapLength returns the length of heap.
func (Keeper) GetSafetyHeapStore ¶
func (k Keeper) GetSafetyHeapStore( ctx sdk.Context, perpetualId uint32, side types.SafetyHeapPositionSide, ) prefix.Store
GetSafetyHeapStore returns the safety heap store.
func (Keeper) GetStreamSubaccountUpdate ¶
func (k Keeper) GetStreamSubaccountUpdate( ctx sdk.Context, id types.SubaccountId, snapshot bool, ) (val types.StreamSubaccountUpdate)
func (Keeper) GetSubaccount ¶
func (k Keeper) GetSubaccount( ctx sdk.Context, id types.SubaccountId, ) (val types.Subaccount)
GetSubaccount returns a subaccount from its index.
Note that this function is getting called very frequently; metrics in this function should be sampled to reduce CPU time.
func (Keeper) GetSubaccountAtIndex ¶
func (k Keeper) GetSubaccountAtIndex( store prefix.Store, heapIndex uint32, ) ( subaccountId types.SubaccountId, found bool, )
GetSubaccountAtIndex returns the subaccount at the given index.
func (Keeper) GetSubaccountHeapIndex ¶
func (k Keeper) GetSubaccountHeapIndex( store prefix.Store, subaccountId types.SubaccountId, ) ( heapIndex uint32, found bool, )
GetSubaccountHeapIndex returns the heap index of the subaccount.
func (Keeper) GetWithdrawalAndTransfersBlockedInfo ¶
func (k Keeper) GetWithdrawalAndTransfersBlockedInfo( c context.Context, req *types.QueryGetWithdrawalAndTransfersBlockedInfoRequest, ) (*types.QueryGetWithdrawalAndTransfersBlockedInfoResponse, error)
func (Keeper) HeapifyDown ¶
HeapifyDown moves the element at the given index down the heap until the heap property is restored.
func (Keeper) HeapifyUp ¶
HeapifyUp moves the element at the given index up the heap until the heap property is restored.
func (Keeper) InitializeForGenesis ¶
func (Keeper) LegacyGetNegativeTncSubaccountSeenAtBlock ¶
LegacyGetNegativeTncSubaccountSeenAtBlock gets the last block height a negative TNC subaccount was seen in state and a boolean for whether it exists in state. Deprecated: This is the legacy implementation and meant to be used for the v5.0.0 state migration. Use `GetNegativeTncSubaccountSeenAtBlock` instead.
func (Keeper) Less ¶
Less returns true if the element at the first index is less than the element at the second index.
func (Keeper) MustGetSubaccountAtIndex ¶
func (k Keeper) MustGetSubaccountAtIndex( store prefix.Store, heapIndex uint32, ) ( subaccountId types.SubaccountId, )
MustGetSubaccountAtIndex returns the subaccount at the given index. Panics if the subaccount is not found.
func (Keeper) MustGetSubaccountHeapIndex ¶
func (k Keeper) MustGetSubaccountHeapIndex( store prefix.Store, subaccountId types.SubaccountId, ) ( heapIndex uint32, )
MustGetSubaccountHeapIndex returns the heap index of the subaccount. Panics if the heap index is not found.
func (Keeper) MustRemoveElementAtIndex ¶
MustRemoveElementAtIndex removes the element at the given index from the safety heap.
func (Keeper) RemoveSubaccountFromSafetyHeap ¶
func (k Keeper) RemoveSubaccountFromSafetyHeap( ctx sdk.Context, subaccountId types.SubaccountId, perpetualId uint32, side types.SafetyHeapPositionSide, )
RemoveSubaccountFromSafetyHeap removes a subaccount from the safety heap given a peretual and side.
func (Keeper) SetNegativeTncSubaccountSeenAtBlock ¶
func (k Keeper) SetNegativeTncSubaccountSeenAtBlock( ctx sdk.Context, perpetualId uint32, blockHeight uint32, ) error
SetNegativeTncSubaccountSeenAtBlock sets a block number in state where a negative TNC subaccount was seen for a specific collateral pool. This function will overwrite previous values at this key. This function will panic if the old block height is greater than the new block height.
func (Keeper) SetSafetyHeapLength ¶
SetSafetyHeapLength sets the heap length.
func (Keeper) SetSubaccount ¶
func (k Keeper) SetSubaccount(ctx sdk.Context, subaccount types.Subaccount)
SetSubaccount set a specific subaccount in the store from its index. Note that empty subaccounts are removed from state.
func (Keeper) SetSubaccountAtIndex ¶
func (k Keeper) SetSubaccountAtIndex( store prefix.Store, subaccountId types.SubaccountId, heapIndex uint32, )
SetSubaccountAtIndex updates the subaccount at the given index.
func (Keeper) SetSubaccountHeapIndex ¶
func (k Keeper) SetSubaccountHeapIndex( store prefix.Store, subaccountId types.SubaccountId, heapIndex uint32, )
SetSubaccountHeapIndex sets the heap index of the subaccount.
func (Keeper) Subaccount ¶
func (k Keeper) Subaccount( c context.Context, req *types.QueryGetSubaccountRequest, ) (*types.QuerySubaccountResponse, error)
func (Keeper) SubaccountAll ¶
func (k Keeper) SubaccountAll( c context.Context, req *types.QueryAllSubaccountRequest, ) (*types.QuerySubaccountAllResponse, error)
func (Keeper) TransferFees ¶
func (k Keeper) TransferFees( ctx sdk.Context, assetId uint32, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, quantums *big.Int, ) error
TransferFees translates the assetId and quantums into a sdk.Coin, and moves the funds from `fromAddr` to `toAddr` by calling `bankKeeper.SendCoins()`
func (Keeper) TransferFundsFromSubaccountToSubaccount ¶
func (k Keeper) TransferFundsFromSubaccountToSubaccount( ctx sdk.Context, senderSubaccountId types.SubaccountId, recipientSubaccountId types.SubaccountId, assetId uint32, quantums *big.Int, ) error
TransferFundsFromSubaccountToSubaccount returns an error if the call to `k.CanUpdateSubaccounts()` fails. Otherwise, updates the asset quantums in the subaccounts, translates the `assetId` and `quantums` into a `sdk.Coin`, and call `bankKeeper.SendCoins()` if the collateral pools for the two subaccounts are different. TODO(CORE-168): Change function interface to accept `denom` and `amount` instead of `assetId` and `quantums`.
func (Keeper) TransferInsuranceFundPayments ¶
func (k Keeper) TransferInsuranceFundPayments( ctx sdk.Context, insuranceFundDelta *big.Int, perpetualId uint32, ) error
TransferInsuranceFundPayments transfers funds in and out of the insurance fund to the subaccounts module by calling `bankKeeper.SendCoins`. This function transfers funds
- from the insurance fund to the subaccounts module when `insuranceFundDelta` is negative.
- from the subaccounts module to the insurance fund when `insuranceFundDelta` is positive.
- does nothing if `insuranceFundDelta` is zero.
If the sender account does not have enough balance for the transfer, an error is returned. Note this function does not change any individual subaccount state.
func (Keeper) TransferIsolatedCollateralToCross ¶
TransferIsolatedCollateralToCross transfers the collateral balance from an isolated perpetual's collateral pool to the cross-margin collateral pool. This is used during the upgrade process from isolated perpetuals to cross-margin. Note: This uses the `x/bank` keeper and modifies `x/bank` state.
func (Keeper) TransferIsolatedInsuranceFundToCross ¶
TransferIsolatedInsuranceFundToCross transfers funds from an isolated perpetual's insurance fund to the cross-perpetual insurance fund. Note: This uses the `x/bank` keeper and modifies `x/bank` state.
func (Keeper) UpdateSubaccounts ¶
func (k Keeper) UpdateSubaccounts( ctx sdk.Context, updates []types.Update, updateType types.UpdateType, ) ( success bool, successPerUpdate []types.UpdateResult, err error, )
UpdateSubaccounts validates and applies all `updates` to the relevant subaccounts as long as this is a valid state-transition for all subaccounts involved. All `updates` are made atomically, meaning that all state-changes will either succeed or all will fail.
Returns a boolean indicating whether the update was successfully applied or not. If `false`, then no updates to any subaccount were made. A second return value returns an array of `UpdateResult` which map to the `updates` to indicate which of the updates caused a failure, if any. This function also transfers collateral between the cross-perpetual collateral pool and isolated perpetual collateral pools if any of the updates led to an isolated perpetual posititon to be opened or closed. This is done using the `x/bank` keeper and updates `x/bank` state.
Each `SubaccountId` in the `updates` must be unique or an error is returned.
func (Keeper) WithdrawFundsFromSubaccountToAccount ¶
func (k Keeper) WithdrawFundsFromSubaccountToAccount( ctx sdk.Context, fromSubaccountId types.SubaccountId, toAccount sdk.AccAddress, assetId uint32, quantums *big.Int, ) error
WithdrawFundsFromSubaccountToAccount returns an error if the call to `k.CanUpdateSubaccounts()` fails. Otherwise, deducts the asset quantums from the subaccount, translates the `assetId` and `quantums` into a `sdk.Coin`, and calls `bankKeeper.SendCoins()`.