IUsdnProtocolLong

Git Source

Inherits: IUsdnProtocolTypes

Interface for the long side layer of the USDN protocol.

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

NameTypeDescription
tick_int24The 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 view returns (uint128 liqPrice_);

Parameters

NameTypeDescription
desiredLiqPriceWithoutPenaltyuint128The desired liquidation price without the penalty.
assetPriceuint256The current price of the asset.
longTradingExpouint256The trading exposition of the long side.
accumulatorHugeUint.Uint512The liquidation multiplier accumulator.
tickSpacingint24The tick spacing.
liquidationPenaltyuint24The liquidation penalty set on the tick.

Returns

NameTypeDescription
liqPrice_uint128The 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

NameTypeDescription
posIdPositionIdThe unique position identifier.
priceuint128The asset price.
timestampuint128The timestamp of the price.

Returns

NameTypeDescription
value_int256The 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

NameTypeDescription
priceuint128The asset price.

Returns

NameTypeDescription
tick_int24The tick number, a multiple of the tick spacing.

getEffectiveTickForPrice

Gets the tick number corresponding to a given price, accounting for funding effects.

function getEffectiveTickForPrice(
    uint128 price,
    uint256 assetPrice,
    uint256 longTradingExpo,
    HugeUint.Uint512 memory accumulator,
    int24 tickSpacing
) external view returns (int24 tick_);

Parameters

NameTypeDescription
priceuint128The asset price.
assetPriceuint256The current price of the asset.
longTradingExpouint256The trading exposition of the long side.
accumulatorHugeUint.Uint512The liquidation multiplier accumulator.
tickSpacingint24The tick spacing.

Returns

NameTypeDescription
tick_int24The 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

NameTypeDescription
tickint24The tick number.

Returns

NameTypeDescription
liquidationPenalty_uint24The liquidation penalty, in tick spacing units.

getLongPosition

Gets a long position identified by its tick, tick version and index.

function getLongPosition(PositionId calldata posId)
    external
    view
    returns (Position memory pos_, uint24 liquidationPenalty_);

Parameters

NameTypeDescription
posIdPositionIdThe unique position identifier.

Returns

NameTypeDescription
pos_PositionThe position data.
liquidationPenalty_uint24The 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

NameTypeDescription
currentPriceuint128The given asset price.
timestampuint128The timestamp corresponding to the given price.

Returns

NameTypeDescription
available_uint256The 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

NameTypeDescription
currentPriceuint128The given asset price.
timestampuint128The timestamp corresponding to the given price.

Returns

NameTypeDescription
expo_uint256The long trading exposure value in assets.