# Automatic Staking Optimization

The target of the delegation strategy is to provide the best yield for the stakers while making NEAR more decentralized and censorship-resistant.

When the users stake $NEAR on LiNEAR Protocol, the automatic staking optimization determines which validators to be selected and how many $NEAR should be staked ideally.

**Eligibility rules to receive stake from LiNEAR protocol.**

* Validator is in the active set ;
* Validator's APY > 6% ;\
  APY = (1 + ROI) ^ (1 year / epoch\_length) - 1
* Validator's commission fee ≤ 10 % ;
* Satisfy the above three conditions for 10 consecutive epochs.

**We evaluate all the active validators and calculate the score by a variety of metrics.**

Score=CS\*(1-C / 100)\*(1-10R)

[![](https://lh3.googleusercontent.com/EybY48jz_5pw_LDz3U9GyRE5uBj2P-B7mppbwDC4HbIglY0JJzCqZsGlEzbSEc_oxRVt1n6skyHYFQhKs_0IzVn8A1t2XG6BRt5rI1WdD0qpdFoBeqK5AGNnsg9dglCDZUh5T6kkXs917t6N2Etkyo0)](https://www.codecogs.com/eqnedit.php?latex=CS%20%3D%20min\(%5Cfrac%7B100%7D%7B%5Csqrt%7B1-RL%2FRA%7D%7D%2C%205000\)#0)

* RL: The validator’s average ROI in the past 10 epochs
* RA: LiNEAR’s ROI  in the past 50 epochs
* C: Commission fee
* R: The validator’s staked amount / Total active validators staked amount<br>

**Target staked amount of a given validator**=Total $NEAR staked \* Score / Sum(Scores)

**Delta** = Current staked amount - Target staked amount&#x20;

*<mark style="background-color:blue;">**When staking**</mark><mark style="background-color:blue;">,</mark>* the validator with the minimum Delta is selected first until Delta=0, and then the second minimum validator is selected until all the requested $NEAR staking are satisfied.

<mark style="background-color:orange;">**When unstaking**</mark><mark style="background-color:orange;">:</mark>

* The validator which will be selected is the one with the minimum Delta of all the validators under the condition of Delta>Unstake amount;
* If there is no validator that meets the condition above, the validator with the maximum delta/target ratio is selected first and unstake the $NEAR amount no more than max(Target/2, Delta), and then the second maximum validator is selected until all the requested $NEAR unstaking are satisfied.

<br>
