Skip to content

Latest commit

 

History

History
1536 lines (1238 loc) · 49 KB

GovernanceUtilV1.md

File metadata and controls

1536 lines (1238 loc) · 49 KB

GovernanceUtilV1.sol

View Source: contracts/libraries/GovernanceUtilV1.sol

GovernanceUtilV1

Functions

getReportingPeriodInternal

Gets the reporting period for the given cover. Warning: this function does not validate the input arguments.

function getReportingPeriodInternal(IStore s, bytes32 coverKey) external view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32
Source Code
function getReportingPeriodInternal(IStore s, bytes32 coverKey) external view returns (uint256) {
    return s.getUintByKeys(ProtoUtilV1.NS_GOVERNANCE_REPORTING_PERIOD, coverKey);
  }

getReportingBurnRateInternal

Gets the NPM stake burn rate (upon resolution) for the given cover. Warning: this function does not validate the input arguments.

function getReportingBurnRateInternal(IStore s) public view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
Source Code
function getReportingBurnRateInternal(IStore s) public view returns (uint256) {
    return s.getUintByKey(ProtoUtilV1.NS_GOVERNANCE_REPORTING_BURN_RATE);
  }

getGovernanceReporterCommissionInternal

Gets the "valid" reporter's NPM commission rate (upon each unstake claim invoked by individual "valid" stakers) for the given cover. Warning: this function does not validate the input arguments.

function getGovernanceReporterCommissionInternal(IStore s) public view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
Source Code
function getGovernanceReporterCommissionInternal(IStore s) public view returns (uint256) {
    return s.getUintByKey(ProtoUtilV1.NS_GOVERNANCE_REPORTER_COMMISSION);
  }

getPlatformCoverFeeRateInternal

Gets the protocol's NPM commission rate (upon each unstake claim invoked by individual "valid" stakers) for the given cover. Warning: this function does not validate the input arguments.

function getPlatformCoverFeeRateInternal(IStore s) external view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
Source Code
function getPlatformCoverFeeRateInternal(IStore s) external view returns (uint256) {
    return s.getUintByKey(ProtoUtilV1.NS_COVER_PLATFORM_FEE);
  }

getClaimReporterCommissionInternal

Gets the "valid" reporter's stablecoin commission rate on protocol's earnings (upon each claim payout received by claimants) for the given cover. Warning: this function does not validate the input arguments.

function getClaimReporterCommissionInternal(IStore s) external view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
Source Code
function getClaimReporterCommissionInternal(IStore s) external view returns (uint256) {
    return s.getUintByKey(ProtoUtilV1.NS_CLAIM_REPORTER_COMMISSION);
  }

getMinReportingStakeInternal

Gets the minimum units of NPM tokens required to report the supplied cover. Warning: this function does not validate the input arguments.

function getMinReportingStakeInternal(IStore s, bytes32 coverKey) external view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
Source Code
function getMinReportingStakeInternal(IStore s, bytes32 coverKey) external view returns (uint256) {
    uint256 fb = s.getUintByKey(ProtoUtilV1.NS_GOVERNANCE_REPORTING_MIN_FIRST_STAKE);
    uint256 custom = s.getUintByKeys(ProtoUtilV1.NS_GOVERNANCE_REPORTING_MIN_FIRST_STAKE, coverKey);

    return custom > 0 ? custom : fb;
  }

getResolutionTimestampInternal

Gets a cover's resolution timestamp. Warning: this function does not validate the cover and product key supplied.

function getResolutionTimestampInternal(IStore s, bytes32 coverKey, bytes32 productKey) external view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
Source Code
function getResolutionTimestampInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey
  ) external view returns (uint256) {
    return s.getUintByKeys(ProtoUtilV1.NS_GOVERNANCE_RESOLUTION_TS, coverKey, productKey);
  }

getReporterInternal

Gets the given cover incident's reporter. Note that this keeps changing between "first reporter" and "candidate reporter" until resolution is achieved.

Read More

Warning: this function does not validate the cover and product key supplied.

