# EeseeStaking

## EeseeStaking

### ESE

```solidity
contract IERC20 ESE
```

*ESE token to use in staking.*

### volumeUpdaters

```solidity
mapping(address => bool) volumeUpdaters
```

*Addresses that can update volume. It can be useful to us to have multiple volume updaters.*

### volume

```solidity
mapping(address => uint256) volume
```

*Volume for each user on Eesee marketplace.*

### userInfo

```solidity
mapping(bool => mapping(address => struct IEeseeStaking.UserInfo)) userInfo
```

*Maps isLocked bool to user to struct containing user data.*

### totalDeposits

```solidity
uint96 totalDeposits
```

*Total ESE staked in this contract (not including rewards).*

### duration

```solidity
uint32 duration
```

*Min locked staking duration.*

### rewardID

```solidity
uint32 rewardID
```

*The number of negative reward rate updates.*

### deposit

```solidity
function deposit(uint96 amount, uint32 lockDuration, uint32 expectedRewardID, bytes permit) external
```

*Stakes ESE tokens. If {lockDuration} == 0, the user can withdraw tokens anytime. Else, the user can withdraw their tokens after {duration} seconds.*

#### Parameters

| Name             | Type   | Description                                                                                                                                                                   |
| ---------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| amount           | uint96 | - Amount of ESE tokens to stake.                                                                                                                                              |
| lockDuration     | uint32 | - If lockDuration == 0, stakes tokens using Flexible scheme. If lockDuration == duration stakes tokens using Locked scheme.                                                   |
| expectedRewardID | uint32 | - Frontrunning protection for reward rates. If reward rates are negatively changed before the transaction execution, reverts it. Can be set to any value for Flexible scheme. |
| permit           | bytes  | - Abi-encoded ESE permit data containing approveAmount, deadline, v, r and s. Set to empty bytes to skip permit.                                                              |

### withdraw

```solidity
function withdraw(bool isLocked, uint96 amount, address recipient) external returns (uint96 ESEReceived)
```

*Withdraws staked ESE tokens, collects rewards and sends them to {recipient}. Pass 0 to {amount} to only receive rewards. In case reward rates are negatively changed during Locked staker's staking period, they are able to withdraw their funds.*

#### Parameters

| Name      | Type    | Description                                                                                                                   |
| --------- | ------- | ----------------------------------------------------------------------------------------------------------------------------- |
| isLocked  | bool    | - Set to true to withdraw from locked scheme. Can only be done if the stake has unlocked (block.timestamp < user.unlockTime). |
| amount    | uint96  | - Amount of ESE tokens to unstake.                                                                                            |
| recipient | address | - ESE receiver.                                                                                                               |

#### Return Values

| Name        | Type   | Description                  |
| ----------- | ------ | ---------------------------- |
| ESEReceived | uint96 | - Amount of ESE tokens sent. |

```
    Note: If there are not enough tokens in the contract, only part of pending tokens will be sent.     The other tokens will be available after the balance of this contract has increased. |
```

### addVolume

```solidity
function addVolume(uint96 _volume, address _address) external
```

\_Adds {\_volume} to an {*address}'es volume. Emits {AddVolume} event.*

#### Parameters

| Name                                                     | Type    | Description          |
| -------------------------------------------------------- | ------- | -------------------- |
| \_volume                                                 | uint96  | - Volume to add.     |
| \_address                                                | address | - Address to update. |
| Note: This function can only be called by volumeUpdater. |         |                      |

### updateRewardRates

```solidity
function updateRewardRates(uint64[] rewardRatesFlexible, uint64[] rewardRatesLocked) external
```

*Changes the reward rates for all staking schemes and tiers.*

#### Parameters

| Name                                                                 | Type      | Description                                            |
| -------------------------------------------------------------------- | --------- | ------------------------------------------------------ |
| rewardRatesFlexible                                                  | uint64\[] | - New reward per token per second for flexible scheme. |
| rewardRatesLocked                                                    | uint64\[] | - New reward per token per second for locked scheme.   |
| Note: This function rewardRatesLocked only be called by ADMIN\_ROLE. |           |                                                        |

### changeDuration

```solidity
function changeDuration(uint32 _duration) external
```

*Changes duration for locked staking. Emits {ChangeDuration} event.*

#### Parameters

| Name                                                   | Type   | Description     |
| ------------------------------------------------------ | ------ | --------------- |
| \_duration                                             | uint32 | - New duration. |
| Note: This function can only be called by ADMIN\_ROLE. |        |                 |

