View Source: contracts/core/policy/Policy.sol
↗ Extends: IPolicy, Recoverable
Policy
The policy contract enables you to a purchase cover
Constants & Variables
uint256 public lastPolicyId;
- constructor(IStore store, uint256 _lastPolicyId)
- purchaseCover(address onBehalfOf, bytes32 coverKey, bytes32 productKey, uint256 coverDuration, uint256 amountToCover, bytes32 referralCode)
- getCxToken(bytes32 coverKey, bytes32 productKey, uint256 coverDuration)
- getCxTokenByExpiryDate(bytes32 coverKey, bytes32 productKey, uint256 expiryDate)
- getExpiryDate(uint256 today, uint256 coverDuration)
- getCommitment(bytes32 coverKey, bytes32 productKey)
- getAvailableLiquidity(bytes32 coverKey)
- getCoverFeeInfo(bytes32 coverKey, bytes32 productKey, uint256 coverDuration, uint256 amountToCover)
- getCoverPoolSummary(bytes32 coverKey, bytes32 productKey)
- version()
- getName()
function (IStore store, uint256 _lastPolicyId) public nonpayable Recoverable
Arguments
Name | Type | Description |
---|---|---|
store | IStore | |
_lastPolicyId | uint256 |
Source Code
constructor(IStore store, uint256 _lastPolicyId) Recoverable(store) {
lastPolicyId = _lastPolicyId;
}
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.
https://docs.neptunemutual.com/covers/purchasing-covers
function purchaseCover(address onBehalfOf, bytes32 coverKey, bytes32 productKey, uint256 coverDuration, uint256 amountToCover, bytes32 referralCode) external nonpayable nonReentrant
returns(address, uint256)
Arguments
Name | Type | Description |
---|---|---|
onBehalfOf | address | Enter an address you would like to send the claim tokens (cxTokens) to. |
coverKey | bytes32 | Enter the cover key you wish to purchase the policy for |
productKey | bytes32 | |
coverDuration | uint256 | Enter the number of months to cover. Accepted values: 1-3. |
amountToCover | uint256 | Enter the amount of the stablecoin to cover. |
referralCode | bytes32 |
Source Code
function purchaseCover(
address onBehalfOf,
bytes32 coverKey,
bytes32 productKey,
uint256 coverDuration,
uint256 amountToCover,
bytes32 referralCode
) external override nonReentrant returns (address, uint256) {
// @todo: When the POT system is replaced with NPM tokens in the future, upgrade this contract
// and uncomment the following line
// require(IERC20(s.getNpmTokenAddress()).balanceOf(msg.sender) >= 1 ether, "No NPM balance");
require(coverKey > 0, "Invalid cover key");
require(onBehalfOf != address(0), "Invalid `onBehalfOf`");
require(amountToCover > 0, "Enter an amount");
require(coverDuration > 0 && coverDuration <= 3, "Invalid cover duration");
s.mustNotBePaused();
s.mustNotExceedProposalThreshold(amountToCover);
s.mustBeSupportedProductOrEmpty(coverKey, productKey);
s.mustHaveNormalProductStatus(coverKey, productKey);
s.mustNotHavePolicyDisabled(coverKey, productKey);
s.senderMustBeWhitelistedIfRequired(coverKey, productKey, onBehalfOf);
lastPolicyId += 1;
(ICxToken cxToken, uint256 fee, uint256 platformFee) = s.purchaseCoverInternal(onBehalfOf, coverKey, productKey, coverDuration, amountToCover);
emit CoverPurchased(coverKey, productKey, onBehalfOf, address(cxToken), fee, platformFee, amountToCover, cxToken.expiresOn(), referralCode, lastPolicyId);
return (address(cxToken), lastPolicyId);
}
function getCxToken(bytes32 coverKey, bytes32 productKey, uint256 coverDuration) external view
returns(cxToken address, expiryDate uint256)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | |
productKey | bytes32 | |
coverDuration | uint256 |
Source Code
function getCxToken(
bytes32 coverKey,
bytes32 productKey,
uint256 coverDuration
) external view override returns (address cxToken, uint256 expiryDate) {
return s.getCxTokenInternal(coverKey, productKey, coverDuration);
}
function getCxTokenByExpiryDate(bytes32 coverKey, bytes32 productKey, uint256 expiryDate) external view
returns(cxToken address)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | |
productKey | bytes32 | |
expiryDate | uint256 |
Source Code
function getCxTokenByExpiryDate(
bytes32 coverKey,
bytes32 productKey,
uint256 expiryDate
) external view override returns (address cxToken) {
return s.getCxTokenByExpiryDateInternal(coverKey, productKey, 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 coverKey, bytes32 productKey) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | |
productKey | bytes32 |
Source Code
function getCommitment(bytes32 coverKey, bytes32 productKey) external view override returns (uint256) {
uint256 precision = s.getStablecoinPrecision();
return s.getActiveLiquidityUnderProtection(coverKey, productKey, precision);
}
function getAvailableLiquidity(bytes32 coverKey) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 |
Source Code
function getAvailableLiquidity(bytes32 coverKey) external view override returns (uint256) {
return s.getStablecoinOwnedByVaultInternal(coverKey);
}
Gets the cover fee info for the given cover key, duration, and amount
function getCoverFeeInfo(bytes32 coverKey, bytes32 productKey, uint256 coverDuration, uint256 amountToCover) external view
returns(fee uint256, utilizationRatio uint256, totalAvailableLiquidity uint256, floor uint256, ceiling uint256, rate uint256)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
productKey | bytes32 | |
coverDuration | uint256 | Enter the number of months to cover. Accepted values: 1-3. |
amountToCover | uint256 | Enter the amount of the stablecoin to cover. |
Source Code
function getCoverFeeInfo(
bytes32 coverKey,
bytes32 productKey,
uint256 coverDuration,
uint256 amountToCover
)
external
view
override
returns (
uint256 fee,
uint256 utilizationRatio,
uint256 totalAvailableLiquidity,
uint256 floor,
uint256 ceiling,
uint256 rate
)
{
return s.calculatePolicyFeeInternal(coverKey, productKey, coverDuration, amountToCover);
}
Returns the values of the given cover key
function getCoverPoolSummary(bytes32 coverKey, bytes32 productKey) external view
returns(_values uint256[])
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | |
productKey | bytes32 |
Source Code
function getCoverPoolSummary(bytes32 coverKey, bytes32 productKey) external view override returns (uint256[] memory _values) {
return s.getCoverPoolSummaryInternal(coverKey, productKey);
}
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
- Cover
- CoverBase
- CoverLibV1
- CoverReassurance
- CoverStake
- CoverUtilV1
- cxToken
- cxTokenFactory
- cxTokenFactoryLibV1
- Delayable
- Destroyable
- ERC165
- ERC20
- FakeAaveLendingPool
- FakeCompoundDaiDelegator
- FakePriceOracle
- FakeRecoverable
- FakeStore
- FakeToken
- FakeUniswapPair
- FakeUniswapV2FactoryLike
- FakeUniswapV2PairLike
- FakeUniswapV2RouterLike
- FaultyAaveLendingPool
- FaultyCompoundDaiDelegator
- Finalization
- ForceEther
- Governance
- GovernanceUtilV1
- IAaveV2LendingPoolLike
- IAccessControl
- IBondPool
- IClaimsProcessor
- ICompoundERC20DelegatorLike
- ICover
- ICoverReassurance
- ICoverStake
- ICxToken
- ICxTokenFactory
- IERC165
- IERC20
- IERC20Detailed
- IERC20Metadata
- IERC3156FlashBorrower
- IERC3156FlashLender
- IFinalization
- IGovernance
- ILendingStrategy
- ILiquidityEngine
- IMember
- InvalidStrategy
- IPausable
- IPolicy
- IPolicyAdmin
- IPriceOracle
- IProtocol
- IRecoverable
- IReporter
- IResolution
- IResolvable
- IStakingPools
- IStore
- IStoreLike
- IUniswapV2FactoryLike
- IUniswapV2PairLike
- IUniswapV2RouterLike
- IUnstakable
- IVault
- IVaultDelegate
- IVaultFactory
- IWitness
- LiquidityEngine
- MaliciousToken
- MockAccessControlUser
- MockCoverUtilUser
- MockCxToken
- MockCxTokenPolicy
- MockCxTokenStore
- MockFlashBorrower
- MockLiquidityEngineUser
- MockProcessorStore
- MockProcessorStoreLib
- MockProtocol
- MockRegistryClient
- MockStore
- MockStoreKeyUtilUser
- MockValidationLibUser
- MockVault
- MockVaultLibUser
- NPM
- NpmDistributor
- NTransferUtilV2
- NTransferUtilV2Intermediate
- Ownable
- Pausable
- Policy
- PolicyAdmin
- PolicyHelperV1
- PoorMansERC20
- POT
- PriceLibV1
- Processor
- ProtoBase
- Protocol
- ProtoUtilV1
- Recoverable
- ReentrancyGuard
- RegistryLibV1
- Reporter
- Resolution
- Resolvable
- RoutineInvokerLibV1
- SafeERC20
- StakingPoolBase
- StakingPoolCoreLibV1
- StakingPoolInfo
- StakingPoolLibV1
- StakingPoolReward
- StakingPools
- Store
- StoreBase
- StoreKeyUtil
- StrategyLibV1
- Strings
- TimelockController
- Unstakable
- ValidationLibV1
- Vault
- VaultBase
- VaultDelegate
- VaultDelegateBase
- VaultDelegateWithFlashLoan
- VaultFactory
- VaultFactoryLibV1
- VaultLibV1
- VaultLiquidity
- VaultStrategy
- WithFlashLoan
- WithPausability
- WithRecovery
- Witness