IPolicyPool

There's a single instance of PolicyPool contract for a given deployment of the protocol

Some methods of this interface will be called by other components of the protocol (like RiskModule or PremiumsAccount).

Events

NewPolicy

event NewPolicy(contract IRiskModule riskModule, struct Policy.PolicyData policy)

Event emitted every time a new policy is added to the pool

Contains all the data about the policy that is later required for doing operations with the policy like resolution or expiration.

Parameters

Name Type Description
riskModule contract IRiskModule The risk module that created the policy
policy struct Policy.PolicyData The {Policy-PolicyData} struct with all the immutable fields of the policy.

PolicyReplaced

event PolicyReplaced(contract IRiskModule riskModule, uint256 oldPolicyId, uint256 newPolicyId)

Event emitted every time a new policy replaces an old Policy.

The event contains only the id of the replacement policy, the full data is available in the NewPolicy event.

Parameters

Name Type Description
riskModule contract IRiskModule The risk module that created the policy
oldPolicyId uint256 The id of the replaced policy.
newPolicyId uint256 The id of the new policy.

PolicyCancelled

event PolicyCancelled(contract IRiskModule riskModule, uint256 cancelledPolicyId, uint256 purePremiumRefund, uint256 jrCocRefund, uint256 srCocRefund)

Event emitted when a policy is cancelled, and part of the paid premium is refunded.

After this, the policy is no longer active. The refund amounts are transferred to the policy holder.

Parameters

Name Type Description
riskModule contract IRiskModule The risk module that created the policy
cancelledPolicyId uint256 The id of the cancelled policy.
purePremiumRefund uint256 The amount of pure premium refunded
jrCocRefund uint256 The amount of Jr CoC refunded
srCocRefund uint256 The amount of Sr CoC refunded

PolicyResolved

event PolicyResolved(contract IRiskModule riskModule, uint256 policyId, uint256 payout)

Event emitted every time a policy is removed from the pool

If the policy expired, the payout is 0, otherwise is the amount transferred to the policyholder.

Parameters

Name Type Description
riskModule contract IRiskModule The risk module where that created the policy initially.
policyId uint256 The unique id of the policy
payout uint256 The payout that has been paid to the policy holder. 0 when the policy expired.

Public Functions

currency

function currency() external view returns (contract IERC20Metadata)

Reference to the main currency (ERC20, e.g. USDC) used in the protocol

treasury

function treasury() external view returns (address)

Address of the treasury, that receives protocol fees.

newPolicy

function newPolicy(struct Policy.PolicyData policy, address payer, address policyHolder, uint96 internalId) external returns (uint256)

Creates a new Policy

It charges the premium and distributes it to the different parties (PremiumsAccount, ETokens, treasury)

Parameters

Name Type Description
policy struct Policy.PolicyData A policy created with {Policy-initialize}
payer address The address that will pay for the premium
policyHolder address The address of the policy holder
internalId uint96 A unique id within the RiskModule, that will be used to compute the policy id

Return Values

Name Type Description
[0] uint256 The policy id, identifying the NFT and the policy

Pre-conditions

  • msg.sender must be an active RiskModule
  • rm.premiumsAccount() must be an active PremiumsAccount
  • payer approved the spending of currency() for at least policy.premium
  • internalId must be unique within the risk module (msg.sender) and not used before

Throws

PolicyAlreadyExists
when reusing an internalId

Emits

NewPolicy
with all the details about the policy
ERC20-Transfer
transfers from `payer` to the different receivers of the premium
(see Premium Split in the docs)

replacePolicy

function replacePolicy(struct Policy.PolicyData oldPolicy, struct Policy.PolicyData newPolicy_, address payer, uint96 internalId) external returns (uint256)

Replaces a policy with another

After this call, the oldPolicy is no longer active and a new policy is created. Diferencial changes to premiums and locked SCR.

Parameters

Name Type Description
oldPolicy struct Policy.PolicyData A policy created previously and not expired
newPolicy_ struct Policy.PolicyData A policy created with {Policy-initialize}
payer address The address that will pay for the premium difference
internalId uint96 A unique id within the RiskModule, that will be used to compute the policy id

Return Values

Name Type Description
[0] uint256 The policy id, identifying the NFT and the policy

Pre-conditions

  • msg.sender must be an active RiskModule
  • rm.premiumsAccount() must be an active PremiumsAccount
  • payer approved the spending of currency() for at least newPolicy_.premium - oldPolicy.premium
  • internalId must be unique within policy.riskModule and not used before

Throws

PolicyAlreadyExpired
when trying to replace an expired policy
InvalidPolicyReplacement
when trying to reduce some of the premium componentsa

Emits

PolicyReplaced
with the ids of the new and replaced policy
NewPolicy
with all the details of the new policy

cancelPolicy

function cancelPolicy(struct Policy.PolicyData policyToCancel, uint256 purePremiumRefund, uint256 jrCocRefund, uint256 srCocRefund) external

Cancels a policy, doing optional refunds of parts of the premium.

After this call the policy is not claimable and funds are unlocked

Parameters