function getReporterInternal(IStore s, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) external view
returns(address)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256
Source Code
function getReporterInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) external view returns (address) {
    CoverUtilV1.ProductStatus status = s.getProductStatusOfInternal(coverKey, productKey, incidentDate);
    bool incidentHappened = status == CoverUtilV1.ProductStatus.IncidentHappened || status == CoverUtilV1.ProductStatus.Claimable;
    bytes32 prefix = incidentHappened ? ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_YES : ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_NO;

    return s.getAddressByKeys(prefix, coverKey, productKey);
  }

getStakesInternal

Returns stakes of the given cover product's incident. Warning: this function does not validate the input arguments.

function getStakesInternal(IStore s, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) public view
returns(yes uint256, no uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getStakesInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) public view returns (uint256 yes, uint256 no) {
    yes = s.getUintByKey(_getIncidentOccurredStakesKey(coverKey, productKey, incidentDate));
    no = s.getUintByKey(_getFalseReportingStakesKey(coverKey, productKey, incidentDate));
  }

_getReporterKey

Hash key of the reporter for the given cover product. Warning: this function does not validate the input arguments.

function _getReporterKey(bytes32 coverKey, bytes32 productKey) private pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
Source Code
function _getReporterKey(bytes32 coverKey, bytes32 productKey) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_YES, coverKey, productKey));
  }

_getIncidentOccurredStakesKey

Hash key of the stakes added under Incident Happened camp for the given cover product. Warning: this function does not validate the input arguments.

function _getIncidentOccurredStakesKey(bytes32 coverKey, bytes32 productKey, uint256 incidentDate) private pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256
Source Code
function _getIncidentOccurredStakesKey(
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_YES, coverKey, productKey, incidentDate));
  }

_getClaimPayoutsKey

Hash key of the claims payout given for the supplied cover product. Warning: this function does not validate the input arguments.

function _getClaimPayoutsKey(bytes32 coverKey, bytes32 productKey, uint256 incidentDate) private pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256
Source Code
function _getClaimPayoutsKey(
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_CLAIM_PAYOUTS, coverKey, productKey, incidentDate));
  }

_getReassurancePayoutKey

Hash key of the reassurance payout granted for the supplied cover product. Warning: this function does not validate the input arguments.

function _getReassurancePayoutKey(bytes32 coverKey, bytes32 productKey, uint256 incidentDate) private pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256
Source Code
function _getReassurancePayoutKey(
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_REASSURANCE_PAYOUT, coverKey, productKey, incidentDate));
  }

_getIndividualIncidentOccurredStakeKey

Hash key of an individual's stakes added under Incident Happened camp for the given cover product. Warning: this function does not validate the input arguments.

function _getIndividualIncidentOccurredStakeKey(bytes32 coverKey, bytes32 productKey, uint256 incidentDate, address account) private pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256
account address
Source Code
function _getIndividualIncidentOccurredStakeKey(
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate,
    address account
  ) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_STAKE_OWNED_YES, coverKey, productKey, incidentDate, account));
  }

_getDisputerKey

Hash key of the "candidate reporter" for the supplied cover product. Warning: this function does not validate the input arguments.

function _getDisputerKey(bytes32 coverKey, bytes32 productKey) private pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
Source Code
function _getDisputerKey(bytes32 coverKey, bytes32 productKey) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_NO, coverKey, productKey));
  }

_getFalseReportingStakesKey

Hash key of the stakes added under False Reporting camp for the given cover product. Warning: this function does not validate the input arguments.

function _getFalseReportingStakesKey(bytes32 coverKey, bytes32 productKey, uint256 incidentDate) private pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256
Source Code
function _getFalseReportingStakesKey(
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_NO, coverKey, productKey, incidentDate));
  }

_getIndividualFalseReportingStakeKey

Hash key of an individual's stakes added under False Reporting camp for the given cover product. Warning: this function does not validate the input arguments.

function _getIndividualFalseReportingStakeKey(bytes32 coverKey, bytes32 productKey, uint256 incidentDate, address account) private pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256
account address
Source Code
function _getIndividualFalseReportingStakeKey(
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate,
    address account
  ) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_STAKE_OWNED_NO, coverKey, productKey, incidentDate, account));
  }

getStakesOfInternal

Returns stakes of the given account for a cover product's incident. Warning: this function does not validate the input arguments.

function getStakesOfInternal(IStore s, address account, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) public view
returns(yes uint256, no uint256)

Arguments

