IUsdnProtocolTypes
Structs
Position
Information about a long user position.
struct Position {
bool validated;
uint40 timestamp;
address user;
uint128 totalExpo;
uint128 amount;
}
Properties
Name | Type | Description |
---|---|---|
validated | bool | Whether the position was validated. |
timestamp | uint40 | The timestamp of the position start. |
user | address | The user's address. |
totalExpo | uint128 | The total exposure of the position (0 for vault deposits). The product of the initial collateral and the initial leverage. |
amount | uint128 | The amount of initial collateral in the position. |
PendingAction
A pending action in the queue.
struct PendingAction {
ProtocolAction action;
uint40 timestamp;
uint24 var0;
address to;
address validator;
uint64 securityDepositValue;
int24 var1;
uint128 var2;
uint128 var3;
uint256 var4;
uint256 var5;
uint256 var6;
uint256 var7;
}
Properties
Name | Type | Description |
---|---|---|
action | ProtocolAction | The action type. |
timestamp | uint40 | The timestamp of the initiate action. |
var0 | uint24 | See DepositPendingAction, WithdrawalPendingAction and LongPendingAction. |
to | address | The target of the action. |
validator | address | The address that is supposed to validate the action. |
securityDepositValue | uint64 | The security deposit of the pending action. |
var1 | int24 | See DepositPendingAction, WithdrawalPendingAction and LongPendingAction. |
var2 | uint128 | See DepositPendingAction, WithdrawalPendingAction and LongPendingAction. |
var3 | uint128 | See DepositPendingAction, WithdrawalPendingAction and LongPendingAction. |
var4 | uint256 | See DepositPendingAction, WithdrawalPendingAction and LongPendingAction. |
var5 | uint256 | See DepositPendingAction, WithdrawalPendingAction and LongPendingAction. |
var6 | uint256 | See DepositPendingAction, WithdrawalPendingAction and LongPendingAction. |
var7 | uint256 | See DepositPendingAction, WithdrawalPendingAction and LongPendingAction. |
DepositPendingAction
A pending action in the queue for a vault deposit.
struct DepositPendingAction {
ProtocolAction action;
uint40 timestamp;
uint24 feeBps;
address to;
address validator;
uint64 securityDepositValue;
uint24 _unused;
uint128 amount;
uint128 assetPrice;
uint256 totalExpo;
uint256 balanceVault;
uint256 balanceLong;
uint256 usdnTotalShares;
}
Properties
Name | Type | Description |
---|---|---|
action | ProtocolAction | The action type. |
timestamp | uint40 | The timestamp of the initiate action. |
feeBps | uint24 | Fee for the deposit, in BPS. |
to | address | The recipient of the funds. |
validator | address | The address that is supposed to validate the action. |
securityDepositValue | uint64 | The security deposit of the pending action. |
_unused | uint24 | Unused field to align the struct to PendingAction . |
amount | uint128 | The amount of assets of the pending deposit. |
assetPrice | uint128 | The price of the asset at the time of the last update. |
totalExpo | uint256 | The total exposure at the time of the last update. |
balanceVault | uint256 | The balance of the vault at the time of the last update. |
balanceLong | uint256 | The balance of the long position at the time of the last update. |
usdnTotalShares | uint256 | The total supply of USDN shares at the time of the action. |
WithdrawalPendingAction
A pending action in the queue for a vault withdrawal.
struct WithdrawalPendingAction {
ProtocolAction action;
uint40 timestamp;
uint24 feeBps;
address to;
address validator;
uint64 securityDepositValue;
uint24 sharesLSB;
uint128 sharesMSB;
uint128 assetPrice;
uint256 totalExpo;
uint256 balanceVault;
uint256 balanceLong;
uint256 usdnTotalShares;
}
Properties
Name | Type | Description |
---|---|---|
action | ProtocolAction | The action type. |
timestamp | uint40 | The timestamp of the initiate action. |
feeBps | uint24 | Fee for the withdrawal, in BPS. |
to | address | The recipient of the funds. |
validator | address | The address that is supposed to validate the action. |
securityDepositValue | uint64 | The security deposit of the pending action. |
sharesLSB | uint24 | 3 least significant bytes of the withdrawal shares amount (uint152). |
sharesMSB | uint128 | 16 most significant bytes of the withdrawal shares amount (uint152). |
assetPrice | uint128 | The price of the asset at the time of the last update. |
totalExpo | uint256 | The total exposure at the time of the last update. |
balanceVault | uint256 | The balance of the vault at the time of the last update. |
balanceLong | uint256 | The balance of the long position at the time of the last update. |
usdnTotalShares | uint256 | The total shares supply of USDN at the time of the action. |
LongPendingAction
A pending action in the queue for a long position.
struct LongPendingAction {
ProtocolAction action;
uint40 timestamp;
uint24 closeLiqPenalty;
address to;
address validator;
uint64 securityDepositValue;
int24 tick;
uint128 closeAmount;
uint128 closePosTotalExpo;
uint256 tickVersion;
uint256 index;
uint256 liqMultiplier;
uint256 closeBoundedPositionValue;
}
Properties
Name | Type | Description |
---|---|---|
action | ProtocolAction | The action type. |
timestamp | uint40 | The timestamp of the initiate action. |
closeLiqPenalty | uint24 | The liquidation penalty of the tick (only used when closing a position). |
to | address | The recipient of the position. |
validator | address | The address that is supposed to validate the action. |
securityDepositValue | uint64 | The security deposit of the pending action. |
tick | int24 | The tick of the position. |
closeAmount | uint128 | The portion of the initial position amount to close (only used when closing a position). |
closePosTotalExpo | uint128 | The total expo of the position (only used when closing a position). |
tickVersion | uint256 | The version of the tick. |
index | uint256 | The index of the position in the tick list. |
liqMultiplier | uint256 | A fixed precision representation of the liquidation multiplier (with LIQUIDATION_MULTIPLIER_DECIMALS decimals) used to calculate the effective price for a given tick number. |
closeBoundedPositionValue | uint256 | The amount that was removed from the long balance on initiateClosePosition (only used when closing a position). |
PreviousActionsData
The data allowing to validate an actionable pending action.
struct PreviousActionsData {
bytes[] priceData;
uint128[] rawIndices;
}
Properties
Name | Type | Description |
---|---|---|
priceData | bytes[] | An array of bytes, each representing the data to be forwarded to the oracle middleware to validate a pending action in the queue. |
rawIndices | uint128[] | An array of raw indices in the pending actions queue, in the same order as the corresponding priceData. |
LiqTickInfo
Information of a liquidated tick.
struct LiqTickInfo {
uint256 totalPositions;
uint256 totalExpo;
int256 remainingCollateral;
uint128 tickPrice;
uint128 priceWithoutPenalty;
}
Properties
Name | Type | Description |
---|---|---|
totalPositions | uint256 | The total number of positions in the tick. |
totalExpo | uint256 | The total expo of the tick. |
remainingCollateral | int256 | The remaining collateral after liquidation. |
tickPrice | uint128 | The corresponding price. |
priceWithoutPenalty | uint128 | The price without the liquidation penalty. |
LiquidationsEffects
The effects of executed liquidations on the protocol.
struct LiquidationsEffects {
uint256 liquidatedPositions;
int256 remainingCollateral;
uint256 newLongBalance;
uint256 newVaultBalance;
bool isLiquidationPending;
LiqTickInfo[] liquidatedTicks;
}
Properties
Name | Type | Description |
---|---|---|
liquidatedPositions | uint256 | The total number of liquidated positions. |
remainingCollateral | int256 | The remaining collateral after liquidation. |
newLongBalance | uint256 | The new balance of the long side. |
newVaultBalance | uint256 | The new balance of the vault side. |
isLiquidationPending | bool | Whether some ticks are still populated above the current price (left to liquidate). |
liquidatedTicks | LiqTickInfo[] | Information about the liquidated ticks. |
TickData
Accumulator for tick data.
Since the liquidation penalty is a parameter that can be updated, we need to ensure that positions that get created with a given penalty, use this penalty throughout their lifecycle. As such, once a tick gets populated by a first position, it gets assigned the current liquidation penalty parameter value and can't use another value until it gets liquidated or all positions exit the tick.
struct TickData {
uint256 totalExpo;
uint248 totalPos;
uint24 liquidationPenalty;
}
Properties
Name | Type | Description |
---|---|---|
totalExpo | uint256 | The sum of the total expo of each position in the tick. |
totalPos | uint248 | The number of positions in the tick. |
liquidationPenalty | uint24 | The liquidation penalty for the positions in the tick. |
PositionId
The unique identifier for a long position.
struct PositionId {
int24 tick;
uint256 tickVersion;
uint256 index;
}
Properties
Name | Type | Description |
---|---|---|
tick | int24 | The tick of the position. |
tickVersion | uint256 | The version of the tick. |
index | uint256 | The index of the position in the tick list. |
InitiateOpenPositionParams
Parameters for the internal _initiateOpenPosition function.
struct InitiateOpenPositionParams {
address user;
address to;
address validator;
uint128 amount;
uint128 desiredLiqPrice;
uint128 userMaxPrice;
uint256 userMaxLeverage;
uint256 deadline;
uint64 securityDepositValue;
}
Properties
Name | Type | Description |
---|---|---|
user | address | The address of the user initiating the open position. |
to | address | The address that will be the owner of the position. |
validator | address | The address that is supposed to validate the action. |
amount | uint128 | The amount of assets to deposit. |
desiredLiqPrice | uint128 | The desired liquidation price, including the liquidation penalty. |
userMaxPrice | uint128 | The maximum price at which the position can be opened. The userMaxPrice is compared with the price after confidence interval, penalty, etc... |
userMaxLeverage | uint256 | The maximum leverage for the newly created position. |
deadline | uint256 | The deadline of the open position to be initiated. |
securityDepositValue | uint64 | The value of the security deposit for the newly created pending action. |
PrepareInitiateOpenPositionParams
Parameters for the internal {UsdnProtocolLongLibrary._prepareInitiateOpenPosition} function.
struct PrepareInitiateOpenPositionParams {
address validator;
uint128 amount;
uint128 desiredLiqPrice;
uint256 userMaxPrice;
uint256 userMaxLeverage;
bytes currentPriceData;
}
Properties
Name | Type | Description |
---|---|---|
validator | address | The address that is supposed to validate the action. |
amount | uint128 | The amount of assets to deposit. |
desiredLiqPrice | uint128 | The desired liquidation price, including the liquidation penalty. |
userMaxPrice | uint256 | The maximum price at which the position can be opened. The userMaxPrice is compared with the price after confidence interval, penalty, etc... |
userMaxLeverage | uint256 | The maximum leverage for the newly created position. |
currentPriceData | bytes | The current price data. |
PrepareInitiateClosePositionParams
Parameters for the internal _prepareClosePositionData function.
struct PrepareInitiateClosePositionParams {
address to;
address validator;
PositionId posId;
uint128 amountToClose;
uint256 userMinPrice;
uint256 deadline;
bytes currentPriceData;
bytes delegationSignature;
bytes32 domainSeparatorV4;
}
Properties
Name | Type | Description |
---|---|---|
to | address | The recipient of the funds. |
validator | address | The address that is supposed to validate the action. |
posId | PositionId | The unique identifier of the position. |
amountToClose | uint128 | The amount of collateral to remove from the position's amount. |
userMinPrice | uint256 | The minimum price at which the position can be closed. |
deadline | uint256 | The deadline until the position can be closed. |
currentPriceData | bytes | The current price data. |
delegationSignature | bytes | An EIP712 signature that proves the caller is authorized by the owner of the position to close it on their behalf. |
domainSeparatorV4 | bytes32 | The domain separator v4. |
InitiateClosePositionParams
Parameters for the internal _initiateClosePosition function.
struct InitiateClosePositionParams {
address to;
address payable validator;
uint256 deadline;
PositionId posId;
uint128 amountToClose;
uint256 userMinPrice;
uint64 securityDepositValue;
bytes32 domainSeparatorV4;
}
Properties
Name | Type | Description |
---|---|---|
to | address | The recipient of the funds. |
validator | address payable | The address that is supposed to validate the action. |
deadline | uint256 | The deadline of the close position to be initiated. |
posId | PositionId | The unique identifier of the position. |
amountToClose | uint128 | The amount to close. |
userMinPrice | uint256 | The minimum price at which the position can be closed. |
securityDepositValue | uint64 | The value of the security deposit for the newly created pending action. |
domainSeparatorV4 | bytes32 | The domain separator v4 for EIP712 signature. |
ClosePositionData
Structure to hold the transient data during _initiateClosePosition
struct ClosePositionData {
Position pos;
uint24 liquidationPenalty;
uint128 totalExpoToClose;
uint128 lastPrice;
uint256 tempPositionValue;
uint256 longTradingExpo;
HugeUint.Uint512 liqMulAcc;
bool isLiquidationPending;
}
Properties
Name | Type | Description |
---|---|---|
pos | Position | The position to close. |
liquidationPenalty | uint24 | The liquidation penalty. |
totalExpoToClose | uint128 | The total expo to close. |
lastPrice | uint128 | The price after the last balances update. |
tempPositionValue | uint256 | The bounded value of the position that was removed from the long balance. |
longTradingExpo | uint256 | The long trading expo. |
liqMulAcc | HugeUint.Uint512 | The liquidation multiplier accumulator. |
isLiquidationPending | bool | Whether some ticks are still populated above the current price (left to liquidate). |
ValidateOpenPositionData
Structure to hold the transient data during _validateOpenPosition.
struct ValidateOpenPositionData {
LongPendingAction action;
uint128 startPrice;
uint128 lastPrice;
bytes32 tickHash;
Position pos;
uint128 liqPriceWithoutPenaltyNorFunding;
uint128 liqPriceWithoutPenalty;
uint256 leverage;
uint256 oldPosValue;
uint24 liquidationPenalty;
bool isLiquidationPending;
}
Properties
Name | Type | Description |
---|---|---|
action | LongPendingAction | The long pending action. |
startPrice | uint128 | The new entry price of the position. |
lastPrice | uint128 | The price of the last balances update. |
tickHash | bytes32 | The tick hash. |
pos | Position | The position object. |
liqPriceWithoutPenaltyNorFunding | uint128 | The liquidation price without penalty nor funding used to calculate the user leverage and the new total expo. |
liqPriceWithoutPenalty | uint128 | The new liquidation price without penalty. |
leverage | uint256 | The new leverage. |
oldPosValue | uint256 | The value of the position according to the old entry price and the _lastPrice. |
liquidationPenalty | uint24 | The liquidation penalty for the position's tick. |
isLiquidationPending | bool | Whether some ticks are still populated above the current price (left to liquidate). |
InitiateOpenPositionData
Structure to hold the transient data during _initiateOpenPosition.
struct InitiateOpenPositionData {
uint128 adjustedPrice;
PositionId posId;
uint24 liquidationPenalty;
uint128 positionTotalExpo;
uint256 positionValue;
uint256 liqMultiplier;
bool isLiquidationPending;
}
Properties
Name | Type | Description |
---|---|---|
adjustedPrice | uint128 | The adjusted price with position fees applied. |
posId | PositionId | The unique identifier of the position. |
liquidationPenalty | uint24 | The liquidation penalty. |
positionTotalExpo | uint128 | The total expo of the position. The product of the initial collateral and the initial leverage. |
positionValue | uint256 | The value of the position, taking into account the position fee. |
liqMultiplier | uint256 | The liquidation multiplier represented with fixed precision. |
isLiquidationPending | bool | Whether some ticks are still populated above the current price (left to liquidate). |
CachedProtocolState
Structure to hold the state of the protocol.
struct CachedProtocolState {
uint256 totalExpo;
uint256 tradingExpo;
uint256 longBalance;
uint256 vaultBalance;
HugeUint.Uint512 liqMultiplierAccumulator;
}
Properties
Name | Type | Description |
---|---|---|
totalExpo | uint256 | The long total expo. |
tradingExpo | uint256 | The long trading expo. |
longBalance | uint256 | The long balance. |
vaultBalance | uint256 | The vault balance. |
liqMultiplierAccumulator | HugeUint.Uint512 | The liquidation multiplier accumulator. |
CalcRebalancerPositionTickData
Structure to hold transient data during the {UsdnProtocolActionsLongLibrary._calcRebalancerPositionTick} function.
struct CalcRebalancerPositionTickData {
uint256 protocolMaxLeverage;
int256 longImbalanceTargetBps;
uint256 tradingExpoToFill;
uint256 highestUsableTradingExpo;
uint24 currentLiqPenalty;
uint128 liqPriceWithoutPenalty;
}
Properties
Name | Type | Description |
---|---|---|
protocolMaxLeverage | uint256 | The protocol maximum leverage. |
longImbalanceTargetBps | int256 | The long imbalance target in basis points. |
tradingExpoToFill | uint256 | The trading expo to fill. |
highestUsableTradingExpo | uint256 | The highest usable trading expo. |
currentLiqPenalty | uint24 | The current liquidation penalty. |
liqPriceWithoutPenalty | uint128 | The liquidation price without penalty. |
RebalancerPositionData
Structure to hold the return values of the {UsdnProtocolActionsLongLibrary._calcRebalancerPositionTick} function.
struct RebalancerPositionData {
int24 tick;
uint128 totalExpo;
uint24 liquidationPenalty;
}
Properties
Name | Type | Description |
---|---|---|
tick | int24 | The tick of the rebalancer position, includes liquidation penalty. |
totalExpo | uint128 | The total expo of the rebalancer position. |
liquidationPenalty | uint24 | The liquidation penalty of the tick. |
ApplyPnlAndFundingData
Data structure for the _applyPnlAndFunding function.
struct ApplyPnlAndFundingData {
int256 tempLongBalance;
int256 tempVaultBalance;
uint128 lastPrice;
}
Properties
Name | Type | Description |
---|---|---|
tempLongBalance | int256 | The new balance of the long side, could be negative (temporarily). |
tempVaultBalance | int256 | The new balance of the vault side, could be negative (temporarily). |
lastPrice | uint128 | The last price. |
TickPriceConversionData
Data structure for tick to price conversion functions.
struct TickPriceConversionData {
uint256 tradingExpo;
HugeUint.Uint512 accumulator;
int24 tickSpacing;
}
Properties
Name | Type | Description |
---|---|---|
tradingExpo | uint256 | The long side trading expo. |
accumulator | HugeUint.Uint512 | The liquidation multiplier accumulator. |
tickSpacing | int24 | The tick spacing. |
Storage
Structure to hold the state of the protocol.
Note: storage-location: erc7201:UsdnProtocol.storage.main.
struct Storage {
int24 _tickSpacing;
IERC20Metadata _asset;
uint8 _assetDecimals;
uint8 _priceFeedDecimals;
IUsdn _usdn;
IERC20Metadata _sdex;
uint256 _usdnMinDivisor;
IBaseOracleMiddleware _oracleMiddleware;
IBaseLiquidationRewardsManager _liquidationRewardsManager;
IBaseRebalancer _rebalancer;
mapping(address => bool) _isRebalancer;
uint256 _minLeverage;
uint256 _maxLeverage;
uint128 _lowLatencyValidatorDeadline;
uint128 _onChainValidatorDeadline;
uint256 _safetyMarginBps;
uint16 _liquidationIteration;
uint16 _protocolFeeBps;
uint16 _rebalancerBonusBps;
uint24 _liquidationPenalty;
uint128 _EMAPeriod;
uint256 _fundingSF;
uint256 _feeThreshold;
int256 _openExpoImbalanceLimitBps;
int256 _withdrawalExpoImbalanceLimitBps;
int256 _depositExpoImbalanceLimitBps;
int256 _closeExpoImbalanceLimitBps;
int256 _rebalancerCloseExpoImbalanceLimitBps;
int256 _longImbalanceTargetBps;
uint16 _positionFeeBps;
uint16 _vaultFeeBps;
uint16 _sdexRewardsRatioBps;
uint32 __unused;
address _feeCollector;
uint64 _securityDepositValue;
uint128 _targetUsdnPrice;
uint128 _usdnRebaseThreshold;
uint256 _minLongPosition;
int256 _lastFundingPerDay;
uint128 _lastPrice;
uint128 _lastUpdateTimestamp;
uint256 _pendingProtocolFee;
mapping(address => uint256) _pendingActions;
DoubleEndedQueue.Deque _pendingActionsQueue;
uint256 _balanceVault;
int256 _pendingBalanceVault;
int256 _EMA;
uint256 _balanceLong;
uint256 _totalExpo;
HugeUint.Uint512 _liqMultiplierAccumulator;
mapping(int24 => uint256) _tickVersion;
mapping(bytes32 => Position[]) _longPositions;
mapping(bytes32 => TickData) _tickData;
int24 _highestPopulatedTick;
uint256 _totalLongPositions;
LibBitmap.Bitmap _tickBitmap;
address _protocolFallbackAddr;
mapping(address => uint256) _nonce;
uint64 _sdexBurnOnDepositRatio;
}
Properties
Name | Type | Description |
---|---|---|
_tickSpacing | int24 | The liquidation tick spacing for storing long positions. A tick spacing of 1 is equivalent to a 0.01% increase in liquidation price between ticks. A tick spacing of 100 is equivalent to a ~1.005% increase in liquidation price between ticks. |
_asset | IERC20Metadata | The asset ERC20 contract. Assets with a blacklist are not supported because the protocol would be DoS if transfers revert. |
_assetDecimals | uint8 | The number of decimals used by the _asset . |
_priceFeedDecimals | uint8 | The price feed decimals (18). |
_usdn | IUsdn | The USDN ERC20 contract. |
_sdex | IERC20Metadata | The SDEX ERC20 contract. |
_usdnMinDivisor | uint256 | The minimum divisor for USDN. |
_oracleMiddleware | IBaseOracleMiddleware | The oracle middleware contract. |
_liquidationRewardsManager | IBaseLiquidationRewardsManager | The liquidation rewards manager contract. |
_rebalancer | IBaseRebalancer | The rebalancer contract. |
_isRebalancer | mapping(address => bool) | Whether an address is or has been a rebalancer. |
_minLeverage | uint256 | The minimum leverage for a position. |
_maxLeverage | uint256 | The maximum leverage for a position. |
_lowLatencyValidatorDeadline | uint128 | The deadline for a user to confirm their action with a low-latency oracle. After this deadline, any user can validate the action with the low-latency oracle until the OracleMiddleware's _lowLatencyDelay. This is an offset compared to the timestamp of the initiate action. |
_onChainValidatorDeadline | uint128 | The deadline for a user to confirm their action with an on-chain oracle. After this deadline, any user can validate the action with the on-chain oracle. This is an offset compared to the timestamp of the initiate action + the oracle middleware's _lowLatencyDelay. |
_safetyMarginBps | uint256 | Safety margin for the liquidation price of newly open positions, in basis points. |
_liquidationIteration | uint16 | The number of iterations to perform during the user's action (in tick). |
_protocolFeeBps | uint16 | The protocol fee in basis points. |
_rebalancerBonusBps | uint16 | Part of the remaining collateral that is given as a bonus to the Rebalancer upon liquidation of a tick, in basis points. The rest is sent to the Vault balance. |
_liquidationPenalty | uint24 | The liquidation penalty (in ticks). |
_EMAPeriod | uint128 | The moving average period of the funding rate. |
_fundingSF | uint256 | The scaling factor (SF) of the funding rate. |
_feeThreshold | uint256 | The threshold above which the fee will be sent. |
_openExpoImbalanceLimitBps | int256 | The imbalance limit of the long expo for open actions (in basis points). As soon as the difference between the vault expo and the long expo exceeds this basis point limit in favor of long the open rebalancing mechanism is triggered, preventing the opening of a new long position. |
_withdrawalExpoImbalanceLimitBps | int256 | The imbalance limit of the long expo for withdrawal actions (in basis points). As soon as the difference between vault expo and long expo exceeds this basis point limit in favor of long, the withdrawal rebalancing mechanism is triggered, preventing the withdrawal of the existing vault position. |
_depositExpoImbalanceLimitBps | int256 | The imbalance limit of the vault expo for deposit actions (in basis points). As soon as the difference between the vault expo and the long expo exceeds this basis point limit in favor of the vault, the deposit vault rebalancing mechanism is triggered, preventing the opening of a new vault position. |
_closeExpoImbalanceLimitBps | int256 | The imbalance limit of the vault expo for close actions (in basis points). As soon as the difference between the vault expo and the long expo exceeds this basis point limit in favor of the vault, the close rebalancing mechanism is triggered, preventing the close of an existing long position. |
_rebalancerCloseExpoImbalanceLimitBps | int256 | The imbalance limit of the vault expo for close actions from the rebalancer (in basis points). As soon as the difference between the vault expo and the long expo exceeds this basis point limit in favor of the vault, the close rebalancing mechanism is triggered, preventing the close of an existing long position from the rebalancer contract. |
_longImbalanceTargetBps | int256 | The target imbalance on the long side (in basis points) This value will be used to calculate how much of the missing trading expo the rebalancer position will try to compensate. A negative value means the rebalancer will compensate enough to go above the equilibrium. A positive value means the rebalancer will compensate but stay below the equilibrium. |
_positionFeeBps | uint16 | The position fee in basis points. |
_vaultFeeBps | uint16 | The fee for vault deposits and withdrawals, in basis points. |
_sdexRewardsRatioBps | uint16 | The ratio of SDEX rewards to send to the user (in basis points). |
__unused | uint32 | Old slot for _sdexBurnOnDepositRatio . |
_feeCollector | address | The fee collector's address. |
_securityDepositValue | uint64 | The deposit required for a new position. |
_targetUsdnPrice | uint128 | The nominal (target) price of USDN (with _priceFeedDecimals). |
_usdnRebaseThreshold | uint128 | The USDN price threshold to trigger a rebase (with _priceFeedDecimals). |
_minLongPosition | uint256 | The minimum long position size (with _assetDecimals ). |
_lastFundingPerDay | int256 | The funding rate calculated at the last update timestamp. |
_lastPrice | uint128 | The price of the asset during the last balances update (with price feed decimals). |
_lastUpdateTimestamp | uint128 | The timestamp of the last balances update. |
_pendingProtocolFee | uint256 | The pending protocol fee accumulator. |
_pendingActions | mapping(address => uint256) | The pending actions by the user (1 per user max). The value stored is an index into the pendingActionsQueue deque, shifted by one. A value of 0 means no pending action. Since the deque uses uint128 indices, the highest index will not overflow when adding one. |
_pendingActionsQueue | DoubleEndedQueue.Deque | The queue of pending actions. |
_balanceVault | uint256 | The balance of deposits (with _assetDecimals ). |
_pendingBalanceVault | int256 | The unreflected balance change due to pending vault actions (with _assetDecimals ). |
_EMA | int256 | The exponential moving average of the funding (0.0003 at initialization). |
_balanceLong | uint256 | The balance of long positions (with _assetDecimals ). |
_totalExpo | uint256 | The total exposure of the long positions (with _assetDecimals ). |
_liqMultiplierAccumulator | HugeUint.Uint512 | The accumulator used to calculate the liquidation multiplier. This is the sum, for all ticks, of the total expo of positions inside the tick, multiplied by the unadjusted price of the tick which is _tickData[tickHash].liquidationPenalty below The unadjusted price is obtained with `TickMath.getPriceAtTick. |
_tickVersion | mapping(int24 => uint256) | The liquidation tick version. |
_longPositions | mapping(bytes32 => Position[]) | The long positions per versioned tick (liquidation price). |
_tickData | mapping(bytes32 => TickData) | Accumulated data for a given tick and tick version. |
_highestPopulatedTick | int24 | The highest tick with a position. |
_totalLongPositions | uint256 | Cache of the total long positions count. |
_tickBitmap | LibBitmap.Bitmap | The bitmap used to quickly find populated ticks. |
_protocolFallbackAddr | address | The address of the fallback contract. |
_nonce | mapping(address => uint256) | The user EIP712 nonce. |
_sdexBurnOnDepositRatio | uint64 | The ratio of USDN to SDEX tokens to burn on deposit. |
InitStorage
Structure to hold initial parameters for the protocol.
struct InitStorage {
int24 tickSpacing;
IERC20Metadata asset;
IUsdn usdn;
IERC20Metadata sdex;
IBaseOracleMiddleware oracleMiddleware;
IBaseLiquidationRewardsManager liquidationRewardsManager;
uint256 minLeverage;
uint256 maxLeverage;
uint128 lowLatencyValidatorDeadline;
uint128 onChainValidatorDeadline;
uint256 safetyMarginBps;
uint16 liquidationIteration;
uint16 protocolFeeBps;
uint16 rebalancerBonusBps;
uint24 liquidationPenalty;
uint128 emaPeriod;
uint256 fundingSF;
uint256 feeThreshold;
int256 openExpoImbalanceLimitBps;
int256 withdrawalExpoImbalanceLimitBps;
int256 depositExpoImbalanceLimitBps;
int256 closeExpoImbalanceLimitBps;
int256 rebalancerCloseExpoImbalanceLimitBps;
int256 longImbalanceTargetBps;
uint16 positionFeeBps;
uint16 vaultFeeBps;
uint16 sdexRewardsRatioBps;
uint64 sdexBurnOnDepositRatio;
address feeCollector;
uint64 securityDepositValue;
uint128 targetUsdnPrice;
uint128 usdnRebaseThreshold;
uint256 minLongPosition;
int256 EMA;
address protocolFallbackAddr;
}
Properties
Name | Type | Description |
---|---|---|
tickSpacing | int24 | The liquidation tick spacing for storing long positions. |
asset | IERC20Metadata | The asset ERC20 contract. |
usdn | IUsdn | The USDN ERC20 contract. |
sdex | IERC20Metadata | The SDEX ERC20 contract. |
oracleMiddleware | IBaseOracleMiddleware | The oracle middleware contract. |
liquidationRewardsManager | IBaseLiquidationRewardsManager | The liquidation rewards manager contract. |
minLeverage | uint256 | The minimum leverage for a position. |
maxLeverage | uint256 | The maximum leverage for a position. |
lowLatencyValidatorDeadline | uint128 | The deadline for a user to confirm their action with a low-latency oracle. |
onChainValidatorDeadline | uint128 | The deadline for a user to confirm their action with an on-chain oracle. |
safetyMarginBps | uint256 | Safety margin for the liquidation price of newly open positions, in basis points. |
liquidationIteration | uint16 | The number of iterations to perform during the user's action (in tick). |
protocolFeeBps | uint16 | The protocol fee in basis points. |
rebalancerBonusBps | uint16 | Part of the remaining collateral that is given as a bonus to the Rebalancer upon liquidation of a tick, in basis points. The rest is sent to the Vault balance. |
liquidationPenalty | uint24 | The liquidation penalty (in ticks). |
emaPeriod | uint128 | The moving average period of the funding rate. |
fundingSF | uint256 | The scaling factor (SF) of the funding rate. |
feeThreshold | uint256 | The threshold above which the fee will be sent. |
openExpoImbalanceLimitBps | int256 | The imbalance limit of the long expo for open actions (in basis points). |
withdrawalExpoImbalanceLimitBps | int256 | The imbalance limit of the long expo for withdrawal actions (in basis points). |
depositExpoImbalanceLimitBps | int256 | The imbalance limit of the vault expo for deposit actions (in basis points). |
closeExpoImbalanceLimitBps | int256 | The imbalance limit of the vault expo for close actions (in basis points). |
rebalancerCloseExpoImbalanceLimitBps | int256 | The imbalance limit of the vault expo for close actions from the rebalancer (in basis points). |
longImbalanceTargetBps | int256 | The target imbalance on the long side (in basis points) |
positionFeeBps | uint16 | The position fee in basis points. |
vaultFeeBps | uint16 | The fee for vault deposits and withdrawals, in basis points. |
sdexRewardsRatioBps | uint16 | The ratio of SDEX rewards to send to the user (in basis points). |
sdexBurnOnDepositRatio | uint64 | The ratio of USDN to SDEX tokens to burn on deposit. |
feeCollector | address | The fee collector's address. |
securityDepositValue | uint64 | The deposit required for a new position. |
targetUsdnPrice | uint128 | The nominal (target) price of USDN (with _priceFeedDecimals). |
usdnRebaseThreshold | uint128 | The USDN price threshold to trigger a rebase (with _priceFeedDecimals). |
minLongPosition | uint256 | The minimum long position size (with _assetDecimals ). |
EMA | int256 | The exponential moving average of the funding (0.0003 at initialization). |
protocolFallbackAddr | address | The address of the fallback contract. |
Enums
ProtocolAction
All possible action types for the protocol.
This is used for pending actions and to interact with the oracle middleware.
enum ProtocolAction {
None,
Initialize,
InitiateDeposit,
ValidateDeposit,
InitiateWithdrawal,
ValidateWithdrawal,
InitiateOpenPosition,
ValidateOpenPosition,
InitiateClosePosition,
ValidateClosePosition,
Liquidation
}
LongActionOutcome
The outcome of the call targeting a long position.
enum LongActionOutcome {
Processed,
Liquidated,
PendingLiquidations
}
RebalancerAction
Classifies how far in its logic the _triggerRebalancer function made it to.
Used to estimate the gas spent by the function call to more accurately calculate liquidation rewards.
enum RebalancerAction {
None,
NoImbalance,
PendingLiquidation,
NoCloseNoOpen,
Closed,
Opened,
ClosedOpened
}