UsdnProtocolActions
Inherits: IUsdnProtocolActions, InitializableReentrancyGuard, PausableUpgradeable, EIP712Upgradeable
Functions
initiateOpenPosition
Initiates an open position action.
Consult the current oracle middleware for price data format and possible oracle fee.
Requires _securityDepositValue
to be included in the transaction value. In case of pending liquidations, this
function will not initiate the position (isInitiated_
would be false).
The user's input for price and leverage is not guaranteed due to the price difference between the initiate and
validate actions.
function initiateOpenPosition(
uint128 amount,
uint128 desiredLiqPrice,
uint128 userMaxPrice,
uint256 userMaxLeverage,
address to,
address payable validator,
uint256 deadline,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData
) external payable whenNotPaused initializedAndNonReentrant returns (bool isInitiated_, PositionId memory posId_);
Parameters
Name | Type | Description |
---|---|---|
amount | uint128 | The amount of assets to deposit. |
desiredLiqPrice | uint128 | The desired liquidation price, including the penalty. |
userMaxPrice | uint128 | The user's wanted maximum price at which the position can be opened. |
userMaxLeverage | uint256 | The user's wanted maximum leverage for the new position. |
to | address | The address that will owns of the position. |
validator | address payable | The address that is supposed to validate the opening and receive the security deposit. If not an EOA, it must be a contract that implements a receive function. |
deadline | uint256 | The deadline for initiating the open position. |
currentPriceData | bytes | The price data used for temporary leverage and entry price computations. |
previousActionsData | PreviousActionsData | The data needed to validate actionable pending actions. |
Returns
Name | Type | Description |
---|---|---|
isInitiated_ | bool | Whether the position was successfully initiated. If false, the security deposit was refunded |
posId_ | PositionId | The unique position identifier. If the position was not initiated, the tick number will be NO_POSITION_TICK . |
validateOpenPosition
Validates a pending open position action.
Consult the current oracle middleware for price data format and possible oracle fee.
It is possible for this operation to change the tick, tick version and index of the position, in which case we emit
the LiquidationPriceUpdated
event.
This function always sends the security deposit to the validator. So users wanting to earn the corresponding
security deposit must use validateActionablePendingActions
.
In case liquidations are pending (outcome_ == LongActionOutcome.PendingLiquidations
), the pending action will
not be removed from the queue, and the user will have to try again.
In case the position was liquidated by this call (outcome_ == LongActionOutcome.Liquidated
), this function will
refund the security deposit and remove the pending action from the queue.
function validateOpenPosition(
address payable validator,
bytes calldata openPriceData,
PreviousActionsData calldata previousActionsData
)
external
payable
whenNotPaused
initializedAndNonReentrant
returns (LongActionOutcome outcome_, PositionId memory posId_);
Parameters
Name | Type | Description |
---|---|---|
validator | address payable | The address associated with the pending open position. If not an EOA, it must be a contract that implements a receive function. |
openPriceData | bytes | The price data for the pending open position. |
previousActionsData | PreviousActionsData | The data needed to validate actionable pending actions. |
Returns
Name | Type | Description |
---|---|---|
outcome_ | LongActionOutcome | The effect on the pending action (processed, liquidated, or pending liquidations). |
posId_ | PositionId | The position ID after validation (or NO_POSITION_TICK if liquidated). |
initiateClosePosition
Initiates a close position action.
Consult the current oracle middleware for price data format and possible oracle fee.
Requires _securityDepositValue
to be included in the transaction value.
If the current tick version is greater than the tick version of the position (when it was opened), then the
position has been liquidated and the transaction will revert.
In case liquidations are pending (outcome_ == LongActionOutcome.PendingLiquidations
), the pending action will
not be removed from the queue, and the user will have to try again.
In case the position was liquidated by this call (outcome_ == LongActionOutcome.Liquidated
), this function will
refund the security deposit and remove the pending action from the queue.
The user's input for the price is not guaranteed due to the price difference between the initiate and validate
actions.
function initiateClosePosition(
PositionId calldata posId,
uint128 amountToClose,
uint256 userMinPrice,
address to,
address payable validator,
uint256 deadline,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData,
bytes calldata delegationSignature
) external payable whenNotPaused initializedAndNonReentrant returns (LongActionOutcome outcome_);
Parameters
Name | Type | Description |
---|---|---|
posId | PositionId | The unique identifier of the position to close. |
amountToClose | uint128 | The amount of collateral to remove. |
userMinPrice | uint256 | The user's wanted minimum price for closing the position. |
to | address | The address that will receive the assets. |
validator | address payable | The address that is supposed to validate the closing and receive the security deposit. If not an EOA, it must be a contract that implements a receive function. |
deadline | uint256 | The deadline for initiating the close position. |
currentPriceData | bytes | The price data for temporary calculations. |
previousActionsData | PreviousActionsData | The data needed to validate actionable pending actions. |
delegationSignature | bytes | Optional EIP712 signature for delegated action. |
Returns
Name | Type | Description |
---|---|---|
outcome_ | LongActionOutcome | The effect on the pending action (processed, liquidated, or pending liquidations). |
validateClosePosition
Validates a pending close position action.
Consult the current oracle middleware for price data format and possible oracle fee.
This function calculates the final exit price, determines the profit of the long position, and performs the
payout.
This function always sends the security deposit to the validator. So users wanting to earn the corresponding
security deposit must use validateActionablePendingActions
.
In case liquidations are pending (outcome_ == LongActionOutcome.PendingLiquidations
),
the pending action will not be removed from the queue, and the user will have to try again.
In case the position was liquidated by this call (outcome_ == LongActionOutcome.Liquidated
),
this function will refund the security deposit and remove the pending action from the queue.
function validateClosePosition(
address payable validator,
bytes calldata closePriceData,
PreviousActionsData calldata previousActionsData
) external payable whenNotPaused initializedAndNonReentrant returns (LongActionOutcome outcome_);
Parameters
Name | Type | Description |
---|---|---|
validator | address payable | The address associated with the pending close position. If not an EOA, it must be a contract that implements a receive function. |
closePriceData | bytes | The price data for the pending close position action. |
previousActionsData | PreviousActionsData | The data required to validate actionable pending actions. |
Returns
Name | Type | Description |
---|---|---|
outcome_ | LongActionOutcome | The outcome of the action (processed, liquidated, or pending liquidations). |
initiateDeposit
Initiates a deposit of assets into the vault to mint USDN.
Consult the current oracle middleware for price data format and possible oracle fee.
Requires _securityDepositValue
to be included in the transaction value.
In case liquidations are pending, this function might not initiate the deposit, and success_
would be false.
The user's input for the shares is not guaranteed due to the price difference between the initiate and validate
actions.
function initiateDeposit(
uint128 amount,
uint256 sharesOutMin,
address to,
address payable validator,
uint256 deadline,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData
) external payable whenNotPaused initializedAndNonReentrant returns (bool success_);
Parameters
Name | Type | Description |
---|---|---|
amount | uint128 | The amount of assets to deposit. |
sharesOutMin | uint256 | The minimum amount of USDN shares to receive. |
to | address | The address that will receive the USDN tokens. |
validator | address payable | The address that is supposed to validate the deposit and receive the security deposit. If not an EOA, it must be a contract that implements a receive function. |
deadline | uint256 | The deadline for initiating the deposit. |
currentPriceData | bytes | The current price data. |
previousActionsData | PreviousActionsData | The data required to validate actionable pending actions. |
Returns
Name | Type | Description |
---|---|---|
success_ | bool | Indicates whether the deposit was successfully initiated. |
validateDeposit
Validates a pending deposit action.
Consult the current oracle middleware for price data format and possible oracle fee.
This function always sends the security deposit to the validator. So users wanting to earn the corresponding
security deposit must use validateActionablePendingActions
.
If liquidations are pending, the validation may fail, and success_
would be false.
function validateDeposit(
address payable validator,
bytes calldata depositPriceData,
PreviousActionsData calldata previousActionsData
) external payable whenNotPaused initializedAndNonReentrant returns (bool success_);
Parameters
Name | Type | Description |
---|---|---|
validator | address payable | The address associated with the pending deposit action. If not an EOA, it must be a contract that implements a receive function. |
depositPriceData | bytes | The price data for the pending deposit action. |
previousActionsData | PreviousActionsData | The data required to validate actionable pending actions. |
Returns
Name | Type | Description |
---|---|---|
success_ | bool | Indicates whether the deposit was successfully validated. |
initiateWithdrawal
Initiates a withdrawal of assets from the vault using USDN tokens.
Consult the current oracle middleware for price data format and possible oracle fee.
Requires _securityDepositValue
to be included in the transaction value.
Note that in case liquidations are pending, this function might not initiate the withdrawal, and success_
would
be false.
The user's input for the minimum amount is not guaranteed due to the price difference between the initiate and
validate actions.
function initiateWithdrawal(
uint152 usdnShares,
uint256 amountOutMin,
address to,
address payable validator,
uint256 deadline,
bytes calldata currentPriceData,
PreviousActionsData calldata previousActionsData
) external payable whenNotPaused initializedAndNonReentrant returns (bool success_);
Parameters
Name | Type | Description |
---|---|---|
usdnShares | uint152 | The amount of USDN shares to burn. |
amountOutMin | uint256 | The minimum amount of assets to receive. |
to | address | The address that will receive the assets. |
validator | address payable | The address that is supposed to validate the withdrawal and receive the security deposit. If not an EOA, it must be a contract that implements a receive function. |
deadline | uint256 | The deadline for initiating the withdrawal. |
currentPriceData | bytes | The current price data. |
previousActionsData | PreviousActionsData | The data required to validate actionable pending actions. |
Returns
Name | Type | Description |
---|---|---|
success_ | bool | Indicates whether the withdrawal was successfully initiated. |
validateWithdrawal
Validates a pending withdrawal action.
Consult the current oracle middleware for price data format and possible oracle fee.
This function always sends the security deposit to the validator. So users wanting to earn the corresponding
security deposit must use validateActionablePendingActions
.
In case liquidations are pending, this function might not validate the withdrawal, and success_
would be false.
function validateWithdrawal(
address payable validator,
bytes calldata withdrawalPriceData,
PreviousActionsData calldata previousActionsData
) external payable whenNotPaused initializedAndNonReentrant returns (bool success_);
Parameters
Name | Type | Description |
---|---|---|
validator | address payable | The address associated with the pending withdrawal action. If not an EOA, it must be a contract that implements a receive function. |
withdrawalPriceData | bytes | The price data for the pending withdrawal action. |
previousActionsData | PreviousActionsData | The data required to validate actionable pending actions. |
Returns
Name | Type | Description |
---|---|---|
success_ | bool | Indicates whether the withdrawal was successfully validated. |
liquidate
Liquidates positions based on the provided asset price.
Consult the current oracle middleware for price data format and possible oracle fee. Each tick is liquidated in constant time. The tick version is incremented for each liquidated tick.
function liquidate(bytes calldata currentPriceData)
external
payable
whenNotPaused
initializedAndNonReentrant
returns (LiqTickInfo[] memory liquidatedTicks_);
Parameters
Name | Type | Description |
---|---|---|
currentPriceData | bytes | The price data. |
Returns
Name | Type | Description |
---|---|---|
liquidatedTicks_ | LiqTickInfo[] | Information about the liquidated ticks. |
validateActionablePendingActions
Manually validates actionable pending actions.
Consult the current oracle middleware for price data format and possible oracle fee.
The timestamp for each pending action is calculated by adding the OracleMiddleware.validationDelay
to its
initiation timestamp.
function validateActionablePendingActions(PreviousActionsData calldata previousActionsData, uint256 maxValidations)
external
payable
whenNotPaused
initializedAndNonReentrant
returns (uint256 validatedActions_);
Parameters
Name | Type | Description |
---|---|---|
previousActionsData | PreviousActionsData | The data required to validate actionable pending actions. |
maxValidations | uint256 | The maximum number of actionable pending actions to validate. At least one validation will be performed. |
Returns
Name | Type | Description |
---|---|---|
validatedActions_ | uint256 | The number of successfully validated actions. |
transferPositionOwnership
Transfers the ownership of a position to another address.
This function reverts if the caller is not the position owner, if the position does not exist, or if the new
owner's address is the zero address.
If the new owner is a contract that implements the IOwnershipCallback
interface, its ownershipCallback
function will be invoked after the transfer.
function transferPositionOwnership(PositionId calldata posId, address newOwner, bytes calldata delegationSignature)
external
whenNotPaused
initializedAndNonReentrant;
Parameters
Name | Type | Description |
---|---|---|
posId | PositionId | The unique identifier of the position. |
newOwner | address | The address of the new position owner. |
delegationSignature | bytes | An optional EIP712 signature to authorize the transfer on the owner's behalf. |
domainSeparatorV4
Retrieves the domain separator used in EIP-712 signatures.
function domainSeparatorV4() external view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | domainSeparatorV4_ The domain separator compliant with EIP-712. |