From 4ce8c631cc5f3e2f44b3fc9ebb6948b614d78811 Mon Sep 17 00:00:00 2001 From: Mantas S Date: Thu, 29 Jun 2023 11:13:18 +0300 Subject: [PATCH] Update index.ts --- .../providers/moonbeam/clipper/index.ts | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/factory/providers/moonbeam/clipper/index.ts b/src/factory/providers/moonbeam/clipper/index.ts index 027f446e..2966007c 100644 --- a/src/factory/providers/moonbeam/clipper/index.ts +++ b/src/factory/providers/moonbeam/clipper/index.ts @@ -1,19 +1,38 @@ import util from '../../../../util/blockchainUtil'; import formatter from '../../../../util/formatter'; +import basicUtil from '../../../../util/basicUtil'; +import { log } from '../../../../util/logger/logger'; import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; import axios from 'axios'; -async function getChainData() { - const { - data: { - pool: { address: poolAddress }, - assets, - }, - } = await axios.get(`https://api.clipper.exchange/rfq/pool?chain_id=1284`); - return { - poolAddress, - tokens: assets.map(({ address }) => address), - }; +async function getChainData(chain, provider) { + let poolInfo: { poolAddress: string; tokens: string[] }; + + try { + const { + data: { + pool: { address: poolAddress }, + assets, + }, + } = await axios.get(`https://api.clipper.exchange/rfq/pool?chain_id=1284`); + + poolInfo = { + poolAddress, + tokens: assets.map(({ address }) => address), + }; + + await basicUtil.saveIntoCache(poolInfo, 'poolInfo.json', chain, provider); + } catch (e) { + log.error({ + message: `Issue with Clipper API`, + stack: e.stack, + detail: `Error: getChainData of moonbeam/clipper`, + endpoint: 'getChainData', + }); + poolInfo = await basicUtil.readFromCache('poolInfo.json', chain, provider); + } + + return poolInfo; } async function tvl(params: ITvlParams): Promise> { @@ -23,7 +42,7 @@ async function tvl(params: ITvlParams): Promise> { } const balances = {}; - const { poolAddress, tokens } = await getChainData(); + const { poolAddress, tokens } = await getChainData(chain, provider); const tokenBalances = await util.getTokenBalances( poolAddress, tokens,