From d4353a7cd3faa568b22e46686199381764e39c67 Mon Sep 17 00:00:00 2001 From: x <1574533602@qq.com> Date: Tue, 30 Apr 2024 17:36:16 +0800 Subject: [PATCH 1/3] add dfs tvl --- projects/dfs/index.js | 14 ++++++++++++++ projects/helper/chains.json | 1 + 2 files changed, 15 insertions(+) diff --git a/projects/dfs/index.js b/projects/dfs/index.js index 545947a86c0f..4c2973735ce1 100644 --- a/projects/dfs/index.js +++ b/projects/dfs/index.js @@ -20,9 +20,23 @@ async function eos() { return await get_account_tvl("defisswapcnt", tokens); } + +// https://dfs.land/ +const utils = require("../helper/utils"); +const endpoint = 'https://api.dfs.land/dfschain'; +async function dfs() { + const info = await utils.fetchURL(`${endpoint}/infos`); + return { + tether: info.data.tvl, + } +} + module.exports = { methodology: `DFS TVL is achieved by querying token balances from DFS's AMM swap liquidity smart contract.`, eos: { tvl: eos }, + dfs: { + tvl: dfs + }, } diff --git a/projects/helper/chains.json b/projects/helper/chains.json index c1520b8f4dae..53c47d89cff7 100644 --- a/projects/helper/chains.json +++ b/projects/helper/chains.json @@ -73,6 +73,7 @@ "defiverse", "degen", "dexit", + "dfs", "dfk", "doge", "dogechain", From 8764430ba3613e8bcbac187cc8b1abb3bcfc73f0 Mon Sep 17 00:00:00 2001 From: x <1574533602@qq.com> Date: Sun, 12 May 2024 10:21:44 +0800 Subject: [PATCH 2/3] calc tvl by chain --- projects/dfs/index.js | 76 ++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/projects/dfs/index.js b/projects/dfs/index.js index 4c2973735ce1..180cf1007bbb 100644 --- a/projects/dfs/index.js +++ b/projects/dfs/index.js @@ -1,42 +1,72 @@ -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 utils = require("../helper/utils"); -const endpoint = 'https://api.dfs.land/dfschain'; +const axios = require('axios'); +const endpoint = 'https://api.dfs.land'; async function dfs() { - const info = await utils.fetchURL(`${endpoint}/infos`); - return { - tether: info.data.tvl, + 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, + }), + }); + console.log(info.data); + 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 + tvl: dfs, }, -} +}; From 617238b2607fb7ff31426afbee200d96423d8d79 Mon Sep 17 00:00:00 2001 From: x <1574533602@qq.com> Date: Sun, 12 May 2024 10:25:07 +0800 Subject: [PATCH 3/3] del log --- projects/dfs/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/dfs/index.js b/projects/dfs/index.js index 180cf1007bbb..968aa75f2963 100644 --- a/projects/dfs/index.js +++ b/projects/dfs/index.js @@ -34,7 +34,6 @@ async function dfs() { limit: -1, }), }); - console.log(info.data); const markets = info.data.rows || []; const dfsMkt = markets.find((m) => m.mid == 1); let dfsPrice = 1;