---
# System prepended metadata

title: SmartPool README.md

---

# SmartPool README.md

## Overview

This project includes:

* A [Web App UI for the Smart-Pool](https://github.com/SolanaSmartPool/TEST-basic-web-app) including:
  * Stake Sol
  * Liquid Unstake

* a [Backend Solana Program, the "Smart-Pool"](program) allowing users to stake SOL, to add stake-accounts to the pool and alod including a *Liquidity Pool* and with that the possibility "liquid Unstaking", meaning "selling" your staked-sol tokens (stSOL) and receive wSOL immediately. By using this functionality, users can skip the cool-down period and get their wSOL out of the staking-pool in a single step.

* a [CLI tool, called *smartpool*](smart-cli) allowing :
  * Basic Usage
    * `stake` Stakes SOL, get stSOL token in return
    * `sell` sell stSol toekn, get SOL in return
  * Advanced
    * `deposit-stake-account` Deposits an stake-account, get stSOL in return
    * `withdraw-stake-account` burn stSOL, withdraw an stake-account
  * Liquidity Providers
    * `add-liquidity` add liquidity (wSOL), get SmartLP
    * `remove-liquidity` (WIP) burn SmartLP, get wSOL & a stake-account

### Value Added

#### Helps users distribute stake between validators
* The web app UI simplifies stakinkg/unstaking for everyone

#### Provides liquid unstake 
* The backend solana program includes a liquidity pool holding wSOL and stSOL (smartpool staked-SOL tokens). The users can sell their stSOL in a liquid unstaking, receiving wSOL immediately instead of waiting days for the cool-down period. The liquidity pool creates the opportunity for advanced users to become liquidity providers, earning a fee while providing liquidity for the liquid unstake. 

#### Contributes to decentralization 
* This program helps decentralization by distributing users' stake to several validators.

#### Creates a Liquidity Pool
* This program includes a liquidity pool and the opportunity for liquidity providers to earn fees. The liquidity-pool is the wSOL/stSOL pool that provides liquid unstake (sell stSOL) to get wSOL in a single step.

## stSOL Tokens

When you stake you get **stSOL** tokens, for *staked SOL* tokens. The smartpool's stSOL tokens will increase in value on each epoch when staking rewards are distributed. You can hold or trade your stSOL, now your stake is liquid!

## Liquid Unstake

Users wanting to unstake skipping the 2 day cool-down period can do so in the *wSOL/stSOL Liquidity Pool*.

In the Liquidity Pool:
 * Users providing liquidity can earn fees on each sell
 * Users wanting to unstake without the cool-down period can do so for a fee.

The *wSOL/stSOL Liquidity Pool* is a one-sided Liquidity pool. Liquidity providers add only wSOL to the Liq-Pool. The Liq-Pool allows other users to SELL stSOL for wSOL at a discounted price. The discount represents how much users value skipping the 2 day cool-down period to receive their funds. The fee % is computed on a curve to incentivize liquidity providers when the wSOL side of the pool is low, i.e. if the liquidity is abundant, fee is 0.5%, if there is low liquidity the fee raises up to 5% 


## User stories:

![Storyboard](doc/img/smartpool_storyboard.png)

### Alice 

Alice wants to stake her SOL with low risk, and also help the community by promoting validator diversification. 

Alice uses the Smart-pool to stake 100 SOL.

Alice stakes. The smart pool redirects the stake to different validators according to validator performance and decentralization objectives. Alice receives stSOL tokens, representing her share of the smart-pool. She starts earning staking rewards on her stSOL. She has the possibility to liquid-unstake some stSOL, getting back wSOL and skipping the waiting period for a fee.

### Bob 

Bob already has deposited stake and now holds 10,000 stSOL earning rewards. 

Bob needs 1,000 SOL to use in an emergency. He can’t wait 2 days to get his SOL. 

Each stSol is now worth 1.10 SOl. Bob unstakes 930 stSOL and gets for 1,012.77 wSOL. The unstake includes an 1% fee for the liquidity providers, and Bob gets his funds  immediately. Bob gets wSOL in his account. Bob can use his SOL immediately.

### Eve

Eve is an advanced user with large SOL stake-accounts. Eve wants to stake her SOL with low risk, and also help the community by promoting validator diversification. 
Eve uses the Smart-pool to stake.

Eve now deposits some of her stake-accounts into the smart-pool using the command line. Eve receives stSOL tokens on each deposit, representing her share of the stake-pool.

She starts earning staking rewards on her stSOL. By holding stSOL she also has the possibility to sell some of her stSOL skipping the waiting period if the need arises, or she can trade her tokens in any solana market.

### Carol 

Carol is an investor. She wants to provide liquidity for the wSOL/stSOL pool, earning operation fees.
Carol uses the Smart-cli tool, to deposit 7,000 wSOL in the liquidity pool.
She is the first in the pool, so she gets 7,000 $SmartLP tokens.

Bob unstakes 930 stSOL for 1,012.77 wSOL. The unstake includes an 1% fee to get the SOL immediately. The Liq-Pool delivers 1,012.77 wSOL to Bob and acquires 930 stSOL from Bob valued 1023 SOL. The new value of the $Smart-LP is now 7,010.23 SOL.

Carol $Smart-LP holding value have increased, and now she owns some stSOL via the Liq-Pool. Carol can eventually withdraw all her liquidity retrieving wSOL and stSOL from the pool. 

## Under the hood

### What happens when Alice stakes 100 SOL ?

Alice's 100 SOL are stored in the *RESERVE* account. Alice gets x amount of stSOL tokens valued 100 SOL.

Periodically, the bot scans the *RESERVE* account. If there are funds pending to be staked, the funds are staked in the best validator available within the program's validators list according to performance and decentralization objectives.

The staking process can take several days.

### What happens when Carol adds 7000 wSOL into the liquidity pool ?

The program transfers Carol's 7000 wSOL into the wSOL leg of the Liquidity-Pool. Carol gets x amount of $Smart-LP tokens valued 7000 SOL.

### What happens when Bob liquid-unstakes 930 stSOL ?

The program transfers Bob's 930 wSOL into the stSOL leg of the Liquidity-Pool.

The program computes liquid-unstake fee according to remaining liquidity after Bob's unstake (with a program defined curve).

Bob receives wSOL for a value x = stSOL*stSOL_price - fee

In our example, if the stSOL_price is 1.10 and fee is 1%, Bob receives 1,012.77 wSOL for his 930 stSOL.

From the Liquidiy-Provider's fee of 9.3 stSOL, 2.55 stSOL is sent to the operator-fee account to cover operational costs (turning the crank on the bot)

At the end, Bob added 930 stSOL to the liq-pool (valued 1023 SOL) and gets 1012.77 wSOL from the liq-pool.
