diff --git a/src/api/hls/getHLSVaults.ts b/src/api/hls/getHLSVaults.ts new file mode 100644 index 00000000..2b09a9b3 --- /dev/null +++ b/src/api/hls/getHLSVaults.ts @@ -0,0 +1,34 @@ +import { getCreditManagerQueryClient } from 'api/cosmwasm-client' +import getAssetParams from 'api/params/getAssetParams' +import { getVaultConfigs } from 'api/vaults/getVaultConfigs' +import { BN } from 'utils/helpers' +import { resolveHLSStrategies } from 'utils/resolvers' + +export default async function getHLSVaults() { + const assetParams = await getAssetParams() + const client = await getCreditManagerQueryClient() + const vaultConfigs = await getVaultConfigs() + const HLSAssets = assetParams.filter((asset) => asset.credit_manager.hls) + const strategies = resolveHLSStrategies('vault', HLSAssets) + + const vaultUtilizations$ = strategies.map((strategy) => + client.vaultUtilization({ vault: { address: strategy.denoms.deposit } }), + ) + + return Promise.all(vaultUtilizations$).then((vaultUtilizations) => + vaultUtilizations.map( + (utilization, index) => + ({ + ...strategies[index], + depositCap: { + denom: utilization.vault.address, + used: BN(utilization.utilization.amount), + max: BN( + vaultConfigs.find((config) => config.addr === utilization.vault.address)?.deposit_cap + .amount || 0, + ), + }, + }) as HLSStrategy, + ), + ) +} diff --git a/src/components/Account/AccountDetails/index.tsx b/src/components/Account/AccountDetails/index.tsx index 550e5d78..8ef7122a 100644 --- a/src/components/Account/AccountDetails/index.tsx +++ b/src/components/Account/AccountDetails/index.tsx @@ -112,8 +112,8 @@ function AccountDetails(props: Props) {