Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message from Florian Lebourneur - DO NOT MERGE THAT PR #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# How much is my lp worth?
Hi,
I do not know how to contact you, so I am creating this PR as a communication mean.
Thanks a lot for this project, given the MasterChef, it allows me to understand a lot on how the pools are handled.
I am trying to list all the MasterChef addresses, and therefore ask the community to add/update the following repo: How much is my LP worth?

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
=> what do you think of using the jsons provided as a input for you?

A tool to calculate your lp worth in the staking contract.

http://howmuchismylp.com/

# License

[MIT](https://github.com/npty/lp-inspector/blob/master/LICENSE)
regards
31 changes: 27 additions & 4 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export const PANCAKE_ROUTER = "0x05ff2b0db69458a0750badebc4f9e13add608c7f";
export const BNB = "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c";
export const BUSD = "0xe9e7cea3dedca5984780bafc599bd69add087d56";
export const USDT = "0x55d398326f99059ff775485246999027b3197955";
export const AUTO = "0x0895196562C7868C5Be92459FaE7f877ED450452";
export const ibBNB = "0xd7d069493685a581d27824fc46eda46b7efc0063";
export const ibBUSD = "0x7c9e73d4c71dae564d41f78d56439bb4ba87592f";
export const masterChefPresets = [
{
name: "-",
Expand Down Expand Up @@ -60,8 +63,24 @@ export const masterChefPresets = [
address: "0xc26316b19117495e89c187339ddb6e86f1e39f0c",
},
{
name: "ForkSwap",
address: "0xC46c1bcf592f94899DCDabCf9abb48436770a4f1",
name: "Viking",
address: "0xEf6e807fD2c0Ef5883A03Ed1b962333E8C9b725f",
},
{
name: "UFO",
address: "0x95d9a00087f0db9e72b4014017842336480a153b",
},
{
name: "TACO",
address: "0x36f44a1C8e973739D0034FF1B9B9f6c4c7085625",
},
{
name: "Alpaca",
address: "0xA625AB01B08ce023B2a342Dbb12a16f2C8489A8F",
},
{
name: "Sashimi",
address: "0x34E483600e9c73390C7fBB4C9985a057156a611F",
},
];

Expand All @@ -76,6 +95,10 @@ export const routerPresets = [
},
{
name: "Icecream",
address: "0x6728f3c8241c44cc741c9553ff7824ba9e932a4a"
}
address: "0x6728f3c8241c44cc741c9553ff7824ba9e932a4a",
},
{
name: "Sashimi",
address: "0x24cEFA86fC1826FD31b4cb911034907735F8085A",
},
];
86 changes: 62 additions & 24 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Web3 from "web3";
import { BalanceLP, BaseBalance, Balance } from "../types";
import BigNumber from "bignumber.js";
import { BUSD } from "./constants";
import { BNB, BUSD, ibBNB, ibBUSD, USDT } from "./constants";
import Exchange from "./exchange";
import { weiToEth } from "./unit";

const pair = require("../abis/pair.json");
const erc20 = require("../abis/erc20.json");

const stablecoins = [USDT, BUSD];

async function isLP(web3: Web3, lp: BaseBalance) {
const contractLP = new web3.eth.Contract(pair, lp.lpAddress);
try {
Expand Down Expand Up @@ -68,31 +70,62 @@ async function calculateBalanceLP(
const tokenBDecimals = await tokenBContract.methods.decimals().call();

let worth: string = "0";
if (tokenA !== BUSD && tokenB !== BUSD) {
if (
stablecoins.indexOf(tokenA) === -1 &&
stablecoins.indexOf(tokenB) === -1
) {
const exchange = new Exchange(routerContractAddress);
const busdAmount = await exchange.getEquivalentToken(
tokenA,
BUSD,
tokenAmountA.integerValue().toFixed()
);
const _worth = new BigNumber(2)
.multipliedBy(busdAmount)
.integerValue()
.toFixed();
worth = parseFloat(weiToEth(_worth)).toFixed(2);
if (tokenA === BNB || tokenB === BNB) {
const bnb = tokenA === BNB ? tokenA : tokenB;
const bnbAmount = tokenA === BNB ? tokenAmountA : tokenAmountB;
const busdAmount = await exchange.getEquivalentToken(
bnb,
BUSD,
bnbAmount.integerValue().toFixed()
);
const _worth = new BigNumber(2)
.multipliedBy(busdAmount)
.integerValue()
.toFixed();
worth = parseFloat(weiToEth(_worth)).toFixed(2);
} else {
const stablecoin = stablecoins.indexOf(tokenA) > -1 ? tokenA : tokenB;
const token = stablecoin === tokenA ? tokenB : tokenA;
const tokenAmount = token === tokenA ? tokenAmountA : tokenAmountB;
const busdAmount = await exchange.getEquivalentToken(
token,
stablecoin,
tokenAmount.integerValue().toFixed()
);
const _worth = new BigNumber(2)
.multipliedBy(busdAmount)
.integerValue()
.toFixed();
worth = parseFloat(weiToEth(_worth)).toFixed(2);
}
} else {
const busdAmount = tokenA === BUSD ? tokenAmountA : tokenAmountB;
const stablecoin = stablecoins.indexOf(tokenA) > -1 ? tokenA : tokenB;
const stablecoinAmount =
tokenA === stablecoin ? tokenAmountA : tokenAmountB;
const _worth = new BigNumber(2)
.multipliedBy(busdAmount)
.multipliedBy(stablecoinAmount)
.integerValue()
.toFixed();
worth = parseFloat(weiToEth(_worth)).toFixed(2);
}

return {
...lp,
tokenA: { name: tokenASymbol, amount: tokenAmountA, decimals: tokenADecimals },
tokenB: { name: tokenBSymbol, amount: tokenAmountB, decimals: tokenBDecimals },
tokenA: {
name: tokenASymbol,
amount: tokenAmountA,
decimals: tokenADecimals,
},
tokenB: {
name: tokenBSymbol,
amount: tokenAmountB,
decimals: tokenBDecimals,
},
worth,
};
}
Expand All @@ -110,24 +143,29 @@ async function calculateBalance(
const token = {
name: tokenSymbol,
amount: new BigNumber(tokenAmount),
decimals: tokenDecimals
decimals: tokenDecimals,
};

let worth = "0";

if (lp.lpAddress.toLowerCase() !== BUSD) {
const _tokenAddress =
lp.lpAddress.toLowerCase() === ibBNB ? BNB : lp.lpAddress.toLowerCase();

if ([BUSD, ibBUSD].indexOf(_tokenAddress) > -1) {
worth = parseFloat(weiToEth(lp.balance)).toFixed(2);
} else {
const exchange = new Exchange(routerContractAddress);
const [reserveA, reserveB] = await exchange.getReserves(lp.lpAddress, BUSD);
const busdAmount = new BigNumber(reserveA)
.div(reserveB)
const [reserveA, reserveB] = await exchange.getReserves(
_tokenAddress,
BUSD
);
const busdAmount = new BigNumber(reserveB)
.div(reserveA)
.multipliedBy(tokenAmount)
.integerValue()
.toFixed();
worth = parseFloat(weiToEth(busdAmount)).toFixed(2);
} else {
worth = parseFloat(weiToEth(lp.balance)).toFixed(2);
}

return {
...lp,
token,
Expand Down