Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PositionRiskAccountingLib

Git Source

Functions

getPendingFunding

function getPendingFunding(
    CfdTypes.Position memory pos,
    int256 currentIndex
) internal pure returns (int256 fundingUsdc);

previewPendingFunding

function previewPendingFunding(
    CfdTypes.Position memory pos,
    int256 bullFundingIndex,
    int256 bearFundingIndex,
    uint256 lastMarkPrice,
    uint256 bullOi,
    uint256 bearOi,
    uint64 lastFundingTime,
    uint256 currentTimestamp,
    uint256 vaultDepthUsdc,
    CfdTypes.RiskParams memory riskParams
) internal pure returns (int256 fundingUsdc);

computeFundingStep

function computeFundingStep(
    FundingStepInputs memory inputs
) internal pure returns (FundingStepResult memory result);

buildPositionRiskState

function buildPositionRiskState(
    CfdTypes.Position memory pos,
    uint256 price,
    uint256 capPrice,
    int256 pendingFundingUsdc,
    uint256 reachableCollateralUsdc,
    uint256 requiredBps
) internal pure returns (PositionRiskState memory state);

Structs

FundingStepInputs

struct FundingStepInputs {
    uint256 price;
    uint256 bullOi;
    uint256 bearOi;
    uint256 timeDelta;
    uint256 vaultDepthUsdc;
    CfdTypes.RiskParams riskParams;
}

FundingStepResult

struct FundingStepResult {
    uint256 absSkewUsdc;
    int256 bullFundingIndexDelta;
    int256 bearFundingIndexDelta;
}

PositionRiskState

struct PositionRiskState {
    int256 pendingFundingUsdc;
    int256 unrealizedPnlUsdc;
    int256 equityUsdc;
    uint256 currentNotionalUsdc;
    uint256 maintenanceMarginUsdc;
    bool liquidatable;
}