Skip to main content

BinClosedPosition.sol

BinClosedPosition

struct BinClosedPosition {
uint256 _totalMakerMargin;
uint256 _totalTakerMargin;
struct BinClosingPosition _closing;
struct EnumerableSet.UintSet _waitingVersions;
mapping(uint256 => struct _ClaimWaitingPosition) _waitingPositions;
struct AccruedInterest _accruedInterest;
}

Represents a closed position within an LiquidityBin.

_ClaimWaitingPosition

struct _ClaimWaitingPosition {
int256 totalQty;
uint256 totalEntryAmount;
uint256 totalMakerMargin;
uint256 totalTakerMargin;
}

Represents the accumulated values of the waiting positions to be claimed for a specific version within BinClosedPosition.

BinClosedPositionLib

A library that provides functions to manage the closed position within an LiquidityBin.

settleClosingPosition

function settleClosingPosition(struct BinClosedPosition self, struct LpContext ctx) internal

Settles the closing position within the BinClosedPosition.

If the closeVersion is not set or is equal to the current oracle version, no action is taken. Otherwise, the waiting position is stored and the accrued interest is accumulated.

  • Parameters:

    NameTypeDescription
    selfstruct BinClosedPositionThe BinClosedPosition storage.
    ctxstruct LpContextThe LpContext memory.

onClosePosition

function onClosePosition(struct BinClosedPosition self, struct LpContext ctx, struct PositionParam param) internal

Closes the position within the BinClosedPosition.

Delegates the onClosePosition function call to the underlying BinClosingPosition.

  • Parameters:

    NameTypeDescription
    selfstruct BinClosedPositionThe BinClosedPosition storage.
    ctxstruct LpContextThe LpContext memory.
    paramstruct PositionParamThe PositionParam memory.

onClaimPosition

function onClaimPosition(struct BinClosedPosition self, struct LpContext ctx, struct PositionParam param) internal

Claims the position within the BinClosedPosition.

If the closeVersion is equal to the BinClosingPosition's closeVersion, the claim is made directly. Otherwise, the claim is made from the waiting position, and if exhausted, the waiting position is removed. The accrued interest is accumulated and deducted accordingly.

  • Parameters:

    NameTypeDescription
    selfstruct BinClosedPositionThe BinClosedPosition storage.
    ctxstruct LpContextThe LpContext memory.
    paramstruct PositionParamThe PositionParam memory.

totalMakerMargin

function totalMakerMargin(struct BinClosedPosition self) internal view returns (uint256)

Returns the total maker margin for a liquidity bin closed position.

  • Parameters:

    NameTypeDescription
    selfstruct BinClosedPositionThe BinClosedPosition storage struct.
  • Return Values:

    NameTypeDescription
    [0]uint256uint256 The total maker margin.

totalTakerMargin

function totalTakerMargin(struct BinClosedPosition self) internal view returns (uint256)

Returns the total taker margin for a liquidity bin closed position.

  • Parameters:

    NameTypeDescription
    selfstruct BinClosedPositionThe BinClosedPosition storage struct.
  • Return Values:

    NameTypeDescription
    [0]uint256uint256 The total taker margin.

closingPosition

function closingPosition(struct BinClosedPosition self) internal view returns (struct ClosingPosition)

Retrieves the closing position information.

  • Parameters:

    NameTypeDescription
    selfstruct BinClosedPositionThe reference to the BinClosedPosition struct.
  • Return Values:

    NameTypeDescription
    [0]struct ClosingPositionclosingPosition An instance of ClosingPosition representing the closing position information.

currentInterest

function currentInterest(struct BinClosedPosition self, struct LpContext ctx) internal view returns (uint256)

Calculates the current interest for a liquidity bin closed position.

  • Parameters:

    NameTypeDescription
    selfstruct BinClosedPositionThe BinClosedPosition storage struct.
    ctxstruct LpContextThe LpContext data struct.
  • Return Values:

    NameTypeDescription
    [0]uint256uint256 The current interest.