> 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/signedbucketriskmodule.md).

# SignedBucketRiskModule

This RiskModule implementation supports a more flexible pricing scheme by setting arbitrary pricing buckets. It has a base set of parameters, similar to other riskmodules, but also allows different sets of parameters for each policy.

The pricing of the policy is done off-chain and provided as a [cryptographically signed quote](/ensuro-docs/offchain-apis/api-reference/dynamic-pricing-api.md). 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 width="187">Role</th><th width="102" data-type="checkbox">Global*</th><th width="203">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="#setbucketparams">setBucketParams</a>: Sets the parameters for a risk bucket.</li><li><a href="#deletebucket">deleteBucket</a>: Deletes a risk bucket.</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="#setbucketparams">setBucketParams</a>: Sets the parameters for a risk bucket.</li><li><a href="#deletebucket">deleteBucket</a>: Deletes a risk bucket.</li></ul></td></tr><tr><td>RESOLVER_ROLE</td><td>false</td><td>Resolves policies.</td><td><ul><li><a href="#resolvepolicy">resolvePolicy</a>: Resolves a policy.</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

**IMPORTANT**: See [Note on risk module roles](/ensuro-docs/smart-contracts/contracts/riskmodule/signedquoteriskmodule.md#note-on-risk-module-roles)

## External Methods

### newPolicy

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

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           |
| bucketId         | uint256 | Identifies the group to which the policy belongs (that defines the RM parameters applicable to it) |
| 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,
    uint256 bucketId,
    bytes32 quoteSignatureR,
    bytes32 quoteSignatureVS,
    uint40 quoteValidUntil
)
```

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           |
| bucketId         | uint256 | Identifies the group to which the policy belongs (that defines the RM parameters applicable to it) |
| 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,
    uint256 bucketId,
    bytes32 quoteSignatureR,
    bytes32 quoteSignatureVS,
    uint40 quoteValidUntil
)
```

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           |
| bucketId         | uint256 | Identifies the group to which the policy belongs (that defines the RM parameters applicable to it) |
| 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
```

Resolves a policy with a given payout. Requires RESOLVER\_ROLE.

### resolvePolicyFullPayout

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

### setBucketParams

```solidity
function setBucketParams(uint256 bucketId, struct Params params_)
```

Sets the parameters for a risk bucket.

| Name     | Type          | Description                                                                                                         |
| -------- | ------------- | ------------------------------------------------------------------------------------------------------------------- |
| bucketId | uint256       | The id of the pricing bucket to be set.                                                                             |
| params\_ | struct Params | The parameters of the new bucket. See [Parameters](/ensuro-docs/smart-contracts/contracts/riskmodule.md#parameters) |

### deleteBucket

Deletes a pricing bucket.

| Name     | Type    | Description                                 |
| -------- | ------- | ------------------------------------------- |
| bucketId | uint256 | The id of the pricing bucket to be deleted. |
