Skip to content

Latest commit

 

History

History
318 lines (274 loc) · 11.1 KB

Unstakable.md

File metadata and controls

318 lines (274 loc) · 11.1 KB

Unstakable Contract (Unstakable.sol)

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.

Functions

unstake

Reporters on the valid camp can unstake their tokens even after finalization. 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.getNpmTokenInstanceInternal().ensureTransfer(msg.sender, myStakeInWinningCamp);
    s.updateStateAndLiquidityInternal(coverKey);

    emit Unstaken(coverKey, productKey, msg.sender, myStakeInWinningCamp, 0);
  }

unstakeWithClaim

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.getBurnAddressInternal();

    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.getNpmTokenInstanceInternal().ensureTransfer(msg.sender, myStakeWithReward);

    if (info.toReporter > 0) {
      s.getNpmTokenInstanceInternal().ensureTransfer(finalReporter, info.toReporter);
    }

    if (info.toBurn > 0) {
      s.getNpmTokenInstanceInternal().ensureTransfer(burner, info.toBurn);
    }

    s.updateStateAndLiquidityInternal(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);
  }

getUnstakeInfoFor

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

Contracts