1
+ const axios = require ( 'axios' )
2
+ const { getLogs2 } = require ( '../helper/cache/getLogs' )
3
+
4
+ const config = {
5
+ bsc : {
6
+ vault : '0x8F73b65B4caAf64FBA2aF91cC5D4a2A1318E5D8C' ,
7
+ fromBlock : 48000000 ,
8
+ }
9
+ }
10
+ const abi = {
11
+ totalAssets : "uint256:totalAssets" ,
12
+ idToMarketParams : "function idToMarketParams(bytes32) view returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv)"
13
+ }
14
+ const eventAbis = {
15
+ supplyCollateral : 'event SupplyCollateral(bytes32 indexed id, address indexed caller, address indexed onBehalf, uint256 assets)' ,
16
+ withdrawCollateral : 'event WithdrawCollateral(bytes32 indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 assets)' ,
17
+ liquidate : 'event Liquidate(bytes32 indexed id, address indexed caller, address indexed borrower, uint256 repaidAssets, uint256 repaidShares, uint256 seizedAssets, uint256 badDebtAssets, uint256 badDebtShares)'
18
+ }
19
+
20
+ module . exports = {
21
+ methodology : "TVL counts the tokens locked in the protocol's vaults based on supply, withdraw and liquidate events" ,
22
+ start : '2025-04-01' ,
23
+ misrepresentedTokens : true ,
24
+ bsc : {
25
+ tvl : async ( api ) => {
26
+
27
+ // const { data: { data: vaults } } = await axios.get('https://api.lista.org/api/moolah/vault/list?page=1&pageSize=1000')
28
+
29
+ // const totalAssets = await api.multiCall({
30
+ // abi: abi.totalAssets,
31
+ // calls: vaults.list.map(i => i.address)
32
+ // })
33
+ // const tokensAndOwners = vaults.list.map((vault, i) => {
34
+ // api.add(vault.asset, totalAssets[i])
35
+ // return [vault.asset, vault.address]
36
+ // })
37
+
38
+
39
+
40
+ // const [supplyLogs
41
+ // , withdrawLogs,
42
+ // liquidateLogs
43
+ // ] = await Promise.all([
44
+ // getLogs2({
45
+ // api,
46
+ // target: config.bsc.vault,
47
+ // eventAbi: eventAbis.supplyCollateral,
48
+ // fromBlock: config.bsc.fromBlock,
49
+ // extraKey: 'SupplyCollateral',
50
+
51
+ // }),
52
+ // getLogs2({
53
+ // api,
54
+ // target: config.bsc.vault,
55
+ // eventAbi: eventAbis.withdrawCollateral,
56
+ // fromBlock: config.bsc.fromBlock,
57
+ // extraKey: 'WithdrawCollateral'
58
+ // }),
59
+ // getLogs2({
60
+ // api,
61
+ // target: config.bsc.vault,
62
+ // eventAbi: eventAbis.liquidate,
63
+ // fromBlock: config.bsc.fromBlock,
64
+ // extraKey: 'Liquidate'
65
+ // })
66
+ // ])
67
+
68
+
69
+
70
+ // const tokenBalances = {}
71
+
72
+ // const uniqueIds = [...new Set(supplyLogs.map(log => log.id))]
73
+
74
+ // const marketParams = await api.multiCall({
75
+ // abi: abi.idToMarketParams,
76
+ // calls: uniqueIds.map(id => ({
77
+ // target: config.bsc.vault,
78
+ // params: [id]
79
+ // }))
80
+ // })
81
+
82
+ // const idToCollateralToken = {}
83
+ // uniqueIds.forEach((id, i) => {
84
+ // idToCollateralToken[id] = marketParams[i].collateralToken
85
+ // })
86
+
87
+ // supplyLogs.forEach(log => {
88
+ // const collateralToken = idToCollateralToken[log.id]
89
+ // const amount = log.assets
90
+ // tokenBalances[collateralToken] = (tokenBalances[collateralToken] || 0) + Number(amount)
91
+ // })
92
+
93
+ // withdrawLogs.forEach(log => {
94
+ // const collateralToken = idToCollateralToken[log.id]
95
+ // const amount = log.assets
96
+ // tokenBalances[collateralToken] = (tokenBalances[collateralToken] || 0) - Number(amount)
97
+ // })
98
+
99
+ // liquidateLogs.forEach(log => {
100
+ // const collateralToken = idToCollateralToken[log.id]
101
+ // const amount = log.seizedAssets
102
+ // tokenBalances[collateralToken] = (tokenBalances[collateralToken] || 0) - Number(amount)
103
+ // })
104
+
105
+ // Object.entries(tokenBalances).forEach(([token, balance]) => {
106
+ // if (balance > 0) {
107
+ // api.add(token, balance)
108
+ // }
109
+ // })
110
+
111
+ // return api.getBalances()
112
+ const { data : { data : { totalDeposits, totalCollateral } } } = await axios . get ( 'https://api.lista.org/api/moolah/overall' )
113
+
114
+ // Convert string to number and sum up
115
+ const totalValue = Number ( totalDeposits ) + Number ( totalCollateral )
116
+
117
+ return {
118
+ 'tether' : totalValue
119
+ }
120
+ }
121
+ }
122
+ }
0 commit comments