YearnStakingDelegate

Git Source

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

NameTypeDescription
gaugeRewardReceiverImpladdressAddress of the GaugeRewardReceiver implementation.
treasury_addressAddress of the treasury.
adminaddressAddress of the admin.
pauseraddressAddress of the pauser.
timelockaddressAddress 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

NameTypeDescription
gaugeaddressThe address of the gauge token to deposit.
amountuint256The 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

NameTypeDescription
gaugeaddressThe address of the gauge token to withdraw.
amountuint256The amount of tokens to withdraw.
receiveraddress

withdraw

Withdraws a specified amount of gauge tokens from this staking delegate.

function withdraw(address gauge, uint256 amount) external;

Parameters

NameTypeDescription
gaugeaddressThe address of the gauge token to withdraw.
amountuint256The 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

NameTypeDescription
gaugeaddressAddress of the gauge to harvest from.

Returns

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

NameTypeDescription
amountuint256Amount of YFI tokens to lock.

Returns

NameTypeDescription
<none>IVotingYFI.LockedBalanceThe 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

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

NameTypeDescription
treasury_addressaddress to receive rewards

setSwapAndLock

Sets the address for the SwapAndLock contract.

function setSwapAndLock(address newSwapAndLock) external onlyRole(TIMELOCK_ROLE);

Parameters

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

NameTypeDescription
gaugeaddressaddress of the gauge token
treasuryPctuint64percentage of rewards to treasury
coveYfiPctuint64percentage of rewards to coveYFI Reward Forwarder
userPctuint64percentage of rewards to user
veYfiPctuint64percentage 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

NameTypeDescription
treasuryPctuint128percentage of rewards to treasury
coveYfiPctuint128percentage 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

NameTypeDescription
treasuryPctuint128percentage of rewards to treasury
coveYfiPctuint128percentage 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

NameTypeDescription
gaugeTokenaddressaddress of the gauge token
limituint256maximum 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

NameTypeDescription
idbytes32name of the space in snapshot to apply delegation. For yearn it is "veyfi.eth"
delegateaddressaddress to delegate voting power to

addGaugeRewards

Adds gauge rewards configuration.

function addGaugeRewards(
    address gauge,
    address stakingDelegateRewards
)
    external
    nonReentrant
    onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
gaugeaddressAddress of the gauge.
stakingDelegateRewardsaddressAddress of the StakingDelegateRewards contract.

updateGaugeRewards

Updates gauge rewards configuration.

function updateGaugeRewards(
    address gauge,
    address stakingDelegateRewards
)
    external
    nonReentrant
    onlyRole(TIMELOCK_ROLE);

Parameters

NameTypeDescription
gaugeaddressAddress of the gauge.
stakingDelegateRewardsaddressAddress of the new StakingDelegateRewards contract.

setPerpetualLock

Set perpetual lock status

function setPerpetualLock(bool lock) external onlyRole(TIMELOCK_ROLE);

Parameters

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

NameTypeDescription
targetaddresscontract to call
databytescalldata to execute the call with
valueuint256call value

Returns

NameTypeDescription
<none>bytesresult of the call

availableDepositLimit

Get the available deposit limit for a gauge token

function availableDepositLimit(address gaugeToken) external view returns (uint256);

Parameters

NameTypeDescription
gaugeTokenaddressThe address of the gauge token

Returns

NameTypeDescription
<none>uint256Available deposit limit

getBoostRewardSplit

Get the dYFI boost reward split

function getBoostRewardSplit() external view returns (BoostRewardSplit memory);

Returns

NameTypeDescription
<none>BoostRewardSplitBoostRewardSplit struct containing the treasury and coveYFI split.

getExitRewardSplit

Get the YFI exit reward split

function getExitRewardSplit() external view returns (ExitRewardSplit memory);

Returns

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

NameTypeDescription
gaugeaddressAddress of the gauge

Returns

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

NameTypeDescription
<none>addressThe address of the treasury

coveYfiRewardForwarder

Get the address of the stored CoveYFI Reward Forwarder

function coveYfiRewardForwarder() external view returns (address);

Returns

NameTypeDescription
<none>addressThe address of the CoveYFI Reward Forwarder

swapAndLock

Get the address of the SwapAndLock contract

function swapAndLock() external view returns (address);

Returns

NameTypeDescription
<none>addressThe address of the SwapAndLock contract

shouldPerpetuallyLock

Get the perpetual lock status

function shouldPerpetuallyLock() external view returns (bool);

Returns

NameTypeDescription
<none>boolTrue if perpetual lock is enabled

yfi

Get the address of the YFI token

function yfi() external pure returns (address);

Returns

NameTypeDescription
<none>addressThe address of the YFI token

dYfi

Get the address of the dYFI token

function dYfi() external pure returns (address);

Returns

NameTypeDescription
<none>addressThe address of the dYFI token

