mars-v2-frontend/src/api/hls/getHLSStakingAccounts.ts
Bob van der Helm 7439bea0d8
Hls staking manage actions (#622)
* Add basic modal for HLS staking

* UI components for Manage

* All Manage actions (except change lev)

* 🐛hls intro icons + checkbox, hide repay when no debt, clickable dropdown

* fix build
2023-11-08 13:05:39 +01:00

40 lines
1.3 KiB
TypeScript

import getHLSStakingAssets from 'api/hls/getHLSStakingAssets'
import getPrices from 'api/prices/getPrices'
import getAccounts from 'api/wallets/getAccounts'
import { calculateAccountLeverage, getAccountPositionValues, isAccountEmpty } from 'utils/accounts'
export default async function getHLSStakingAccounts(
address?: string,
): Promise<HLSAccountWithStrategy[]> {
const accounts = await getAccounts('high_levered_strategy', address)
const activeAccounts = accounts.filter((account) => !isAccountEmpty(account))
const hlsStrategies = await getHLSStakingAssets()
const prices = await getPrices()
const hlsAccountsWithStrategy: HLSAccountWithStrategy[] = []
activeAccounts.forEach((account) => {
if (account.deposits.length === 0) return
const strategy = hlsStrategies.find(
(strategy) => strategy.denoms.deposit === account.deposits.at(0).denom,
)
if (!strategy) return
const [deposits, lends, debts, vaults] = getAccountPositionValues(account, prices)
hlsAccountsWithStrategy.push({
...account,
strategy,
values: {
net: deposits.minus(debts),
debt: debts,
total: deposits,
},
leverage: calculateAccountLeverage(account, prices).toNumber(),
})
})
return hlsAccountsWithStrategy
}