Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions projects/CatFee/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const ADDRESSES = require("../helper/coreAssets.json");
const { post } = require('../helper/http');

const { getEnv } = require('../helper/env')
const sleep = (ms) => new Promise(r => setTimeout(r, ms));

const addresses = [
'TKoffapJgw2E586kp9taJvjqdfpiKrWKWG',
'TSmrfRFesHf9of94mNKLgrunbFzrPYGiPZ',
'TYEMUMKBmkTRMa1CNh7xkNYZ2mTVFw9f1a',
'TQmxShUFhs8bHxdQKeWWFNPYJJp5mzUz38',
'TXtt43tfe6SUL8HU6KNutXNm4Ybuj1Ro25',
'TGinDyFgTLYcnoJtFatxictWB1dfN6no26'
]

async function callApi(api, body) {
return await post(getEnv('TRON_RPC') + api, body)
}
async function getDelegatedAmountSun(from, to) {
const data = await callApi('/wallet/getdelegatedresourcev2', {
fromAddress: from,
toAddress: to,
visible: true
})
const list = data.delegatedResource || [];
let bw = 0, en = 0;
for (const it of list) {
bw += Number(it.frozen_balance_for_bandwidth || 0);
en += Number(it.frozen_balance_for_energy || 0);
}
return bw + en
}

async function sumOneAddress(to) {
const response = await callApi('/wallet/getdelegatedresourceaccountindexv2', {
value: to,
visible: true
})
const perRequestDelayMs = 100
let totalSun = 0;
for (const from of response.fromAccounts) {
const a = await getDelegatedAmountSun(from, to);
totalSun += a || 0;
if (perRequestDelayMs > 0) await sleep(perRequestDelayMs);
}
return totalSun
}
async function getStakedTron() {
let total = 0
for (const address of addresses) {
total += await sumOneAddress(address)
}
return total / 1000_000
}


module.exports = {
tron: {
tvl: async () => {
return {
tron: await getStakedTron(),
};
},
},
timetravel: false,
};
Loading