From 17b080147e10807243bd483b412cbe2d4da27504 Mon Sep 17 00:00:00 2001 From: Saber Coder <45599139+SaberDoTcodeR@users.noreply.github.com> Date: Tue, 5 Mar 2024 13:29:09 +0000 Subject: [PATCH] Add TONNEL Network (#9183) * Add TONNEL Network * code refactor, count staked tonnel under staking * fix address format add sleep between tvl and staking to avoid rate limit * fix staking * code refactor --------- Co-authored-by: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> --- projects/helper/chain/ton.js | 15 ++++++++++++--- projects/tonnel/config.js | 32 ++++++++++++++++++++++++++++++++ projects/tonnel/index.js | 25 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 projects/tonnel/config.js create mode 100644 projects/tonnel/index.js diff --git a/projects/helper/chain/ton.js b/projects/helper/chain/ton.js index c33ad73477fc..898c3ccce022 100644 --- a/projects/helper/chain/ton.js +++ b/projects/helper/chain/ton.js @@ -1,18 +1,23 @@ const { get, post, } = require('../http') const ADDRESSES = require('../coreAssets.json') -const { getUniqueAddresses } = require('../utils') +const plimit = require('p-limit') +const _rateLimited = plimit(1) +const rateLimited = fn => (...args) => _rateLimited(() => fn(...args)) + +const { getUniqueAddresses, sleep } = require('../utils') async function getTonBalance(addr) { const res = await get(`https://tonapi.io/v2/accounts/${addr}`) return res.balance } -async function sumTokensAccount({ api, addr, tokens = [], onlyWhitelistedTokens = false }) { +async function _sumTokensAccount({ api, addr, tokens = [], onlyWhitelistedTokens = false }) { if (tokens.includes(ADDRESSES.null)) { const balance = await getTonBalance(addr) api.add(ADDRESSES.null, balance) } const { balances } = await get(`https://tonapi.io/v2/accounts/${addr}/jettons?currencies=usd`) + await sleep(1000 * (10 * Math.random() + 3)) balances.forEach(({ balance, price, jetton }) => { if (onlyWhitelistedTokens && !tokens.includes(jetton.address)) return; const decimals = jetton.decimals @@ -23,12 +28,16 @@ async function sumTokensAccount({ api, addr, tokens = [], onlyWhitelistedTokens }) } +const sumTokensAccount = rateLimited(_sumTokensAccount) + async function sumTokens({ api, tokens, owners = [], owner, onlyWhitelistedTokens = false }) { if (!api) throw new Error('api is required') if (owner) owners.push(owner) owners = getUniqueAddresses(owners, api.chain) - await Promise.all(owners.map(i => sumTokensAccount({ api, addr: i, tokens, onlyWhitelistedTokens }))) + for (const addr of owners) { + await sumTokensAccount({ api, addr, tokens, onlyWhitelistedTokens }) + } return api.getBalances() } diff --git a/projects/tonnel/config.js b/projects/tonnel/config.js new file mode 100644 index 000000000000..5303ead06b5a --- /dev/null +++ b/projects/tonnel/config.js @@ -0,0 +1,32 @@ +const ADDRESSES = require('../helper/coreAssets.json') +const tokens = { + "GRAM": "0:b8ef4f77a17e5785bd31ba4da50abd91852f2b8febee97ad6ee16d941f939198", // EQC47093oX5Xhb0xuk2lCr2RhS8rj-vul61u4W2UH5ORmG_O + "DFC": "0:f6eb371de82aa9cfb5b22ca547f31fdc0fa0fbb41ae89ba84a73272ff0bf2157"//EQD26zcd6Cqpz7WyLKVH8x_cD6D7tBrom6hKcycv8L8hV0GP +} + +module.exports = { + ton: [ + { + tokens: [ADDRESSES.null], + holders: [ + "EQBemaU1eAM-fJP7tSniJGEmltPjitgGnlrP6UaXI7nzmEuV", // 5 TON + "EQBZ0-2-isPEN_lIyg9eqXO_RFWrl_PWIJq5K6SVcUwne23W", // 50 TON + "EQBYpQiQMwGBMzhOlJ52e4yXmcKCB_5uTTJ7bVSGqr-8YANi", // 250 TON + "EQB-s4WzIgGP9U6DNlFH_kSn0JuxhBCBXr_rKz2ztEiozTto", // 1000 TON + ], + }, + { + tokens: [tokens.GRAM], // GRAM + holders: [ + "EQD7U_FPYRFTGgiqrpiKh8_giyrIQHZtokUKvz2EmWvlmViC", // 500k GRAM + "EQCZXyOWRih3jtyhdCA7DV7KXluNbzqeIpJPnRkF4KEE1STp", // 30k GRAM + ], + }, + { + tokens: [tokens.DFC], // DFC + holders: [ + "EQC14SC0-P0iOXzn1971HVIDsCzQ0LllY0y5O7EE2pMLe9pT" // 100 DFC + ], + }, + ], +} \ No newline at end of file diff --git a/projects/tonnel/index.js b/projects/tonnel/index.js new file mode 100644 index 000000000000..960b2259497f --- /dev/null +++ b/projects/tonnel/index.js @@ -0,0 +1,25 @@ +const { sumTokensExport } = require('../helper/chain/ton') + +const config = require('./config.js') +const tonnel = "0:cd0efe78bff4c4539b76eab17293296c74f42cbf99ec499687fefec94893ed32" //EQDNDv54v_TEU5t26rFykylsdPQsv5nsSZaH_v7JSJPtMitv +const tonnelHolders = [ + "EQDTs-yjPLn7XzaRRq8pjp7H8Nw4y_OJ51Bk2dcrPlIYgwtV", // 10000 TONNEL + "EQAgoyECSzCIFTFkMIvDLgdUE3D9RxGfYQQGfxy3lBBc_Ke_", // 1000 TONNEL + "EQDzAhS3Ev8cxEBJ96MIqPjxyD_k0L3enzDWnQ3Z-4tUK1h5", // 200 TONNEL + "EQASyc8d2DjZHrFevnF432NRLc4qwh6HGUPAbMvbofMkeRZl", // 50 TONNEL + "EQCNoApBzMacKKdTwcvi1iOx78e98bTSaN1Gx_nnmd3Ek5Yn", // 66 TONNEL +] + +Object.keys(config).forEach((chain) => { + const tokenSet = new Set() + const owners = config[chain].map(({ tokens, holders }) => { + tokens.forEach(i => tokenSet.add(i)) + return holders + }).flat() + + module.exports[chain] = { + tvl: sumTokensExport({ owners, tokens: [...tokenSet], onlyWhitelistedTokens: true, }) + } + if (chain === 'ton') + module.exports.ton.staking = sumTokensExport({ owners: tonnelHolders, tokens: [tonnel], onlyWhitelistedTokens: true,}) +}) \ No newline at end of file