This file contains hidden or 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
import Web3 from "web3"; | |
import { abi as IUniswapV2Pair } from "@uniswap/v2-core/build/IUniswapV2Pair.json"; | |
import { BigNumber } from "bignumber.js"; | |
import { ChainId, Token, WETH, Fetcher, Route } from "@uniswap/sdk"; | |
// Create a new Web3 Instance | |
const web3 = new Web3(window.ethereum); | |
// Replace the addresses to point to your Farming Contract | |
// and LP Token Contract on the desired network |
This file contains hidden or 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
// Create a new Web3 Instance | |
const web3 = new Web3(window.ethereum); | |
// Replace the addresses to point to your Farming Contract | |
// and LP Token Contract on the desired network | |
const FARMING_CONTRACT_ADDRESS = "0xeF682Ae89e74BcBB3fC3B24B6b3e************" | |
const LP_TOKEN_ADDRESS = "0x9ba8dd47C8a85aD45aB7dab82727************" | |
This file contains hidden or 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 calculateAPY = async () => { | |
try { | |
//BLOCKS_PER_DAY varies acccording to network all values are approx and they keep changing | |
//BLOCKS_PER_DAY = 21600 for Kovan Testnet | |
//BLOCKS_PER_DAY = 28800 for BSC Testnet | |
//BLOCKS_PER_DAY = 6400 for Ethereum Mainnet | |
//I am using the value for Ethereum mainnet | |
const BLOCKS_PER_YEAR = 6400 * 365; | |
let rewardTokenPrice = 0; |
This file contains hidden or 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 calculateLpTokenPrice = async () => { | |
let rewardTokenPrice = 0; | |
// For Price IN ETH | |
// Reward Token is Dodgecoin in our case | |
rewardTokenPrice = await getDogecoinPriceInETH(); | |
// For Price in BNB | |
// If you want to do calculations in BNB uncomment line below and comment line number 5 | |
// rewardTokenPrice = await getDodgecoinPriceInBNB() |
This file contains hidden or 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 getLpTokenTotalSupply = async () => { | |
try { | |
const LpTokenContract = new web3.eth.Contract( | |
IUniswapV2Pair, | |
LP_TOKEN_ADDRESS | |
); | |
const totalSupply = await LpTokenContract.methods.totalSupply().call(); | |
return totalSupply; | |
} catch (e) { | |
console.log(e); |
This file contains hidden or 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 getLpTokenReserves = async () => { | |
try { | |
const LpTokenContract = new web3.eth.Contract( | |
IUniswapV2Pair, | |
LP_TOKEN_ADDRESS | |
); | |
const totalReserves = await LpTokenContract.methods.getReserves().call(); | |
// For ETH/DOGE Pool totalReserves[0] = ETH Reserve and totalReserves[1] = DOGE Reserve | |
// For BNB/DOGE Pool totalReserves[0] = BNB Reserve and totalReserves[1] = DOGE Reserve | |
return [totalReserves[0], totalReserves[1]]; |
This file contains hidden or 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
// Get DOGECOIN price in ETH | |
const getDogecoinPriceInETH = async () => { | |
try { | |
const DOGECOIN = new Token( | |
ChainId.MAINNET, //ChainId for Ethereum Mainnet | |
"0x4206931337dc273a630d328da6441786bfad668f", //DOGECOIN address on Ethereum Mainnet | |
8 //Number of Decimals | |
); | |
const pair = await Fetcher.fetchPairData(DOGECOIN, WETH[DOGECOIN.chainId]); | |
const route = new Route([pair], WETH[DOGECOIN.chainId]); |
This file contains hidden or 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
import Web3 from "web3"; | |
import { abi as IUniswapV2Pair } from "@uniswap/v2-core/build/IUniswapV2Pair.json"; | |
import { BigNumber } from "bignumber.js"; | |
import { ChainId, Token, WETH, Fetcher, Route } from "@uniswap/sdk"; | |