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

Add Dankswap & Yieldnyan #2

Open
wants to merge 6 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
30 changes: 26 additions & 4 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const PANCAKE_ROUTER = "0x05ff2b0db69458a0750badebc4f9e13add608c7f";
export const BNB = "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c";
export const BUSD = "0xe9e7cea3dedca5984780bafc599bd69add087d56";
export const AUTO = "0x0895196562C7868C5Be92459FaE7f877ED450452";
export const ibBNB = "0xd7d069493685a581d27824fc46eda46b7efc0063";
export const ibBUSD = "0x7c9e73d4c71dae564d41f78d56439bb4ba87592f";
export const masterChefPresets = [
{
name: "-",
Expand Down Expand Up @@ -60,8 +62,28 @@ 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: "YieldNyan",
address: "0xC885b97220ad6a8dfE4AC7aF7C7A4776c7A21f06",
},
{
name: "DankSwap",
address: "0x4923de3EE2c525F3A6086B90d78630F8D9634223",
},
];

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

Expand Down Expand Up @@ -70,16 +70,31 @@ async function calculateBalanceLP(
let worth: string = "0";
if (tokenA !== BUSD && tokenB !== BUSD) {
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 busdAmount = await exchange.getEquivalentToken(
tokenA,
BUSD,
tokenAmountA.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 _worth = new BigNumber(2)
Expand All @@ -91,8 +106,16 @@ async function calculateBalanceLP(

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 +133,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