View Source: contracts/core/lifecycle/CoverStake.sol
↗ Extends: ICoverStake, Recoverable
CoverStake
When you create a new cover, you have to specify the amount of
NPM tokens you wish to stake as a cover creator.
To demonstrate support for a cover pool, anyone can add and remove
NPM stakes (minimum required). The higher the sake, the more visibility
the contract gets if there are multiple cover contracts with the same name
or similar terms. Even when there are no duplicate contract, a higher stake
would normally imply a better cover pool commitment.
- constructor(IStore store)
- increaseStake(bytes32 coverKey, address account, uint256 amount, uint256 fee)
- decreaseStake(bytes32 coverKey, uint256 amount)
- stakeOf(bytes32 coverKey, address account)
- _getDrawingPower(bytes32 coverKey, address account)
- version()
- getName()
Constructs this contract
function (IStore store) public nonpayable Recoverable
Arguments
Name | Type | Description |
---|---|---|
store | IStore | Provide the store contract instance |
Source Code
constructor(IStore store) Recoverable(store) {}
Increase the stake of the given cover pool
function increaseStake(bytes32 coverKey, address account, uint256 amount, uint256 fee) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
account | address | Enter the account from where the NPM tokens will be transferred |
amount | uint256 | Enter the amount of stake |
fee | uint256 | Enter the fee amount. Note: do not enter the fee if you are directly calling this function. |
Source Code
function increaseStake(
bytes32 coverKey,
address account,
uint256 amount,
uint256 fee
) external override nonReentrant {
s.mustNotBePaused();
s.mustBeValidCoverKey(coverKey);
s.senderMustBeCoverContract();
require(amount >= fee, "Invalid fee");
s.npmToken().ensureTransferFrom(msg.sender, address(this), amount);
if (fee > 0) {
s.npmToken().ensureTransfer(s.getBurnAddress(), fee);
emit FeeBurned(coverKey, fee);
}
// @suppress-subtraction Checked usage. Fee is always less than amount
// if we reach this far.
s.addUintByKeys(ProtoUtilV1.NS_COVER_STAKE, coverKey, amount - fee);
s.addUintByKeys(ProtoUtilV1.NS_COVER_STAKE_OWNED, coverKey, account, amount - fee);
emit StakeAdded(coverKey, account, amount - fee);
}
Decreases the stake from the given cover pool. A cover creator can withdraw their full stake after 365 days
function decreaseStake(bytes32 coverKey, uint256 amount) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
amount | uint256 | Enter the amount of stake to decrease |
Source Code
function decreaseStake(bytes32 coverKey, uint256 amount) external override nonReentrant {
s.mustNotBePaused();
s.mustBeValidCoverKey(coverKey);
s.mustEnsureAllProductsAreNormal(coverKey);
uint256 drawingPower = _getDrawingPower(coverKey, msg.sender);
require(amount > 0, "Please specify amount");
require(drawingPower >= amount, "Exceeds your drawing power");
// @suppress-subtraction
s.subtractUintByKeys(ProtoUtilV1.NS_COVER_STAKE, coverKey, amount);
s.subtractUintByKeys(ProtoUtilV1.NS_COVER_STAKE_OWNED, coverKey, msg.sender, amount);
s.npmToken().ensureTransfer(msg.sender, amount);
s.updateStateAndLiquidity(coverKey);
emit StakeRemoved(coverKey, msg.sender, amount);
}
Gets the stake of an account for the given cover key
function stakeOf(bytes32 coverKey, address account) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
account | address | Specify the account to obtain the stake of |
Returns
Returns the total stake of the specified account on the given cover key
Source Code
function stakeOf(bytes32 coverKey, address account) public view override returns (uint256) {
return s.getUintByKeys(ProtoUtilV1.NS_COVER_STAKE_OWNED, coverKey, account);
}
Gets the drawing power of (the stake amount that can be withdrawn from) an account.
function _getDrawingPower(bytes32 coverKey, address account) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
account | address | Specify the account to obtain the drawing power of |
Returns
Returns the drawing power of the specified account on the given cover key
Source Code
function _getDrawingPower(bytes32 coverKey, address account) private view returns (uint256) {
uint256 createdAt = s.getCoverCreationDate(coverKey);
uint256 yourStake = stakeOf(coverKey, account);
bool isOwner = account == s.getCoverOwner(coverKey);
uint256 minStakeRequired = block.timestamp > createdAt + 365 days ? 0 : s.getMinCoverCreationStake(); // solhint-disable-line
return isOwner ? yourStake - minStakeRequired : yourStake;
}
Version number of this contract
function version() external pure
returns(bytes32)
Arguments
Name | Type | Description |
---|
Source Code
function version() external pure override returns (bytes32) {
return "v0.1";
}
Name of this contract
function getName() external pure
returns(bytes32)
Arguments
Name | Type | Description |
---|
Source Code
function getName() external pure override returns (bytes32) {
return ProtoUtilV1.CNAME_COVER_STAKE;
}
- 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