LiquidationRewardsManager

Git Source

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

NameTypeDescription
liquidatedTicksTypes.LiqTickInfo[]Information about the liquidated ticks.
currentPriceuint256The current price of the asset.
rebasedboolIndicates whether a USDN rebase was performed.
rebalancerActionTypes.RebalancerActionThe action performed by the _triggerRebalancer function.
actionTypes.ProtocolActionThe type of protocol action that triggered the liquidation.
rebaseCallbackResultbytesThe result of the rebase callback, if any.
priceDatabytesThe oracle price data, if any. This can be used to differentiate rewards based on the oracle used to provide the liquidation price.

Returns

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

NameTypeDescription
<none>RewardsParametersrewardsParameters_ 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

NameTypeDescription
gasUsedPerTickuint32The gas consumed per tick for liquidation.
otherGasUseduint32The gas consumed for all additional computations.
rebaseGasUseduint32The gas consumed for optional USDN rebase operation.
rebalancerGasUseduint32The gas consumed for the optional rebalancer trigger.
baseFeeOffsetuint64An offset added to the block's base gas fee.
gasMultiplierBpsuint16The multiplier for the gas usage (in BPS).
positionBonusMultiplierBpsuint16Multiplier for position size bonus (in BPS).
fixedRewarduint128A fixed reward amount (in native currency, converted to wstETH).
maxRewarduint128The 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

NameTypeDescription
baseFeeOffsetuint64An offset added to the block's base gas fee.

Returns

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

NameTypeDescription
liquidatedTicksTypes.LiqTickInfo[]Information about the liquidated ticks.
currentPriceuint256The current asset price.
multiplieruint16The bonus multiplier (in BPS).

Returns

NameTypeDescription
bonus_uint256The calculated bonus (in _rewardAsset).