# VStaker

VStaker allows users to stake their LP Tokens and their VRSW tokens, and calculates rewards that accrue to users according to their stakes.

A single VStaker instance can exist per VirtuSwap deployment on a network.

### Events

#### event StakeVrsw

```solidity
event StakeVrsw(
    address who, 
    uint256 amount);
```

Emitted when someone stakes VRSW

#### event StakeLp

```solidity
event StakeLp(
    address who, 
    address lpToken,
    uint256 amount);
```

Emitted when someone stakes an LP token of a VirtuSwap Pool

#### event RewardsClaimed

```solidity
event RewardsClaimed(
    address who, 
    address lpToken,
    uint256 amount);
```

Emitted when rewards on a pool are claimed

#### event UnstakeVrsw

```solidity
event UnstakeVrsw(
    address who, 
    uint256 amount);
```

Emitted when someone unstakes VRSW tokens

#### event UnstakeLp

```solidity
event UnstakeLp(
    address who,
    address lpToken, 
    uint256 amount);
```

Emitted when someone unstakes LP tokens

#### event LockVrsw

```solidity
event LockVrsw(
    address who, 
    uint256 amount,
    uint256 lockDuration);
```

Emitted when someone locks VRSW tokens for lockDuration seconds

#### event LockStakedVrsw

```solidity
event LockStakedVrsw(
    address who, 
    uint256 amount,
    uint256 lockDuration);
```

Emitted when someone locks staked VRSW tokens for lockDuration seconds

#### event UnlockVrsw

```solidity
event UnlockVrsw(
    address who, 
    uint256 amount);
```

Emitted when someone unlocks VRSW tokens

### State-Changing Functions

#### function stakeVrsw

```solidity
function stakeVrsw(uint256 amount) external;
```

Stakes VRSW tokens into the Staker. The caller receives the same amount of veVRSW tokens.

Emits [StakeVrsw](#event-stakervrsw) event

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount</td><td><code>uint256</code></td><td>Amount to stake</td></tr></tbody></table>

#### function stakeLp

```solidity
function stakeLP(address lpToken, uint256 amount) external;
```

Stakes LP tokens into the Staker

Emits [StakeLp](#event-stakelp) event

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>lpToken</td><td><code>address</code></td><td>Address of the LP token being staked</td></tr><tr><td>amount</td><td><code>uint256</code></td><td>Amount to stake</td></tr></tbody></table>

#### function unstakeVrsw

```solidity
function stakeVrsw(uint256 amount) external;
```

Unstakes VRSW tokens from the Staker, burning the same amount of veVRSW. Caller must have staked at least the `amount` previously

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount</td><td><code>uint256</code></td><td>Amount to stake</td></tr></tbody></table>

#### function unstakeLp

```solidity
function unstakeLP(address lpToken, uint256 amount) external;
```

Unstakes LP tokens from the staker. Caller must have staked at least the `amount` previously

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>lpToken</td><td><code>address</code></td><td>Address of the LP token being unstaked</td></tr><tr><td>amount</td><td><code>uint256</code></td><td>Amount to stake</td></tr></tbody></table>

#### function lockVrsw

```solidity
function lockVrsw(uint256 amount, uint256 lockDuration) external;
```

Allows the user to lock VRSW tokens in the contract for a specified duration of time.

Locking Vrsw tokens boosts the protocol rewards for the locker.

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount</td><td><code>uint256</code></td><td>Amount to stake</td></tr><tr><td>lockDuration</td><td><code>uint256</code></td><td>lock duration in seconds</td></tr></tbody></table>

#### function lockStakedVrsw

```solidity
function lockStakedVrsw(uint256 amount, uint256 lockDuration) external;
```

Allows the user to lock staked VRSW tokens in the contract for a specified duration of time.

Locking staked VRSW tokens boosts the protocol rewards for the locker.

Parameters:

<table><thead><tr><th width="270">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>amount</td><td><code>uint256</code></td><td>Amount to stake</td></tr><tr><td>lockDuration</td><td><code>uint256</code></td><td>lock duration in seconds</td></tr></tbody></table>

#### function claimRewards

```solidity
function claimRewards(
    address lpToken
) external override
```

Allows a user to claim their accrued VRSW rewards. The sender's accrued rewards are calculated according to the Tokenomics formulas. The rewards claimed are transferred to the user's address using the transferRewards function of the vMinter contract.

### Read-Only Functions

#### function checkLock

```solidity
function checkLock(
    address who
) external view returns (uint[] memory unlockedPositions);
```

Checks for any stake positions of a given users that are currently unlocked

Parameters:

<table><thead><tr><th width="126">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>who</td><td><code>address</code></td><td>Address of the wallet to check for</td></tr></tbody></table>

#### function viewRewards

```solidity
function viewRewards(
        address who,
        address lpToken) 
external view returns (uint256 rewards);
```

Returns the amount of VRSW rewards that a user has accrued in a given VirtuSwap pool, but not yet claimed

Parameters:

<table><thead><tr><th width="141">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>who</td><td><code>address</code></td><td>Address of the wallet to check for</td></tr><tr><td>lpToken</td><td><code>address</code></td><td>Address of the LP Token representing the pool</td></tr></tbody></table>

#### function viewVrswStakes

```solidity
function viewVrswStakes() 
    external view 
    returns (VrswStake[] memory stakes);
```

Returns an array of [VrswStake](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/structures#vrswstake) structures containing information about the caller's VRSW stakes

Parameters:

<table><thead><tr><th width="141">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>who</td><td><code>address</code></td><td>Address of the wallet to check for</td></tr></tbody></table>

#### function viewLpStakes

```solidity
function viewLpStakes() 
    external view 
    returns (LpStake[] memory stakes);
```

Returns an array of [LpStake](https://docs.virtuswap.io/virtuswap-documentation/technical-reference/smart-contracts-v1/structures#lpstake) structures containing information about the caller's LP Token stakes

Parameters:

<table><thead><tr><th width="141">Name</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>who</td><td><code>address</code></td><td>Address of the wallet to check for</td></tr></tbody></table>

#### function isLpTokenValid

```solidity
function isLpTokenValid(address lpToken) 
    external view returns (bool);
```

Checks if a given address represents a valid VirtuSwap pool LP token.
