PerpRewardDistributor

Git Source

Inherits: RewardDistributor, IPerpRewardDistributor

Author: webthethird

Handles reward accrual and distribution for liquidity providers in Perpetual markets

State Variables

clearingHouse

Clearing House contract

IClearingHouse public immutable clearingHouse;

_earlyWithdrawalThreshold

Amount of time after which LPs can remove liquidity without penalties

uint256 internal _earlyWithdrawalThreshold;

_withdrawTimerStartByUserByMarket

Last timestamp when user changed their position in a market

First address is user, second is the market

mapping(address => mapping(address => uint256)) internal _withdrawTimerStartByUserByMarket;

Functions

onlyClearingHouse

Modifier for functions that can only be called by the ClearingHouse, i.e., updatePosition

modifier onlyClearingHouse();

constructor

PerpRewardDistributor constructor

constructor(
    uint88 _initialInflationRate,
    uint88 _initialReductionFactor,
    address _rewardToken,
    address _clearingHouse,
    address _ecosystemReserve,
    uint256 _earlyWithdrawThreshold,
    uint256[] memory _initialRewardWeights
) payable RewardDistributor(_ecosystemReserve);

Parameters

updatePosition

Accrues rewards and updates the stored LP position of a user and the total LP of a market

Only callable by the clearing house, executes whenever a user's liquidity is updated for any reason

function updatePosition(address market, address user) external virtual override onlyClearingHouse;

Parameters

earlyWithdrawalThreshold

Gets the number of seconds that a user must leave their liquidity in the market to avoid the early withdrawal penalty

function earlyWithdrawalThreshold() external view returns (uint256);

Returns

withdrawTimerStartByUserByMarket

Start time of the user's early withdrawal timer for a specific market, i.e., when they last changed their position in the market

The user can withdraw their liquidity without penalty after withdrawTimerStartByUserByMarket(user, market) + earlyWithdrawalThreshold

function withdrawTimerStartByUserByMarket(address _user, address _market) external view returns (uint256);

Parameters

Returns

paused

Indicates whether claiming rewards is currently paused

Contract is paused if either this contract or the ClearingHouse has been paused

function paused() public view override returns (bool);

Returns

initMarketStartTime

Sets the start time for accruing rewards to a market which has not been initialized yet

Only callable by governance

function initMarketStartTime(address _market) external onlyRole(GOVERNANCE);

Parameters

setEarlyWithdrawalThreshold

Sets the number of seconds that a user must leave their liquidity in the market to avoid the early withdrawal penalty

Only callable by governance

function setEarlyWithdrawalThreshold(uint256 _newEarlyWithdrawalThreshold) external onlyRole(GOVERNANCE);

Parameters

_getNumMarkets

Gets the number of markets to be used for reward distribution

Markets are the perpetual markets (for the PerpRewardDistributor) or staked tokens (for the SafetyModule)

function _getNumMarkets() internal view override returns (uint256);

Returns

_getMarketAddress

Gets the address of a market at a given index

Markets are the perpetual markets (for the PerpRewardDistributor) or staked tokens (for the SafetyModule)

function _getMarketAddress(uint256 idx) internal view override returns (address);

Parameters

Returns

_getMarketIdx

Gets the index of an allowlisted market

Markets are the perpetual markets (for the PerpRewardDistributor) or staked tokens (for the SafetyModule)

function _getMarketIdx(uint256 i) internal view override returns (uint256);

Parameters

Returns

_getCurrentPosition

Returns the current position of the user in the market (i.e., perpetual market or staked token)

function _getCurrentPosition(address user, address market) internal view override returns (uint256);

Parameters

Returns

_accrueRewards

Accrues rewards and updates the stored LP position of a user and the total liquidity in the market

Called by updatePosition, which can only be called by the ClearingHouse when an LP's position changes, and claimRewards, which always passes msg.sender as the user

function _accrueRewards(address market, address user) internal virtual override;

Parameters

Last updated