Name Type Description
s IStore Specify store instance
account address Specify the account to get stakes
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getStakesOfInternal(
    IStore s,
    address account,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) public view returns (uint256 yes, uint256 no) {
    yes = s.getUintByKey(_getIndividualIncidentOccurredStakeKey(coverKey, productKey, incidentDate, account));
    no = s.getUintByKey(_getIndividualFalseReportingStakeKey(coverKey, productKey, incidentDate, account));
  }

getResolutionInfoForInternal

Returns resolution info of the given account for a cover product's incident. Warning: this function does not validate the input arguments.

function getResolutionInfoForInternal(IStore s, address account, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) public view
returns(totalStakeInWinningCamp uint256, totalStakeInLosingCamp uint256, myStakeInWinningCamp uint256)

Arguments

Name Type Description
s IStore Specify store instance
account address Specify the account to get stakes
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getResolutionInfoForInternal(
    IStore s,
    address account,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  )
    public
    view
    returns (
      uint256 totalStakeInWinningCamp,
      uint256 totalStakeInLosingCamp,
      uint256 myStakeInWinningCamp
    )
  {
    (uint256 yes, uint256 no) = getStakesInternal(s, coverKey, productKey, incidentDate);
    (uint256 myYes, uint256 myNo) = getStakesOfInternal(s, account, coverKey, productKey, incidentDate);

    CoverUtilV1.ProductStatus decision = s.getProductStatusOfInternal(coverKey, productKey, incidentDate);
    bool incidentHappened = decision == CoverUtilV1.ProductStatus.IncidentHappened || decision == CoverUtilV1.ProductStatus.Claimable;

    totalStakeInWinningCamp = incidentHappened ? yes : no;
    totalStakeInLosingCamp = incidentHappened ? no : yes;
    myStakeInWinningCamp = incidentHappened ? myYes : myNo;
  }

getUnstakeInfoForInternal

Returns unstake info of the given account for a cover product's incident. Warning: this function does not validate the input arguments.

function getUnstakeInfoForInternal(IStore s, address account, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) external view
returns(info struct IUnstakable.UnstakeInfoType)

Arguments

Name Type Description
s IStore Specify store instance
account address Specify the account to get stakes
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getUnstakeInfoForInternal(
    IStore s,
    address account,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) external view returns (IUnstakable.UnstakeInfoType memory info) {
    (info.totalStakeInWinningCamp, info.totalStakeInLosingCamp, info.myStakeInWinningCamp) = getResolutionInfoForInternal(s, account, coverKey, productKey, incidentDate);

    info.unstaken = getReportingUnstakenAmountInternal(s, account, coverKey, productKey, incidentDate);
    require(info.myStakeInWinningCamp > 0, "Nothing to unstake");

    uint256 rewardRatio = (info.myStakeInWinningCamp * ProtoUtilV1.MULTIPLIER) / info.totalStakeInWinningCamp;

    uint256 reward = 0;

    // Incident dates are reset when a reporting is finalized.
    // This check ensures only the people who come to unstake
    // before the finalization will receive rewards
    if (s.getActiveIncidentDateInternal(coverKey, productKey) == incidentDate) {
      // slither-disable-next-line divide-before-multiply
      reward = (info.totalStakeInLosingCamp * rewardRatio) / ProtoUtilV1.MULTIPLIER;
    }

    require(getReportingBurnRateInternal(s) + getGovernanceReporterCommissionInternal(s) <= ProtoUtilV1.MULTIPLIER, "Invalid configuration");

    info.toBurn = (reward * getReportingBurnRateInternal(s)) / ProtoUtilV1.MULTIPLIER;
    info.toReporter = (reward * getGovernanceReporterCommissionInternal(s)) / ProtoUtilV1.MULTIPLIER;
    info.myReward = reward - info.toBurn - info.toReporter;
  }

getReportingUnstakenAmountInternal

Returns NPM already unstaken by the specified account for a cover incident. Warning: this function does not validate the input arguments.

function getReportingUnstakenAmountInternal(IStore s, address account, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) public view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
account address Specify the account to get stakes
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getReportingUnstakenAmountInternal(
    IStore s,
    address account,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) public view returns (uint256) {
    bytes32 k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKEN, coverKey, productKey, incidentDate, account));
    return s.getUintByKey(k);
  }

