UsdnProtocolLong
Inherits: IUsdnProtocolLong
Functions
minTick
Gets the value of the lowest usable tick, taking into account the tick spacing.
Note that the effective minimum tick of a newly open long position also depends on the minimum allowed leverage value and the current value of the liquidation price multiplier.
function minTick() external view returns (int24 tick_);
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The lowest usable tick. |
getLiqPriceFromDesiredLiqPrice
Gets the liquidation price from a desired one by taking into account the tick rounding.
function getLiqPriceFromDesiredLiqPrice(
uint128 desiredLiqPriceWithoutPenalty,
uint256 assetPrice,
uint256 longTradingExpo,
HugeUint.Uint512 memory accumulator,
int24 tickSpacing,
uint24 liquidationPenalty
) external pure returns (uint128 liqPrice_);
Parameters
Name | Type | Description |
---|---|---|
desiredLiqPriceWithoutPenalty | uint128 | The desired liquidation price without the penalty. |
assetPrice | uint256 | The current price of the asset. |
longTradingExpo | uint256 | The trading exposition of the long side. |
accumulator | HugeUint.Uint512 | The liquidation multiplier accumulator. |
tickSpacing | int24 | The tick spacing. |
liquidationPenalty | uint24 | The liquidation penalty set on the tick. |
Returns
Name | Type | Description |
---|---|---|
liqPrice_ | uint128 | The new liquidation price without the penalty. |
getPositionValue
Gets the value of a long position when the asset price is equal to the given price, at the given timestamp.
If the current price is smaller than the liquidation price of the position without the liquidation penalty, then the value of the position is negative.
function getPositionValue(PositionId calldata posId, uint128 price, uint128 timestamp)
external
view
returns (int256 value_);
Parameters
Name | Type | Description |
---|---|---|
posId | PositionId | The unique position identifier. |
price | uint128 | The asset price. |
timestamp | uint128 | The timestamp of the price. |
Returns
Name | Type | Description |
---|---|---|
value_ | int256 | The position value in assets. |
getEffectiveTickForPrice
Gets the tick number corresponding to a given price, accounting for funding effects.
Uses the stored parameters for calculation.
function getEffectiveTickForPrice(uint128 price) external view returns (int24 tick_);
Parameters
Name | Type | Description |
---|---|---|
price | uint128 | The asset price. |
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The tick number, a multiple of the tick spacing. |
getEffectiveTickForPrice
Gets the tick number corresponding to a given price, accounting for funding effects.
Uses the stored parameters for calculation.
function getEffectiveTickForPrice(
uint128 price,
uint256 assetPrice,
uint256 longTradingExpo,
HugeUint.Uint512 memory accumulator,
int24 tickSpacing
) external pure returns (int24 tick_);
Parameters
Name | Type | Description |
---|---|---|
price | uint128 | The asset price. |
assetPrice | uint256 | |
longTradingExpo | uint256 | |
accumulator | HugeUint.Uint512 | |
tickSpacing | int24 |
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The tick number, a multiple of the tick spacing. |
getTickLiquidationPenalty
Retrieves the liquidation penalty assigned to the given tick if there are positions in it, otherwise retrieve the current setting value from storage.
function getTickLiquidationPenalty(int24 tick) external view returns (uint24 liquidationPenalty_);
Parameters
Name | Type | Description |
---|---|---|
tick | int24 | The tick number. |
Returns
Name | Type | Description |
---|---|---|
liquidationPenalty_ | uint24 | The liquidation penalty, in tick spacing units. |
getLongPosition
Gets a long position identified by its tick, tick version and index.
function getLongPosition(PositionId memory posId)
external
view
returns (Position memory pos_, uint24 liquidationPenalty_);
Parameters
Name | Type | Description |
---|---|---|
posId | PositionId | The unique position identifier. |
Returns
Name | Type | Description |
---|---|---|
pos_ | Position | The position data. |
liquidationPenalty_ | uint24 | The liquidation penalty for that position. |
longAssetAvailableWithFunding
Gets the predicted value of the long balance for the given asset price and timestamp.
The effects of the funding and any PnL of the long positions since the last contract state
update is taken into account, as well as the fees. If the provided timestamp is older than the last state
update, the function reverts with UsdnProtocolTimestampTooOld
. The value cannot be below 0.
function longAssetAvailableWithFunding(uint128 currentPrice, uint128 timestamp)
external
view
returns (uint256 available_);
Parameters
Name | Type | Description |
---|---|---|
currentPrice | uint128 | The given asset price. |
timestamp | uint128 | The timestamp corresponding to the given price. |
Returns
Name | Type | Description |
---|---|---|
available_ | uint256 | The long balance value in assets. |
longTradingExpoWithFunding
Gets the predicted value of the long trading exposure for the given asset price and timestamp.
The effects of the funding and any profit or loss of the long positions since the last contract state
update is taken into account. If the provided timestamp is older than the last state update, the function reverts
with UsdnProtocolTimestampTooOld
. The value cannot be below 0.
function longTradingExpoWithFunding(uint128 currentPrice, uint128 timestamp) external view returns (uint256 expo_);
Parameters
Name | Type | Description |
---|---|---|
currentPrice | uint128 | The given asset price. |
timestamp | uint128 | The timestamp corresponding to the given price. |
Returns
Name | Type | Description |
---|---|---|
expo_ | uint256 | The long trading exposure value in assets. |