Skip to content

Commit

Permalink
add cache for asset params (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobthebuidlr authored Dec 8, 2023
1 parent 5bc8afb commit aef2940
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/api/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
12 changes: 10 additions & 2 deletions src/api/params/getAssetParams.ts
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/vaults/getDepositedVaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function getVaultPositionStatusAndUnlockIdAndUnlockTime(
}
}

function flatVaultPositionAmount(
export function flatVaultPositionAmount(
vaultPositionAmount: VaultPositionAmount,
): VaultPositionFlatAmounts {
const amounts = {
Expand All @@ -82,7 +82,7 @@ function flatVaultPositionAmount(
return amounts
}

async function getLpTokensForVaultPosition(
export async function getLpTokensForVaultPosition(
vault: Vault,
vaultPosition: VaultPosition,
): Promise<Coin[]> {
Expand Down

0 comments on commit aef2940

Please sign in to comment.