Skip to content

Commit

Permalink
add dfs tvl (#10046)
Browse files Browse the repository at this point in the history
* add dfs tvl

* calc tvl by chain

* del log
  • Loading branch information
webWorker-eos authored May 13, 2024
1 parent 976ed71 commit 1228d36
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 16 deletions.
75 changes: 59 additions & 16 deletions projects/dfs/index.js
Original file line number Diff line number Diff line change
@@ -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,
},
};
1 change: 1 addition & 0 deletions projects/helper/chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"defiverse",
"degen",
"dexit",
"dfs",
"dfk",
"doge",
"dogechain",
Expand Down

0 comments on commit 1228d36

Please sign in to comment.