# SignedQuoteRiskModule

This is an implementation of the RiskModule that relays fully on trusted accounts to price and resolve the policies. The pricing of the policy is done off-chain and provided as a cryptographically signed quote. This signature has to be later provided by the user creating the policy.

## **Roles**

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

<table><thead><tr><th>Role</th><th width="92" data-type="checkbox">Global*</th><th width="157">Description</th><th>Methods Accessible</th></tr></thead><tbody><tr><td>RESOLVER_ROLE</td><td>false</td><td>Resolves policies.</td><td><ul><li><a href="#resolvepolicy">resolvePolicy</a>: Resolves a policy.</li><li><a href="#resolvepolicyfullpayout">resolvePolicyFullPayout</a>: Resolves a policy with full payout.</li></ul></td></tr><tr><td>POLICY_CREATOR_ROLE</td><td>false</td><td>Creates new policies.</td><td><ul><li><a href="#newpolicy">newPolicy</a>:  Creates a policy.</li><li><a href="#newpolicyfull">newPolicyFull</a>: Creates a new policy.</li><li><a href="#newpolicypaidbyholder">newPolicyPaidByHolder</a>: Creates a new policy.</li></ul></td></tr><tr><td>PRICER_ROLE</td><td>false</td><td>Prices policies</td><td><ul><li><a href="#newpolicy">newPolicy</a>:  Creates a policy.</li><li><a href="#newpolicyfull">newPolicyFull</a>: Creates a new policy.</li><li><a href="#newpolicypaidbyholder">newPolicyPaidByHolder</a>: Creates a new policy.</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.

#### Note on risk module roles

The PRICER\_ROLE is normally granted to a Service EOA (i.e., an account used by a service as opposed to a human user) that produces signed quotes for a risk partner. Given that these are services exposed to the internet, they may require regular or emergency private key rotation for security reasons.

Usually, the role admin for the PRICER\_ROLE is globally changed from the DEFAULT\_ADMIN\_ROLE to a specific PRICER\_ROLE\_ADMIN role that's granted to an operational Multisig with no timelocks, or to a timelock with a lower delay.

The same applies to the role admin for RESOLVER\_ROLE and POLICY\_CREATOR\_ROL.

## External Methods

### newPolicy

```solidity
function newPolicy(uint256 payout, uint256 premium, uint256 lossProb, uint40 expiration, address onBehalfOf, bytes32 policyData, bytes32 quoteSignatureR, bytes32 quoteSignatureVS, uint40 quoteValidUntil) external returns (uint256)
```

Creates a new Policy using a signed quote. The caller is the payer of the policy.

Requirements:

* The caller approved the spending of the premium to the PolicyPool
* The quote has been signed by an address with the component role PRICER\_ROLE

Emits:

* {PolicyPool.NewPolicy}
* {NewSignedPolicy}

| Name             | Type    | Description                                                                              |
| ---------------- | ------- | ---------------------------------------------------------------------------------------- |
| payout           | uint256 | The exposure (maximum payout) of the policy                                              |
| premium          | uint256 | The premium that will be paid by the payer                                               |
| 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                                                                        |
| policyData       | bytes32 | A hash of the private details of the policy. The last 96 bits will be used as internalId |
| quoteSignatureR  | bytes32 | The signature of the quote. R component (EIP-2098 signature)                             |
| quoteSignatureVS | bytes32 | The signature of the quote. VS component (EIP-2098 signature)                            |
| quoteValidUntil  | uint40  | The expiration of the quote                                                              |

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

### newPolicyFull

```solidity
function newPolicyFull(uint256 payout, uint256 premium, uint256 lossProb, uint40 expiration, address onBehalfOf, bytes32 policyData, bytes32 quoteSignatureR, bytes32 quoteSignatureVS, uint40 quoteValidUntil) external returns (struct Policy.PolicyData createdPolicy)
```

Creates a new Policy using a signed quote. The caller is the payer of the policy. Returns all the struct, not just the id.

Requirements:

* The caller approved the spending of the premium to the PolicyPool
* The quote has been signed by an address with the component role PRICER\_ROLE

Emits:

* {PolicyPool.NewPolicy}
* {NewSignedPolicy}

| Name             | Type    | Description                                                                              |
| ---------------- | ------- | ---------------------------------------------------------------------------------------- |
| payout           | uint256 | The exposure (maximum payout) of the policy                                              |
| premium          | uint256 | The premium that will be paid by the payer                                               |
| 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                                                                        |
| policyData       | bytes32 | A hash of the private details of the policy. The last 96 bits will be used as internalId |
| quoteSignatureR  | bytes32 | The signature of the quote. R component (EIP-2098 signature)                             |
| quoteSignatureVS | bytes32 | The signature of the quote. VS component (EIP-2098 signature)                            |
| quoteValidUntil  | uint40  | The expiration of the quote                                                              |

| Name          | Type                     | Description                |
| ------------- | ------------------------ | -------------------------- |
| createdPolicy | struct Policy.PolicyData | Returns the created policy |

### newPolicyPaidByHolder

```solidity
function newPolicyPaidByHolder(uint256 payout, uint256 premium, uint256 lossProb, uint40 expiration, address onBehalfOf, bytes32 policyData, bytes32 quoteSignatureR, bytes32 quoteSignatureVS, uint40 quoteValidUntil) external returns (uint256)
```

Creates a new Policy using a signed quote. The payer is the policy holder

Requirements:

* currency().allowance(onBehalfOf, \_msgSender()) > 0
* The quote has been signed by an address with the component role PRICER\_ROLE

Emits:

* {PolicyPool.NewPolicy}
* {NewSignedPolicy}

| Name             | Type    | Description                                                                              |
| ---------------- | ------- | ---------------------------------------------------------------------------------------- |
| payout           | uint256 | The exposure (maximum payout) of the policy                                              |
| premium          | uint256 | The premium that will be paid by the payer                                               |
| 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                                                                        |
| policyData       | bytes32 | A hash of the private details of the policy. The last 96 bits will be used as internalId |
| quoteSignatureR  | bytes32 | The signature of the quote. R component (EIP-2098 signature)                             |
| quoteSignatureVS | bytes32 | The signature of the quote. VS component (EIP-2098 signature)                            |
| quoteValidUntil  | uint40  | The expiration of the quote                                                              |

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

### resolvePolicy

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

### resolvePolicyFullPayout

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


---

# 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/signedquoteriskmodule.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.
