# Conservative Staking

ConservativeStaking is a smart contract intended for staking purposes within a blockchain ecosystem. It integrates with other contracts such as `ConservativeStakingPool` and utilises [`Pass`](/smartcontracts-description/pass-contract.md) for additional functionalities. This contract is designed to offer a conservative staking mechanism, allowing users to stake tokens, claim profits, and participate in a structured reward distribution system.

These existing pools remain active until their scheduled end dates. To integrate with the new infrastructure, they utilize a `ConservativePoolWrapper` which ensures fees from PvP games are distributed proportionally between legacy stakers and new liquidity providers.

> **Note:** New participation is handled through the [Liquidity Pool (V2)](/smartcontracts-description/liquidity-pool-v2.md). Existing users can continue to claim rewards and withdraw principal once their original window expires.

## Features

* **Staking**: Users can stake tokens in different pools.
* **Profit Calculation and Distribution**: Calculates profit based on staked amounts and distributes it accordingly.
* **Claiming**: Users can claim their profits from individual pools or all at once.
* **Conservative Pool Management**: Supports opening new pools and closing existing ones based on specific conditions.

## Contract Structure

| Element                | Description                                                                                      |
| ---------------------- | ------------------------------------------------------------------------------------------------ |
| **Variables**          | Stores contract state such as pools, staked amounts, profits, and roles.                         |
| **Events**             | Signals significant actions in the contract like pool openings/closings, staking, claiming, etc. |
| **Public Functions**   | Functions accessible to all users for actions like staking, claiming, and viewing contract data. |
| **External Functions** | Functions callable from other contracts, mainly for administrative purposes.                     |
| **Internal Functions** | Utility functions for internal contract management, not accessible externally.                   |

## Functions

{% tabs %}
{% tab title="View Functions" %}

| Function name                                                                                                              | Description                                                |
| -------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| `getStaked(address staker)`                                                                                                | Returns the amount staked by a specific user.              |
| `totalClaimed()`                                                                                                           | Returns the total amount of tokens claimed by all users.   |
| `totalStaked()`                                                                                                            | Returns the total amount of tokens staked in the contract. |
| `totalProfit()`                                                                                                            | Returns the total profit generated by the contract.        |
| `totalStakers()`                                                                                                           | Returns the total number of users who have staked tokens.  |
| `getActivePoolCount()`, `getStakedPoolsCount(address staker)`, `getProfit(address staker)`, `getClaimable(address staker)` | Provide detailed information about pools and profits.      |
| {% endtab %}                                                                                                               |                                                            |

{% tab title="User functions" %}

| Function name                           | Description                                                        |
| --------------------------------------- | ------------------------------------------------------------------ |
| `stake(address staker, uint256 amount)` | Allows a user to stake a specified amount of tokens.               |
| `claim(address pool)`, `claimAll()`     | Allows users to claim profits from specific or all pools.          |
| `withdraw(address pool)`                | Allows users to withdraw their staked amount from a specific pool. |
| {% endtab %}                            |                                                                    |

{% tab title="Administrative functions" %}

| Function name                           | Description                                             |
| --------------------------------------- | ------------------------------------------------------- |
| `setCalculatingWindow(uint256 _window)` | Adjusts the calculation window for profit distribution. |
| `setMinAllowedAmount(uint256 _amount)`  | Sets the minimum amount of tokens that can be staked.   |
| `newPool()`                             | Manually triggers the creation of a new staking pool.   |
| {% endtab %}                            |                                                         |
| {% endtabs %}                           |                                                         |

The `ConservativeStaking` contract provides a comprehensive solution for staking mechanisms, emphasizing security with its non-reentrancy guard and flexibility through dynamic pool management.


---

# 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.celestium.digital/smartcontracts-description/conservative-staking.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.