updateUnstakeDetailsInternal

function updateUnstakeDetailsInternal(IStore s, address account, bytes32 coverKey, bytes32 productKey, uint256 incidentDate, uint256 originalStake, uint256 reward, uint256 burned, uint256 reporterFee) external nonpayable

Arguments

Name Type Description
s IStore
account address
coverKey bytes32
productKey bytes32
incidentDate uint256
originalStake uint256
reward uint256
burned uint256
reporterFee uint256
Source Code
function updateUnstakeDetailsInternal(
    IStore s,
    address account,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate,
    uint256 originalStake,
    uint256 reward,
    uint256 burned,
    uint256 reporterFee
  ) external {
    // Unstake timestamp of the account
    bytes32 k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKE_TS, coverKey, productKey, incidentDate, account));
    s.setUintByKey(k, block.timestamp); // solhint-disable-line

    // Last unstake timestamp
    k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKE_TS, coverKey, productKey, incidentDate));
    s.setUintByKey(k, block.timestamp); // solhint-disable-line

    // ---------------------------------------------------------------------

    // Amount unstaken by the account
    k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKEN, coverKey, productKey, incidentDate, account));
    s.setUintByKey(k, originalStake);

    // Amount unstaken by everyone
    k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKEN, coverKey, productKey, incidentDate));
    s.addUintByKey(k, originalStake);

    // ---------------------------------------------------------------------

    if (reward > 0) {
      // Reward received by the account
      k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKE_REWARD, coverKey, productKey, incidentDate, account));
      s.setUintByKey(k, reward);

      // Total reward received
      k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKE_REWARD, coverKey, productKey, incidentDate));
      s.addUintByKey(k, reward);
    }

    // ---------------------------------------------------------------------

    if (burned > 0) {
      // Total burned
      k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKE_BURNED, coverKey, productKey, incidentDate));
      s.addUintByKey(k, burned);
    }

    if (reporterFee > 0) {
      // Total fee paid to the final reporter
      k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKE_REPORTER_FEE, coverKey, productKey, incidentDate));
      s.addUintByKey(k, reporterFee);
    }
  }

_updateProductStatusBeforeResolutionInternal

function _updateProductStatusBeforeResolutionInternal(IStore s, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) private nonpayable

Arguments

Name Type Description
s IStore
coverKey bytes32
productKey bytes32
incidentDate uint256
Source Code
function _updateProductStatusBeforeResolutionInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) private {
    require(incidentDate > 0, "Invalid incident date");

    uint256 yes = s.getUintByKey(_getIncidentOccurredStakesKey(coverKey, productKey, incidentDate));
    uint256 no = s.getUintByKey(_getFalseReportingStakesKey(coverKey, productKey, incidentDate));

    if (no > yes) {
      s.setStatusInternal(coverKey, productKey, incidentDate, CoverUtilV1.ProductStatus.FalseReporting);
      return;
    }

    s.setStatusInternal(coverKey, productKey, incidentDate, CoverUtilV1.ProductStatus.IncidentHappened);
  }

addAttestationInternal

Adds attestation to an incident report

function addAttestationInternal(IStore s, bytes32 coverKey, bytes32 productKey, address who, uint256 incidentDate, uint256 stake) external nonpayable

Arguments

Name Type Description
s IStore
coverKey bytes32
productKey bytes32
who address
incidentDate uint256
stake uint256
Source Code
function addAttestationInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    address who,
    uint256 incidentDate,
    uint256 stake
  ) external {
    mustNotExceedNpmThreshold(stake);

    // Add individual stake of the reporter
    s.addUintByKey(_getIndividualIncidentOccurredStakeKey(coverKey, productKey, incidentDate, who), stake);

    // All "incident happened" camp witnesses combined
    uint256 currentStake = s.getUintByKey(_getIncidentOccurredStakesKey(coverKey, productKey, incidentDate));

    // No has reported yet, this is the first report
    if (currentStake == 0) {
      s.setAddressByKey(_getReporterKey(coverKey, productKey), who);
    }

    s.addUintByKey(_getIncidentOccurredStakesKey(coverKey, productKey, incidentDate), stake);
    _updateProductStatusBeforeResolutionInternal(s, coverKey, productKey, incidentDate);

    s.updateStateAndLiquidityInternal(coverKey);
  }

