# TrustfulRiskModule

This is an implementation of the RiskModule that relays fully on trusted accounts to price and resolve the policies.

## **Roles**

The specific functions of the contract are as follows:

<table><thead><tr><th>Role</th><th width="99" data-type="checkbox">Global*</th><th>Description</th><th>Methods Accessible</th></tr></thead><tbody><tr><td>PRICER_ROLE</td><td>false</td><td>Creates new policies.</td><td><ul><li>newPolicy: Creates a new policy.</li><li>newPolicyFull: Creates a new policy with all its details and returns the created policy data.</li></ul></td></tr><tr><td>RESOLVER_ROLE</td><td>false</td><td>Resolves policies.</td><td><ul><li>resolvePolicy: Resolves a policy by executing the necessary actions within the contract.</li><li>resolvePolicyFullPayout: Resolves a policy with full payout.</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.

## External Methods

### newPolicy

```solidity
function newPolicy(uint256 payout, uint256 premium, uint256 lossProb, uint40 expiration, address onBehalfOf, uint96 internalId) external returns (uint256)
```

Creates a new Policy

Requirements:

* The caller has been granted componentRole(PRICER\_ROLE)

Emits:

* {PolicyPool.NewPolicy}

| 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)                                          |
| onBehalfOf | address | The policy holder                                                                 |
| internalId | uint96  | An id that's unique within this module and it will be used to identify the policy |

| Name | Type    | Description                          |
| ---- | ------- | ------------------------------------ |
| \[0] | uint256 | Returns the id of the created policy |

### resolvePolicy

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

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

Requirements:

* The caller has been granted componentRole(RESOLVER\_ROLE)
* payout <= policy.payout
* block.timestamp >= policy.expiration

Emits:

* {PolicyPool.PolicyResolved}

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

### resolvePolicyFullPayout

```solidity
function resolvePolicyFullPayout(struct Policy.PolicyData policy, bool customerWon) external
```

Resolves a policy with full payout (policy.payout) if customerWon == true

Requirements:

* The caller has been granted componentRole(RESOLVER\_ROLE)
* block.timestamp >= policy.expiration

Emits:

* {PolicyPool.PolicyResolved}

| Name        | Type                     | Description                                                                                                                              |
| ----------- | ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| policy      | struct Policy.PolicyData | The policy previously created (from {NewPolicy} event)                                                                                   |
| customerWon | bool                     | If true, policy.payout is transferred to the policy holder. If false, the policy is resolved without payout and can't be longer claimed. |


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
