Remove dependency on web3

This commit is contained in:
g1nt0ki
2022-05-12 20:08:40 +05:30
parent 74c8bd81d3
commit b755598fb0
10 changed files with 269 additions and 408 deletions

View File

@@ -1,36 +1,36 @@
const web3 = require('./config/web3.js');
const retry = require('./helper/retry')
const axios = require("axios");
const sdk = require("@defillama/sdk");
const abis = require('./config/cover/cover.js')
const utils = require('./helper/utils');
const { sumTokens } = require('./helper/unwrapLPs');
async function fetch() {
async function tvl(ts, block) {
let factory = '0xedfC81Bf63527337cD2193925f9C0cF2D537AccA';
let dacontract = new web3.eth.Contract(abis.abis.protocols, factory)
let allProtocols = await dacontract.methods.getAllProtocolAddresses().call();
let factory = '0xedfC81Bf63527337cD2193925f9C0cF2D537AccA';
const { output: allProtocols } = await sdk.api.abi.call({
block,
target: factory,
abi: abis.abis.protocols.find(i => i.name === 'getAllProtocolAddresses')
})
let tvl = 0;
await Promise.all(
allProtocols.map(async (protocol) => {
let dacontract = new web3.eth.Contract(abis.abis.cover, protocol)
let protocolDetails = await dacontract.methods.getProtocolDetails().call();
await Promise.all(
protocolDetails._allCovers.map(async cover => {
let coverBalance = await utils.returnBalance('0x6b175474e89094c44da98b954eedeac495271d0f', cover)
let coverBalanceYdai = await utils.returnBalance('0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01', cover)
tvl += coverBalanceYdai
tvl += coverBalance
})
)
})
)
return tvl;
const calls = allProtocols.map(p => ({ target: p }))
const { output: protocolDetails } = await sdk.api.abi.multiCall({
block,
calls,
abi: abis.abis.cover.find(i => i.name === 'getProtocolDetails')
})
const toa = []
protocolDetails.forEach(({ output }) => {
output._allCovers.forEach(cover => toa.push(
['0x6b175474e89094c44da98b954eedeac495271d0f', cover], // DAI
['0x16de59092dAE5CcF4A1E6439D611fd0653f0Bd01', cover], // yearn DAI
))
})
return sumTokens({}, toa, block, undefined, undefined, { resolveYearn: true })
}
module.exports = {
fetch
ethereum: {
tvl
}
}

View File

@@ -1,11 +1,7 @@
const utils = require('./helper/utils')
const BigNumber = require('bignumber.js')
const web3 = require('./config/web3.js');
const sdk = require("@defillama/sdk")
const ADDRESS_CONFIG_ADDRESS = '0x1D415aa39D647834786EB9B5a333A50e9935b796'
const TOKEN_ADDRESS = '0x5cAf454Ba92e6F2c929DF14667Ee360eD9fD5b26'
const TOKEN_ID = 'dev-protocol'
const ADDRESS_CONFIG_ABI = [
{
@@ -43,29 +39,25 @@ const LOCKUP_ABI = [
},
]
const KEYS = [
{
TOKEN_ADDRESS: TOKEN_ID,
},
]
async function fetch() {
const addressConfigInstance = await new web3.eth.Contract(
ADDRESS_CONFIG_ABI,
ADDRESS_CONFIG_ADDRESS
)
const lockupAddress = await addressConfigInstance.methods.lockup().call()
const lockupInstance = await new web3.eth.Contract(LOCKUP_ABI, lockupAddress)
const [allValue, priceFeed, decimals] = await Promise.all([
lockupInstance.methods.getAllValue().call(),
utils.getPrices(KEYS),
utils.returnDecimals(TOKEN_ADDRESS),
])
const price = priceFeed.data[TOKEN_ID].usd
const tvl = new BigNumber(allValue).div(10 ** decimals).times(price)
return parseFloat(tvl.toFixed())
async function staking(ts, block) {
const { output: lockupAddress } = await sdk.api.abi.call({
block,
target: ADDRESS_CONFIG_ADDRESS,
abi: ADDRESS_CONFIG_ABI.find(i => i.name === 'lockup')
})
const { output: allValue } = await sdk.api.abi.call({
block,
target: lockupAddress,
abi: LOCKUP_ABI.find(i => i.name === 'getAllValue')
})
return {
[TOKEN_ADDRESS]: allValue
}
}
module.exports = {
fetch,
ethereum: {
tvl: () => ({}),
staking,
}
}

View File

@@ -1,40 +1,36 @@
const web3 = require('./config/web3.js');
const BigNumber = require("bignumber.js");
const retry = require('./helper/retry')
const axios = require("axios");
const abis = require('./config/flamincome/abis.js');
const sdk = require("@defillama/sdk")
async function fetch() {
var price_feed = await retry(async bail => await axios.get('https://api.coingecko.com/api/v3/simple/price?ids=ethereum,tether,wrapped-bitcoin&vs_currencies=usd&include_market_cap=true&include_24hr_vol=true&include_24hr_change=true'))
async function returnUnderlyingBalance(address) {
let contract = new web3.eth.Contract(abis['VaultBaseline'], address);
let decimals = await contract.methods.decimals().call();
let balance = await contract.methods.balance().call();
balance = await new BigNumber(balance).div(10 ** decimals).toFixed(2);
return parseFloat(balance);
}
async function tvl(ts, block) {
var tvl = 0;
const contracts = [
'0x54bE9254ADf8D5c8867a91E44f44c27f0c88e88A',
'0x1a389c381a8242B7acFf0eB989173Cd5d0EFc3e3',
'0x1E9DC5d843731D333544e63B2B2082D21EF78ed3',
]
const calls = contracts.map(t => ({ target: t }))
const { output: token } = await sdk.api.abi.multiCall({
block,
calls,
abi: abis['VaultBaseline'].find(i => i.name === 'token')
})
const { output: balance } = await sdk.api.abi.multiCall({
block,
calls,
abi: abis['VaultBaseline'].find(i => i.name === 'balance')
})
// Staking and pool assets
const stakingAssets = [
{ contract: '0x54bE9254ADf8D5c8867a91E44f44c27f0c88e88A', slug: 'tether' },
{ contract: '0x1a389c381a8242B7acFf0eB989173Cd5d0EFc3e3', slug: 'wrapped-bitcoin' },
{ contract: '0x1E9DC5d843731D333544e63B2B2082D21EF78ed3', slug: 'ethereum' },
]
await Promise.all(stakingAssets.map(async (asset) => {
let balance = await returnUnderlyingBalance(asset.contract);
tvl += (parseFloat(balance) * price_feed.data[asset.slug].usd)
}))
return tvl
const balances = {}
token.forEach((t, i) => sdk.util.sumSingleBalance(balances, t.output, balance[i].output))
return balances
}
module.exports = {
doublecounted: true,
fetch
doublecounted: true,
ethereum: {
tvl,
}
}

View File

@@ -1,19 +1,6 @@
const utils = require('./helper/utils');
const web3 = require('./config/web3.js')
let totalSupplyABI = [
{
"constant":true,
"inputs":[],
"name":"totalSupply",
"outputs":[{"internalType":"uint256","name":"","type":"uint256"}],
"payable":false,
"stateMutability":"view",
"type":"function"
}
];
const { sumTokens } = require('./helper/unwrapLPs');
const { pool2 } = require('./helper/pool2');
const { staking } = require('./helper/staking');
const liquidityMinesAddress = '0x4DaC3e07316D2A31baABb252D89663deE8F76f09';
const loyaltyMineAddress = '0xda58927f4065f1d02a6ea850c2aac49d7362a643';
@@ -30,72 +17,20 @@ const stakedTokens = [
];
const GDAOLP = '0x4d184bf6f805ee839517164d301f0c4e5d25c374';
const gdaoToken = '0x515d7E9D75E2b76DB60F8a051Cd890eBa23286Bc';
const wethToken = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
let priceKeys = [
{
'0x514910771af9ca656af840dff83e8264ecf986ca': 'chainlink',
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': 'uniswap',
'0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9': 'aave',
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': 'bitcoin',
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2': 'ethereum',
'0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f': 'havven',
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': 'stable',
'0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e': 'yearn-finance',
'0x515d7E9D75E2b76DB60F8a051Cd890eBa23286Bc': 'governor-dao',
}
]
async function getTotalSupply(abi, address) {
var tcontract = new web3.eth.Contract(abi, address);
var totalSup = await tcontract.methods.totalSupply().call();
totalSup = await tcontract.methods.totalSupply().call();
totalSup = web3.utils.fromWei(totalSup, "ether");
return totalSup;
}
async function fetch() {
var prices = await utils.getPrices(priceKeys);
var tvl = 0;
await Promise.all(
stakedTokens.map(async token => {
var balance = await utils.returnBalance(token, liquidityMinesAddress);
var key = priceKeys[0][token]
if (key !== 'stable') {
tvl += balance * prices.data[key].usd;
} else {
tvl += balance;
}
})
);
var GDAOLPMinesBalance = await utils.returnBalance(GDAOLP, liquidityMinesAddress);
var GDAOLPTotalSupply = await getTotalSupply(totalSupplyABI, GDAOLP);
var ETHInLP = await utils.returnBalance(wethToken, GDAOLP);
var GDAOInLP = await utils.returnBalance(gdaoToken, GDAOLP);
var stakedLPFraction = GDAOLPMinesBalance / GDAOLPTotalSupply;
tvl += stakedLPFraction * ETHInLP * prices.data['ethereum'].usd;
tvl += stakedLPFraction * GDAOInLP * prices.data['governor-dao'].usd;
var GDAOLoyaltyBalance = await utils.returnBalance(gdaoToken, loyaltyMineAddress);
tvl += GDAOLoyaltyBalance * prices.data['governor-dao'].usd;
return tvl.toFixed(2);
async function tvl(ts, block) {
const balances = {}
const tao = stakedTokens.map(t => [t, liquidityMinesAddress])
return sumTokens(balances, tao, block)
}
module.exports = {
methodology: 'TVL counts tokens deposited in the Liquidity Mining program.',
fetch,
ethereum: {
tvl,
staking: staking(loyaltyMineAddress, gdaoToken),
pool2: pool2(loyaltyMineAddress, GDAOLP),
}
}

View File

@@ -172,6 +172,7 @@ async function transformBscAddress() {
'0x0000000000000000000000000000000000000000': 'bsc:0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', // BNB -> WBNB
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 'bsc:0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', // BNB -> WBNB
'0xe1c110e1b1b4a1ded0caf3e42bfbdbb7b5d7ce1c': 'avax:0xe1c110e1b1b4a1ded0caf3e42bfbdbb7b5d7ce1c', // ELK
'0xb7f8cd00c5a06c0537e2abff0b58033d02e5e094': '0x8e870d67f660d95d5be530380d0ec0bd388289e1', // PAX
'0x2170ed0880ac9a755fd29b2688956bd959f933f8': '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH
'0xa35d95872d8eb056eb2cbd67d25124a6add7455e': '0x123', // 2030FLOKI returns nonsense TVL
'0x0cf8e180350253271f4b917ccfb0accc4862f262': '0x123', // BTCBR returns nonsense TVL

View File

@@ -34,7 +34,11 @@ const yearnVaults = {
// yvDAI
"0x19d3364a399d251e894ac732651be8b0e4e85001": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
// yvDAI
"0xacd43e627e64355f1861cec6d3a6688b31a6f952": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
// yvDAI
"0xda816459f1ab5631232fe5e97a05bbbb94970c95": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
// yvDAI
"0x16de59092dae5ccf4a1e6439d611fd0653f0bd01": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
// yvSNX
"0xf29ae508698bdef169b89834f76704c3b205aedf": "0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F",
// yvUNI
@@ -71,12 +75,17 @@ async function unwrapYearn(balances, yToken, block, chain = "ethereum", transfor
const tokenKey = chain == 'ethereum' ? yToken : `${chain}:${yToken}`
if (!balances[tokenKey]) return;
let pricePerShare = await sdk.api.abi.call({
target: yToken,
abi: getPricePerShare[1],
block: block,
chain: chain
});
let pricePerShare
try {
pricePerShare = await sdk.api.abi.call({
target: yToken,
abi: getPricePerShare[1],
block: block,
chain: chain
});
} catch (e) {
console.log('Failing to get price per share for %s, trying getPricePerFullShare', yToken)
}
if (pricePerShare == undefined) {
pricePerShare = await sdk.api.abi.call({
target: yToken,

View File

@@ -31,12 +31,15 @@ async function returnBalance(token, address) {
return parseFloat(balance);
}
async function returnDecimals(address) {
async function returnDecimals(address, block) {
if (address.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee') {
return 18;
}
let contract = new web3.eth.Contract(abis.minABI, address)
let decimals = await contract.methods.decimals().call();
const { output: decimals } = await sdk.api.abi.multiCall({
block,
target: address,
abi: abis.minABI.find(i => i.name === 'decimals')
})
return decimals;
}

View File

@@ -1,67 +1,15 @@
const web3 = require('./config/web3.js');
const abis = require('./config/n3rd/abis.js');
const BN = require("bignumber.js");
const { masterChefExports, } = require("./helper/masterchef")
const { mergeExports, } = require("./helper/utils")
const { staking, } = require("./helper/staking")
let zeroAddress = '0x0000000000000000000000000000000000000000';
const token = "0x32C868F6318D6334B2250F323D914Bc2239E4EeE";
const masterchef = "0x47cE2237d7235Ff865E1C74bF3C6d9AF88d1bbfF";
function tvl(poolState, price) {
var ret = new BN("0");
for (const pool of Object.values(poolState)) {
if (pool.liquidityInfo && pool.liquidityInfo.totalNerdAmount) {
ret = ret.plus(new BN(pool.liquidityInfo.totalNerdAmount));
let lockedIn0x = new BN(pool.lockedIn0x)
.multipliedBy(new BN(pool.liquidityInfo.totalNerdAmount))
.dividedBy(new BN(pool.liquidityInfo.totalLockedLP))
.toFixed(0);
ret = ret.plus(new BN(lockedIn0x));
module.exports = mergeExports([
masterChefExports(masterchef, "ethereum", token),
{
ethereum: {
staking: staking('0x357ADa6E0da1BB40668BDDd3E3aF64F472Cbd9ff', token)
}
}
let priceNerd = new BN(price).dividedBy(new BN("1e6"));
return ret
.dividedBy(new BN("1e18"))
.multipliedBy(new BN(priceNerd))
.multipliedBy(2)
.toFixed(0);
}
async function fetch() {
let nerdVaultAddress = '0x47cE2237d7235Ff865E1C74bF3C6d9AF88d1bbfF';
let nerd = "0x32C868F6318D6334B2250F323D914Bc2239E4EeE";
let price = '0';
{
let routerAddr = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";
let usdc = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
let weth = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
let path = [nerd, weth, usdc];
let router = await new web3.eth.Contract(abis.minRouter, routerAddr);
let amountsOut = await router.methods.getAmountsOut(new BN('1e18').toFixed(0), path).call();
price = amountsOut[2];
}
let nerdToken = await new web3.eth.Contract(abis.minERC20, nerd);
let nerdVault = await new web3.eth.Contract(abis.minVault, nerdVaultAddress);
let poolLength = new BN(await nerdVault.methods.poolLength().call()).toNumber();
let poolState = {};
for (var i = 0; i < poolLength; i++) {
let poolInfo = await nerdVault.methods.poolInfo(i).call();
let lpAddress = poolInfo.token;
let lp = await new web3.eth.Contract(abis.minERC20, lpAddress);
poolState[i] = {};
poolState[i].lockedIn0x = await lp.methods.balanceOf(zeroAddress).call();
poolState[i].liquidityInfo = await nerdVault.methods.getLiquidityInfo(i).call();
}
let vaultTvl = tvl(poolState, price);
let stakingPool = "0x357ADa6E0da1BB40668BDDd3E3aF64F472Cbd9ff";
let nerdLockedInPool = await nerdToken.methods.balanceOf(stakingPool).call();
let priceNerd = new BN(price).dividedBy(new BN("1e6"));
let poolTvl = new BN(nerdLockedInPool)
.dividedBy(new BN("1e18"))
.multipliedBy(new BN(priceNerd))
.toFixed(0);
ret = new BN(vaultTvl).plus(new BN(poolTvl)).toFixed(0);
return ret;
}
module.exports = {
fetch
}
])

View File

@@ -1,63 +1,56 @@
const Web3 = require('web3')
const web3 = require('./config/web3.js');
const abis = require('./config/smoothy/abis.js')
const abisbsc = require('./config/smoothy-bsc/abis.js')
const BigNumber = require("bignumber.js");
const web3bsc = new Web3(new Web3.providers.HttpProvider(`https://bsc-dataseed.binance.org/`));
async function getGWeiFromWei(wei, decimals = 18) {
return BigNumber(wei)
.dividedBy(BigNumber(10).pow(decimals))
.toString(10);
}
async function fetch() {
let bsctvl = await fetchETH();
let tvlETH = await fetchBSC();
return bsctvl + tvlETH
}
async function fetchETH() {
const imp = '0xe5859f4efc09027a9b718781dcb2c6910cac6e91';
const dacontract = new web3.eth.Contract(abis.abis.smoothy, imp)
const allTokens = abis.abis.tokens;
let tvl = BigNumber(0);
await Promise.all(
allTokens.map(async (token) => {
const result = await dacontract.methods.getTokenStats(token.id).call();
let balance = result[2];
tvl = tvl.plus(await getGWeiFromWei(balance, token.decimals));
})
)
tvl = tvl.toFixed(2);
return parseFloat(tvl);
}
async function fetchBSC() {
const imp = '0xe5859f4efc09027a9b718781dcb2c6910cac6e91';
const dacontract = new web3bsc.eth.Contract(abisbsc.abis.smoothy, imp)
const allTokens = abisbsc.abis.bsctokens;
let tvl = BigNumber(0);
await Promise.all(
allTokens.map(async (token) => {
const result = await dacontract.methods.getTokenStats(token.id).call();
let balance = result[2];
tvl = tvl.plus(await getGWeiFromWei(balance, token.decimals));
})
)
tvl = tvl.toFixed(2);
return parseFloat(tvl);
}
const { sumTokens } = require('./helper/unwrapLPs');
const { toUSDTBalances } = require('./helper/balances');
const imp = '0xe5859f4efc09027a9b718781dcb2c6910cac6e91';
const sdk = require("@defillama/sdk");
module.exports = {
fetch
ethereum: {
tvl: async (ts, block) => {
let tvl = 0
const { output: poolLength } = await sdk.api.abi.call({
block,
target: imp,
abi: abis.abis.smoothy.find(i => i.name === '_ntokens')
})
const calls = []
for (let i = 0; i < poolLength; i++)
calls.push({ params: [i] })
const { output: tvls } = await sdk.api.abi.multiCall({
block,
calls,
target: imp,
abi: abis.abis.smoothy.find(i => i.name === 'getTokenStats')
})
tvls.forEach(t => tvl += t.output.balance / 10 ** t.output.decimals)
return toUSDTBalances(tvl)
}
},
bsc: {
tvl: async (ts, _block, { bsc: block }) => {
let tvl = 0
const { output: poolLength } = await sdk.api.abi.call({
block,
target: imp,
chain: 'bsc',
abi: abis.abis.smoothy.find(i => i.name === '_ntokens')
})
const calls = []
for (let i = 0; i < poolLength; i++)
calls.push({ params: [i] })
const { output: tvls } = await sdk.api.abi.multiCall({
block,
calls,
target: imp,
chain: 'bsc',
abi: abis.abis.smoothy.find(i => i.name === 'getTokenStats')
})
tvls.forEach(t => tvl += t.output.balance / 10 ** t.output.decimals)
return toUSDTBalances(tvl)
}
}
}

View File

@@ -1,54 +1,52 @@
const BigNumber = require("bignumber.js");
const web3 = require('./config/web3.js');
const curveAbis = require('./config/curve/abis.js')
const minAbi = require('./config/abis.js').abis.minABI
const utils = require('./helper/utils')
const sdk = require("@defillama/sdk");
const { sumTokens } = require('./helper/unwrapLPs');
const wBTC = '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599'
const y2DAI = {addr: "0xacd43e627e64355f1861cec6d3a6688b31a6f952", dec: 18, getPrice: false, type: 'yv', pfsDec: 18} ///y2DAI yv
const y2USDC = {addr: "0x597ad1e0c13bfe8025993d9e79c69e1c0233522e", dec: 6, getPrice: false, type: 'yv', pfsDec: 18} ///y2USDC yv
const y2USDT = {addr: "0x2f08119c6f07c006695e079aafc638b8789faf18", dec: 6, getPrice: false, type: 'yv', pfsDec: 18} ///y2USDT yv
const Y2TUSD = {addr: "0x37d19d1c4e1fa9dc47bd1ea12f742a0887eda74a", dec: 18, getPrice: false, type: 'yv', pfsDec: 18} ///Y2TUSD yv
const yyDAIT = {addr: "0x5dbcf33d8c2e976c6b560249878e6f1491bca25c", dec: 18, getPrice: false, type: 'yv', pfsDec: 18} ///yyDAI+yUSDC+yUSDT+yTUSD hbtc
const yyDAIB = {addr: "0x2994529c0652d127b7842094103715ec5299bbed", dec: 18, getPrice: false, type: 'yv', pfsDec: 18} ///yyDAI+yUSDC+yUSDT+yBUSD hbtc
const WETH = {addr: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", dec: 18, get getPrice(){return this.addr}, type: ''} ///WETH crvETH
const eCRV = {addr: "0xa3d87fffce63b53e0d54faa1cc983b7eb0b74a9c", dec: 18, getPrice: WETH.getPrice, type: ''} ///eCRV crvETH
const steCRV = {addr: "0x06325440d014e39736583c165c2963ba99faf14e", dec: 18, getPrice: WETH.getPrice, type: ''} ///steCRV crvETH
const ankrCRV = {addr: "0xaa17a236f2badc98ddc0cf999abb47d47fc0a6cf", dec: 18, getPrice: WETH.getPrice, type: ''} ///ankrCRV crvETH
const y2DAI = { addr: "0xacd43e627e64355f1861cec6d3a6688b31a6f952", dec: 18, getPrice: false, type: 'yv', pfsDec: 18 } ///y2DAI yv
const y2USDC = { addr: "0x597ad1e0c13bfe8025993d9e79c69e1c0233522e", dec: 6, getPrice: false, type: 'yv', pfsDec: 18 } ///y2USDC yv
const y2USDT = { addr: "0x2f08119c6f07c006695e079aafc638b8789faf18", dec: 6, getPrice: false, type: 'yv', pfsDec: 18 } ///y2USDT yv
const Y2TUSD = { addr: "0x37d19d1c4e1fa9dc47bd1ea12f742a0887eda74a", dec: 18, getPrice: false, type: 'yv', pfsDec: 18 } ///Y2TUSD yv
const yyDAIT = { addr: "0x5dbcf33d8c2e976c6b560249878e6f1491bca25c", dec: 18, getPrice: false, type: 'yv', pfsDec: 18 } ///yyDAI+yUSDC+yUSDT+yTUSD hbtc
const yyDAIB = { addr: "0x2994529c0652d127b7842094103715ec5299bbed", dec: 18, getPrice: false, type: 'yv', pfsDec: 18 } ///yyDAI+yUSDC+yUSDT+yBUSD hbtc
const WETH = { addr: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", dec: 18, get getPrice() { return this.addr }, type: '' } ///WETH crvETH
const eCRV = { addr: "0xa3d87fffce63b53e0d54faa1cc983b7eb0b74a9c", dec: 18, getPrice: WETH.getPrice, type: '' } ///eCRV crvETH
const steCRV = { addr: "0x06325440d014e39736583c165c2963ba99faf14e", dec: 18, getPrice: WETH.getPrice, type: '' } ///steCRV crvETH
const ankrCRV = { addr: "0xaa17a236f2badc98ddc0cf999abb47d47fc0a6cf", dec: 18, getPrice: WETH.getPrice, type: '' } ///ankrCRV crvETH
const usdc = {addr: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", dec: 6, getPrice: false, type: ''} ///fUSD
const fUSDC = {addr: "0xf0358e8c3cd5fa238a29301d0bea3d63a17bedbe", dec: 6, getPrice: false, type: 'yv', pfsDec: 6} ///fUSD
const fUSDT = {addr: "0x053c80ea73dc6941f518a68e2fc52ac45bde7c9c", dec: 6, getPrice: false, type: 'yv', pfsDec: 6} ///fUSD
const fDAI = {addr: "0xab7fa2b2985bccfc13c6d86b1d5a17486ab1e04c", dec: 18, getPrice: false, type: 'yv', pfsDec: 18} ///fUSD
const usdc = { addr: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", dec: 6, getPrice: false, type: '' } ///fUSD
const fUSDC = { addr: "0xf0358e8c3cd5fa238a29301d0bea3d63a17bedbe", dec: 6, getPrice: false, type: 'yv', pfsDec: 6 } ///fUSD
const fUSDT = { addr: "0x053c80ea73dc6941f518a68e2fc52ac45bde7c9c", dec: 6, getPrice: false, type: 'yv', pfsDec: 6 } ///fUSD
const fDAI = { addr: "0xab7fa2b2985bccfc13c6d86b1d5a17486ab1e04c", dec: 18, getPrice: false, type: 'yv', pfsDec: 18 } ///fUSD
const yvDAI = {addr: '0xda816459f1ab5631232fe5e97a05bbbb94970c95', dec: 18, getPrice: false, type: 'yv2', pfsDec: 18} ///yVault v3
const yvUSDC = {addr: '0x5f18c75abdae578b483e5f43f12a39cf75b973a9', dec: 6, getPrice: false, type: 'yv2', pfsDec: 6} ///yVault v3
const yvUSDT = {addr: '0x7da96a3891add058ada2e826306d812c638d87a7', dec: 6, getPrice: false, type: 'yv2', pfsDec: 6} ///yVault v3
const yvDAI = { addr: '0xda816459f1ab5631232fe5e97a05bbbb94970c95', dec: 18, getPrice: false, type: 'yv2', pfsDec: 18 } ///yVault v3
const yvUSDC = { addr: '0x5f18c75abdae578b483e5f43f12a39cf75b973a9', dec: 6, getPrice: false, type: 'yv2', pfsDec: 6 } ///yVault v3
const yvUSDT = { addr: '0x7da96a3891add058ada2e826306d812c638d87a7', dec: 6, getPrice: false, type: 'yv2', pfsDec: 6 } ///yVault v3
// WETH ///eth2SNOW
const vETH2 = {addr: "0x898bad2774eb97cf6b94605677f43b41871410b1", dec: 18, getPrice: WETH.getPrice, type: ''} ///eth2SNOW
const aETHc = {addr: "0xe95a203b1a91a908f9b9ce46459d101078c2c3cb", dec: 18, getPrice: WETH.getPrice, type: 'ankr', pfsDec: 18} ///eth2SNOW
const CRETH2 = {addr: "0xcbc1065255cbc3ab41a6868c22d1f1c573ab89fd", dec: 18, getPrice: WETH.getPrice, type: ''} ///eth2SNOW
const vETH2 = { addr: "0x898bad2774eb97cf6b94605677f43b41871410b1", dec: 18, getPrice: WETH.getPrice, type: '' } ///eth2SNOW
const aETHc = { addr: "0xe95a203b1a91a908f9b9ce46459d101078c2c3cb", dec: 18, getPrice: WETH.getPrice, type: 'ankr', pfsDec: 18 } ///eth2SNOW
const CRETH2 = { addr: "0xcbc1065255cbc3ab41a6868c22d1f1c573ab89fd", dec: 18, getPrice: WETH.getPrice, type: '' } ///eth2SNOW
const ycrvRenWSBTC = {addr: '0x7ff566e1d69deff32a7b244ae7276b9f90e9d0f6', dec: 18, getPrice: wBTC, type: 'yv', pfsDec: 18} ///btcSnow
const ycrvRenWSBTC = { addr: '0x7ff566e1d69deff32a7b244ae7276b9f90e9d0f6', dec: 18, getPrice: wBTC, type: 'yv', pfsDec: 18 } ///btcSnow
// TODO: the next should be yv
const fcrvRenWBTC = {addr: '0x5f18c75abdae578b483e5f43f12a39cf75b973a9', dec: 18, getPrice: wBTC, type: '', pfsDec: 18} ///btcSnow
const fcrvRenWBTC = { addr: '0x5f18c75abdae578b483e5f43f12a39cf75b973a9', dec: 18, getPrice: wBTC, type: '', pfsDec: 18 } ///btcSnow
const polyDai = {addr: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063", dec: 18, getPrice: false} ///penguin
const polyUsdc = {addr: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", dec: 6, getPrice: false} ///penguin
const polyUSDT = {addr: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f", dec: 6, getPrice: false} ///penguin
const polyDai = { addr: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063", dec: 18, getPrice: false } ///penguin
const polyUsdc = { addr: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", dec: 6, getPrice: false } ///penguin
const polyUSDT = { addr: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f", dec: 6, getPrice: false } ///penguin
const snow = {addr: '0xfe9a29ab92522d14fc65880d817214261d8479ae', dec: 18, get getPrice(){return this.addr}} ///Frosty
const snow = { addr: '0xfe9a29ab92522d14fc65880d817214261d8479ae', dec: 18, get getPrice() { return this.addr } } ///Frosty
const polySnow = {addr: "0x33c9f7c0afe2722cb9e426360c261fb755b4483d", dec: 18, getPrice: snow.getPrice}; /// Olaf's
const polySnow = { addr: "0x33c9f7c0afe2722cb9e426360c261fb755b4483d", dec: 18, getPrice: snow.getPrice }; /// Olaf's
let swaps = [
{
'name': 'yv',
'addr': '0x4571753311e37ddb44faa8fb78a6df9a6e3c6c0b',
'coins': [ y2DAI, y2USDC, y2USDT, Y2TUSD ],
'coins': [y2DAI, y2USDC, y2USDT, Y2TUSD],
'abi': curveAbis.abis.abisBTC
},
{
@@ -60,7 +58,7 @@ let swaps = [
{
'name': 'crvETH',
'addr': '0x3820a21c6d99e57fb6a17ab3fbdbe22552af9bb0',
'coins': [ WETH, eCRV, steCRV, ankrCRV ],
'coins': [WETH, eCRV, steCRV, ankrCRV],
// 'abi': abi
'abi': curveAbis.abis.abiNew
},
@@ -110,112 +108,98 @@ const pools = [
}
]
async function polygon(){
var tvl = 0;
const tokensForPrice = [WETH.getPrice, wBTC, snow.getPrice]
const prices = await utils.getPricesFromContract(tokensForPrice);
await Promise.all(
pools.filter(p=>p.chain==="polygon").map(async pool => {
await Promise.all(
pool.coins.map(async coin => {
let tokenLocked = await sdk.api.erc20.balanceOf({
owner: pool.addr,
target: coin.addr,
chain: pool.chain,
});
let collectorTvl = BigNumber(tokenLocked.output).div(Math.pow(10, coin.dec)).toNumber()
if(coin.getPrice){
collectorTvl = collectorTvl * prices.data[coin.getPrice].usd
}
tvl+=collectorTvl
}))
}),
)
return tvl
async function polygon(ts, _block, { polygon: block }) {
const poolsPolygon = pools.filter(p => p.chain === "polygon")
const toa = []
poolsPolygon.forEach(pool => {
pool.coins.map(coin => toa.push([coin.addr, pool.addr]))
})
return sumTokens({}, toa, block, 'polygon')
}
async function ethereum() {
var tvl = 0;
async function ethereum(ts, block) {
const tokensForPrice = [WETH.getPrice, wBTC, snow.getPrice]
const prices = await utils.getPricesFromContract(tokensForPrice);
await Promise.all([
...pools.filter(p=>p.chain==="ethereum").map(async pool => {
await Promise.all(
pool.coins.map(async coin => {
let tokenLocked = await sdk.api.erc20.balanceOf({
owner: pool.addr,
target: coin.addr,
chain: pool.chain,
});
let collectorTvl = BigNumber(tokenLocked.output).div(Math.pow(10, coin.dec)).toNumber()
if(coin.getPrice){
collectorTvl = collectorTvl * prices.data[coin.getPrice].usd
}
tvl+=collectorTvl
}))
}),
...swaps.map(async item => {
await Promise.all(
item.coins.map(async (coin, index) => {
var dacontract = new web3.eth.Contract(item.abi, item.addr)
var balance = await dacontract.methods.balances(index).call();
var poolAmount = await new BigNumber(balance).div(10 ** coin.dec).toFixed(2);
const poolsEth = pools.filter(p => p.chain === "ethereum")
const toa = []
poolsEth.forEach(pool => {
pool.coins.map(coin => toa.push([coin.addr, pool.addr]))
})
const balances = await sumTokens({}, toa, block)
if (coin.type) {
var multiplier = 1;
switch (coin.type){
case 'yv': // getPricePerFullShare
var coinContract = new web3.eth.Contract(curveAbis.abis.yTokens, coin.addr);
var virtualPrice = await coinContract.methods
.getPricePerFullShare()
.call();
await Promise.all(swaps.map(async item => {
await Promise.all(
item.coins.map(async (coin, index) => {
let { output: balance } = await sdk.api.abi.call({
block,
params: [index],
target: item.addr,
abi: item.abi.find(i => i.name === 'balances')
})
let poolAmount = new BigNumber(balance).div(10 ** coin.dec);
balance = BigNumber(balance)
if (coin.type) {
var multiplier = 1;
let virtualPrice, virtualPriceObj
switch (coin.type) {
case 'yv': // getPricePerFullShare
virtualPriceObj = await sdk.api.abi.call({
block,
target: coin.addr,
abi: curveAbis.abis.yTokens.find(i => i.name === 'getPricePerFullShare')
})
virtualPrice = virtualPriceObj.output
break;
case 'yv2': // pricePerShare
var coinContract = new web3.eth.Contract(abi.yv2, coin.addr);
var virtualPrice = await coinContract.methods
.pricePerShare()
.call();
virtualPriceObj = await sdk.api.abi.call({
block,
target: coin.addr,
abi: abi.yv2.find(i => i.name === 'pricePerShare')
})
virtualPrice = virtualPriceObj.output
break;
case 'ankr': // ratio
var coinContract = new web3.eth.Contract(abi.ankr, coin.addr);
var virtualPrice = await coinContract.methods
.ratio()
.call();
break;
virtualPriceObj = await sdk.api.abi.call({
block,
target: coin.addr,
abi: abi.ankr.find(i => i.name === 'ratio')
})
virtualPrice = virtualPriceObj.output
break;
default:
virtualPrice = 1;
}
}
multiplier = await new BigNumber(virtualPrice)
.div(10 ** coin.pfsDec)
.toFixed(4);
multiplier = await new BigNumber(virtualPrice)
.div(10 ** coin.pfsDec)
.toFixed(4);
poolAmount = poolAmount * multiplier;
}
if(coin.getPrice){
poolAmount = poolAmount * prices.data[coin.getPrice].usd
}
tvl += parseFloat(poolAmount )
})
)
})
])
return tvl;
poolAmount = poolAmount.multipliedBy(multiplier)
balance = balance.multipliedBy(multiplier)
}
if (coin.getPrice) {
if (coin.getPrice === wBTC) balance = poolAmount.multipliedBy(1e8)
sdk.util.sumSingleBalance(balances, coin.getPrice, balance.toFixed(0))
} else {
sdk.util.sumSingleBalance(balances, '0xdac17f958d2ee523a2206206994597c13d831ec7', poolAmount.multipliedBy(1e6).toFixed(0)) // add as usdt
}
})
)
}))
return balances
}
module.exports = {
ethereum:{
fetch:ethereum
ethereum: {
tvl: ethereum
},
polygon:{
fetch:polygon
polygon: {
tvl: polygon
},
fetch:async()=>((await polygon())+(await ethereum()))
}
const abi = {
yv2:[{"stateMutability":"view","type":"function","name":"pricePerShare","inputs":[],"outputs":[{"name":"","type":"uint256"}],"gas":77734}],
ankr: [{"inputs":[],"name":"ratio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]
yv2: [{ "stateMutability": "view", "type": "function", "name": "pricePerShare", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }], "gas": 77734 }],
ankr: [{ "inputs": [], "name": "ratio", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }]
}