Skip to content

Latest commit

 

History

History
962 lines (759 loc) · 25.1 KB

ValidationLibV1.md

File metadata and controls

962 lines (759 loc) · 25.1 KB

ValidationLibV1.sol

View Source: contracts/libraries/ValidationLibV1.sol

ValidationLibV1

Functions

mustNotBePaused

Reverts if the protocol is paused

function mustNotBePaused(IStore s) public view

Arguments

Name Type Description
s IStore
Source Code
function mustNotBePaused(IStore s) public view {
    address protocol = s.getProtocolAddress();
    require(IPausable(protocol).paused() == false, "Protocol is paused");
  }

mustBeValidCover

Reverts if the key does not resolve in a valid cover contract or if the cover is under governance.

function mustBeValidCover(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32 Enter the cover key to check
Source Code
function mustBeValidCover(IStore s, bytes32 key) external view {
    require(s.getBoolByKeys(ProtoUtilV1.NS_COVER, key), "Cover does not exist");
    require(s.getCoverStatus(key) == CoverUtilV1.CoverStatus.Normal, "Actively Reporting");
  }

mustBeValidCoverKey

Reverts if the key does not resolve in a valid cover contract.

function mustBeValidCoverKey(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32 Enter the cover key to check
Source Code
function mustBeValidCoverKey(IStore s, bytes32 key) external view {
    require(s.getBoolByKeys(ProtoUtilV1.NS_COVER, key), "Cover does not exist");
  }

mustBeCoverOwner

Reverts if the sender is not the cover owner

function mustBeCoverOwner(IStore s, bytes32 key, address sender) external view

Arguments

Name Type Description
s IStore ender The msg.sender value
key bytes32 Enter the cover key to check
sender address The msg.sender value
Source Code
function mustBeCoverOwner(
    IStore s,
    bytes32 key,
    address sender
  ) external view {
    bool isCoverOwner = s.getCoverOwner(key) == sender;
    require(isCoverOwner, "Forbidden");
  }

mustBeCoverOwnerOrCoverContract

Reverts if the sender is not the cover owner or the cover contract

function mustBeCoverOwnerOrCoverContract(IStore s, bytes32 key, address sender) external view

Arguments

Name Type Description
s IStore ender The msg.sender value
key bytes32 Enter the cover key to check
sender address The msg.sender value
Source Code
function mustBeCoverOwnerOrCoverContract(
    IStore s,
    bytes32 key,
    address sender
  ) external view {
    bool isCoverOwner = s.getCoverOwner(key) == sender;
    bool isCoverContract = address(s.getCoverContract()) == sender;

    require(isCoverOwner || isCoverContract, "Forbidden");
  }

callerMustBePolicyContract

function callerMustBePolicyContract(IStore s) external view

Arguments

Name Type Description
s IStore
Source Code
function callerMustBePolicyContract(IStore s) external view {
    s.callerMustBeExactContract(ProtoUtilV1.CNS_COVER_POLICY);
  }

callerMustBePolicyManagerContract

function callerMustBePolicyManagerContract(IStore s) external view

Arguments

Name Type Description
s IStore
Source Code
function callerMustBePolicyManagerContract(IStore s) external view {
    s.callerMustBeExactContract(ProtoUtilV1.CNS_COVER_POLICY_MANAGER);
  }

callerMustBeCoverContract

function callerMustBeCoverContract(IStore s) external view

Arguments

Name Type Description
s IStore
Source Code
function callerMustBeCoverContract(IStore s) external view {
    s.callerMustBeExactContract(ProtoUtilV1.CNS_COVER);
  }

callerMustBeVaultContract

function callerMustBeVaultContract(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function callerMustBeVaultContract(IStore s, bytes32 key) external view {
    address vault = s.getVaultAddress(key);
    require(msg.sender == vault, "Forbidden");
  }

callerMustBeGovernanceContract

function callerMustBeGovernanceContract(IStore s) external view

Arguments

Name Type Description
s IStore
Source Code
function callerMustBeGovernanceContract(IStore s) external view {
    s.callerMustBeExactContract(ProtoUtilV1.CNS_GOVERNANCE);
  }

callerMustBeClaimsProcessorContract

function callerMustBeClaimsProcessorContract(IStore s) external view

Arguments

Name Type Description
s IStore
Source Code
function callerMustBeClaimsProcessorContract(IStore s) external view {
    s.callerMustBeExactContract(ProtoUtilV1.CNS_CLAIM_PROCESSOR);
  }

callerMustBeStrategyContract

function callerMustBeStrategyContract(IStore s) external view

Arguments

Name Type Description
s IStore
Source Code
function callerMustBeStrategyContract(IStore s) external view {
    bool callerIsStrategyContract = s.getBoolByKey(_getIsActiveStrategyKey(msg.sender));
    require(callerIsStrategyContract == true, "Not a strategy contract");
  }

_getIsActiveStrategyKey

function _getIsActiveStrategyKey(address strategyAddress) private pure
returns(bytes32)

Arguments

Name Type Description
strategyAddress address
Source Code
function _getIsActiveStrategyKey(address strategyAddress) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_LENDING_STRATEGY_ACTIVE, strategyAddress));
  }

