From b9c558f68a73a7d1cb234150e602252ea5853dfb Mon Sep 17 00:00:00 2001 From: Mantas S Date: Wed, 13 Nov 2024 18:01:33 +0200 Subject: [PATCH] levana, stride, wormhole --- .../providers/injective/levana/index.ts | 50 +++++++++++++++++++ .../providers/injective/stride/index.ts | 17 +++++++ .../providers/injective/wormhole/index.ts | 17 +++++++ 3 files changed, 84 insertions(+) create mode 100644 src/factory/providers/injective/levana/index.ts create mode 100644 src/factory/providers/injective/stride/index.ts create mode 100644 src/factory/providers/injective/wormhole/index.ts diff --git a/src/factory/providers/injective/levana/index.ts b/src/factory/providers/injective/levana/index.ts new file mode 100644 index 0000000..2b697c7 --- /dev/null +++ b/src/factory/providers/injective/levana/index.ts @@ -0,0 +1,50 @@ +import formatter from '../../../../util/formatter'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; + +const LEVANA_FACTORY_ADDRESS = 'inj1vdu3s39dl8t5l88tyqwuhzklsx9587adv8cnn9'; +const MARKETS = 'markets'; + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + let balances = {}; + + const limit = 30; + let markets = []; + const marketAddresses = []; + let iterationMarkets = []; + do { + const start_after = markets.length + ? markets[markets.length - 1] + : undefined; + + const query = { + limit, + ...(start_after && { start_after }), + }; + + iterationMarkets = await web3.eth + .call(LEVANA_FACTORY_ADDRESS, MARKETS, query) + .then((response) => response[MARKETS]); + markets = markets.concat(iterationMarkets); + + for (const iterationMarket of iterationMarkets) { + const marketAddress = await web3.eth + .call(LEVANA_FACTORY_ADDRESS, 'market_info', { + market_id: iterationMarket, + }) + .then((response) => response.market_addr); + + marketAddresses.push(marketAddress); + } + } while (iterationMarkets.length > 0); + + for (const marketAddress of marketAddresses) { + const marketBalances = await web3.eth.getAccountBalances(marketAddress); + balances = formatter.sum([balances, marketBalances]); + } + + formatter.convertBalancesToFixed(balances); + return { balances }; +} + +export { tvl }; diff --git a/src/factory/providers/injective/stride/index.ts b/src/factory/providers/injective/stride/index.ts new file mode 100644 index 0000000..e1de0da --- /dev/null +++ b/src/factory/providers/injective/stride/index.ts @@ -0,0 +1,17 @@ +import formatter from '../../../../util/formatter'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; + +const STINJ_ADDRESS = 'inj10fd06xl4q6jp9qlhemvm6ymmm83ppj2g8rzquw'; + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + let balances = {}; + + const accountBalances = await web3.eth.getAccountBalances(STINJ_ADDRESS); + balances = formatter.sum([balances, accountBalances]); + + formatter.convertBalancesToFixed(balances); + return { balances }; +} + +export { tvl }; diff --git a/src/factory/providers/injective/wormhole/index.ts b/src/factory/providers/injective/wormhole/index.ts new file mode 100644 index 0000000..803680d --- /dev/null +++ b/src/factory/providers/injective/wormhole/index.ts @@ -0,0 +1,17 @@ +import formatter from '../../../../util/formatter'; +import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; + +const PORTAL_ADDRESS = 'inj1ghd753shjuwexxywmgs4xz7x2q732vcnxxynfn'; + +async function tvl(params: ITvlParams): Promise> { + const { block, chain, provider, web3 } = params; + let balances = {}; + + const portalBalances = await web3.eth.getAccountBalances(PORTAL_ADDRESS); + balances = formatter.sum([balances, portalBalances]); + + formatter.convertBalancesToFixed(balances); + return { balances }; +} + +export { tvl };