Skip to content

Latest commit

 

History

History
523 lines (436 loc) · 15.4 KB

Policy.md

File metadata and controls

523 lines (436 loc) · 15.4 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

Contract Members

Constants & Variables

uint256 public lastPolicyId;

Functions

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

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

getCxToken

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

getCxTokenByExpiryDate

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

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

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

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

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

getCoverPoolSummary

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

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