View Source: contracts/governance/Staking/modules/shared/CheckpointsShared.sol
↗ Extends: StakingStorageShared, SafeMath96 ↘ Derived Contracts: StakingGovernanceModule, StakingStakeModule, StakingWithdrawModule, WeightedStakingModule
Increases and decreases storage values for users, delegatees and total daily stake.
Events
event DelegateChanged(address indexed delegator, uint256 lockedUntil, address indexed fromDelegate, address indexed toDelegate);
event DelegateStakeChanged(address indexed delegate, uint256 lockedUntil, uint256 previousBalance, uint256 newBalance);
event TokensStaked(address indexed staker, uint256 amount, uint256 lockedUntil, uint256 totalStaked);
event StakingWithdrawn(address indexed staker, uint256 amount, uint256 until, address indexed receiver, bool isGovernance);
event VestingTokensWithdrawn(address vesting, address receiver);
event TokensUnlocked(uint256 amount);
event ExtendedStakingDuration(address indexed staker, uint256 previousDate, uint256 newDate, uint256 amountStaked);
event AdminAdded(address admin);
event AdminRemoved(address admin);
event PauserAddedOrRemoved(address indexed pauser, bool indexed added);
event StakingPaused(bool indexed setPaused);
event StakingFrozen(bool indexed setFrozen);
event ContractCodeHashAdded(bytes32 hash);
event ContractCodeHashRemoved(bytes32 hash);
event VestingStakeSet(uint256 lockedTS, uint96 value);
event TeamVestingCancelled(address indexed caller, address receiver);
event TeamVestingPartiallyCancelled(address indexed caller, address receiver, uint256 lastProcessedDate);
- constructor()
- _increaseVestingStake(uint256 lockedTS, uint96 value)
- _decreaseVestingStake(uint256 lockedTS, uint96 value)
- _writeVestingCheckpoint(uint256 lockedTS, uint32 nCheckpoints, uint96 newVest)
- _increaseUserStake(address account, uint256 lockedTS, uint96 value)
- _decreaseUserStake(address account, uint256 lockedTS, uint96 value)
- _writeUserCheckpoint(address account, uint256 lockedTS, uint32 nCheckpoints, uint96 newStake)
- _increaseDelegateStake(address delegatee, uint256 lockedTS, uint96 value)
- _decreaseDelegateStake(address delegatee, uint256 lockedTS, uint96 value)
- _writeDelegateCheckpoint(address delegatee, uint256 lockedTS, uint32 nCheckpoints, uint96 newStake)
- _increaseDailyStake(uint256 lockedTS, uint96 value)
- _decreaseDailyStake(uint256 lockedTS, uint96 value)
- _writeStakingCheckpoint(uint256 lockedTS, uint32 nCheckpoints, uint96 newStake)
- _currentBalance(address account, uint256 lockDate)
function () internal nonpayable
Source Code
constructor() internal {
// abstract
}
Increases the user's vesting stake for a giving lock date and writes a checkpoint.
function _increaseVestingStake(uint256 lockedTS, uint96 value) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
lockedTS | uint256 | The lock date. |
value | uint96 | The value to add to the staked balance. |
Source Code
function _increaseVestingStake(uint256 lockedTS, uint96 value) internal {
uint32 nCheckpoints = numVestingCheckpoints[lockedTS];
uint96 vested = vestingCheckpoints[lockedTS][nCheckpoints - 1].stake;
uint96 newVest = add96(vested, value, "CP01"); // vested overflow
_writeVestingCheckpoint(lockedTS, nCheckpoints, newVest);
}
Decreases the user's vesting stake for a giving lock date and writes a checkpoint.
function _decreaseVestingStake(uint256 lockedTS, uint96 value) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
lockedTS | uint256 | The lock date. |
value | uint96 | The value to substract to the staked balance. |
Source Code
function _decreaseVestingStake(uint256 lockedTS, uint96 value) internal {
uint32 nCheckpoints = numVestingCheckpoints[lockedTS];
uint96 vested = vestingCheckpoints[lockedTS][nCheckpoints - 1].stake;
uint96 newVest = sub96(vested, value, "CP02"); // vested underflow
_writeVestingCheckpoint(lockedTS, nCheckpoints, newVest);
}
Writes on storage the user vested amount.
function _writeVestingCheckpoint(uint256 lockedTS, uint32 nCheckpoints, uint96 newVest) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
lockedTS | uint256 | The lock date. |
nCheckpoints | uint32 | The number of checkpoints, to find out the last one index. |
newVest | uint96 | The new vest balance. |
Source Code
function _writeVestingCheckpoint(
uint256 lockedTS,
uint32 nCheckpoints,
uint96 newVest
) internal {
uint32 blockNumber = safe32(block.number, "CP03"); // block num > 32 bits
if (
nCheckpoints > 0 &&
vestingCheckpoints[lockedTS][nCheckpoints - 1].fromBlock == blockNumber
) {
vestingCheckpoints[lockedTS][nCheckpoints - 1].stake = newVest;
} else {
vestingCheckpoints[lockedTS][nCheckpoints] = Checkpoint(blockNumber, newVest);
numVestingCheckpoints[lockedTS] = nCheckpoints + 1;
}
}
Increases the user's stake for a giving lock date and writes a checkpoint.
function _increaseUserStake(address account, uint256 lockedTS, uint96 value) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
account | address | The user address. |
lockedTS | uint256 | The lock date. |
value | uint96 | The value to add to the staked balance. |
Source Code
function _increaseUserStake(
address account,
uint256 lockedTS,
uint96 value
) internal {
uint32 nCheckpoints = numUserStakingCheckpoints[account][lockedTS];
uint96 staked = userStakingCheckpoints[account][lockedTS][nCheckpoints - 1].stake;
uint96 newStake = add96(staked, value, "CP04"); // staked overflow
_writeUserCheckpoint(account, lockedTS, nCheckpoints, newStake);
}
Decreases the user's stake for a giving lock date and writes a checkpoint.
function _decreaseUserStake(address account, uint256 lockedTS, uint96 value) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
account | address | The user address. |
lockedTS | uint256 | The lock date. |
value | uint96 | The value to substract to the staked balance. |
Source Code
function _decreaseUserStake(
address account,
uint256 lockedTS,
uint96 value
) internal {
uint32 nCheckpoints = numUserStakingCheckpoints[account][lockedTS];
uint96 staked = userStakingCheckpoints[account][lockedTS][nCheckpoints - 1].stake;
uint96 newStake = sub96(staked, value, "CP05"); // staked underflow
_writeUserCheckpoint(account, lockedTS, nCheckpoints, newStake);
}
Writes on storage the user stake.
function _writeUserCheckpoint(address account, uint256 lockedTS, uint32 nCheckpoints, uint96 newStake) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
account | address | The user address. |
lockedTS | uint256 | The lock date. |
nCheckpoints | uint32 | The number of checkpoints, to find out the last one index. |
newStake | uint96 | The new staked balance. |
Source Code
function _writeUserCheckpoint(
address account,
uint256 lockedTS,
uint32 nCheckpoints,
uint96 newStake
) internal {
uint32 blockNumber = safe32(block.number, "CP06"); // block number > 32 bits
if (
nCheckpoints > 0 &&
userStakingCheckpoints[account][lockedTS][nCheckpoints - 1].fromBlock == blockNumber
) {
userStakingCheckpoints[account][lockedTS][nCheckpoints - 1].stake = newStake;
} else {
userStakingCheckpoints[account][lockedTS][nCheckpoints] = Checkpoint(
blockNumber,
newStake
);
numUserStakingCheckpoints[account][lockedTS] = nCheckpoints + 1;
}
}
Increases the delegatee's stake for a giving lock date and writes a checkpoint.
function _increaseDelegateStake(address delegatee, uint256 lockedTS, uint96 value) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
delegatee | address | The delegatee address. |
lockedTS | uint256 | The lock date. |
value | uint96 | The value to add to the staked balance. |
Source Code
function _increaseDelegateStake(
address delegatee,
uint256 lockedTS,
uint96 value
) internal {
uint32 nCheckpoints = numDelegateStakingCheckpoints[delegatee][lockedTS];
uint96 staked = delegateStakingCheckpoints[delegatee][lockedTS][nCheckpoints - 1].stake;
uint96 newStake = add96(staked, value, "CP07"); // block number > 32 bits
_writeDelegateCheckpoint(delegatee, lockedTS, nCheckpoints, newStake);
}
Decreases the delegatee's stake for a giving lock date and writes a checkpoint.
function _decreaseDelegateStake(address delegatee, uint256 lockedTS, uint96 value) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
delegatee | address | The delegatee address. |
lockedTS | uint256 | The lock date. |
value | uint96 | The value to substract to the staked balance. |
Source Code
function _decreaseDelegateStake(
address delegatee,
uint256 lockedTS,
uint96 value
) internal {
uint32 nCheckpoints = numDelegateStakingCheckpoints[delegatee][lockedTS];
uint96 staked = delegateStakingCheckpoints[delegatee][lockedTS][nCheckpoints - 1].stake;
uint96 newStake = 0;
// @dev We need to check delegate checkpoint value here,
// because we had an issue in `stake` function:
// delegate checkpoint wasn't updating for the second and next stakes for the same date
// if first stake was withdrawn completely and stake was delegated to the staker
// (no delegation to another address).
// @dev It can be greater than 0, but inconsistent after 3 transactions
if (staked > value) {
newStake = sub96(staked, value, "CP08"); // staked underflow
}
_writeDelegateCheckpoint(delegatee, lockedTS, nCheckpoints, newStake);
}
Writes on storage the delegate stake.
function _writeDelegateCheckpoint(address delegatee, uint256 lockedTS, uint32 nCheckpoints, uint96 newStake) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
delegatee | address | The delegate address. |
lockedTS | uint256 | The lock date. |
nCheckpoints | uint32 | The number of checkpoints, to find out the last one index. |
newStake | uint96 | The new staked balance. |
Source Code
function _writeDelegateCheckpoint(
address delegatee,
uint256 lockedTS,
uint32 nCheckpoints,
uint96 newStake
) internal {
uint32 blockNumber = safe32(block.number, "CP09"); // block numb > 32 bits
uint96 oldStake = delegateStakingCheckpoints[delegatee][lockedTS][nCheckpoints - 1].stake;
if (
nCheckpoints > 0 &&
delegateStakingCheckpoints[delegatee][lockedTS][nCheckpoints - 1].fromBlock ==
blockNumber
) {
delegateStakingCheckpoints[delegatee][lockedTS][nCheckpoints - 1].stake = newStake;
} else {
delegateStakingCheckpoints[delegatee][lockedTS][nCheckpoints] = Checkpoint(
blockNumber,
newStake
);
numDelegateStakingCheckpoints[delegatee][lockedTS] = nCheckpoints + 1;
}
emit DelegateStakeChanged(delegatee, lockedTS, oldStake, newStake);
}
Increases the total stake for a giving lock date and writes a checkpoint.
function _increaseDailyStake(uint256 lockedTS, uint96 value) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
lockedTS | uint256 | The lock date. |
value | uint96 | The value to add to the staked balance. |
Source Code
function _increaseDailyStake(uint256 lockedTS, uint96 value) internal {
uint32 nCheckpoints = numTotalStakingCheckpoints[lockedTS];
uint96 staked = totalStakingCheckpoints[lockedTS][nCheckpoints - 1].stake;
uint96 newStake = add96(staked, value, "CP10"); // staked overflow
_writeStakingCheckpoint(lockedTS, nCheckpoints, newStake);
}
Decreases the total stake for a giving lock date and writes a checkpoint.
function _decreaseDailyStake(uint256 lockedTS, uint96 value) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
lockedTS | uint256 | The lock date. |
value | uint96 | The value to substract to the staked balance. |
Source Code
function _decreaseDailyStake(uint256 lockedTS, uint96 value) internal {
uint32 nCheckpoints = numTotalStakingCheckpoints[lockedTS];
uint96 staked = totalStakingCheckpoints[lockedTS][nCheckpoints - 1].stake;
uint96 newStake = sub96(staked, value, "CP11"); // staked underflow
_writeStakingCheckpoint(lockedTS, nCheckpoints, newStake);
}
Writes on storage the total stake.
function _writeStakingCheckpoint(uint256 lockedTS, uint32 nCheckpoints, uint96 newStake) internal nonpayable
Arguments
Name | Type | Description |
---|---|---|
lockedTS | uint256 | The lock date. |
nCheckpoints | uint32 | The number of checkpoints, to find out the last one index. |
newStake | uint96 | The new staked balance. |
Source Code
function _writeStakingCheckpoint(
uint256 lockedTS,
uint32 nCheckpoints,
uint96 newStake
) internal {
uint32 blockNumber = safe32(block.number, "CP12"); // block num > 32 bits
if (
nCheckpoints > 0 &&
totalStakingCheckpoints[lockedTS][nCheckpoints - 1].fromBlock == blockNumber
) {
totalStakingCheckpoints[lockedTS][nCheckpoints - 1].stake = newStake;
} else {
totalStakingCheckpoints[lockedTS][nCheckpoints] = Checkpoint(blockNumber, newStake);
numTotalStakingCheckpoints[lockedTS] = nCheckpoints + 1;
}
}
Get the current balance of an account locked until a certain date.
function _currentBalance(address account, uint256 lockDate) internal view
returns(uint96)
Arguments
Name | Type | Description |
---|---|---|
account | address | The user address. |
lockDate | uint256 | The lock date. |
Returns
The stake amount.
Source Code
function _currentBalance(address account, uint256 lockDate) internal view returns (uint96) {
uint32 _numUnserStakingCheckpoints = numUserStakingCheckpoints[account][lockDate] - 1;
return userStakingCheckpoints[account][lockDate][_numUnserStakingCheckpoints].stake;
}
- 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