UsdnProtocolActionsUtilsLibrary
Functions
liquidate
See liquidate.
function liquidate(bytes calldata currentPriceData) external returns (Types.LiqTickInfo[] memory liquidatedTicks_);
validateActionablePendingActions
See validateActionablePendingActions.
function validateActionablePendingActions(
Types.PreviousActionsData calldata previousActionsData,
uint256 maxValidations
) external returns (uint256 validatedActions_);
transferPositionOwnership
See transferPositionOwnership.
function transferPositionOwnership(
Types.PositionId calldata posId,
address newOwner,
bytes calldata delegationSignature,
bytes32 domainSeparatorV4
) external;
_checkImbalanceLimitWithdrawal
Checks and reverts if the withdrawn value breaks the imbalance limits.
function _checkImbalanceLimitWithdrawal(uint256 withdrawalValue, uint256 totalExpo) external view;
Parameters
Name | Type | Description |
---|---|---|
withdrawalValue | uint256 | The withdrawal value in asset. |
totalExpo | uint256 | The current total exposure of the long side. |
_checkImbalanceLimitDeposit
Checks and reverts if the deposited value breaks the imbalance limits.
function _checkImbalanceLimitDeposit(uint256 depositValue) external view;
Parameters
Name | Type | Description |
---|---|---|
depositValue | uint256 | The deposit value in asset. |
getLongPosition
See getLongPosition.
function getLongPosition(Types.PositionId memory posId)
public
view
returns (Types.Position memory pos_, uint24 liquidationPenalty_);
_prepareClosePositionData
Updates the protocol state, then prepares the data for the initiate close position action.
Reverts if the imbalance limit is reached, or if any checks in _checkInitiateClosePosition fail. Returns without creating a pending action if the position gets liquidated in this transaction or if there are still positions pending liquidation.
function _prepareClosePositionData(Types.PrepareInitiateClosePositionParams calldata params)
public
returns (Types.ClosePositionData memory data_, bool liquidated_);
Parameters
Name | Type | Description |
---|---|---|
params | Types.PrepareInitiateClosePositionParams | The parameters for the _prepareClosePositionData function. |
Returns
Name | Type | Description |
---|---|---|
data_ | Types.ClosePositionData | The close position data. |
liquidated_ | bool | Indicates whether the position was liquidated. |
_validateMultipleActionable
Validates multiple actionable pending actions.
function _validateMultipleActionable(Types.PreviousActionsData calldata previousActionsData, uint256 maxValidations)
internal
returns (uint256 validatedActions_, uint256 amountToRefund_);
Parameters
Name | Type | Description |
---|---|---|
previousActionsData | Types.PreviousActionsData | The data for the actions to validate (price and raw indices). |
maxValidations | uint256 | The maximum number of validations to perform. |
Returns
Name | Type | Description |
---|---|---|
validatedActions_ | uint256 | The number of actions successfully validated. |
amountToRefund_ | uint256 | The total amount of security deposits to be refunded. |
_isActionable
Checks whether a pending action is actionable, allowing any user to validate it and claim the security deposit.
Between initiateTimestamp
and initiateTimestamp + lowLatencyDeadline
,
the validator receives the security deposit.
Between initiateTimestamp + lowLatencyDelay
and initiateTimestamp + lowLatencyDelay + onChainDeadline
,
the validator also receives the security deposit.
Outside of those periods, the security deposit goes to the user validating the pending action.
function _isActionable(
uint256 initiateTimestamp,
uint256 lowLatencyDeadline,
uint256 lowLatencyDelay,
uint256 onChainDeadline
) internal view returns (bool actionable_);
Parameters
Name | Type | Description |
---|---|---|
initiateTimestamp | uint256 | The timestamp at which the action was initiated. |
lowLatencyDeadline | uint256 | The deadline after which the action is actionable within a low latency oracle. |
lowLatencyDelay | uint256 | The amount of time the action can be validated with a low latency oracle. |
onChainDeadline | uint256 | The deadline after which the action is actionable with an on-chain oracle. |
Returns
Name | Type | Description |
---|---|---|
actionable_ | bool | Indicates whether the pending action is actionable. |
_checkImbalanceLimitClose
Checks the close vault imbalance limit state.
Ensures that the protocol does not imbalance more than the close limit on the vault side, otherwise revert.
function _checkImbalanceLimitClose(uint256 posTotalExpoToClose, uint256 posValueToClose) internal view;
Parameters
Name | Type | Description |
---|---|---|
posTotalExpoToClose | uint256 | The total exposure to remove from the position. |
posValueToClose | uint256 | The value to remove from the position (and the long balance). |
_checkInitiateClosePosition
Performs checks for the initiate close position action.
function _checkInitiateClosePosition(
Types.Position memory pos,
Types.PrepareInitiateClosePositionParams calldata params
) internal;
Parameters
Name | Type | Description |
---|---|---|
pos | Types.Position | The position to close. |
params | Types.PrepareInitiateClosePositionParams | The parameters for the _prepareClosePositionData function. |
_assetToRemove
Calculates how much assets must be removed from the long balance due to a position closing.
The amount is bound by the amount of assets available on the long side.
function _assetToRemove(uint256 balanceLong, uint128 price, uint128 liqPriceWithoutPenalty, uint128 posExpo)
internal
pure
returns (uint256 boundedPosValue_);
Parameters
Name | Type | Description |
---|---|---|
balanceLong | uint256 | The balance of the long side. |
price | uint128 | The price to use for the position value calculation. |
liqPriceWithoutPenalty | uint128 | The liquidation price without penalty. |
posExpo | uint128 | The total exposure to remove from the position. |
Returns
Name | Type | Description |
---|---|---|
boundedPosValue_ | uint256 | The amount of assets to remove from the long balance. |
_verifyInitiateCloseDelegation
Performs the initiateClosePosition EIP712 delegation signature verification.
Reverts if the function arguments don't match those included in the signature and if the signer isn't the owner of the position.
function _verifyInitiateCloseDelegation(Types.PrepareInitiateClosePositionParams calldata params, address positionOwner)
internal;
Parameters
Name | Type | Description |
---|---|---|
params | Types.PrepareInitiateClosePositionParams | The parameters for the _prepareClosePositionData function. |
positionOwner | address | The position owner. |
_verifyTransferPositionOwnershipDelegation
Performs the transferPositionOwnership EIP712 delegation signature verification.
Reverts if the function arguments don't match those included in the signature and if the signer isn't the owner of the position.
function _verifyTransferPositionOwnershipDelegation(
Types.PositionId calldata posId,
address positionOwner,
address newPositionOwner,
bytes calldata delegationSignature,
bytes32 domainSeparatorV4
) internal;
Parameters
Name | Type | Description |
---|---|---|
posId | Types.PositionId | The unique identifier of the position. |
positionOwner | address | The current position owner. |
newPositionOwner | address | The new position owner. |
delegationSignature | bytes | An EIP712 signature that proves the caller is authorized by the owner of the position to transfer the ownership to a different address on his behalf. |
domainSeparatorV4 | bytes32 | The domain separator v4. |
Structs
ValidateMultipleActionableData
Data structure for the transient state of the _validateMultipleActionable function.
struct ValidateMultipleActionableData {
Types.PendingAction pending;
uint128 frontRawIndex;
uint128 rawIndex;
bool executed;
bool liq;
}
Properties
Name | Type | Description |
---|---|---|
pending | Types.PendingAction | The candidate pending action to validate. |
frontRawIndex | uint128 | The raw index of the front of the queue. |
rawIndex | uint128 | The raw index of the candidate pending action in the queue. |
executed | bool | Indicates whether the pending action has been executed. |
liq | bool | Indicates whether the pending action has been liquidated. |