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:
Name Type Description self struct BinClosedPosition The BinClosedPosition storage. ctx struct LpContext The 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:
Name Type Description self struct BinClosedPosition The BinClosedPosition storage. ctx struct LpContext The LpContext memory. param struct PositionParam The 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:
Name Type Description self struct BinClosedPosition The BinClosedPosition storage. ctx struct LpContext The LpContext memory. param struct PositionParam The PositionParam memory.
totalMakerMargin
function totalMakerMargin(struct BinClosedPosition self) internal view returns (uint256)
Returns the total maker margin for a liquidity bin closed position.
Parameters:
Name Type Description self struct BinClosedPosition The BinClosedPosition storage struct. Return Values:
Name Type Description [0] uint256 uint256 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:
Name Type Description self struct BinClosedPosition The BinClosedPosition storage struct. Return Values:
Name Type Description [0] uint256 uint256 The total taker margin.
closingPosition
function closingPosition(struct BinClosedPosition self) internal view returns (struct ClosingPosition)
Retrieves the closing position information.
Parameters:
Name Type Description self struct BinClosedPosition The reference to the BinClosedPosition struct. Return Values:
Name Type Description [0] struct ClosingPosition closingPosition 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:
Name Type Description self struct BinClosedPosition The BinClosedPosition storage struct. ctx struct LpContext The LpContext data struct. Return Values:
Name Type Description [0] uint256 uint256 The current interest.