Documentation
¶
Index ¶
- func CalculateUpdatedAssetPositions(assetPositions []*types.AssetPosition, updates []types.AssetUpdate) []*types.AssetPosition
- func CalculateUpdatedPerpetualPositions(positions []*types.PerpetualPosition, updates []types.PerpetualUpdate, ...) []*types.PerpetualPosition
- func CalculateUpdatedSubaccount(settledUpdate types.SettledUpdate, perpInfos perptypes.PerpInfos) types.Subaccount
- func GetDeltaOpenInterestFromUpdates(settledUpdates []types.SettledUpdate, updateType types.UpdateType) (ret *perptypes.OpenInterestDelta)
- func GetRiskForSubaccount(subaccount types.Subaccount, perpInfos perptypes.PerpInfos) (risk margin.Risk, err error)
- func GetSettledSubaccountWithPerpetuals(subaccount types.Subaccount, perpInfos perptypes.PerpInfos) (settledSubaccount types.Subaccount, ...)
- func GetUpdatedAssetPositions(update types.SettledUpdate) []*types.AssetPosition
- func GetUpdatedPerpetualPositions(update types.SettledUpdate, fundingPayments map[uint32]dtypes.SerializableInt) []*types.PerpetualPosition
- func IsValidStateTransitionForUndercollateralizedSubaccount(riskCur margin.Risk, riskNew margin.Risk) types.UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateUpdatedAssetPositions ¶
func CalculateUpdatedAssetPositions( assetPositions []*types.AssetPosition, updates []types.AssetUpdate, ) []*types.AssetPosition
CalculateUpdatedAssetPositions returns a deep-copy of the asset positions with the updates applied.
func CalculateUpdatedPerpetualPositions ¶
func CalculateUpdatedPerpetualPositions( positions []*types.PerpetualPosition, updates []types.PerpetualUpdate, perpInfos perptypes.PerpInfos, ) []*types.PerpetualPosition
CalculateUpdatedPerpetualPositions returns a deep-copy of the perpetual positions with the updates applied.
func CalculateUpdatedSubaccount ¶
func CalculateUpdatedSubaccount( settledUpdate types.SettledUpdate, perpInfos perptypes.PerpInfos, ) types.Subaccount
CalculateUpdatedSubaccount returns a copy of the settled subaccount with the updates applied.
func GetDeltaOpenInterestFromUpdates ¶
func GetDeltaOpenInterestFromUpdates( settledUpdates []types.SettledUpdate, updateType types.UpdateType, ) (ret *perptypes.OpenInterestDelta)
For `Match` updates:
- returns a struct `OpenInterest` if input updates results in OI delta.
- returns nil if OI delta is zero.
- panics if update format is invalid.
For other update types, returns nil.
func GetRiskForSubaccount ¶
func GetRiskForSubaccount( subaccount types.Subaccount, perpInfos perptypes.PerpInfos, ) ( risk margin.Risk, err error, )
GetRiskForSubaccount returns the risk value of the `Subaccount` after updates are applied. It is used to get information about speculative changes to the `Subaccount`. The input subaccount must be settled.
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.
func GetSettledSubaccountWithPerpetuals ¶
func GetSettledSubaccountWithPerpetuals( subaccount types.Subaccount, perpInfos perptypes.PerpInfos, ) ( settledSubaccount types.Subaccount, fundingPayments map[uint32]dtypes.SerializableInt, )
GetSettledSubaccountWithPerpetuals returns 1. a new settled subaccount given an unsettled subaccount, updating the USDC AssetPosition, FundingIndex, and LastFundingPayment fields accordingly (does not persist any changes) and 2. a map with perpetual ID as key and last funding payment as value (for emitting funding payments to indexer).
func GetUpdatedAssetPositions ¶
func GetUpdatedAssetPositions( update types.SettledUpdate, ) []*types.AssetPosition
GetUpdatedAssetPositions filters out all the asset positions on a subaccount that have been updated. This will include any asset postions that were closed due to an update. TODO(DEC-1295): look into reducing code duplication here using Generics+Reflect.
func GetUpdatedPerpetualPositions ¶
func GetUpdatedPerpetualPositions( update types.SettledUpdate, fundingPayments map[uint32]dtypes.SerializableInt, ) []*types.PerpetualPosition
GetUpdatedPerpetualPositions filters out all the perpetual positions on a subaccount that have been updated. This will include any perpetual postions that were closed due to an update or that received / paid out funding payments..
func IsValidStateTransitionForUndercollateralizedSubaccount ¶
func IsValidStateTransitionForUndercollateralizedSubaccount( riskCur margin.Risk, riskNew margin.Risk, ) types.UpdateResult
IsValidStateTransitionForUndercollateralizedSubaccount returns an `UpdateResult` denoting whether this state transition is valid. This function accepts the collateral and margin requirements of a subaccount before and after an update ("cur" and "new", respectively).
This function should only be called if the account is undercollateralized after the update.
A state transition is valid if the subaccount enters a "less-or-equally-risky" state after an update. i.e.`newNetCollateral / newMaintenanceMargin >= curNetCollateral / curMaintenanceMargin`.
Otherwise, the state transition is invalid. If the account was previously undercollateralized, `types.StillUndercollateralized` is returned. If the account was previously collateralized and is now undercollateralized, `types.NewlyUndercollateralized` is returned.
Note that the inequality `newNetCollateral / newMaintenanceMargin >= curNetCollateral / curMaintenanceMargin` has divide-by-zero issue when margin requirements are zero. To make sure the state transition is valid, we special case this scenario and only allow state transition that improves net collateral.
Types ¶
This section is empty.