add cache for asset params (#683)

This commit is contained in:
Bob van der Helm 2023-12-08 12:54:40 +01:00 committed by GitHub
parent 5bc8afb410
commit aef2940ed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View File

@ -61,3 +61,4 @@ export const allParamsCache: Cache<AssetParamsBaseForAddr[]> = new Map()
export const underlyingDebtCache: Cache<string> = new Map()
export const previewDepositCache: Cache<{ vaultAddress: string; amount: string }> = new Map()
export const stakingAprCache: Cache<StakingApr[]> = new Map()
export const assetParamsCache: Cache<AssetParamsBaseForAddr[]> = new Map()

View File

@ -1,11 +1,19 @@
import { assetParamsCache, cacheFn } from 'api/cache'
import { getParamsQueryClient } from 'api/cosmwasm-client'
import { AssetParamsBaseForAddr } from 'types/generated/mars-params/MarsParams.types'
import iterateContractQuery from 'utils/iterateContractQuery'
export default async function getAssetParams(): Promise<AssetParamsBaseForAddr[]> {
try {
const paramsQueryClient = await getParamsQueryClient()
return iterateContractQuery(paramsQueryClient.allAssetParams)
return await cacheFn(
async () => {
const paramsQueryClient = await getParamsQueryClient()
return iterateContractQuery(paramsQueryClient.allAssetParams)
},
assetParamsCache,
'assetParams',
600,
)
} catch (ex) {
throw ex
}

View File

@ -62,7 +62,7 @@ async function getVaultPositionStatusAndUnlockIdAndUnlockTime(
}
}
function flatVaultPositionAmount(
export function flatVaultPositionAmount(
vaultPositionAmount: VaultPositionAmount,
): VaultPositionFlatAmounts {
const amounts = {
@ -82,7 +82,7 @@ function flatVaultPositionAmount(
return amounts
}
async function getLpTokensForVaultPosition(
export async function getLpTokensForVaultPosition(
vault: Vault,
vaultPosition: VaultPosition,
): Promise<Coin[]> {