YearnStakingDelegate
Inherits: IYearnStakingDelegate, AccessControlEnumerable, ReentrancyGuard, Rescuable, Pausable
Contract for staking yearn gauge tokens, managing rewards, and delegating voting power.
Inherits from IYearnStakingDelegate, AccessControlEnumerable, ReentrancyGuard, Rescuable, and Pausable.
State Variables
PAUSER_ROLE
Role identifier for pausers, capable of pausing contract functions.
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
TIMELOCK_ROLE
Role identifier for timelock, capable of performing time-sensitive administrative functions.
bytes32 public constant TIMELOCK_ROLE = keccak256("TIMELOCK_ROLE");
DEPOSITOR_ROLE
Role identifier for depositors, capable of depositing gauge tokens.
bytes32 public constant DEPOSITOR_ROLE = keccak256("DEPOSITOR_ROLE");
_YFI_REWARD_POOL
Address of the Yearn Finance YFI reward pool.
address private constant _YFI_REWARD_POOL = 0xb287a1964AEE422911c7b8409f5E5A273c1412fA;
_DYFI_REWARD_POOL
Address of the Yearn Finance D_YFI reward pool.
address private constant _DYFI_REWARD_POOL = 0x2391Fc8f5E417526338F5aa3968b1851C16D894E;
_YFI
Address of the Yearn Finance YFI token.
address private constant _YFI = 0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e;
_D_YFI
Address of the Yearn Finance D_YFI token.
address private constant _D_YFI = 0x41252E8691e964f7DE35156B68493bAb6797a275;
_VE_YFI
Address of the Yearn Finance veYFI token.
address private constant _VE_YFI = 0x90c1f9220d90d3966FbeE24045EDd73E1d588aD5;
_SNAPSHOT_DELEGATE_REGISTRY
Address of the Snapshot delegate registry.
address private constant _SNAPSHOT_DELEGATE_REGISTRY = 0x469788fE6E9E9681C6ebF3bF78e7Fd26Fc015446;
_MAX_TREASURY_PCT
Maximum percentage of the treasury in basis points.
uint256 private constant _MAX_TREASURY_PCT = 0.2e18;
_GAUGE_REWARD_RECEIVER_IMPL
Address of the GaugeRewardReceiver implementation, set at contract deployment and immutable thereafter.
address private immutable _GAUGE_REWARD_RECEIVER_IMPL;
gaugeStakingRewards
Mapping of gauge addresses to their corresponding staking rewards contract addresses.
mapping(address => address) public gaugeStakingRewards;
gaugeRewardReceivers
Mapping of gauge addresses to their corresponding GaugeRewardReceiver contract addresses.
mapping(address => address) public gaugeRewardReceivers;
balanceOf
Mapping of user addresses to a nested mapping of token addresses to the user's balance of that token.
mapping(address => mapping(address => uint256)) public balanceOf;
totalDeposited
Mapping of gauge token address to the total amount deposited in this contract.
mapping(address => uint256) public totalDeposited;
depositLimit
Mapping of gauge token addresses to their corresponding deposit limits. Note that this is the ideal limit, which should be enforced by the depositing contracts
mapping(address => uint256) public depositLimit;
blockedTargets
Mapping of target addresses to a boolean indicating whether the target is blocked.
mapping(address => bool) public blockedTargets;
_gaugeRewardSplit
Mapping of vault addresses to their corresponding RewardSplit configuration.
mapping(address => RewardSplit) private _gaugeRewardSplit;
_treasury
Address of the treasury where funds are managed.
address private _treasury;
_shouldPerpetuallyLock
Flag indicating whether to lock rewards perpetually.
bool private _shouldPerpetuallyLock;
_swapAndLock
Address of the contract that swaps and locks tokens.
address private _swapAndLock;
_coveYfiRewardForwarder
Address of the contract that forwards YFI rewards to CoveYFI.
address private _coveYfiRewardForwarder;
_boostRewardSplit
Configuration for how rewards are split in the boost phase.
BoostRewardSplit private _boostRewardSplit;
_exitRewardSplit
Configuration for how rewards are split upon exit.
ExitRewardSplit private _exitRewardSplit;
Functions
constructor
Initializes the contract by setting up roles and initializing state variables.
constructor(
address gaugeRewardReceiverImpl,
address treasury_,
address admin,
address pauser,
address timelock
)
payable;
Parameters
Name | Type | Description |
---|---|---|
gaugeRewardReceiverImpl | address | Address of the GaugeRewardReceiver implementation. |
treasury_ | address | Address of the treasury. |
admin | address | Address of the admin. |
pauser | address | Address of the pauser. |
timelock | address | Address of the timelock. |
deposit
Deposits a specified amount of gauge tokens into this staking delegate.
Deposits can be paused in case of emergencies by the admin or pauser roles.
function deposit(address gauge, uint256 amount) external onlyRole(DEPOSITOR_ROLE) whenNotPaused;
Parameters
Name | Type | Description |
---|---|---|
gauge | address | The address of the gauge token to deposit. |
amount | uint256 | The amount of tokens to deposit. |
withdraw
Withdraws a specified amount of gauge tokens from this staking delegate.
function withdraw(address gauge, uint256 amount, address receiver) external;
Parameters
Name | Type | Description |
---|---|---|
gauge | address | The address of the gauge token to withdraw. |
amount | uint256 | The amount of tokens to withdraw. |
receiver | address |
withdraw
Withdraws a specified amount of gauge tokens from this staking delegate.
function withdraw(address gauge, uint256 amount) external;
Parameters
Name | Type | Description |
---|---|---|
gauge | address | The address of the gauge token to withdraw. |
amount | uint256 | The amount of tokens to withdraw. |
_withdraw
function _withdraw(address gauge, uint256 amount, address receiver) internal;
harvest
Harvests rewards from a gauge and distributes them.
function harvest(address gauge) external returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
gauge | address | Address of the gauge to harvest from. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of rewards harvested. |
claimBoostRewards
Claim dYFI rewards from the reward pool and transfer them to the CoveYFI Reward Forwarder
function claimBoostRewards() external;
claimExitRewards
Claim YFI rewards from the reward pool and transfer them to the CoveYFI Reward Forwarder
function claimExitRewards() external;
lockYfi
Locks YFI tokens in the veYFI contract.
Locking YFI can be paused in case of emergencies by the admin or pauser roles.
function lockYfi(uint256 amount) external whenNotPaused returns (IVotingYFI.LockedBalance memory);
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | Amount of YFI tokens to lock. |
Returns
Name | Type | Description |
---|---|---|
<none> | IVotingYFI.LockedBalance | The locked balance information. |
setCoveYfiRewardForwarder
Sets the address for the CoveYFI Reward Forwarder.
Can only be called by an address with the TIMELOCK_ROLE. Emits CoveYfiRewardForwarderSet event.
function setCoveYfiRewardForwarder(address forwarder) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
forwarder | address | The address of the new CoveYFI Reward Forwarder. |
setTreasury
Set treasury address. This address will receive a portion of the rewards
function setTreasury(address treasury_) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
treasury_ | address | address to receive rewards |
setSwapAndLock
Sets the address for the SwapAndLock contract.
function setSwapAndLock(address newSwapAndLock) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
newSwapAndLock | address | Address of the SwapAndLock contract. |
setGaugeRewardSplit
Set the reward split percentages
Sum of percentages must equal to 1e18
function setGaugeRewardSplit(
address gauge,
uint64 treasuryPct,
uint64 coveYfiPct,
uint64 userPct,
uint64 veYfiPct
)
external
onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
gauge | address | address of the gauge token |
treasuryPct | uint64 | percentage of rewards to treasury |
coveYfiPct | uint64 | percentage of rewards to coveYFI Reward Forwarder |
userPct | uint64 | percentage of rewards to user |
veYfiPct | uint64 | percentage of rewards to veYFI |
setBoostRewardSplit
Set the reward split percentages for dYFI boost rewards
Sum of percentages must equal to 1e18
function setBoostRewardSplit(uint128 treasuryPct, uint128 coveYfiPct) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
treasuryPct | uint128 | percentage of rewards to treasury |
coveYfiPct | uint128 | percentage of rewards to CoveYFI Reward Forwarder |
setExitRewardSplit
Set the reward split percentages for YFI exit rewards
Sum of percentages must equal to 1e18
function setExitRewardSplit(uint128 treasuryPct, uint128 coveYfiPct) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
treasuryPct | uint128 | percentage of rewards to treasury |
coveYfiPct | uint128 | percentage of rewards to CoveYFI Reward Forwarder |
setDepositLimit
Set the deposit limit for a gauge token. This is the ideal limit, which should be enforced by the depositing contracts.
function setDepositLimit(address gaugeToken, uint256 limit) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
gaugeToken | address | address of the gauge token |
limit | uint256 | maximum amount of tokens that can be deposited |
setSnapshotDelegate
Delegates voting power to a given address
function setSnapshotDelegate(bytes32 id, address delegate) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
id | bytes32 | name of the space in snapshot to apply delegation. For yearn it is "veyfi.eth" |
delegate | address | address to delegate voting power to |
addGaugeRewards
Adds gauge rewards configuration.
function addGaugeRewards(
address gauge,
address stakingDelegateRewards
)
external
nonReentrant
onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
Name | Type | Description |
---|---|---|
gauge | address | Address of the gauge. |
stakingDelegateRewards | address | Address of the StakingDelegateRewards contract. |
updateGaugeRewards
Updates gauge rewards configuration.
function updateGaugeRewards(
address gauge,
address stakingDelegateRewards
)
external
nonReentrant
onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
gauge | address | Address of the gauge. |
stakingDelegateRewards | address | Address of the new StakingDelegateRewards contract. |
setPerpetualLock
Set perpetual lock status
function setPerpetualLock(bool lock) external onlyRole(TIMELOCK_ROLE);
Parameters
Name | Type | Description |
---|---|---|
lock | bool | if true, lock YFI for 4 years after each harvest |
earlyUnlock
early unlock veYFI and send YFI to treasury
function earlyUnlock() external onlyRole(TIMELOCK_ROLE);
pause
Pauses the contract. Only callable by PAUSER_ROLE or DEFAULT_ADMIN_ROLE.
function pause() external;
unpause
Unpauses the contract. Only callable by DEFAULT_ADMIN_ROLE.
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE);
execute
Execute arbitrary calls from the staking delegate. This function is callable by the admin role for future proofing. Target must not be YFI, dYFI, veYFI, or a known gauge token.
function execute(
address target,
bytes calldata data,
uint256 value
)
external
payable
onlyRole(TIMELOCK_ROLE)
returns (bytes memory);
Parameters
Name | Type | Description |
---|---|---|
target | address | contract to call |
data | bytes | calldata to execute the call with |
value | uint256 | call value |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | result of the call |
availableDepositLimit
Get the available deposit limit for a gauge token
function availableDepositLimit(address gaugeToken) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
gaugeToken | address | The address of the gauge token |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Available deposit limit |
getBoostRewardSplit
Get the dYFI boost reward split
function getBoostRewardSplit() external view returns (BoostRewardSplit memory);
Returns
Name | Type | Description |
---|---|---|
<none> | BoostRewardSplit | BoostRewardSplit struct containing the treasury and coveYFI split. |
getExitRewardSplit
Get the YFI exit reward split
function getExitRewardSplit() external view returns (ExitRewardSplit memory);
Returns
Name | Type | Description |
---|---|---|
<none> | ExitRewardSplit | ExitRewardSplit struct containing the treasury and coveYFI split. |
getGaugeRewardSplit
Get the dYFI reward split for a gauge
function getGaugeRewardSplit(address gauge) external view returns (RewardSplit memory);
Parameters
Name | Type | Description |
---|---|---|
gauge | address | Address of the gauge |
Returns
Name | Type | Description |
---|---|---|
<none> | RewardSplit | RewardSplit struct containing the treasury, coveYFI, user, and lock splits for the gauge |
treasury
Get the address of the treasury
function treasury() external view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the treasury |
coveYfiRewardForwarder
Get the address of the stored CoveYFI Reward Forwarder
function coveYfiRewardForwarder() external view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the CoveYFI Reward Forwarder |
swapAndLock
Get the address of the SwapAndLock contract
function swapAndLock() external view returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the SwapAndLock contract |
shouldPerpetuallyLock
Get the perpetual lock status
function shouldPerpetuallyLock() external view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if perpetual lock is enabled |
yfi
Get the address of the YFI token
function yfi() external pure returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the YFI token |
dYfi
Get the address of the dYFI token
function dYfi() external pure returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the dYFI token |
veYfi
Get the address of the veYFI token
function veYfi() external pure returns (address);
Returns
Name | Type | Description |
---|---|---|
<none> | address | The address of the veYFI token |
_setTreasury
Internal function to set the treasury address.
function _setTreasury(address treasury_) internal;
Parameters
Name | Type | Description |
---|---|---|
treasury_ | address | The address of the new treasury. |
_setCoveYfiRewardForwarder
Internal function to set the CoveYFI Reward Forwarder address.
function _setCoveYfiRewardForwarder(address forwarder) internal;
Parameters
Name | Type | Description |
---|---|---|
forwarder | address | The address of the CoveYFI Reward Forwarder. |
_setGaugeRewards
Internal function to set gauge rewards and reward receiver.
function _setGaugeRewards(address gauge, address stakingDelegateRewards) internal;
Parameters
Name | Type | Description |
---|---|---|
gauge | address | Address of the gauge. |
stakingDelegateRewards | address | Address of the StakingDelegateRewards contract. |
_setPerpetualLock
Internal function to set the perpetual lock status.
function _setPerpetualLock(bool lock) internal;
Parameters
Name | Type | Description |
---|---|---|
lock | bool | True for max lock. |
_setGaugeRewardSplit
Internal function to set the reward split for a gauge.
function _setGaugeRewardSplit(
address gauge,
uint64 treasuryPct,
uint64 coveYfiPct,
uint64 userPct,
uint64 lockPct
)
internal;
Parameters
Name | Type | Description |
---|---|---|
gauge | address | Address of the gauge. |
treasuryPct | uint64 | Percentage of rewards to the treasury. |
coveYfiPct | uint64 | |
userPct | uint64 | Percentage of rewards to the user. |
lockPct | uint64 | Percentage of rewards to lock in veYFI. |
_setBoostRewardSplit
Internal function to set the reward split for the dYFI boost rewards
function _setBoostRewardSplit(uint128 treasuryPct, uint128 coveYfiPct) internal;
Parameters
Name | Type | Description |
---|---|---|
treasuryPct | uint128 | Percentage of rewards to the treasury. |
coveYfiPct | uint128 | Percentage of rewards to the CoveYFI Reward Forwarder. |
_setExitRewardSplit
Internal function to set the reward split for the YFI exit rewards (when veYFI holders early unlock their YFI, a portion of their YFI is distributed to other veYFI holders).
function _setExitRewardSplit(uint128 treasuryPct, uint128 coveYfiPct) internal;
Parameters
Name | Type | Description |
---|---|---|
treasuryPct | uint128 | Percentage of rewards to the treasury. |
coveYfiPct | uint128 | Percentage of rewards to the CoveYFI Reward Forwarder. |
_checkpointUserBalance
Internal function to checkpoint a user's balance for a gauge.
function _checkpointUserBalance(
address stakingDelegateReward,
address gauge,
address user,
uint256 userBalance,
uint256 currentTotalDeposited
)
internal;
Parameters
Name | Type | Description |
---|---|---|
stakingDelegateReward | address | Address of the StakingDelegateRewards contract. |
gauge | address | Address of the gauge. |
user | address | Address of the user. |
userBalance | uint256 | New balance of the user for the gauge. |
currentTotalDeposited | uint256 |
Events
LockYfi
Emitted when YFI tokens are locked.
event LockYfi(address indexed sender, uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The address of the sender who locked YFI tokens. |
amount | uint256 | The amount of YFI tokens locked. |
GaugeRewardsSet
Emitted when gauge rewards are set.
event GaugeRewardsSet(address indexed gauge, address stakingRewardsContract, address receiver);
Parameters
Name | Type | Description |
---|---|---|
gauge | address | The address of the gauge for which rewards are set. |
stakingRewardsContract | address | The address of the staking rewards contract. |
receiver | address | The address of the rewards receiver. |
PerpetualLockSet
Emitted when the perpetual lock setting is updated.
event PerpetualLockSet(bool shouldLock);
Parameters
Name | Type | Description |
---|---|---|
shouldLock | bool | The status of the perpetual lock setting. |
GaugeRewardSplitSet
Emitted when the reward split configuration for a gauge is set.
event GaugeRewardSplitSet(address indexed gauge, RewardSplit split);
Parameters
Name | Type | Description |
---|---|---|
gauge | address | The address of the gauge for which the reward split is set. |
split | RewardSplit | The reward split configuration. |
BoostRewardSplitSet
Emitted when the boost reward split configuration is set.
event BoostRewardSplitSet(uint128 treasuryPct, uint128 coveYfiPct);
Parameters
Name | Type | Description |
---|---|---|
treasuryPct | uint128 | The percentage of the boost reward allocated to the treasury. |
coveYfiPct | uint128 | The percentage of the boost reward allocated to CoveYFI. |
ExitRewardSplitSet
Emitted when the exit reward split configuration is set.
event ExitRewardSplitSet(uint128 treasuryPct, uint128 coveYfiPct);
Parameters
Name | Type | Description |
---|---|---|
treasuryPct | uint128 | The percentage of the exit reward allocated to the treasury. |
coveYfiPct | uint128 | The percentage of the exit reward allocated to CoveYFI. |
DepositLimitSet
Emitted when a deposit limit is set.
event DepositLimitSet(address indexed gaugeToken, uint256 limit);
Parameters
Name | Type | Description |
---|---|---|
gaugeToken | address | The address of the gauge token for which the deposit limit is set. |
limit | uint256 | The deposit limit. |
SwapAndLockSet
Emitted when the swap and lock contract address is set.
event SwapAndLockSet(address swapAndLockContract);
Parameters
Name | Type | Description |
---|---|---|
swapAndLockContract | address | The address of the swap and lock contract. |
TreasurySet
Emitted when the treasury address is updated.
event TreasurySet(address newTreasury);
Parameters
Name | Type | Description |
---|---|---|
newTreasury | address | The new address of the treasury. |
CoveYfiRewardForwarderSet
Emitted when the CoveYFI reward forwarder address is set.
event CoveYfiRewardForwarderSet(address forwarder);
Parameters
Name | Type | Description |
---|---|---|
forwarder | address | The address of the CoveYFI reward forwarder. |
Deposit
Emitted when a gauge token is deposited
event Deposit(address indexed sender, address indexed gauge, uint256 amount, uint256 newTotalDeposited);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The address of the sender who made the deposit. |
gauge | address | The address of the gauge token deposited. |
amount | uint256 | The amount of tokens deposited. |
newTotalDeposited | uint256 | The new total amount of the gauge tokens deposited across all users. |
Withdraw
Emitted when a gauge token is withdrawn
event Withdraw(address indexed sender, address indexed gauge, uint256 amount, uint256 newTotalDeposited);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The address of the sender who made the withdrawal. |
gauge | address | The address of the gauge token withdrawn. |
amount | uint256 | The amount of tokens withdrawn. |
newTotalDeposited | uint256 | The new total amount of the gauge tokens deposited across all users. |
StakingDelegateRewardsFaulty
Emitted when the checkpointing of a user's balance fails
event StakingDelegateRewardsFaulty(
address stakingDelegateRewards,
address user,
address gauge,
uint256 currentUserBalance,
uint256 currentTotalDeposited
);
Parameters
Name | Type | Description |
---|---|---|
stakingDelegateRewards | address | The address of the StakingDelegateRewards contract. |
user | address | The address of the user whose balance failed to checkpoint. |
gauge | address | The address of the gauge token. |
currentUserBalance | uint256 | The current balance of gauge tokens deposited by the user. |
currentTotalDeposited | uint256 | The current total amount of the gauge tokens deposited across all users. |