veYfi

Get the address of the veYFI token

function veYfi() external pure returns (address);

Returns

NameTypeDescription
<none>addressThe address of the veYFI token

_setTreasury

Internal function to set the treasury address.

function _setTreasury(address treasury_) internal;

Parameters

NameTypeDescription
treasury_addressThe address of the new treasury.

_setCoveYfiRewardForwarder

Internal function to set the CoveYFI Reward Forwarder address.

function _setCoveYfiRewardForwarder(address forwarder) internal;

Parameters

NameTypeDescription
forwarderaddressThe address of the CoveYFI Reward Forwarder.

_setGaugeRewards

Internal function to set gauge rewards and reward receiver.

function _setGaugeRewards(address gauge, address stakingDelegateRewards) internal;

Parameters

NameTypeDescription
gaugeaddressAddress of the gauge.
stakingDelegateRewardsaddressAddress of the StakingDelegateRewards contract.

_setPerpetualLock

Internal function to set the perpetual lock status.

function _setPerpetualLock(bool lock) internal;

Parameters

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

NameTypeDescription
gaugeaddressAddress of the gauge.
treasuryPctuint64Percentage of rewards to the treasury.
coveYfiPctuint64
userPctuint64Percentage of rewards to the user.
lockPctuint64Percentage 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

NameTypeDescription
treasuryPctuint128Percentage of rewards to the treasury.
coveYfiPctuint128Percentage 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

NameTypeDescription
treasuryPctuint128Percentage of rewards to the treasury.
coveYfiPctuint128Percentage 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

NameTypeDescription
stakingDelegateRewardaddressAddress of the StakingDelegateRewards contract.
gaugeaddressAddress of the gauge.
useraddressAddress of the user.
userBalanceuint256New balance of the user for the gauge.
currentTotalDepositeduint256

Events

LockYfi

Emitted when YFI tokens are locked.

event LockYfi(address indexed sender, uint256 amount);

Parameters

NameTypeDescription
senderaddressThe address of the sender who locked YFI tokens.
amountuint256The amount of YFI tokens locked.

GaugeRewardsSet

Emitted when gauge rewards are set.

event GaugeRewardsSet(address indexed gauge, address stakingRewardsContract, address receiver);

Parameters

NameTypeDescription
gaugeaddressThe address of the gauge for which rewards are set.
stakingRewardsContractaddressThe address of the staking rewards contract.
receiveraddressThe address of the rewards receiver.

PerpetualLockSet

Emitted when the perpetual lock setting is updated.

event PerpetualLockSet(bool shouldLock);

Parameters

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

NameTypeDescription
gaugeaddressThe address of the gauge for which the reward split is set.
splitRewardSplitThe reward split configuration.

BoostRewardSplitSet

Emitted when the boost reward split configuration is set.

event BoostRewardSplitSet(uint128 treasuryPct, uint128 coveYfiPct);

Parameters

NameTypeDescription
treasuryPctuint128The percentage of the boost reward allocated to the treasury.
coveYfiPctuint128The 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

NameTypeDescription
treasuryPctuint128The percentage of the exit reward allocated to the treasury.
coveYfiPctuint128The percentage of the exit reward allocated to CoveYFI.

DepositLimitSet

Emitted when a deposit limit is set.

event DepositLimitSet(address indexed gaugeToken, uint256 limit);

Parameters

NameTypeDescription
gaugeTokenaddressThe address of the gauge token for which the deposit limit is set.
limituint256The deposit limit.

SwapAndLockSet

Emitted when the swap and lock contract address is set.

event SwapAndLockSet(address swapAndLockContract);

Parameters

NameTypeDescription
swapAndLockContractaddressThe address of the swap and lock contract.

TreasurySet

Emitted when the treasury address is updated.

event TreasurySet(address newTreasury);

Parameters

NameTypeDescription
newTreasuryaddressThe new address of the treasury.

CoveYfiRewardForwarderSet

Emitted when the CoveYFI reward forwarder address is set.

event CoveYfiRewardForwarderSet(address forwarder);

Parameters

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

NameTypeDescription
senderaddressThe address of the sender who made the deposit.
gaugeaddressThe address of the gauge token deposited.
amountuint256The amount of tokens deposited.
newTotalDepositeduint256The 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

NameTypeDescription
senderaddressThe address of the sender who made the withdrawal.
gaugeaddressThe address of the gauge token withdrawn.
amountuint256The amount of tokens withdrawn.
newTotalDepositeduint256The 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

NameTypeDescription
stakingDelegateRewardsaddressThe address of the StakingDelegateRewards contract.
useraddressThe address of the user whose balance failed to checkpoint.
gaugeaddressThe address of the gauge token.
currentUserBalanceuint256The current balance of gauge tokens deposited by the user.
currentTotalDepositeduint256The current total amount of the gauge tokens deposited across all users.