Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save larrythecucumber321/ed88adfdcaa6e4b1aa85b7a077da5852 to your computer and use it in GitHub Desktop.
Save larrythecucumber321/ed88adfdcaa6e4b1aa85b7a077da5852 to your computer and use it in GitHub Desktop.
Get pJar Value
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