Skip to content

Commit

Permalink
Add TONNEL Network (#9183)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
SaberDoTcodeR and g1nt0ki authored Mar 5, 2024
1 parent f4950c8 commit 17b0801
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
15 changes: 12 additions & 3 deletions projects/helper/chain/ton.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}

Expand Down
32 changes: 32 additions & 0 deletions projects/tonnel/config.js
Original file line number Diff line number Diff line change
@@ -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
],
},
],
}
25 changes: 25 additions & 0 deletions projects/tonnel/index.js
Original file line number Diff line number Diff line change
@@ -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,})
})

0 comments on commit 17b0801

Please sign in to comment.