-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #319 from dappradar/injective-DeFi-integration
levana, stride, wormhole
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |