Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Latest commit

 

History

History
389 lines (316 loc) · 11.1 KB

CoverStake.md

File metadata and controls

389 lines (316 loc) · 11.1 KB

Cover Stake (CoverStake.sol)

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.

Functions

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) {}

increaseStake

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);
  }

decreaseStake

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);
  }

stakeOf

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);
  }

_getDrawingPower

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

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";
  }

getName

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;
  }

Contracts