View Source: contracts/governance/Staking/modules/WeightedStakingModule.sol
↗ Extends: IFunctionsList, StakingShared, CheckpointsShared
Implements getters for weighted staking functionality
- getPriorWeightedStake(address account, uint256 blockNumber, uint256 date)
- _getPriorWeightedStake(address account, uint256 blockNumber, uint256 date)
- weightedStakeByDate(address account, uint256 date, uint256 startDate, uint256 blockNumber)
- _weightedStakeByDate(address account, uint256 date, uint256 startDate, uint256 blockNumber)
- computeWeightByDate(uint256 date, uint256 startDate)
- getFunctionsList()
Determine the prior weighted stake for an account as of a block number. Iterate through checkpoints adding up voting power.
function getPriorWeightedStake(address account, uint256 blockNumber, uint256 date) external view
returns(priorWeightedStake uint96)
Arguments
Name | Type | Description |
---|---|---|
account | address | The address of the account to check. |
blockNumber | uint256 | The block number to get the vote balance at. |
date | uint256 | The date/timestamp of the unstaking time. |
Returns
The weighted stake the account had as of the given block.
Source Code
function getPriorWeightedStake(
address account,
uint256 blockNumber,
uint256 date
) external view returns (uint96 priorWeightedStake) {
return _getPriorWeightedStake(account, blockNumber, date);
}
function _getPriorWeightedStake(address account, uint256 blockNumber, uint256 date) internal view
returns(priorWeightedStake uint96)
Arguments
Name | Type | Description |
---|---|---|
account | address | |
blockNumber | uint256 | |
date | uint256 |
Source Code
function _getPriorWeightedStake(
address account,
uint256 blockNumber,
uint256 date
) internal view returns (uint96 priorWeightedStake) {
/// @dev If date is not an exact break point, start weight computation from the previous break point (alternative would be the next).
uint256 start = _timestampToLockDate(date);
uint256 end = start + MAX_DURATION;
/// @dev Max 78 iterations.
for (uint256 i = start; i <= end; i += TWO_WEEKS) {
uint96 weightedStake = _weightedStakeByDate(account, i, start, blockNumber);
if (weightedStake > 0) {
priorWeightedStake = add96(
priorWeightedStake,
weightedStake,
"overflow on total weight calc"
); // WS12
}
}
}
Compute the voting power for a specific date. Power = stake * weight
function weightedStakeByDate(address account, uint256 date, uint256 startDate, uint256 blockNumber) external view
returns(power uint96)
Arguments
Name | Type | Description |
---|---|---|
account | address | The user address. |
date | uint256 | The staking date to compute the power for. Adjusted to the previous valid lock date, if necessary. |
startDate | uint256 | The date for which we need to know the power of the stake. Adjusted to the previous valid lock date, if necessary. |
blockNumber | uint256 | The block number, needed for checkpointing. |
Returns
The staking power.
Source Code
function weightedStakeByDate(
address account,
uint256 date,
uint256 startDate,
uint256 blockNumber
) external view returns (uint96 power) {
date = _timestampToLockDate(date);
startDate = _timestampToLockDate(startDate);
return _weightedStakeByDate(account, date, startDate, blockNumber);
}
Compute the voting power for a specific date. Power = stake * weight
function _weightedStakeByDate(address account, uint256 date, uint256 startDate, uint256 blockNumber) internal view
returns(power uint96)
Arguments
Name | Type | Description |
---|---|---|
account | address | The user address. |
date | uint256 | The staking date to compute the power for. |
startDate | uint256 | The date for which we need to know the power of the stake. |
blockNumber | uint256 | The block number, needed for checkpointing. |
Returns
The staking power.
Source Code
function _weightedStakeByDate(
address account,
uint256 date,
uint256 startDate,
uint256 blockNumber
) internal view returns (uint96 power) {
uint96 staked = _getPriorUserStakeByDate(account, date, blockNumber);
if (staked > 0) {
uint96 weight = _computeWeightByDate(date, startDate);
power = mul96(staked, weight, "mul overflow") / WEIGHT_FACTOR; // WS13
} else {
power = 0;
}
}
Compute the weight for a specific date.
function computeWeightByDate(uint256 date, uint256 startDate) external pure
returns(weight uint96)
Arguments
Name | Type | Description |
---|---|---|
date | uint256 | The unlocking date. |
startDate | uint256 | We compute the weight for the tokens staked until 'date' on 'startDate'. |
Returns
The weighted stake the account had as of the given block.
Source Code
function computeWeightByDate(uint256 date, uint256 startDate)
external
pure
returns (uint96 weight)
{
return _computeWeightByDate(date, startDate);
}
⤾ overrides IFunctionsList.getFunctionsList
function getFunctionsList() external pure
returns(bytes4[])
Source Code
function getFunctionsList() external pure returns (bytes4[] memory) {
bytes4[] memory functionsList = new bytes4[](3);
functionsList[0] = this.getPriorWeightedStake.selector;
functionsList[1] = this.weightedStakeByDate.selector;
functionsList[2] = this.computeWeightByDate.selector;
return functionsList;
}
- 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