Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions projects/euler/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { ethereum } = require('.')
const { getLogs } = require('../helper/cache/getLogs')
const { sumTokens2 } = require('../helper/unwrapLPs')

const EULER_FACTORY = "0x29a56a1b8214D9Cf7c5561811750D5cBDb45CC8e"
module.exports = {
methodology: `TVL is supply balance minus borrows the euler contract.`,
ethereum: {
tvl,
borrowed
}
};

async function tvl(api) {
const logs = await getLogs({
api,
target: EULER_FACTORY,
fromBlock: 20529225,
eventAbi: "event ProxyCreated(address indexed proxy, bool upgradeable, address implementation, bytes trailingData)",
onlyArgs: true
});

const vaults = logs.map(log => log.proxy);
const underlyingAssets = await api.multiCall({ abi: "address:asset", calls: vaults})
const tokensAndOwners = underlyingAssets.map((underlying, i) => [underlying, vaults[i]]);

return sumTokens2({ api, tokensAndOwners });
}

async function borrowed(api) {
const logs = await getLogs({
api,
target: EULER_FACTORY,
fromBlock: 20529225,
eventAbi: "event ProxyCreated(address indexed proxy, bool upgradeable, address implementation, bytes trailingData)",
onlyArgs: true
});

const vaults = logs.map(log => log.proxy);
const underlyingAssets = await api.multiCall({ abi: "address:asset", calls: vaults})
const borrows = await api.multiCall({ abi: "uint256:totalBorrows", calls: vaults})

api.addTokens(underlyingAssets, borrows);
return api.getBalances();
}