> For the complete documentation index, see [llms.txt](https://docs.javsphere.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.javsphere.com/engineering/smart-contracts/javfreezer.md).

# JavFreezer

### General Description

The `JavFreezer` contract facilitates user deposits, rewards distribution, and freeze mechanisms in a DeFi ecosystem. It supports multiple pools, different lock periods for freeze, and rewards tied to the amount of time a user locks their tokens. Additionally, users can claim rewards or withdraw tokens based on the freeze period they choose.

### Key Features:

* **Pools and Fees:**
  * Pools represent different staking options, each with a base token (e.g., a freeze  token) and a reward token.
  * Fees are applied during deposits and withdrawals.
* **Rewards Distribution:**
  * The contract includes mechanisms for distributing rewards over time, updating reward information, and handling pending rewards.
* **Lock Periods and Multipliers:**
  * Users can choose to lock tokens for different periods (e.g., months), each with different multipliers affecting rewards.
* **Vesting Mechanism:**
  * There is support for special "vesting" deposits where tokens can be locked and withdrawn after certain conditions.

### Contract State Variables

#### Core Pool Structures:

1. **PoolInfo\[]** `poolInfo`: Stores details for each pool, such as:
   * Base and reward tokens.
   * Accumulated rewards per share.
   * Total shares in the pool.
2. **PoolFee\[]** `poolFee`: Defines fee structures for each pool, including deposit, withdraw, and claim fees.
3. **mapping(uint256 => mapping(address => UserInfo))** `userInfo`: Tracks user-specific freezer information such as shares and reward debts.
4. **mapping(uint256 => mapping(address => UseDeposit\[]))** `userDeposits`: Tracks user-specific freezer deposit information such as amount, stake period  and witdraw timestampo.
5. **mapping(address => TokenPrecisionInfo)** `tokensPrecision`: Holds precision configurations for base and reward tokens.

### Core Functionalities

* **Pool Management:**
  * **addPool**: Adds a new pool by specifying the base and reward tokens, the reward configuration, and associated fees.
  * **setPoolInfo**: Updates pool reward configuration.
  * **setPoolFee**: Allows changing the fee configuration for a specific pool.
* **Reward Configuration and Claims:**
  * **setRewardConfiguration**: Admin function to configure reward rates.
  * **addRewards**: Used by the rewards distributor to add rewards to the system.
  * **claimAll**: A user function that allows claiming rewards for all their deposits in a given pool.
  * **claim**: Claims rewards for a specific deposit.
* **Staking and Withdrawal:**
  * **deposit**: Allows a user to deposit tokens into a specific pool, locked for a given period.
  * **withdrawVesting**: Allows the vesting contract to withdraw tokens on behalf of users who have locked them in a pool.
  * **withdraw**: Allows users to withdraw tokens from their deposit (after fulfilling lock period requirements).
* **Migration** (<mark style="color:red;">will be deleted after base migration</mark>)
  * **makeMigration**: Migrates user deposits from migration contract, enabling assets to be transferred to this contract.
* **Rewards and APR Calculations:**
  * **pendingReward**: Returns the pending reward for a specific deposit.
  * **apr**: Returns the Annual Percentage Rate (APR) for a given pool and lock period.
