From 1228d3630f3524064249b3fee071f1ef38124fc2 Mon Sep 17 00:00:00 2001 From: webWorker-eos <67700142+webWorker-eos@users.noreply.github.com> Date: Mon, 13 May 2024 22:36:39 +0800 Subject: [PATCH] add dfs tvl (#10046) * add dfs tvl * calc tvl by chain * del log --- projects/dfs/index.js | 75 +++++++++++++++++++++++++++++-------- projects/helper/chains.json | 1 + 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/projects/dfs/index.js b/projects/dfs/index.js index 545947a86c0f..968aa75f2963 100644 --- a/projects/dfs/index.js +++ b/projects/dfs/index.js @@ -1,28 +1,71 @@ -const { get_account_tvl } = require("../helper/chain/eos"); +const { get_account_tvl } = require('../helper/chain/eos'); const tokens = [ - ["eosio.token", "EOS", "eos"], - ["tethertether", "USDT", "tether"], - ["btc.ptokens", "PBTC", "ptokens-btc"], - ["token.defi", "BOX", "defibox"], - ["minedfstoken", "DFS", "defis-network"], - ["emanateoneos", "EMT", "emanate"], - ["token.newdex", "DEX", "newdex-token"], - ["chexchexchex", "CHEX", "chex-token"], - ["everipediaiq", "IQ", "everipedia"], - ["eosiotptoken", "TPT", "token-pocket"], - ["core.ogx", "OGX", "organix"], -] + ['eosio.token', 'EOS', 'eos'], + ['tethertether', 'USDT', 'tether'], + ['btc.ptokens', 'PBTC', 'ptokens-btc'], + ['token.defi', 'BOX', 'defibox'], + ['minedfstoken', 'DFS', 'defis-network'], + ['emanateoneos', 'EMT', 'emanate'], + ['token.newdex', 'DEX', 'newdex-token'], + ['chexchexchex', 'CHEX', 'chex-token'], + ['everipediaiq', 'IQ', 'everipedia'], + ['eosiotptoken', 'TPT', 'token-pocket'], + ['core.ogx', 'OGX', 'organix'], +]; // https://apps.defis.network/ // AMM swap async function eos() { - return await get_account_tvl("defisswapcnt", tokens); + return await get_account_tvl('defisswapcnt', tokens); +} + +// https://dfs.land/ +const axios = require('axios'); +const endpoint = 'https://api.dfs.land'; +async function dfs() { + const info = await axios(`${endpoint}/v1/chain/get_table_rows`, { + method: 'POST', + data: JSON.stringify({ + code: 'swapswapswap', + scope: 'swapswapswap', + table: 'markets', + json: true, + limit: -1, + }), + }); + const markets = info.data.rows || []; + const dfsMkt = markets.find((m) => m.mid == 1); + let dfsPrice = 1; + if (!dfsMkt) { + dfsPrice = 1; + } else { + dfsPrice = parseFloat(dfsMkt.reserve0) / parseFloat(dfsMkt.reserve1); + } + let tvl = 0; + for (let i = 0; i < markets.length; i++) { + const m = markets[i]; + if (m.contract0 == 'usdtusdtusdt' && m.sym0 == '8,USDT') { + tvl += parseFloat(m.reserve0) * 2; + } else if (m.contract1 == 'usdtusdtusdt' && m.sym1 == '8,USDT') { + tvl += parseFloat(m.reserve1) * 2; + } else if (m.contract0 == 'eosio.token' && m.sym0 == '8,DFS') { + tvl += parseFloat(m.reserve0) * 2 * dfsPrice; + } else if (m.contract1 == 'eosio.token' && m.sym1 == '8,DFS') { + tvl += parseFloat(m.reserve1) * 2 * dfsPrice; + } + } + return { + tether: tvl, + }; } module.exports = { methodology: `DFS TVL is achieved by querying token balances from DFS's AMM swap liquidity smart contract.`, eos: { - tvl: eos + tvl: eos, }, -} + dfs: { + tvl: dfs, + }, +}; diff --git a/projects/helper/chains.json b/projects/helper/chains.json index d4b5c965c6e6..6dfa8b9b43e2 100644 --- a/projects/helper/chains.json +++ b/projects/helper/chains.json @@ -76,6 +76,7 @@ "defiverse", "degen", "dexit", + "dfs", "dfk", "doge", "dogechain",