LiquidationRewardsManager
Inherits: ILiquidationRewardsManager, Ownable2Step
This abstract contract calculates the bonus portion of the rewards based on the size of the liquidated ticks. The actual reward calculation is left to the implementing contract.
State Variables
BPS_DIVISOR
Gets the denominator used for the reward multipliers.
uint32 public constant BPS_DIVISOR = 10_000;
BASE_GAS_COST
Gets the fixed gas amount used as a base for transaction cost computations.
Stored as a uint256 to prevent overflow during gas usage computations.
uint256 public constant BASE_GAS_COST = 21_000;
MAX_GAS_USED_PER_TICK
Gets the maximum allowable gas usage per liquidated tick.
uint256 public constant MAX_GAS_USED_PER_TICK = 500_000;
MAX_OTHER_GAS_USED
Gets the maximum allowable gas usage for all other computations.
uint256 public constant MAX_OTHER_GAS_USED = 1_000_000;
MAX_REBASE_GAS_USED
Gets the maximum allowable gas usage for rebase operations.
uint256 public constant MAX_REBASE_GAS_USED = 200_000;
MAX_REBALANCER_GAS_USED
Gets the maximum allowable gas usage for triggering the optional rebalancer.
uint256 public constant MAX_REBALANCER_GAS_USED = 300_000;
_rewardAsset
The address of the reward asset.
IERC20 internal immutable _rewardAsset;
_rewardsParameters
Holds the parameters used for rewards calculation.
Parameters should be updated to reflect changes in gas costs or protocol adjustments.
RewardsParameters internal _rewardsParameters;
Functions
getLiquidationRewards
Computes the amount of assets to reward a liquidator.
function getLiquidationRewards(
Types.LiqTickInfo[] calldata liquidatedTicks,
uint256 currentPrice,
bool rebased,
Types.RebalancerAction rebalancerAction,
Types.ProtocolAction action,
bytes calldata rebaseCallbackResult,
bytes calldata priceData
) external view virtual returns (uint256 rewards_);
Parameters
Name | Type | Description |
---|---|---|
liquidatedTicks | Types.LiqTickInfo[] | Information about the liquidated ticks. |
currentPrice | uint256 | The current price of the asset. |
rebased | bool | Indicates whether a USDN rebase was performed. |
rebalancerAction | Types.RebalancerAction | The action performed by the _triggerRebalancer function. |
action | Types.ProtocolAction | The type of protocol action that triggered the liquidation. |
rebaseCallbackResult | bytes | The result of the rebase callback, if any. |
priceData | bytes | The oracle price data, if any. This can be used to differentiate rewards based on the oracle used to provide the liquidation price. |
Returns
Name | Type | Description |
---|---|---|
rewards_ | uint256 | assetRewards_ The amount of asset tokens to reward the liquidator. |
getRewardsParameters
Retrieves the current parameters used for reward calculations.
function getRewardsParameters() external view returns (RewardsParameters memory);
Returns
Name | Type | Description |
---|---|---|
<none> | RewardsParameters | rewardsParameters_ A struct containing the rewards parameters. |
setRewardsParameters
Updates the parameters used for calculating liquidation rewards.
function setRewardsParameters(
uint32 gasUsedPerTick,
uint32 otherGasUsed,
uint32 rebaseGasUsed,
uint32 rebalancerGasUsed,
uint64 baseFeeOffset,
uint16 gasMultiplierBps,
uint16 positionBonusMultiplierBps,
uint128 fixedReward,
uint128 maxReward
) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
gasUsedPerTick | uint32 | The gas consumed per tick for liquidation. |
otherGasUsed | uint32 | The gas consumed for all additional computations. |
rebaseGasUsed | uint32 | The gas consumed for optional USDN rebase operation. |
rebalancerGasUsed | uint32 | The gas consumed for the optional rebalancer trigger. |
baseFeeOffset | uint64 | An offset added to the block's base gas fee. |
gasMultiplierBps | uint16 | The multiplier for the gas usage (in BPS). |
positionBonusMultiplierBps | uint16 | Multiplier for position size bonus (in BPS). |
fixedReward | uint128 | A fixed reward amount (in native currency, converted to wstETH). |
maxReward | uint128 | The maximum allowable reward amount (in native currency, converted to wstETH). |
_calcGasPrice
Calculates the gas price used for rewards calculations.
function _calcGasPrice(uint64 baseFeeOffset) internal view returns (uint256 gasPrice_);
Parameters
Name | Type | Description |
---|---|---|
baseFeeOffset | uint64 | An offset added to the block's base gas fee. |
Returns
Name | Type | Description |
---|---|---|
gasPrice_ | uint256 | The gas price used for reward calculation. |
_calcPositionSizeBonus
Computes the size and price-dependent bonus given for liquidating the ticks.
function _calcPositionSizeBonus(Types.LiqTickInfo[] calldata liquidatedTicks, uint256 currentPrice, uint16 multiplier)
internal
pure
returns (uint256 bonus_);
Parameters
Name | Type | Description |
---|---|---|
liquidatedTicks | Types.LiqTickInfo[] | Information about the liquidated ticks. |
currentPrice | uint256 | The current asset price. |
multiplier | uint16 | The bonus multiplier (in BPS). |
Returns
Name | Type | Description |
---|---|---|
bonus_ | uint256 | The calculated bonus (in _rewardAsset). |