View Source: contracts/core/governance/resolution/Unstakable.sol
↗ Extends: Resolvable, IUnstakable ↘ Derived Contracts: Resolution
Unstakable
Enables voters to unstake their NPM tokens after resolution is achieved on any cover product.
- unstake(bytes32 coverKey, bytes32 productKey, uint256 incidentDate)
- unstakeWithClaim(bytes32 coverKey, bytes32 productKey, uint256 incidentDate)
- getUnstakeInfoFor(address account, bytes32 coverKey, bytes32 productKey, uint256 incidentDate)
Reporters on the valid camp can unstake their tokens even after the claim period is over.
Unlike unstakeWithClaim
, stakers can unstake but do not receive any reward if they choose to
use this function.
function unstake(bytes32 coverKey, bytes32 productKey, uint256 incidentDate) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
productKey | bytes32 | Enter the product key |
incidentDate | uint256 | Enter the incident date |
Source Code
function unstake(
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate
) external override nonReentrant {
require(incidentDate > 0, "Please specify incident date");
// Incident date is reset (when cover is finalized) and
// therefore shouldn't be validated otherwise "valid" reporters
// will never be able to unstake
// s.mustBeValidIncidentDate(coverKey, productKey, incidentDate);
s.validateUnstakeWithoutClaim(coverKey, productKey, incidentDate);
(, , uint256 myStakeInWinningCamp) = s.getResolutionInfoForInternal(msg.sender, coverKey, productKey, incidentDate);
// Set the unstake details
s.updateUnstakeDetailsInternal(msg.sender, coverKey, productKey, incidentDate, myStakeInWinningCamp, 0, 0, 0);
s.npmToken().ensureTransfer(msg.sender, myStakeInWinningCamp);
s.updateStateAndLiquidity(coverKey);
emit Unstaken(coverKey, productKey, msg.sender, myStakeInWinningCamp, 0);
}
Reporters on the valid camp can unstake their token with a claim
to receive
back their original stake with a portion of the invalid camp's stake
as an additional reward.
During each unstake with claim
processing, the protocol distributes reward to
the final reporter and also burns some NPM tokens, as described in the documentation.
function unstakeWithClaim(bytes32 coverKey, bytes32 productKey, uint256 incidentDate) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
productKey | bytes32 | Enter the product key |
incidentDate | uint256 | Enter the incident date |
Source Code
function unstakeWithClaim(
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate
) external override nonReentrant {
require(incidentDate > 0, "Please specify incident date");
s.validateUnstakeWithClaim(coverKey, productKey, incidentDate);
address finalReporter = s.getReporterInternal(coverKey, productKey, incidentDate);
address burner = s.getBurnAddress();
UnstakeInfoType memory info = s.getUnstakeInfoForInternal(msg.sender, coverKey, productKey, incidentDate);
// Set the unstake details
s.updateUnstakeDetailsInternal(msg.sender, coverKey, productKey, incidentDate, info.myStakeInWinningCamp, info.myReward, info.toBurn, info.toReporter);
uint256 myStakeWithReward = info.myReward + info.myStakeInWinningCamp;
s.npmToken().ensureTransfer(msg.sender, myStakeWithReward);
if (info.toReporter > 0) {
s.npmToken().ensureTransfer(finalReporter, info.toReporter);
}
if (info.toBurn > 0) {
s.npmToken().ensureTransfer(burner, info.toBurn);
}
s.updateStateAndLiquidity(coverKey);
emit Unstaken(coverKey, productKey, msg.sender, info.myStakeInWinningCamp, info.myReward);
emit ReporterRewardDistributed(coverKey, productKey, msg.sender, finalReporter, info.myReward, info.toReporter);
emit GovernanceBurned(coverKey, productKey, msg.sender, burner, info.myReward, info.toBurn);
}
Gets the unstake information for the supplied account Warning: this function does not validate the input arguments.
function getUnstakeInfoFor(address account, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) external view
returns(struct IUnstakable.UnstakeInfoType)
Arguments
Name | Type | Description |
---|---|---|
account | address | Enter account to get the unstake information of |
coverKey | bytes32 | Enter the cover key |
productKey | bytes32 | |
incidentDate | uint256 | Enter the incident date |
Source Code
function getUnstakeInfoFor(
address account,
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate
) external view override returns (UnstakeInfoType memory) {
return s.getUnstakeInfoForInternal(account, coverKey, productKey, incidentDate);
}
- AaveStrategy
- AccessControl
- AccessControlLibV1
- Address
- BaseLibV1
- BokkyPooBahsDateTimeLibrary
- BondPool
- BondPoolBase
- BondPoolLibV1
- CompoundStrategy
- Context
- Cover
- CoverBase
- CoverLibV1
- CoverReassurance
- CoverStake
- CoverUtilV1
- cxToken
- cxTokenFactory
- cxTokenFactoryLibV1
- Delayable
- Destroyable
- ERC165
- ERC20
- FakeAaveLendingPool
- FakeCompoundDaiDelegator
- FakePriceOracle
- FakeRecoverable
- FakeStore
- FakeToken
- FakeUniswapPair
- FakeUniswapV2FactoryLike
- FakeUniswapV2PairLike
- FakeUniswapV2RouterLike
- FaultyAaveLendingPool
- FaultyCompoundDaiDelegator
- Finalization
- ForceEther
- Governance
- GovernanceUtilV1
- IAaveV2LendingPoolLike
- IAccessControl
- IBondPool
- IClaimsProcessor
- ICompoundERC20DelegatorLike
- ICover
- ICoverReassurance
- ICoverStake
- ICxToken
- ICxTokenFactory
- IERC165
- IERC20
- IERC20Detailed
- IERC20Metadata
- IERC3156FlashBorrower
- IERC3156FlashLender
- IFinalization
- IGovernance
- ILendingStrategy
- ILiquidityEngine
- IMember
- INeptuneRouterV1
- InvalidStrategy
- IPausable
- IPolicy
- IPolicyAdmin
- IPriceOracle
- IProtocol
- IRecoverable
- IReporter
- IResolution
- IResolvable
- IStakingPools
- IStore
- IStoreLike
- IUniswapV2FactoryLike
- IUniswapV2PairLike
- IUniswapV2RouterLike
- IUnstakable
- IVault
- IVaultDelegate
- IVaultFactory
- IWitness
- LiquidityEngine
- MaliciousToken
- MockAccessControlUser
- MockCoverUtilUser
- MockCxToken
- MockCxTokenPolicy
- MockCxTokenStore
- MockFlashBorrower
- MockLiquidityEngineUser
- MockProcessorStore
- MockProcessorStoreLib
- MockProtocol
- MockRegistryClient
- MockStore
- MockStoreKeyUtilUser
- MockValidationLibUser
- MockVault
- MockVaultLibUser
- NeptuneRouterV1
- NPM
- NpmDistributor
- NTransferUtilV2
- NTransferUtilV2Intermediate
- Ownable
- Pausable
- Policy
- PolicyAdmin
- PolicyHelperV1
- PoorMansERC20
- POT
- PriceLibV1
- Processor
- ProtoBase
- Protocol
- ProtoUtilV1
- Recoverable
- ReentrancyGuard
- RegistryLibV1
- Reporter
- Resolution
- Resolvable
- RoutineInvokerLibV1
- SafeERC20
- StakingPoolBase
- StakingPoolCoreLibV1
- StakingPoolInfo
- StakingPoolLibV1
- StakingPoolReward
- StakingPools
- Store
- StoreBase
- StoreKeyUtil
- StrategyLibV1
- Strings
- TimelockController
- Unstakable
- ValidationLibV1
- Vault
- VaultBase
- VaultDelegate
- VaultDelegateBase
- VaultDelegateWithFlashLoan
- VaultFactory
- VaultFactoryLibV1
- VaultLibV1
- VaultLiquidity
- VaultStrategy
- WithFlashLoan
- WithPausability
- WithRecovery
- Witness