Skip to content

Commit 2fafd22

Browse files
authored
Get chainlog pool list from registry (#1486)
1 parent 3a70779 commit 2fafd22

File tree

1 file changed

+39
-68
lines changed

1 file changed

+39
-68
lines changed

apps/hyperdrive-trading/src/ui/chainlog/PoolsTable.tsx

Lines changed: 39 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -221,88 +221,59 @@ function usePoolsQuery(): UseQueryResult<Pool[], any> {
221221
}),
222222
placeholderData: [],
223223
queryFn: async () => {
224-
// registries and clients for each chain
225-
const clients: Map<
226-
number,
227-
{
228-
registry: ReadRegistry;
229-
publicClient: PublicClient;
230-
}
231-
> = new Map();
224+
const pools: Pool[] = [];
232225

233-
for (const chainId of chainIds) {
234-
// TODO: Cleanup type casting
235-
const publicClient = getPublicClient(wagmiConfig as any, {
236-
chainId,
237-
}) as PublicClient;
226+
await Promise.all(
227+
chainIds.map(async (chainId) => {
228+
const publicClient = getPublicClient(wagmiConfig as any, {
229+
chainId,
230+
}) as PublicClient;
238231

239-
clients.set(chainId, {
240-
publicClient,
241-
registry: new ReadRegistry({
232+
const registry = new ReadRegistry({
242233
address: appConfig.registries[chainId],
243234
publicClient,
244235
cache: sdkCache,
245236
namespace: chainId.toString(),
246-
}),
247-
});
248-
}
237+
});
249238

250-
return Promise.all(
251-
appConfig.hyperdrives.map(async (hyperdrive): Promise<Pool> => {
252-
const { registry, publicClient } =
253-
clients.get(hyperdrive.chainId) || {};
239+
const addresses = await registry.getInstanceAddresses();
240+
const metas = await registry.getInstanceInfos(addresses);
254241

255-
// Return available static data if no registry is found
256-
if (!registry || !publicClient) {
257-
console.error(
258-
`No registry found for chainId ${hyperdrive.chainId}`,
259-
);
260-
return {
261-
name: hyperdrive.name,
262-
address: hyperdrive.address,
263-
chainId: hyperdrive.chainId,
264-
version: hyperdrive.version,
265-
isPaused: false,
266-
status: "active",
267-
factoryAddress: "0x",
268-
deployerCoordinatorAddress: "0x",
269-
baseToken: hyperdrive.poolConfig.baseToken,
270-
vaultToken: hyperdrive.poolConfig.vaultSharesToken,
271-
};
272-
}
242+
for (const [i, address] of addresses.entries()) {
243+
const { data, factory, name, version } = metas[i];
244+
const { status } = decodeInstanceData(data);
273245

274-
const { data, factory, name, version } =
275-
await registry.getInstanceInfo(hyperdrive.address);
276-
const readHyperdrive = await getReadHyperdrive({
277-
appConfig,
278-
hyperdriveAddress: hyperdrive.address,
279-
publicClient,
280-
});
246+
const readHyperdrive = await getReadHyperdrive({
247+
appConfig,
248+
hyperdriveAddress: address,
249+
publicClient,
250+
});
281251

282-
const { baseToken, vaultSharesToken: vaultToken } =
283-
await readHyperdrive.getPoolConfig();
252+
const { baseToken, vaultSharesToken: vaultToken } =
253+
await readHyperdrive.getPoolConfig();
254+
const { isPaused } = await readHyperdrive.getMarketState();
255+
const [deployerCoordinatorAddress] =
256+
await factory.getDeployerCoordinatorAddresses({
257+
instances: [address],
258+
});
284259

285-
const { isPaused } = await readHyperdrive.getMarketState();
286-
const { status } = decodeInstanceData(data);
287-
const [deployerCoordinatorAddress] =
288-
await factory.getDeployerCoordinatorAddresses({
289-
instances: [hyperdrive.address],
260+
pools.push({
261+
name,
262+
address,
263+
chainId,
264+
version,
265+
isPaused,
266+
status,
267+
factoryAddress: factory.address,
268+
deployerCoordinatorAddress,
269+
baseToken,
270+
vaultToken,
290271
});
291-
292-
return {
293-
name,
294-
address: hyperdrive.address,
295-
chainId: hyperdrive.chainId,
296-
version,
297-
isPaused,
298-
status,
299-
factoryAddress: factory.address,
300-
deployerCoordinatorAddress,
301-
baseToken,
302-
vaultToken,
303-
};
272+
}
304273
}),
305274
);
275+
276+
return pools;
306277
},
307278
});
308279
}

0 commit comments

Comments
 (0)