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

Fix Element TVL #563

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
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
73 changes: 16 additions & 57 deletions projects/element/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@ const _ = require('underscore')
const bn = require('bignumber.js')

const trancheFactory = '0x62F161BF3692E4015BefB05A03a94A40f520d1c0';
const wpFactory = '0x8E9aa87E45e92bad84D5F8DD1bff34Fb92637dE9';
const ccpFactory = '0xb7561f547F3207eDb42A6AfA42170Cd47ADD17BD';
const ccpFactory_v1 = '0xb7561f547F3207eDb42A6AfA42170Cd47ADD17BD';
const ccpFactory_v1_1 = '0xE88628700eaE9213169D715148ac5A5F47B5dCd9';
const balVault = '0xBA12222222228d8Ba445958a75a0704d566BF2C8'


const wps = [
'0xD5D7bc115B32ad1449C6D0083E43C87be95F2809',
'0xDe620bb8BE43ee54d7aa73f8E99A7409Fe511084',
'0x67F8FCb9D3c463da05DE1392EfDbB2A87F8599Ea',
'0xF94A7Df264A2ec8bCEef2cFE54d7cA3f6C6DFC7a',
'0xE54B3F5c444a801e61BECDCa93e74CdC1C4C1F90',
'0x2D6e3515C8b47192Ca3913770fa741d3C4Dac354',
'0xd16847480D6bc218048CD31Ad98b63CC34e5c2bF',
'0x7320d680Ca9BCE8048a286f00A79A2c9f8DCD7b3',
'0x9e030b67a8384cbba09D5927533Aa98010C87d91'
]

async function tvl(timestamp, block) {
let balances = {};

Expand Down Expand Up @@ -54,57 +42,28 @@ async function tvl(timestamp, block) {
balances[underlying.toLowerCase()] = balances[underlying.toLowerCase()] ? new bn(balances[underlying.toLowerCase()]).plus(valueSupplied) : valueSupplied
}

// wp tvl

for (let wp of wps) {
try {
let poolId = (await sdk.api.abi.call({
block,
target: wp,
abi: abi['getPoolId'],
})).output;

let poolTokens = (await sdk.api.abi.call({
block,
target: balVault,
abi: abi['getPoolTokens'],
params: poolId
})).output;

for (let i = 0; i < poolTokens.tokens.length; i++) {
let token = poolTokens.tokens[i];
let tranche;
try {
tranche = (await sdk.api.abi.call({
block,
target: token,
abi: abi['tranche']
})).output;
} catch (e) {
}
if (tranche && tranches.indexOf(tranche.toLowerCase()) >= 0) {
continue;
}

balances[token.toLowerCase()] = balances[token.toLowerCase()] ? new bn(balances[token.toLowerCase()]).plus(poolTokens.balances[i]) : poolTokens.balances[i];
}
} catch (e) {
console.log(e)
}
}


// // // cc tvl

let ccLogs = (await sdk.api.util
let ccLogs_v1 = (await sdk.api.util
.getLogs({
keys: [],
toBlock: block,
target: ccpFactory,
fromBlock: 12686198,
target: ccpFactory_v1,
fromBlock: 12686198, // June 22nd, 2021
topic: 'PoolCreated(address)',
})).output;

let ccLogs_v1_1 = (await sdk.api.util
.getLogs({
keys: [],
toBlock: block,
target: ccpFactory_v1_1,
fromBlock: 14366198, // March 11th, 2022
topic: 'PoolCreated(address)',
})).output;

let ccLogs = [].concat(ccLogs_v1, ccLogs_v1_1);

for (let log of ccLogs) {
if (block < log.blockNumber) continue;
let cc = `0x${log.topics[1].substr(-40)}`;
Expand Down