> For the complete documentation index, see [llms.txt](https://docs.inverter.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.inverter.network/contracts/technical-reference/modules/logic-module/lm_pc_bounties_v1.sol.md).

# LM\_PC\_Bounties\_v1.sol

[Git Source](https://github.com/InverterNetwork/inverter-contracts/blob/649b450f02fc8b735c128ff0821467e71966c666/src/modules/logicModule/LM_PC_Bounties_v1.sol)

**Inherits:** ILM\_PC\_Bounties\_v1, ERC20PaymentClientBase\_v1

**Author:** Inverter Network

Provides functionality to manage bounties and process claims, allowing participants to propose, update, and claim bounties securely and transparently.

*Extends {ERC20PaymentClientBase\_v1} to integrate payment processing with bounty management, supporting dynamic additions, updates, and the locking of bounties. Utilizes roles for managing permissions and maintaining robust control over bounty operations.*

### State Variables

#### \_SENTINEL

*Marks the beginning of the list.*

```solidity
uint internal constant _SENTINEL = type(uint).max;
```

#### BOUNTY\_ISSUER\_ROLE

*Role for the bounty issuer.*

```solidity
bytes32 public constant BOUNTY_ISSUER_ROLE = "BOUNTY_ISSUER";
```

#### CLAIMANT\_ROLE

*Role for the claimant.*

```solidity
bytes32 public constant CLAIMANT_ROLE = "CLAIMANT";
```

#### VERIFIER\_ROLE

*Role for the verifier.*

```solidity
bytes32 public constant VERIFIER_ROLE = "VERIFIER";
```

#### \_nextId

*Value for what the next id will be.*

```solidity
uint private _nextId;
```

#### \_bountyRegistry

*Registry mapping ids to Bounty structs id => Bounty.*

```solidity
mapping(uint => Bounty) private _bountyRegistry;
```

#### \_bountyList

*List of Bounty id's.*

```solidity
LinkedIdList.List _bountyList;
```

#### \_claimRegistry

*Registry mapping ids to Claim struct id => Claim.*

```solidity
mapping(uint => Claim) private _claimRegistry;
```

#### \_claimList

*List of Claim id's.*

```solidity
LinkedIdList.List _claimList;
```

#### contributorAddressToClaimIds

*Connects contributor addresses to claim Ids contributor address => claim ids.*

```solidity
mapping(address => EnumerableSet.UintSet) contributorAddressToClaimIds;
```

#### \_\_gap

*Storage gap for future upgrades.*

```solidity
uint[50] private __gap;
```

### Modifiers

#### supportsInterface

*See {IERC165-supportsInterface}.*

```solidity
function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC20PaymentClientBase_v1)
    returns (bool);
```

#### onlyClaimContributor

*Checks if the sender is a contributor of the given claimId.*

```solidity
modifier onlyClaimContributor(uint claimId);
```

**Parameters**

| Name      | Type      | Description                   |
| --------- | --------- | ----------------------------- |
| `claimId` | `uint256` | The id of the claim to check. |

#### validPayoutAmounts

*Checks if the payout amounts are valid.*

```solidity
modifier validPayoutAmounts(uint minimumPayoutAmount, uint maximumPayoutAmount);
```

**Parameters**

| Name                  | Type      | Description                |
| --------------------- | --------- | -------------------------- |
| `minimumPayoutAmount` | `uint256` | The minimum payout amount. |
| `maximumPayoutAmount` | `uint256` | The maximum payout amount. |

#### validArrayLengths

*Checks if the array lengths are valid*

```solidity
modifier validArrayLengths(
    uint minimumPayoutAmountLength,
    uint maximumPayoutAmountLength,
    uint detailArrayLength
);
```

**Parameters**

| Name                        | Type      | Description                      |
| --------------------------- | --------- | -------------------------------- |
| `minimumPayoutAmountLength` | `uint256` | The minimum payout amount length |
| `maximumPayoutAmountLength` | `uint256` | The maximum payout amount length |
| `detailArrayLength`         | `uint256` | The detail array length          |

#### validBountyId

*Checks if the bountyId is valid.*

```solidity
modifier validBountyId(uint bountyId);
```

**Parameters**

| Name       | Type      | Description                    |
| ---------- | --------- | ------------------------------ |
| `bountyId` | `uint256` | The id of the bounty to check. |

#### validClaimId

*Checks if the claimId is valid.*

```solidity
modifier validClaimId(uint claimId);
```

**Parameters**

| Name      | Type      | Description                   |
| --------- | --------- | ----------------------------- |
| `claimId` | `uint256` | The id of the claim to check. |

#### notLocked

*Checks if the bounty is not locked.*

```solidity
modifier notLocked(uint bountyId);
```

**Parameters**

| Name       | Type      | Description                    |
| ---------- | --------- | ------------------------------ |
| `bountyId` | `uint256` | The id of the bounty to check. |

#### notClaimed

*Checks if the claim is not claimed.*

```solidity
modifier notClaimed(uint claimId);
```

**Parameters**

| Name      | Type      | Description                   |
| --------- | --------- | ----------------------------- |
| `claimId` | `uint256` | The id of the claim to check. |

#### \_contributorsNotChanged

*Checks if the contributors have not changed.*

```solidity
function _contributorsNotChanged(
    uint claimId,
    Contributor[] memory contributors
) internal view;
```

**Parameters**

| Name           | Type            | Description                    |
| -------------- | --------------- | ------------------------------ |
| `claimId`      | `uint256`       | The id of the claim to check.  |
| `contributors` | `Contributor[]` | The new contributors to check. |

### Public Functions

#### init

```solidity
function init(
    IOrchestrator_v1 orchestrator_,
    Metadata memory metadata,
    bytes memory
) external override(Module_v1) initializer;
```

#### getBountyInformation

Returns the Bounty instance with id `id`.

```solidity
function getBountyInformation(uint bountyId)
    external
    view
    validBountyId(bountyId)
    returns (Bounty memory);
```

**Parameters**

| Name       | Type      | Description                     |
| ---------- | --------- | ------------------------------- |
| `bountyId` | `uint256` | The id of the Bounty to return. |

**Returns**

| Name     | Type     | Description          |
| -------- | -------- | -------------------- |
| `<none>` | `Bounty` | Bounty with id `id`. |

#### listBountyIds

Returns total list of Bounty ids.

*List is in ascending order.*

```solidity
function listBountyIds() external view returns (uint[] memory);
```

**Returns**

| Name     | Type        | Description         |
| -------- | ----------- | ------------------- |
| `<none>` | `uint256[]` | List of Bounty ids. |

#### isExistingBountyId

Returns whether Bounty with id `id` exists.

```solidity
function isExistingBountyId(uint bountyId) public view returns (bool);
```

**Parameters**

| Name       | Type      | Description                   |
| ---------- | --------- | ----------------------------- |
| `bountyId` | `uint256` | The id of the Bounty to test. |

**Returns**

| Name     | Type   | Description                                         |
| -------- | ------ | --------------------------------------------------- |
| `<none>` | `bool` | True if Claim with id `id` exists, false otherwise. |

#### getClaimInformation

Returns the Claim instance with id `id`.

```solidity
function getClaimInformation(uint claimId)
    external
    view
    validClaimId(claimId)
    returns (Claim memory);
```

**Parameters**

| Name      | Type      | Description                    |
| --------- | --------- | ------------------------------ |
| `claimId` | `uint256` | The id of the Claim to return. |

**Returns**

| Name     | Type    | Description         |
| -------- | ------- | ------------------- |
| `<none>` | `Claim` | Claim with id `id`. |

#### listClaimIds

Returns total list of Claim ids.

*List is in ascending order.*

```solidity
function listClaimIds() external view returns (uint[] memory);
```

**Returns**

| Name     | Type        | Description        |
| -------- | ----------- | ------------------ |
| `<none>` | `uint256[]` | List of Claim ids. |

#### isExistingClaimId

Returns whether Claim with id `id` exists.

```solidity
function isExistingClaimId(uint claimId) public view returns (bool);
```

**Parameters**

| Name      | Type      | Description                   |
| --------- | --------- | ----------------------------- |
| `claimId` | `uint256` | The id of the Bounty to test. |

**Returns**

| Name     | Type   | Description                                         |
| -------- | ------ | --------------------------------------------------- |
| `<none>` | `bool` | True if Claim with id `id` exists, false otherwise. |

#### listClaimIdsForContributorAddress

Returns a list of Claim ids in which contributor Address is used.

*List is in ascending order.*

```solidity
function listClaimIdsForContributorAddress(address contributorAddrs)
    external
    view
    returns (uint[] memory);
```

**Parameters**

| Name               | Type      | Description                                        |
| ------------------ | --------- | -------------------------------------------------- |
| `contributorAddrs` | `address` | claim ids are filtered by the contributor address. |

**Returns**

| Name     | Type        | Description        |
| -------- | ----------- | ------------------ |
| `<none>` | `uint256[]` | List of Claim ids. |

#### addBounty

Adds a new Bounty.

*Reverts if an argument invalid.*

```solidity
function addBounty(
    uint minimumPayoutAmount,
    uint maximumPayoutAmount,
    bytes calldata details
)
    external
    onlyModuleRole(BOUNTY_ISSUER_ROLE)
    validPayoutAmounts(minimumPayoutAmount, maximumPayoutAmount)
    returns (uint id);
```

**Parameters**

| Name                  | Type      | Description                                                              |
| --------------------- | --------- | ------------------------------------------------------------------------ |
| `minimumPayoutAmount` | `uint256` | The minimum amount of tokens the Bounty will pay out upon being claimed. |
| `maximumPayoutAmount` | `uint256` | The maximum amount of tokens the Bounty will pay out upon being claimed. |
| `details`             | `bytes`   | The Bounty's details.                                                    |

**Returns**

| Name | Type      | Description                |
| ---- | --------- | -------------------------- |
| `id` | `uint256` | The newly added Bounty id. |

#### addBountyBatch

Adds a new array of Bounties.

*Reverts if an argument invalid.*

```solidity
function addBountyBatch(
    uint[] calldata minimumPayoutAmounts,
    uint[] calldata maximumPayoutAmounts,
    bytes[] calldata detailArray
)
    external
    onlyModuleRole(BOUNTY_ISSUER_ROLE)
    validArrayLengths(
        minimumPayoutAmounts.length,
        maximumPayoutAmounts.length,
        detailArray.length
    )
    returns (uint[] memory ids);
```

**Parameters**

| Name                   | Type        | Description                                                                      |
| ---------------------- | ----------- | -------------------------------------------------------------------------------- |
| `minimumPayoutAmounts` | `uint256[]` | The array of minimum amount of tokens the Bounty will pay out upon being claimed |
| `maximumPayoutAmounts` | `uint256[]` | The array of maximum amount of tokens the Bounty will pay out upon being claimed |
| `detailArray`          | `bytes[]`   | The array of Bounty's details.                                                   |

**Returns**

| Name  | Type        | Description                          |
| ----- | ----------- | ------------------------------------ |
| `ids` | `uint256[]` | The newly added array of Bounty ids. |

#### updateBounty

Updates a Bounty's informations.

*Reverts if an argument invalid.*

```solidity
function updateBounty(uint bountyId, bytes calldata details)
    external
    onlyModuleRole(BOUNTY_ISSUER_ROLE)
    validBountyId(bountyId)
    notLocked(bountyId);
```

**Parameters**

| Name       | Type      | Description                                |
| ---------- | --------- | ------------------------------------------ |
| `bountyId` | `uint256` | The id of the Bounty that will be updated. |
| `details`  | `bytes`   | The Bounty's details.                      |

#### lockBounty

Locks the Bounty so it cant be claimed.

*Only callable by authorized addresses.*

```solidity
function lockBounty(uint bountyId)
    external
    onlyModuleRole(BOUNTY_ISSUER_ROLE)
    validBountyId(bountyId)
    notLocked(bountyId);
```

**Parameters**

| Name       | Type      | Description                               |
| ---------- | --------- | ----------------------------------------- |
| `bountyId` | `uint256` | The id of the Bounty that will be locked. |

#### addClaim

Adds a new Claim.

*Reverts if an argument invalid.*

```solidity
function addClaim(
    uint bountyId,
    Contributor[] calldata contributors,
    bytes calldata details
)
    external
    onlyModuleRole(CLAIMANT_ROLE)
    validBountyId(bountyId)
    notLocked(bountyId)
    returns (uint id);
```

**Parameters**

| Name           | Type            | Description                                 |
| -------------- | --------------- | ------------------------------------------- |
| `bountyId`     | `uint256`       | The id of the bounty this claim belongs to. |
| `contributors` | `Contributor[]` | The contributor information for the Claim.  |
| `details`      | `bytes`         | The Claim's details.                        |

**Returns**

| Name | Type      | Description                 |
| ---- | --------- | --------------------------- |
| `id` | `uint256` | The newly added Claim's id. |

#### updateClaimContributors

Updates a Claim's contributor informations.

*Reverts if an argument invalid.*

```solidity
function updateClaimContributors(
    uint claimId,
    Contributor[] calldata contributors
)
    external
    validClaimId(claimId)
    notClaimed(claimId)
    notLocked(_claimRegistry[claimId].bountyId)
    onlyModuleRole(CLAIMANT_ROLE);
```

**Parameters**

| Name           | Type            | Description                                |
| -------------- | --------------- | ------------------------------------------ |
| `claimId`      | `uint256`       | The id of the Claim that will be updated.  |
| `contributors` | `Contributor[]` | The contributor information for the Claim. |

#### updateClaimDetails

Updates a Claim Details.

```solidity
function updateClaimDetails(uint claimId, bytes calldata details)
    external
    validClaimId(claimId)
    notClaimed(claimId)
    notLocked(_claimRegistry[claimId].bountyId)
    onlyClaimContributor(claimId);
```

**Parameters**

| Name      | Type      | Description                               |
| --------- | --------- | ----------------------------------------- |
| `claimId` | `uint256` | The id of the Claim that will be updated. |
| `details` | `bytes`   | The Claim's details.                      |

#### verifyClaim

Completes a Bounty by verifying a claim.

*Only callable by authorized addresses.*

```solidity
function verifyClaim(uint claimId, Contributor[] calldata contributors)
    external
    onlyModuleRole(VERIFIER_ROLE)
    validClaimId(claimId)
    notClaimed(claimId)
    notLocked(_claimRegistry[claimId].bountyId);
```

**Parameters**

| Name           | Type            | Description                                         |
| -------------- | --------------- | --------------------------------------------------- |
| `claimId`      | `uint256`       | The id of the Claim that wants to claim the Bounty. |
| `contributors` | `Contributor[]` | The contributor information for the Claim.          |

### Internal Functions

#### \_validPayoutAmounts

*Internal function to check if the payout amounts are valid*

```solidity
function _validPayoutAmounts(uint minimumPayoutAmount, uint maximumPayoutAmount)
    internal
    pure;
```

**Parameters**

| Name                  | Type      | Description               |
| --------------------- | --------- | ------------------------- |
| `minimumPayoutAmount` | `uint256` | The minimum payout amount |
| `maximumPayoutAmount` | `uint256` | The maximum payout amount |

#### \_validContributorsForBounty

*Checks if the contributors are valid for the given bounty.*

```solidity
function _validContributorsForBounty(
    Contributor[] memory contributors,
    Bounty memory bounty
) internal view;
```

**Parameters**

| Name           | Type            | Description                |
| -------------- | --------------- | -------------------------- |
| `contributors` | `Contributor[]` | The contributors to check. |
| `bounty`       | `Bounty`        | The bounty to check.       |

#### \_addBounty

*Internal function to add a bounty*

```solidity
function _addBounty(
    uint minimumPayoutAmount,
    uint maximumPayoutAmount,
    bytes calldata details
) internal returns (uint bountyId);
```

**Parameters**

| Name                  | Type      | Description               |
| --------------------- | --------- | ------------------------- |
| `minimumPayoutAmount` | `uint256` | The minimum payout amount |
| `maximumPayoutAmount` | `uint256` | The maximum payout amount |
| `details`             | `bytes`   | The details of the bounty |

**Returns**

| Name       | Type      | Description          |
| ---------- | --------- | -------------------- |
| `bountyId` | `uint256` | The id of the bounty |
