From e2022ee739bdfb09aae070d8f590677489321c89 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Wed, 18 Sep 2024 13:30:53 +0300 Subject: [PATCH 1/4] Update index.ts --- src/factory/providers/bsc/pancakeswapv3/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factory/providers/bsc/pancakeswapv3/index.ts b/src/factory/providers/bsc/pancakeswapv3/index.ts index 7a1c7b9..7f1888e 100644 --- a/src/factory/providers/bsc/pancakeswapv3/index.ts +++ b/src/factory/providers/bsc/pancakeswapv3/index.ts @@ -7,7 +7,7 @@ const THEGRAPTH_ENDPOINT = `https://gateway-arbitrum.network.thegraph.com/api/${ async function tvl(params: ITvlParams): Promise> { const { chain, provider, web3 } = params; - const block = params.block - 100; + const block = params.block - 1000; if (block < START_BLOCK) { return { balances: {} }; From 1f9fa86d38d39dd1a27cd26a5147498502da20da Mon Sep 17 00:00:00 2001 From: Mantas S Date: Tue, 24 Sep 2024 11:24:22 +0300 Subject: [PATCH 2/4] reduce --- src/util/logger/logger.ts | 34 ++++++++++++-- src/web3Provider/solana.ts | 94 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 122 insertions(+), 6 deletions(-) diff --git a/src/util/logger/logger.ts b/src/util/logger/logger.ts index d257464..56760a4 100644 --- a/src/util/logger/logger.ts +++ b/src/util/logger/logger.ts @@ -3,9 +3,37 @@ import { getLogger, configure } from 'log4js'; const logger = getLogger(); interface ILogger { - info: ({ message, endpoint }) => void; - warning: ({ message, stack, detail, endpoint }) => void; - error: ({ message, stack, detail, endpoint }) => void; + info: ({ + message, + detail, + endpoint, + }: { + message?: string; + detail?: string; + endpoint?: string; + }) => void; + warning: ({ + message, + stack, + detail, + endpoint, + }: { + message?: string; + stack?: string; + detail?: string; + endpoint?: string; + }) => void; + error: ({ + message, + stack, + detail, + endpoint, + }: { + message?: string; + stack?: string; + detail?: string; + endpoint?: string; + }) => void; } configure({ diff --git a/src/web3Provider/solana.ts b/src/web3Provider/solana.ts index 6bacd7e..e970b98 100644 --- a/src/web3Provider/solana.ts +++ b/src/web3Provider/solana.ts @@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js'; import { Injectable } from '@nestjs/common'; import { config, nodeUrls } from '../app.config'; import Bottleneck from 'bottleneck'; +import { log } from '../util/logger/logger'; const nodeUrl = nodeUrls.SOLANA_NODE_URL; const solanaBottleNeckMinTime = config.SOLANA_BOTTLENECK_MIN_TIME; @@ -13,12 +14,25 @@ const limiter = new Bottleneck({ @Injectable() export class Solana { getNodeUrl() { + log.info({ + message: 'Fetching Solana node URL', + detail: 'solana - Fetched Solana node URL.', + endpoint: 'solana.getNodeUrl', + }); return nodeUrl; } async call(method, params) { return limiter.schedule(async () => { try { + log.info({ + message: `Calling method: ${method} with params: ${JSON.stringify( + params, + )}`, + detail: `solana - API call initiated.`, + endpoint: 'solana.call', + }); + const res = await fetch(nodeUrl, { method: 'post', headers: { 'Content-Type': 'application/json' }, @@ -31,11 +45,29 @@ export class Solana { }).then((res) => res.json()); if (res.error) { + log.error({ + message: `Error in method ${method}: ${res.error.message}`, + detail: `solana - API call encountered an error.`, + endpoint: 'solana.call', + }); throw res.error; } + log.info({ + message: `Response from method ${method}: ${JSON.stringify( + res.result, + )}`, + detail: `solana - API call returned successfully.`, + endpoint: 'solana.call', + }); + return res.result; - } catch { + } catch (e) { + log.error({ + message: `Exception in method ${method}: ${e.message}`, + detail: `solana - API call failed with exception.`, + endpoint: 'solana.call', + }); return null; } }); @@ -43,19 +75,29 @@ export class Solana { async getBlockNumber() { const res = await this.call('getSlot', []); + log.info({ + message: `Fetched block number: ${res}`, + detail: `solana - Fetched block number using getSlot.`, + endpoint: 'solana.getBlockNumber', + }); return res; } async getBlock(slotNumber) { let slot = slotNumber || 0; if (slotNumber == 'latest') { - slot = await module.exports.eth.getBlockNumber(); + slot = await this.getBlockNumber(); } let res; while (true) { res = await this.call('getBlockTime', [slot]); if (res && !res.error) { + log.info({ + message: `Found block at slot ${slot} with timestamp: ${res}`, + detail: `solana - Block found successfully.`, + endpoint: 'solana.getBlock', + }); break; } slot += 1; @@ -76,11 +118,24 @@ class Contract { constructor(abi, address) { this.abi = abi; this.address = address; + log.info({ + message: `Contract instance created for address: ${address}`, + detail: `solana - Contract creation logged.`, + endpoint: 'solana.Contract.constructor', + }); } async call(method, params) { return limiter.schedule(async () => { try { + log.info({ + message: `Calling method: ${method} with params: ${JSON.stringify( + params, + )} for contract ${this.address}`, + detail: `solana - Contract API call initiated.`, + endpoint: 'solana.Contract.call', + }); + const res = await fetch(nodeUrl, { method: 'post', headers: { 'Content-Type': 'application/json' }, @@ -93,11 +148,29 @@ class Contract { }).then((res) => res.json()); if (res.error) { + log.error({ + message: `Error in method ${method}: ${res.error.message} for contract ${this.address}`, + detail: `solana - Contract API call encountered an error.`, + endpoint: 'solana.Contract.call', + }); throw res.error; } + log.info({ + message: `Response from method ${method}: ${JSON.stringify( + res.result, + )} for contract ${this.address}`, + detail: `solana - Contract API call returned successfully.`, + endpoint: 'solana.Contract.call', + }); + return res.result; - } catch { + } catch (e) { + log.error({ + message: `Exception in method ${method}: ${e.message} for contract ${this.address}`, + detail: `solana - Contract API call failed with exception.`, + endpoint: 'solana.Contract.call', + }); return null; } }); @@ -109,6 +182,11 @@ class Contract { return { call: async () => { const res = await this.call('getTokenSupply', [this.address]); + log.info({ + message: `Total supply fetched: ${res.value.amount} for contract ${this.address}`, + detail: `solana - Fetched total supply of contract.`, + endpoint: 'solana.Contract.methods.totalSupply.call', + }); return res.value.amount; }, }; @@ -125,6 +203,7 @@ class Contract { encoding: 'jsonParsed', }, ]); + let balance = BigNumber(0); res.value.forEach((value) => { if (value && value.account && value.account.data) { @@ -133,6 +212,15 @@ class Contract { ); } }); + + log.info({ + message: `Balance fetched for account ${account}: ${balance.toFixed()} for contract ${ + this.address + }`, + detail: `solana - Balance fetched successfully.`, + endpoint: 'solana.Contract.methods.balanceOf.call', + }); + return balance.toFixed(); }, }; From b30fb45771ca190fbac8cf6f4ea974dde50d4700 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Tue, 24 Sep 2024 12:47:31 +0300 Subject: [PATCH 3/4] Update index.ts --- src/factory/providers/solana/raydium/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/factory/providers/solana/raydium/index.ts b/src/factory/providers/solana/raydium/index.ts index 4d6d0f6..6bd4a63 100644 --- a/src/factory/providers/solana/raydium/index.ts +++ b/src/factory/providers/solana/raydium/index.ts @@ -18,6 +18,7 @@ const RAYDIUM_POOLS_ENDPOINT = async function tvl(params: ITvlParams): Promise> { const { web3 } = params; + const balances = {}; const pools = await fetch(RAYDIUM_POOLS_ENDPOINT).then((res) => res.json()); const RAYDIUM_POOLS = pools.official; From faecc674b71746ac4cf0a5b81dc3cef83ac8b7d6 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Tue, 24 Sep 2024 16:32:13 +0300 Subject: [PATCH 4/4] aavev3 --- src/factory/providers/bsc/aavev3/index.ts | 24 +++++++++++++++++++ .../providers/optimism/aavev3/data.json | 7 ------ .../providers/zksync-era/aavev3/index.ts | 24 +++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 src/factory/providers/bsc/aavev3/index.ts delete mode 100644 src/factory/providers/optimism/aavev3/data.json create mode 100644 src/factory/providers/zksync-era/aavev3/index.ts diff --git a/src/factory/providers/bsc/aavev3/index.ts b/src/factory/providers/bsc/aavev3/index.ts new file mode 100644 index 0000000..a8a2efe --- /dev/null +++ b/src/factory/providers/bsc/aavev3/index.ts @@ -0,0 +1,24 @@ +import formatter from '../../../../util/formatter'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; +import aaveV3 from '../../../../util/calculators/aaveV3'; + +const START_BLOCK = 33571625; +const POOL_DATA_PROVIDER_V3 = '0x41585C50524fb8c3899B43D7D797d9486AAc94DB'; + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + if (block < START_BLOCK) { + return {}; + } + + const balances = await aaveV3.getTvl( + POOL_DATA_PROVIDER_V3, + block, + chain, + web3, + ); + + formatter.convertBalancesToFixed(balances); + return { balances }; +} +export { tvl }; diff --git a/src/factory/providers/optimism/aavev3/data.json b/src/factory/providers/optimism/aavev3/data.json deleted file mode 100644 index 1b8f1a8..0000000 --- a/src/factory/providers/optimism/aavev3/data.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "address": "0x76fb31fb4af56892a25e32cfc43de717950c9278", - "name": "Aave", - "symbol": "AAVE", - "decimals": 18, - "logo": "https://assets.coingecko.com/coins/images/12645/small/AAVE.png" -} \ No newline at end of file diff --git a/src/factory/providers/zksync-era/aavev3/index.ts b/src/factory/providers/zksync-era/aavev3/index.ts new file mode 100644 index 0000000..4babd13 --- /dev/null +++ b/src/factory/providers/zksync-era/aavev3/index.ts @@ -0,0 +1,24 @@ +import formatter from '../../../../util/formatter'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; +import aaveV3 from '../../../../util/calculators/aaveV3'; + +const START_BLOCK = 43708965; +const POOL_DATA_PROVIDER_V3 = '0x48B96565291d1B23a014bb9f68E07F4B2bb3Cd6D'; + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + if (block < START_BLOCK) { + return {}; + } + + const balances = await aaveV3.getTvl( + POOL_DATA_PROVIDER_V3, + block, + chain, + web3, + ); + + formatter.convertBalancesToFixed(balances); + return { balances }; +} +export { tvl };