-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpancakeAPR.js
45 lines (35 loc) · 1.55 KB
/
pancakeAPR.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const Web3 = require("web3");
const fs = require("fs");
var web3 = new Web3("https://bsc-dataseed1.binance.org:443");
const BNObject = Web3.utils.BN;
const BN = (x) => new BNObject(x);
const ABIjson = fs.readFileSync("./contracts/pancakeswapContract.json"); // pool contract
const CakeABIJson = fs.readFileSync("./contracts/cakeContract.json"); //cake contract
const ABI = JSON.parse(ABIjson);
const CakeABI = JSON.parse(CakeABIJson);
const contractAdd = "0x73feaa1eE314F8c655E354234017bE2193C9E24E";
const cakeContractAdd = "0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82";
async function pancakeAPR() {
const contract = new web3.eth.Contract(ABI, contractAdd);
const poolInfo = await contract.methods.poolInfo("0").call();
const allocPoints = poolInfo.allocPoint;
let result = await contract.methods.cakePerBlock().call();
const cakePerBlock = BN(result);
const poolAllocPoint = BN(allocPoints);
result = await contract.methods.totalAllocPoint().call();
const totalAllocPoint = BN(result);
const blockReward = cakePerBlock.mul(poolAllocPoint).div(totalAllocPoint);
const numberOfBlocks = 20 * 60 * 24 * 365;
const annualBlockReward = blockReward
.mul(BN(numberOfBlocks.toString()))
.mul(BN("1000000000000"));
const cakeContract = new web3.eth.Contract(CakeABI, cakeContractAdd);
result = await cakeContract.methods
.balanceOf(contract.options.address)
.call();
const lpSupply = BN(result);
const apr =
annualBlockReward.div(lpSupply).divRound(BN("100000000")).toNumber() / 100;
return apr;
}
exports.pancakeAPR = pancakeAPR;