Skip to content

Latest commit

 

History

History
534 lines (438 loc) · 16.2 KB

Policy.md

File metadata and controls

534 lines (438 loc) · 16.2 KB

Policy Contract (Policy.sol)

View Source: contracts/core/policy/Policy.sol

↗ Extends: IPolicy, Recoverable

Policy

The policy contract enables you to a purchase cover

Functions

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) {}

purchaseCover

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

Payouts and Incident Date

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);
  }

purchaseCovers

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]);
    }
  }

getCxToken

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);
  }

getCxTokenByExpiryDate

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);
  }

getExpiryDate

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);
  }

getCommitment

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);
  }

getAvailableLiquidity

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);
  }

getCoverFeeInfo

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);
  }

getCoverPoolSummary

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

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";
  }

getName

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;
  }

Contracts