From 976411ae43da537613793dc8d0857a7082f4dc3e Mon Sep 17 00:00:00 2001 From: danilo neves cruz Date: Fri, 18 Oct 2024 20:18:58 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20server:=20batch=20activity?= =?UTF-8?q?=20log=20querying?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/api/activity.ts | 51 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/server/api/activity.ts b/server/api/activity.ts index db9bbb95..78e9ae4f 100644 --- a/server/api/activity.ts +++ b/server/api/activity.ts @@ -120,33 +120,38 @@ export default app.get( .filter((value: T | undefined): value is T => value !== undefined); } - const repays = ignore("repay") - ? [] - : await publicClient.getLogs({ - event: marketAbi.find((item) => item.type === "event" && item.name === "RepayAtMaturity"), - address: [...marketsByAddress.keys()], - args: { caller: exaPluginAddress, borrower: account }, - toBlock: "latest", - fromBlock: 0n, - }); - - const withdraws = ignore("withdraw") - ? [] - : await publicClient - .getLogs({ - event: marketAbi.find((item) => item.type === "event" && item.name === "Withdraw"), + const [repays, withdraws] = await Promise.all([ + ignore("repay") + ? [] + : await publicClient.getLogs({ + event: marketAbi.find((item) => item.type === "event" && item.name === "RepayAtMaturity"), address: [...marketsByAddress.keys()], - args: { caller: account, owner: account }, + args: { caller: exaPluginAddress, borrower: account }, toBlock: "latest", fromBlock: 0n, - }) - .then((logs) => - logs.filter( - ({ topics, data }) => - decodeEventLog({ abi: marketAbi, eventName: "Withdraw", topics, data }).args.receiver.toLowerCase() !== - collector, + }), + ignore("withdraw") + ? [] + : await publicClient + .getLogs({ + event: marketAbi.find((item) => item.type === "event" && item.name === "Withdraw"), + address: [...marketsByAddress.keys()], + args: { caller: account, owner: account }, + toBlock: "latest", + fromBlock: 0n, + }) + .then((logs) => + logs.filter( + ({ topics, data }) => + decodeEventLog({ + abi: marketAbi, + eventName: "Withdraw", + topics, + data, + }).args.receiver.toLowerCase() !== collector, + ), ), - ); + ]); const blocks = await Promise.all( [...new Set([...repays, ...withdraws].map(({ blockNumber }) => blockNumber))].map((blockNumber) =>