RiskModule

Risk Module that keeps the configuration and is responsible for injecting policies and policy resolution

Variables

_premiumsAccount

contract IPremiumsAccount _premiumsAccount

_underwriter

contract IUnderwriter _underwriter

_wallet

address _wallet

Events

PartnerWalletChanged

event PartnerWalletChanged(address oldWallet, address newWallet)

UnderwriterChanged

event UnderwriterChanged(contract IUnderwriter oldUW, contract IUnderwriter newUW)

Errors

InvalidWallet

error InvalidWallet(address wallet)

InvalidUnderwriter

error InvalidUnderwriter(contract IUnderwriter uw)

PremiumsAccountMustBePartOfThePool

error PremiumsAccountMustBePartOfThePool()

UpgradeCannotChangePremiumsAccount

error UpgradeCannotChangePremiumsAccount()

ExpirationMustBeInTheFuture

error ExpirationMustBeInTheFuture(uint40 expiration, uint40 now)

InvalidCustomer

error InvalidCustomer(address customer)

Public Functions

constructor

constructor(contract IPolicyPool policyPool_, contract IPremiumsAccount premiumsAccount_) public

initialize

function initialize(contract IUnderwriter underwriter_, address wallet_) public

Initializes the RiskModule

Parameters

Name Type Description
underwriter_ contract IUnderwriter Contract in charge of decoding and validating the input and pricing the policies
wallet_ address Address of the RiskModule provider

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)

See {IERC165-supportsInterface}.

wallet

function wallet() public view returns (address)

Returns the address of the partner that receives the partnerCommission

setWallet

function setWallet(address newWallet) public

Changes the wallet that will receive the partner commission of the policies created by this risk module. Events: - {RiskModule-PartnerWalletChanged}

Parameters

Name Type Description
newWallet address The new wallet that will receive the partner commissions. It can't be address(0).

underwriter

function underwriter() public view returns (contract IUnderwriter)

Returns the underwriter contract, responsible for pricing and validating new policies, replacements and cancellations.

setUnderwriter

function setUnderwriter(contract IUnderwriter newUW) public

Changes the underwriter contract, responsible for pricing and validating new policies, replacements and cancellations. Events: - {RiskModule-UnderwriterChanged}

Parameters

Name Type Description
newUW contract IUnderwriter The new underwriter contract. It can't be address(0)

premiumsAccount

function premiumsAccount() external view returns (contract IPremiumsAccount)

Returns the {PremiumsAccount} where the premiums of this risk module are collected. Never changes.

getMinimumPremium

function getMinimumPremium(uint256 payout, uint256 lossProb, uint40 start, uint40 expiration, struct Policy.Params p) public pure returns (uint256)

newPolicy

function newPolicy(bytes inputData, address onBehalfOf) public returns (struct Policy.PolicyData policy)

Creates a new policy. The premium will paid by msg.sender

Parameters

Name Type Description
inputData bytes Input data that will be decoded by the _underwriter to construct the parameters for the new policy.
onBehalfOf address The address that will be the owner of the created policy

newPolicies

function newPolicies(bytes[] inputData, address onBehalfOf) external

Creates several policies, the premium is paid by msg.sender

Parameters

Name Type Description
inputData bytes[] Input data that will be decoded by the _underwriter to construct the parameters for the new policy.
onBehalfOf address The address that will be the owner of the created policy (same for all the policies)

replacePolicy

function replacePolicy(bytes inputData) external virtual returns (struct Policy.PolicyData policy)

Replaces a policy with a new one, with the same owner

Parameters

Name Type Description
inputData bytes Input data that will be decoded by the _underwriter to construct the oldPolicy and the parameters for the new policy.

cancelPolicy

function cancelPolicy(bytes inputData) external virtual

Cancels a policy, giving back all (or part) of the pure premium and the non-accrued CoC

Parameters

Name Type Description
inputData bytes Input data that will be decoded by the _underwriter to construct the oldPolicy and the parameters for the new policy.

resolvePolicy

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

_Resolves a policy, if payout > 0, it pays to the policy holder.

Requirements: - payout <= policy.payout - block.timestamp >= policy.expiration

Emits: - {PolicyPool.PolicyResolved}_

Parameters

Name Type Description
policy struct Policy.PolicyData The policy previously created (from {NewPolicy} event)
payout uint256 The payout to transfer to the policy holder

Private Functions

__RiskModule_init

function __RiskModule_init(contract IUnderwriter underwriter_, address wallet_) internal

Initializes the RiskModule

Parameters

Name Type Description
underwriter_ contract IUnderwriter Contract in charge of decoding and validating the input and pricing the policies
wallet_ address Address of the RiskModule provider

__RiskModule_init_unchained

function __RiskModule_init_unchained(contract IUnderwriter underwriter_, address wallet_) internal

_upgradeValidations

function _upgradeValidations(address newImpl) internal view virtual