Created
September 19, 2020 23:21
-
-
Save larrythecucumber321/ed88adfdcaa6e4b1aa85b7a077da5852 to your computer and use it in GitHub Desktop.
Get pJar Value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const totalPTokenSupply = await pickleJar.totalSupply(); | |
const userFraction = userPTokenBalance / totalPTokenSupply; | |
const tokensInPool = | |
(await token.balanceOf(pair.address)) / tokenDivisor; | |
const wethInPool = (await weth.balanceOf(pair.address)) / 1e18; | |
// balance of UNI tokens inside the jar | |
const balance = await pickleJar.balance(); | |
setLocked(balance); | |
// total UNI tokens | |
const totalSupply = (await pair.totalSupply()) / 1e18; | |
const fraction = balance / 1e18 / totalSupply; | |
// tokens in pair | |
const tokensLocked = fraction * tokensInPool; | |
const wethLocked = fraction * wethInPool; | |
const valueLocked = | |
tokensLocked * underlyingPrice + wethLocked * ethPrice; | |
console.log("TOTAL VALUE", valueLocked); | |
const lockedUserValue = valueLocked * userFraction; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment