> 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/interfaces/ilm_pc_staking_v1.sol.md).

# ILM\_PC\_Staking\_v1.sol

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

### Functions

#### getStakingToken

Returns address of the token users can stake.

```solidity
function getStakingToken() external view returns (address);
```

**Returns**

| Name     | Type      | Description               |
| -------- | --------- | ------------------------- |
| `<none>` | `address` | The address of the token. |

#### getTotalSupply

Returns the total supply of staked tokens of this contract.

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

**Returns**

| Name     | Type      | Description                        |
| -------- | --------- | ---------------------------------- |
| `<none>` | `uint256` | The total supply of staked tokens. |

#### getRewardRate

Returns how much Tokens will be distributed per second to all users that staked in this contract.

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

**Returns**

| Name     | Type      | Description      |
| -------- | --------- | ---------------- |
| `<none>` | `uint256` | The reward rate. |

#### getRewardsEnd

Returns when the rewards will not be distributed anymore.

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

**Returns**

| Name     | Type      | Description                                 |
| -------- | --------- | ------------------------------------------- |
| `<none>` | `uint256` | The timestamp of when the rewards will end. |

#### getBalance

Returns the amount of tokens a user staked in this contract.

```solidity
function getBalance(address user) external view returns (uint);
```

**Parameters**

| Name   | Type      | Description                        |
| ------ | --------- | ---------------------------------- |
| `user` | `address` | The address of a user that staked. |

#### getEarned

Returns the amount of tokens earned up until now by the current stake of a user.

```solidity
function getEarned(address user) external view returns (uint);
```

**Parameters**

| Name   | Type      | Description                        |
| ------ | --------- | ---------------------------------- |
| `user` | `address` | The address of a user that staked. |

**Returns**

| Name     | Type      | Description                  |
| -------- | --------- | ---------------------------- |
| `<none>` | `uint256` | The amount of tokens earned. |

#### getEstimatedReward

Returns a estimation of how much rewards will be earned with the current state of the staking contract.

*This calculation uses the current reward rate and the current totalSupply to calculate the rewards.*

*the estimated result could be 0 if the estimated rewards are not high enough.*

```solidity
function getEstimatedReward(uint amount, uint duration)
    external
    view
    returns (uint);
```

**Parameters**

| Name       | Type      | Description                         |
| ---------- | --------- | ----------------------------------- |
| `amount`   | `uint256` | How much token are staked.          |
| `duration` | `uint256` | How long the tokens will be staked. |

**Returns**

| Name     | Type      | Description                            |
| -------- | --------- | -------------------------------------- |
| `<none>` | `uint256` | The estimated amount of tokens earned. |

#### getRewardValue

Returns the reward value.

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

**Returns**

| Name     | Type      | Description       |
| -------- | --------- | ----------------- |
| `<none>` | `uint256` | The reward value. |

#### getLastUpdate

Returns the timestamp of last state change.

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

**Returns**

| Name     | Type      | Description                         |
| -------- | --------- | ----------------------------------- |
| `<none>` | `uint256` | The timestamp of last state change. |

#### 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.*

*Fee on transfer tokens are currently not supported.*

```solidity
function stake(uint amount) external;
```

**Parameters**

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

#### unstake

Unstake a specified amount of tokens and collect rewards.

*Reaps the rewards collected up to this point for the msg.Sender().*

*Fee on transfer tokens are currently not supported.*

```solidity
function unstake(uint amount) external;
```

**Parameters**

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

#### claimRewards

Collects the rewards that are earned up until now.

*Reaps the rewards collected up to this point for the msg.Sender().*

```solidity
function claimRewards() external;
```

#### setRewards

Sets the rewards that are to be distributed.

*Equally distributes the reward amount over the given time period.*

```solidity
function setRewards(uint amount, uint duration) external;
```

**Parameters**

| Name       | Type      | Description                                         |
| ---------- | --------- | --------------------------------------------------- |
| `amount`   | `uint256` | How much token should be distributed.               |
| `duration` | `uint256` | How much time it will take to distribute the token. |

### Events

#### RewardSet

Event emitted when a reward is added.

```solidity
event RewardSet(
    uint rewardAmount, uint duration, uint newRewardRate, uint newRewardsEnd
);
```

**Parameters**

| Name            | Type      | Description                                     |
| --------------- | --------- | ----------------------------------------------- |
| `rewardAmount`  | `uint256` | The amount of tokens to distribute.             |
| `duration`      | `uint256` | The duration of the reward period.              |
| `newRewardRate` | `uint256` | The new reward rate.                            |
| `newRewardsEnd` | `uint256` | The new timestamp of when the rewards will end. |

#### Staked

Event emitted when a user stakes an amount.

```solidity
event Staked(address indexed user, uint amount);
```

**Parameters**

| Name     | Type      | Description                  |
| -------- | --------- | ---------------------------- |
| `user`   | `address` | The address of the user.     |
| `amount` | `uint256` | The amount of tokens staked. |

#### Unstaked

Event emitted when a user unstakes an amount.

```solidity
event Unstaked(address indexed user, uint amount);
```

**Parameters**

| Name     | Type      | Description                    |
| -------- | --------- | ------------------------------ |
| `user`   | `address` | The address of the user.       |
| `amount` | `uint256` | The amount of tokens unstaked. |

#### RewardsDistributed

Event emitted when a user receives Rewards.

```solidity
event RewardsDistributed(address indexed user, uint amount);
```

**Parameters**

| Name     | Type      | Description                  |
| -------- | --------- | ---------------------------- |
| `user`   | `address` | The address of the user.     |
| `amount` | `uint256` | The amount of tokens earned. |

#### Updated

Event emitted for each major change of state.

```solidity
event Updated(
    address indexed triggerAddress,
    uint rewardValue,
    uint lastUpdate,
    uint earnedRewards
);
```

**Parameters**

| Name             | Type      | Description                                                                          |
| ---------------- | --------- | ------------------------------------------------------------------------------------ |
| `triggerAddress` | `address` | Address of user if state change was triggered by a staking action. Else can be zero. |
| `rewardValue`    | `uint256` | Variable necessary to calculate how much rewards a staker is eligible for.           |
| `lastUpdate`     | `uint256` | Timestamp of last state change.                                                      |
| `earnedRewards`  | `uint256` | How much a user earned up to point of state change.                                  |

#### StakingTokenSet

Event emitted when staking token is set.

```solidity
event StakingTokenSet(address indexed token);
```

**Parameters**

| Name    | Type      | Description                          |
| ------- | --------- | ------------------------------------ |
| `token` | `address` | Address of token that can be staked. |

### Errors

#### Module\_\_LM\_PC\_Staking\_v1\_\_InvalidStakingToken

Given staking token address is invalid.

```solidity
error Module__LM_PC_Staking_v1__InvalidStakingToken();
```

#### Module\_\_LM\_PC\_Staking\_v1\_\_InvalidDuration

Given Duration is invalid.

```solidity
error Module__LM_PC_Staking_v1__InvalidDuration();
```

#### Module\_\_LM\_PC\_Staking\_v1\_\_InvalidRewardRate

The calculated Reward rate is too low to be used.

```solidity
error Module__LM_PC_Staking_v1__InvalidRewardRate();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.inverter.network/contracts/technical-reference/modules/logic-module/interfaces/ilm_pc_staking_v1.sol.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.
