# xWin Locked Stake

### xWinLockedStake

#### UserInfo

```solidity
struct UserInfo {
  uint256 shares;
  uint256 amount;
  uint256 lockedShares;
  uint256 rewardDebt;
  uint256 startTimestamp;
  uint256 endPeriodTimestamp;
  uint256 xWinFavor;
}
```

#### token

```solidity
contract IERC20Upgradeable token
```

#### masterChef

```solidity
contract xWinMasterChef masterChef
```

#### userInfo

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

#### totalShares

```solidity
uint256 totalShares
```

#### lastHarvestedTime

```solidity
uint256 lastHarvestedTime
```

#### totalLockedShares

```solidity
uint256 totalLockedShares
```

#### accXWINperLockedShare

```solidity
uint256 accXWINperLockedShare
```

#### treasury

```solidity
address treasury
```

#### lockedRewardsVault

```solidity
uint256 lockedRewardsVault
```

#### performanceFee

```solidity
uint256 performanceFee
```

#### callFee

```solidity
uint256 callFee
```

#### blocksPerDay

```solidity
uint256 blocksPerDay
```

#### xwinpid

```solidity
uint256 xwinpid
```

#### lockpid

```solidity
uint256 lockpid
```

#### Deposit

```solidity
event Deposit(address sender, uint256 amount, uint256 shares)
```

#### Withdraw

```solidity
event Withdraw(address sender, uint256 amount, uint256 shares)
```

#### Harvest

```solidity
event Harvest(address sender, uint256 performanceFee, uint256 callFee)
```

#### initialize

```solidity
function initialize(contract IERC20Upgradeable _token, address _masterChef, address _treasury, uint256 _xwinpid, uint256 _lockpid) external
```

#### masterChefDeposit

```solidity
function masterChefDeposit() external
```

#### deposit

```solidity
function deposit(uint256 _amount, uint8 _duration) external
```

Deposit into locked staking farm If locked position already exists, this function acts to deposit more and extend locking period

**Parameters**

| Name       | Type    | Description                      |
| ---------- | ------- | -------------------------------- |
| \_amount   | uint256 | Amount of xWin Tokens to deposit |
| \_duration | uint8   | Duration to lock                 |

#### harvest

```solidity
function harvest() public
```

Re-invest rewards for compounding rewards

#### \_harvest

```solidity
function _harvest() internal
```

#### harvestLockBonus

```solidity
function harvestLockBonus() internal
```

Collect locking bonus

#### withdraw

```solidity
function withdraw() external
```

Withdraws everything from user

#### \_earn

```solidity
function _earn() internal
```

Reinvest reward tokens into MasterChef to compound staking rewards

#### setTreasury

```solidity
function setTreasury(address _treasury) external
```

Sets treasury address

*Only callable by the contract owner.*

#### setFees

```solidity
function setFees(uint256 _callFee, uint256 _performanceFee) external
```

Sets call fee and performance fee

*Only callable by the contract admin.*

#### setBlocksPerDay

```solidity
function setBlocksPerDay(uint256 _blocksPerDay) external
```

#### migrateMasterChef

```solidity
function migrateMasterChef(address _newMasterChef, uint256 _xwinpid, uint256 _lockpid) external
```

#### calculateHarvestCakeRewards

```solidity
function calculateHarvestCakeRewards() external view returns (uint256)
```

Calculates the expected harvest reward from third party

**Return Values**

| Name | Type    | Description                        |
| ---- | ------- | ---------------------------------- |
| \[0] | uint256 | Expected reward to collect in CAKE |

#### calculateTotalPendingCakeRewards

```solidity
function calculateTotalPendingCakeRewards() external view returns (uint256)
```

Calculates the total pending rewards that can be restaked

**Return Values**

| Name | Type    | Description                        |
| ---- | ------- | ---------------------------------- |
| \[0] | uint256 | Returns total pending cake rewards |

#### \_doWithdraw

```solidity
function _doWithdraw(struct xWinLockedStake.UserInfo user) internal returns (uint256)
```

withdraws the user's entire position from both lock bonus and staking

#### getPricePerFullShare

```solidity
function getPricePerFullShare() external view returns (uint256)
```

Calculates the price per share

#### available

```solidity
function available() public view returns (uint256)
```

Custom logic for how much the vault allows to be borrowed

*The contract puts all of the tokens except for lockedRewards to work.*

#### getFavor

```solidity
function getFavor(address _user) external view returns (uint256)
```

#### totalXWINBalance

```solidity
function totalXWINBalance() public view returns (uint256)
```

Calculates the total underlying tokens

*It includes tokens held by the contract and held in MasterChef*

#### shareMultiplier

```solidity
function shareMultiplier(uint256 amount, uint8 period) public pure returns (uint256)
```

#### getUserPosition

```solidity
function getUserPosition(address _user) public view returns (uint256 rewardAmount, uint256 xwinAmount)
```

Views a user's current position

**Parameters**

| Name   | Type    | Description     |
| ------ | ------- | --------------- |
| \_user | address | Address of user |

**Return Values**

| Name         | Type    | Description                           |
| ------------ | ------- | ------------------------------------- |
| rewardAmount | uint256 | xWin Token amount from locking reward |
| xwinAmount   | uint256 | xWin Tokens amount from staking       |

#### convertWeeksToTimestamp

```solidity
function convertWeeksToTimestamp(uint256 w) internal pure returns (uint256)
```

#### getUserCompoundAPYrate

```solidity
function getUserCompoundAPYrate(address _user) external view returns (uint256 estimatedDailyRate)
```

Returns user's daily reward rate

#### getUserLockingBonusAPR

```solidity
function getUserLockingBonusAPR(address _user) external view returns (uint256 apr)
```

Gets the user's rate from lock duration bonus

#### getEstimatedDepositAPY

```solidity
function getEstimatedDepositAPY(uint256 _amount, uint8 _duration) external view returns (uint256 estimatedDailyRate, uint256 estimatedBonusApr)
```

Given an amount and duration, return the user's rate and bonus rate

**Parameters**

| Name       | Type    | Description            |
| ---------- | ------- | ---------------------- |
| \_amount   | uint256 | Amount to be deposited |
| \_duration | uint8   | Duration to be locked  |
