|
1 | 1 | const { sumTokens2 } = require('../helper/unwrapLPs'); |
2 | | -const { fetchURL } = require('../helper/utils') |
| 2 | +const { fetchURL } = require('../helper/utils'); |
| 3 | + |
| 4 | +const BASE_URL = 'https://mainnet-dapp1.sunube.net:7740/query'; |
| 5 | +const BLOCKCHAIN_RID = 'F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6'; |
| 6 | + |
| 7 | +function buildQueryUrl(queryType, params = {}) { |
| 8 | + const url = `${BASE_URL}/${BLOCKCHAIN_RID}?type=${queryType}`; |
| 9 | + const queryParams = new URLSearchParams(params).toString(); |
| 10 | + return queryParams ? `${url}&${queryParams}` : url; |
| 11 | +} |
3 | 12 |
|
4 | 13 | async function tvl(api, isBorrows) { |
5 | | - const { data } = await fetchURL("https://mainnet-dapp1.sunube.net:7740/query/F4E33267A8FF1ACCE3C6D7B441B8542FB84FF6DAA5114105563D2AA34979BEF6?type=get_stats_supply_deposit"); |
| 14 | + const { data } = await fetchURL( |
| 15 | + buildQueryUrl('get_stats_supply_deposit') |
| 16 | + ); |
| 17 | + |
| 18 | + |
| 19 | + data.forEach(({ asset_id, total_borrow, total_deposit }) => { |
| 20 | + const balance = isBorrows ? total_borrow : total_deposit - total_borrow; |
| 21 | + api.add(asset_id, balance); |
| 22 | + }); |
6 | 23 |
|
7 | | - data.map(({ asset_id, total_borrow, total_deposit, price, decimals }) => { |
8 | | - // const multiplier = price/10 **decimals |
9 | | - // total_borrow = total_borrow * multiplier |
10 | | - // total_deposit = total_deposit * multiplier |
11 | | - // const balance = isBorrows ? total_borrow : total_deposit - total_borrow |
12 | | - // api.addUSDValue(balance) |
13 | | - const balance = isBorrows ? total_borrow : total_deposit - total_borrow |
14 | | - api.add(asset_id, balance) |
15 | | - }) |
16 | | - return sumTokens2({ api }) |
| 24 | + return sumTokens2({ api }); |
17 | 25 | } |
18 | 26 |
|
19 | 27 | module.exports = { |
|
0 commit comments