UsdnProtocolLongLibrary
Functions
getPositionValue
See getPositionValue.
function getPositionValue(Types.PositionId calldata posId, uint128 price, uint128 timestamp)
external
view
returns (int256 value_);
getEffectiveTickForPrice
function getEffectiveTickForPrice(uint128 price) external view returns (int24 tick_);
minTick
See minTick.
function minTick() public view returns (int24 tick_);
getTickLiquidationPenalty
See getTickLiquidationPenalty.
function getTickLiquidationPenalty(int24 tick) public view returns (uint24 liquidationPenalty_);
getEffectiveTickForPrice
function getEffectiveTickForPrice(
uint128 price,
uint256 assetPrice,
uint256 longTradingExpo,
HugeUint.Uint512 memory accumulator,
int24 tickSpacing
) public pure returns (int24 tick_);
_applyPnlAndFundingAndLiquidate
Applies PnL, funding, and liquidates positions if necessary.
If there were any liquidations, it sends the rewards to the msg.sender
.
function _applyPnlAndFundingAndLiquidate(
uint256 neutralPrice,
uint256 timestamp,
uint16 iterations,
Types.ProtocolAction action,
bytes calldata priceData
) public returns (Types.LiqTickInfo[] memory liquidatedTicks_, bool isLiquidationPending_);
Parameters
Name | Type | Description |
---|---|---|
neutralPrice | uint256 | The neutral price for the asset. |
timestamp | uint256 | The timestamp at which the operation is performed. |
iterations | uint16 | The number of iterations for the liquidation process. |
action | Types.ProtocolAction | The type of action that is being performed by the user. |
priceData | bytes | The data given to the oracle middleware corresponding to neutralPrice . |
Returns
Name | Type | Description |
---|---|---|
liquidatedTicks_ | Types.LiqTickInfo[] | Information about the liquidated ticks. |
isLiquidationPending_ | bool | If there are remaining ticks that can be liquidated. |
_prepareInitiateOpenPositionData
Prepares the data for the initiateOpenPosition
function.
function _prepareInitiateOpenPositionData(Types.PrepareInitiateOpenPositionParams calldata params)
public
returns (Types.InitiateOpenPositionData memory data_);
Parameters
Name | Type | Description |
---|---|---|
params | Types.PrepareInitiateOpenPositionParams | The parameters for the _prepareInitiateOpenPositionData function. |
Returns
Name | Type | Description |
---|---|---|
data_ | Types.InitiateOpenPositionData | The transient data for the open position action. |
_removeAmountFromPosition
Removes amountToRemove
from position pos
then updates the tick data and the position.
This method does not update the long balance. If the amount to remove is greater than or equal to the position's total amount, the position is deleted instead.
function _removeAmountFromPosition(
int24 tick,
uint256 index,
Types.Position memory pos,
uint128 amountToRemove,
uint128 totalExpoToRemove
) public returns (HugeUint.Uint512 memory liqMultiplierAccumulator_);
Parameters
Name | Type | Description |
---|---|---|
tick | int24 | The tick the position is in. |
index | uint256 | Index of the position in the tick array. |
pos | Types.Position | The position to remove the amount from. |
amountToRemove | uint128 | The amount to remove from the position. |
totalExpoToRemove | uint128 | The total exposure to remove from the position. |
Returns
Name | Type | Description |
---|---|---|
liqMultiplierAccumulator_ | HugeUint.Uint512 | The updated liquidation multiplier accumulator. |
_getTickFromDesiredLiqPrice
Computes the tick number with penalty and liquidation price without penalty from the desired liquidation price.
This function first calculates a tick for the desired liquidation price (no rounding), then adds the penalty to the tick and rounds down to the nearest tick spacing. Then it subtracts the penalty from the final tick and calculates the corresponding liquidation price.
function _getTickFromDesiredLiqPrice(uint128 desiredLiqPriceWithoutPenalty, uint24 liquidationPenalty)
public
view
returns (int24 tickWithPenalty_, uint128 liqPriceWithoutPenalty_);
Parameters
Name | Type | Description |
---|---|---|
desiredLiqPriceWithoutPenalty | uint128 | The desired liquidation price without penalty. |
liquidationPenalty | uint24 | The liquidation penalty. |
Returns
Name | Type | Description |
---|---|---|
tickWithPenalty_ | int24 | The tick number including the liquidation penalty. |
liqPriceWithoutPenalty_ | uint128 | The liquidation price without penalty. |
_getTickFromDesiredLiqPrice
Computes the tick number with penalty and liquidation price without penalty from the desired liquidation price and protocol state.
This function first calculates a tick for the desired liquidation price (no rounding), then adds the penalty to the tick and rounds down to the nearest tick spacing. Then it subtracts the penalty from the final tick and calculates the corresponding liquidation price.
function _getTickFromDesiredLiqPrice(
uint128 desiredLiqPriceWithoutPenalty,
uint256 assetPrice,
uint256 longTradingExpo,
HugeUint.Uint512 memory accumulator,
int24 tickSpacing,
uint24 liquidationPenalty
) public pure returns (int24 tickWithPenalty_, uint128 liqPriceWithoutPenalty_);
Parameters
Name | Type | Description |
---|---|---|
desiredLiqPriceWithoutPenalty | uint128 | The desired liquidation price without penalty. |
assetPrice | uint256 | The current price of the asset. |
longTradingExpo | uint256 | The trading exposure of the long side (total exposure - balance long). |
accumulator | HugeUint.Uint512 | The liquidation multiplier accumulator. |
tickSpacing | int24 | The tick spacing. |
liquidationPenalty | uint24 | The liquidation penalty. |
Returns
Name | Type | Description |
---|---|---|
tickWithPenalty_ | int24 | The tick number including the liquidation penalty. |
liqPriceWithoutPenalty_ | uint128 | The liquidation price without penalty. |
_getTickFromDesiredLiqPrice
Computes the tick number with penalty and liquidation price without penalty from the desired liquidation price and a fixed precision version of the liquidation multiplier accumulator.
This function first calculates a tick for the desired liquidation price (no rounding), then adds the penalty to the tick and rounds down to the nearest tick spacing. Then it subtracts the penalty from the final tick and calculates the corresponding liquidation price.
function _getTickFromDesiredLiqPrice(
uint128 desiredLiqPriceWithoutPenalty,
uint256 liqMultiplier,
int24 tickSpacing,
uint24 liquidationPenalty
) public pure returns (int24 tickWithPenalty_, uint128 liqPriceWithoutPenalty_);
Parameters
Name | Type | Description |
---|---|---|
desiredLiqPriceWithoutPenalty | uint128 | The desired liquidation price without penalty. |
liqMultiplier | uint256 | The liquidation price multiplier (with LIQUIDATION_MULTIPLIER_DECIMALS decimals). |
tickSpacing | int24 | The tick spacing. |
liquidationPenalty | uint24 | The liquidation penalty. |
Returns
Name | Type | Description |
---|---|---|
tickWithPenalty_ | int24 | The tick number including the liquidation penalty. |
liqPriceWithoutPenalty_ | uint128 | The liquidation price without penalty. |
_findHighestPopulatedTick
Finds the highest tick that contains at least one position.
If there are no ticks with a position left, returns minTick.
function _findHighestPopulatedTick(int24 searchStart) public view returns (int24 tick_);
Parameters
Name | Type | Description |
---|---|---|
searchStart | int24 | The tick to start searching from. |
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The highest tick at or below searchStart . |
_usdnRebase
Checks if a USDN rebase is required and adjust the divisor if needed.
Only call this function after _applyPnlAndFunding
has been called to update the balances.
function _usdnRebase(uint128 assetPrice) internal returns (bool rebased_, bytes memory callbackResult_);
Parameters
Name | Type | Description |
---|---|---|
assetPrice | uint128 | The current price of the underlying asset. |
Returns
Name | Type | Description |
---|---|---|
rebased_ | bool | Whether a rebase was performed. |
callbackResult_ | bytes | The rebase callback result, if any. |
_sendRewardsToLiquidator
Sends rewards to the liquidator.
Should still emit an event if liquidationRewards = 0 to better keep track of those anomalies as rewards for those will be managed off-chain.
function _sendRewardsToLiquidator(
Types.LiqTickInfo[] memory liquidatedTicks,
uint256 currentPrice,
bool rebased,
Types.RebalancerAction rebalancerAction,
Types.ProtocolAction action,
bytes memory rebaseCallbackResult,
bytes memory priceData
) internal;
Parameters
Name | Type | Description |
---|---|---|
liquidatedTicks | Types.LiqTickInfo[] | Information about the liquidated ticks. |
currentPrice | uint256 | The current price of the asset. |
rebased | bool | Whether a USDN rebase was performed. |
rebalancerAction | Types.RebalancerAction | The rebalancer action that was performed. |
action | Types.ProtocolAction | The protocol action that triggered liquidations. |
rebaseCallbackResult | bytes | The rebase callback result, if any. |
priceData | bytes | The data given to the oracle middleware to get a price. |
_triggerRebalancer
Triggers the rebalancer if the imbalance on the long side is too high. It will close the rebalancer's position (if there is one) and open a new one with the pending assets, the value of the previous position and the liquidation bonus (if available) with a leverage that would fill enough trading exposure to reach the desired imbalance, up to the max leverages.
Only call this function after liquidations are performed to have a non-zero remainingCollateral
value.
Will return the provided long and vault balances if no rebalancer is set or if the imbalance is not high enough.
If remainingCollateral
is negative, the rebalancer bonus will be 0.
function _triggerRebalancer(uint128 lastPrice, uint256 longBalance, uint256 vaultBalance, int256 remainingCollateral)
internal
returns (uint256 longBalance_, uint256 vaultBalance_, Types.RebalancerAction action_);
Parameters
Name | Type | Description |
---|---|---|
lastPrice | uint128 | The last price used to update the protocol. |
longBalance | uint256 | The balance of the long side. |
vaultBalance | uint256 | The balance of the vault side. |
remainingCollateral | int256 | The collateral remaining after the liquidations. |
Returns
Name | Type | Description |
---|---|---|
longBalance_ | uint256 | The updated long balance not saved into storage yet. |
vaultBalance_ | uint256 | The updated vault balance not saved into storage yet. |
action_ | Types.RebalancerAction | The action performed by this function. |
_flashOpenPosition
Immediately opens a position with the given price.
Should only be used to open the rebalancer's position.
function _flashOpenPosition(
address user,
uint128 lastPrice,
int24 tick,
uint128 posTotalExpo,
uint24 liquidationPenalty,
uint128 amount
) internal returns (Types.PositionId memory posId_);
Parameters
Name | Type | Description |
---|---|---|
user | address | The address of the rebalancer. |
lastPrice | uint128 | The last price used to update the protocol. |
tick | int24 | The tick the position should be opened in. |
posTotalExpo | uint128 | The total exposure of the position. |
liquidationPenalty | uint24 | The liquidation penalty of the tick. |
amount | uint128 | The amount of collateral in the position. |
Returns
Name | Type | Description |
---|---|---|
posId_ | Types.PositionId | The ID of the position that was created. |
_flashClosePosition
Immediately closes a position with the given price.
Should only be used to close the rebalancer's position.
function _flashClosePosition(Types.PositionId memory posId, uint128 lastPrice, Types.CachedProtocolState memory cache)
internal
returns (int256 positionValue_);
Parameters
Name | Type | Description |
---|---|---|
posId | Types.PositionId | The ID of the position to close. |
lastPrice | uint128 | The last price used to update the protocol. |
cache | Types.CachedProtocolState | The cached state of the protocol, will be updated during this call. |
Returns
Name | Type | Description |
---|---|---|
positionValue_ | int256 | The value of the closed position. |
_liquidatePositions
Liquidates positions that have a liquidation price lower than the current price.
function _liquidatePositions(uint256 currentPrice, uint16 iteration, int256 tempLongBalance, int256 tempVaultBalance)
internal
returns (Types.LiquidationsEffects memory effects_);
Parameters
Name | Type | Description |
---|---|---|
currentPrice | uint256 | The current price of the asset. |
iteration | uint16 | The maximum number of ticks to liquidate (minimum is 1). |
tempLongBalance | int256 | The temporary long balance as calculated when applying the PnL and funding. |
tempVaultBalance | int256 | The temporary vault balance as calculated when applying the PnL and funding. |
Returns
Name | Type | Description |
---|---|---|
effects_ | Types.LiquidationsEffects | The effects of the liquidations on the protocol. |
_updateStateAfterLiquidation
Updates the state of the contract according to the liquidation effects.
function _updateStateAfterLiquidation(LiquidationData memory data, Types.LiquidationsEffects memory effects) internal;
Parameters
Name | Type | Description |
---|---|---|
data | LiquidationData | The liquidation data, which gets mutated by the function. |
effects | Types.LiquidationsEffects | The effects of the liquidations. |
_checkImbalanceLimitOpen
Checks and reverts if the position's trading exposure exceeds the imbalance limits.
function _checkImbalanceLimitOpen(
uint256 openTotalExpoValue,
uint256 collateralAmount,
uint256 collateralAmountAfterFees
) internal view;
Parameters
Name | Type | Description |
---|---|---|
openTotalExpoValue | uint256 | The total exposure of the position to open. |
collateralAmount | uint256 | The amount of collateral of the position. |
collateralAmountAfterFees | uint256 | The amount of collateral of the position after fees. |
_calcRebalancerPositionTick
Calculates the tick of the rebalancer position to open.
The returned tick must give a leverage higher than or equal to the minimum leverage of the protocol and lower than or equal to the rebalancer and USDN protocol leverages (lowest of the 2).
function _calcRebalancerPositionTick(
uint128 lastPrice,
uint128 positionAmount,
uint256 rebalancerMaxLeverage,
Types.CachedProtocolState memory cache
) internal view returns (Types.RebalancerPositionData memory posData_);
Parameters
Name | Type | Description |
---|---|---|
lastPrice | uint128 | The last price used to update the protocol. |
positionAmount | uint128 | The amount of assets in the position. |
rebalancerMaxLeverage | uint256 | The maximum leverage supported by the rebalancer. |
cache | Types.CachedProtocolState | The cached protocol state values. |
Returns
Name | Type | Description |
---|---|---|
posData_ | Types.RebalancerPositionData | The tick, total exposure and liquidation penalty for the rebalancer position. |
_checkSafetyMargin
Checks and reverts if the leverage of a position exceeds the safety margin.
function _checkSafetyMargin(uint128 currentPrice, uint128 liquidationPrice) internal view;
Parameters
Name | Type | Description |
---|---|---|
currentPrice | uint128 | The current price of the asset. |
liquidationPrice | uint128 | The liquidation price of the position. |
_getTickLiquidationPenalty
Retrieves the liquidation penalty assigned to the given tickHash
.
If there are no positions in it, returns the current setting from storage.
function _getTickLiquidationPenalty(bytes32 tickHash) internal view returns (uint24 liquidationPenalty_);
Parameters
Name | Type | Description |
---|---|---|
tickHash | bytes32 | The tick hash (hashed tick number + version). |
Returns
Name | Type | Description |
---|---|---|
liquidationPenalty_ | uint24 | The liquidation penalty (in tick spacing units). |
_calcTickFromBitmapIndex
Converts the given bitmap index to a tick number using the stored tick spacing.
function _calcTickFromBitmapIndex(uint256 index) internal view returns (int24 tick_);
Parameters
Name | Type | Description |
---|---|---|
index | uint256 | The index into the bitmap. |
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The tick corresponding to the index, a multiple of the tick spacing. |
_unadjustPrice
Calculates the unadjusted price of a position's liquidation price, which can be used to find the corresponding tick.
function _unadjustPrice(uint256 price, uint256 assetPrice, uint256 longTradingExpo, HugeUint.Uint512 memory accumulator)
internal
pure
returns (uint256 unadjustedPrice_);
Parameters
Name | Type | Description |
---|---|---|
price | uint256 | An adjusted liquidation price (taking into account the effects of funding). |
assetPrice | uint256 | The current price of the asset. |
longTradingExpo | uint256 | The trading exposure of the long side (total exposure - balance long). |
accumulator | HugeUint.Uint512 | The liquidation multiplier accumulator. |
Returns
Name | Type | Description |
---|---|---|
unadjustedPrice_ | uint256 | The unadjusted price of price . |
_unadjustPrice
Calculates the unadjusted price of a position's liquidation price, which can be used to find the corresponding tick, with a fixed precision representation of the liquidation multiplier.
function _unadjustPrice(uint256 price, uint256 liqMultiplier) internal pure returns (uint256 unadjustedPrice_);
Parameters
Name | Type | Description |
---|---|---|
price | uint256 | An adjusted liquidation price (taking into account the effects of funding). |
liqMultiplier | uint256 | The liquidation price multiplier, with LIQUIDATION_MULTIPLIER_DECIMALS decimals. |
Returns
Name | Type | Description |
---|---|---|
unadjustedPrice_ | uint256 | The unadjusted price for the liquidation price. |
_tickValue
Calculates the value of a tick, knowing its contained total exposure and the current asset price.
function _tickValue(
int24 tick,
uint256 currentPrice,
uint256 longTradingExpo,
HugeUint.Uint512 memory accumulator,
Types.TickData memory tickData
) internal pure returns (int256 value_);
Parameters
Name | Type | Description |
---|---|---|
tick | int24 | The tick number. |
currentPrice | uint256 | The current price of the asset. |
longTradingExpo | uint256 | The trading exposure of the long side. |
accumulator | HugeUint.Uint512 | The liquidation multiplier accumulator. |
tickData | Types.TickData | The aggregated data of the tick. |
Returns
Name | Type | Description |
---|---|---|
value_ | int256 | The amount of asset tokens the tick is worth. |
_calcLiqPriceFromTradingExpo
Calculates the liquidation price without penalty of a position to reach a certain trading exposure.
If the sum of amount
and tradingExpo
equals 0, reverts.
function _calcLiqPriceFromTradingExpo(uint128 currentPrice, uint128 amount, uint256 tradingExpo)
internal
pure
returns (uint128 liqPrice_);
Parameters
Name | Type | Description |
---|---|---|
currentPrice | uint128 | The price of the asset. |
amount | uint128 | The amount of asset used as collateral. |
tradingExpo | uint256 | The trading exposure. |
Returns
Name | Type | Description |
---|---|---|
liqPrice_ | uint128 | The liquidation price without penalty. |
_calcTickFromBitmapIndex
Converts a bitmap index to a tick number using the provided tick spacing.
function _calcTickFromBitmapIndex(uint256 index, int24 tickSpacing) internal pure returns (int24 tick_);
Parameters
Name | Type | Description |
---|---|---|
index | uint256 | The index into the bitmap. |
tickSpacing | int24 | The tick spacing to use. |
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The tick corresponding to the index, a multiple of tickSpacing . |
_handleNegativeBalances
Handles negative balances by transferring assets from one side to the other.
Balances are unsigned integers and can't be negative.
In theory, this can not happen anymore because we have more precise calculations with the
liqMultiplierAccumulator
compared to the old liquidationMultiplier
.
function _handleNegativeBalances(int256 tempLongBalance, int256 tempVaultBalance)
internal
pure
returns (uint256 longBalance_, uint256 vaultBalance_);
Parameters
Name | Type | Description |
---|---|---|
tempLongBalance | int256 | The temporary long balance after liquidations |
tempVaultBalance | int256 | The temporary vault balance after liquidations |
Returns
Name | Type | Description |
---|---|---|
longBalance_ | uint256 | The new long balance after rebalancing |
vaultBalance_ | uint256 | The new vault balance after rebalancing |
_calcImbalanceOpenBps
Calculates the current imbalance for the open action checks.
If the value is positive, the long trading exposure is larger than the vault trading exposure.
In case of an empty vault balance, returns int256.max
since the resulting imbalance would be infinity.
function _calcImbalanceOpenBps(int256 vaultExpo, int256 longBalance, uint256 totalExpo)
internal
pure
returns (int256 imbalanceBps_);
Parameters
Name | Type | Description |
---|---|---|
vaultExpo | int256 | The vault exposure (including the pending vault balance and the fees of the position to open). |
longBalance | int256 | The balance of the long side (including the long position to open). |
totalExpo | uint256 | The total exposure of the long side (including the long position to open). |
Returns
Name | Type | Description |
---|---|---|
imbalanceBps_ | int256 | The imbalance (in basis points). |
_unadjustedPriceToTick
Calculates the tick corresponding to an unadjusted price, without rounding to the tick spacing.
function _unadjustedPriceToTick(uint256 unadjustedPrice) internal pure returns (int24 tick_);
Parameters
Name | Type | Description |
---|---|---|
unadjustedPrice | uint256 | The unadjusted price. |
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The tick number, bound by MIN_TICK . |
_roundTickDown
Rounds a tick down to a multiple of the tick spacing.
The function is bound by minTick, so the first tick which is a multiple of the tick spacing
and greater than or equal to MIN_TICK
.
function _roundTickDown(int24 tick, int24 tickSpacing) internal pure returns (int24 roundedTick_);
Parameters
Name | Type | Description |
---|---|---|
tick | int24 | The tick number. |
tickSpacing | int24 | The tick spacing. |
Returns
Name | Type | Description |
---|---|---|
roundedTick_ | int24 | The rounded tick number. |
_roundTickDownWithPenalty
Rounds the given tick down to a multiple of the tick spacing .
The result will always be above MIN_TICK
+ liquidationPenalty.
function _roundTickDownWithPenalty(int24 tickWithPenalty, int24 tickSpacing, uint24 liqPenalty)
internal
pure
returns (int24 roundedTick_);
Parameters
Name | Type | Description |
---|---|---|
tickWithPenalty | int24 | The tick number with the liquidation penalty. |
tickSpacing | int24 | The tick spacing. |
liqPenalty | uint24 | The liquidation penalty. |
Returns
Name | Type | Description |
---|---|---|
roundedTick_ | int24 | The rounded tick number. |
_getEffectiveTickForPriceNoRounding
Calculates the effective tick for a given price without rounding to the tick spacing.
function _getEffectiveTickForPriceNoRounding(
uint128 price,
uint256 assetPrice,
uint256 longTradingExpo,
HugeUint.Uint512 memory accumulator
) internal pure returns (int24 tick_);
Parameters
Name | Type | Description |
---|---|---|
price | uint128 | The price to be adjusted. |
assetPrice | uint256 | The current asset price. |
longTradingExpo | uint256 | The long trading exposure. |
accumulator | HugeUint.Uint512 | The liquidation multiplier accumulator. |
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The tick number. |
_getEffectiveTickForPriceNoRounding
Calculates the effective tick for a given price without rounding to the tick spacing with a fixed precision representation of the liquidation multiplier.
function _getEffectiveTickForPriceNoRounding(uint128 price, uint256 liqMultiplier)
internal
pure
returns (int24 tick_);
Parameters
Name | Type | Description |
---|---|---|
price | uint128 | The price to be adjusted. |
liqMultiplier | uint256 | The liquidation price multiplier (with LIQUIDATION_MULTIPLIER_DECIMALS decimals). |
Returns
Name | Type | Description |
---|---|---|
tick_ | int24 | The tick number. |
_calcRebaseTotalSupply
Calculates the required USDN total supply to reach targetPrice
.
function _calcRebaseTotalSupply(uint256 vaultBalance, uint128 assetPrice, uint128 targetPrice, uint8 assetDecimals)
internal
pure
returns (uint256 totalSupply_);
Parameters
Name | Type | Description |
---|---|---|
vaultBalance | uint256 | The balance of the vault. |
assetPrice | uint128 | The price of the underlying asset. |
targetPrice | uint128 | The target USDN price to reach. |
assetDecimals | uint8 | The number of decimals of the asset. |
Returns
Name | Type | Description |
---|---|---|
totalSupply_ | uint256 | The required total supply to achieve targetPrice . |
Structs
LiquidationData
Structure to hold the temporary data during liquidations.
struct LiquidationData {
int256 tempLongBalance;
int256 tempVaultBalance;
int24 currentTick;
int24 iTick;
uint256 totalExpoToRemove;
uint256 accumulatorValueToRemove;
uint256 longTradingExpo;
uint256 currentPrice;
HugeUint.Uint512 accumulator;
bool isLiquidationPending;
}
Properties
Name | Type | Description |
---|---|---|
tempLongBalance | int256 | The updated long balance not saved into storage yet. |
tempVaultBalance | int256 | The updated vault balance not saved into storage yet. |
currentTick | int24 | The current tick (corresponding to the current asset price). |
iTick | int24 | Tick iterator index. |
totalExpoToRemove | uint256 | The total exposure to remove due to liquidations. |
accumulatorValueToRemove | uint256 | The value to remove from the liquidation multiplier accumulator due to liquidations. |
longTradingExpo | uint256 | The long trading exposure. |
currentPrice | uint256 | The current price of the asset. |
accumulator | HugeUint.Uint512 | The liquidation multiplier accumulator before liquidations. |
isLiquidationPending | bool | Whether some ticks are still populated above the current price (left to liquidate). |
ApplyPnlAndFundingAndLiquidateData
Data structure for the _applyPnlAndFundingAndLiquidate
function.
struct ApplyPnlAndFundingAndLiquidateData {
int256 tempLongBalance;
int256 tempVaultBalance;
uint128 lastPrice;
bool rebased;
bytes callbackResult;
Types.RebalancerAction rebalancerAction;
}
Properties
Name | Type | Description |
---|---|---|
tempLongBalance | int256 | The updated long balance not saved into storage yet. |
tempVaultBalance | int256 | The updated vault balance not saved into storage yet. |
lastPrice | uint128 | The last price used to update the protocol. |
rebased | bool | A boolean indicating if the USDN token was rebased. |
callbackResult | bytes | The result of the USDN rebase callback. |
rebalancerAction | Types.RebalancerAction | The action performed by the _triggerRebalancer function. |
TriggerRebalancerData
Data structure for the _triggerRebalancer
function.
struct TriggerRebalancerData {
uint128 positionAmount;
uint256 rebalancerMaxLeverage;
Types.PositionId rebalancerPosId;
uint128 positionValue;
}
Properties
Name | Type | Description |
---|---|---|
positionAmount | uint128 | The amount of assets in the rebalancer's position. |
rebalancerMaxLeverage | uint256 | The maximum leverage of the rebalancer. |
rebalancerPosId | Types.PositionId | The ID of the rebalancer's position. |
positionValue | uint128 | The value of the rebalancer's position. |