getAttestationInternal

Returns sum total of NPM staken under Incident Happened camp. Warning: this function does not validate the input arguments.

function getAttestationInternal(IStore s, bytes32 coverKey, bytes32 productKey, address who, uint256 incidentDate) external view
returns(myStake uint256, totalStake uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
who address Specify the account to get attestation info
incidentDate uint256 Enter incident date
Source Code
function getAttestationInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    address who,
    uint256 incidentDate
  ) external view returns (uint256 myStake, uint256 totalStake) {
    myStake = s.getUintByKey(_getIndividualIncidentOccurredStakeKey(coverKey, productKey, incidentDate, who));
    totalStake = s.getUintByKey(_getIncidentOccurredStakesKey(coverKey, productKey, incidentDate));
  }

addRefutationInternal

Adds refutation to an incident report

function addRefutationInternal(IStore s, bytes32 coverKey, bytes32 productKey, address who, uint256 incidentDate, uint256 stake) external nonpayable

Arguments

Name Type Description
s IStore
coverKey bytes32
productKey bytes32
who address
incidentDate uint256
stake uint256
Source Code
function addRefutationInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    address who,
    uint256 incidentDate,
    uint256 stake
  ) external {
    mustNotExceedNpmThreshold(stake);

    s.addUintByKey(_getIndividualFalseReportingStakeKey(coverKey, productKey, incidentDate, who), stake);

    uint256 currentStake = s.getUintByKey(_getFalseReportingStakesKey(coverKey, productKey, incidentDate));

    if (currentStake == 0) {
      // The first reporter who disputed
      s.setAddressByKey(_getDisputerKey(coverKey, productKey), who);
      s.setBoolByKey(getHasDisputeKeyInternal(coverKey, productKey), true);
    }

    s.addUintByKey(_getFalseReportingStakesKey(coverKey, productKey, incidentDate), stake);
    _updateProductStatusBeforeResolutionInternal(s, coverKey, productKey, incidentDate);

    s.updateStateAndLiquidityInternal(coverKey);
  }

getHasDisputeKeyInternal

Hash key of the "has dispute flag" for the specified cover product. Warning: this function does not validate the input arguments.

function getHasDisputeKeyInternal(bytes32 coverKey, bytes32 productKey) public pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
Source Code
function getHasDisputeKeyInternal(bytes32 coverKey, bytes32 productKey) public pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_HAS_A_DISPUTE, coverKey, productKey));
  }

getHasFinalizedKeyInternal

Hash key of the "has finalized flag" for the specified cover product. Warning: this function does not validate the input arguments.

function getHasFinalizedKeyInternal(bytes32 coverKey, bytes32 productKey, uint256 incidentDate) public pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getHasFinalizedKeyInternal(
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) public pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_FINALIZATION, coverKey, productKey, incidentDate));
  }

getRefutationInternal

Returns sum total of NPM staken under False Reporting camp. Warning: this function does not validate the input arguments.

function getRefutationInternal(IStore s, bytes32 coverKey, bytes32 productKey, address who, uint256 incidentDate) external view
returns(myStake uint256, totalStake uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
who address Specify the account to get attestation info
incidentDate uint256 Enter incident date
Source Code
function getRefutationInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    address who,
    uint256 incidentDate
  ) external view returns (uint256 myStake, uint256 totalStake) {
    myStake = s.getUintByKey(_getIndividualFalseReportingStakeKey(coverKey, productKey, incidentDate, who));
    totalStake = s.getUintByKey(_getFalseReportingStakesKey(coverKey, productKey, incidentDate));
  }

getCoolDownPeriodInternal

Returns cooldown period. Cooldown period is a defense against collusion and last-block attacks. Warning: this function does not validate the input arguments.

function getCoolDownPeriodInternal(IStore s, bytes32 coverKey) external view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
Source Code
function getCoolDownPeriodInternal(IStore s, bytes32 coverKey) external view returns (uint256) {
    uint256 fromKey = s.getUintByKeys(ProtoUtilV1.NS_RESOLUTION_COOL_DOWN_PERIOD, coverKey);
    uint256 fallbackValue = s.getUintByKey(ProtoUtilV1.NS_RESOLUTION_COOL_DOWN_PERIOD);

    return fromKey > 0 ? fromKey : fallbackValue;
  }