callerMustBeProtocolMember

function callerMustBeProtocolMember(IStore s) external view

Arguments

Name Type Description
s IStore
Source Code
function callerMustBeProtocolMember(IStore s) external view {
    require(s.isProtocolMember(msg.sender), "Forbidden");
  }

mustBeReporting

function mustBeReporting(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeReporting(IStore s, bytes32 key) external view {
    require(s.getCoverStatus(key) == CoverUtilV1.CoverStatus.IncidentHappened, "Not reporting");
  }

mustBeDisputed

function mustBeDisputed(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeDisputed(IStore s, bytes32 key) external view {
    require(s.getCoverStatus(key) == CoverUtilV1.CoverStatus.FalseReporting, "Not disputed");
  }

mustBeClaimable

function mustBeClaimable(IStore s, bytes32 key) public view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeClaimable(IStore s, bytes32 key) public view {
    require(s.getCoverStatus(key) == CoverUtilV1.CoverStatus.Claimable, "Not claimable");
  }

mustBeClaimingOrDisputed

function mustBeClaimingOrDisputed(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeClaimingOrDisputed(IStore s, bytes32 key) external view {
    CoverUtilV1.CoverStatus status = s.getCoverStatus(key);

    bool claiming = status == CoverUtilV1.CoverStatus.Claimable;
    bool falseReporting = status == CoverUtilV1.CoverStatus.FalseReporting;

    require(claiming || falseReporting, "Not reported nor disputed");
  }

mustBeReportingOrDisputed

function mustBeReportingOrDisputed(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeReportingOrDisputed(IStore s, bytes32 key) external view {
    CoverUtilV1.CoverStatus status = s.getCoverStatus(key);
    bool incidentHappened = status == CoverUtilV1.CoverStatus.IncidentHappened;
    bool falseReporting = status == CoverUtilV1.CoverStatus.FalseReporting;

    require(incidentHappened || falseReporting, "Not reported nor disputed");
  }

mustBeValidIncidentDate

function mustBeValidIncidentDate(IStore s, bytes32 key, uint256 incidentDate) public view

Arguments

Name Type Description
s IStore
key bytes32
incidentDate uint256
Source Code
function mustBeValidIncidentDate(
    IStore s,
    bytes32 key,
    uint256 incidentDate
  ) public view {
    require(s.getLatestIncidentDate(key) == incidentDate, "Invalid incident date");
  }

mustNotHaveDispute

function mustNotHaveDispute(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustNotHaveDispute(IStore s, bytes32 key) external view {
    address reporter = s.getAddressByKeys(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_NO, key);
    require(reporter == address(0), "Already disputed");
  }

mustBeDuringReportingPeriod

function mustBeDuringReportingPeriod(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeDuringReportingPeriod(IStore s, bytes32 key) external view {
    require(s.getUintByKeys(ProtoUtilV1.NS_GOVERNANCE_RESOLUTION_TS, key) >= block.timestamp, "Reporting window closed"); // solhint-disable-line
  }

mustBeAfterReportingPeriod

function mustBeAfterReportingPeriod(IStore s, bytes32 key) public view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeAfterReportingPeriod(IStore s, bytes32 key) public view {
    require(block.timestamp > s.getUintByKeys(ProtoUtilV1.NS_GOVERNANCE_RESOLUTION_TS, key), "Reporting still active"); // solhint-disable-line
  }

mustBeValidCxToken

function mustBeValidCxToken(IStore s, bytes32 key, address cxToken, uint256 incidentDate) public view

Arguments

Name Type Description
s IStore
key bytes32
cxToken address
incidentDate uint256
Source Code
function mustBeValidCxToken(
    IStore s,
    bytes32 key,
    address cxToken,
    uint256 incidentDate
  ) public view {
    require(s.getBoolByKeys(ProtoUtilV1.NS_COVER_CXTOKEN, cxToken) == true, "Unknown cxToken");

    bytes32 coverKey = ICxToken(cxToken).coverKey();
    require(coverKey == key, "Invalid cxToken");

    uint256 expires = ICxToken(cxToken).expiresOn();
    require(expires > incidentDate, "Invalid or expired cxToken");
  }

mustBeValidClaim

function mustBeValidClaim(IStore s, bytes32 key, address cxToken, uint256 incidentDate) external view

Arguments

Name Type Description
s IStore
key bytes32
cxToken address
incidentDate uint256
Source Code
function mustBeValidClaim(
    IStore s,
    bytes32 key,
    address cxToken,
    uint256 incidentDate
  ) external view {
    s.mustBeProtocolMember(cxToken);
    mustBeValidCxToken(s, key, cxToken, incidentDate);
    mustBeClaimable(s, key);
    mustBeValidIncidentDate(s, key, incidentDate);
    mustBeDuringClaimPeriod(s, key);
  }

mustNotHaveUnstaken

function mustNotHaveUnstaken(IStore s, address account, bytes32 key, uint256 incidentDate) public view

Arguments

Name Type Description
s IStore
account address
key bytes32
incidentDate uint256
Source Code
function mustNotHaveUnstaken(
    IStore s,
    address account,
    bytes32 key,
    uint256 incidentDate
  ) public view {
    bytes32 k = keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_UNSTAKE_TS, key, incidentDate, account));
    uint256 withdrawal = s.getUintByKey(k);

    require(withdrawal == 0, "Already unstaken");
  }

validateUnstakeAfterClaimPeriod

function validateUnstakeAfterClaimPeriod(IStore s, bytes32 key, uint256 incidentDate) external view

Arguments

Name Type Description
s IStore
key bytes32
incidentDate uint256
Source Code
function validateUnstakeAfterClaimPeriod(
    IStore s,
    bytes32 key,
    uint256 incidentDate
  ) external view {
    mustNotBePaused(s);
    mustNotHaveUnstaken(s, msg.sender, key, incidentDate);
  }

validateUnstakeWithClaim

function validateUnstakeWithClaim(IStore s, bytes32 key, uint256 incidentDate) external view

Arguments

Name Type Description
s IStore
key bytes32
incidentDate uint256
Source Code
function validateUnstakeWithClaim(
    IStore s,
    bytes32 key,
    uint256 incidentDate
  ) external view {
    mustNotBePaused(s);
    mustNotHaveUnstaken(s, msg.sender, key, incidentDate);
    // If a cover is finalized, this incident date will not be valid anymore
    mustBeValidIncidentDate(s, key, incidentDate);

    bool incidentHappened = s.getCoverStatus(key) == CoverUtilV1.CoverStatus.IncidentHappened;

    if (incidentHappened) {
      // Incident occurred. Must unstake with claim during the claim period.
      mustBeDuringClaimPeriod(s, key);
      return;
    }

    // Incident did not occur.
    mustBeAfterReportingPeriod(s, key);
  }

mustBeDuringClaimPeriod

function mustBeDuringClaimPeriod(IStore s, bytes32 key) public view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeDuringClaimPeriod(IStore s, bytes32 key) public view {
    uint256 beginsFrom = s.getUintByKeys(ProtoUtilV1.NS_CLAIM_BEGIN_TS, key);
    uint256 expiresAt = s.getUintByKeys(ProtoUtilV1.NS_CLAIM_EXPIRY_TS, key);

    require(beginsFrom > 0, "Invalid claim begin date");
    require(expiresAt > beginsFrom, "Invalid claim period");

    require(block.timestamp >= beginsFrom, "Claim period hasn't begun"); // solhint-disable-line
    require(block.timestamp <= expiresAt, "Claim period has expired"); // solhint-disable-line
  }

mustBeAfterClaimExpiry

function mustBeAfterClaimExpiry(IStore s, bytes32 key) external view

Arguments

Name Type Description
s IStore
key bytes32
Source Code
function mustBeAfterClaimExpiry(IStore s, bytes32 key) external view {
    require(block.timestamp > s.getUintByKeys(ProtoUtilV1.NS_CLAIM_EXPIRY_TS, key), "Claim still active"); // solhint-disable-line
  }

Contracts