View Source: contracts/core/policy/Policy.sol
↗ Extends: IPolicy, Recoverable
Policy
The policy contract enables you to a purchase cover
- constructor(IStore store)
- purchaseCover(struct IPolicy.PurchaseCoverArgs args)
- purchaseCovers(struct IPolicy.PurchaseCoverArgs[] args)
- 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()
Constructs this contract
function (IStore store) public nonpayable Recoverable
Arguments
Name | Type | Description |
---|---|---|
store | IStore | Provide an implementation of 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.
https://docs.neptunemutual.com/covers/purchasing-covers
function purchaseCover(struct IPolicy.PurchaseCoverArgs args) public nonpayable nonReentrant
returns(address, uint256)
Arguments
Name | Type | Description |
---|---|---|
args | struct IPolicy.PurchaseCoverArgs |
Source Code
function purchaseCover(PurchaseCoverArgs calldata args) public 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(args.coverKey > 0, "Invalid cover key");
require(args.onBehalfOf != address(0), "Invalid `onBehalfOf`");
require(args.amountToCover > 0, "Enter an amount");
require(args.coverDuration > 0 && args.coverDuration <= ProtoUtilV1.MAX_POLICY_DURATION, "Invalid cover duration");
s.mustNotBePaused();
s.mustNotExceedProposalThreshold(args.amountToCover);
s.mustBeSupportedProductOrEmpty(args.coverKey, args.productKey);
s.mustHaveNormalProductStatus(args.coverKey, args.productKey);
s.mustNotHavePolicyDisabled(args.coverKey, args.productKey);
s.senderMustBeWhitelistedIfRequired(args.coverKey, args.productKey, args.onBehalfOf);
uint256 lastPolicyId = s.incrementPolicyId();
(ICxToken cxToken, uint256 fee, uint256 platformFee) = s.purchaseCoverInternal(args);
emit CoverPurchased(args, address(cxToken), fee, platformFee, cxToken.expiresOn(), lastPolicyId);
return (address(cxToken), lastPolicyId);
}
function purchaseCovers(struct IPolicy.PurchaseCoverArgs[] args) external nonpayable
Arguments
Name | Type | Description |
---|---|---|
args | struct IPolicy.PurchaseCoverArgs[] |
Source Code
function purchaseCovers(PurchaseCoverArgs[] calldata args) external {
for (uint256 i = 0; i < args.length; i++) {
purchaseCover(args[i]);
}
}
Gets cxToken and its expiry address by the supplied arguments. Warning: this function does not validate the cover and product key supplied.
function getCxToken(bytes32 coverKey, bytes32 productKey, uint256 coverDuration) external view
returns(cxToken address, expiryDate uint256)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
productKey | bytes32 | Enter the cover key |
coverDuration | uint256 | Enter the cover's policy duration. Valid values: 1-3. |
Source Code
function getCxToken(
bytes32 coverKey,
bytes32 productKey,
uint256 coverDuration
) external view override returns (address cxToken, uint256 expiryDate) {
require(coverDuration > 0 && coverDuration <= ProtoUtilV1.MAX_POLICY_DURATION, "Invalid cover duration");
return s.getCxTokenInternal(coverKey, productKey, coverDuration);
}
Returns cxToken address by the cover key, product key, and expiry date. Warning: this function does not validate the cover and product key supplied.
function getCxTokenByExpiryDate(bytes32 coverKey, bytes32 productKey, uint256 expiryDate) external view
returns(cxToken address)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key |
productKey | bytes32 | Enter the cover key |
expiryDate | uint256 | Enter the cxToken's expiry date |
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);
}
Gets the sum total of cover commitment that has not expired yet. Warning: this function does not validate the cover and product key supplied.
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);
}
Gets the available liquidity in the pool. Warning: this function does not validate the cover key supplied.
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 Warning: this function does not validate the cover key supplied.
function getCoverFeeInfo(bytes32 coverKey, bytes32 productKey, uint256 coverDuration, uint256 amountToCover) external view
returns(struct IPolicy.CoverFeeInfoType)
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 (CoverFeeInfoType memory) {
PolicyHelperV1.CalculatePolicyFeeArgs memory args = PolicyHelperV1.CalculatePolicyFeeArgs({coverKey: coverKey, productKey: productKey, coverDuration: coverDuration, amountToCover: amountToCover});
return s.calculatePolicyFeeInternal(args);
}
Returns the pool summary of the given cover key Warning: this function does not validate the cover key supplied.
function getCoverPoolSummary(bytes32 coverKey, bytes32 productKey) external view
returns(summary struct IPolicy.CoverPoolSummaryType)
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | |
productKey | bytes32 |
Source Code
function getCoverPoolSummary(bytes32 coverKey, bytes32 productKey) external view override returns (IPolicy.CoverPoolSummaryType memory summary) {
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
- INeptuneRouterV1
- 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
- NeptuneRouterV1
- 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