View Source: contracts/core/policy/Policy.sol
↗ Extends: IPolicy, Recoverable
Policy
The policy contract enables you to a purchase cover
- constructor(IStore store)
- purchaseCover(bytes32 key, uint256 coverDuration, uint256 amountToCover)
- getCxToken(bytes32 key, uint256 coverDuration)
- getCxTokenByExpiryDate(bytes32 key, uint256 expiryDate)
- getExpiryDate(uint256 today, uint256 coverDuration)
- getCommitment(bytes32 key)
- getCoverable(bytes32 key)
- getCoverFeeInfo(bytes32 key, uint256 coverDuration, uint256 amountToCover)
- getCoverPoolSummary(bytes32 key)
- version()
- getName()
function (IStore store) public nonpayable Recoverable
Arguments
Name | Type | Description |
---|---|---|
store | IStore |
Source Code
constructor(IStore store) Recoverable(store) {}
Purchase cover for the specified amount.
When you purchase covers, you receive equal amount of cxTokens back.
You need the cxTokens to claim the cover when resolution occurs.
Each unit of cxTokens are fully redeemable at 1:1 ratio to the given
stablecoins (like wxDai, DAI, USDC, or BUSD) based on the chain.
function purchaseCover(bytes32 key, uint256 coverDuration, uint256 amountToCover) external nonpayable nonReentrant
returns(address)
Arguments
Name | Type | Description |
---|---|---|
key | bytes32 | Enter the cover key you wish to purchase the policy for |
coverDuration | uint256 | Enter the number of months to cover. Accepted values: 1-3. |
amountToCover | uint256 | Enter the amount of the stablecoin liquidityToken to cover. |
Source Code
function purchaseCover(
bytes32 key,
uint256 coverDuration,
uint256 amountToCover
) external override nonReentrant returns (address) {
// @suppress-acl Marking this as publicly accessible
s.mustNotBePaused();
s.mustBeValidCover(key);
require(coverDuration > 0 && coverDuration <= 3, "Invalid cover duration");
(ICxToken cxToken, uint256 fee) = s.purchaseCoverInternal(key, coverDuration, amountToCover);
emit CoverPurchased(key, msg.sender, address(cxToken), fee, amountToCover, cxToken.expiresOn());
return address(cxToken);
}
function getCxToken(bytes32 key, uint256 coverDuration) external view
returns(cxToken address, expiryDate uint256)
Arguments
Name | Type | Description |
---|---|---|
key | bytes32 | |
coverDuration | uint256 |
Source Code
function getCxToken(bytes32 key, uint256 coverDuration) external view override returns (address cxToken, uint256 expiryDate) {
return s.getCxTokenInternal(key, coverDuration);
}
function getCxTokenByExpiryDate(bytes32 key, uint256 expiryDate) external view
returns(cxToken address)
Arguments
Name | Type | Description |
---|---|---|
key | bytes32 | |
expiryDate | uint256 |
Source Code
function getCxTokenByExpiryDate(bytes32 key, uint256 expiryDate) external view override returns (address cxToken) {
return s.getCxTokenByExpiryDateInternal(key, expiryDate);
}
Gets the expiry date based on cover duration
function getExpiryDate(uint256 today, uint256 coverDuration) external pure
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
today | uint256 | Enter the current timestamp |
coverDuration | uint256 | Enter the number of months to cover. Accepted values: 1-3. |
Source Code
function getExpiryDate(uint256 today, uint256 coverDuration) external pure override returns (uint256) {
return CoverUtilV1.getExpiryDateInternal(today, coverDuration);
}
function getCommitment(bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
key | bytes32 |
Source Code
function getCommitment(bytes32 key) external view override returns (uint256) {
return s.getCommitmentInternal(key);
}
function getCoverable(bytes32 key) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
key | bytes32 |
Source Code
function getCoverable(bytes32 key) external view override returns (uint256) {
return s.getCoverableInternal(key);
}
Gets the cover fee info for the given cover key, duration, and amount
function getCoverFeeInfo(bytes32 key, uint256 coverDuration, uint256 amountToCover) external view
returns(fee uint256, utilizationRatio uint256, totalAvailableLiquidity uint256, coverRatio uint256, floor uint256, ceiling uint256, rate uint256)
Arguments
Name | Type | Description |
---|---|---|
key | bytes32 | Enter the cover key |
coverDuration | uint256 | Enter the number of months to cover. Accepted values: 1-3. |
amountToCover | uint256 | Enter the amount of the stablecoin liquidityToken to cover. |
Source Code
function getCoverFeeInfo(
bytes32 key,
uint256 coverDuration,
uint256 amountToCover
)
external
view
override
returns (
uint256 fee,
uint256 utilizationRatio,
uint256 totalAvailableLiquidity,
uint256 coverRatio,
uint256 floor,
uint256 ceiling,
uint256 rate
)
{
return s.getCoverFeeInfoInternal(key, coverDuration, amountToCover);
}
Returns the values of the given cover key
function getCoverPoolSummary(bytes32 key) external view
returns(_values uint256[])
Arguments
Name | Type | Description |
---|---|---|
key | bytes32 |
Source Code
function getCoverPoolSummary(bytes32 key) external view override returns (uint256[] memory _values) {
return s.getCoverPoolSummaryInternal(key);
}
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";
}
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_POLICY;
}
- 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