Skip to content

Commit

Permalink
Merge pull request #319 from dappradar/injective-DeFi-integration
Browse files Browse the repository at this point in the history
levana, stride, wormhole
  • Loading branch information
mantasfam authored Nov 13, 2024
2 parents 1bee201 + b9c558f commit 9ebf574
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/factory/providers/injective/levana/index.ts
Original file line number Diff line number Diff line change
@@ -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<Partial<ITvlReturn>> {
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 };
17 changes: 17 additions & 0 deletions src/factory/providers/injective/stride/index.ts
Original file line number Diff line number Diff line change
@@ -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<Partial<ITvlReturn>> {
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 };
17 changes: 17 additions & 0 deletions src/factory/providers/injective/wormhole/index.ts
Original file line number Diff line number Diff line change
@@ -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<Partial<ITvlReturn>> {
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 };

0 comments on commit 9ebf574

Please sign in to comment.