View Source: contracts/libraries/ValidationLibV1.sol
ValidationLibV1
- mustNotBePaused(IStore s)
- mustBeValidCover(IStore s, bytes32 key)
- mustBeValidCoverKey(IStore s, bytes32 key)
- mustBeCoverOwner(IStore s, bytes32 key, address sender)
- mustBeCoverOwnerOrCoverContract(IStore s, bytes32 key, address sender)
- callerMustBePolicyContract(IStore s)
- callerMustBePolicyManagerContract(IStore s)
- callerMustBeCoverContract(IStore s)
- callerMustBeVaultContract(IStore s, bytes32 key)
- callerMustBeGovernanceContract(IStore s)
- callerMustBeClaimsProcessorContract(IStore s)
- callerMustBeStrategyContract(IStore s)
- _getIsActiveStrategyKey(address strategyAddress)
- callerMustBeProtocolMember(IStore s)
- mustBeReporting(IStore s, bytes32 key)
- mustBeDisputed(IStore s, bytes32 key)
- mustBeClaimable(IStore s, bytes32 key)
- mustBeClaimingOrDisputed(IStore s, bytes32 key)
- mustBeReportingOrDisputed(IStore s, bytes32 key)
- mustBeValidIncidentDate(IStore s, bytes32 key, uint256 incidentDate)
- mustNotHaveDispute(IStore s, bytes32 key)
- mustBeDuringReportingPeriod(IStore s, bytes32 key)
- mustBeAfterReportingPeriod(IStore s, bytes32 key)
- mustBeValidCxToken(IStore s, bytes32 key, address cxToken, uint256 incidentDate)
- mustBeValidClaim(IStore s, bytes32 key, address cxToken, uint256 incidentDate)
- mustNotHaveUnstaken(IStore s, address account, bytes32 key, uint256 incidentDate)
- validateUnstakeAfterClaimPeriod(IStore s, bytes32 key, uint256 incidentDate)
- validateUnstakeWithClaim(IStore s, bytes32 key, uint256 incidentDate)
- mustBeDuringClaimPeriod(IStore s, bytes32 key)
- mustBeAfterClaimExpiry(IStore s, bytes32 key)
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");
}
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");
}
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");
}
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");
}
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");
}
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);
}
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);
}
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);
}
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");
}
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);
}
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);
}
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");
}
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));
}
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");
}
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");
}
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");
}
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");
}
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");
}
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");
}
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");
}
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");
}
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
}
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
}
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");
}
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);
}
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");
}
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);
}
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);
}
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
}
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
}
- 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