added finnexus tlv calculation

This commit is contained in:
jiaqinggang1
2020-11-30 07:38:47 -08:00
parent 3c30d168fc
commit 6c71420320
4 changed files with 45 additions and 24 deletions

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -0,0 +1,6 @@
let abis = {};
abis.fnxOracle = [{"constant":true,"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"getPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getTotalCollateral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}];
module.exports = {
abis
}

33
projects/finnexus.js Normal file
View File

@@ -0,0 +1,33 @@
var Web3 = require('web3');
const env = require('dotenv').config()
const web3 = new Web3(new Web3.providers.HttpProvider(`https://mainnet.infura.io/v3/${env.parsed.INFURA_KEY}`));
const BN = require("bignumber.js");
const abis = require('./config/finnexus/abis.js')
const utils = require('./helper/utils');
async function getTotalCollateral(abi,contract) {
var dacontract = new web3.eth.Contract(abi, contract)
var totalCol = await dacontract.methods.getTotalCollateral().call();
return totalCol;
}
async function fetch() {
let usdcPool = '0x120f18f5b8edcaa3c083f9464c57c11d81a9e549';
let fnxPool = '0xfdf252995da6d6c54c03fc993e7aa6b593a57b8d';
let usdcTotal = await getTotalCollateral(abis.abis.fnxOracle,usdcPool);
let fnxTotal = await getTotalCollateral(abis.abis.fnxOracle,fnxPool);
usdcTotal = new BN(usdcTotal).div(new BN(10 ** 24)).toFixed(2);
fnxTotal = new BN(fnxTotal).div(new BN(10 ** 24)).toFixed(2);
let tlv = parseFloat(usdcTotal) + parseFloat(fnxTotal);
return tlv;
}
module.exports = {
fetch
}

View File

@@ -1,24 +0,0 @@
var Web3 = require('web3');
const env = require('dotenv').config()
const web3 = new Web3(new Web3.providers.HttpProvider(`https://mainnet.infura.io/v3/${env.parsed.INFURA_KEY}`));
const BigNumber = require("bignumber.js");
const utils = require('./helper/utils');
async function fetch() {
let ethPool = '0x878f15ffc8b894a1ba7647c7176e4c01f74e140b';
let btcPool = '0x20DD9e22d22dd0a6ef74a520cb08303B5faD5dE7';
let btcAmount = await utils.returnBalance('0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', btcPool);
let getethBalanceRes = await web3.eth.getBalance(ethPool);
let price_feed = await utils.getPricesfromString('bitcoin,ethereum');
let ethAmount = new BigNumber(getethBalanceRes).div(10 ** 18).toFixed(2);
let tvl = (price_feed.data.bitcoin.usd * btcAmount) + (ethAmount * price_feed.data.ethereum.usd)
return tvl;
}
module.exports = {
fetch
}