Skip to content

Commit

Permalink
Update yield farms
Browse files Browse the repository at this point in the history
add taco swap

Support Alpaca

Fix alpaca/wbnb value

Add sashimi

Add meercat

typo meerkat

Remove meerkat
  • Loading branch information
ripzery authored and npty committed Mar 16, 2021
1 parent 82225e1 commit 29b235c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 24 deletions.
25 changes: 25 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
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 mebBUSD = "0x7e0c621ea9f7afd5b86a50b0942eaee68b04a61c";
export const mebBNB = "0x639f18c72b6a017bdd209c161d1617c9481a1e4d";
export const masterChefPresets = [
{
name: "-",
Expand Down Expand Up @@ -63,6 +68,22 @@ export const masterChefPresets = [
name: "Viking",
address: "0xEf6e807fD2c0Ef5883A03Ed1b962333E8C9b725f",
},
{
name: "UFO",
address: "0x95d9a00087f0db9e72b4014017842336480a153b",
},
{
name: "TACO",
address: "0x36f44a1C8e973739D0034FF1B9B9f6c4c7085625",
},
{
name: "Alpaca",
address: "0xA625AB01B08ce023B2a342Dbb12a16f2C8489A8F",
},
{
name: "Sashimi",
address: "0x34E483600e9c73390C7fBB4C9985a057156a611F",
},
];

export const routerPresets = [
Expand All @@ -78,4 +99,8 @@ export const routerPresets = [
name: "Icecream",
address: "0x6728f3c8241c44cc741c9553ff7824ba9e932a4a",
},
{
name: "Sashimi",
address: "0x24cEFA86fC1826FD31b4cb911034907735F8085A",
},
];
88 changes: 64 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, mebBNB, mebBUSD, 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,31 @@ 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 =
[ibBNB, mebBNB].indexOf(lp.lpAddress.toLowerCase()) > -1
? BNB
: lp.lpAddress.toLowerCase();

if ([BUSD, ibBUSD, mebBUSD].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

0 comments on commit 29b235c

Please sign in to comment.