Policy

Library for PolicyData struct. This struct represents an active policy, the premium and solvency breakdown

Tracks how the premium is distributed, the probability of payout, duration and how the capital is locked. It is never stored on-chain, but instead we store a hash and we receive the policy on each operation

Types

Params

Struct of the parameters of the risk module that are used to calculate the different Policy fields (see {Policy-PolicyData}.

struct Params {
  uint256 moc;
  uint256 jrCollRatio;
  uint256 collRatio;
  uint256 ensuroPpFee;
  uint256 ensuroCocFee;
  uint256 jrRoc;
  uint256 srRoc;
}

PolicyData

Struct with all the info of a given policy

It includes the premium breakdown (premium=purePremium + jrCoc + srCoc + ensuroCommission + partnerCommission), the solvency breakdown (solvency = purePremium + jrScr + srScr = payout * collRatio), and the start and end of the policy.

struct PolicyData {
  uint256 id;
  uint256 payout;
  uint256 jrScr;
  uint256 srScr;
  uint256 lossProb;
  uint256 purePremium;
  uint256 ensuroCommission;
  uint256 partnerCommission;
  uint256 jrCoc;
  uint256 srCoc;
  uint40 start;
  uint40 expiration;
}

PremiumComposition

Struct that contains the breakdown of premium and policy solvency

Used for internal calculations. totalPremium = purePremium + jrCoc + srCoc + ensuroCommission + partnerCommission

struct PremiumComposition {
  uint256 purePremium;
  uint256 jrScr;
  uint256 srScr;
  uint256 jrCoc;
  uint256 srCoc;
  uint256 ensuroCommission;
  uint256 partnerCommission;
  uint256 totalPremium;
}

Variables

WAD

uint256 WAD

SECONDS_PER_YEAR

uint256 SECONDS_PER_YEAR

Errors

PremiumLessThanMinimum

error PremiumLessThanMinimum(uint256 premium, uint256 minPremium)

Raised when the received premium is less than the minimum

The minPremium is the one that results of computing the CoCs, purePremium and ensuroCommission for the given parameters, assuming partnerCommission = 0.

PremiumExceedsPayout

error PremiumExceedsPayout(uint256 premium, uint256 payout)

Raised when the premium exceeds the payoutreceived premium is less than the minimum

ZeroHash

error ZeroHash(struct Policy.PolicyData policy)

Raised when the computed hash is bytes32(0)

Private Functions

getMinimumPremium

function getMinimumPremium(struct Policy.Params rmParams, uint256 payout, uint256 lossProb, uint40 expiration, uint40 start) internal pure returns (struct Policy.PremiumComposition minPremium)

Computes the minimum premium

The minPremium is the one that results of computing the CoCs, purePremium and ensuroCommission for the given parameters, assuming partnerCommission = 0.

Parameters

Name Type Description
rmParams struct Policy.Params Struct with the business and quantitative parameters that define the risk (see {Params}).
payout uint256 Maximum payout (exposure) of the policy
lossProb uint256 Probability of paying the maximum payout (purePremium = rmParams.moc * lossProb * payout)
expiration uint40 Timestamp when the policy expires (can't be claimed anymore)
start uint40 Timestamp when the policy starts (block.timestamp for new policies)

Return Values

Name Type Description
minPremium struct Policy.PremiumComposition PremiumComposition struct with the computed premium and its breakdown

initialize

function initialize(struct Policy.Params rmParams, uint256 premium, uint256 payout, uint256 lossProb, uint40 expiration, uint40 start) internal pure returns (struct Policy.PolicyData newPolicy)

Initializes a policy struct

Computes the minimum premium and the remaining (premium - minPremium) is assigned as partnerCommissiona

Parameters

Name Type Description
rmParams struct Policy.Params Struct with the business and quantitative parameters that define the risk (see {Params}).
premium uint256 The premium that will be paid for the policy
payout uint256 Maximum payout (exposure) of the policy
lossProb uint256 Probability of paying the maximum payout (purePremium = rmParams.moc * lossProb * payout)
expiration uint40 Timestamp when the policy expires (can't be claimed anymore)
start uint40 Timestamp when the policy starts (block.timestamp for new policies)

Return Values

Name Type Description
newPolicy struct Policy.PolicyData PolicyData struct with the fields initialized (all except .id)

Throws

PremiumLessThanMinimum
when `premium` parameter is less than the computed minPremium

jrInterestRate

function jrInterestRate(struct Policy.PolicyData policy) internal pure returns (uint256)

Computes the annualized interest rate paid to Junior LPs, for a given policy

Computed as (jrCoc / jrScr) * (SECONDS_PER_YEAR / duration). The result should be almost the same as the initial rmParams.jrRoc sent to initialize.

Parameters

Name Type Description
policy struct Policy.PolicyData Struct with all the info of the policy

Return Values

Name Type Description
[0] uint256 Annualized interest rate in WAD

jrAccruedInterest

function jrAccruedInterest(struct Policy.PolicyData policy) internal view returns (uint256)

Computed the interest accrued by junior LPs

The value is directly proportional to the elapsed time since policy.start with respect to the duration

Parameters

Name Type Description
policy struct Policy.PolicyData Struct with all the info of the policy

Return Values

Name Type Description
[0] uint256 Amount of the JrCoc accrued so far

srInterestRate

function srInterestRate(struct Policy.PolicyData policy) internal pure returns (uint256)

Computes the annualized interest rate paid to Senior LPs, for a given policy

Computed as (srCoc / srScr) * (SECONDS_PER_YEAR / duration). The result should be almost the same as the initial rmParams.srRoc sent to initialize.

Parameters

Name Type Description
policy struct Policy.PolicyData Struct with all the info of the policy

Return Values

Name Type Description
[0] uint256 Annualized interest rate in WAD

srAccruedInterest

function srAccruedInterest(struct Policy.PolicyData policy) internal view returns (uint256)

Computed the interest accrued by senior LPs

The value is directly proportional to the elapsed time since policy.start with respect to the duration

Parameters

Name Type Description
policy struct Policy.PolicyData Struct with all the info of the policy

Return Values

Name Type Description
[0] uint256 Amount of the SrCoc accrued so far

duration

function duration(struct Policy.PolicyData policy) internal pure returns (uint40)

Returns the duration in seconds of the policy

hash

function hash(struct Policy.PolicyData policy) internal pure returns (bytes32 retHash)

Returns a hash of all the fields of the policy

extractRiskModule

function extractRiskModule(uint256 policyId) internal pure returns (address)

Extracts the risk module address from a policyId (first 20 bytes)

extractInternalId

function extractInternalId(uint256 policyId) internal pure returns (uint96)

Extracts the internalId from a policyId (last 96 bits)

makePolicyId

function makePolicyId(address rm, uint96 internalId) internal pure returns (uint256)

Generates a policyId, combining the riskModule (first 20 bytes) with the internalId (last 12 bytes)

Parameters

Name Type Description
rm address The risk module
internalId uint96 An identifier for the policy that is unique within a given risk module

Return Values

Name Type Description
[0] uint256 The policy id, that will be used as the tokenId for the minted policy NFT