Skip to content

Commit 4669d82

Browse files
committed
fix: cache lists per chain
1 parent 27ebbf8 commit 4669d82

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/govv3/utils/checkAddress.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,24 @@ export async function findAsset(client: Client, address: Hex) {
7070
return assetsCache[chainId][address];
7171
}
7272

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

7575
export async function assetIndexesToAsset(
7676
client: Client,
7777
poolAddress: Hex,
7878
indexes: number[],
7979
): Promise<string[]> {
80-
if (!cachedReservesList.length)
81-
cachedReservesList = await getContract({
80+
if (!cachedReservesList[client.chain!.id])
81+
cachedReservesList[client.chain!.id] = await getContract({
8282
client,
8383
abi: IPool_ABI,
8484
address: poolAddress,
8585
}).read.getReservesList();
86+
const reservesList = cachedReservesList[client.chain!.id];
8687
return await Promise.all(
8788
indexes.map(async (index) => {
88-
if (index < cachedReservesList.length) {
89-
const reserve = cachedReservesList[index];
89+
if (index < reservesList.length) {
90+
const reserve = reservesList[index];
9091
return `${(await findAsset(client, reserve)).symbol}(id: ${index})`;
9192
}
9293
return `unknown(id: ${index})`;

0 commit comments

Comments
 (0)