View Source: contracts/governance/Vesting/VestingLogic.sol
↗ Extends: IVesting, VestingStorage, ApprovalReceiver
Staking, delegating and withdrawal functionality.
Events
event TokensStaked(address indexed caller, uint256 amount);
event VotesDelegated(address indexed caller, address delegatee);
event TokensWithdrawn(address indexed caller, address receiver);
event DividendsCollected(address indexed caller, address loanPoolToken, address receiver, uint32 maxCheckpoints);
event MigratedToNewStakingContract(address indexed caller, address newStakingContract);
Throws if called by any account other than the token owner or the contract owner.
modifier onlyOwners() internal
Throws if called by any account other than the token owner.
modifier onlyTokenOwner() internal
- stakeTokens(uint256 _amount)
- stakeTokensWithApproval(address _sender, uint256 _amount)
- _stakeTokens(address _sender, uint256 _amount)
- delegate(address _delegatee)
- governanceWithdrawTokens(address receiver)
- withdrawTokens(address receiver)
- _withdrawTokens(address receiver, bool isGovernance)
- collectDividends(address _loanPoolToken, uint32 _maxCheckpoints, address _receiver)
- migrateToNewStakingContract()
- _getToken()
- _getSelectors()
⤾ overrides IVesting.stakeTokens
Stakes tokens according to the vesting schedule.
function stakeTokens(uint256 _amount) public nonpayable
Arguments
Name | Type | Description |
---|---|---|
_amount | uint256 | The amount of tokens to stake. |
Source Code
function stakeTokens(uint256 _amount) public {
_stakeTokens(msg.sender, _amount);
}
Stakes tokens according to the vesting schedule.
function stakeTokensWithApproval(address _sender, uint256 _amount) public nonpayable onlyThisContract
Arguments
Name | Type | Description |
---|---|---|
_sender | address | The sender of SOV.approveAndCall |
_amount | uint256 | The amount of tokens to stake. |
Source Code
function stakeTokensWithApproval(address _sender, uint256 _amount) public onlyThisContract {
_stakeTokens(_sender, _amount);
}
Stakes tokens according to the vesting schedule. Low level function.
function _stakeTokens(address _sender, uint256 _amount) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
_sender | address | The sender of tokens to stake. |
_amount | uint256 | The amount of tokens to stake. |
Source Code
function _stakeTokens(address _sender, uint256 _amount) internal {
/// @dev Maybe better to allow staking unil the cliff was reached.
if (startDate == 0) {
startDate = staking.timestampToLockDate(block.timestamp);
}
endDate = staking.timestampToLockDate(block.timestamp + duration);
/// @dev Transfer the tokens to this contract.
bool success = SOV.transferFrom(_sender, address(this), _amount);
require(success);
/// @dev Allow the staking contract to access them.
SOV.approve(address(staking), _amount);
staking.stakeBySchedule(_amount, cliff, duration, FOUR_WEEKS, address(this), tokenOwner);
emit TokensStaked(_sender, _amount);
}
Delegate votes from msg.sender
which are locked until lockDate
to delegatee
.
function delegate(address _delegatee) public nonpayable onlyTokenOwner
Arguments
Name | Type | Description |
---|---|---|
_delegatee | address | The address to delegate votes to. |
Source Code
function delegate(address _delegatee) public onlyTokenOwner {
require(_delegatee != address(0), "delegatee address invalid");
/// @dev Withdraw for each unlocked position.
/// @dev Don't change FOUR_WEEKS to TWO_WEEKS, a lot of vestings already deployed with FOUR_WEEKS
/// workaround found, but it doesn't work with TWO_WEEKS
for (uint256 i = startDate + cliff; i <= endDate; i += FOUR_WEEKS) {
staking.delegate(_delegatee, i);
}
emit VotesDelegated(msg.sender, _delegatee);
}
Withdraws all tokens from the staking contract and forwards them to an address specified by the token owner.
function governanceWithdrawTokens(address receiver) public nonpayable
Arguments
Name | Type | Description |
---|---|---|
receiver | address | The receiving address. |
Source Code
function governanceWithdrawTokens(address receiver) public {
require(msg.sender == address(staking), "unauthorized");
_withdrawTokens(receiver, true);
}
Withdraws unlocked tokens from the staking contract and forwards them to an address specified by the token owner.
function withdrawTokens(address receiver) public nonpayable onlyOwners
Arguments
Name | Type | Description |
---|---|---|
receiver | address | The receiving address. |
Source Code
function withdrawTokens(address receiver) public onlyOwners {
_withdrawTokens(receiver, false);
}
Withdraws tokens from the staking contract and forwards them to an address specified by the token owner. Low level function.
function _withdrawTokens(address receiver, bool isGovernance) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
receiver | address | The receiving address. |
isGovernance | bool | Whether all tokens (true) or just unlocked tokens (false). |
Source Code
function _withdrawTokens(address receiver, bool isGovernance) internal {
require(receiver != address(0), "receiver address invalid");
uint96 stake;
/// @dev Usually we just need to iterate over the possible dates until now.
uint256 end;
/// @dev In the unlikely case that all tokens have been unlocked early,
/// allow to withdraw all of them.
if (staking.allUnlocked() || isGovernance) {
end = endDate;
} else {
end = block.timestamp;
}
/// @dev Withdraw for each unlocked position.
/// @dev Don't change FOUR_WEEKS to TWO_WEEKS, a lot of vestings already deployed with FOUR_WEEKS
/// workaround found, but it doesn't work with TWO_WEEKS
for (uint256 i = startDate + cliff; i <= end; i += FOUR_WEEKS) {
/// @dev Read amount to withdraw.
stake = staking.getPriorUserStakeByDate(address(this), i, block.number - 1);
/// @dev Withdraw if > 0
if (stake > 0) {
if (isGovernance) {
staking.governanceWithdraw(stake, i, receiver);
} else {
staking.withdraw(stake, i, receiver);
}
}
}
emit TokensWithdrawn(msg.sender, receiver);
}
Collect dividends from fee sharing proxy.
function collectDividends(address _loanPoolToken, uint32 _maxCheckpoints, address _receiver) public nonpayable onlyOwners
Arguments
Name | Type | Description |
---|---|---|
_loanPoolToken | address | The loan pool token address. |
_maxCheckpoints | uint32 | Maximum number of checkpoints to be processed. |
_receiver | address | The receiver of tokens or msg.sender |
Source Code
function collectDividends(
address _loanPoolToken,
uint32 _maxCheckpoints,
address _receiver
) public onlyOwners {
require(_receiver != address(0), "receiver address invalid");
/// @dev Invokes the fee sharing proxy.
feeSharingCollector.withdraw(_loanPoolToken, _maxCheckpoints, _receiver);
emit DividendsCollected(msg.sender, _loanPoolToken, _receiver, _maxCheckpoints);
}
Allows the owners to migrate the positions to a new staking contract.
function migrateToNewStakingContract() public nonpayable onlyOwners
Source Code
function migrateToNewStakingContract() public onlyOwners {
staking.migrateToNewStakingContract();
staking = IStaking(staking.newStakingContract());
emit MigratedToNewStakingContract(msg.sender, address(staking));
}
⤾ overrides ApprovalReceiver._getToken
Overrides default ApprovalReceiver._getToken function to register SOV token on this contract.
function _getToken() internal view
returns(address)
Source Code
function _getToken() internal view returns (address) {
return address(SOV);
}
⤾ overrides ApprovalReceiver._getSelectors
Overrides default ApprovalReceiver._getSelectors function to register stakeTokensWithApproval selector on this contract.
function _getSelectors() internal pure
returns(bytes4[])
Source Code
function _getSelectors() internal pure returns (bytes4[] memory) {
bytes4[] memory selectors = new bytes4[](1);
selectors[0] = this.stakeTokensWithApproval.selector;
return selectors;
}
- Address
- Administered
- AdminRole
- AdvancedToken
- AdvancedTokenStorage
- Affiliates
- AffiliatesEvents
- ApprovalReceiver
- BProPriceFeed
- CheckpointsShared
- Constants
- Context
- DevelopmentFund
- DummyContract
- EnumerableAddressSet
- EnumerableBytes32Set
- EnumerableBytes4Set
- ERC20
- ERC20Detailed
- ErrorDecoder
- Escrow
- EscrowReward
- FeedsLike
- FeesEvents
- FeeSharingCollector
- FeeSharingCollectorProxy
- FeeSharingCollectorStorage
- FeesHelper
- FourYearVesting
- FourYearVestingFactory
- FourYearVestingLogic
- FourYearVestingStorage
- GenericTokenSender
- GovernorAlpha
- GovernorVault
- IApproveAndCall
- IChai
- IContractRegistry
- IConverterAMM
- IERC1820Registry
- IERC20_
- IERC20
- IERC777
- IERC777Recipient
- IERC777Sender
- IFeeSharingCollector
- IFourYearVesting
- IFourYearVestingFactory
- IFunctionsList
- ILiquidityMining
- ILiquidityPoolV1Converter
- ILoanPool
- ILoanToken
- ILoanTokenLogicBeacon
- ILoanTokenLogicModules
- ILoanTokenLogicProxy
- ILoanTokenModules
- ILoanTokenWRBTC
- ILockedSOV
- IMoCState
- IModulesProxyRegistry
- Initializable
- InterestUser
- IPot
- IPriceFeeds
- IPriceFeedsExt
- IProtocol
- IRSKOracle
- ISovryn
- ISovrynSwapNetwork
- IStaking
- ISwapsImpl
- ITeamVesting
- ITimelock
- IV1PoolOracle
- IVesting
- IVestingFactory
- IVestingRegistry
- IWrbtc
- IWrbtcERC20
- LenderInterestStruct
- LiquidationHelper
- LiquidityMining
- LiquidityMiningConfigToken
- LiquidityMiningProxy
- LiquidityMiningStorage
- LoanClosingsEvents
- LoanClosingsLiquidation
- LoanClosingsRollover
- LoanClosingsShared
- LoanClosingsWith
- LoanClosingsWithoutInvariantCheck
- LoanInterestStruct
- LoanMaintenance
- LoanMaintenanceEvents
- LoanOpenings
- LoanOpeningsEvents
- LoanParamsStruct
- LoanSettings
- LoanSettingsEvents
- LoanStruct
- LoanToken
- LoanTokenBase
- LoanTokenLogicBeacon
- LoanTokenLogicLM
- LoanTokenLogicProxy
- LoanTokenLogicStandard
- LoanTokenLogicStorage
- LoanTokenLogicWrbtc
- LoanTokenSettingsLowerAdmin
- LockedSOV
- MarginTradeStructHelpers
- Medianizer
- ModuleCommonFunctionalities
- ModulesCommonEvents
- ModulesProxy
- ModulesProxyRegistry
- MultiSigKeyHolders
- MultiSigWallet
- Mutex
- Objects
- OrderStruct
- OrigingVestingCreator
- OriginInvestorsClaim
- Ownable
- Pausable
- PausableOz
- PreviousLoanToken
- PreviousLoanTokenSettingsLowerAdmin
- PriceFeedRSKOracle
- PriceFeeds
- PriceFeedsLocal
- PriceFeedsMoC
- PriceFeedV1PoolOracle
- ProtocolAffiliatesInterface
- ProtocolLike
- ProtocolSettings
- ProtocolSettingsEvents
- ProtocolSettingsLike
- ProtocolSwapExternalInterface
- ProtocolTokenUser
- Proxy
- ProxyOwnable
- ReentrancyGuard
- RewardHelper
- RSKAddrValidator
- SafeERC20
- SafeMath
- SafeMath96
- setGet
- SharedReentrancyGuard
- SignedSafeMath
- SOV
- sovrynProtocol
- StakingAdminModule
- StakingGovernanceModule
- StakingInterface
- StakingProxy
- StakingRewards
- StakingRewardsProxy
- StakingRewardsStorage
- StakingShared
- StakingStakeModule
- StakingStorageModule
- StakingStorageShared
- StakingVestingModule
- StakingWithdrawModule
- State
- SwapsEvents
- SwapsExternal
- SwapsImplLocal
- SwapsImplSovrynSwap
- SwapsUser
- TeamVesting
- Timelock
- TimelockHarness
- TimelockInterface
- TokenSender
- UpgradableProxy
- USDTPriceFeed
- Utils
- VaultController
- Vesting
- VestingCreator
- VestingFactory
- VestingLogic
- VestingRegistry
- VestingRegistry2
- VestingRegistry3
- VestingRegistryLogic
- VestingRegistryProxy
- VestingRegistryStorage
- VestingStorage
- WeightedStakingModule
- WRBTC