### grantVolumeUpdater

```solidity
function grantVolumeUpdater(address _address) external
```

\_Grants rights to update volume to {*address}. Emits {GrantVolumeUpdater} event.*

#### Parameters

| Name                                                   | Type    | Description          |
| ------------------------------------------------------ | ------- | -------------------- |
| \_address                                              | address | - New volumeUpdater. |
| Note: This function can only be called by ADMIN\_ROLE. |         |                      |

### revokeVolumeUpdater

```solidity
function revokeVolumeUpdater(address _address) external
```

\_Revokes rights to update volume from {*address}. Emits {RevokeVolumeUpdater} event.*

#### Parameters

| Name                                                   | Type    | Description                             |
| ------------------------------------------------------ | ------- | --------------------------------------- |
| \_address                                              | address | - Address to revoke volumeUpdater from. |
| Note: This function can only be called by ADMIN\_ROLE. |         |                                         |

### pendingReward

```solidity
function pendingReward(bool isLocked, address _user) external view returns (uint96)
```

\_Returns ESE tokens earned by {*user}. Note: Does not take unlockTime or current contract reward balance into account.*

#### Parameters

| Name     | Type    | Description         |
| -------- | ------- | ------------------- |
| isLocked | bool    |                     |
| \_user   | address | - Address to check. |

#### Return Values

| Name | Type   | Description                                          |
| ---- | ------ | ---------------------------------------------------- |
| \[0] | uint96 | uint96 - Amount of ESE tokens ready to be collected. |

### tierInfo

```solidity
function tierInfo(uint256 _tier) external view returns (struct IEeseeStaking._TierData _tierData)
```

*Returns the info on specified tier.*

#### Parameters

| Name   | Type    | Description             |
| ------ | ------- | ----------------------- |
| \_tier | uint256 | - Tier to get info for. |

#### Return Values

| Name       | Type                            | Description                                                                     |
| ---------- | ------------------------------- | ------------------------------------------------------------------------------- |
| \_tierData | struct IEeseeStaking.\_TierData | - uint256 volumeBreakpoint, uint64 rewardRateFlexible, uint64 rewardRateLocked. |

### tier

```solidity
function tier(uint256 _volume) public view returns (uint256)
```

*Returns the tier from volume.*

#### Parameters

| Name     | Type    | Description                 |
| -------- | ------- | --------------------------- |
| \_volume | uint256 | - Volume to check tier for. |

#### Return Values

| Name | Type    | Description        |
| ---- | ------- | ------------------ |
| \[0] | uint256 | uint256 - Tier ID. |

## Inherited from EeseeRoleHandler

## Inherited from ERC2771Context

### isTrustedForwarder

```solidity
function isTrustedForwarder(address forwarder) public view virtual returns (bool)
```

## Inherited from IEeseeStaking

### ESE

```solidity
function ESE() external view returns (contract IERC20)
```

### volumeUpdaters

```solidity
function volumeUpdaters(address) external view returns (bool)
```

### volume

```solidity
function volume(address) external view returns (uint256)
```

### userInfo

```solidity
function userInfo(bool isLocked, address user) external view returns (uint96 amount, uint96 reward, uint32 unlockTime, uint32 rewardRateID, uint256 rewardDebt)
```

### totalDeposits

```solidity
function totalDeposits() external view returns (uint96)
```

### duration

```solidity
function duration() external view returns (uint32)
```

### DepositFlexible

```solidity
event DepositFlexible(address user, uint96 amount)
```

### DepositLocked

```solidity
event DepositLocked(address user, uint96 amount, uint32 unlockTime)
```

### WithdrawFlexible

```solidity
event WithdrawFlexible(address sender, address recipient, uint96 amount)
```

### WithdrawLocked

```solidity
event WithdrawLocked(address sender, address recipient, uint96 amount)
```

### AddVolume

```solidity
event AddVolume(address volumeUpdater, address user, uint96 amount)
```

### UpdateRewardRates

```solidity
event UpdateRewardRates(uint64[] rewardRatesFlexible, uint64[] rewardRatesLocked)
```

### ChangeDuration

```solidity
event ChangeDuration(uint32 previousDuration, uint32 newDuration)
```

### GrantVolumeUpdater

```solidity
event GrantVolumeUpdater(address account)
```

### RevokeVolumeUpdater

```solidity
event RevokeVolumeUpdater(address account)
```
