Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Latest commit

 

History

History
456 lines (373 loc) · 12.3 KB

Policy.md

File metadata and controls

456 lines (373 loc) · 12.3 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

function (IStore store) public nonpayable Recoverable 

Arguments

Name Type Description
store 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.

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

getCxToken

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

getCxTokenByExpiryDate

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

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

getCoverable

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

getCoverFeeInfo

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

getCoverPoolSummary

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

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