> For the complete documentation index, see [llms.txt](https://betfin.gitbook.io/betfin-public/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://betfin.gitbook.io/betfin-public/smartcontracts-description/conservative-staking.md).

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

<mark style="color:$warning;">Note: New participation is handled through the Liquidity Pool (V2). Existing users can continue to claim rewards and withdraw principal once their original window expires.</mark>

### Features <a href="#features" id="features"></a>

* **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 <a href="#contract-structure" id="contract-structure"></a>

<table><thead><tr><th width="218">Element</th><th>Description</th></tr></thead><tbody><tr><td><strong>Variables</strong></td><td>- Stores contract state such as pools, staked amounts, profits, and roles.</td></tr><tr><td><strong>Events</strong></td><td>- Signals significant actions in the contract like pool openings/closings, staking, claiming, etc.</td></tr><tr><td><strong>Public Functions</strong></td><td>- Functions accessible to all users for actions like staking, claiming, and viewing contract data.</td></tr><tr><td><strong>External Functions</strong></td><td>- Functions callable from other contracts, mainly for administrative purposes.</td></tr><tr><td><strong>Internal Functions</strong></td><td>- Utility functions for internal contract management, not accessible externally.</td></tr></tbody></table>

### Functions <a href="#functions" id="functions"></a>

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

<table><thead><tr><th width="302">Function name</th><th>Description</th></tr></thead><tbody><tr><td><code>getStaked(address staker)</code></td><td>Returns the amount staked by a specific user.</td></tr><tr><td><code>totalClaimed()</code></td><td>Returns the total amount of tokens claimed by all users</td></tr><tr><td><code>totalStaked()</code></td><td>Returns the total amount of tokens staked in the contract</td></tr><tr><td><code>totalProfit()</code></td><td>Returns the total profit generated by the contract</td></tr><tr><td><code>totalStakers()</code></td><td>Returns the total number of users who have staked tokens</td></tr><tr><td><code>getActivePoolCount()</code>, <code>getStakedPoolsCount(address staker)</code>, <code>getProfit(address staker)</code>, <code>getClaimable(address staker)</code></td><td>Provide detailed information about pools and profits.</td></tr></tbody></table>
{% endtab %}

{% tab title="User functions" %}

<table><thead><tr><th width="281">Function name</th><th>Description</th></tr></thead><tbody><tr><td><code>stake(address staker, uint256 amount)</code></td><td>Allows a user to stake a specified amount of tokens.</td></tr><tr><td><code>claim(address pool)</code>, <code>claimAll()</code></td><td> Allows users to claim profits from specific or all pools.</td></tr><tr><td><code>withdraw(address pool)</code></td><td>Allows users to withdraw their staked amount from a specific pool.</td></tr></tbody></table>
{% endtab %}

{% tab title="Administrative functions" %}

<table><thead><tr><th width="250">Function name</th><th>Description</th></tr></thead><tbody><tr><td><code>setCalculatingWindow(uint256 _window)</code></td><td>Adjusts the calculation window for profit distribution</td></tr><tr><td><code>setMinAllowedAmount(uint256 _amount)</code></td><td>Sets the minimum amount of tokens that can be staked.</td></tr><tr><td><code>newPool()</code></td><td>Manually triggers the creation of a new staking pool.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

<mark style="color:blue;">The</mark> <mark style="color:blue;"></mark><mark style="color:blue;">`ConservativeStaking`</mark> <mark style="color:blue;"></mark><mark style="color:blue;">contract provides a comprehensive solution for staking mechanisms, emphasizing security with its non-reentrancy guard and flexibility through dynamic pool management</mark>