getResolutionDeadlineInternal

The date and time prior to which a governance administrator may still initiate a "emergency resolution." Warning: this function does not validate the cover and product key supplied.

function getResolutionDeadlineInternal(IStore s, bytes32 coverKey, bytes32 productKey) external view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
Source Code
function getResolutionDeadlineInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey
  ) external view returns (uint256) {
    return s.getUintByKeys(ProtoUtilV1.NS_RESOLUTION_DEADLINE, coverKey, productKey);
  }

addClaimPayoutsInternal

function addClaimPayoutsInternal(IStore s, bytes32 coverKey, bytes32 productKey, uint256 incidentDate, uint256 claimed) external nonpayable

Arguments

Name Type Description
s IStore
coverKey bytes32
productKey bytes32
incidentDate uint256
claimed uint256
Source Code
function addClaimPayoutsInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate,
    uint256 claimed
  ) external {
    s.addUintByKey(_getClaimPayoutsKey(coverKey, productKey, incidentDate), claimed);
  }

getClaimPayoutsInternal

Returns the total amount of payouts awarded to claimants for this incident. Warning: this function does not validate the input arguments.

function getClaimPayoutsInternal(IStore s, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) public view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getClaimPayoutsInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) public view returns (uint256) {
    return s.getUintByKey(_getClaimPayoutsKey(coverKey, productKey, incidentDate));
  }

getReassurancePayoutInternal

Returns the total amount of reassurance granted to vault for this incident. Warning: this function does not validate the input arguments.

function getReassurancePayoutInternal(IStore s, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) public view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getReassurancePayoutInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) public view returns (uint256) {
    return s.getUintByKey(_getReassurancePayoutKey(coverKey, productKey, incidentDate));
  }

addReassurancePayoutInternal

function addReassurancePayoutInternal(IStore s, bytes32 coverKey, bytes32 productKey, uint256 incidentDate, uint256 capitalized) external nonpayable

Arguments

Name Type Description
s IStore
coverKey bytes32
productKey bytes32
incidentDate uint256
capitalized uint256
Source Code
function addReassurancePayoutInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate,
    uint256 capitalized
  ) external {
    s.addUintByKey(_getReassurancePayoutKey(coverKey, productKey, incidentDate), capitalized);
  }

getReassuranceTransferrableInternal

Returns the remaining reassurance amount that can be transferred to the vault following the claim period but prior to finalisation. Warning: this function does not validate the input arguments.

function getReassuranceTransferrableInternal(IStore s, bytes32 coverKey, bytes32 productKey, uint256 incidentDate) external view
returns(uint256)

Arguments

Name Type Description
s IStore Specify store instance
coverKey bytes32 Enter cover key
productKey bytes32 Enter product key
incidentDate uint256 Enter incident date
Source Code
function getReassuranceTransferrableInternal(
    IStore s,
    bytes32 coverKey,
    bytes32 productKey,
    uint256 incidentDate
  ) external view returns (uint256) {
    uint256 reassuranceRate = s.getReassuranceRateInternal(coverKey);
    uint256 available = s.getReassuranceAmountInternal(coverKey);
    uint256 reassurancePaid = getReassurancePayoutInternal(s, coverKey, productKey, incidentDate);

    uint256 totalReassurance = available + reassurancePaid;

    uint256 claimsPaid = getClaimPayoutsInternal(s, coverKey, productKey, incidentDate);

    uint256 principal = claimsPaid <= totalReassurance ? claimsPaid : totalReassurance;
    uint256 transferAmount = (principal * reassuranceRate) / ProtoUtilV1.MULTIPLIER;

    return transferAmount - reassurancePaid;
  }

mustNotExceedNpmThreshold

function mustNotExceedNpmThreshold(uint256 amount) public pure

Arguments

Name Type Description
amount uint256
Source Code
function mustNotExceedNpmThreshold(uint256 amount) public pure {
    require(amount <= ProtoUtilV1.MAX_NPM_STAKE * 1 ether, "NPM stake is above threshold");
  }

Contracts