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 key, address account, uint256 amount, uint256 fee)
- decreaseStake(bytes32 key, address account, uint256 amount)
- stakeOf(bytes32 key, address account)
- _getDrawingPower(bytes32 key, 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 key, address account, uint256 amount, uint256 fee) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
key | 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 key,
address account,
uint256 amount,
uint256 fee
) external override nonReentrant {
// @suppress-acl Can only be accessed by the latest cover contract
s.mustNotBePaused();
s.mustBeValidCoverKey(key);
s.callerMustBeCoverContract();
require(amount >= fee, "Invalid fee");
s.npmToken().ensureTransferFrom(account, address(this), amount);
if (fee > 0) {
s.npmToken().ensureTransferFrom(address(this), s.getBurnAddress(), fee);
emit FeeBurned(key, fee);
}
s.addUintByKeys(ProtoUtilV1.NS_COVER_STAKE, key, amount - fee);
s.addUintByKeys(ProtoUtilV1.NS_COVER_STAKE_OWNED, key, account, amount - fee);
emit StakeAdded(key, amount - fee);
}
Decreases the stake from the given cover pool
function decreaseStake(bytes32 key, address account, uint256 amount) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
key | bytes32 | Enter the cover key |
account | address | Enter the account to decrease the stake of |
amount | uint256 | Enter the amount of stake to decrease |
Source Code
function decreaseStake(
bytes32 key,
address account,
uint256 amount
) external override nonReentrant {
// @todo this function is not called anywhere. Remove this.
// @suppress-acl Can only be accessed by the latest cover contract
s.mustNotBePaused();
s.mustBeValidCoverKey(key);
s.callerMustBeCoverContract();
uint256 drawingPower = _getDrawingPower(key, account);
require(drawingPower >= amount, "Exceeds your drawing power");
s.subtractUintByKeys(ProtoUtilV1.NS_COVER_STAKE, key, amount);
s.subtractUintByKeys(ProtoUtilV1.NS_COVER_STAKE_OWNED, key, account, amount);
s.npmToken().ensureTransfer(account, amount);
// Remove if the strategy is being invoked on the cover contract during this transaction
s.updateStateAndLiquidity(key);
emit StakeRemoved(key, amount);
}
Gets the stake of an account for the given cover key
function stakeOf(bytes32 key, address account) public view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
key | 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 key, address account) public view override returns (uint256) {
return s.getUintByKeys(ProtoUtilV1.NS_COVER_STAKE_OWNED, key, account);
}
Gets the drawing power of (the stake amount that can be withdrawn from) an account.
function _getDrawingPower(bytes32 key, address account) private view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
key | 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 key, address account) private view returns (uint256) {
uint256 yourStake = stakeOf(key, account);
bool isOwner = account == s.getCoverOwner(key);
uint256 minStake = s.getMinCoverCreationStake();
return isOwner ? yourStake - minStake : 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
- Controller
- Cover
- CoverBase
- CoverLibV1
- CoverProvision
- CoverReassurance
- CoverStake
- CoverUtilV1
- cxToken
- cxTokenFactory
- cxTokenFactoryLibV1
- Destroyable
- ERC165
- ERC20
- FakeAaveLendingPool
- FakeCompoundERC20Delegator
- FakeRecoverable
- FakeStore
- FakeToken
- FakeUniswapPair
- FakeUniswapV2FactoryLike
- FakeUniswapV2PairLike
- FakeUniswapV2RouterLike
- Finalization
- Governance
- GovernanceUtilV1
- IAaveV2LendingPoolLike
- IAccessControl
- IBondPool
- IClaimsProcessor
- ICommission
- ICompoundERC20DelegatorLike
- ICover
- ICoverProvision
- ICoverReassurance
- ICoverStake
- ICxToken
- ICxTokenFactory
- IERC165
- IERC20
- IERC20Detailed
- IERC20Metadata
- IERC3156FlashBorrower
- IERC3156FlashLender
- IFinalization
- IGovernance
- ILendingStrategy
- IMember
- IPausable
- IPolicy
- IPolicyAdmin
- IPriceDiscovery
- IProtocol
- IRecoverable
- IReporter
- IResolution
- IResolvable
- IStakingPools
- IStore
- IUniswapV2FactoryLike
- IUniswapV2PairLike
- IUniswapV2RouterLike
- IUnstakable
- IVault
- IVaultFactory
- IWitness
- LiquidityEngine
- MaliciousToken
- Migrations
- MockCxToken
- MockCxTokenPolicy
- MockCxTokenStore
- MockProcessorStore
- MockProcessorStoreLib
- MockProtocol
- MockStore
- MockVault
- NTransferUtilV2
- NTransferUtilV2Intermediate
- Ownable
- Pausable
- Policy
- PolicyAdmin
- PolicyHelperV1
- PriceDiscovery
- PriceLibV1
- Processor
- ProtoBase
- Protocol
- ProtoUtilV1
- Recoverable
- ReentrancyGuard
- RegistryLibV1
- Reporter
- Resolution
- Resolvable
- RoutineInvokerLibV1
- SafeERC20
- StakingPoolBase
- StakingPoolCoreLibV1
- StakingPoolInfo
- StakingPoolLibV1
- StakingPoolReward
- StakingPools
- Store
- StoreBase
- StoreKeyUtil
- StrategyLibV1
- Strings
- Unstakable
- ValidationLibV1
- Vault
- VaultBase
- VaultFactory
- VaultFactoryLibV1
- VaultLibV1
- WithFlashLoan
- Witness