Skip to content

Commit

Permalink
fix: cache lists per chain
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra committed Oct 4, 2024
1 parent 27ebbf8 commit 4669d82
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/govv3/utils/checkAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,24 @@ export async function findAsset(client: Client, address: Hex) {
return assetsCache[chainId][address];
}

let cachedReservesList: readonly Hex[] = [];
const cachedReservesList: Record<number, readonly Hex[]> = {};

export async function assetIndexesToAsset(
client: Client,
poolAddress: Hex,
indexes: number[],
): Promise<string[]> {
if (!cachedReservesList.length)
cachedReservesList = await getContract({
if (!cachedReservesList[client.chain!.id])
cachedReservesList[client.chain!.id] = await getContract({
client,
abi: IPool_ABI,
address: poolAddress,
}).read.getReservesList();
const reservesList = cachedReservesList[client.chain!.id];
return await Promise.all(
indexes.map(async (index) => {
if (index < cachedReservesList.length) {
const reserve = cachedReservesList[index];
if (index < reservesList.length) {
const reserve = reservesList[index];
return `${(await findAsset(client, reserve)).symbol}(id: ${index})`;
}
return `unknown(id: ${index})`;
Expand Down

0 comments on commit 4669d82

Please sign in to comment.