saddle-finance / saddle-frontend

An open source UI for saddle.finance 🤠
https://saddle.exchange
54 stars 58 forks source link

Fix boost math and decimal #1140

Closed nkrulikovsky closed 2 years ago

nkrulikovsky commented 2 years ago

What does this PR do?



- UserVeSdlBalance = 0
Then boost = (min(UserLiquidity*40/100, UserLiquidity) / (UserLiquidity*40/100) = 1.0

- UserVeSdlBalance = TotalVeSdlBalance
Then `TotalLiquidity*UserVeSdlBalance/TotalVeSdlBalance*(100-40)/100` will be `TotalLiquidity*(100-40)/100` .
numerator will be UserLiquidity.

So, boost = UserLiquidity/(UserLiquidity * 40 /100) = 2.5,  this is max value of the bost.

- veSDL for max boost
When `userLiquidity*40/100) + TotalLiquidity*UserVeSdlBalance/TotalVeSdlBalance*(100-40)/100` === `UserLiquidity`, user can have max boost under user's Liquidity.
In this case, `TotalLiquidity*UserVeSdlBalance/TotalVeSdlBalance` should be  `UserLiqudiity` for maxboost
So, `UserVeSdlBalance = (UserLiquidity / TotalLiquidity ) * TotalVeSdlBalance`. This is veSDL balance for max boost.

## Context

closes: https://github.com/saddle-finance/saddle-frontend/issues/1138
codecov[bot] commented 2 years ago

Codecov Report

Merging #1140 (7f5e260) into master (01dc63d) will decrease coverage by 0.02%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #1140      +/-   ##
==========================================
- Coverage   10.16%   10.13%   -0.03%     
==========================================
  Files         154      154              
  Lines        5570     5586      +16     
  Branches     1780     1785       +5     
==========================================
  Hits          566      566              
- Misses       5002     5018      +16     
  Partials        2        2              
Impacted Files Coverage Δ
src/hooks/useUserGauge.ts 0.00% <0.00%> (ø)
src/pages/Farm/StakeDialog.tsx 0.00% <0.00%> (ø)
src/pages/VeSDL/VeTokenCalculator.tsx 0.00% <0.00%> (ø)
src/utils/index.ts 46.63% <0.00%> (+0.22%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 01dc63d...7f5e260. Read the comment docs.