Skip to content

Commit 45cd291

Browse files
committed
Euler v2 TVL and borrowed adapter
1 parent d74eb83 commit 45cd291

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

projects/euler/v2.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { ethereum } = require('.')
2+
const { getLogs } = require('../helper/cache/getLogs')
3+
const { sumTokens2 } = require('../helper/unwrapLPs')
4+
5+
const EULER_FACTORY = "0x29a56a1b8214D9Cf7c5561811750D5cBDb45CC8e"
6+
module.exports = {
7+
methodology: `TVL is supply balance minus borrows the euler contract.`,
8+
ethereum: {
9+
tvl,
10+
borrowed
11+
}
12+
};
13+
14+
async function tvl(api) {
15+
const logs = await getLogs({
16+
api,
17+
target: EULER_FACTORY,
18+
fromBlock: 20529225,
19+
eventAbi: "event ProxyCreated(address indexed proxy, bool upgradeable, address implementation, bytes trailingData)",
20+
onlyArgs: true
21+
});
22+
23+
const vaults = logs.map(log => log.proxy);
24+
const underlyingAssets = await api.multiCall({ abi: "address:asset", calls: vaults})
25+
const tokensAndOwners = underlyingAssets.map((underlying, i) => [underlying, vaults[i]]);
26+
27+
return sumTokens2({ api, tokensAndOwners });
28+
}
29+
30+
async function borrowed(api) {
31+
const logs = await getLogs({
32+
api,
33+
target: EULER_FACTORY,
34+
fromBlock: 20529225,
35+
eventAbi: "event ProxyCreated(address indexed proxy, bool upgradeable, address implementation, bytes trailingData)",
36+
onlyArgs: true
37+
});
38+
39+
const vaults = logs.map(log => log.proxy);
40+
const underlyingAssets = await api.multiCall({ abi: "address:asset", calls: vaults})
41+
const borrows = await api.multiCall({ abi: "uint256:totalBorrows", calls: vaults})
42+
43+
api.addTokens(underlyingAssets, borrows);
44+
return api.getBalances();
45+
}

0 commit comments

Comments
 (0)