diff --git a/projects/bidask/index.js b/projects/bidask/index.js index efbc899e9..cb4fa7ee3 100644 --- a/projects/bidask/index.js +++ b/projects/bidask/index.js @@ -41,7 +41,6 @@ async function listFactoryPools() { let stack = await rateLimitedCall({ target: pool, abi: 'get_pool_info', rawStack: true }) const xWallet = processTVMSliceReadAddress(stack[0][1].bytes) const yWallet = processTVMSliceReadAddress(stack[1][1].bytes) - await sleep(1500); if (xWallet == 'EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c') { // bidask assigns this address for TON jetton wallet (which doesn't exist) token0 = ADDRESSES.ton.TON; @@ -49,7 +48,6 @@ async function listFactoryPools() { try { const stack0 = await rateLimitedCall({ target: xWallet, abi: 'get_wallet_data', rawStack: true}) token0 = processTVMSliceReadAddress(stack0[2][1].bytes) // https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md#get-methods - await sleep(1500); } catch (e) { continue // sometimes it's ok, jetton wallet might be uninit } @@ -61,9 +59,8 @@ async function listFactoryPools() { try { let stack1 = await rateLimitedCall({ target: yWallet, abi: 'get_wallet_data', rawStack: true}) token1 = processTVMSliceReadAddress(stack1[2][1].bytes) - await sleep(1500); } catch (e) { - continue + continue } } diff --git a/projects/helper/chain/ton.js b/projects/helper/chain/ton.js index ee1b1e8bc..97284190e 100644 --- a/projects/helper/chain/ton.js +++ b/projects/helper/chain/ton.js @@ -1,15 +1,17 @@ const { get, post, } = require('../http') const ADDRESSES = require('../coreAssets.json') const plimit = require('p-limit') -const _rateLimited = plimit(1) +const _rateLimited = plimit(9) const rateLimited = fn => (...args) => _rateLimited(() => fn(...args)) const { sumTokens2 } = require('../unwrapLPs') const tonUtils = require('../utils/ton') - const { getUniqueAddresses, sleep, sliceIntoChunks } = require('../utils') +require('dotenv').config() + +const key = process.env.TONCENTER_API_KEY; async function getTonBalance(addr) { - const res = await get(`https://toncenter.com/api/v3/account?address=${addr}`) + const res = await get(`https://toncenter.com/api/v3/account?address=${addr}` + (key ? `?api_key=${key}` : '')) return res.balance } @@ -104,7 +106,6 @@ async function call({ target, abi, params = [], rawStack = false, }) { "stack": params } - const key = process.env.TONCENTER_API_KEY; // TODO: add api key to env const { ok, result } = await post('https://toncenter.com/api/v2/runGetMethod' + (key ? `?api_key=${key}` : ''), requestBody) if (!ok) { throw new Error("Unknown"); @@ -131,7 +132,7 @@ async function addTonBalances({ api, addresses }) { let i = 0 for (const chunk of chunks) { api.log('Fetching TON balances', { chunk: i++, chunks: chunks.length }) - const { accounts } = await get('https://toncenter.com/api/v3/accountStates?address=' + encodeURIComponent(chunk.join(',')) + '&include_boc=false') + const { accounts } = await get('https://toncenter.com/api/v3/accountStates?address=' + (key ? `?api_key=${key}` : '') + encodeURIComponent(chunk.join(',')) + '&include_boc=false') accounts.forEach(({ balance }) => { api.add(ADDRESSES.null, balance) })