> For the complete documentation index, see [llms.txt](https://docs.ethervista.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ethervista.app/hardstake-and-hardlock.md).

# Hardstake and Hardlock

## Introduction

To safely manage LPs and prevent exploits within the Euler model, the Ethervista Router introduces three key functions: `updateSelf`, `safeTransferLp`, and **`hardstake`**.

### safeTransferLp

```solidity
function safeTransferLp(address _token, address to, uint256 _amount) public override
```

This function ensures secure transfer of LP tokens:

* Updates the `msg.sender`'s provider struct in the pair contract when transferring LP tokens
* Prevents liquidity providers from manipulating their reward share through balance duplication
* **Requires all LP transfers to go through the router**

### hardstake

```solidity
function hardstake(address _contract, address _token,  uint256 _amount) public override 
```

Enables staking/locking of any ERC20 and LP tokens in compliance with the Euler model:

#### Process:

1. Transfers tokens to a contract implementing the external function:

   ```solidity
   stake(uint256 amount, address staker, address token)
   ```
2. Verifies if the token is a VISTA-LP token
3. If verification passes, updates the `msg.sender`'s provider struct to reflect reduced balance and share
4. Calls the contract's custom stake implementation

#### Important Notes:

* `stake` ensures consistency between tokens/amounts passed to the external stake function and those transferred by the `hardstake` function
* Developers must restrict stake calls to this router for guaranteed token receipt verification (**router is a variable stored in the factory's contrac**t)
* Receivers (users/contracts) must call `updateSelf(address _pair)` to begin accruing rewards for received LP-tokens
  * This can be done directly inside the `stake` implementation
* Liquidity staking contracts must accurately allocate and distribute rewards to stakers based on their contributions
* Staking/locking contracts can use the Euler model to distribute rewards in paid in ETH. For example, Ethervista leverages the protocol fee alongside the Euler model to reward $VISTA stakers based on their share of the total staked amount. It also rewards liquidity providers who lock their liquidity for at least two weeks, ensuring more stable liquidity pools

## Templates

We provide two templates for staking:

1. Standard ERC-20 tokens (**Hardstake**). This template allows users to stake their tokens and earn ETH rewards from the protocol fee or other ETH contribution using the Euler model

{% embed url="<https://github.com/Ethervista/HARDSTAKE/blob/main/hardstakeTemplate.sol>" %}

2. LP tokens (**Hardlock**) : This is a specialized case of Hardstake for LP tokens that ensures proper allocation and distribution of rewards to liquidity stakers based on their contributions to the pair contract. This contract maintains its own Euler sequence, which is based on the liquidity fees accrued by the pair contract

{% embed url="<https://github.com/Ethervista/HARDSTAKE/blob/main/hardstakeLpTemplate.sol>" %}

**Note**: In these template contracts, staking or unstaking actions will reset the lock time. Additionally, staking or unstaking will reset the rewards balance to zero. Therefore, users are advised to claim any accumulated rewards *before* performing these actions to avoid losing unclaimed earnings.
