> 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_kpirewarder_v1.sol.md).

# LM\_PC\_KPIRewarder\_v1.sol

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

**Inherits:** ILM\_PC\_KPIRewarder\_v1, LM\_PC\_Staking\_v1, OptimisticOracleIntegrator

**Author:** Inverter Network

Provides a mechanism for distributing rewards to stakers based on Key Performance Indicators (KPIs).

*Extends {LM\_PC\_Staking\_v1} and integrates with {OptimisticOracleIntegrator} to enable KPI-based reward distribution within the staking manager.*

### State Variables

#### KPICounter

*The number of KPIs created.*

```solidity
uint internal KPICounter;
```

#### registryOfKPIs

*Registry of KPIsid -> KPI.*

```solidity
mapping(uint => KPI) internal registryOfKPIs;
```

#### assertionConfig

*Registry of Assertion Configurations assertionId -> RewardRoundConfiguration.*

```solidity
mapping(bytes32 => RewardRoundConfiguration) internal assertionConfig;
```

#### assertionPending

*For locking certain utilities when there are assertions open.*

```solidity
bool internal assertionPending;
```

#### \_\_gap

*Storage gap for future upgrades.*

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

### Functions

#### supportsInterface

*See {IERC165-supportsInterface}.*

```solidity
function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(OptimisticOracleIntegrator, LM_PC_Staking_v1)
    returns (bool);
```

#### init

```solidity
function init(
    IOrchestrator_v1 orchestrator_,
    Metadata memory metadata,
    bytes memory configData
)
    external
    virtual
    override(LM_PC_Staking_v1, OptimisticOracleIntegrator)
    initializer;
```

#### getKPI

Returns the KPI with the given number.

```solidity
function getKPI(uint KPInum) external view returns (KPI memory);
```

**Parameters**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `KPInum` | `uint256` | The number of the KPI to return. |

**Returns**

| Name     | Type  | Description |
| -------- | ----- | ----------- |
| `<none>` | `KPI` | The KPI.    |

#### getAssertionConfig

Returns the Assertion Configuration for a given assertionId.

```solidity
function getAssertionConfig(bytes32 assertionId)
    external
    view
    returns (RewardRoundConfiguration memory);
```

**Parameters**

| Name          | Type      | Description                        |
| ------------- | --------- | ---------------------------------- |
| `assertionId` | `bytes32` | The id of the Assertion to return. |

**Returns**

| Name     | Type                       | Description                  |
| -------- | -------------------------- | ---------------------------- |
| `<none>` | `RewardRoundConfiguration` | The Assertion Configuration. |

#### getKPICounter

Returns the current KPI counter.

```solidity
function getKPICounter() external view returns (uint);
```

**Returns**

| Name     | Type      | Description      |
| -------- | --------- | ---------------- |
| `<none>` | `uint256` | The KPI counter. |

#### getAssertionPending

Returns the assertion pending flag.

```solidity
function getAssertionPending() external view returns (bool);
```

**Returns**

| Name     | Type   | Description                 |
| -------- | ------ | --------------------------- |
| `<none>` | `bool` | The assertion pending flag. |

#### postAssertion

Posts an assertion to the Optimistic Oracle, specifying the KPI to use and the asserted value.

*about the asserter address: any address can be set as asserter, it will be expected to pay for the bond on posting. The bond tokens can also be deposited in the Module and used to pay for itself, but ONLY if the bond token is different from the one being used for staking. If the asserter is set to 0, whomever calls postAssertion will be paying the bond.*

```solidity
function postAssertion(
    bytes32 dataId,
    uint assertedValue,
    address asserter,
    uint targetKPI
) public onlyModuleRole(ASSERTER_ROLE) returns (bytes32 assertionId);
```

**Parameters**

| Name            | Type      | Description                                                              |
| --------------- | --------- | ------------------------------------------------------------------------ |
| `dataId`        | `bytes32` | The dataId to be posted.                                                 |
| `assertedValue` | `uint256` | The target value that will be asserted and posted as data to the oracle. |
| `asserter`      | `address` | The address of the asserter.                                             |
| `targetKPI`     | `uint256` | The KPI to be used for distribution once the assertion confirms.         |

**Returns**

| Name          | Type      | Description                                        |
| ------------- | --------- | -------------------------------------------------- |
| `assertionId` | `bytes32` | The assertionId received for the posted assertion. |

#### depositFeeFunds

Deposits funds into the contract so it can pay for the oracle bond and fee itself.

*Top up funds to pay the optimistic oracle fee*

```solidity
function depositFeeFunds(uint amount)
    external
    onlyOrchestratorAdmin
    nonReentrant
    validAmount(amount);
```

**Parameters**

| Name     | Type      | Description            |
| -------- | --------- | ---------------------- |
| `amount` | `uint256` | The amount to deposit. |

#### createKPI

Creates a KPI for the Rewarder.

```solidity
function createKPI(
    bool _continuous,
    uint[] calldata _trancheValues,
    uint[] calldata _trancheRewards
) external onlyOrchestratorAdmin returns (uint);
```

**Parameters**

| Name              | Type        | Description                                                         |
| ----------------- | ----------- | ------------------------------------------------------------------- |
| `_continuous`     | `bool`      | Should the tranche rewards be distributed continuously or in steps. |
| `_trancheValues`  | `uint256[]` | The value at which the tranches end.                                |
| `_trancheRewards` | `uint256[]` | The rewards to be distributed at completion of each tranche.        |

**Returns**

| Name     | Type      | Description |
| -------- | --------- | ----------- |
| `<none>` | `uint256` | The KPI id. |

#### stake

Stake a specified amount of tokens to earn rewards.

*Should tokens already be staked, then the sending address will collect the rewards up until this point.*

```solidity
function stake(uint amount)
    external
    override
    nonReentrant
    validAmount(amount);
```

**Parameters**

| Name     | Type      | Description                      |
| -------- | --------- | -------------------------------- |
| `amount` | `uint256` | How much token should be staked. |

#### deleteStuckAssertion

Deletes a stuck assertion.

*This function is only callable by the Orchestrator Admin.*

```solidity
function deleteStuckAssertion(bytes32 assertionId)
    public
    onlyOrchestratorAdmin;
```

**Parameters**

| Name          | Type      | Description                        |
| ------------- | --------- | ---------------------------------- |
| `assertionId` | `bytes32` | The id of the assertion to delete. |

#### assertionResolvedCallback

Callback function that is called by Optimistic Oracle V3 when an assertion is resolved.

```solidity
function assertionResolvedCallback(bytes32 assertionId, bool assertedTruthfully)
    public
    override;
```

**Parameters**

| Name                 | Type      | Description                                            |
| -------------------- | --------- | ------------------------------------------------------ |
| `assertionId`        | `bytes32` | The identifier of the assertion that was resolved.     |
| `assertedTruthfully` | `bool`    | Whether the assertion was resolved as truthful or not. |

#### assertionDisputedCallback

Callback function that is called by Optimistic Oracle V3 when an assertion is disputed.

*This OptimisticOracleV3 callback function needs to be defined so the OOv3 doesn't revert when it tries*

```solidity
function assertionDisputedCallback(bytes32 assertionId) public override;
```

**Parameters**

| Name          | Type      | Description                                        |
| ------------- | --------- | -------------------------------------------------- |
| `assertionId` | `bytes32` | The identifier of the assertion that was disputed. |