Name Type Description
policyToCancel struct Policy.PolicyData A policy created previously and not expired, that will be cancelled
purePremiumRefund uint256 The amount to refund from pure premiums (<= policyToCancel.purePremium)
jrCocRefund uint256 The amount to refund from jrCoc (<= policyToCancel.jrCoc)
srCocRefund uint256 The amount to refund from srCoc (<= policyToCancel.jrCoc)

Pre-conditions

  • msg.sender must be an active or deprecated RiskModule
  • Policy not expired
  • Events:

Emits

PolicyCancelled
with the refund amounts
ERC20-Transfer
transfers of the refunds amount to the policy holder

resolvePolicy

function resolvePolicy(struct Policy.PolicyData policy, uint256 payout) external

Resolves a policy with a payout, sending the payment to the owner of the policy NFT.

After this call the policy is no longer active and the funds have been unlocked.

Parameters

Name Type Description
policy struct Policy.PolicyData A policy previously created with newPolicy
payout uint256 The amount to pay to the policyholder

Pre-conditions

  • msg.sender must be an active or deprecated RiskModule
  • payout: must be less than equal to policy.payout.
  • policy: must be a Policy not resolved before and not expired (if payout > 0).

Emits

PolicyResolved
with the payout amount
ERC20-Transfer
to the policyholder with the payout

expirePolicy

function expirePolicy(struct Policy.PolicyData policy) external

Expires a policy, unlocked the solvency.

Resolves a policy with a payout 0, unlocking the solvency. Can be called by anyone, but only after Policy.expiration.

Parameters

Name Type Description
policy struct Policy.PolicyData A policy previously created with newPolicy

Pre-conditions

  • policy: must be a Policy not resolved before
  • policy.expiration <= block.timestamp

Emits

PolicyResolved
with the payout == 0

isActive

function isActive(uint256 policyId) external view returns (bool)

Returns whether a policy is active

A policy is active when it's still in the PolicyPool, not yet resolved or expired. Be aware that a policy might be active but the block.timestamp might be after the expiration date, so it can't be triggered with a payout.

Parameters

Name Type Description
policyId uint256 The id of the policy queried

Return Values

Name Type Description
[0] bool Whether the policy is active or not

getPolicyHash

function getPolicyHash(uint256 policyId) external view returns (bytes32)

Returns the stored hash of the policy

Returns bytes32(0) if the policy isn't active.

Parameters

Name Type Description
policyId uint256 The id of the policy queried

Return Values

Name Type Description
[0] bytes32 Returns the hash of a given policy id

deposit

function deposit(contract IEToken eToken, uint256 amount, address receiver) external

Deposits liquidity into an eToken

Forwards the call to {EToken-deposit}, after transferring the funds. The user will receive etokens for the same amount deposited.

Parameters

Name Type Description
eToken contract IEToken The address of the eToken to which the user wants to provide liquidity
amount uint256 The amount to deposit
receiver address The user that will receive the minted tokens

Pre-conditions

  • msg.sender approved the spending of currency() for at least amount
  • eToken is an active eToken installed in the pool.

Emits

EToken-Transfer
from 0x0 to `receiver`, reflects the eTokens minted.
ERC20-Transfer
from `msg.sender` to address(eToken)

depositWithPermit

function depositWithPermit(contract IEToken eToken, uint256 amount, address receiver, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external

Deposits liquidity into an eToken, EIP-2612 compatible version.

Forwards the call to {EToken-deposit}, after transferring the funds. The user will receive etokens for the same amount deposited. EIP-2612 compatible version, allows sending a signed permit in the same operation.

Parameters

Name Type Description
eToken contract IEToken The address of the eToken to which the user wants to provide liquidity
amount uint256 The amount to deposit
receiver address The user that will receive the minted tokens
deadline uint256 The deadline of the permit
v uint8 Component of the secp256k1 signature
r bytes32 Component of the secp256k1 signature
s bytes32 Component of the secp256k1 signature

Pre-conditions

  • msg.sender approved the spending of currency() for at least amount
  • eToken is an active eToken installed in the pool.

Emits

EToken-Transfer
from 0x0 to `receiver`, reflects the eTokens minted.
ERC20-Transfer
from `msg.sender` to address(eToken)

withdraw

function withdraw(contract IEToken eToken, uint256 amount, address receiver, address owner) external returns (uint256)

Withdraws an amount from an eToken

Forwards the call to {EToken-withdraw}. amount of eTokens will be burned and the user will receive the same amount in currency().

Parameters

Name Type Description
eToken contract IEToken The address of the eToken from where the user wants to withdraw liquidity
amount uint256 The amount to withdraw. If equal to type(uint256).max, means full withdrawal. If the balance is not enough or can't be withdrawn (locked as SCR), it withdraws as much as it can, but doesn't fails.
receiver address The user that will receive the resulting currency()
owner address The user that owns the eTokens (must be msg.sender or have allowance)

Return Values

Name Type Description
[0] uint256 Returns the actual amount withdrawn.

Pre-conditions

  • eToken is an active (or deprecated) eToken installed in the pool.

Emits

EToken-Transfer
from `owner` to `0x0`, reflects the eTokens burned.
ERC20-Transfer
from address(eToken) to `receiver`