LIS Formulas
This is a simple worked out example for calculating user rewards, donations to NGOs, and withdrawals.
Last updated
This is a simple worked out example for calculating user rewards, donations to NGOs, and withdrawals.
Last updated
amount - amount that user want to stake
totalShares - all shares of the users combined
totalAssets - total staked balance
currentBalance - current balance from LIDO
muldiv - function that do multiply and after that divide
stakeInfo.percent - percent that users gives to Ngo
shares[user][id] - shares user(his amount converted to shares)
Eg: Suppose a user stakes 5 ETH with a share of 50% set for donation.
Values we know
stakedInfo = 5 ETH
currentBalance = 0 ETH (assume the the user is the first ever to stake)
totalShares = 0 shares (since it is the first user)
PERCENT_DIVIDER = 10000 (constant)
function stake()
User stakes 5 ETH
Since it is the first user,
= 5 * 10^18
= 5 * 10^18 - 0
= 5 * 10^18
= 5 * 10^18
= 5 * 10^18 -= 10^3 = 5 * 10^18 - 10^3 ≈ 4.999999999999999 * 10^18
≈ 4.999999999999999 * 10^18
≈ 5 * 10^18
= (5 * 10^18 * (5000))/1000 [50% is stored as 5000] = = 250 * 10^18 * 10^-3
User Rewards
= 4.999999999999999 * 10^18 . mulDiv (5 ETH, 4.999999999999999 * 10^18) ≈ 5 ETH
Rewards to NGO
=((((4.999999999999999 * 10^18 × 5 ETH) / 4.999999999999999 * 10^18 ) -5 ETH)×5000)​ / 10^3
≈ 0
Known Variables:
totalAssets: 0
stakedBalance: 5 (The total staked balance in the NGO)
totalShareToday: 250 * 10^18 * 10^-3 (The total share of the NGO for the day)
currentBalance = 5 ETH (The current balance in the contract)
PERCENT_DIVIDER: 10000 (constant)
LIS_FEE: 500 (constant)
Rewards:
= 5* 10^18- 5 *10^18 -0 = 0
NGO Share for the day:
= 0
LIS Fee:
= 0
Eg : Suppose we have the following initial conditions -> - User A has staked 5 ETH. - The total staked balance in the contract is 100 ETH. - User A has earned 2 ETH in rewards. - There are a total of 1000 shares in the contract. - The current balance in the Lido contract is 200 ETH.
Now, let's say User A wants to withdraw 3 ETH.
Retrieve User's Stake Information:
Retrieve Current Balance:
Check Stake Existence and User Balance:
User A has staked funds (stakeInfo.amount != 0)
User A's balance of 5 ETH is sufficient to withdraw 3 ETH.
Calculate Rewards:
Calculate Amount in Shares:
Update User Shares and total shares:
Both users' shares and total shares will be reduced by 15shares.
An approval of 3ETH is granted to the withdrawal contract and an event is emitted to signal that user has requested a withdrawal.