> For the complete documentation index, see [llms.txt](https://docs.ensuro.co/ensuro-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ensuro.co/ensuro-docs/smart-contracts/contracts/riskmodule.md).

# RiskModule

Risk Module is an abstract contract that needs to be implemented with specific policies for the main responsibilities of the contract: pricing and resolution.

The contract also stores several parameters that are used for the creation and validation of the policies.

## **Roles**

The specific roles and functions of the contract are as follows:

<table><thead><tr><th>Role</th><th width="83" data-type="checkbox">Global*</th><th>Description</th><th>Methods Accessible</th></tr></thead><tbody><tr><td>LEVEL1_ROLE</td><td>true</td><td>High impact changes like upgrades or other critical operations.</td><td><ul><li><a href="#setting-parameters">setParam</a>: Set parameters.</li></ul></td></tr><tr><td>LEVEL2_ROLE</td><td>true</td><td>Mid-impact changes like changing some parameters.</td><td><ul><li><a href="#setting-parameters">setParam</a>: Set parameters.</li></ul></td></tr><tr><td>LEVEL3_ROLE</td><td>true</td><td>Low-impact changes like changing some parameters up to given percentage (tweaks).</td><td><ul><li><a href="https://app.gitbook.com/o/0kzqc3VraIOjgEzncVRI/s/pvASGnPdK0F6cKq9e2Lh/~/changes/73/smart-contracts/contracts/riskmodule#setting-parameters">setParam</a>: Set parameters.</li></ul></td></tr><tr><td>RM_PROVIDER</td><td>false</td><td>Manages the risk module.</td><td><ul><li>setWallet: Sets the risk module wallet.</li></ul></td></tr></tbody></table>

( \* ) Global means that the role can be delegated to a user at the protocol level (for all components) or only for a specific component. Non-global roles can only be granted for a specific component.

## Parameters

These parameters are managed and adjusted by the protocol governance. Some come from business decisions and others are quantitative analysis decisions.

| Field              | Type             | Description                                                                                                                                                                                           |
| ------------------ | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| moc                | uint256 (wad)    | Margin of Conservatism. A factor used to scale the expected losses calculated as `payout * lossProb`                                                                                                  |
| jrCollRatio        | uint256 (wad)    | The collateralization ratio up to the junior eToken (see [Solvency Breakdown](/ensuro-docs/smart-contracts/policy.md#solvency-breakdown))                                                             |
| collRatio          | uint256 (wad)    | The overall collateralization ratio (see [Solvency Breakdown](/ensuro-docs/smart-contracts/policy.md#solvency-breakdown))                                                                             |
| ensuroPpFee        | uint256 (wad)    | Percentage applied to the pure premium used to compute the [Ensuro Commision](/ensuro-docs/smart-contracts/policy.md#ensuro-commission).                                                              |
| ensuroCocFee       | uint256 (wad)    | Percentage applied to the cost of capital used to compute the [Ensuro Commision](/ensuro-docs/smart-contracts/policy.md#ensuro-commission).                                                           |
| jrRoc              | uint256 (wad)    | Annualized return expected by Junior eToken liquidity providers for the capital exposed to these risks. See [more details](/ensuro-docs/smart-contracts/policy.md#junior-and-senior-cost-of-capital). |
| srRoc              | uint256 (wad)    | Annualized return expected by Senior eToken liquidity providers for the capital exposed to these risks. See [more details](/ensuro-docs/smart-contracts/policy.md#junior-and-senior-cost-of-capital). |
| maxPayoutPerPolicy | uint256 (amount) | The maximum payout that's allowed as payout for each individual policy of this risk module.                                                                                                           |
| exposureLimit      | uint256 (amount) | The limit on the cumulative exposure of all the active policies of this module.                                                                                                                       |
| maxDuration        | uint256(hours)   | The maximum duration of the policies (in hours).                                                                                                                                                      |

### Packed parameters

To save gas, the parameters are stored in a packed struct that fits in 256bits (a *word* in the EVM). This is not visible externally, but put's limits on the precision of the parameters. The *wad* ones, have 4 decimals as precision, so 1.12345 will be truncated to 1.1234. *maxPayoutPerPolicy* has a precision of two decimals, and *exposureLimit* 0 decimals.

## Internal methods

### \_newPolicy

```solidity
function _newPolicy(uint256 payout, uint256 premium, uint256 lossProb, uint40 expiration, address payer, address onBehalfOf, uint96 internalId) internal returns (struct Policy.PolicyData)
```

Called from child contracts to create policies (after they validated the pricing)

| Name       | Type    | Description                                                                       |
| ---------- | ------- | --------------------------------------------------------------------------------- |
| payout     | uint256 | The exposure (maximum payout) of the policy                                       |
| premium    | uint256 | The premium that will be paid by the policyHolder                                 |
| lossProb   | uint256 | The probability of having to pay the maximum payout (wad)                         |
| expiration | uint40  | The expiration of the policy (timestamp)                                          |
| payer      | address | The account that pays for the premium                                             |
| onBehalfOf | address | The policy holder                                                                 |
| internalId | uint96  | An id that's unique within this module and it will be used to identify the policy |

## External Methods

### releaseExposure

```solidity
function releaseExposure(uint256 payout) external
```

Called when a policy expires or is resolved to update the exposure.

Requirements:

* Must be called by `policyPool()`

| Name   | Type    | Description                                 |
| ------ | ------- | ------------------------------------------- |
| payout | uint256 | The exposure (maximum payout) of the policy |

### Setting parameters

Usually, **LEVEL1\_ROLE, LEVEL2\_ROLE** or **LEVEL3\_ROLE** is requested for performing operations that change numerical parameters of the components. Both global and component role are accepted. If the user has **LEVEL3\_ROLE** the changes might be restricted to small tweaks.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ensuro.co/ensuro-docs/smart-contracts/contracts/riskmodule.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
