Skip to content

Commit 72c7312

Browse files
committed
feat: update TVL calculation method for 1DEX to use account balance querying
1 parent 3a6a22a commit 72c7312

File tree

1 file changed

+11
-84
lines changed

1 file changed

+11
-84
lines changed

projects/1dex/index.js

Lines changed: 11 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,19 @@
1-
const { post } = require("../helper/http");
2-
3-
const endpoint = 'https://eos.greymass.com/v1';
4-
5-
const symbolToCoingeckoId = {
6-
'EOS': 'eos',
7-
'USDT': 'tether',
8-
'BTC': 'bitcoin',
9-
'XSAT': 'exsat-network',
10-
};
11-
12-
async function getContractActions(contract, actionNames) {
13-
const allActions = [];
14-
const pageSize = 100;
15-
let pos = -1;
16-
let hasMore = true;
17-
18-
while (hasMore) {
19-
const response = await post(`${endpoint}/history/get_actions`, {
20-
account_name: contract,
21-
pos: pos,
22-
offset: -pageSize
23-
});
24-
25-
const actions = response.actions || [];
26-
if (actions.length === 0) break;
27-
28-
const filteredActions = actions.filter(action =>
29-
Array.isArray(actionNames)
30-
? actionNames.includes(action.action_trace.act.name)
31-
: action.action_trace.act.name === actionNames
32-
);
33-
34-
allActions.push(...filteredActions);
35-
36-
const lastAction = actions[actions.length - 1];
37-
pos = lastAction.account_action_seq - pageSize + 1;
38-
hasMore = actions.length === pageSize;
39-
}
40-
41-
return allActions;
42-
}
43-
44-
function calculateBalancesFromActions(actions) {
45-
const balances = {};
46-
47-
for (const action of actions) {
48-
const { name, data } = action.action_trace.act;
49-
const { quantity, contract } = data;
50-
const [amount, symbol] = quantity.split(' ');
51-
52-
if (!balances[symbol]) {
53-
balances[symbol] = {
54-
amount: 0,
55-
contract,
56-
symbol
57-
};
58-
}
59-
60-
const parsedAmount = parseFloat(amount);
61-
if (name === 'logdeposit1' || name === 'logwithdraw1') {
62-
balances[symbol].amount += name === 'logdeposit1' ? parsedAmount : -parsedAmount;
63-
}
64-
}
65-
66-
return balances;
67-
}
68-
69-
function convertToDefiLlamaFormat(balances) {
70-
const result = {};
71-
72-
for (const [symbol, data] of Object.entries(balances)) {
73-
if (data.amount > 0 && symbolToCoingeckoId[symbol]) {
74-
result[symbolToCoingeckoId[symbol]] = data.amount;
75-
}
76-
}
77-
78-
return result;
79-
}
1+
const { get_account_tvl } = require("../helper/chain/eos");
802

3+
// 1DEX
4+
// https://1dex.com
815
async function eos() {
82-
const actions = await getContractActions("portal.1dex", ["logdeposit1", "logwithdraw1"]);
83-
const balances = calculateBalancesFromActions(actions);
84-
return convertToDefiLlamaFormat(balances);
6+
const accounts = ["dex.velox"];
7+
const tokens = [
8+
["eosio.token", "EOS", "eos"],
9+
["usdt.xsat", "USDT", "tether"],
10+
];
11+
return await get_account_tvl(accounts, tokens, "eos");
8512
}
8613

8714
module.exports = {
88-
methodology: `1DEX TVL is calculated by tracking deposit and withdrawal actions (logdeposit1 and logwithdraw1) from the portal.1dex contract.`,
15+
methodology: `1DEX TVL is achieved by querying token balances from swap smart contract.`,
8916
eos: {
90-
tvl: eos,
17+
tvl: eos
9118
},
9219
}

0 commit comments

Comments
 (0)